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.

200 lines
5.2KB

  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. #pragma once
  19. #include <FL/Fl_Widget.H>
  20. #include <FL/fl_draw.H>
  21. #include <FL/Fl.H>
  22. #include <math.h>
  23. #include <vector>
  24. using namespace std;
  25. class Panner : public Fl_Widget
  26. {
  27. void draw_the_box( int, int, int, int );
  28. struct Point
  29. {
  30. /* axes */
  31. /* distance from center (from 0 to 1) */
  32. float d;
  33. /* angle */
  34. float a;
  35. Point ( ) : d( 0.0f ), a( 0.0f ) { }
  36. Point ( float D, float A ) : d( D ), a( A ) { }
  37. /** translate angle /a/ into x/y coords and place the result in /X/ and /Y/ */
  38. void
  39. axes ( float *X, float *Y ) const
  40. {
  41. /* rotate */
  42. float A = ( 270 - a ) * ( M_PI / 180 );
  43. *X = -d * cosf( A );
  44. *Y = d * sinf( A );
  45. }
  46. float azimuth ( void ) const
  47. {
  48. return a > 180.0f ? a - 360.0f : a;
  49. }
  50. float elevation ( void ) const
  51. {
  52. return ( 1.0f - d ) * 90.0f;
  53. }
  54. void azimuth ( float v )
  55. {
  56. a = v < 0.0f ? v + 360.0f : v;
  57. a = a < 0.0f ? 0.0f : a > 360.0f ? 360.0f : a;
  58. }
  59. void elevation ( float v )
  60. {
  61. d = 1.0f - ( v / 90.0f );
  62. d = d < 0.0f ? 0.0f : d > 1.0f ? 1.0f : d;
  63. }
  64. /** set point position in X, Y coordinates (0.0 to 1.0) */
  65. void
  66. angle ( float X1, float Y1 )
  67. {
  68. float X2, Y2;
  69. Y2 = X2 = 0;
  70. float t;
  71. t = atan2( X2 - X1, Y2 - Y1 );
  72. a = t * (180 / M_PI);
  73. if ( a < 0 )
  74. a = 360 + a;
  75. a = 360 - a;
  76. /* standard distance calculation */
  77. d = sqrt( pow( X2 - X1, 2 ) + pow( Y2 - Y1, 2 ) );
  78. if ( d > 1.0f )
  79. d = 1.0f;
  80. }
  81. /** return the distance between the point and that referenced by /p/ */
  82. float
  83. distance ( const Point &p )
  84. {
  85. /* first, transform point coords */
  86. float x1, y1, x2, y2;
  87. axes( &x1, &y1 );
  88. p.axes( &x2, &y2 );
  89. /* standard distance calculation */
  90. return sqrt( pow( x1 - x2, 2 ) + pow( y1 - y2, 2 ) );
  91. }
  92. };
  93. /* channel configuration */
  94. int _ins,
  95. _outs;
  96. bool _bypassed;
  97. vector <Point> _points;
  98. static int pw ( void ) { return 12; }
  99. static int ph ( void ) { return 12; }
  100. static int _configs[][12];
  101. void bbox ( int &X, int &Y, int &W, int &H ) const
  102. {
  103. W = w() - Fl::box_dw( box() );
  104. H = h() - Fl::box_dh( box() );
  105. X = x() + Fl::box_dx( box() );
  106. Y = y() + Fl::box_dy( box() );
  107. }
  108. void point_bbox ( const Point *p, int *X, int *Y, int *W, int *H ) const;
  109. Point * event_point ( void );
  110. Point angle_to_axes ( float a );
  111. enum {
  112. NONE = -1,
  113. R = 90,
  114. L = 270,
  115. C = 0,
  116. FL = 315,
  117. FR = 45,
  118. RL = 225,
  119. RR = 135,
  120. };
  121. static Point * drag;
  122. protected:
  123. virtual void draw ( void );
  124. virtual int handle ( int );
  125. public:
  126. Panner ( int X, int Y, int W, int H, const char *L = 0 ) :
  127. Fl_Widget( X, Y, W, H, L )
  128. {
  129. _bypassed = false;
  130. _ins = 1;
  131. _outs = 1;
  132. // _ins = _outs = 4;
  133. // _points.push_back( Point( 1, FL ) );
  134. _points.push_back( Point( 1, C ) );
  135. /* _points.push_back( Point( 1, FR ) ); */
  136. /* _points.push_back( Point( 1, RL ) ); */
  137. /* _points.push_back( Point( 1, RR ) ); */
  138. }
  139. virtual ~Panner ( ) { }
  140. Panner::Point *point ( int i );
  141. };