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.

185 lines
5.5KB

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