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.

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