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.

330 lines
9.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 "StreamPluginGUI.h"
  19. #include <FL/fl_draw.h>
  20. #include <FL/fl_draw.H>
  21. #include <FL/fl_file_chooser.h>
  22. static const int GUI_COLOUR = 179;
  23. static const int GUIBG_COLOUR = 144;
  24. static const int GUIBG2_COLOUR = 145;
  25. char PitchLabel[256];
  26. bool StreamPluginGUI::TimerSet=false;
  27. vector<StreamPluginGUI*> StreamPluginGUI::PluginList;
  28. ////////////////////////////////////////////
  29. StreamPluginGUI::StreamPluginGUI(int w, int h,StreamPlugin *o,ChannelHandler *ch,const HostInfo *Info) :
  30. SpiralPluginGUI(w,h,o,ch)
  31. {
  32. StartTimer(this);
  33. int Width=20;
  34. int Height=100;
  35. //What are Width and Height for.
  36. m_PitchValue=1.0f;
  37. m_Load = new Fl_Button(2, 130, 30, 30, "Load");
  38. m_Load->labelsize(9);
  39. m_Load->callback((Fl_Callback*)cb_Load);
  40. add(m_Load);
  41. int sx=32;
  42. m_ToStart = new Fl_Button(sx, 130, 30, 30, "@|<");
  43. m_ToStart->labelsize(10);
  44. m_ToStart->labeltype(FL_SYMBOL_LABEL);
  45. m_ToStart->callback((Fl_Callback*)cb_ToStart);
  46. add(m_ToStart);
  47. m_Stop = new Fl_Button(sx+30, 130, 30, 30, "@||");
  48. m_Stop->labelsize(10);
  49. m_Stop->labeltype(FL_SYMBOL_LABEL);
  50. m_Stop->callback((Fl_Callback*)cb_Stop);
  51. add(m_Stop);
  52. m_Play = new Fl_Button(sx+60, 130, 30, 30, "@>");
  53. m_Play->labelsize(10);
  54. m_Play->labeltype(FL_SYMBOL_LABEL);
  55. m_Play->callback((Fl_Callback*)cb_Play);
  56. add(m_Play);
  57. m_Div = new Fl_Button(sx+90, 130, 30, 30, "/2");
  58. m_Div->labelsize(9);
  59. m_Div->callback((Fl_Callback*)cb_Div);
  60. add(m_Div);
  61. m_Reset = new Fl_Button(sx+120, 130, 30, 30, "Reset");
  62. m_Reset->labelsize(9);
  63. m_Reset->callback((Fl_Callback*)cb_Reset);
  64. add(m_Reset);
  65. m_Loop = new Fl_Button(sx+150, 130, 30, 30, "X2");
  66. m_Loop->labelsize(9);
  67. m_Loop->callback((Fl_Callback*)cb_Loop);
  68. add(m_Loop);
  69. m_Nudge = new Fl_Repeat_Button(sx+180, 130, 30, 30, "Nudge");
  70. m_Nudge->labelsize(9);
  71. m_Nudge->callback((Fl_Callback*)cb_Nudge);
  72. add(m_Nudge);
  73. // Andy Preston changed
  74. // m_Volume = new Fl_Knob(170, 15, 50, 50, "Volume");
  75. // to
  76. m_Volume = new Fl_Knob (180, 15, 50, 50, "Volume");
  77. m_Volume->color(GUI_COLOUR);
  78. m_Volume->type(Fl_Knob::LINELIN);
  79. m_Volume->labelsize(10);
  80. m_Volume->maximum(2);
  81. m_Volume->step(0.001);
  82. m_Volume->value(1);
  83. m_Volume->callback((Fl_Callback*)cb_Volume);
  84. add(m_Volume);
  85. m_Pitch = new Fl_Slider(5,85,235,20, "");
  86. m_Pitch->type(FL_HORIZONTAL);
  87. m_Pitch->align(FL_ALIGN_INSIDE | FL_ALIGN_RIGHT);
  88. m_Pitch->labelsize(10);
  89. m_Pitch->labelcolor(GUI_COLOUR);
  90. m_Pitch->maximum(20);
  91. m_Pitch->step(0.001);
  92. sprintf(PitchLabel,"%1.3f ",1.0);
  93. m_Pitch->label(PitchLabel);
  94. m_Pitch->value(11);
  95. m_Pitch->callback((Fl_Callback*)cb_Pitch);
  96. add(m_Pitch);
  97. // Andy Preston changed
  98. // int k=4;
  99. // m_Display[0] = new Fl_SevenSeg(10, 20, 30, 60);
  100. // m_Display[0]->bar_width(k);
  101. // m_Display[0]->color(FL_WHITE);
  102. // m_Display[0]->color2(GUI_COLOUR);
  103. // add(m_Display[0]);
  104. // m_Display[1] = new Fl_SevenSeg(30, 20, 30, 60);
  105. // m_Display[1]->bar_width(k);
  106. // m_Display[1]->color(FL_WHITE);
  107. // m_Display[1]->color2(GUI_COLOUR);
  108. // add(m_Display[1]);
  109. // m_Display[2] = new Fl_SevenSeg(60, 20, 30, 60);
  110. // m_Display[2]->bar_width(k);
  111. // m_Display[2]->color(FL_WHITE);
  112. // m_Display[2]->color2(GUI_COLOUR);
  113. // add(m_Display[2]);
  114. // m_Display[3] = new Fl_SevenSeg(80, 20, 30, 60);
  115. // m_Display[3]->bar_width(k);
  116. // m_Display[3]->color(FL_WHITE);
  117. // m_Display[3]->color2(GUI_COLOUR);
  118. // add(m_Display[3]);
  119. // m_Display[4] = new Fl_SevenSeg(110, 20, 30, 60);
  120. // m_Display[4]->bar_width(k);
  121. // m_Display[4]->color(FL_WHITE);
  122. // m_Display[4]->color2(GUI_COLOUR);
  123. // add(m_Display[4]);
  124. // m_Display[5] = new Fl_SevenSeg(130, 20, 30, 60);
  125. // m_Display[5]->bar_width(k);
  126. // m_Display[5]->color(FL_WHITE);
  127. // m_Display[5]->color2(GUI_COLOUR);
  128. // add(m_Display[5]);
  129. // to
  130. for (int dis=0; dis<6; dis++) {
  131. m_Display[dis] = new Fl_SevenSeg (5 + 28*dis, 20, 28, 60);
  132. m_Display[dis] -> bar_width (4);
  133. m_Display[dis] -> color (FL_WHITE);
  134. m_Display[dis] -> color2 (GUI_COLOUR);
  135. if (dis > 0 && dis % 2 == 0) m_Display[dis] -> dp (colon);
  136. add (m_Display[dis]);
  137. }
  138. m_Pos = new Fl_Slider(5,108,235,20,"");
  139. m_Pos->type(FL_HORIZONTAL);
  140. m_Pos->maximum(1);
  141. m_Pos->callback((Fl_Callback*)cb_Pos);
  142. add(m_Pos);
  143. end();
  144. }
  145. StreamPluginGUI::~StreamPluginGUI()
  146. {
  147. cerr << "~StreamPluginGUI" << endl;
  148. StopTimer(this);
  149. }
  150. void StreamPluginGUI::SetTime()
  151. {
  152. cerr << "foo" << endl;
  153. float t=m_GUICH->GetFloat("TimeOut");
  154. m_Pos->value(t);
  155. m_Display[5]->value((int)(t*100)%10);
  156. m_Display[4]->value((int)(t*10)%10);
  157. m_Display[3]->value((int)t%10);
  158. m_Display[2]->value((int)(t/10)%6);
  159. m_Display[1]->value((int)(t/60)%10);
  160. m_Display[0]->value((int)(t/600)%10);
  161. redraw();
  162. }
  163. void StreamPluginGUI::UpdateValues(SpiralPlugin *o)
  164. {
  165. StreamPlugin *Plugin = (StreamPlugin*)o;
  166. m_Volume->value(Plugin->GetVolume());
  167. m_Pitch->value(Plugin->GetPitch()+10);
  168. m_Loop->value(Plugin->GetLoop());
  169. }
  170. inline void StreamPluginGUI::cb_Load_i(Fl_Button* o, void* v)
  171. {
  172. char *fn=fl_file_chooser("Load a sample", "{*.wav,*.WAV}", NULL);
  173. if (fn && fn!='\0')
  174. {
  175. strcpy(m_TextBuf,fn);
  176. m_GUICH->Set("FileName",m_TextBuf);
  177. m_GUICH->SetCommand(StreamPlugin::LOAD);
  178. }
  179. }
  180. void StreamPluginGUI::cb_Load(Fl_Button* o, void* v)
  181. { ((StreamPluginGUI*)(o->parent()))->cb_Load_i(o,v);}
  182. inline void StreamPluginGUI::cb_Volume_i(Fl_Knob* o, void* v)
  183. { m_GUICH->Set("Volume",(float)o->value()); }
  184. void StreamPluginGUI::cb_Volume(Fl_Knob* o, void* v)
  185. { ((StreamPluginGUI*)(o->parent()))->cb_Volume_i(o,v);}
  186. inline void StreamPluginGUI::cb_Pitch_i(Fl_Slider* o, void* v)
  187. {
  188. m_GUICH->Set("Pitch",(float)o->value()-10);
  189. sprintf(PitchLabel,"%1.3f ",o->value()-10);
  190. m_Pitch->label(PitchLabel);
  191. m_PitchValue=o->value()-10;
  192. }
  193. void StreamPluginGUI::cb_Pitch(Fl_Slider* o, void* v)
  194. { ((StreamPluginGUI*)(o->parent()))->cb_Pitch_i(o,v);}
  195. inline void StreamPluginGUI::cb_Loop_i(Fl_Button* o, void* v) //Why is this function named so.
  196. {
  197. m_PitchValue*=2.0f;
  198. m_GUICH->SetCommand(StreamPlugin::DOUBLE);
  199. sprintf(PitchLabel,"%1.3f ",m_PitchValue);
  200. m_Pitch->label(PitchLabel);
  201. m_Pitch->value(m_PitchValue+10);
  202. redraw();
  203. }
  204. void StreamPluginGUI::cb_Loop(Fl_Button* o, void* v)
  205. { ((StreamPluginGUI*)(o->parent()))->cb_Loop_i(o,v);}
  206. inline void StreamPluginGUI::cb_Div_i(Fl_Button* o, void* v)
  207. {
  208. m_PitchValue/=2.0f;
  209. m_GUICH->SetCommand(StreamPlugin::HALF);
  210. sprintf(PitchLabel,"%1.3f ",m_PitchValue);
  211. m_Pitch->label(PitchLabel);
  212. m_Pitch->value(m_PitchValue+10);
  213. redraw();
  214. }
  215. void StreamPluginGUI::cb_Div(Fl_Button* o, void* v)
  216. { ((StreamPluginGUI*)(o->parent()))->cb_Div_i(o,v);}
  217. inline void StreamPluginGUI::cb_ToStart_i(Fl_Button* o, void* v)
  218. { m_GUICH->SetCommand(StreamPlugin::RESTART); }
  219. void StreamPluginGUI::cb_ToStart(Fl_Button* o, void* v)
  220. { ((StreamPluginGUI*)(o->parent()))->cb_ToStart_i(o,v);}
  221. inline void StreamPluginGUI::cb_Stop_i(Fl_Button* o, void* v)
  222. { m_GUICH->SetCommand(StreamPlugin::STOP); }
  223. void StreamPluginGUI::cb_Stop(Fl_Button* o, void* v)
  224. { ((StreamPluginGUI*)(o->parent()))->cb_Stop_i(o,v);}
  225. inline void StreamPluginGUI::cb_Play_i(Fl_Button* o, void* v)
  226. { m_GUICH->SetCommand(StreamPlugin::PLAY); }
  227. void StreamPluginGUI::cb_Play(Fl_Button* o, void* v)
  228. { ((StreamPluginGUI*)(o->parent()))->cb_Play_i(o,v);}
  229. inline void StreamPluginGUI::cb_Reset_i(Fl_Button* o, void* v)
  230. {
  231. m_GUICH->SetCommand(StreamPlugin::RESET);
  232. sprintf(PitchLabel,"%1.3f ",1.0);
  233. m_Pitch->label(PitchLabel);
  234. m_Pitch->value(11);
  235. m_PitchValue=1.0f;
  236. redraw();
  237. }
  238. void StreamPluginGUI::cb_Reset(Fl_Button* o, void* v)
  239. { ((StreamPluginGUI*)(o->parent()))->cb_Reset_i(o,v);}
  240. inline void StreamPluginGUI::cb_Nudge_i(Fl_Button* o, void* v)
  241. {
  242. m_GUICH->SetCommand(StreamPlugin::NUDGE);
  243. }
  244. void StreamPluginGUI::cb_Nudge(Fl_Button* o, void* v)
  245. { ((StreamPluginGUI*)(o->parent()))->cb_Nudge_i(o,v);}
  246. inline void StreamPluginGUI::cb_Pos_i(Fl_Slider* o, void* v)
  247. {
  248. m_GUICH->Set("Time",(float)o->value());
  249. m_GUICH->SetCommand(StreamPlugin::SET_TIME);
  250. }
  251. void StreamPluginGUI::cb_Pos(Fl_Slider* o, void* v)
  252. { ((StreamPluginGUI*)(o->parent()))->cb_Pos_i(o,v);}
  253. //The timer stuff
  254. #define TIME_OUT_DURATION 0.01
  255. //This is temparary, should use a variable, and let it be set from the command line ore something.
  256. void StreamPluginGUI::StartTimer(StreamPluginGUI* p)
  257. {
  258. if (!TimerSet)
  259. {
  260. Fl::add_timeout(TIME_OUT_DURATION,&StreamPluginGUI::TimerCallBack);
  261. TimerSet=True;
  262. }
  263. PluginList.push_back(p);
  264. }
  265. void StreamPluginGUI::StopTimer(StreamPluginGUI* p)
  266. {
  267. cerr << "StopTimer" << endl;
  268. for (vector<StreamPluginGUI*>::iterator i=PluginList.begin();i!=PluginList.end();i++)
  269. if ((*i)==p)
  270. i=PluginList.erase(i);
  271. }
  272. //If Spiral synth modular unloaded the .so file this is in, the timeout
  273. //would probably cause a problem
  274. void StreamPluginGUI::TimerCallBack(void* x)
  275. {
  276. /*for(vector<const StreamPluginGUI*>::iterator i=PluginList.begin();
  277. i!=PluginList.end();i++)
  278. {*/
  279. for (vector<StreamPluginGUI*>::iterator i=PluginList.begin();i!=PluginList.end();i++)
  280. (*i)->SetTime();
  281. Fl::add_timeout(TIME_OUT_DURATION,&StreamPluginGUI::TimerCallBack);
  282. }