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.

148 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. using namespace std;
  22. ScopeWidget::ScopeWidget (int x, int y, int w, int h, const char *l, int BUFSIZE) :
  23. Fl_Widget (x, y, w, h, l),
  24. m_Data (NULL),
  25. //m_Channels (1),
  26. m_WaveColour (FL_WHITE),
  27. m_Attenuation (1.0),
  28. m_TimeBase (1.0),
  29. m_Bufsize (BUFSIZE)
  30. {
  31. m_Data = new float[BUFSIZE];
  32. }
  33. ScopeWidget::~ScopeWidget()
  34. {
  35. delete[] m_Data;
  36. }
  37. void ScopeWidget::draw() {
  38. int ho=h()/2;
  39. fl_color (color());
  40. fl_rectf (x(), y(), w(), h());
  41. if (!m_Data) return;
  42. fl_push_clip (x(), y(), w(), h());
  43. float Value=0, NextValue=0;
  44. fl_color (m_WaveColour);
  45. for (int n=0; /*n<m_Bufsize-1 &&*/ n<w(); n++) {
  46. int p = int ((float)n*m_TimeBase);
  47. if (p>=m_Bufsize) break;
  48. Value = NextValue;
  49. NextValue = m_Data[p] * m_Attenuation * ho;
  50. fl_line ((int)(x()+n-2), (int)(y()+ho-Value), (int)(x()+n-1), (int)(y()+ho-NextValue));
  51. }
  52. fl_pop_clip();
  53. }
  54. ////////////////////////////////////////////
  55. ScopePluginGUI::ScopePluginGUI(int w, int h, SpiralPlugin *o, ChannelHandler *ch, const HostInfo *Info) :
  56. SpiralPluginGUI(w,h,o,ch),
  57. m_Bypass(false)
  58. {
  59. m_Scope = new ScopeWidget(5, 20, 210, 85, "Scope", Info->BUFSIZE);
  60. m_Scope->color (Info->SCOPE_BG_COLOUR);
  61. m_Scope->SetWaveColour (Info->SCOPE_FG_COLOUR);
  62. m_Attenuation = new Fl_Knob (220, 10, 40, 40, "Attenuation");
  63. m_Attenuation->color(Info->GUI_COLOUR);
  64. m_Attenuation->type(Fl_Knob::LINELIN);
  65. m_Attenuation->labelsize (9);
  66. m_Attenuation->maximum (1);
  67. m_Attenuation->step (.001);
  68. m_Attenuation->value (0);
  69. m_Attenuation->callback ((Fl_Callback*)cb_Attenuation);
  70. m_TimeBase = new Fl_Knob (220, 60, 40, 40, "Time Base");
  71. m_TimeBase->color(Info->GUI_COLOUR);
  72. m_TimeBase->type(Fl_Knob::LINELIN);
  73. m_TimeBase->labelsize (9);
  74. m_TimeBase->minimum (0.001);
  75. //m_TimeBase->maximum (5); // It'd be better if we could do this, but it makes the display look crummy
  76. m_TimeBase->maximum (1);
  77. m_TimeBase->step (.001);
  78. m_TimeBase->value (1);
  79. m_TimeBase->callback ((Fl_Callback*)cb_TimeBase);
  80. /*Bypass = new Fl_Button(175, 107, 40, 16, "Bypass");
  81. Bypass->labelsize(10);
  82. Bypass->type(1);
  83. Bypass->callback((Fl_Callback*)cb_Bypass);*/
  84. end();
  85. }
  86. void ScopePluginGUI::Display(const float *data)
  87. {
  88. //m_Scope->m_Data=data;
  89. if (!m_Bypass) m_Scope->redraw();
  90. }
  91. void ScopePluginGUI::Update()
  92. {
  93. redraw();
  94. }
  95. void ScopePluginGUI::draw()
  96. {
  97. SpiralGUIType::draw();
  98. const float *data;
  99. //cerr<<"getting and drawing..."<<endl;
  100. m_GUICH->GetData("AudioData",(void*)m_Scope->m_Data);
  101. Display(data);
  102. }
  103. void ScopePluginGUI::UpdateValues(SpiralPlugin* o)
  104. {
  105. }
  106. inline void ScopePluginGUI::cb_Attenuation_i (Fl_Knob* o, void* v)
  107. {
  108. m_Scope->SetAttenuation (1.0-(o->value()));
  109. }
  110. void ScopePluginGUI::cb_Attenuation (Fl_Knob* o, void* v) {
  111. ((ScopePluginGUI*)(o->parent()))->cb_Attenuation_i (o, v);
  112. }
  113. inline void ScopePluginGUI::cb_TimeBase_i (Fl_Knob* o, void* v)
  114. {
  115. m_Scope->SetTimeBase (o->value());
  116. }
  117. void ScopePluginGUI::cb_TimeBase (Fl_Knob* o, void* v) {
  118. ((ScopePluginGUI*)(o->parent()))->cb_TimeBase_i (o, v);
  119. }
  120. //void ScopePluginGUI::cb_Bypass_i(Fl_Button* o, void* v)
  121. //{m_Bypass=o->value();}
  122. //void ScopePluginGUI::cb_Bypass(Fl_Button* o, void* v)
  123. //{((ScopePluginGUI*)(o->parent()))->cb_Bypass_i(o,v);}
  124. const string ScopePluginGUI::GetHelpText(const string &loc){
  125. return string("")
  126. + "The Scope lets you see a visual representation of the\n"
  127. + "data flowing through it. It does nothing to the signal,\n"
  128. + "but its very useful for checking the layouts, looking at\n"
  129. + "CV value etc.\n";
  130. }