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.

271 lines
6.3KB

  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. Panner::Point *
  61. Panner::event_point ( void )
  62. {
  63. int X, Y, W, H;
  64. bbox( X, Y, W, H );
  65. W -= pw();
  66. H -= ph();
  67. for ( int i = _ins; i--; )
  68. {
  69. Point *p = &_points[ i ];
  70. float px, py;
  71. p->axes( &px, &py );
  72. if ( Fl::event_inside( X + ((px * (W / 2)) + (W / 2)),
  73. Y + ((py * (H / 2)) + (H / 2)), pw(), ph() ) )
  74. return p;
  75. }
  76. return NULL;
  77. }
  78. /* translate angle /a/ into x/y coords and place the result in /X/ and /Y/ */
  79. /* Panner::Point */
  80. /* Panner::angle_to_axes ( float a ) */
  81. /* { */
  82. /* Point p; */
  83. /* a -= 90; */
  84. /* a = 360 - a; */
  85. /* double A; */
  86. /* A = a * ( M_PI / 180 ); */
  87. /* // const float r = tw / 2; */
  88. /* const double r = 1.0f; */
  89. /* p.x = r * cos( A ); */
  90. /* p.y = -r * sin( A ); */
  91. /* return p; */
  92. /* } */
  93. void
  94. Panner::draw ( void )
  95. {
  96. // draw_box();
  97. draw_box( FL_FLAT_BOX, x(), y(), w(), h(), FL_BLACK );
  98. draw_label();
  99. int tw, th, tx, ty;
  100. bbox( tx, ty, tw, th );
  101. fl_push_clip( tx, ty, tw, th );
  102. fl_color( FL_WHITE );
  103. const int b = 10;
  104. tx += b;
  105. ty += b;
  106. tw -= b * 2;
  107. th -= b * 2;
  108. fl_arc( tx, ty, tw, th, 0, 360 );
  109. if ( _configs[ _outs ][0] >= 0 )
  110. {
  111. for ( int i = _outs; i--; )
  112. {
  113. int a = _configs[ _outs ][ i ];
  114. Point p( 1.2f, (float)a );
  115. float px, py;
  116. p.axes( &px, &py );
  117. fl_push_matrix();
  118. const int bx = tx + ((tw / 2) * px + (tw / 2));
  119. const int by = ty + ((th / 2) * py + (th / 2));
  120. fl_translate( bx, by );
  121. fl_scale( 5, 5 );
  122. a = 90 - a;
  123. fl_rotate( a );
  124. draw_speaker( FL_WHITE );
  125. fl_rotate( -a );
  126. fl_pop_matrix();
  127. }
  128. }
  129. tw -= pw();
  130. th -= ph();
  131. for ( int i = _ins; i--; )
  132. {
  133. Point *p = &_points[ i ];
  134. Fl_Color c = (Fl_Color)(10 + i);
  135. float px, py;
  136. p->axes( &px, &py );
  137. const int bx = tx + ((tw / 2) * px + (tw / 2));
  138. const int by = ty + ((th / 2) * py + (th / 2));
  139. /* draw point */
  140. fl_color( c );
  141. fl_pie( bx, by, pw(), ph(), 0, 360 );
  142. /* draw echo */
  143. fl_color( c = fl_darker( c ) );
  144. fl_arc( bx - 5, by - 5, pw() + 10, ph() + 10, 0, 360 );
  145. fl_color( c = fl_darker( c ) );
  146. fl_arc( bx - 10, by - 10, pw() + 20, ph() + 20, 0, 360 );
  147. fl_color( c = fl_darker( c ) );
  148. fl_arc( bx - 30, by - 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, bx + 1, by + 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. int
  162. Panner::handle ( int m )
  163. {
  164. static Point *drag;
  165. switch ( m )
  166. {
  167. case FL_PUSH:
  168. if ( ( drag = event_point() ) )
  169. {
  170. printf( "bing\n" );
  171. return 1;
  172. }
  173. else
  174. return 0;
  175. case FL_RELEASE:
  176. drag = NULL;
  177. return 1;
  178. case FL_DRAG:
  179. {
  180. float X = Fl::event_x() - x();
  181. float Y = Fl::event_y() - y();
  182. drag->angle( (float)(X / (w() / 2)) - 1.0f, (float)(Y / (h() / 2)) - 1.0f );
  183. /* drag->x = (float)(X / (w() / 2)) - 1.0f; */
  184. /* drag->y = (float)(Y / (h() / 2)) - 1.0f; */
  185. // printf( "%f\n", drag->distance( angle_to_axes( _configs[ _outs ][ 0 ] ) ) );
  186. redraw();
  187. return 1;
  188. }
  189. }
  190. return 0;
  191. }