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.

367 lines
11KB

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