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.

198 lines
5.9KB

  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[65];
  22. MeterPluginGUI::~MeterPluginGUI () {
  23. delete m_Data;
  24. }
  25. MeterPluginGUI::MeterPluginGUI (int w, int h, MeterPlugin *o, ChannelHandler *ch, const HostInfo *Info) :
  26. SpiralPluginGUI (w, h, o, ch),
  27. m_Bypass (false)
  28. {
  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 (Info->GUI_COLOUR);
  37. Bypass->selection_color (Info->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 (Info->GUI_COLOUR);
  44. VUMode->selection_color (Info->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 (Info->GUI_COLOUR);
  53. MMMode->selection_color (Info->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 (Info->SCOPE_FG_COLOUR);
  61. Digits[display]->color2 (Info->SCOPE_BG_COLOUR);
  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 (Info->GUI_COLOUR);
  73. Reset->selection_color (Info->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 (Info->SCOPE_BG_COLOUR);
  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. float datum = 0.0;
  91. m_GUICH->GetData ("AudioData", m_Data);
  92. // The min and max values are based on the whole buffer
  93. for (int c=0; c<m_BufSize; c++) {
  94. datum = m_Data[c];
  95. if (VUMode->value ()) datum = fabs (datum);
  96. if (datum < m_Min) m_Min = datum;
  97. if (datum > m_Max) m_Max = datum;
  98. }
  99. SetMinMax (m_Min, m_Max);
  100. // The meter displays the last datum we touched (it's a quick average)
  101. Meter->value (datum);
  102. Meter->redraw();
  103. // Yeuck - have I REALLY used stdio for that - this is supposed to be C++
  104. //snprintf (label_buf, 64, "%1.5f", *m_Data);
  105. char* c = label_buf;
  106. for (int display=0; display<8; display++) {
  107. Digits[display] -> dp (off);
  108. if (*c == 0) Digits[display] -> value (0);
  109. else {
  110. if (*c == '.') {
  111. Digits[display] -> dp (point);
  112. c++;
  113. }
  114. int val;
  115. if (*c == '-') val = -1; else val = (int)*c - (int)'0';
  116. Digits[display] -> value (val);
  117. c++;
  118. }
  119. }
  120. }
  121. }
  122. void MeterPluginGUI::Update () {
  123. redraw();
  124. }
  125. void MeterPluginGUI::UpdateValues (SpiralPlugin* o) {
  126. MeterPlugin* Plugin = (MeterPlugin*)o;
  127. VUMode->value (Plugin->GetVUMode ());
  128. MMMode->value (! Plugin->GetVUMode ());
  129. }
  130. void MeterPluginGUI::SetMinMax (float NewMin, float NewMax) {
  131. m_Min = NewMin;
  132. m_Max = NewMax;
  133. snprintf (label_buf, 64, "%1.5f", m_Min);
  134. MinBox->value (label_buf);
  135. snprintf (label_buf, 64, "%1.5f", m_Max);
  136. MaxBox->value (label_buf);
  137. if (MMMode->value ()) {
  138. Meter->minimum (m_Min);
  139. Meter->maximum (m_Max);
  140. }
  141. else {
  142. Meter->minimum (0.0);
  143. Meter->maximum (1.0);
  144. if (m_Max > 1.0) {
  145. MaxBox->color (FL_RED);
  146. }
  147. }
  148. }
  149. void MeterPluginGUI::cb_Bypass_i (Fl_Button* o, void* v) {
  150. m_Bypass = o->value();
  151. }
  152. void MeterPluginGUI::cb_Bypass (Fl_Button* o, void* v) {
  153. ((MeterPluginGUI*)(o->parent()))->cb_Bypass_i (o, v);
  154. }
  155. void MeterPluginGUI::DoReset (void) {
  156. MaxBox->color (MinBox->color());
  157. SetMinMax (10, -10); // Yes, I know that LOOKS the wrong way round, but it isn't!
  158. }
  159. void MeterPluginGUI::cb_Reset_i (Fl_Button* o, void* v) {
  160. DoReset ();
  161. }
  162. void MeterPluginGUI::cb_Reset (Fl_Button* o, void* v) {
  163. ((MeterPluginGUI*)(o->parent()))->cb_Reset_i (o, v);
  164. }
  165. void MeterPluginGUI::cb_Mode_i (Fl_Button* o, void* v) {
  166. DoReset ();
  167. if (o==VUMode) m_GUICH->SetCommand (MeterPlugin::SETVU);
  168. else m_GUICH->SetCommand (MeterPlugin::SETMM);
  169. Meter->vu_mode (o==VUMode);
  170. }
  171. void MeterPluginGUI::cb_Mode (Fl_Button* o, void* v) {
  172. ((MeterPluginGUI*)(o->parent()))->cb_Mode_i (o, v);
  173. }
  174. const string MeterPluginGUI::GetHelpText (const string &loc) {
  175. return string ("")
  176. + "The Meter lets you see a numeric representation of the\n"
  177. + "data flowing through it. It does nothing to the signal,\n"
  178. + "but its very useful for checking the layouts, looking at\n"
  179. + "CV value etc.\n";
  180. }