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.

336 lines
10KB

  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. ////////////////////////////////////////////
  23. StreamPluginGUI::StreamPluginGUI(int w, int h,StreamPlugin *o,ChannelHandler *ch,const HostInfo *Info) :
  24. SpiralPluginGUI(w,h,o,ch),
  25. m_Playing (false),
  26. m_PitchValue (1.0f)
  27. {
  28. // 7 seg displays
  29. for (int dis=0; dis<6; dis++) {
  30. m_Display[dis] = new Fl_SevenSeg (5 + 28*dis, 20, 28, 60);
  31. m_Display[dis] -> bar_width (4);
  32. m_Display[dis] -> color (Info->SCOPE_FG_COLOUR);
  33. m_Display[dis] -> color2 (Info->SCOPE_BG_COLOUR);
  34. if (dis > 0 && dis % 2 == 0) m_Display[dis] -> dp (colon);
  35. add (m_Display[dis]);
  36. }
  37. // volume control
  38. m_Volume = new Fl_Knob (180, 15, 50, 50, "Volume");
  39. m_Volume->color (Info->GUI_COLOUR);
  40. m_Volume->type (Fl_Knob::LINELIN);
  41. m_Volume->labelsize (10);
  42. m_Volume->maximum (2);
  43. m_Volume->step (0.001);
  44. m_Volume->value (1);
  45. m_Volume->callback ((Fl_Callback*)cb_Volume);
  46. add (m_Volume);
  47. // pitch indicator
  48. m_Pitch = new Fl_Slider (5, 85, 235, 20, "");
  49. m_Pitch->type (FL_HORIZONTAL);
  50. m_Pitch->labelsize (10);
  51. m_Pitch->labelcolor (Info->GUI_COLOUR);
  52. m_Pitch->label (m_PitchLabel);
  53. m_Pitch->selection_color (Info->GUI_COLOUR);
  54. m_Pitch->box (FL_PLASTIC_DOWN_BOX);
  55. m_Pitch->maximum (20);
  56. m_Pitch->step (0.001);
  57. m_Pitch->callback ((Fl_Callback*)cb_Pitch);
  58. add (m_Pitch);
  59. // position indicator
  60. m_Pos = new Fl_Slider (5, 108, 235, 20, "");
  61. m_Pos->type (FL_HORIZONTAL);
  62. m_Pos->box (FL_PLASTIC_DOWN_BOX);
  63. m_Pos->labelcolor (Info->GUI_COLOUR);
  64. m_Pos->selection_color (Info->GUI_COLOUR);
  65. m_Pos->maximum (1);
  66. m_Pos->callback ((Fl_Callback*)cb_Pos);
  67. add (m_Pos);
  68. // load btn
  69. m_Load = new Fl_Button (2, 130, 30, 30, "Load");
  70. m_Load->labelsize (9);
  71. m_Load->box (FL_PLASTIC_UP_BOX);
  72. m_Load->color (Info->GUI_COLOUR);
  73. m_Load->selection_color (Info->GUI_COLOUR);
  74. m_Load->callback ((Fl_Callback*)cb_Load);
  75. add (m_Load);
  76. // reset btn
  77. m_ToStart = new Fl_Button (32, 130, 30, 30, "@|<");
  78. m_ToStart->labelsize (10);
  79. m_ToStart->labeltype (FL_SYMBOL_LABEL);
  80. m_ToStart->box (FL_PLASTIC_UP_BOX);
  81. m_ToStart->color (Info->GUI_COLOUR);
  82. m_ToStart->selection_color (Info->GUI_COLOUR);
  83. m_ToStart->callback ((Fl_Callback*)cb_ToStart);
  84. add (m_ToStart);
  85. // play btn
  86. m_Play = new Fl_Button (62, 130, 30, 30, "@>");
  87. m_Play->labelsize (10);
  88. m_Play->labeltype (FL_SYMBOL_LABEL);
  89. m_Play->box (FL_PLASTIC_UP_BOX);
  90. m_Play->color (Info->GUI_COLOUR);
  91. m_Play->selection_color (Info->GUI_COLOUR);
  92. m_Play->callback ((Fl_Callback*)cb_Play);
  93. add (m_Play);
  94. // normal speed btn
  95. m_Reset = new Fl_Button (92, 130, 30, 30, "Reset");
  96. m_Reset->labelsize (9);
  97. m_Reset->box (FL_PLASTIC_UP_BOX);
  98. m_Reset->color (Info->GUI_COLOUR);
  99. m_Reset->selection_color (Info->GUI_COLOUR);
  100. m_Reset->callback ((Fl_Callback*)cb_Reset);
  101. add (m_Reset);
  102. // Reverse Button
  103. m_Rev = new Fl_Button (122, 130, 30, 30, "@<-");
  104. m_Rev->labelsize (10);
  105. m_Rev->labeltype (FL_SYMBOL_LABEL);
  106. m_Rev->box (FL_PLASTIC_UP_BOX);
  107. m_Rev->color (Info->GUI_COLOUR);
  108. m_Rev->selection_color (Info->GUI_COLOUR);
  109. m_Rev->callback ((Fl_Callback*)cb_Rev);
  110. add (m_Rev);
  111. // 1/2 speed btn
  112. m_Div = new Fl_Button (152, 130, 30, 30, "/2");
  113. m_Div->labelsize (9);
  114. m_Div->box (FL_PLASTIC_UP_BOX);
  115. m_Div->color (Info->GUI_COLOUR);
  116. m_Div->selection_color (Info->GUI_COLOUR);
  117. m_Div->callback ((Fl_Callback*)cb_Div);
  118. add (m_Div);
  119. // dbl speed btn
  120. m_Dbl = new Fl_Button (182, 130, 30, 30, "X2");
  121. m_Dbl->labelsize (9);
  122. m_Dbl->box (FL_PLASTIC_UP_BOX);
  123. m_Dbl->color (Info->GUI_COLOUR);
  124. m_Dbl->selection_color (Info->GUI_COLOUR);
  125. m_Dbl->callback ((Fl_Callback*)cb_Dbl);
  126. add (m_Dbl);
  127. // nudge btn
  128. m_Nudge = new Fl_Repeat_Button (212, 130, 30, 30, "Nudge");
  129. m_Nudge->labelsize (9);
  130. m_Nudge->box (FL_PLASTIC_UP_BOX);
  131. m_Nudge->color (Info->GUI_COLOUR);
  132. m_Nudge->selection_color (Info->GUI_COLOUR);
  133. m_Nudge->callback ((Fl_Callback*)cb_Nudge);
  134. add (m_Nudge);
  135. end ();
  136. UpdatePitch (true, false, false);
  137. }
  138. StreamPluginGUI::~StreamPluginGUI () {
  139. }
  140. // Update signalled from plugin
  141. void StreamPluginGUI::Update() {
  142. float t=m_GUICH->GetFloat ("TimeOut");
  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. SetMaxTime (m_GUICH->GetFloat ("MaxTime"));
  152. if (m_Playing != m_GUICH->GetBool ("Playing")) UpdatePlayStatus ();
  153. }
  154. // Update GUI on load
  155. void StreamPluginGUI::UpdateValues (SpiralPlugin *o) {
  156. StreamPlugin *Plugin = (StreamPlugin*)o;
  157. m_Volume->value (Plugin->GetVolume());
  158. m_PitchValue = Plugin->GetPitch();
  159. UpdatePitch (true, true, false);
  160. }
  161. // volume
  162. inline void StreamPluginGUI::cb_Volume_i (Fl_Knob* o, void* v) {
  163. m_GUICH->Set ("Volume", (float)o->value ());
  164. }
  165. void StreamPluginGUI::cb_Volume (Fl_Knob* o, void* v) {
  166. ((StreamPluginGUI*)(o->parent ()))->cb_Volume_i (o, v);
  167. }
  168. // pitch
  169. void StreamPluginGUI::UpdatePitch (bool UpdateIt, bool DrawIt, bool SendIt) {
  170. if (m_PitchValue<0) {
  171. m_Pitch->align (FL_ALIGN_INSIDE | FL_ALIGN_LEFT);
  172. m_Rev->label ("@->");
  173. }
  174. else {
  175. m_Pitch->align (FL_ALIGN_INSIDE | FL_ALIGN_RIGHT);
  176. m_Rev->label ("@<-");
  177. }
  178. sprintf (m_PitchLabel, " %1.3f ", m_PitchValue);
  179. if (UpdateIt) m_Pitch->value (m_PitchValue+10);
  180. if (DrawIt) redraw();
  181. if (SendIt) m_GUICH->Set ("Pitch", m_PitchValue);
  182. }
  183. inline void StreamPluginGUI::cb_Pitch_i (Fl_Slider* o, void* v) {
  184. m_PitchValue=o->value()-10;
  185. UpdatePitch (false, false);
  186. }
  187. void StreamPluginGUI::cb_Pitch (Fl_Slider* o, void* v) {
  188. ((StreamPluginGUI*)(o->parent ()))->cb_Pitch_i(o,v);
  189. }
  190. // position
  191. inline void StreamPluginGUI::cb_Pos_i (Fl_Slider* o, void* v) {
  192. m_GUICH->Set ("Time",(float)o->value());
  193. m_GUICH->SetCommand (StreamPlugin::SET_TIME);
  194. }
  195. void StreamPluginGUI::cb_Pos (Fl_Slider* o, void* v) {
  196. ((StreamPluginGUI*)(o->parent ()))->cb_Pos_i (o, v);
  197. }
  198. // load
  199. inline void StreamPluginGUI::cb_Load_i (Fl_Button* o, void* v) {
  200. char *fn=fl_file_chooser("Load a sample", "{*.wav,*.WAV}", NULL);
  201. if (fn && fn!='\0') {
  202. strcpy (m_TextBuf, fn);
  203. m_GUICH->SetData ("FileName", (void*)m_TextBuf);
  204. m_GUICH->SetCommand (StreamPlugin::LOAD);
  205. m_GUICH->Wait();
  206. SetMaxTime (m_GUICH->GetFloat ("MaxTime"));
  207. }
  208. }
  209. void StreamPluginGUI::cb_Load (Fl_Button* o, void* v) {
  210. ((StreamPluginGUI*)(o->parent ()))->cb_Load_i (o, v);
  211. }
  212. // restart
  213. inline void StreamPluginGUI::cb_ToStart_i (Fl_Button* o, void* v) {
  214. m_GUICH->SetCommand (StreamPlugin::RESTART);
  215. }
  216. void StreamPluginGUI::cb_ToStart (Fl_Button* o, void* v) {
  217. ((StreamPluginGUI*)(o->parent ()))->cb_ToStart_i (o, v);
  218. }
  219. // play
  220. void StreamPluginGUI::UpdatePlayStatus (void) {
  221. m_Playing = ! m_Playing;
  222. if (m_Playing) m_Play->label ("@||");
  223. else m_Play->label ("@>");
  224. }
  225. inline void StreamPluginGUI::cb_Play_i (Fl_Button* o, void* v) {
  226. if (m_Playing) m_GUICH->SetCommand (StreamPlugin::STOP);
  227. else m_GUICH->SetCommand (StreamPlugin::PLAY);
  228. }
  229. void StreamPluginGUI::cb_Play (Fl_Button* o, void* v) {
  230. ((StreamPluginGUI*)(o->parent ()))->cb_Play_i (o, v);
  231. }
  232. // reset
  233. inline void StreamPluginGUI::cb_Reset_i (Fl_Button* o, void* v) {
  234. m_PitchValue = 1.0f;
  235. UpdatePitch ();
  236. }
  237. void StreamPluginGUI::cb_Reset (Fl_Button* o, void* v) {
  238. ((StreamPluginGUI*)(o->parent ()))->cb_Reset_i (o, v);
  239. }
  240. // Rev
  241. inline void StreamPluginGUI::cb_Rev_i (Fl_Button* o, void* v) {
  242. m_PitchValue = -m_PitchValue;
  243. UpdatePitch ();
  244. }
  245. void StreamPluginGUI::cb_Rev (Fl_Button* o, void* v) {
  246. ((StreamPluginGUI*)(o->parent ()))->cb_Rev_i (o, v);
  247. }
  248. // div 2
  249. inline void StreamPluginGUI::cb_Div_i (Fl_Button* o, void* v) {
  250. m_PitchValue /= 2.0f;
  251. UpdatePitch ();
  252. }
  253. void StreamPluginGUI::cb_Div (Fl_Button* o, void* v) {
  254. ((StreamPluginGUI*)(o->parent()))->cb_Div_i (o, v);
  255. }
  256. // mul 2
  257. inline void StreamPluginGUI::cb_Dbl_i (Fl_Button* o, void* v) {
  258. m_PitchValue *= 2.0f;
  259. UpdatePitch ();
  260. }
  261. void StreamPluginGUI::cb_Dbl (Fl_Button* o, void* v) {
  262. ((StreamPluginGUI*)(o->parent ()))->cb_Dbl_i (o, v);
  263. }
  264. //nudge
  265. inline void StreamPluginGUI::cb_Nudge_i (Fl_Button* o, void* v) {
  266. int NudgeSize = 1;
  267. if (m_PitchValue < 0) NudgeSize = -NudgeSize;
  268. float P = m_Pos->value() + NudgeSize;
  269. if (P < 0) P = 0;
  270. if (P > m_Pos->maximum()) P = m_Pos->maximum();
  271. m_Pos->value (P);
  272. m_GUICH->Set ("Time", P);
  273. m_GUICH->SetCommand (StreamPlugin::SET_TIME);
  274. }
  275. void StreamPluginGUI::cb_Nudge (Fl_Button* o, void* v) {
  276. ((StreamPluginGUI*)(o->parent ()))->cb_Nudge_i (o, v);
  277. }
  278. // help text
  279. const string StreamPluginGUI::GetHelpText (const string &loc){
  280. return string("")
  281. + "If you want to mix whole tracks and add effects etc, then this is the\n"
  282. + "way to do it. The StreamPlugin loads a wav in bit by bit, so it doesn't\n"
  283. + "use much memory. The track can be pitched for mixing.\n"
  284. + "Operates pretty much like a media player such as XMMS (only wav\n"
  285. + "format though).\n\n"
  286. + "Connect the finish trigger to the stop trigger to play the wav only\nonce.\n\n"
  287. + "Note: Not realtime safe, if you're using JACK, use a client such as\n"
  288. + "alsaplayer.";
  289. }