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.

245 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 <stdio.h>
  19. #include "ControllerPluginGUI.h"
  20. #include <FL/fl_draw.h>
  21. #include <FL/fl_draw.H>
  22. static const int GUI_COLOUR = 179;
  23. static const int GUIBG_COLOUR = 144;
  24. static const int GUIBG2_COLOUR = 145;
  25. ////////////////////////////////////////////
  26. ControllerPluginGUI::CVGUI::CVGUI(int n, ControllerPluginGUI *p)
  27. {
  28. m_SliderGroup = new Fl_Group(0,0,60,153,"");
  29. m_SliderGroup->box(FL_UP_BOX);
  30. m_SliderGroup->user_data((void *)p);
  31. m_Title = new Fl_Input(5,2,50,15,"");
  32. m_Title->value("Name");
  33. m_Title->textsize(10);
  34. m_SliderGroup->add(m_Title);
  35. m_Max = new Fl_Int_Input(5,18,50,15,"");
  36. char t[64];
  37. sprintf(t,"%d",1);
  38. m_Max->value(t);
  39. m_Max->textsize(10);
  40. m_SliderGroup->add(m_Max);
  41. m_Chan = new Fl_Slider(20, 34, 20, 100, "");
  42. m_Chan->type(4);
  43. m_Chan->selection_color(GUI_COLOUR);
  44. m_Chan->maximum(1);
  45. m_Chan->step(0.01);
  46. m_Chan->value(0.5);
  47. m_Chan->callback((Fl_Callback*)ControllerPluginGUI::cb_Chan,
  48. (void*)&Numbers[n]);
  49. m_SliderGroup->add(m_Chan);
  50. m_Min = new Fl_Int_Input(5,136,50,15,"");
  51. char t2[64];
  52. sprintf(t2,"%d",-1);
  53. m_Min->value(t2);
  54. m_Min->textsize(10);
  55. m_SliderGroup->add(m_Min);
  56. }
  57. ////////////////////////////////////////////
  58. ControllerPluginGUI::ControllerPluginGUI(int w, int h,ControllerPlugin *o,const HostInfo *Info) :
  59. SpiralPluginGUI(w,h,o),
  60. m_CVCount(0)
  61. {
  62. m_Plugin=o;
  63. for (int n=0; n<MAX_CHANNELS; n++)
  64. {
  65. Numbers[n]=n;
  66. }
  67. m_MainPack = new Fl_Pack(0,20,w,h-44);
  68. m_MainPack->type(FL_HORIZONTAL);
  69. // start with four...
  70. AddCV();
  71. AddCV();
  72. AddCV();
  73. AddCV();
  74. m_Delete = new Fl_Button(2,h-22,20,20,"-");
  75. m_Delete->user_data(this);
  76. m_Delete->callback((Fl_Callback*)cb_Delete);
  77. add(m_Delete);
  78. m_Add = new Fl_Button(24,h-22,20,20,"+");
  79. m_Add->user_data(this);
  80. m_Add->callback((Fl_Callback*)cb_Add);
  81. add(m_Add);
  82. }
  83. void ControllerPluginGUI::AddCV()
  84. {
  85. CVGUI *NewCV = new CVGUI(m_CVCount,this);
  86. m_GuiVec.push_back(NewCV);
  87. m_MainPack->add(NewCV->m_SliderGroup);
  88. m_CVCount++;
  89. }
  90. void ControllerPluginGUI::DeleteCV()
  91. {
  92. vector<CVGUI*>::iterator i=m_GuiVec.end();
  93. i--;
  94. m_MainPack->remove((*i)->m_SliderGroup);
  95. delete *i;
  96. m_GuiVec.erase(i);
  97. m_CVCount--;
  98. }
  99. void ControllerPluginGUI::Clear()
  100. {
  101. for (vector<ControllerPluginGUI::CVGUI*>::iterator i=m_GuiVec.begin();
  102. i!=m_GuiVec.end(); i++)
  103. {
  104. m_MainPack->remove((*i)->m_SliderGroup);
  105. delete *i;
  106. }
  107. m_GuiVec.clear();
  108. m_CVCount=0;
  109. }
  110. void ControllerPluginGUI::UpdateValues()
  111. {
  112. }
  113. inline void ControllerPluginGUI::cb_Chan_i(Fl_Slider* o, void* v)
  114. {
  115. int num=*(int*)(v);
  116. // swap em over, cos it's the easiqest way to reverse
  117. // the fltk slider, which is upside down imho
  118. long max=strtol(m_GuiVec[num]->m_Min->value(),NULL,10);
  119. long min=strtol(m_GuiVec[num]->m_Max->value(),NULL,10);
  120. float val=o->value()*(max-min)+min;
  121. m_Plugin->SetChannel(num,val);
  122. }
  123. void ControllerPluginGUI::cb_Chan(Fl_Slider* o, void* v)
  124. { ((ControllerPluginGUI*)(o->parent()->user_data()))->cb_Chan_i(o,v);}
  125. inline void ControllerPluginGUI::cb_Add_i(Fl_Button* o, void* v)
  126. {
  127. if (m_CVCount<MAX_CHANNELS)
  128. {
  129. AddCV();
  130. resize(x(),y(),w()+60,h());
  131. redraw();
  132. m_Plugin->SetNum(m_GuiVec.size());
  133. }
  134. }
  135. void ControllerPluginGUI::cb_Add(Fl_Button* o, void* v)
  136. { ((ControllerPluginGUI*)(o->parent()))->cb_Add_i(o,v);}
  137. inline void ControllerPluginGUI::cb_Delete_i(Fl_Button* o, void* v)
  138. {
  139. if (m_GuiVec.size()>1)
  140. {
  141. DeleteCV();
  142. resize(x(),y(),w()-60,h());
  143. redraw();
  144. m_Plugin->SetNum(m_GuiVec.size());
  145. }
  146. }
  147. void ControllerPluginGUI::cb_Delete(Fl_Button* o, void* v)
  148. { ((ControllerPluginGUI*)(o->parent()))->cb_Delete_i(o,v);}
  149. // call for version <3
  150. istream &operator>>(istream &s, ControllerPluginGUI &o)
  151. {
  152. int c;
  153. string Title,Min,Max;
  154. float Val;
  155. o.Clear();
  156. s>>c;
  157. for (int n=0; n<c; n++)
  158. {
  159. s>>Title>>Min>>Max>>Val;
  160. o.AddCV();
  161. o.m_GuiVec[n]->m_Title->value(Title.c_str());
  162. o.m_GuiVec[n]->m_Min->value(Min.c_str());
  163. o.m_GuiVec[n]->m_Max->value(Max.c_str());
  164. o.m_GuiVec[n]->m_Chan->value(Val);
  165. }
  166. o.resize(o.x(),o.y(),c*60,o.h());
  167. return s;
  168. }
  169. // call for version >=3
  170. // another version of the stream to fix the old style string streaming problem
  171. void ControllerPluginGUI::StreamIn(istream &s)
  172. {
  173. int c,version,size;
  174. string Title,Min,Max;
  175. float Val;
  176. char Buf[4096];
  177. Clear();
  178. s>>version;
  179. s>>c;
  180. for (int n=0; n<c; n++)
  181. {
  182. AddCV();
  183. s>>size;
  184. s.ignore(1);
  185. s.get(Buf,size+1);
  186. m_GuiVec[n]->m_Title->value(Buf);
  187. s>>Min>>Max>>Val;
  188. m_GuiVec[n]->m_Min->value(Min.c_str());
  189. m_GuiVec[n]->m_Max->value(Max.c_str());
  190. m_GuiVec[n]->m_Chan->value(Val);
  191. }
  192. resize(x(),y(),c*60,h());
  193. }
  194. void ControllerPluginGUI::StreamOut(ostream &s)
  195. {
  196. // version
  197. s<<1<<endl;
  198. s<<m_GuiVec.size()<<endl;
  199. for (vector<ControllerPluginGUI::CVGUI*>::iterator i=m_GuiVec.begin();
  200. i!=m_GuiVec.end(); i++)
  201. {
  202. s<<strlen((*i)->m_Title->value())<<endl;
  203. s<<(*i)->m_Title->value()<<" ";
  204. s<<(*i)->m_Min->value()<<" ";
  205. s<<(*i)->m_Max->value()<<" ";
  206. s<<(*i)->m_Chan->value()<<endl;
  207. }
  208. }