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.

209 lines
6.2KB

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