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.

172 lines
4.4KB

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