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.

210 lines
5.9KB

  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_Group.H>
  20. #include <FL/fl_draw.H>
  21. #include <FL/Fl.H>
  22. #include <FL/Fl_Choice.H>
  23. #include <math.h>
  24. #include <FL/Fl_Image.H>
  25. #include <vector>
  26. using namespace std;
  27. class Panner : public Fl_Group
  28. {
  29. Fl_Choice *_range_choice;
  30. Fl_Choice *_projection_choice;
  31. Fl_Image *_bg_image;
  32. bool _bg_image_scaled;
  33. int _bg_image_projection;
  34. void draw_grid( int,int,int,int);
  35. void draw_the_box( int, int, int, int );
  36. static int _range_mode;
  37. static int _projection_mode;
  38. public:
  39. struct Point
  40. {
  41. float x,y,z;
  42. const char *label;
  43. void *userdata;
  44. Fl_Color color;
  45. bool visible;
  46. bool radius_enabled;
  47. Point ( ) {
  48. x = 1;
  49. y = 0;
  50. z = 0;
  51. label = 0;
  52. visible = 1;
  53. color = FL_WHITE;
  54. radius_enabled = false;
  55. }
  56. Point ( float D, float A )
  57. {
  58. radius( D );
  59. azimuth( A );
  60. label = 0;
  61. visible = 1;
  62. color = FL_WHITE;
  63. radius_enabled = false;
  64. }
  65. static inline void spherical_to_cartesian (float a, float e, float &x, float &y, float &z )
  66. {
  67. a *= M_PI / 180.0f;
  68. e *= M_PI / 180.0f;
  69. z = sinf(e);
  70. const float ce = cosf(e);
  71. x = ce * cosf(-a);
  72. y = ce * sinf(-a);
  73. }
  74. float azimuth ( void ) const {
  75. return -atan2f( y,x ) * ( 180 / M_PI );
  76. }
  77. float elevation ( void ) const {
  78. return atan2f(z,sqrtf(powf(x,2)+powf(y,2)) ) * ( 180 / M_PI );
  79. }
  80. float radius ( void ) const {
  81. if ( ! radius_enabled )
  82. return 1.0f;
  83. else
  84. return sqrtf(powf(x,2)+powf(y,2)+powf(z,2));
  85. }
  86. void azimuth ( float v )
  87. {
  88. float r = radius();
  89. spherical_to_cartesian( v, elevation(), x,y,z );
  90. x *= r;
  91. y *= r;
  92. z *= r;
  93. }
  94. void elevation ( float v )
  95. {
  96. float r = radius();
  97. spherical_to_cartesian( azimuth(), v, x,y,z );
  98. x *= r;
  99. y *= r;
  100. z *= r;
  101. }
  102. void radius ( float v )
  103. {
  104. if (! radius_enabled )
  105. return;
  106. float r = v;
  107. spherical_to_cartesian( azimuth(), elevation(), x,y,z );
  108. x *= r;
  109. y *= r;
  110. z *= r;
  111. }
  112. };
  113. private:
  114. vector <Point> _points;
  115. static int _configs[][12];
  116. void bbox ( int &X, int &Y, int &W, int &H ) const
  117. {
  118. W = w() - Fl::box_dw( box() );
  119. H = h() - Fl::box_dh( box() );
  120. X = x() + Fl::box_dx( box() );
  121. Y = y() + Fl::box_dy( box() );
  122. int S = W > H ? H : W;
  123. if ( W > H )
  124. X += ( (W/2) - (S/2) );
  125. else if ( H > W )
  126. Y += ( (H/2) - (S/2) );
  127. W = H = S;
  128. }
  129. void point_bbox ( const Point *p, int *X, int *Y, int *W, int *H ) const;
  130. Point * event_point ( void );
  131. Point angle_to_axes ( float a );
  132. static Point * drag;
  133. void set_polar ( Point *p, float x, float y );
  134. void set_ortho ( Point *p, float x, float y );
  135. void set_polar_radius ( Point *p, float x, float y );
  136. void project_polar ( const Point *p, float *X, float *Y, float *S ) const;
  137. void project_ortho ( const Point *p, float *X, float *Y, float *S ) const;
  138. static void cb_mode ( Fl_Widget *w, void *v );
  139. void cb_mode ( Fl_Widget *w );
  140. protected:
  141. virtual void draw ( void );
  142. virtual int handle ( int );
  143. public:
  144. enum { POLAR, ORTHO };
  145. int projection ( void ) const { return _projection_mode; }
  146. void projection ( int v ) { _projection_choice->value(v); _projection_mode = v; }
  147. Panner ( int X, int Y, int W, int H, const char *L = 0 );
  148. float range ( void ) const { return *((float*)_range_choice->menu()[_range_mode].user_data()); }
  149. void range ( float v );
  150. void clear_points ( void ) { _points.clear(); }
  151. void add_point( Panner::Point &p )
  152. {
  153. _points.push_back( p );
  154. }
  155. virtual ~Panner ( );
  156. Panner::Point *point ( int i );
  157. int points ( void ) const { return _points.size(); }
  158. Panner::Point *pushed ( void ) { return drag; }
  159. };