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.

280 lines
6.6KB

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