Assists music production by grouping standalone programs into sessions. Community version of "Non Session Manager".
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.

339 lines
7.9KB

  1. /*******************************************************************************/
  2. /* Copyright (C) 2008 Jonathan Moore Liles */
  3. /* */
  4. /* This program is free software; you can redistribute it and/or modify it */
  5. /* under the terms of the GNU General Public License as published by the */
  6. /* Free Software Foundation; either version 2 of the License, or (at your */
  7. /* option) any later version. */
  8. /* */
  9. /* This program is distributed in the hope that it will be useful, but WITHOUT */
  10. /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
  11. /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */
  12. /* more details. */
  13. /* */
  14. /* You should have received a copy of the GNU General Public License along */
  15. /* with This program; see the file COPYING. If not,write to the Free Software */
  16. /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  17. /*******************************************************************************/
  18. #include "Panner.H"
  19. #include <stdio.h>
  20. #include <math.h>
  21. /* 2D Panner widget. Supports various multichannel configurations. */
  22. Panner::Point *Panner::drag;
  23. /* multichannel layouts, in degrees */
  24. int Panner::_configs[][12] =
  25. {
  26. /* none, error condition? */
  27. { NONE },
  28. /* mono, panner disabled */
  29. { NONE },
  30. /* stereo */
  31. { L, R },
  32. /* stereo + mono */
  33. { L, R, C },
  34. /* quad */
  35. { FL, FR, RL, RR },
  36. /* 5.1 */
  37. { FL, FR, RL, RR, C },
  38. /* no such config */
  39. { NONE },
  40. /* 7.1 */
  41. { FL, FR, RL, RR, C, L, R },
  42. };
  43. /* speaker symbol */
  44. #define BP fl_begin_polygon()
  45. #define EP fl_end_polygon()
  46. #define BCP fl_begin_complex_polygon()
  47. #define ECP fl_end_complex_polygon()
  48. #define BL fl_begin_line()
  49. #define EL fl_end_line()
  50. #define BC fl_begin_loop()
  51. #define EC fl_end_loop()
  52. #define vv(x,y) fl_vertex(x,y)
  53. static void draw_speaker ( Fl_Color col )
  54. {
  55. fl_color(col);
  56. BP; vv(0.2,0.4); vv(0.6,0.4); vv(0.6,-0.4); vv(0.2,-0.4); EP;
  57. BP; vv(-0.6,0.8); vv(0.2,0.0); vv(-0.6,-0.8); EP;
  58. fl_color( fl_darker( col ) );
  59. BC; vv(0.2,0.4); vv(0.6,0.4); vv(0.6,-0.4); vv(0.2,-0.4); EC;
  60. BC; vv(-0.6,0.8); vv(0.2,0.0); vv(-0.6,-0.8); EC;
  61. }
  62. /** set X, Y, W, and H to the bounding box of point /p/ in screen coords */
  63. void
  64. Panner::point_bbox ( const Point *p, int *X, int *Y, int *W, int *H ) const
  65. {
  66. int tx, ty, tw, th;
  67. bbox( tx, ty, tw, th );
  68. tw -= pw();
  69. th -= ph();
  70. float px, py;
  71. p->axes( &px, &py );
  72. *X = tx + ((tw / 2) * px + (tw / 2));
  73. *Y = ty + ((th / 2) * py + (th / 2));
  74. *W = pw();
  75. *H = ph();
  76. }
  77. Panner::Point *
  78. Panner::event_point ( void )
  79. {
  80. for ( int i = _ins; i--; )
  81. {
  82. int px, py, pw, ph;
  83. Point *p = &_points[ i ];
  84. point_bbox( p, &px, &py, &pw, &ph );
  85. // printf( "%d, %d -- %d %d %d %d\n", Fl::event_x(), Fl::event_y(), px, py, pw, ph );
  86. if ( Fl::event_inside( px, py, pw, ph ) )
  87. return p;
  88. }
  89. return NULL;
  90. }
  91. void
  92. Panner::draw ( void )
  93. {
  94. draw_box();
  95. // draw_box( FL_FLAT_BOX, x(), y(), w(), h(), FL_BLACK );
  96. draw_label();
  97. if ( _bypassed )
  98. {
  99. fl_color( 0 );
  100. fl_font( FL_HELVETICA, 12 );
  101. fl_draw( "(bypass)", x(), y(), w(), h(), FL_ALIGN_CENTER );
  102. return;
  103. }
  104. int tw, th, tx, ty;
  105. bbox( tx, ty, tw, th );
  106. fl_push_clip( tx, ty, tw, th );
  107. fl_color( FL_RED );
  108. const int b = 10;
  109. tx += b;
  110. ty += b;
  111. tw -= b * 2;
  112. th -= b * 2;
  113. /* draw perimeter */
  114. {
  115. Fl_Color c1, c2;
  116. int iter;
  117. if ( Fl::belowmouse() == this )
  118. {
  119. iter = 12;
  120. c1 = fl_darker( FL_RED );
  121. c2 = FL_GRAY;
  122. }
  123. else
  124. {
  125. iter = 6;
  126. c1 = FL_GRAY;
  127. c2 = FL_BLACK;
  128. }
  129. Fl_Color c = c1;
  130. for ( int i = iter; i--; )
  131. {
  132. fl_color( c );
  133. fl_arc( tx + (i * (tw / iter)) / 2, ty + (i * (th / iter)) / 2, tw - (i * (tw / iter)), th - (i * ( th / iter )), 0, 360 );
  134. c = fl_color_average( c1, c2, (float)i / iter);
  135. }
  136. }
  137. /* fl_color( FL_WHITE ); */
  138. /* fl_arc( tx, ty, tw, th, 0, 360 ); */
  139. if ( _configs[ _outs ][0] >= 0 )
  140. {
  141. for ( int i = _outs; i--; )
  142. {
  143. int a = _configs[ _outs ][ i ];
  144. Point p( 1.2f, (float)a );
  145. float px, py;
  146. p.axes( &px, &py );
  147. fl_push_matrix();
  148. const int bx = tx + ((tw / 2) * px + (tw / 2));
  149. const int by = ty + ((th / 2) * py + (th / 2));
  150. fl_translate( bx, by );
  151. fl_scale( 5, 5 );
  152. a = 90 - a;
  153. fl_rotate( a );
  154. draw_speaker( FL_WHITE );
  155. fl_rotate( -a );
  156. fl_pop_matrix();
  157. }
  158. }
  159. /* ensure that points are drawn *inside* the circle */
  160. for ( int i = _ins; i--; )
  161. {
  162. Point *p = &_points[ i ];
  163. Fl_Color c = (Fl_Color)(10 + i);
  164. int px, py, pw, ph;
  165. point_bbox( p, &px, &py, &pw, &ph );
  166. /* draw point */
  167. if ( p != drag )
  168. fl_color( c );
  169. else
  170. fl_color( FL_WHITE );
  171. fl_pie( px, py, pw, ph, 0, 360 );
  172. /* draw echo */
  173. fl_color( c = fl_darker( c ) );
  174. fl_arc( px - 5, py - 5, pw + 10, ph + 10, 0, 360 );
  175. if ( Fl::belowmouse() == this )
  176. {
  177. fl_color( c = fl_darker( c ) );
  178. fl_arc( px - 10, py - 10, pw + 20, ph + 20, 0, 360 );
  179. fl_color( c = fl_darker( c ) );
  180. fl_arc( px - 30, py - 30, pw + 60, ph + 60, 0, 360 );
  181. }
  182. /* draw number */
  183. char pat[4];
  184. snprintf( pat, 4, "%d", i + 1 );
  185. fl_color( FL_BLACK );
  186. fl_font( FL_HELVETICA, ph + 2 );
  187. fl_draw( pat, px + 1, py + 1, pw - 1, ph - 1, FL_ALIGN_CENTER );
  188. /* draw line */
  189. /* fl_color( FL_WHITE ); */
  190. /* fl_line( bx + pw() / 2, by + ph() / 2, tx + (tw / 2), ty + (th / 2) ); */
  191. }
  192. fl_pop_clip();
  193. }
  194. /* return the current gain setting for the path in/out */
  195. Panner::Point *
  196. Panner::point( int i )
  197. {
  198. return &_points[ i ];
  199. }
  200. int
  201. Panner::handle ( int m )
  202. {
  203. int r = Fl_Widget::handle( m );
  204. switch ( m )
  205. {
  206. case FL_ENTER:
  207. case FL_LEAVE:
  208. redraw();
  209. return 1;
  210. case FL_PUSH:
  211. if ( Fl::event_button2() )
  212. {
  213. _bypassed = ! _bypassed;
  214. redraw();
  215. return 1;
  216. }
  217. else if ( Fl::event_button1() && ( drag = event_point() ) )
  218. return 1;
  219. else
  220. return 0;
  221. case FL_RELEASE:
  222. if ( Fl::event_button1() && drag )
  223. {
  224. drag = NULL;
  225. do_callback();
  226. redraw();
  227. return 1;
  228. }
  229. else
  230. return 0;
  231. case FL_MOUSEWHEEL:
  232. {
  233. /* TODO: place point on opposite face of sphere */
  234. }
  235. case FL_DRAG:
  236. {
  237. if ( ! drag )
  238. return 0;
  239. float X = Fl::event_x() - x();
  240. float Y = Fl::event_y() - y();
  241. int tx, ty, tw, th;
  242. bbox( tx, ty, tw, th );
  243. /* if ( _outs < 3 ) */
  244. /* drag->angle( (float)(X / (tw / 2)) - 1.0f, 0.0f ); */
  245. /* else */
  246. drag->angle( (float)(X / (tw / 2)) - 1.0f, (float)(Y / (th / 2)) - 1.0f );
  247. if ( when() & FL_WHEN_CHANGED )
  248. do_callback();
  249. redraw();
  250. return 1;
  251. }
  252. }
  253. return r;
  254. // return 0;
  255. }