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.

294 lines
8.8KB

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