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.

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