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.

303 lines
7.1KB

  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. /* multichannel layouts, in degrees */
  23. int Panner::_configs[][12] =
  24. {
  25. /* none, error condition? */
  26. { NONE },
  27. /* mono, panner disabled */
  28. { NONE },
  29. /* stereo */
  30. { L, R },
  31. /* stereo + mono */
  32. { L, R, C },
  33. /* quad */
  34. { FL, FR, RL, RR },
  35. /* 5.1 */
  36. { FL, FR, RL, RR, C },
  37. /* no such config */
  38. { NONE },
  39. /* 7.1 */
  40. { FL, FR, RL, RR, C, L, R },
  41. };
  42. /* speaker symbol */
  43. #define BP fl_begin_polygon()
  44. #define EP fl_end_polygon()
  45. #define BCP fl_begin_complex_polygon()
  46. #define ECP fl_end_complex_polygon()
  47. #define BL fl_begin_line()
  48. #define EL fl_end_line()
  49. #define BC fl_begin_loop()
  50. #define EC fl_end_loop()
  51. #define vv(x,y) fl_vertex(x,y)
  52. static void draw_speaker ( Fl_Color col )
  53. {
  54. fl_color(col);
  55. BP; vv(0.2,0.4); vv(0.6,0.4); vv(0.6,-0.4); vv(0.2,-0.4); EP;
  56. BP; vv(-0.6,0.8); vv(0.2,0.0); vv(-0.6,-0.8); EP;
  57. fl_color( fl_darker( col ) );
  58. BC; vv(0.2,0.4); vv(0.6,0.4); vv(0.6,-0.4); vv(0.2,-0.4); EC;
  59. BC; vv(-0.6,0.8); vv(0.2,0.0); vv(-0.6,-0.8); EC;
  60. }
  61. /** set X, Y, W, and H to the bounding box of point /p/ in screen coords */
  62. void
  63. Panner::point_bbox ( const Point *p, int *X, int *Y, int *W, int *H ) const
  64. {
  65. int tx, ty, tw, th;
  66. bbox( tx, ty, tw, th );
  67. tw -= pw();
  68. th -= ph();
  69. float px, py;
  70. p->axes( &px, &py );
  71. *X = tx + ((tw / 2) * px + (tw / 2));
  72. *Y = ty + ((th / 2) * py + (th / 2));
  73. *W = pw();
  74. *H = ph();
  75. }
  76. Panner::Point *
  77. Panner::event_point ( void )
  78. {
  79. for ( int i = _ins; i--; )
  80. {
  81. int px, py, pw, ph;
  82. Point *p = &_points[ i ];
  83. point_bbox( p, &px, &py, &pw, &ph );
  84. // printf( "%d, %d -- %d %d %d %d\n", Fl::event_x(), Fl::event_y(), px, py, pw, ph );
  85. if ( Fl::event_inside( px, py, pw, ph ) )
  86. return p;
  87. }
  88. return NULL;
  89. }
  90. void
  91. Panner::draw ( void )
  92. {
  93. draw_box();
  94. // draw_box( FL_FLAT_BOX, x(), y(), w(), h(), FL_BLACK );
  95. draw_label();
  96. if ( _bypassed )
  97. {
  98. fl_color( 0 );
  99. fl_font( FL_HELVETICA, 12 );
  100. fl_draw( "(bypass)", x(), y(), w(), h(), FL_ALIGN_CENTER );
  101. return;
  102. }
  103. int tw, th, tx, ty;
  104. bbox( tx, ty, tw, th );
  105. fl_push_clip( tx, ty, tw, th );
  106. fl_color( FL_WHITE );
  107. const int b = 10;
  108. tx += b;
  109. ty += b;
  110. tw -= b * 2;
  111. th -= b * 2;
  112. /* draw perimeter */
  113. {
  114. Fl_Color c = FL_RED;
  115. const int iter = 8;
  116. for ( int i = iter; i--; )
  117. {
  118. fl_color( c );
  119. fl_arc( tx + (i * (tw / iter)) / 2, ty + (i * (th / iter)) / 2, tw - (i * (tw / iter)), th - (i * ( th / iter )), 0, 360 );
  120. c = fl_color_average( FL_RED, FL_GRAY, (float)i / iter);
  121. }
  122. }
  123. /* fl_color( FL_WHITE ); */
  124. /* fl_arc( tx, ty, tw, th, 0, 360 ); */
  125. if ( _configs[ _outs ][0] >= 0 )
  126. {
  127. for ( int i = _outs; i--; )
  128. {
  129. int a = _configs[ _outs ][ i ];
  130. Point p( 1.2f, (float)a );
  131. float px, py;
  132. p.axes( &px, &py );
  133. fl_push_matrix();
  134. const int bx = tx + ((tw / 2) * px + (tw / 2));
  135. const int by = ty + ((th / 2) * py + (th / 2));
  136. fl_translate( bx, by );
  137. fl_scale( 5, 5 );
  138. a = 90 - a;
  139. fl_rotate( a );
  140. draw_speaker( FL_WHITE );
  141. fl_rotate( -a );
  142. fl_pop_matrix();
  143. }
  144. }
  145. /* ensure that points are drawn *inside* the circle */
  146. for ( int i = _ins; i--; )
  147. {
  148. Point *p = &_points[ i ];
  149. Fl_Color c = (Fl_Color)(10 + i);
  150. int px, py, pw, ph;
  151. point_bbox( p, &px, &py, &pw, &ph );
  152. /* draw point */
  153. fl_color( c );
  154. fl_pie( px, py, pw, ph, 0, 360 );
  155. /* draw echo */
  156. fl_color( c = fl_darker( c ) );
  157. fl_arc( px - 5, py - 5, pw + 10, ph + 10, 0, 360 );
  158. fl_color( c = fl_darker( c ) );
  159. fl_arc( px - 10, py - 10, pw + 20, ph + 20, 0, 360 );
  160. fl_color( c = fl_darker( c ) );
  161. fl_arc( px - 30, py - 30, pw + 60, ph + 60, 0, 360 );
  162. /* draw number */
  163. char pat[4];
  164. snprintf( pat, 4, "%d", i + 1 );
  165. fl_color( FL_BLACK );
  166. fl_font( FL_HELVETICA, ph + 2 );
  167. fl_draw( pat, px + 1, py + 1, pw - 1, ph - 1, FL_ALIGN_CENTER );
  168. /* draw line */
  169. /* fl_color( FL_WHITE ); */
  170. /* fl_line( bx + pw() / 2, by + ph() / 2, tx + (tw / 2), ty + (th / 2) ); */
  171. }
  172. fl_pop_clip();
  173. }
  174. /* return the current gain setting for the path in/out */
  175. Panner::Point
  176. Panner::point( int i )
  177. {
  178. return _points[ i ];
  179. }
  180. int
  181. Panner::handle ( int m )
  182. {
  183. static Point *drag;
  184. int r = Fl_Widget::handle( m );
  185. switch ( m )
  186. {
  187. case FL_PUSH:
  188. if ( Fl::event_button2() )
  189. {
  190. _bypassed = ! _bypassed;
  191. redraw();
  192. return 0;
  193. }
  194. else if ( Fl::event_button1() && ( drag = event_point() ) )
  195. return 1;
  196. else
  197. return 0;
  198. case FL_RELEASE:
  199. drag = NULL;
  200. do_callback();
  201. return 1;
  202. case FL_MOUSEWHEEL:
  203. {
  204. /* TODO: place point on opposite face of sphere */
  205. }
  206. case FL_DRAG:
  207. {
  208. float X = Fl::event_x() - x();
  209. float Y = Fl::event_y() - y();
  210. int tx, ty, tw, th;
  211. bbox( tx, ty, tw, th );
  212. /* if ( _outs < 3 ) */
  213. /* drag->angle( (float)(X / (tw / 2)) - 1.0f, 0.0f ); */
  214. /* else */
  215. drag->angle( (float)(X / (tw / 2)) - 1.0f, (float)(Y / (th / 2)) - 1.0f );
  216. redraw();
  217. return 1;
  218. }
  219. }
  220. return r;
  221. // return 0;
  222. }