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.

177 lines
6.0KB

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