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.

271 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,ChannelHandler *ch,const HostInfo *Info) :
  28. SpiralPluginGUI(w,h,o,ch)
  29. {
  30. m_PitchValue=1.0f;
  31. m_TempPitch=1.0f;
  32. m_Load = new Fl_Button(2, 130, 30, 30, "Load");
  33. m_Load->labelsize(9);
  34. m_Load->callback((Fl_Callback*)cb_Load);
  35. add(m_Load);
  36. int sx=32;
  37. m_ToStart = new Fl_Button(sx, 130, 30, 30, "@|<");
  38. m_ToStart->labelsize(10);
  39. m_ToStart->labeltype(FL_SYMBOL_LABEL);
  40. m_ToStart->callback((Fl_Callback*)cb_ToStart);
  41. add(m_ToStart);
  42. m_Stop = new Fl_Button(sx+30, 130, 30, 30, "@||");
  43. m_Stop->labelsize(10);
  44. m_Stop->labeltype(FL_SYMBOL_LABEL);
  45. m_Stop->callback((Fl_Callback*)cb_Stop);
  46. add(m_Stop);
  47. m_Play = new Fl_Button(sx+60, 130, 30, 30, "@>");
  48. m_Play->labelsize(10);
  49. m_Play->labeltype(FL_SYMBOL_LABEL);
  50. m_Play->callback((Fl_Callback*)cb_Play);
  51. add(m_Play);
  52. m_Div = new Fl_Button(sx+90, 130, 30, 30, "/2");
  53. m_Div->labelsize(9);
  54. m_Div->callback((Fl_Callback*)cb_Div);
  55. add(m_Div);
  56. m_Reset = new Fl_Button(sx+120, 130, 30, 30, "Reset");
  57. m_Reset->labelsize(9);
  58. m_Reset->callback((Fl_Callback*)cb_Reset);
  59. add(m_Reset);
  60. m_Loop = new Fl_Button(sx+150, 130, 30, 30, "X2");
  61. m_Loop->labelsize(9);
  62. m_Loop->callback((Fl_Callback*)cb_Loop);
  63. add(m_Loop);
  64. m_Nudge = new Fl_Repeat_Button(sx+180, 130, 30, 30, "Nudge");
  65. m_Nudge->labelsize(9);
  66. m_Nudge->callback((Fl_Callback*)cb_Nudge);
  67. add(m_Nudge);
  68. m_Volume = new Fl_Knob (180, 15, 50, 50, "Volume");
  69. m_Volume->color(GUI_COLOUR);
  70. m_Volume->type(Fl_Knob::LINELIN);
  71. m_Volume->labelsize(10);
  72. m_Volume->maximum(2);
  73. m_Volume->step(0.001);
  74. m_Volume->value(1);
  75. m_Volume->callback((Fl_Callback*)cb_Volume);
  76. add(m_Volume);
  77. m_Pitch = new Fl_Slider(5,85,235,20, "");
  78. m_Pitch->type(FL_HORIZONTAL);
  79. m_Pitch->align(FL_ALIGN_INSIDE | FL_ALIGN_RIGHT);
  80. m_Pitch->labelsize(10);
  81. m_Pitch->labelcolor(GUI_COLOUR);
  82. m_Pitch->maximum(20);
  83. m_Pitch->step(0.001);
  84. sprintf(PitchLabel,"%1.3f ",1.0);
  85. m_Pitch->label(PitchLabel);
  86. m_Pitch->value(11);
  87. m_Pitch->callback((Fl_Callback*)cb_Pitch);
  88. add(m_Pitch);
  89. for (int dis=0; dis<6; dis++) {
  90. m_Display[dis] = new Fl_SevenSeg (5 + 28*dis, 20, 28, 60);
  91. m_Display[dis] -> bar_width (4);
  92. m_Display[dis] -> color (FL_WHITE);
  93. m_Display[dis] -> color2 (GUI_COLOUR);
  94. if (dis > 0 && dis % 2 == 0) m_Display[dis] -> dp (colon);
  95. add (m_Display[dis]);
  96. }
  97. m_Pos = new Fl_Slider(5,108,235,20,"");
  98. m_Pos->type(FL_HORIZONTAL);
  99. m_Pos->maximum(1);
  100. m_Pos->callback((Fl_Callback*)cb_Pos);
  101. add(m_Pos);
  102. end();
  103. }
  104. StreamPluginGUI::~StreamPluginGUI()
  105. {
  106. }
  107. void StreamPluginGUI::Update()
  108. {
  109. float t=m_GUICH->GetFloat("TimeOut");
  110. m_Pos->value(t);
  111. m_Display[5]->value((int)(t*100)%10);
  112. m_Display[4]->value((int)(t*10)%10);
  113. m_Display[3]->value((int)t%10);
  114. m_Display[2]->value((int)(t/10)%6);
  115. m_Display[1]->value((int)(t/60)%10);
  116. m_Display[0]->value((int)(t/600)%10);
  117. redraw();
  118. SetMaxTime(m_GUICH->GetFloat("MaxTime"));
  119. }
  120. void StreamPluginGUI::UpdateValues(SpiralPlugin *o)
  121. {
  122. StreamPlugin *Plugin = (StreamPlugin*)o;
  123. m_Volume->value(Plugin->GetVolume());
  124. m_Pitch->value(Plugin->GetPitch()+10);
  125. m_Loop->value(Plugin->GetLoop());
  126. }
  127. inline void StreamPluginGUI::cb_Load_i(Fl_Button* o, void* v)
  128. {
  129. char *fn=fl_file_chooser("Load a sample", "{*.wav,*.WAV}", NULL);
  130. if (fn && fn!='\0')
  131. {
  132. strcpy(m_TextBuf,fn);
  133. m_GUICH->SetData("FileName",(void*)m_TextBuf);
  134. m_GUICH->SetCommand(StreamPlugin::LOAD);
  135. m_GUICH->Wait();
  136. SetMaxTime(m_GUICH->GetFloat("MaxTime"));
  137. }
  138. }
  139. void StreamPluginGUI::cb_Load(Fl_Button* o, void* v)
  140. { ((StreamPluginGUI*)(o->parent()))->cb_Load_i(o,v);}
  141. inline void StreamPluginGUI::cb_Volume_i(Fl_Knob* o, void* v)
  142. { m_GUICH->Set("Volume",(float)o->value()); }
  143. void StreamPluginGUI::cb_Volume(Fl_Knob* o, void* v)
  144. { ((StreamPluginGUI*)(o->parent()))->cb_Volume_i(o,v);}
  145. inline void StreamPluginGUI::cb_Pitch_i(Fl_Slider* o, void* v)
  146. {
  147. m_GUICH->Set("Pitch",(float)o->value()-10);
  148. sprintf(PitchLabel,"%1.3f ",o->value()-10);
  149. m_Pitch->label(PitchLabel);
  150. m_PitchValue=o->value()-10;
  151. }
  152. void StreamPluginGUI::cb_Pitch(Fl_Slider* o, void* v)
  153. { ((StreamPluginGUI*)(o->parent()))->cb_Pitch_i(o,v);}
  154. inline void StreamPluginGUI::cb_Loop_i(Fl_Button* o, void* v) //Why is this function named so.
  155. {
  156. m_PitchValue*=2.0f;
  157. m_GUICH->Set("Pitch",m_PitchValue);
  158. sprintf(PitchLabel,"%1.3f ",m_PitchValue);
  159. m_Pitch->label(PitchLabel);
  160. m_Pitch->value(m_PitchValue+10);
  161. redraw();
  162. }
  163. void StreamPluginGUI::cb_Loop(Fl_Button* o, void* v)
  164. { ((StreamPluginGUI*)(o->parent()))->cb_Loop_i(o,v);}
  165. inline void StreamPluginGUI::cb_Div_i(Fl_Button* o, void* v)
  166. {
  167. m_PitchValue/=2.0f;
  168. m_GUICH->Set("Pitch",m_PitchValue);
  169. sprintf(PitchLabel,"%1.3f ",m_PitchValue);
  170. m_Pitch->label(PitchLabel);
  171. m_Pitch->value(m_PitchValue+10);
  172. redraw();
  173. }
  174. void StreamPluginGUI::cb_Div(Fl_Button* o, void* v)
  175. { ((StreamPluginGUI*)(o->parent()))->cb_Div_i(o,v);}
  176. inline void StreamPluginGUI::cb_ToStart_i(Fl_Button* o, void* v)
  177. { m_GUICH->SetCommand(StreamPlugin::RESTART); }
  178. void StreamPluginGUI::cb_ToStart(Fl_Button* o, void* v)
  179. { ((StreamPluginGUI*)(o->parent()))->cb_ToStart_i(o,v);}
  180. inline void StreamPluginGUI::cb_Stop_i(Fl_Button* o, void* v)
  181. {
  182. m_TempPitch=m_PitchValue;
  183. m_PitchValue=0;
  184. m_GUICH->Set("Pitch",m_PitchValue);
  185. }
  186. void StreamPluginGUI::cb_Stop(Fl_Button* o, void* v)
  187. { ((StreamPluginGUI*)(o->parent()))->cb_Stop_i(o,v);}
  188. inline void StreamPluginGUI::cb_Play_i(Fl_Button* o, void* v)
  189. {
  190. m_PitchValue=m_TempPitch;
  191. m_GUICH->Set("Pitch",m_PitchValue);
  192. }
  193. void StreamPluginGUI::cb_Play(Fl_Button* o, void* v)
  194. { ((StreamPluginGUI*)(o->parent()))->cb_Play_i(o,v);}
  195. inline void StreamPluginGUI::cb_Reset_i(Fl_Button* o, void* v)
  196. {
  197. m_GUICH->Set("Pitch",1.0f);
  198. sprintf(PitchLabel,"%1.3f ",1.0);
  199. m_Pitch->label(PitchLabel);
  200. m_Pitch->value(11);
  201. m_PitchValue=1.0f;
  202. redraw();
  203. }
  204. void StreamPluginGUI::cb_Reset(Fl_Button* o, void* v)
  205. { ((StreamPluginGUI*)(o->parent()))->cb_Reset_i(o,v);}
  206. inline void StreamPluginGUI::cb_Nudge_i(Fl_Button* o, void* v)
  207. {
  208. m_GUICH->SetCommand(StreamPlugin::NUDGE);
  209. }
  210. void StreamPluginGUI::cb_Nudge(Fl_Button* o, void* v)
  211. { ((StreamPluginGUI*)(o->parent()))->cb_Nudge_i(o,v);}
  212. inline void StreamPluginGUI::cb_Pos_i(Fl_Slider* o, void* v)
  213. {
  214. m_GUICH->Set("Time",(float)o->value());
  215. m_GUICH->SetCommand(StreamPlugin::SET_TIME);
  216. }
  217. void StreamPluginGUI::cb_Pos(Fl_Slider* o, void* v)
  218. { ((StreamPluginGUI*)(o->parent()))->cb_Pos_i(o,v);}
  219. const string StreamPluginGUI::GetHelpText(const string &loc){
  220. return string("")
  221. + "If you want to mix whole tracks and add effects etc, then this is the\n"
  222. + "way to do it. The StreamPlugin loads a wav in bit by bit, so it doesn't\n"
  223. + "use much memory. The track can be pitched for mixing.\n"
  224. + "Operates pretty much like a media player such as XMMS (only wav\n"
  225. + "format though).\n\n"
  226. + "Note: Not realtime safe, if you're using JACK, use a client such as\n"
  227. + "alsaplayer.";
  228. }