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.

193 lines
5.5KB

  1. /* WaveShaper Plugin Copyleft (C) 2001 Yves Usson
  2. * for SpiralSynthModular
  3. / * Copyleft (C) 2000 David Griffiths <dave@pawfal.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19. #include "WaveShaperPluginGUI.h"
  20. #include <FL/fl_draw.h>
  21. #include <FL/fl_draw.H>
  22. static const int GUI_COLOUR = 179;
  23. static const int GUIBG_COLOUR = 144;
  24. static const int GUIBG2_COLOUR = 145;
  25. FunctionPlot::FunctionPlot(int ox, int oy, int ww, int hh) : Fl_Widget (ox, oy, ww, hh) {
  26. fval = new float[256];
  27. for (int i=0;i<256;i++) fval[i] = i / 128.0 - 1.0;
  28. }
  29. FunctionPlot::~FunctionPlot() {
  30. delete [] fval;
  31. }
  32. void FunctionPlot::draw() {
  33. int ox = x() + 3;
  34. int oy = y() +3;
  35. int ww = w() - 6;
  36. int hh = h() - 6;
  37. float coefx,coefy;
  38. draw_box();
  39. fl_clip(ox,oy,ww,hh);
  40. coefx = ww / 256.0;
  41. coefy = hh / 2.0;
  42. for (int i = -5; i < 5; i++)
  43. {
  44. if (i==0) fl_color(FL_BLUE); else fl_color(FL_CYAN);
  45. fl_line(ox,oy+hh/2+i*hh/10,ox+ww,oy+hh/2+i*hh/10);
  46. }
  47. for (int i = -5; i < 5; i++)
  48. {
  49. if (i==0) fl_color(FL_BLUE); else fl_color(FL_CYAN);
  50. fl_line(ox+i*ww/10+ww/2,oy,ox+i*ww/10+ww/2,oy+hh);
  51. }
  52. fl_color(FL_RED);
  53. float y1 = oy+hh/2-coefy*fval[0];
  54. for (int i = 0; i < 255; i++)
  55. {
  56. float y2 = oy+hh/2-coefy*fval[i+1];
  57. fl_line((int)(ox+i*coefx),(int)y1,(int)(ox+(i+1)*coefx),(int)y2);
  58. y1 = y2;
  59. }
  60. fl_color(FL_BLACK);
  61. fl_pop_clip();
  62. }
  63. int FunctionPlot::handle(int event) {
  64. return 0;
  65. }
  66. void FunctionPlot::set(const int index, const float v) {
  67. if ((index < 0) || (index > 255)) return;
  68. fval[index] = v;
  69. if (fval[index] > 1.0f) fval[index] = 1.0f;
  70. if (fval[index] < -1.0f) fval[index] = -1.0f;
  71. }
  72. float FunctionPlot::get(const int index) const {
  73. if ((index < 0) || (index > 255)) return (-10.0f);
  74. return fval[index];
  75. }
  76. ////////////////////////////////////////////
  77. WaveShaperPluginGUI::WaveShaperPluginGUI (int w, int h, WaveShaperPlugin *o, ChannelHandler *ch, const HostInfo *Info) :
  78. SpiralPluginGUI(w, h, o, ch)
  79. {
  80. fplot = new FunctionPlot(3, 20, 268, 195);
  81. fplot->box(FL_ENGRAVED_BOX);
  82. fplot->color(7);
  83. radio_polynomial = new Fl_Round_Button(3, 218, 30, 20, "S");
  84. radio_polynomial->down_box(FL_ROUND_DOWN_BOX);
  85. radio_polynomial->value(1);
  86. radio_polynomial->type(102);
  87. radio_polynomial->labelfont(12);
  88. radio_polynomial->labelsize(12);
  89. radio_polynomial->callback((Fl_Callback*)cb_radio);
  90. radio_sines = new Fl_Round_Button(3, 238, 30, 20, "S");
  91. radio_sines->down_box(FL_ROUND_DOWN_BOX);
  92. radio_sines->value(0);
  93. radio_sines->type(102);
  94. radio_sines->labelfont(12);
  95. radio_sines->labelsize(12);
  96. radio_sines->callback((Fl_Callback*)cb_radio);
  97. { Fl_Box* o = new Fl_Box(26, 218, 25, 20, "a .x");
  98. o->labelfont(2);
  99. o->labelsize(10);
  100. }
  101. { Fl_Box* o = new Fl_Box(33, 227, 10, 15, "i");
  102. o->labelfont(2);
  103. o->labelsize(10);
  104. }
  105. { Fl_Box* o = new Fl_Box(47, 217, 10, 15, "i");
  106. o->labelfont(2);
  107. o->labelsize(10);
  108. }
  109. { Fl_Box* o = new Fl_Box(31, 246, 10, 15, "i");
  110. o->labelfont(2);
  111. o->labelsize(10);
  112. }
  113. { Fl_Box* o = new Fl_Box(36, 237, 25, 20, "a .sin i x");
  114. o->labelfont(2);
  115. o->labelsize(10);
  116. }
  117. for (int i=0; i<6; i++) {
  118. knob[i] = new Fl_Knob (70+i*35, 220, 30, 30, "");
  119. knob[i]->color (GUI_COLOUR);
  120. knob[i]->type (Fl_Knob::DOTLIN);
  121. knob[i]->labelsize (10);
  122. knob[i]->maximum (1);
  123. knob[i]->minimum (-1);
  124. knob[i]->step (0.01);
  125. knob[i]->value (0);
  126. knob[i]->callback ((Fl_Callback*)cb_knob);
  127. }
  128. knob[0]->value(1.0);
  129. end();
  130. }
  131. void WaveShaperPluginGUI::UpdateValues (SpiralPlugin *o) {
  132. WaveShaperPlugin* Plugin = (WaveShaperPlugin*) o;
  133. int wt = Plugin->GetWaveType ();
  134. radio_polynomial->value (wt);
  135. radio_sines->value (!wt);
  136. for (int j=0; j<6; j++) knob[j]->value (Plugin->GetCoef (j));
  137. Update ();
  138. }
  139. void WaveShaperPluginGUI::Update () {
  140. // Formerly KnobCB
  141. float WTData[256];
  142. m_GUICH->GetData ("WT", (void*)WTData);
  143. for (int i=0; i<256; i++) fplot->set (i, WTData[i]);
  144. fplot->redraw ();
  145. }
  146. inline void WaveShaperPluginGUI::cb_radio_i (Fl_Round_Button*, void*) {
  147. m_GUICH->Set ("WaveType", (int)radio_polynomial->value ());
  148. m_GUICH->SetCommand (WaveShaperPlugin::SETWAVETYPE);
  149. }
  150. void WaveShaperPluginGUI::cb_radio (Fl_Round_Button* o, void* v) {
  151. ((WaveShaperPluginGUI*)(o->parent()))->cb_radio_i (o, v);
  152. }
  153. inline void WaveShaperPluginGUI::cb_knob_i (Fl_Knob* o, void* v) {
  154. for (int j=0; j<6; j++) {
  155. if (o==knob[j]) {
  156. m_GUICH->Set ("CoefNum", j);
  157. m_GUICH->Set ("CoefVal", (float)knob[j]->value ());
  158. m_GUICH->SetCommand (WaveShaperPlugin::SETCOEF);
  159. break;
  160. }
  161. }
  162. }
  163. void WaveShaperPluginGUI::cb_knob (Fl_Knob* o, void* v) {
  164. ((WaveShaperPluginGUI*)(o->parent()))->cb_knob_i (o, v);
  165. }
  166. const string WaveShaperPluginGUI::GetHelpText(const string &loc){
  167. return string("")
  168. + "This plugin simulates wave shaping as found on analogue\n"
  169. + "synths, usable in two modes, linear or sine based.\n";
  170. }