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.

163 lines
5.7KB

  1. /* SpiralPlugin
  2. * Copyleft (C) 2000 David Griffiths <dave@pawfal.org>
  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 "MixerPluginGUI.h"
  19. #include <FL/fl_draw.h>
  20. #include <FL/fl_draw.H>
  21. using namespace std;
  22. ////////////////////////////////////////////
  23. MixerPluginGUI::MixerPluginGUI (int w, int h, MixerPlugin *o, ChannelHandler *ch, const HostInfo *Info) :
  24. SpiralPluginGUI (w, h, o, ch)
  25. {
  26. m_GUIColour = (Fl_Color)Info->GUI_COLOUR;
  27. for (int n=0; n<MAX_CHANNELS; n++) Numbers[n]=n;
  28. m_MainPack = new Fl_Pack (0, 15, w, 100);
  29. m_MainPack->type (FL_HORIZONTAL);
  30. add (m_MainPack);
  31. // start with four...
  32. AddChan(); AddChan(); AddChan(); AddChan();
  33. m_Buttons = new Fl_Pack (0, 118, 62, 20);
  34. m_Buttons->type (FL_HORIZONTAL);
  35. add (m_Buttons);
  36. m_Delete = new Fl_Button (2, 0, 20, 20, "-");
  37. m_Delete->user_data ((void*)(this));
  38. m_Delete->box (FL_PLASTIC_UP_BOX);
  39. m_Delete->color (Info->GUI_COLOUR);
  40. m_Delete->selection_color (Info->GUI_COLOUR);
  41. m_Delete->callback ((Fl_Callback*)cb_Delete);
  42. m_Buttons->add (m_Delete);
  43. m_Add = new Fl_Button (22, 0, 20, 20, "+");
  44. m_Add->user_data ((void*)(this));
  45. m_Add->box (FL_PLASTIC_UP_BOX);
  46. m_Add->color (Info->GUI_COLOUR);
  47. m_Add->selection_color (Info->GUI_COLOUR);
  48. m_Add->callback ((Fl_Callback*)cb_Add);
  49. m_Buttons->add (m_Add);
  50. m_PeakInd = new Fl_LED_Button (42, 0, 20, 20, "");
  51. m_Buttons->add (m_PeakInd);
  52. }
  53. void MixerPluginGUI::AddChan (bool SendData, bool ResizeIt) {
  54. Fl_Slider *NewSlide = new Fl_Slider (0, 0, 20, 100, "");
  55. NewSlide->user_data ((void*)(this));
  56. NewSlide->type (FL_VERT_NICE_SLIDER);
  57. NewSlide->selection_color (m_GUIColour);
  58. NewSlide->box (FL_PLASTIC_DOWN_BOX);
  59. NewSlide->labelsize (10);
  60. NewSlide->maximum (2);
  61. NewSlide->step (0.01);
  62. NewSlide->value (1.0);
  63. int num = (int)m_SlidVec.size();
  64. NewSlide->callback ((Fl_Callback*)cb_Chan, (void*)&Numbers[num]);
  65. m_MainPack->add (NewSlide);
  66. m_SlidVec.push_back (NewSlide);
  67. if (SendData) {
  68. m_GUICH->Set ("Num", ++num);
  69. m_GUICH->SetCommand (MixerPlugin::SETNUM);
  70. m_GUICH->Wait ();
  71. m_GUICH->Set ("Num", num);
  72. m_GUICH->Set ("Value", (float)(2.0f - NewSlide->value ()));
  73. m_GUICH->SetCommand(MixerPlugin::SETCH);
  74. m_GUICH->Wait ();
  75. }
  76. if (ResizeIt && num > 3) Resize (w()+20, h());
  77. }
  78. void MixerPluginGUI::DeleteChan (bool SendData) {
  79. vector<Fl_Slider*>::iterator i = m_SlidVec.end ();
  80. i--;
  81. m_MainPack->remove (*i);
  82. delete *i;
  83. m_SlidVec.erase (i);
  84. int num = (int)m_SlidVec.size();
  85. if (SendData) {
  86. m_GUICH->Set ("Num", num);
  87. m_GUICH->SetCommand (MixerPlugin::SETNUM);
  88. m_GUICH->Wait ();
  89. }
  90. if (num > 2) Resize (w()-20, h());
  91. }
  92. void MixerPluginGUI::UpdateValues(SpiralPlugin *o) {
  93. MixerPlugin *Plugin = (MixerPlugin *)o;
  94. unsigned int chans = Plugin->GetChannels();
  95. while (chans < m_SlidVec.size()) DeleteChan (false);
  96. while (chans > m_SlidVec.size()) AddChan (false, true);
  97. for (unsigned int n=0; n<chans; n++)
  98. m_SlidVec[n]->value (2.0f - Plugin->GetChannel (n));
  99. redraw();
  100. }
  101. void MixerPluginGUI::Update () {
  102. if (m_GUICH->GetBool ("Peak")) m_PeakInd->value (true);
  103. }
  104. inline void MixerPluginGUI::cb_Add_i (Fl_Button* o, void* v) {
  105. m_PeakInd->value (false);
  106. if ((int)m_SlidVec.size() < MAX_CHANNELS) AddChan (true, true);
  107. }
  108. void MixerPluginGUI::cb_Add (Fl_Button* o, void* v) {
  109. ((MixerPluginGUI*)(o->user_data()))->cb_Add_i (o, v);
  110. }
  111. inline void MixerPluginGUI::cb_Delete_i (Fl_Button* o, void* v) {
  112. m_PeakInd->value (false);
  113. if (m_SlidVec.size() > 2) DeleteChan ();
  114. }
  115. void MixerPluginGUI::cb_Delete (Fl_Button* o, void* v) {
  116. ((MixerPluginGUI*)(o->user_data()))->cb_Delete_i (o, v);
  117. }
  118. inline void MixerPluginGUI::cb_Chan_i (Fl_Slider* o, void* v) {
  119. // This line works fine
  120. // cerr << *(int*)(v) << endl << (float)(2.0f-o->value()) << endl;
  121. // The segfault comes when you do any of the following - don't know why
  122. m_PeakInd->value (false);
  123. m_GUICH->Set("Num", (*(int*)(v)));
  124. m_GUICH->Set("Value", (float)(2.0f-o->value()));
  125. m_GUICH->SetCommand (MixerPlugin::SETCH);
  126. }
  127. void MixerPluginGUI::cb_Chan(Fl_Slider* o, void* v) {
  128. // If you use user_data() instead of parent()->parent() you get a segfault - don't know why
  129. ((MixerPluginGUI*)(o->parent()->parent()))->cb_Chan_i (o, v);
  130. }
  131. // you sometimes get a segfault on exit too - again - don't know why
  132. const string MixerPluginGUI::GetHelpText (const string &loc){
  133. return string("")
  134. + "A general purpose mixer.\n"
  135. + "Useful for mixing CV values as well as mono audio\n"
  136. + "signals.\n"
  137. + "The LED indicates the the mixer output is at peak\n"
  138. + "level, click on it, or change levels to reset it.\n"
  139. + "Add up to 16 channels using the '+' button.\n"
  140. + "Use the '-' button to remove unwanted channels.\n";
  141. }