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.

274 lines
6.5KB

  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. int tw, th, tx, ty;
  96. bbox( tx, ty, tw, th );
  97. fl_push_clip( tx, ty, tw, th );
  98. fl_color( FL_WHITE );
  99. const int b = 10;
  100. tx += b;
  101. ty += b;
  102. tw -= b * 2;
  103. th -= b * 2;
  104. fl_arc( tx, ty, tw, th, 0, 360 );
  105. if ( _configs[ _outs ][0] >= 0 )
  106. {
  107. for ( int i = _outs; i--; )
  108. {
  109. int a = _configs[ _outs ][ i ];
  110. Point p( 1.2f, (float)a );
  111. float px, py;
  112. p.axes( &px, &py );
  113. fl_push_matrix();
  114. const int bx = tx + ((tw / 2) * px + (tw / 2));
  115. const int by = ty + ((th / 2) * py + (th / 2));
  116. fl_translate( bx, by );
  117. fl_scale( 5, 5 );
  118. a = 90 - a;
  119. fl_rotate( a );
  120. draw_speaker( FL_WHITE );
  121. fl_rotate( -a );
  122. fl_pop_matrix();
  123. }
  124. }
  125. /* ensure that points are drawn *inside* the circle */
  126. for ( int i = _ins; i--; )
  127. {
  128. Point *p = &_points[ i ];
  129. Fl_Color c = (Fl_Color)(10 + i);
  130. int px, py, pw, ph;
  131. point_bbox( p, &px, &py, &pw, &ph );
  132. /* draw point */
  133. fl_color( c );
  134. fl_pie( px, py, pw, ph, 0, 360 );
  135. /* draw echo */
  136. fl_color( c = fl_darker( c ) );
  137. fl_arc( px - 5, py - 5, pw + 10, ph + 10, 0, 360 );
  138. fl_color( c = fl_darker( c ) );
  139. fl_arc( px - 10, py - 10, pw + 20, ph + 20, 0, 360 );
  140. fl_color( c = fl_darker( c ) );
  141. fl_arc( px - 30, py - 30, pw + 60, ph + 60, 0, 360 );
  142. /* draw number */
  143. char pat[4];
  144. snprintf( pat, 4, "%d", i + 1 );
  145. fl_color( FL_BLACK );
  146. fl_font( FL_HELVETICA, ph + 2 );
  147. fl_draw( pat, px + 1, py + 1, pw - 1, ph - 1, FL_ALIGN_CENTER );
  148. /* draw line */
  149. /* fl_color( FL_WHITE ); */
  150. /* fl_line( bx + pw() / 2, by + ph() / 2, tx + (tw / 2), ty + (th / 2) ); */
  151. }
  152. fl_pop_clip();
  153. }
  154. int
  155. Panner::handle ( int m )
  156. {
  157. static Point *drag;
  158. switch ( m )
  159. {
  160. case FL_PUSH:
  161. if ( ( drag = event_point() ) )
  162. {
  163. printf( "bing\n" );
  164. return 1;
  165. }
  166. else
  167. return 0;
  168. case FL_RELEASE:
  169. drag = NULL;
  170. return 1;
  171. case FL_DRAG:
  172. {
  173. float X = Fl::event_x() - x();
  174. float Y = Fl::event_y() - y();
  175. int tx, ty, tw, th;
  176. bbox( tx, ty, tw, th );
  177. drag->angle( (float)(X / (tw / 2)) - 1.0f, (float)(Y / (th / 2)) - 1.0f );
  178. /* calculate gains for all output channels */
  179. {
  180. for ( int i = _ins; i--; )
  181. {
  182. int a = _configs[ _outs ][ i ];
  183. // float g = 1.0f - drag->distance( Point( 1.0f, a ) ) / 2.0f;
  184. float g = drag->distance( Point( 1.0f, a ) ) / 2.0f;
  185. /* g = 1.0f / pow( g, 2 ); */
  186. /* g = 20.0f * log10f( g ); */
  187. printf( "%d:%f ", i, g );
  188. }
  189. printf( "\n" );
  190. }
  191. redraw();
  192. return 1;
  193. }
  194. }
  195. return 0;
  196. }