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.

292 lines
8.8KB

  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 "EnvelopePluginGUI.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 const float TIMED_SLIDER_MAX = 3.0f;
  25. ////////////////////////////////////////////
  26. EnvelopePluginGUI::EnvelopePluginGUI(int w, int h,EnvelopePlugin *o,ChannelHandler *ch,const HostInfo *Info) :
  27. SpiralPluginGUI(w,h,o,ch)
  28. {
  29. Thresh = new Fl_Slider(10, 20, 20, 70, "T");
  30. Thresh->type(4);
  31. Thresh->selection_color(GUI_COLOUR);
  32. Thresh->labelsize(10);
  33. Thresh->maximum(1.0);
  34. Thresh->step(0.01);
  35. Thresh->value(0.99f);
  36. Thresh->callback((Fl_Callback*)cb_Thresh);
  37. add(Thresh);
  38. Attack = new Fl_Slider(30, 20, 20, 70, "A");
  39. Attack->type(4);
  40. Attack->selection_color(GUI_COLOUR);
  41. Attack->labelsize(10);
  42. Attack->maximum(TIMED_SLIDER_MAX);
  43. Attack->step(0.01);
  44. Attack->value(3.0f);
  45. Attack->callback((Fl_Callback*)cb_Attack);
  46. add(Attack);
  47. Decay = new Fl_Slider(50, 20, 20, 70, "D");
  48. Decay->type(4);
  49. Decay->selection_color(GUI_COLOUR);
  50. Decay->labelsize(10);
  51. Decay->maximum(TIMED_SLIDER_MAX);
  52. Decay->step(0.01);
  53. Decay->value(2.29);
  54. Decay->callback((Fl_Callback*)cb_Decay);
  55. add(Decay);
  56. Sustain = new Fl_Slider(70, 20, 20, 70, "S");
  57. Sustain->type(4);
  58. Sustain->selection_color(GUI_COLOUR);
  59. Sustain->labelsize(10);
  60. Sustain->maximum(1);
  61. Sustain->step(0.01);
  62. Sustain->value(0.0);
  63. Sustain->callback((Fl_Callback*)cb_Sustain);
  64. add(Sustain);
  65. Release = new Fl_Slider(90, 20, 20, 70, "R");
  66. Release->type(4);
  67. Release->selection_color(GUI_COLOUR);
  68. Release->labelsize(10);
  69. Release->maximum(TIMED_SLIDER_MAX);
  70. Release->step(0.01);
  71. Release->value(2.0);
  72. Release->callback((Fl_Callback*)cb_Release);
  73. add(Release);
  74. Volume = new Fl_Slider(110, 20, 20, 70, "V");
  75. Volume->type(4);
  76. Volume->selection_color(GUI_COLOUR);
  77. Volume->labelsize(10);
  78. Volume->maximum(1);
  79. Volume->step(0.01);
  80. Volume->value(0.5f);
  81. Volume->callback((Fl_Callback*)cb_Volume);
  82. add(Volume);
  83. m_pop = new Fl_Button(1,h-14, 13, 13, "@>");
  84. m_pop->type(1);
  85. m_pop->box(FL_FLAT_BOX);
  86. m_pop->down_box(FL_FLAT_BOX);
  87. m_pop->labeltype(FL_SYMBOL_LABEL);
  88. m_pop->labelsize(10);
  89. m_pop->labelcolor(25);
  90. m_pop->callback((Fl_Callback*)cb_pop);
  91. m_out_thresh = new Fl_Output(15,h+5, 48, 15, "T");
  92. m_out_thresh->box(FL_ENGRAVED_BOX);
  93. m_out_thresh->color(16);
  94. m_out_thresh->labelsize(10);
  95. m_out_thresh->textsize(10);
  96. m_out_thresh->hide();
  97. m_out_thresh->set_output();
  98. m_out_attack = new Fl_Output(15,h+22, 48, 15, "A");
  99. m_out_attack->box(FL_ENGRAVED_BOX);
  100. m_out_attack->color(16);
  101. m_out_attack->labelsize(10);
  102. m_out_attack->textsize(10);
  103. m_out_attack->hide();
  104. m_out_attack->set_output();
  105. m_out_decay = new Fl_Output(15,h+39, 48, 15, "D");
  106. m_out_decay->box(FL_ENGRAVED_BOX);
  107. m_out_decay->color(16);
  108. m_out_decay->labelsize(10);
  109. m_out_decay->textsize(10);
  110. m_out_decay->hide();
  111. m_out_decay->set_output();
  112. m_out_sustain = new Fl_Output(87,h+5, 48, 15, "S");
  113. m_out_sustain->box(FL_ENGRAVED_BOX);
  114. m_out_sustain->color(16);
  115. m_out_sustain->labelsize(10);
  116. m_out_sustain->textsize(10);
  117. m_out_sustain->hide();
  118. m_out_sustain->set_output();
  119. m_out_release = new Fl_Output(87,h+22, 48, 15, "R");
  120. m_out_release->box(FL_ENGRAVED_BOX);
  121. m_out_release->color(16);
  122. m_out_release->labelsize(10);
  123. m_out_release->textsize(10);
  124. m_out_release->hide();
  125. m_out_release->set_output();
  126. m_out_volume = new Fl_Output(87,h+39, 48, 15, "V");
  127. m_out_volume->box(FL_ENGRAVED_BOX);
  128. m_out_volume->color(16);
  129. m_out_volume->labelsize(10);
  130. m_out_volume->textsize(10);
  131. m_out_volume->hide();
  132. m_out_volume->set_output();
  133. end();
  134. }
  135. extern "C" int sprintf(char *,const char *,...);
  136. void EnvelopePluginGUI::UpdateValues(SpiralPlugin *o)
  137. {
  138. EnvelopePlugin *Plugin = (EnvelopePlugin*)o;
  139. Thresh->value(1.0f-Plugin->GetTrigThresh());
  140. Attack->value(TIMED_SLIDER_MAX-sqrt(Plugin->GetAttack()));
  141. Decay->value(TIMED_SLIDER_MAX-sqrt(Plugin->GetDecay()));
  142. Sustain->value(1.0f-Plugin->GetSustain());
  143. Release->value(TIMED_SLIDER_MAX-sqrt(Plugin->GetRelease()));
  144. Volume->value(1.0f-Plugin->GetVolume());
  145. char str[10];
  146. sprintf(str,"%4.0f %%", 100*Plugin->GetTrigThresh());
  147. m_out_thresh->value(str);
  148. sprintf(str,"%5.3f s", Plugin->GetAttack());
  149. m_out_attack->value(str);
  150. sprintf(str,"%5.3f s", Plugin->GetDecay());
  151. m_out_decay->value(str);
  152. sprintf(str,"%4.0f %%", 100*Plugin->GetSustain());
  153. m_out_sustain->value(str);
  154. sprintf(str,"%5.3f s", Plugin->GetRelease());
  155. m_out_release->value(str);
  156. sprintf(str,"%4.0f %%", 100*Plugin->GetVolume());
  157. m_out_volume->value(str);
  158. }
  159. inline void EnvelopePluginGUI::cb_Thresh_i(Fl_Slider* o, void* v)
  160. {
  161. char str[10];
  162. m_GUICH->Set("Trig",(float)(1.0f-o->value()));
  163. sprintf(str,"%4.0f %%", 100*(1.0f-o->value()));
  164. m_out_thresh->value(str);
  165. }
  166. void EnvelopePluginGUI::cb_Thresh(Fl_Slider* o, void* v)
  167. { ((EnvelopePluginGUI*)(o->parent()))->cb_Thresh_i(o,v); }
  168. inline void EnvelopePluginGUI::cb_Attack_i(Fl_Slider* o, void* v)
  169. {
  170. char str[10];
  171. float value=TIMED_SLIDER_MAX-o->value();
  172. m_GUICH->Set("Attack",value*value);
  173. sprintf(str,"%5.3f s", value*value);
  174. m_out_attack->value(str);
  175. }
  176. void EnvelopePluginGUI::cb_Attack(Fl_Slider* o, void* v)
  177. { ((EnvelopePluginGUI*)(o->parent()))->cb_Attack_i(o,v); }
  178. inline void EnvelopePluginGUI::cb_Decay_i(Fl_Slider* o, void* v)
  179. {
  180. char str[10];
  181. float value=TIMED_SLIDER_MAX-o->value();
  182. m_GUICH->Set("Decay",value*value);
  183. sprintf(str,"%5.3f s", value*value);
  184. m_out_decay->value(str);
  185. }
  186. void EnvelopePluginGUI::cb_Decay(Fl_Slider* o, void* v)
  187. { ((EnvelopePluginGUI*)(o->parent()))->cb_Decay_i(o,v); }
  188. inline void EnvelopePluginGUI::cb_Sustain_i(Fl_Slider* o, void* v)
  189. {
  190. char str[10];
  191. m_GUICH->Set("Sustain",(float)(1.0f-o->value()));
  192. sprintf(str,"%4.0f %%", 100*(1.0f-o->value()));
  193. m_out_sustain->value(str);
  194. }
  195. void EnvelopePluginGUI::cb_Sustain(Fl_Slider* o, void* v)
  196. { ((EnvelopePluginGUI*)(o->parent()))->cb_Sustain_i(o,v); }
  197. inline void EnvelopePluginGUI::cb_Release_i(Fl_Slider* o, void* v)
  198. {
  199. char str[10];
  200. float value=TIMED_SLIDER_MAX-o->value();
  201. m_GUICH->Set("Release",value*value);
  202. sprintf(str,"%5.3f s", value*value);
  203. m_out_release->value(str);
  204. }
  205. void EnvelopePluginGUI::cb_Release(Fl_Slider* o, void* v)
  206. { ((EnvelopePluginGUI*)(o->parent()))->cb_Release_i(o,v); }
  207. inline void EnvelopePluginGUI::cb_Volume_i(Fl_Slider* o, void* v)
  208. {
  209. char str[10];
  210. m_GUICH->Set("Volume",(float)(1.0f-o->value()));
  211. sprintf(str,"%4.0f %%", (float)(100.0f*(1.0f-o->value())));
  212. m_out_volume->value(str);
  213. }
  214. void EnvelopePluginGUI::cb_Volume(Fl_Slider* o, void* v)
  215. { ((EnvelopePluginGUI*)(o->parent()))->cb_Volume_i(o,v); }
  216. inline void EnvelopePluginGUI::cb_pop_i(Fl_Button *o, void*) {
  217. if (o->value())
  218. {
  219. o->label("@2>");
  220. m_out_thresh->show();
  221. m_out_attack->show();
  222. m_out_decay->show();
  223. m_out_sustain->show();
  224. m_out_release->show();
  225. redraw();
  226. }
  227. else
  228. {
  229. o->label("@>");
  230. m_out_thresh->hide();
  231. m_out_attack->hide();
  232. m_out_decay->hide();
  233. m_out_sustain->hide();
  234. m_out_release->hide();
  235. redraw();
  236. parent()->redraw();
  237. }
  238. }
  239. void EnvelopePluginGUI::cb_pop(Fl_Button* o, void* v) {
  240. ((EnvelopePluginGUI*)(o->parent()))->cb_pop_i(o,v);
  241. }
  242. const string EnvelopePluginGUI::GetHelpText(const string &loc){
  243. return string("")
  244. + "An ADSR envelope. This plugin also has a built in\n"
  245. + "amplifier for signals, so data fed through the Input\n"
  246. + "and Output are amplified according to the envelope value.\n"
  247. + "The envelope is triggered with an input CV, and the output\n"
  248. + "CV is the value of the envelope at that time. The signal\n"
  249. + "level needed to trigger the envelope can be set using\n"
  250. + "the \"T\" slider, also the volume level of the output can\n"
  251. + "be set with the \"V\" slider.\n\n"
  252. + "This envelope can be used to mimic audio triggered effects\n"
  253. + "units, by feeding the audio signal into the trigger CV.\n"
  254. + "In fact, the envelope plugin itself can be made into a\n"
  255. + "compressor, by feeding the audio signal into both inputs,\n"
  256. + "and tweaking the ADSR values. \n";
  257. }