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.

387 lines
13KB

  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 "OscillatorPluginGUI.h"
  19. #include <FL/fl_draw.h>
  20. #include <FL/fl_draw.H>
  21. static unsigned char *image_Square[] = {
  22. (unsigned char*)"20 20 2 1",
  23. (unsigned char*)" \tc None",
  24. (unsigned char*)".\tc #000000",
  25. (unsigned char*)" ",
  26. (unsigned char*)" ",
  27. (unsigned char*)" ...... ",
  28. (unsigned char*)" . . ",
  29. (unsigned char*)" . . ",
  30. (unsigned char*)" . . ",
  31. (unsigned char*)" . . ",
  32. (unsigned char*)" . . ",
  33. (unsigned char*)" . . ",
  34. (unsigned char*)" . . ",
  35. (unsigned char*)" ... . ... ",
  36. (unsigned char*)" . . ",
  37. (unsigned char*)" . . ",
  38. (unsigned char*)" . . ",
  39. (unsigned char*)" . . ",
  40. (unsigned char*)" . . ",
  41. (unsigned char*)" . . ",
  42. (unsigned char*)" ...... ",
  43. (unsigned char*)" ",
  44. (unsigned char*)" "};
  45. static unsigned char *image_Noise[] = {
  46. (unsigned char*)"20 20 2 1",
  47. (unsigned char*)" \tc None",
  48. (unsigned char*)".\tc #000000",
  49. (unsigned char*)" ",
  50. (unsigned char*)" ",
  51. (unsigned char*)" ",
  52. (unsigned char*)" ",
  53. (unsigned char*)" . ",
  54. (unsigned char*)" . . ",
  55. (unsigned char*)" . . . ",
  56. (unsigned char*)" . . . ",
  57. (unsigned char*)" . . . . ",
  58. (unsigned char*)" . . . . ",
  59. (unsigned char*)" ... . . . . .. ",
  60. (unsigned char*)" . . . . .. ",
  61. (unsigned char*)" . . . . . ",
  62. (unsigned char*)" . . . ",
  63. (unsigned char*)" . . ",
  64. (unsigned char*)" . . ",
  65. (unsigned char*)" . . ",
  66. (unsigned char*)" . ",
  67. (unsigned char*)" ",
  68. (unsigned char*)" "};
  69. static unsigned char *image_Saw[] = {
  70. (unsigned char*)"20 20 2 1",
  71. (unsigned char*)" \tc None",
  72. (unsigned char*)".\tc #000000",
  73. (unsigned char*)" ",
  74. (unsigned char*)" ",
  75. (unsigned char*)" .. ",
  76. (unsigned char*)" .. ",
  77. (unsigned char*)" . . ",
  78. (unsigned char*)" . . ",
  79. (unsigned char*)" . . ",
  80. (unsigned char*)" . . ",
  81. (unsigned char*)" . . ",
  82. (unsigned char*)" . . ",
  83. (unsigned char*)" ... . .... ",
  84. (unsigned char*)" . . ",
  85. (unsigned char*)" . . ",
  86. (unsigned char*)" . . ",
  87. (unsigned char*)" . . ",
  88. (unsigned char*)" . . ",
  89. (unsigned char*)" .. ",
  90. (unsigned char*)" .. ",
  91. (unsigned char*)" ",
  92. (unsigned char*)" "};
  93. OscillatorPluginGUI::OscillatorPluginGUI(int w, int h,OscillatorPlugin *o,ChannelHandler *ch,const HostInfo *Info) :
  94. SpiralPluginGUI(w,h,o,ch),
  95. pixmap_Square(image_Square),
  96. pixmap_Noise(image_Noise),
  97. pixmap_Saw(image_Saw),
  98. m_FineFreq(0),
  99. m_Octave(0)
  100. {
  101. ShapeSquare = new Fl_Check_Button(5, 15, 55, 30);
  102. ShapeSquare->type(102);
  103. ShapeSquare->down_box(FL_DIAMOND_DOWN_BOX);
  104. ShapeSquare->selection_color(Info->GUI_COLOUR);
  105. ShapeSquare->set();
  106. pixmap_Square.label(ShapeSquare);
  107. ShapeSquare->callback((Fl_Callback*)cb_Square);
  108. ShapeNoise = new Fl_Check_Button(5, 65, 55, 30);
  109. ShapeNoise->type(102);
  110. ShapeNoise->down_box(FL_DIAMOND_DOWN_BOX);
  111. ShapeNoise->selection_color(Info->GUI_COLOUR);
  112. pixmap_Noise.label(ShapeNoise);
  113. ShapeNoise->callback((Fl_Callback*)cb_Noise);
  114. ShapeSaw = new Fl_Check_Button(5, 40, 55, 30);
  115. ShapeSaw->type(102);
  116. ShapeSaw->down_box(FL_DIAMOND_DOWN_BOX);
  117. ShapeSaw->selection_color(Info->GUI_COLOUR);
  118. pixmap_Saw.label(ShapeSaw);
  119. ShapeSaw->callback((Fl_Callback*)cb_Saw);
  120. Freq = new Fl_Knob(188, 2, 40, 40, "Octave");
  121. Freq->color(Info->GUI_COLOUR);
  122. Freq->type(Fl_Knob::LINELIN);
  123. Freq->labelsize(10);
  124. Freq->maximum(6);
  125. Freq->step(1);
  126. Freq->value(3);
  127. Freq->scaleticks(6);
  128. Freq->cursor(50);
  129. Freq->callback((Fl_Callback*)cb_Freq);
  130. FineTune = new Fl_Knob(112, 22, 65, 65, "Fine Tune");
  131. FineTune->color(Info->GUI_COLOUR);
  132. FineTune->type(Fl_Knob::LINELIN);
  133. FineTune->labelsize(10);
  134. FineTune->scaleticks(20);
  135. FineTune->maximum(1.414);
  136. FineTune->step(0.000001);
  137. FineTune->value(1);
  138. FineTune->callback((Fl_Callback*)cb_FineTune);
  139. ModAmount = new Fl_Knob(188, 54, 40, 40, "Mod Depth");
  140. ModAmount->color(Info->GUI_COLOUR);
  141. ModAmount->type(Fl_Knob::LINELIN);
  142. ModAmount->labelsize(10);
  143. ModAmount->maximum(2.0f);
  144. ModAmount->step(0.001);
  145. ModAmount->value(1.0);
  146. ModAmount->callback((Fl_Callback*)cb_ModAmount);
  147. PulseWidth = new Fl_Slider(60, 20, 20, 70, "PW");
  148. PulseWidth->type(4);
  149. PulseWidth->selection_color(Info->GUI_COLOUR);
  150. PulseWidth->labelsize(10);
  151. PulseWidth->maximum(1);
  152. PulseWidth->step(0.01);
  153. PulseWidth->value(0.5);
  154. PulseWidth->callback((Fl_Callback*)cb_PulseWidth);
  155. SHLen = new Fl_Slider(80, 20, 20, 70, "SH");
  156. SHLen->type(4);
  157. SHLen->selection_color(Info->GUI_COLOUR);
  158. SHLen->labelsize(10);
  159. SHLen->maximum(0.2);
  160. SHLen->step(0.001);
  161. SHLen->value(0.1);
  162. SHLen->callback((Fl_Callback*)cb_SHLen);
  163. m_pop = new Fl_Button(1,h-14, 13, 13, "@>");
  164. m_pop->type(1);
  165. m_pop->box(FL_FLAT_BOX);
  166. m_pop->down_box(FL_FLAT_BOX);
  167. m_pop->labeltype(FL_SYMBOL_LABEL);
  168. m_pop->labelsize(10);
  169. m_pop->labelcolor(25);
  170. m_pop->callback((Fl_Callback*)cb_pop);
  171. m_out_freq = new Fl_Output(65,h+5, 58, 15, "Frequency");
  172. m_out_freq->box(FL_ENGRAVED_BOX);
  173. m_out_freq->color(16);
  174. m_out_freq->labelsize(10);
  175. m_out_freq->textsize(10);
  176. m_out_freq->hide();
  177. m_out_freq->set_output();
  178. m_out_mod = new Fl_Output(65,h+22, 48, 15, "Modulation");
  179. m_out_mod->box(FL_ENGRAVED_BOX);
  180. m_out_mod->color(16);
  181. m_out_mod->labelsize(10);
  182. m_out_mod->textsize(10);
  183. m_out_mod->hide();
  184. m_out_mod->set_output();
  185. m_out_pulseW = new Fl_Output(190,h+5, 48, 15, "Pulse width");
  186. m_out_pulseW->box(FL_ENGRAVED_BOX);
  187. m_out_pulseW->color(16);
  188. m_out_pulseW->labelsize(10);
  189. m_out_pulseW->textsize(10);
  190. m_out_pulseW->hide();
  191. m_out_pulseW->set_output();
  192. m_out_SHlen = new Fl_Output(190,h+22, 48, 15, "Sampling");
  193. m_out_SHlen->box(FL_ENGRAVED_BOX);
  194. m_out_SHlen->color(16);
  195. m_out_SHlen->labelsize(10);
  196. m_out_SHlen->textsize(10);
  197. m_out_SHlen->hide();
  198. m_out_SHlen->set_output();
  199. end();
  200. }
  201. extern "C" int sprintf(char *,const char *,...);
  202. void OscillatorPluginGUI::UpdateValues(SpiralPlugin *o)
  203. {
  204. OscillatorPlugin *Plugin = (OscillatorPlugin*)o;
  205. ShapeSquare->value(0);
  206. ShapeNoise->value(0);
  207. ShapeSaw->value(0);
  208. switch (Plugin->GetType())
  209. {
  210. case OscillatorPlugin::SQUARE : ShapeSquare->value(1); break;
  211. case OscillatorPlugin::NOISE : ShapeNoise->value(1); break;
  212. case OscillatorPlugin::SAW : ShapeSaw->value(1); break;
  213. case OscillatorPlugin::NONE : break;
  214. }
  215. Freq->value(Plugin->GetOctave()+3);
  216. ModAmount->value(Plugin->GetModAmount());
  217. FineTune->value(sqrt(Plugin->GetFineFreq()));
  218. PulseWidth->value(Plugin->GetPulseWidth());
  219. SHLen->value(0.2f-Plugin->GetSHLen());
  220. char str[10];
  221. float fr = 110.0f * Plugin->GetFineFreq();
  222. m_FineFreq=Plugin->GetFineFreq();
  223. int oc = Plugin->GetOctave();
  224. m_Octave = oc;
  225. if (oc > 0) fr *= 1 << oc;
  226. if (oc < 0) fr /= 1 << (-oc);
  227. sprintf(str,"%4.1f Hz", fr);
  228. m_out_freq->value(str);
  229. sprintf(str,"%4.0f %%", 100*Plugin->GetPulseWidth());
  230. m_out_pulseW->value(str);
  231. sprintf(str,"%4.0f %%", 100*Plugin->GetModAmount());
  232. m_out_mod->value(str);
  233. sprintf(str,"%4.3f s", Plugin->GetSHLen());
  234. m_out_SHlen->value(str);
  235. }
  236. //// Callbacks ////
  237. inline void OscillatorPluginGUI::cb_Freq_i(Fl_Knob* o, void* v)
  238. {
  239. char str[10];
  240. m_GUICH->Set("Octave",(int)o->value()-3);
  241. m_Octave = (int)o->value()-3;
  242. float fr = 110.0f * m_FineFreq;
  243. int oc = m_Octave;
  244. if (oc > 0) fr *= 1 << oc;
  245. if (oc < 0) fr /= 1 << (-oc);
  246. sprintf(str,"%4.1f Hz", fr);
  247. m_out_freq->value(str);
  248. }
  249. void OscillatorPluginGUI::cb_Freq(Fl_Knob* o, void* v)
  250. { ((OscillatorPluginGUI*)(o->parent()))->cb_Freq_i(o,v); }
  251. inline void OscillatorPluginGUI::cb_FineTune_i(Fl_Knob* o, void* v)
  252. {
  253. char str[10];
  254. m_GUICH->Set("FineFreq",(float)(o->value()*o->value()));
  255. m_FineFreq=(float)(o->value()*o->value());
  256. float fr = 110.0f * m_FineFreq;
  257. int oc = m_Octave;
  258. if (oc > 0) fr *= 1 << oc;
  259. if (oc < 0) fr /= 1 << (-oc);
  260. sprintf(str,"%4.1f Hz", fr);
  261. m_out_freq->value(str);
  262. }
  263. void OscillatorPluginGUI::cb_FineTune(Fl_Knob* o, void* v)
  264. { ((OscillatorPluginGUI*)(o->parent()))->cb_FineTune_i(o,v); }
  265. inline void OscillatorPluginGUI::cb_PulseWidth_i(Fl_Slider* o, void* v)
  266. {
  267. char str[10];
  268. m_GUICH->Set("PulseWidth",(float)o->value());
  269. sprintf(str,"%4.0f %%",(float)(100*o->value()));
  270. m_out_pulseW->value(str);
  271. }
  272. void OscillatorPluginGUI::cb_PulseWidth(Fl_Slider* o, void* v)
  273. { ((OscillatorPluginGUI*)(o->parent()))->cb_PulseWidth_i(o,v);}
  274. inline void OscillatorPluginGUI::cb_Square_i(Fl_Check_Button* o, void* v)
  275. { m_GUICH->Set("Type",(char)OscillatorPlugin::SQUARE); }
  276. void OscillatorPluginGUI::cb_Square(Fl_Check_Button* o, void* v)
  277. { ((OscillatorPluginGUI*)(o->parent()))->cb_Square_i(o,v); }
  278. inline void OscillatorPluginGUI::cb_Saw_i(Fl_Check_Button* o, void* v)
  279. { m_GUICH->Set("Type",(char)OscillatorPlugin::SAW); }
  280. void OscillatorPluginGUI::cb_Saw(Fl_Check_Button* o, void* v)
  281. { ((OscillatorPluginGUI*)(o->parent()))->cb_Saw_i(o,v); }
  282. inline void OscillatorPluginGUI::cb_Noise_i(Fl_Check_Button* o, void* v)
  283. { m_GUICH->Set("Type",(char)OscillatorPlugin::NOISE); }
  284. void OscillatorPluginGUI::cb_Noise(Fl_Check_Button* o, void* v)
  285. { ((OscillatorPluginGUI*)(o->parent()))->cb_Noise_i(o,v); }
  286. inline void OscillatorPluginGUI::cb_SHLen_i(Fl_Slider* o, void* v)
  287. {
  288. char str[10];
  289. m_GUICH->Set("SHLen",(float)(0.2f-o->value()));
  290. sprintf(str,"%4.3f s", 0.2f-o->value());
  291. m_out_SHlen->value(str);
  292. }
  293. void OscillatorPluginGUI::cb_SHLen(Fl_Slider* o, void* v)
  294. { ((OscillatorPluginGUI*)(o->parent()))->cb_SHLen_i(o,v); }
  295. inline void OscillatorPluginGUI::cb_ModAmount_i(Fl_Knob* o, void* v)
  296. {
  297. char str[10];
  298. m_GUICH->Set("ModAmount",(float)o->value());
  299. sprintf(str,"%4.0f %%", 100*o->value());
  300. m_out_mod->value(str);
  301. }
  302. void OscillatorPluginGUI::cb_ModAmount(Fl_Knob* o, void* v)
  303. { ((OscillatorPluginGUI*)(o->parent()))->cb_ModAmount_i(o,v); }
  304. inline void OscillatorPluginGUI::cb_pop_i(Fl_Button *o, void*) {
  305. if (o->value())
  306. {
  307. o->label("@2>");
  308. m_out_freq->show();
  309. m_out_mod->show();
  310. m_out_SHlen->show();
  311. m_out_pulseW->show();
  312. redraw();
  313. }
  314. else
  315. {
  316. o->label("@>");
  317. m_out_freq->hide();
  318. m_out_mod->hide();
  319. m_out_SHlen->hide();
  320. m_out_pulseW->hide();
  321. redraw();
  322. parent()->redraw();
  323. }
  324. }
  325. void OscillatorPluginGUI::cb_pop(Fl_Button* o, void* v) {
  326. ((OscillatorPluginGUI*)(o->parent()))->cb_pop_i(o,v);
  327. }
  328. const string OscillatorPluginGUI::GetHelpText(const string &loc){
  329. return string("")
  330. + "The Oscillator generates raw waveforms from CV controls. Three wave \n"
  331. + "shapes are included, Square wave, Triangle wave and white noise.\n\n"
  332. + "In the square and triangle shapes, the Frequency CV controls the pitch \n"
  333. + "of the signal generated, and the pulsewidth turns the squarewave into \n"
  334. + "a pulse wave of varying harmonics, and the triangle wave into a sawtooth,\n"
  335. + "or reverse sawtooth wave.\n\n"
  336. + "The sample & hold CV changes the time between samples with the white noise.\n"
  337. + "This is usful for making the Oscillator into a random CV generator.\n\n"
  338. + "The plugin window allows you to select the wave shape, set the octave and\n"
  339. + "fine tune the frequency. There are also controls to set the pulsewidth,\n"
  340. + "sample and hold manually, and control the modulation depth of the input CV's.\n\n"
  341. + "The frequency can be set extremely low on this oscillator, so you can use\n"
  342. + "it as an LFO for controlling other plugins.";
  343. }