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.

127 lines
3.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, const HostInfo *Info) :
  25. SpiralPluginGUI (w, h, o),
  26. m_Bypass(0) {
  27. m_Plugin=o;
  28. Bypass = new Fl_Button (175, 2, 40, 16, "Bypass");
  29. Bypass -> labelsize (10);
  30. Bypass -> type (1);
  31. Bypass -> callback ((Fl_Callback*)cb_Bypass);
  32. add (Bypass);
  33. for (int display=0; display<8; display++) {
  34. Digits[display] = new Fl_SevenSeg ((display*28)+2, 20, 28, 40);
  35. Digits[display] -> bar_width (4);
  36. Digits[display] -> color (FL_WHITE);
  37. Digits[display] -> color2 (GUI_COLOUR);
  38. add (Digits[display]);
  39. }
  40. MinBox = new Fl_Output (2, 84, 84, 20);
  41. MinBox -> box (FL_ENGRAVED_BOX);
  42. MinBox -> color (16);
  43. MinBox -> set_output();
  44. add (MinBox);
  45. Reset = new Fl_Button (88, 84, 54, 20, "Reset");
  46. Reset -> labelsize (10);
  47. Reset -> type (0);
  48. Reset -> callback ((Fl_Callback*)cb_Reset);
  49. add (Reset);
  50. MaxBox = new Fl_Output (144, 84, 84, 20);
  51. MaxBox->set_output();
  52. MaxBox->box (FL_ENGRAVED_BOX);
  53. MaxBox->color (16);
  54. add (MaxBox);
  55. Meter = new Fl_VU_Meter (2, 62, 226, 20);
  56. Meter->color (FL_BLACK);
  57. cb_Reset_i (Reset, NULL);
  58. add (Reset);
  59. end();
  60. }
  61. void MeterPluginGUI::Display (const float *data) {
  62. if (! m_Bypass) {
  63. snprintf (label_buf, 64, "%1.5f", *data);
  64. if (Meter->minimum() > *data) SetMin (*data);
  65. if (Meter->maximum() < *data) SetMax (*data);
  66. Meter->value (*data);
  67. Meter->redraw();
  68. char* c = label_buf;
  69. for (int display=0; display<8; display++) {
  70. Digits[display] -> dp (off);
  71. if (*c == 0) Digits[display] -> value (0);
  72. else {
  73. if (*c == '.') {
  74. Digits[display] -> dp (point);
  75. c++;
  76. }
  77. int val;
  78. if (*c == '-') val = -1; else val = (int)*c - (int)'0';
  79. Digits[display] -> value (val);
  80. c++;
  81. }
  82. }
  83. }
  84. }
  85. void MeterPluginGUI::draw() {
  86. SpiralGUIType::draw();
  87. if (m_Plugin->GetInput(0) != NULL) {
  88. Display (m_Plugin->GetInput(0)->GetBuffer());
  89. }
  90. }
  91. void MeterPluginGUI::UpdateValues() {
  92. }
  93. void MeterPluginGUI::SetMax (float NewValue) {
  94. Meter->maximum (NewValue);
  95. MaxBox->value (label_buf);
  96. }
  97. void MeterPluginGUI::SetMin (float NewValue) {
  98. Meter->minimum (NewValue);
  99. MinBox->value (label_buf);
  100. }
  101. void MeterPluginGUI::cb_Bypass_i (Fl_Button* o, void* v) {
  102. m_Bypass = o->value();
  103. }
  104. void MeterPluginGUI::cb_Bypass (Fl_Button* o, void* v) {
  105. ((MeterPluginGUI*)(o->parent()))->cb_Bypass_i (o,v);
  106. }
  107. void MeterPluginGUI::cb_Reset_i (Fl_Button* o, void* v) {
  108. SetMin (10); // Yes, I know that LOOKS the wrong way round, but it isn't!
  109. SetMax (-10);
  110. }
  111. void MeterPluginGUI::cb_Reset (Fl_Button* o, void* v) {
  112. ((MeterPluginGUI*)(o->parent()))->cb_Reset_i (o,v);
  113. }