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.

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