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.

185 lines
4.9KB

  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,const HostInfo *Info) :
  78. SpiralPluginGUI(w,h,o)
  79. {
  80. m_Plugin=o;
  81. fplot = new FunctionPlot(3, 20, 268, 195);
  82. fplot->box(FL_ENGRAVED_BOX);
  83. fplot->color(7);
  84. radio_polynomial = new Fl_Round_Button(3, 218, 30, 20, "S");
  85. radio_polynomial->down_box(FL_ROUND_DOWN_BOX);
  86. radio_polynomial->value(1);
  87. radio_polynomial->type(102);
  88. radio_polynomial->labelfont(12);
  89. radio_polynomial->labelsize(12);
  90. radio_polynomial->callback((Fl_Callback*)cb_radio);
  91. radio_sines = new Fl_Round_Button(3, 238, 30, 20, "S");
  92. radio_sines->down_box(FL_ROUND_DOWN_BOX);
  93. radio_sines->value(0);
  94. radio_sines->type(102);
  95. radio_sines->labelfont(12);
  96. radio_sines->labelsize(12);
  97. radio_sines->callback((Fl_Callback*)cb_radio);
  98. { Fl_Box* o = new Fl_Box(26, 218, 25, 20, "a .x");
  99. o->labelfont(2);
  100. o->labelsize(10);
  101. }
  102. { Fl_Box* o = new Fl_Box(33, 227, 10, 15, "i");
  103. o->labelfont(2);
  104. o->labelsize(10);
  105. }
  106. { Fl_Box* o = new Fl_Box(47, 217, 10, 15, "i");
  107. o->labelfont(2);
  108. o->labelsize(10);
  109. }
  110. { Fl_Box* o = new Fl_Box(31, 246, 10, 15, "i");
  111. o->labelfont(2);
  112. o->labelsize(10);
  113. }
  114. { Fl_Box* o = new Fl_Box(36, 237, 25, 20, "a .sin i x");
  115. o->labelfont(2);
  116. o->labelsize(10);
  117. }
  118. for (int i=0;i<6;i++)
  119. {
  120. knob[i] = new Fl_Knob(70+i*35, 220, 30, 30);
  121. knob[i]->labelsize(10);
  122. knob[i]->minimum(-1);
  123. knob[i]->step(0.01);
  124. knob[i]->value(0);
  125. knob[i]->color(GUI_COLOUR);
  126. knob[i]->callback((Fl_Callback*)cb_knob);
  127. knob[i]->type(Fl_Knob::DOTLIN);
  128. }
  129. knob[0]->value(1.0);
  130. end();
  131. }
  132. void WaveShaperPluginGUI::UpdateValues()
  133. {
  134. int wt = m_Plugin->GetWaveType();
  135. radio_polynomial->value(wt);
  136. radio_sines->value(!wt);
  137. for (int j=0; j<6; j++) knob[j]->value(m_Plugin->GetCoef(j));
  138. knobCB();
  139. }
  140. inline void WaveShaperPluginGUI::cb_radio_i(Fl_Round_Button*, void*) {
  141. m_Plugin->SetWaveType(radio_polynomial->value());
  142. knobCB();
  143. }
  144. void WaveShaperPluginGUI::cb_radio(Fl_Round_Button* o, void* v) {
  145. ((WaveShaperPluginGUI*)(o->parent()))->cb_radio_i(o,v);
  146. }
  147. inline void WaveShaperPluginGUI::cb_knob_i(Fl_Knob*, void*) {
  148. for (int j=0; j<6; j++) m_Plugin->SetCoef(j,knob[j]->value());
  149. knobCB();
  150. }
  151. void WaveShaperPluginGUI::cb_knob(Fl_Knob* o, void* v) {
  152. ((WaveShaperPluginGUI*)(o->parent()))->cb_knob_i(o,v);
  153. }
  154. void WaveShaperPluginGUI::knobCB() {
  155. int i;
  156. m_Plugin->Calc();
  157. for (i=0;i<256;i++)
  158. {
  159. fplot->set(i,m_Plugin->Get(i*2));
  160. }
  161. fplot->redraw();
  162. }