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.

190 lines
5.8KB

  1. /* SpiralPlugin
  2. * Copyleft (C) 2002 Andy Preston <andy@clublinux.co.uk>
  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 "MeterPluginGUI.h"
  19. #include <stdio.h>
  20. char label_buf[10];
  21. MeterPluginGUI::MeterPluginGUI (int w, int h, MeterPlugin *o, ChannelHandler *ch, const HostInfo *Info) :
  22. SpiralPluginGUI (w, h, o, ch),
  23. m_Bypass (false)
  24. {
  25. // If I'm only going to use the first value from this, is it worth doing all this
  26. m_BufSize = Info->BUFSIZE;
  27. m_Data = new float[m_BufSize];
  28. // Create the widgets and stuff!
  29. Bypass = new Fl_Button (2, 18, 54, 20, "Bypass");
  30. Bypass->labelsize (10);
  31. Bypass->type (FL_TOGGLE_BUTTON);
  32. Bypass->box (FL_PLASTIC_UP_BOX);
  33. Bypass->color (Info->GUI_COLOUR);
  34. Bypass->selection_color (Info->GUI_COLOUR);
  35. Bypass->callback ((Fl_Callback*)cb_Bypass);
  36. add (Bypass);
  37. VUMode = new Fl_Button (118, 18, 54, 20, "VU");
  38. VUMode->type (FL_RADIO_BUTTON);
  39. VUMode->box (FL_PLASTIC_UP_BOX);
  40. VUMode->color (Info->GUI_COLOUR);
  41. VUMode->selection_color (Info->GUI_COLOUR);
  42. VUMode->labelsize (10);
  43. VUMode->callback ((Fl_Callback*)cb_Mode);
  44. VUMode->set();
  45. add (VUMode);
  46. MMMode = new Fl_Button (174, 18, 54, 20, "Min/Max");
  47. MMMode->type (FL_RADIO_BUTTON);
  48. MMMode->box (FL_PLASTIC_UP_BOX);
  49. MMMode->color (Info->GUI_COLOUR);
  50. MMMode->selection_color (Info->GUI_COLOUR);
  51. MMMode->labelsize (10);
  52. MMMode->callback ((Fl_Callback*)cb_Mode);
  53. add (MMMode);
  54. for (int display=0; display<8; display++) {
  55. Digits[display] = new Fl_SevenSeg ((display*28)+2, 40, 28, 40);
  56. Digits[display]->bar_width (4);
  57. Digits[display]->color (Info->SCOPE_FG_COLOUR);
  58. Digits[display]->color2 (Info->SCOPE_BG_COLOUR);
  59. add (Digits[display]);
  60. }
  61. MinBox = new Fl_Output (2, 104, 84, 20);
  62. MinBox->box (FL_PLASTIC_DOWN_BOX);
  63. MinBox->set_output();
  64. add (MinBox);
  65. Reset = new Fl_Button (88, 104, 54, 20, "Reset");
  66. Reset->labelsize (10);
  67. Reset->type (0);
  68. Reset->box (FL_PLASTIC_UP_BOX);
  69. Reset->color (Info->GUI_COLOUR);
  70. Reset->selection_color (Info->GUI_COLOUR);
  71. Reset->callback ((Fl_Callback*)cb_Reset);
  72. add (Reset);
  73. MaxBox = new Fl_Output (144, 104, 84, 20);
  74. MaxBox->set_output();
  75. MaxBox->box (FL_PLASTIC_DOWN_BOX);
  76. add (MaxBox);
  77. Meter = new Fl_VU_Meter (2, 82, 226, 20);
  78. Meter->color (Info->SCOPE_BG_COLOUR);
  79. Meter->vu_mode (true);
  80. cb_Reset_i (Reset, NULL);
  81. end ();
  82. DoReset ();
  83. }
  84. void MeterPluginGUI::draw() {
  85. SpiralGUIType::draw ();
  86. if (! m_Bypass) {
  87. m_GUICH->GetData ("AudioData", m_Data);
  88. // The min and max values are based on the whole buffer
  89. for (int c=0; c<m_BufSize; c++) {
  90. if (VUMode->value ()) m_Data[c] = fabs (m_Data[c]);
  91. if (m_Data[c] < m_Min) m_Min=m_Data[c];
  92. if (m_Data[c] > m_Max) m_Max=m_Data[c];
  93. }
  94. SetMinMax (m_Min, m_Max);
  95. // The meter displays the first datum in the buffer (it's a quick average)
  96. Meter->value (*m_Data);
  97. Meter->redraw();
  98. snprintf (label_buf, 64, "%1.5f", *m_Data);
  99. char* c = label_buf;
  100. for (int display=0; display<8; display++) {
  101. Digits[display] -> dp (off);
  102. if (*c == 0) Digits[display] -> value (0);
  103. else {
  104. if (*c == '.') {
  105. Digits[display] -> dp (point);
  106. c++;
  107. }
  108. int val;
  109. if (*c == '-') val = -1; else val = (int)*c - (int)'0';
  110. Digits[display] -> value (val);
  111. c++;
  112. }
  113. }
  114. }
  115. }
  116. void MeterPluginGUI::Update () {
  117. redraw();
  118. }
  119. void MeterPluginGUI::UpdateValues (SpiralPlugin* o) {
  120. MeterPlugin* Plugin = (MeterPlugin*)o;
  121. VUMode->value (Plugin->GetVUMode ());
  122. MMMode->value (! Plugin->GetVUMode ());
  123. }
  124. void MeterPluginGUI::SetMinMax (float NewMin, float NewMax) {
  125. m_Min = NewMin;
  126. m_Max = NewMax;
  127. snprintf (label_buf, 64, "%1.5f", m_Min);
  128. MinBox->value (label_buf);
  129. snprintf (label_buf, 64, "%1.5f", m_Max);
  130. MaxBox->value (label_buf);
  131. if (MMMode->value ()) {
  132. Meter->minimum (m_Min);
  133. Meter->maximum (m_Max);
  134. }
  135. else {
  136. Meter->minimum (0.0);
  137. Meter->maximum (1.0);
  138. if (m_Max > 1.0) {
  139. MaxBox->color (FL_RED);
  140. }
  141. }
  142. }
  143. void MeterPluginGUI::cb_Bypass_i (Fl_Button* o, void* v) {
  144. m_Bypass = o->value();
  145. }
  146. void MeterPluginGUI::cb_Bypass (Fl_Button* o, void* v) {
  147. ((MeterPluginGUI*)(o->parent()))->cb_Bypass_i (o, v);
  148. }
  149. void MeterPluginGUI::DoReset (void) {
  150. MaxBox->color (MinBox->color());
  151. SetMinMax (10, -10); // Yes, I know that LOOKS the wrong way round, but it isn't!
  152. }
  153. void MeterPluginGUI::cb_Reset_i (Fl_Button* o, void* v) {
  154. DoReset ();
  155. }
  156. void MeterPluginGUI::cb_Reset (Fl_Button* o, void* v) {
  157. ((MeterPluginGUI*)(o->parent()))->cb_Reset_i (o, v);
  158. }
  159. void MeterPluginGUI::cb_Mode_i (Fl_Button* o, void* v) {
  160. DoReset ();
  161. if (o==VUMode) m_GUICH->SetCommand (MeterPlugin::SETVU);
  162. else m_GUICH->SetCommand (MeterPlugin::SETMM);
  163. Meter->vu_mode (o==VUMode);
  164. }
  165. void MeterPluginGUI::cb_Mode (Fl_Button* o, void* v) {
  166. ((MeterPluginGUI*)(o->parent()))->cb_Mode_i (o, v);
  167. }
  168. const string MeterPluginGUI::GetHelpText (const string &loc) {
  169. return string ("")
  170. + "The Meter lets you see a numeric representation of the\n"
  171. + "data flowing through it. It does nothing to the signal,\n"
  172. + "but its very useful for checking the layouts, looking at\n"
  173. + "CV value etc.\n";
  174. }