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.

167 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) {
  77. resize (x(), y(), w()+20, h());
  78. }
  79. }
  80. void MixerPluginGUI::DeleteChan (bool SendData) {
  81. vector<Fl_Slider*>::iterator i = m_SlidVec.end ();
  82. i--;
  83. m_MainPack->remove (*i);
  84. delete *i;
  85. m_SlidVec.erase (i);
  86. int num = (int)m_SlidVec.size();
  87. if (SendData) {
  88. m_GUICH->Set ("Num", num);
  89. m_GUICH->SetCommand (MixerPlugin::SETNUM);
  90. m_GUICH->Wait ();
  91. }
  92. if (num > 2) {
  93. resize (x(), y(), w()-20, h());
  94. }
  95. }
  96. void MixerPluginGUI::UpdateValues(SpiralPlugin *o) {
  97. MixerPlugin *Plugin = (MixerPlugin *)o;
  98. unsigned int chans = Plugin->GetChannels();
  99. while (chans < m_SlidVec.size()) DeleteChan (false);
  100. while (chans > m_SlidVec.size()) AddChan (false, true);
  101. for (unsigned int n=0; n<chans; n++)
  102. m_SlidVec[n]->value (2.0f - Plugin->GetChannel (n));
  103. redraw();
  104. }
  105. void MixerPluginGUI::Update () {
  106. if (m_GUICH->GetBool ("Peak")) m_PeakInd->value (true);
  107. }
  108. inline void MixerPluginGUI::cb_Add_i (Fl_Button* o, void* v) {
  109. m_PeakInd->value (false);
  110. if ((int)m_SlidVec.size() < MAX_CHANNELS) AddChan (true, true);
  111. }
  112. void MixerPluginGUI::cb_Add (Fl_Button* o, void* v) {
  113. ((MixerPluginGUI*)(o->user_data()))->cb_Add_i (o, v);
  114. }
  115. inline void MixerPluginGUI::cb_Delete_i (Fl_Button* o, void* v) {
  116. m_PeakInd->value (false);
  117. if (m_SlidVec.size() > 2) DeleteChan ();
  118. }
  119. void MixerPluginGUI::cb_Delete (Fl_Button* o, void* v) {
  120. ((MixerPluginGUI*)(o->user_data()))->cb_Delete_i (o, v);
  121. }
  122. inline void MixerPluginGUI::cb_Chan_i (Fl_Slider* o, void* v) {
  123. // This line works fine
  124. // cerr << *(int*)(v) << endl << (float)(2.0f-o->value()) << endl;
  125. // The segfault comes when you do any of the following - don't know why
  126. m_PeakInd->value (false);
  127. m_GUICH->Set("Num", (*(int*)(v)));
  128. m_GUICH->Set("Value", (float)(2.0f-o->value()));
  129. m_GUICH->SetCommand (MixerPlugin::SETCH);
  130. }
  131. void MixerPluginGUI::cb_Chan(Fl_Slider* o, void* v) {
  132. // If you use user_data() instead of parent()->parent() you get a segfault - don't know why
  133. ((MixerPluginGUI*)(o->parent()->parent()))->cb_Chan_i (o, v);
  134. }
  135. // you sometimes get a segfault on exit too - again - don't know why
  136. const string MixerPluginGUI::GetHelpText (const string &loc){
  137. return string("")
  138. + "A general purpose mixer.\n"
  139. + "Useful for mixing CV values as well as mono audio\n"
  140. + "signals.\n"
  141. + "The LED indicates the the mixer output is at peak\n"
  142. + "level, click on it, or change levels to reset it.\n"
  143. + "Add up to 16 channels using the '+' button.\n"
  144. + "Use the '-' button to remove unwanted channels.\n";
  145. }