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.

283 lines
7.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 <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,ChannelHandler *ch,const HostInfo *Info) :
  59. SpiralPluginGUI(w,h,o,ch),
  60. m_CVCount(0)
  61. {
  62. for (int n=0; n<MAX_CHANNELS; n++)
  63. {
  64. Numbers[n]=n;
  65. }
  66. m_MainPack = new Fl_Pack(0,20,w,h-44);
  67. m_MainPack->type(FL_HORIZONTAL);
  68. // start with four...
  69. AddCV();
  70. AddCV();
  71. AddCV();
  72. AddCV();
  73. m_Delete = new Fl_Button(2,h-22,20,20,"-");
  74. m_Delete->user_data(this);
  75. m_Delete->callback((Fl_Callback*)cb_Delete);
  76. add(m_Delete);
  77. m_Add = new Fl_Button(24,h-22,20,20,"+");
  78. m_Add->user_data(this);
  79. m_Add->callback((Fl_Callback*)cb_Add);
  80. add(m_Add);
  81. }
  82. void ControllerPluginGUI::AddCV()
  83. {
  84. CVGUI *NewCV = new CVGUI(m_CVCount,this);
  85. m_GuiVec.push_back(NewCV);
  86. m_MainPack->add(NewCV->m_SliderGroup);
  87. m_CVCount++;
  88. }
  89. void ControllerPluginGUI::DeleteCV()
  90. {
  91. vector<CVGUI*>::iterator i=m_GuiVec.end();
  92. i--;
  93. m_MainPack->remove((*i)->m_SliderGroup);
  94. delete *i;
  95. m_GuiVec.erase(i);
  96. m_CVCount--;
  97. }
  98. void ControllerPluginGUI::Clear()
  99. {
  100. for (vector<ControllerPluginGUI::CVGUI*>::iterator i=m_GuiVec.begin();
  101. i!=m_GuiVec.end(); i++)
  102. {
  103. m_MainPack->remove((*i)->m_SliderGroup);
  104. delete *i;
  105. }
  106. m_GuiVec.clear();
  107. m_CVCount=0;
  108. }
  109. void ControllerPluginGUI::UpdateValues(SpiralPlugin *o)
  110. {
  111. ControllerPlugin *Plugin = (ControllerPlugin *)o;
  112. int c;
  113. string Title,Min,Max;
  114. char temp[64];
  115. Clear();
  116. c=Plugin->GetNum();
  117. for (int n=0; n<c; n++)
  118. {
  119. AddCV();
  120. m_GuiVec[n]->m_Title->value(Plugin->GetName(n).c_str());
  121. sprintf(temp,"%f",Plugin->GetMin(n));
  122. m_GuiVec[n]->m_Min->value(temp);
  123. sprintf(temp,"%f",Plugin->GetMax(n));
  124. m_GuiVec[n]->m_Max->value(temp);
  125. m_GuiVec[n]->m_Chan->value(Plugin->GetVal(n));
  126. }
  127. resize(x(),y(),c*60,h());
  128. }
  129. inline void ControllerPluginGUI::cb_Chan_i(Fl_Slider* o, void* v)
  130. {
  131. int num=*(int*)(v);
  132. // swap em over, cos it's the easiqest way to reverse
  133. // the fltk slider, which is upside down imho
  134. long max=strtol(m_GuiVec[num]->m_Max->value(),NULL,10);
  135. long min=strtol(m_GuiVec[num]->m_Min->value(),NULL,10);
  136. float val=(1.0f-o->value())*(max-min)+min;
  137. m_GUICH->Set("Number",(int)num);
  138. m_GUICH->Set("Value",(float)val);
  139. m_GUICH->Set("Min",(float)min);
  140. m_GUICH->Set("Max",(float)max);
  141. char temp[256];
  142. sprintf(temp,"%s",m_GuiVec[num]->m_Title->value());
  143. m_GUICH->SetData("Name",(void*)temp);
  144. m_GUICH->SetCommand(ControllerPlugin::SETCHANNEL);
  145. }
  146. void ControllerPluginGUI::cb_Chan(Fl_Slider* o, void* v)
  147. { ((ControllerPluginGUI*)(o->parent()->user_data()))->cb_Chan_i(o,v);}
  148. inline void ControllerPluginGUI::cb_Add_i(Fl_Button* o, void* v)
  149. {
  150. if (m_CVCount<MAX_CHANNELS)
  151. {
  152. AddCV();
  153. resize(x(),y(),w()+60,h());
  154. redraw();
  155. m_GUICH->Set("Number",(int)m_GuiVec.size());
  156. m_GUICH->SetCommand(ControllerPlugin::SETNUM);
  157. }
  158. }
  159. void ControllerPluginGUI::cb_Add(Fl_Button* o, void* v)
  160. { ((ControllerPluginGUI*)(o->parent()))->cb_Add_i(o,v);}
  161. inline void ControllerPluginGUI::cb_Delete_i(Fl_Button* o, void* v)
  162. {
  163. if (m_GuiVec.size()>1)
  164. {
  165. DeleteCV();
  166. resize(x(),y(),w()-60,h());
  167. redraw();
  168. m_GUICH->Set("Number",(int)m_GuiVec.size());
  169. m_GUICH->SetCommand(ControllerPlugin::SETNUM);
  170. }
  171. }
  172. void ControllerPluginGUI::cb_Delete(Fl_Button* o, void* v)
  173. { ((ControllerPluginGUI*)(o->parent()))->cb_Delete_i(o,v);}
  174. // call for version <3
  175. istream &operator>>(istream &s, ControllerPluginGUI &o)
  176. {
  177. int c;
  178. string Title,Min,Max;
  179. float Val;
  180. o.Clear();
  181. s>>c;
  182. for (int n=0; n<c; n++)
  183. {
  184. s>>Title>>Min>>Max>>Val;
  185. o.AddCV();
  186. o.m_GuiVec[n]->m_Title->value(Title.c_str());
  187. o.m_GuiVec[n]->m_Min->value(Min.c_str());
  188. o.m_GuiVec[n]->m_Max->value(Max.c_str());
  189. o.m_GuiVec[n]->m_Chan->value(Val);
  190. }
  191. o.resize(o.x(),o.y(),c*60,o.h());
  192. return s;
  193. }
  194. // call for version >=3
  195. // another version of the stream to fix the old style string streaming problem
  196. void ControllerPluginGUI::StreamIn(istream &s)
  197. {
  198. int c,version,size;
  199. string Title,Min,Max;
  200. float Val;
  201. char Buf[4096];
  202. Clear();
  203. s>>version;
  204. s>>c;
  205. for (int n=0; n<c; n++)
  206. {
  207. AddCV();
  208. s>>size;
  209. s.ignore(1);
  210. s.get(Buf,size+1);
  211. m_GuiVec[n]->m_Title->value(Buf);
  212. s>>Min>>Max>>Val;
  213. m_GuiVec[n]->m_Min->value(Min.c_str());
  214. m_GuiVec[n]->m_Max->value(Max.c_str());
  215. m_GuiVec[n]->m_Chan->value(Val);
  216. }
  217. resize(x(),y(),c*60,h());
  218. }
  219. void ControllerPluginGUI::StreamOut(ostream &s)
  220. {
  221. // version
  222. s<<1<<endl;
  223. s<<m_GuiVec.size()<<endl;
  224. for (vector<ControllerPluginGUI::CVGUI*>::iterator i=m_GuiVec.begin();
  225. i!=m_GuiVec.end(); i++)
  226. {
  227. s<<strlen((*i)->m_Title->value())<<endl;
  228. s<<(*i)->m_Title->value()<<" ";
  229. s<<(*i)->m_Min->value()<<" ";
  230. s<<(*i)->m_Max->value()<<" ";
  231. s<<(*i)->m_Chan->value()<<endl;
  232. }
  233. }
  234. const string ControllerPluginGUI::GetHelpText(const string &loc){
  235. return string("")
  236. + "This is a simple plugin to allow you to generate CV values\n"
  237. + "interatively with sliders in the plugin window. Useful if you\n"
  238. + "can't use Midi, or for controlling LADSPA plugins. The slider\n"
  239. + "ranges can be set, and titles can be given to each slider.\n"
  240. + "You can add or delete sliders from the plugin using the\n"
  241. + "+ or - buttons.\n";
  242. }