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.

369 lines
12KB

  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 const int GUI_COLOUR = 179;
  22. static const int GUIBG_COLOUR = 144;
  23. static const int GUIBG2_COLOUR = 145;
  24. static unsigned char *image_Square[] = {
  25. (unsigned char*)"20 20 2 1",
  26. (unsigned char*)" \tc None",
  27. (unsigned char*)".\tc #000000",
  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. (unsigned char*)" ...... ",
  46. (unsigned char*)" ",
  47. (unsigned char*)" "};
  48. static unsigned char *image_Noise[] = {
  49. (unsigned char*)"20 20 2 1",
  50. (unsigned char*)" \tc None",
  51. (unsigned char*)".\tc #000000",
  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. (unsigned char*)" . ",
  70. (unsigned char*)" ",
  71. (unsigned char*)" "};
  72. static unsigned char *image_Saw[] = {
  73. (unsigned char*)"20 20 2 1",
  74. (unsigned char*)" \tc None",
  75. (unsigned char*)".\tc #000000",
  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. (unsigned char*)" .. ",
  94. (unsigned char*)" ",
  95. (unsigned char*)" "};
  96. OscillatorPluginGUI::OscillatorPluginGUI(int w, int h,OscillatorPlugin *o,ChannelHandler *ch,const HostInfo *Info) :
  97. SpiralPluginGUI(w,h,o,ch),
  98. pixmap_Square(image_Square),
  99. pixmap_Noise(image_Noise),
  100. pixmap_Saw(image_Saw)
  101. {
  102. ShapeSquare = new Fl_Check_Button(5, 15, 55, 30);
  103. ShapeSquare->type(102);
  104. ShapeSquare->down_box(FL_DIAMOND_DOWN_BOX);
  105. ShapeSquare->selection_color(GUI_COLOUR);
  106. ShapeSquare->set();
  107. pixmap_Square.label(ShapeSquare);
  108. ShapeSquare->callback((Fl_Callback*)cb_Square);
  109. ShapeNoise = new Fl_Check_Button(5, 65, 55, 30);
  110. ShapeNoise->type(102);
  111. ShapeNoise->down_box(FL_DIAMOND_DOWN_BOX);
  112. ShapeNoise->selection_color(GUI_COLOUR);
  113. pixmap_Noise.label(ShapeNoise);
  114. ShapeNoise->callback((Fl_Callback*)cb_Noise);
  115. ShapeSaw = new Fl_Check_Button(5, 40, 55, 30);
  116. ShapeSaw->type(102);
  117. ShapeSaw->down_box(FL_DIAMOND_DOWN_BOX);
  118. ShapeSaw->selection_color(GUI_COLOUR);
  119. pixmap_Saw.label(ShapeSaw);
  120. ShapeSaw->callback((Fl_Callback*)cb_Saw);
  121. Freq = new Fl_Knob(188, 2, 40, 40, "Octave");
  122. Freq->color(GUI_COLOUR);
  123. Freq->type(Fl_Knob::LINELIN);
  124. Freq->labelsize(10);
  125. Freq->maximum(6);
  126. Freq->step(1);
  127. Freq->value(3);
  128. Freq->scaleticks(6);
  129. Freq->cursor(50);
  130. Freq->callback((Fl_Callback*)cb_Freq);
  131. FineTune = new Fl_Knob(112, 22, 65, 65, "Fine Tune");
  132. FineTune->color(GUI_COLOUR);
  133. FineTune->type(Fl_Knob::LINELIN);
  134. FineTune->labelsize(10);
  135. FineTune->scaleticks(20);
  136. FineTune->maximum(1.414);
  137. FineTune->step(0.000001);
  138. FineTune->value(1);
  139. FineTune->callback((Fl_Callback*)cb_FineTune);
  140. ModAmount = new Fl_Knob(188, 54, 40, 40, "Mod Depth");
  141. ModAmount->color(GUI_COLOUR);
  142. ModAmount->type(Fl_Knob::LINELIN);
  143. ModAmount->labelsize(10);
  144. ModAmount->maximum(2.0f);
  145. ModAmount->step(0.001);
  146. ModAmount->value(1.0);
  147. ModAmount->callback((Fl_Callback*)cb_ModAmount);
  148. PulseWidth = new Fl_Slider(60, 20, 20, 70, "PW");
  149. PulseWidth->type(4);
  150. PulseWidth->selection_color(GUI_COLOUR);
  151. PulseWidth->labelsize(10);
  152. PulseWidth->maximum(1);
  153. PulseWidth->step(0.01);
  154. PulseWidth->value(0.5);
  155. PulseWidth->callback((Fl_Callback*)cb_PulseWidth);
  156. SHLen = new Fl_Slider(80, 20, 20, 70, "SH");
  157. SHLen->type(4);
  158. SHLen->selection_color(GUI_COLOUR);
  159. SHLen->labelsize(10);
  160. SHLen->maximum(0.2);
  161. SHLen->step(0.001);
  162. SHLen->value(0.1);
  163. SHLen->callback((Fl_Callback*)cb_SHLen);
  164. m_pop = new Fl_Button(1,h-14, 13, 13, "@>");
  165. m_pop->type(1);
  166. m_pop->box(FL_FLAT_BOX);
  167. m_pop->down_box(FL_FLAT_BOX);
  168. m_pop->labeltype(FL_SYMBOL_LABEL);
  169. m_pop->labelsize(10);
  170. m_pop->labelcolor(25);
  171. m_pop->callback((Fl_Callback*)cb_pop);
  172. m_out_freq = new Fl_Output(65,h+5, 58, 15, "Frequency");
  173. m_out_freq->box(FL_ENGRAVED_BOX);
  174. m_out_freq->color(16);
  175. m_out_freq->labelsize(10);
  176. m_out_freq->textsize(10);
  177. m_out_freq->hide();
  178. m_out_freq->set_output();
  179. m_out_mod = new Fl_Output(65,h+22, 48, 15, "Modulation");
  180. m_out_mod->box(FL_ENGRAVED_BOX);
  181. m_out_mod->color(16);
  182. m_out_mod->labelsize(10);
  183. m_out_mod->textsize(10);
  184. m_out_mod->hide();
  185. m_out_mod->set_output();
  186. m_out_pulseW = new Fl_Output(190,h+5, 48, 15, "Pulse width");
  187. m_out_pulseW->box(FL_ENGRAVED_BOX);
  188. m_out_pulseW->color(16);
  189. m_out_pulseW->labelsize(10);
  190. m_out_pulseW->textsize(10);
  191. m_out_pulseW->hide();
  192. m_out_pulseW->set_output();
  193. m_out_SHlen = new Fl_Output(190,h+22, 48, 15, "Sampling");
  194. m_out_SHlen->box(FL_ENGRAVED_BOX);
  195. m_out_SHlen->color(16);
  196. m_out_SHlen->labelsize(10);
  197. m_out_SHlen->textsize(10);
  198. m_out_SHlen->hide();
  199. m_out_SHlen->set_output();
  200. end();
  201. }
  202. extern "C" int sprintf(char *,const char *,...);
  203. void OscillatorPluginGUI::UpdateValues(SpiralPlugin *o)
  204. {
  205. OscillatorPlugin *Plugin = (OscillatorPlugin*)o;
  206. ShapeSquare->value(0);
  207. ShapeNoise->value(0);
  208. ShapeSaw->value(0);
  209. switch (Plugin->GetType())
  210. {
  211. case OscillatorPlugin::SQUARE : ShapeSquare->value(1); break;
  212. case OscillatorPlugin::NOISE : ShapeNoise->value(1); break;
  213. case OscillatorPlugin::SAW : ShapeSaw->value(1); break;
  214. case OscillatorPlugin::NONE : break;
  215. }
  216. Freq->value(Plugin->GetOctave()+3);
  217. ModAmount->value(Plugin->GetModAmount());
  218. FineTune->value(sqrt(Plugin->GetFineFreq()));
  219. PulseWidth->value(Plugin->GetPulseWidth());
  220. SHLen->value(0.2f-Plugin->GetSHLen());
  221. char str[10];
  222. float fr = 110.0f * Plugin->GetFineFreq();
  223. int oc = Plugin->GetOctave();
  224. if (oc > 0) fr *= 1 << oc;
  225. if (oc < 0) fr /= 1 << (-oc);
  226. sprintf(str,"%4.1f Hz", fr);
  227. m_out_freq->value(str);
  228. sprintf(str,"%4.0f %%", 100*Plugin->GetPulseWidth());
  229. m_out_pulseW->value(str);
  230. sprintf(str,"%4.0f %%", 100*Plugin->GetModAmount());
  231. m_out_mod->value(str);
  232. sprintf(str,"%4.3f s", Plugin->GetSHLen());
  233. m_out_SHlen->value(str);
  234. }
  235. //// Callbacks ////
  236. inline void OscillatorPluginGUI::cb_Freq_i(Fl_Knob* o, void* v)
  237. {
  238. char str[10];
  239. m_GUICH->Set("Octave",(int)o->value()-3);
  240. //float fr = 110.0f * m_Plugin->GetFineFreq();
  241. //int oc = m_Plugin->GetOctave();
  242. //if (oc > 0) fr *= 1 << oc;
  243. //if (oc < 0) fr /= 1 << (-oc);
  244. //sprintf(str,"%4.1f Hz", fr);
  245. //m_out_freq->value(str);
  246. }
  247. void OscillatorPluginGUI::cb_Freq(Fl_Knob* o, void* v)
  248. { ((OscillatorPluginGUI*)(o->parent()))->cb_Freq_i(o,v); }
  249. inline void OscillatorPluginGUI::cb_FineTune_i(Fl_Knob* o, void* v)
  250. {
  251. char str[10];
  252. m_GUICH->Set("FineFreq",o->value()*o->value());
  253. //float fr = 110.0f * m_Plugin->GetFineFreq();
  254. //int oc = m_Plugin->GetOctave();
  255. //if (oc > 0) fr *= 1 << oc;
  256. //if (oc < 0) fr /= 1 << (-oc);
  257. //sprintf(str,"%4.1f Hz", fr);
  258. //m_out_freq->value(str);
  259. }
  260. void OscillatorPluginGUI::cb_FineTune(Fl_Knob* o, void* v)
  261. { ((OscillatorPluginGUI*)(o->parent()))->cb_FineTune_i(o,v); }
  262. inline void OscillatorPluginGUI::cb_PulseWidth_i(Fl_Slider* o, void* v)
  263. {
  264. char str[10];
  265. m_GUICH->Set("PulseWidth",o->value());
  266. sprintf(str,"%4.0f %%", 100*o->value());
  267. m_out_pulseW->value(str);
  268. }
  269. void OscillatorPluginGUI::cb_PulseWidth(Fl_Slider* o, void* v)
  270. { ((OscillatorPluginGUI*)(o->parent()))->cb_PulseWidth_i(o,v);}
  271. inline void OscillatorPluginGUI::cb_Square_i(Fl_Check_Button* o, void* v)
  272. { m_GUICH->Set("Type",(char)OscillatorPlugin::SQUARE); }
  273. void OscillatorPluginGUI::cb_Square(Fl_Check_Button* o, void* v)
  274. { ((OscillatorPluginGUI*)(o->parent()))->cb_Square_i(o,v); }
  275. inline void OscillatorPluginGUI::cb_Saw_i(Fl_Check_Button* o, void* v)
  276. { m_GUICH->Set("Type",(char)OscillatorPlugin::SAW); }
  277. void OscillatorPluginGUI::cb_Saw(Fl_Check_Button* o, void* v)
  278. { ((OscillatorPluginGUI*)(o->parent()))->cb_Saw_i(o,v); }
  279. inline void OscillatorPluginGUI::cb_Noise_i(Fl_Check_Button* o, void* v)
  280. { m_GUICH->Set("Type",(char)OscillatorPlugin::NOISE); }
  281. void OscillatorPluginGUI::cb_Noise(Fl_Check_Button* o, void* v)
  282. { ((OscillatorPluginGUI*)(o->parent()))->cb_Noise_i(o,v); }
  283. inline void OscillatorPluginGUI::cb_SHLen_i(Fl_Slider* o, void* v)
  284. {
  285. char str[10];
  286. m_GUICH->Set("SHLen",0.2f-o->value());
  287. sprintf(str,"%4.3f s", 0.2f-o->value());
  288. m_out_SHlen->value(str);
  289. }
  290. void OscillatorPluginGUI::cb_SHLen(Fl_Slider* o, void* v)
  291. { ((OscillatorPluginGUI*)(o->parent()))->cb_SHLen_i(o,v); }
  292. inline void OscillatorPluginGUI::cb_ModAmount_i(Fl_Knob* o, void* v)
  293. {
  294. char str[10];
  295. m_GUICH->Set("ModAmount",o->value());
  296. sprintf(str,"%4.0f %%", 100*o->value());
  297. m_out_mod->value(str);
  298. }
  299. void OscillatorPluginGUI::cb_ModAmount(Fl_Knob* o, void* v)
  300. { ((OscillatorPluginGUI*)(o->parent()))->cb_ModAmount_i(o,v); }
  301. inline void OscillatorPluginGUI::cb_pop_i(Fl_Button *o, void*) {
  302. if (o->value())
  303. {
  304. o->label("@2>");
  305. m_out_freq->show();
  306. m_out_mod->show();
  307. m_out_SHlen->show();
  308. m_out_pulseW->show();
  309. redraw();
  310. }
  311. else
  312. {
  313. o->label("@>");
  314. m_out_freq->hide();
  315. m_out_mod->hide();
  316. m_out_SHlen->hide();
  317. m_out_pulseW->hide();
  318. redraw();
  319. parent()->redraw();
  320. }
  321. }
  322. void OscillatorPluginGUI::cb_pop(Fl_Button* o, void* v) {
  323. ((OscillatorPluginGUI*)(o->parent()))->cb_pop_i(o,v);
  324. }