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.

137 lines
4.8KB

  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, 45, 20);
  33. m_Buttons->type (FL_HORIZONTAL);
  34. add (m_Buttons);
  35. m_Delete = new Fl_Button (2, 0, 20, 20, "-");
  36. m_Delete->box (FL_PLASTIC_UP_BOX);
  37. m_Delete->color (Info->GUI_COLOUR);
  38. m_Delete->selection_color (Info->GUI_COLOUR);
  39. m_Delete->callback ((Fl_Callback*)cb_Delete);
  40. m_Buttons->add (m_Delete);
  41. m_Add = new Fl_Button (24, 0, 20, 20, "+");
  42. m_Add->box (FL_PLASTIC_UP_BOX);
  43. m_Add->color (Info->GUI_COLOUR);
  44. m_Add->selection_color (Info->GUI_COLOUR);
  45. m_Add->callback ((Fl_Callback*)cb_Add);
  46. m_Buttons->add (m_Add);
  47. }
  48. void MixerPluginGUI::AddChan (bool SendData, bool ResizeIt) {
  49. Fl_Slider *NewSlide = new Fl_Slider (0, 0, 20, 100, "");
  50. NewSlide->type (FL_VERT_NICE_SLIDER);
  51. NewSlide->selection_color (m_GUIColour);
  52. NewSlide->box (FL_PLASTIC_DOWN_BOX);
  53. NewSlide->labelsize (10);
  54. NewSlide->maximum (2);
  55. NewSlide->step (0.01);
  56. NewSlide->value (1.0);
  57. int num = (int)m_SlidVec.size();
  58. NewSlide->callback ((Fl_Callback*)cb_Chan, (void*)&Numbers[num]);
  59. m_MainPack->add (NewSlide);
  60. m_SlidVec.push_back (NewSlide);
  61. if (ResizeIt) resize (x(), y(), w()+20, h());
  62. if (SendData) {
  63. if (ResizeIt) redraw ();
  64. m_GUICH->Set ("Num", ++num);
  65. m_GUICH->SetCommand (MixerPlugin::SETNUM);
  66. m_GUICH->Wait ();
  67. m_GUICH->Set ("Num", num);
  68. m_GUICH->Set ("Value", (float)(2.0f - NewSlide->value ()));
  69. m_GUICH->SetCommand(MixerPlugin::SETCH);
  70. }
  71. }
  72. void MixerPluginGUI::DeleteChan (bool SendData, bool DrawIt) {
  73. vector<Fl_Slider*>::iterator i = m_SlidVec.end ();
  74. i--;
  75. m_MainPack->remove (*i);
  76. delete *i;
  77. m_SlidVec.erase (i);
  78. if (SendData) {
  79. m_GUICH->Set ("Num", (int)m_SlidVec.size());
  80. m_GUICH->SetCommand (MixerPlugin::SETNUM);
  81. }
  82. resize (x(), y(), w()-20, h());
  83. if (DrawIt) redraw();
  84. }
  85. void MixerPluginGUI::UpdateValues(SpiralPlugin *o) {
  86. MixerPlugin *Plugin = (MixerPlugin *)o;
  87. unsigned int chans = Plugin->GetChannels();
  88. while (chans < m_SlidVec.size()) DeleteChan (false, false);
  89. while (chans > m_SlidVec.size()) AddChan (false, true);
  90. for (unsigned int n=0; n<chans; n++)
  91. m_SlidVec[n]->value (2.0f - Plugin->GetChannel (n));
  92. redraw();
  93. }
  94. inline void MixerPluginGUI::cb_Add_i(Fl_Button* o, void* v) {
  95. if ((int)m_SlidVec.size() < MAX_CHANNELS) AddChan (true, true);
  96. }
  97. void MixerPluginGUI::cb_Add(Fl_Button* o, void* v) {
  98. ((MixerPluginGUI*)(o->parent()->parent()))->cb_Add_i(o,v);
  99. }
  100. inline void MixerPluginGUI::cb_Delete_i(Fl_Button* o, void* v) {
  101. if (m_SlidVec.size() > 2) DeleteChan ();
  102. }
  103. void MixerPluginGUI::cb_Delete(Fl_Button* o, void* v) {
  104. ((MixerPluginGUI*)(o->parent()->parent()))->cb_Delete_i(o,v);
  105. }
  106. inline void MixerPluginGUI::cb_Chan_i(Fl_Slider* o, void* v) {
  107. m_GUICH->Set("Num", (*(int*)(v)));
  108. m_GUICH->Set("Value", (float)(2.0f-o->value()));
  109. m_GUICH->SetCommand (MixerPlugin::SETCH);
  110. }
  111. void MixerPluginGUI::cb_Chan(Fl_Slider* o, void* v) {
  112. ((MixerPluginGUI*)(o->parent()->parent()))->cb_Chan_i(o,v);
  113. }
  114. const string MixerPluginGUI::GetHelpText(const string &loc){
  115. return string("")
  116. + "A general purpose mixer, not much else to say really.\n"
  117. + "Useful for mixing CV values as well as mono audio\n"
  118. + "signals.\n"
  119. + "Add up to 16 channels using the '+' button.\n"
  120. + "Use the '-' button to remove unwanted channels.\n";
  121. }