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.

284 lines
6.7KB

  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. fl_arc( tx, ty, tw, th, 0, 360 );
  113. if ( _configs[ _outs ][0] >= 0 )
  114. {
  115. for ( int i = _outs; i--; )
  116. {
  117. int a = _configs[ _outs ][ i ];
  118. Point p( 1.2f, (float)a );
  119. float px, py;
  120. p.axes( &px, &py );
  121. fl_push_matrix();
  122. const int bx = tx + ((tw / 2) * px + (tw / 2));
  123. const int by = ty + ((th / 2) * py + (th / 2));
  124. fl_translate( bx, by );
  125. fl_scale( 5, 5 );
  126. a = 90 - a;
  127. fl_rotate( a );
  128. draw_speaker( FL_WHITE );
  129. fl_rotate( -a );
  130. fl_pop_matrix();
  131. }
  132. }
  133. /* ensure that points are drawn *inside* the circle */
  134. for ( int i = _ins; i--; )
  135. {
  136. Point *p = &_points[ i ];
  137. Fl_Color c = (Fl_Color)(10 + i);
  138. int px, py, pw, ph;
  139. point_bbox( p, &px, &py, &pw, &ph );
  140. /* draw point */
  141. fl_color( c );
  142. fl_pie( px, py, pw, ph, 0, 360 );
  143. /* draw echo */
  144. fl_color( c = fl_darker( c ) );
  145. fl_arc( px - 5, py - 5, pw + 10, ph + 10, 0, 360 );
  146. fl_color( c = fl_darker( c ) );
  147. fl_arc( px - 10, py - 10, pw + 20, ph + 20, 0, 360 );
  148. fl_color( c = fl_darker( c ) );
  149. fl_arc( px - 30, py - 30, pw + 60, ph + 60, 0, 360 );
  150. /* draw number */
  151. char pat[4];
  152. snprintf( pat, 4, "%d", i + 1 );
  153. fl_color( FL_BLACK );
  154. fl_font( FL_HELVETICA, ph + 2 );
  155. fl_draw( pat, px + 1, py + 1, pw - 1, ph - 1, FL_ALIGN_CENTER );
  156. /* draw line */
  157. /* fl_color( FL_WHITE ); */
  158. /* fl_line( bx + pw() / 2, by + ph() / 2, tx + (tw / 2), ty + (th / 2) ); */
  159. }
  160. fl_pop_clip();
  161. }
  162. /* return the current gain setting for the path in/out */
  163. Panner::Point
  164. Panner::point( int i )
  165. {
  166. return _points[ i ];
  167. }
  168. int
  169. Panner::handle ( int m )
  170. {
  171. static Point *drag;
  172. int r = Fl_Widget::handle( m );
  173. switch ( m )
  174. {
  175. case FL_PUSH:
  176. if ( Fl::event_button2() )
  177. {
  178. _bypassed = ! _bypassed;
  179. redraw();
  180. return 0;
  181. }
  182. else if ( Fl::event_button1() && ( drag = event_point() ) )
  183. return 1;
  184. else
  185. return 0;
  186. case FL_RELEASE:
  187. drag = NULL;
  188. return 1;
  189. case FL_DRAG:
  190. {
  191. float X = Fl::event_x() - x();
  192. float Y = Fl::event_y() - y();
  193. int tx, ty, tw, th;
  194. bbox( tx, ty, tw, th );
  195. /* if ( _outs < 3 ) */
  196. /* drag->angle( (float)(X / (tw / 2)) - 1.0f, 0.0f ); */
  197. /* else */
  198. drag->angle( (float)(X / (tw / 2)) - 1.0f, (float)(Y / (th / 2)) - 1.0f );
  199. printf( "%f %f\n", drag->a, drag->d );
  200. redraw();
  201. return 1;
  202. }
  203. }
  204. return r;
  205. // return 0;
  206. }