You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

146 lines
4.5KB

  1. /* SpiralPlugin
  2. * Copyleft (C) 2000 David Griffiths <dave@pawfal.org>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18. #include "ScopePluginGUI.h"
  19. #include <FL/fl_draw.h>
  20. #include <FL/fl_draw.H>
  21. ScopeWidget::ScopeWidget (int x, int y, int w, int h, const char *l, int BUFSIZE) :
  22. Fl_Widget (x, y, w, h, l),
  23. m_Data (NULL),
  24. //m_Channels (1),
  25. m_WaveColour (FL_WHITE),
  26. m_Attenuation (1.0),
  27. m_TimeBase (1.0),
  28. m_Bufsize (BUFSIZE)
  29. {
  30. m_Data = new float[BUFSIZE];
  31. }
  32. ScopeWidget::~ScopeWidget()
  33. {
  34. delete[] m_Data;
  35. }
  36. void ScopeWidget::draw() {
  37. int ho=h()/2;
  38. fl_color (color());
  39. fl_rectf (x(), y(), w(), h());
  40. if (!m_Data) return;
  41. fl_push_clip (x(), y(), w(), h());
  42. float Value=0, NextValue=0;
  43. fl_color (m_WaveColour);
  44. for (int n=0; /*n<m_Bufsize-1 &&*/ n<w(); n++) {
  45. int p = int ((float)n*m_TimeBase);
  46. if (p>=m_Bufsize) break;
  47. Value = NextValue;
  48. NextValue = m_Data[p] * m_Attenuation * ho;
  49. fl_line ((int)(x()+n-2), (int)(y()+ho-Value), (int)(x()+n-1), (int)(y()+ho-NextValue));
  50. }
  51. fl_pop_clip();
  52. }
  53. ////////////////////////////////////////////
  54. ScopePluginGUI::ScopePluginGUI(int w, int h, SpiralPlugin *o, ChannelHandler *ch, const HostInfo *Info) :
  55. SpiralPluginGUI(w,h,o,ch),
  56. m_Bypass(false)
  57. {
  58. m_Scope = new ScopeWidget(5, 20, 210, 85, "Scope", Info->BUFSIZE);
  59. m_Scope->color (Info->SCOPE_BG_COLOUR);
  60. m_Scope->SetWaveColour (Info->SCOPE_FG_COLOUR);
  61. m_Attenuation = new Fl_Knob (220, 10, 40, 40, "Attenuation");
  62. m_Attenuation->color(Info->GUI_COLOUR);
  63. m_Attenuation->type(Fl_Knob::LINELIN);
  64. m_Attenuation->labelsize (9);
  65. m_Attenuation->maximum (1);
  66. m_Attenuation->step (.001);
  67. m_Attenuation->value (0);
  68. m_Attenuation->callback ((Fl_Callback*)cb_Attenuation);
  69. m_TimeBase = new Fl_Knob (220, 60, 40, 40, "Time Base");
  70. m_TimeBase->color(Info->GUI_COLOUR);
  71. m_TimeBase->type(Fl_Knob::LINELIN);
  72. m_TimeBase->labelsize (9);
  73. m_TimeBase->minimum (0.001);
  74. //m_TimeBase->maximum (5); // It'd be better if we could do this, but it makes the display look crummy
  75. m_TimeBase->maximum (1);
  76. m_TimeBase->step (.001);
  77. m_TimeBase->value (1);
  78. m_TimeBase->callback ((Fl_Callback*)cb_TimeBase);
  79. /*Bypass = new Fl_Button(175, 107, 40, 16, "Bypass");
  80. Bypass->labelsize(10);
  81. Bypass->type(1);
  82. Bypass->callback((Fl_Callback*)cb_Bypass);*/
  83. end();
  84. }
  85. void ScopePluginGUI::Display(const float *data)
  86. {
  87. //m_Scope->m_Data=data;
  88. if (!m_Bypass) m_Scope->redraw();
  89. }
  90. void ScopePluginGUI::Update()
  91. {
  92. redraw();
  93. }
  94. void ScopePluginGUI::draw()
  95. {
  96. SpiralGUIType::draw();
  97. const float *data;
  98. //cerr<<"getting and drawing..."<<endl;
  99. m_GUICH->GetData("AudioData",(void*)m_Scope->m_Data);
  100. Display(data);
  101. }
  102. void ScopePluginGUI::UpdateValues(SpiralPlugin* o)
  103. {
  104. }
  105. inline void ScopePluginGUI::cb_Attenuation_i (Fl_Knob* o, void* v)
  106. {
  107. m_Scope->SetAttenuation (1.0-(o->value()));
  108. }
  109. void ScopePluginGUI::cb_Attenuation (Fl_Knob* o, void* v) {
  110. ((ScopePluginGUI*)(o->parent()))->cb_Attenuation_i (o, v);
  111. }
  112. inline void ScopePluginGUI::cb_TimeBase_i (Fl_Knob* o, void* v)
  113. {
  114. m_Scope->SetTimeBase (o->value());
  115. }
  116. void ScopePluginGUI::cb_TimeBase (Fl_Knob* o, void* v) {
  117. ((ScopePluginGUI*)(o->parent()))->cb_TimeBase_i (o, v);
  118. }
  119. //void ScopePluginGUI::cb_Bypass_i(Fl_Button* o, void* v)
  120. //{m_Bypass=o->value();}
  121. //void ScopePluginGUI::cb_Bypass(Fl_Button* o, void* v)
  122. //{((ScopePluginGUI*)(o->parent()))->cb_Bypass_i(o,v);}
  123. const string ScopePluginGUI::GetHelpText(const string &loc){
  124. return string("")
  125. + "The Scope lets you see a visual representation of the\n"
  126. + "data flowing through it. It does nothing to the signal,\n"
  127. + "but its very useful for checking the layouts, looking at\n"
  128. + "CV value etc.\n";
  129. }