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.

272 lines
8.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 "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. ////////////////////////////////////////////
  27. StreamPluginGUI::StreamPluginGUI(int w, int h,StreamPlugin *o,const HostInfo *Info) :
  28. SpiralPluginGUI(w,h,o)
  29. {
  30. m_Plugin=o;
  31. int Width=20;
  32. int Height=100;
  33. m_Load = new Fl_Button(2, 130, 30, 30, "Load");
  34. m_Load->labelsize(9);
  35. m_Load->callback((Fl_Callback*)cb_Load);
  36. add(m_Load);
  37. int sx=32;
  38. m_ToStart = new Fl_Button(sx, 130, 30, 30, "@|<");
  39. m_ToStart->labelsize(10);
  40. m_ToStart->labeltype(FL_SYMBOL_LABEL);
  41. m_ToStart->callback((Fl_Callback*)cb_ToStart);
  42. add(m_ToStart);
  43. m_Stop = new Fl_Button(sx+30, 130, 30, 30, "@||");
  44. m_Stop->labelsize(10);
  45. m_Stop->labeltype(FL_SYMBOL_LABEL);
  46. m_Stop->callback((Fl_Callback*)cb_Stop);
  47. add(m_Stop);
  48. m_Play = new Fl_Button(sx+60, 130, 30, 30, "@>");
  49. m_Play->labelsize(10);
  50. m_Play->labeltype(FL_SYMBOL_LABEL);
  51. m_Play->callback((Fl_Callback*)cb_Play);
  52. add(m_Play);
  53. m_Div = new Fl_Button(sx+90, 130, 30, 30, "/2");
  54. m_Div->labelsize(9);
  55. m_Div->callback((Fl_Callback*)cb_Div);
  56. add(m_Div);
  57. m_Reset = new Fl_Button(sx+120, 130, 30, 30, "Reset");
  58. m_Reset->labelsize(9);
  59. m_Reset->callback((Fl_Callback*)cb_Reset);
  60. add(m_Reset);
  61. m_Loop = new Fl_Button(sx+150, 130, 30, 30, "X2");
  62. m_Loop->labelsize(9);
  63. m_Loop->callback((Fl_Callback*)cb_Loop);
  64. add(m_Loop);
  65. m_Nudge = new Fl_Repeat_Button(sx+180, 130, 30, 30, "Nudge");
  66. m_Nudge->labelsize(9);
  67. m_Nudge->callback((Fl_Callback*)cb_Nudge);
  68. add(m_Nudge);
  69. // Andy Preston changed
  70. // m_Volume = new Fl_Knob(170, 15, 50, 50, "Volume");
  71. // to
  72. m_Volume = new Fl_Knob (180, 15, 50, 50, "Volume");
  73. m_Volume->color(GUI_COLOUR);
  74. m_Volume->type(Fl_Knob::LINELIN);
  75. m_Volume->labelsize(10);
  76. m_Volume->maximum(2);
  77. m_Volume->step(0.001);
  78. m_Volume->value(1);
  79. m_Volume->callback((Fl_Callback*)cb_Volume);
  80. add(m_Volume);
  81. m_Pitch = new Fl_Slider(5,85,235,20, "");
  82. m_Pitch->type(FL_HORIZONTAL);
  83. m_Pitch->align(FL_ALIGN_INSIDE | FL_ALIGN_RIGHT);
  84. m_Pitch->labelsize(10);
  85. m_Pitch->labelcolor(GUI_COLOUR);
  86. m_Pitch->maximum(20);
  87. m_Pitch->step(0.001);
  88. sprintf(PitchLabel,"%1.3f ",1.0);
  89. m_Pitch->label(PitchLabel);
  90. m_Pitch->value(11);
  91. m_Pitch->callback((Fl_Callback*)cb_Pitch);
  92. add(m_Pitch);
  93. // Andy Preston changed
  94. // int k=4;
  95. // m_Display[0] = new Fl_SevenSeg(10, 20, 30, 60);
  96. // m_Display[0]->bar_width(k);
  97. // m_Display[0]->color(FL_WHITE);
  98. // m_Display[0]->color2(GUI_COLOUR);
  99. // add(m_Display[0]);
  100. // m_Display[1] = new Fl_SevenSeg(30, 20, 30, 60);
  101. // m_Display[1]->bar_width(k);
  102. // m_Display[1]->color(FL_WHITE);
  103. // m_Display[1]->color2(GUI_COLOUR);
  104. // add(m_Display[1]);
  105. // m_Display[2] = new Fl_SevenSeg(60, 20, 30, 60);
  106. // m_Display[2]->bar_width(k);
  107. // m_Display[2]->color(FL_WHITE);
  108. // m_Display[2]->color2(GUI_COLOUR);
  109. // add(m_Display[2]);
  110. // m_Display[3] = new Fl_SevenSeg(80, 20, 30, 60);
  111. // m_Display[3]->bar_width(k);
  112. // m_Display[3]->color(FL_WHITE);
  113. // m_Display[3]->color2(GUI_COLOUR);
  114. // add(m_Display[3]);
  115. // m_Display[4] = new Fl_SevenSeg(110, 20, 30, 60);
  116. // m_Display[4]->bar_width(k);
  117. // m_Display[4]->color(FL_WHITE);
  118. // m_Display[4]->color2(GUI_COLOUR);
  119. // add(m_Display[4]);
  120. // m_Display[5] = new Fl_SevenSeg(130, 20, 30, 60);
  121. // m_Display[5]->bar_width(k);
  122. // m_Display[5]->color(FL_WHITE);
  123. // m_Display[5]->color2(GUI_COLOUR);
  124. // add(m_Display[5]);
  125. // to
  126. for (int dis=0; dis<6; dis++) {
  127. m_Display[dis] = new Fl_SevenSeg (5 + 28*dis, 20, 28, 60);
  128. m_Display[dis] -> bar_width (4);
  129. m_Display[dis] -> color (FL_WHITE);
  130. m_Display[dis] -> color2 (GUI_COLOUR);
  131. if (dis > 0 && dis % 2 == 0) m_Display[dis] -> dp (colon);
  132. add (m_Display[dis]);
  133. }
  134. m_Pos = new Fl_Slider(5,108,235,20,"");
  135. m_Pos->type(FL_HORIZONTAL);
  136. m_Pos->maximum(1);
  137. m_Pos->callback((Fl_Callback*)cb_Pos);
  138. add(m_Pos);
  139. end();
  140. }
  141. void StreamPluginGUI::SetTime(float t)
  142. {
  143. m_Pos->value(t);
  144. m_Display[5]->value((int)(t*100)%10);
  145. m_Display[4]->value((int)(t*10)%10);
  146. m_Display[3]->value((int)t%10);
  147. m_Display[2]->value((int)(t/10)%6);
  148. m_Display[1]->value((int)(t/60)%10);
  149. m_Display[0]->value((int)(t/600)%10);
  150. redraw();
  151. }
  152. void StreamPluginGUI::UpdateValues()
  153. {
  154. m_Volume->value(m_Plugin->GetVolume());
  155. m_Pitch->value(m_Plugin->GetPitch()+10);
  156. m_Loop->value(m_Plugin->GetLoop());
  157. }
  158. inline void StreamPluginGUI::cb_Load_i(Fl_Button* o, void* v)
  159. {
  160. char *fn=fl_file_chooser("Load a sample", "{*.wav,*.WAV}", NULL);
  161. if (fn && fn!='\0')
  162. {
  163. m_Plugin->OpenStream(fn);
  164. }
  165. }
  166. void StreamPluginGUI::cb_Load(Fl_Button* o, void* v)
  167. { ((StreamPluginGUI*)(o->parent()))->cb_Load_i(o,v);}
  168. inline void StreamPluginGUI::cb_Volume_i(Fl_Knob* o, void* v)
  169. { m_Plugin->SetVolume(o->value()); }
  170. void StreamPluginGUI::cb_Volume(Fl_Knob* o, void* v)
  171. { ((StreamPluginGUI*)(o->parent()))->cb_Volume_i(o,v);}
  172. inline void StreamPluginGUI::cb_Pitch_i(Fl_Slider* o, void* v)
  173. {
  174. m_Plugin->SetPitch(o->value()-10);
  175. sprintf(PitchLabel,"%1.3f ",o->value()-10);
  176. m_Pitch->label(PitchLabel);
  177. }
  178. void StreamPluginGUI::cb_Pitch(Fl_Slider* o, void* v)
  179. { ((StreamPluginGUI*)(o->parent()))->cb_Pitch_i(o,v);}
  180. inline void StreamPluginGUI::cb_Loop_i(Fl_Button* o, void* v)
  181. {
  182. float p=m_Plugin->GetPitch()*2;
  183. m_Plugin->SetPitch(p);
  184. sprintf(PitchLabel,"%1.3f ",p);
  185. m_Pitch->label(PitchLabel);
  186. m_Pitch->value(p+10);
  187. redraw();
  188. }
  189. void StreamPluginGUI::cb_Loop(Fl_Button* o, void* v)
  190. { ((StreamPluginGUI*)(o->parent()))->cb_Loop_i(o,v);}
  191. inline void StreamPluginGUI::cb_Div_i(Fl_Button* o, void* v)
  192. {
  193. float p=m_Plugin->GetPitch()/2.0f;
  194. m_Plugin->SetPitch(p);
  195. sprintf(PitchLabel,"%1.3f ",p);
  196. m_Pitch->label(PitchLabel);
  197. m_Pitch->value(p+10);
  198. redraw();
  199. }
  200. void StreamPluginGUI::cb_Div(Fl_Button* o, void* v)
  201. { ((StreamPluginGUI*)(o->parent()))->cb_Div_i(o,v);}
  202. inline void StreamPluginGUI::cb_ToStart_i(Fl_Button* o, void* v)
  203. { m_Plugin->Restart(); }
  204. void StreamPluginGUI::cb_ToStart(Fl_Button* o, void* v)
  205. { ((StreamPluginGUI*)(o->parent()))->cb_ToStart_i(o,v);}
  206. inline void StreamPluginGUI::cb_Stop_i(Fl_Button* o, void* v)
  207. { m_Plugin->Stop(); }
  208. void StreamPluginGUI::cb_Stop(Fl_Button* o, void* v)
  209. { ((StreamPluginGUI*)(o->parent()))->cb_Stop_i(o,v);}
  210. inline void StreamPluginGUI::cb_Play_i(Fl_Button* o, void* v)
  211. { m_Plugin->Play(); }
  212. void StreamPluginGUI::cb_Play(Fl_Button* o, void* v)
  213. { ((StreamPluginGUI*)(o->parent()))->cb_Play_i(o,v);}
  214. inline void StreamPluginGUI::cb_Reset_i(Fl_Button* o, void* v)
  215. {
  216. m_Plugin->SetPitch(1);
  217. sprintf(PitchLabel,"%1.3f ",1.0);
  218. m_Pitch->label(PitchLabel);
  219. m_Pitch->value(11);
  220. redraw();
  221. }
  222. void StreamPluginGUI::cb_Reset(Fl_Button* o, void* v)
  223. { ((StreamPluginGUI*)(o->parent()))->cb_Reset_i(o,v);}
  224. inline void StreamPluginGUI::cb_Nudge_i(Fl_Button* o, void* v)
  225. {
  226. m_Plugin->Nudge();
  227. }
  228. void StreamPluginGUI::cb_Nudge(Fl_Button* o, void* v)
  229. { ((StreamPluginGUI*)(o->parent()))->cb_Nudge_i(o,v);}
  230. inline void StreamPluginGUI::cb_Pos_i(Fl_Slider* o, void* v)
  231. { m_Plugin->SetTime(o->value()); }
  232. void StreamPluginGUI::cb_Pos(Fl_Slider* o, void* v)
  233. { ((StreamPluginGUI*)(o->parent()))->cb_Pos_i(o,v);}