DPF Plugin examples
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.

287 lines
8.0KB

  1. /*
  2. * Author: Harry van Haaren 2013
  3. * harryhaaren@gmail.com
  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., 51 Franklin Street, Fifth Floor, Boston,
  18. * MA 02110-1301, USA.
  19. *
  20. */
  21. #ifndef AVTK_SIDECHAIN_GAIN_H
  22. #define AVTK_SIDECHAIN_GAIN_H
  23. #include <FL/Fl_Widget.H>
  24. #include <FL/Fl_Slider.H>
  25. #include <valarray>
  26. #include <string>
  27. namespace Avtk
  28. {
  29. class SidechainGain : public Fl_Slider
  30. {
  31. public:
  32. SidechainGain(int _x, int _y, int _w, int _h, const char *_label = 0):
  33. Fl_Slider(_x, _y, _w, _h, _label)
  34. {
  35. x = _x;
  36. y = _y;
  37. w = _w;
  38. h = _h;
  39. label = _label;
  40. mouseClickedX = 0;
  41. mouseClickedY = 0;
  42. mouseClicked = false;
  43. active = true;
  44. highlight = false;
  45. _threshold = 1.0;
  46. _target = 1.f;
  47. _reduce = 1.f;
  48. _release = 0.5;
  49. _sidechainAmp = 0;
  50. }
  51. void threshold(float t) {_threshold = t; redraw();}
  52. void reduce (float r) {_reduce = r; redraw();}
  53. void release (float r) {_release = r; redraw();}
  54. /// sets the sidechain amplitude
  55. void sidechain(float s) {_sidechainAmp = s; redraw();}
  56. bool active;
  57. bool highlight;
  58. int x, y, w, h;
  59. const char* label;
  60. int mouseClickedX;
  61. int mouseClickedY;
  62. bool mouseClicked;
  63. bool mouseRightClicked;
  64. float _threshold;
  65. float _target;
  66. float _reduce;
  67. float _release;
  68. float _sidechainAmp;
  69. void set_active(bool a)
  70. {
  71. active = a;
  72. redraw();
  73. }
  74. void draw()
  75. {
  76. if (damage() & FL_DAMAGE_ALL)
  77. {
  78. cairo_t *cr = Fl::cairo_cc();
  79. cairo_save( cr );
  80. cairo_set_line_width(cr, 1.5);
  81. // fill background
  82. cairo_rectangle( cr, x, y, w, h);
  83. cairo_set_source_rgb( cr, 28 / 255.f, 28 / 255.f , 28 / 255.f );
  84. cairo_fill_preserve( cr );
  85. cairo_clip( cr );
  86. // set up dashed lines, 1 px off, 1 px on
  87. double dashes[1];
  88. dashes[0] = 2.0;
  89. cairo_set_dash ( cr, dashes, 1, 0.0);
  90. cairo_set_line_width( cr, 1.0);
  91. // loop over each 2nd line, drawing dots
  92. cairo_set_line_width(cr, 1.0);
  93. cairo_set_source_rgb(cr, 0.4,0.4,0.4);
  94. for ( int i = 0; i < 4; i++ )
  95. {
  96. cairo_move_to( cr, x + ((w / 4.f)*i), y );
  97. cairo_line_to( cr, x + ((w / 4.f)*i), y + h );
  98. }
  99. for ( int i = 0; i < 4; i++ )
  100. {
  101. cairo_move_to( cr, x , y + ((h / 4.f)*i) );
  102. cairo_line_to( cr, x + w, y + ((h / 4.f)*i) );
  103. }
  104. cairo_set_source_rgba( cr, 66 / 255.f, 66 / 255.f , 66 / 255.f , 0.5 );
  105. cairo_stroke(cr);
  106. cairo_set_dash ( cr, dashes, 0, 0.0);
  107. // draw threshold / ducked line
  108. cairo_move_to( cr, x + w * 0.750 - (w * 0.5 * (1-_threshold)), y );
  109. cairo_line_to( cr, x + w * 0.750 - (w * 0.5 * (1-_threshold)) + _sidechainAmp* _reduce*( w * 0.5 ), y + h / 2 );
  110. cairo_line_to( cr, x + w * 0.750 - (w * 0.5 * (1-_threshold)), y + h );
  111. cairo_line_to( cr, x + w , y + h );
  112. cairo_line_to( cr, x + w , y );
  113. cairo_close_path( cr );
  114. cairo_set_source_rgba( cr, 0 / 255.f, 153 / 255.f , 255 / 255.f , 0.21 );
  115. cairo_fill_preserve( cr );
  116. cairo_set_source_rgba( cr, 0 / 255.f, 153 / 255.f , 255 / 255.f , 1 );
  117. cairo_stroke( cr );
  118. // _sidechainAmp => arrow
  119. cairo_move_to( cr, x + w * 0.00 * _sidechainAmp, y + h * 0.4 - (h*0.1*_sidechainAmp) );
  120. cairo_line_to( cr, x + w * 0.65 * _sidechainAmp, y + h * 0.4 );
  121. cairo_line_to( cr, x + w * 0.1 + w * 0.65 * _sidechainAmp, y + h * 0.5 );
  122. cairo_line_to( cr, x + w * 0.65 * _sidechainAmp, y + h * 0.6 );
  123. cairo_line_to( cr, x + w * 0.00 * _sidechainAmp, y + h * 0.6 + (h*0.1*_sidechainAmp) );
  124. cairo_close_path( cr );
  125. cairo_set_source_rgba( cr, 1.0, 0.48, 0.f , 0.21 );
  126. cairo_fill_preserve( cr );
  127. cairo_set_source_rgba( cr, 1.0, 0.48, 0.f , 1 );
  128. cairo_stroke( cr );
  129. // _release horizontal line
  130. cairo_move_to( cr, x , y + h * 0.25 + h/2 * _release );
  131. cairo_line_to( cr, x + w, y + h * 0.25 + h/2 * _release );
  132. cairo_set_source_rgba( cr, 1.0, 0.0, 0.f , 1 );
  133. cairo_stroke( cr );
  134. // stroke outline
  135. cairo_rectangle(cr, x+1, y+1, w-2, h-2);
  136. cairo_set_source_rgba( cr, 126 / 255.f, 126 / 255.f , 126 / 255.f , 0.8 );
  137. cairo_set_line_width(cr, 1.0);
  138. cairo_stroke( cr );
  139. if ( !active )
  140. {
  141. // big grey X
  142. cairo_set_line_width(cr, 20.0);
  143. cairo_set_source_rgba(cr, 0.4,0.4,0.4, 0.7);
  144. cairo_move_to( cr, x + (3 * w / 4.f), y + ( h / 4.f ) );
  145. cairo_line_to( cr, x + (w / 4.f), y + ( 3 *h / 4.f ) );
  146. cairo_move_to( cr, x + (w / 4.f), y + ( h / 4.f ) );
  147. cairo_line_to( cr, x + (3 * w / 4.f), y + ( 3 *h / 4.f ) );
  148. cairo_set_line_cap ( cr, CAIRO_LINE_CAP_BUTT);
  149. cairo_stroke( cr );
  150. }
  151. cairo_restore( cr );
  152. }
  153. }
  154. void resize(int X, int Y, int W, int H)
  155. {
  156. Fl_Widget::resize(X,Y,W,H);
  157. x = X;
  158. y = Y;
  159. w = W;
  160. h = H;
  161. redraw();
  162. }
  163. int handle(int event)
  164. {
  165. /*
  166. switch(event)
  167. {
  168. case FL_PUSH:
  169. highlight = 0;
  170. mouseRightClicked = false;
  171. if ( Fl::event_button() == FL_RIGHT_MOUSE )
  172. {
  173. active = !active;
  174. redraw();
  175. mouseRightClicked = true;
  176. do_callback();
  177. }
  178. return 1;
  179. case FL_DRAG:
  180. {
  181. if ( Fl::event_state(FL_BUTTON1) )
  182. {
  183. if ( mouseClicked == false ) // catch the "click" event
  184. {
  185. mouseClickedX = Fl::event_x();
  186. mouseClickedY = Fl::event_y();
  187. mouseClicked = true;
  188. }
  189. float deltaX = mouseClickedX - Fl::event_x();
  190. float deltaY = mouseClickedY - Fl::event_y();
  191. float valX = value();
  192. valX -= deltaX / 100.f;
  193. float valY = makeupGain;
  194. valY += deltaY / 100.f;
  195. if ( valX > 1.0 ) valX = 1.0;
  196. if ( valX < 0.0 ) valX = 0.0;
  197. if ( valY > 1.0 ) valY = 1.0;
  198. if ( valY < 0.0 ) valY = 0.0;
  199. //handle_drag( value + deltaY );
  200. set_value( valX );
  201. makeupGain = valY;
  202. mouseClickedX = Fl::event_x();
  203. mouseClickedY = Fl::event_y();
  204. redraw();
  205. do_callback();
  206. }
  207. }
  208. return 1;
  209. case FL_RELEASE:
  210. mouseRightClicked = false;
  211. if (highlight) {
  212. highlight = 0;
  213. redraw();
  214. do_callback();
  215. }
  216. mouseClicked = false;
  217. return 1;
  218. case FL_SHORTCUT:
  219. if ( test_shortcut() )
  220. {
  221. do_callback();
  222. return 1;
  223. }
  224. return 0;
  225. default:
  226. return Fl_Widget::handle(event);
  227. }
  228. */
  229. return 0;
  230. }
  231. private:
  232. };
  233. } // Avtk
  234. #endif // AVTK_SIDECHAIN_GAIN_H