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.

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