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.

156 lines
4.9KB

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