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.

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