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.

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