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.

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