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.

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