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.

241 lines
7.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 "Track.H"
  20. #include "Loggable.H"
  21. #include "Audio_File.H"
  22. #include "Timeline.H"
  23. #include <list>
  24. #include <algorithm>
  25. using namespace std;
  26. struct Drag
  27. {
  28. /* mouse coords at start of drag */
  29. int x;
  30. int y;
  31. int state;
  32. Drag( int X, int Y ) : x( X ), y( Y ) { state = 0; }
  33. };
  34. /* Base class for virtual widget on a track */
  35. class Track_Widget : public Loggable
  36. {
  37. static list <Track_Widget *> _selection; /* all the widgets making up the selection */
  38. static Track_Widget * _current; /* the widget initiating events that affect the selection */
  39. protected:
  40. Track *_track; /* track this region belongs to */
  41. nframes_t _offset; /* where on the timeline */
  42. nframes_t _start; /* first sample from clip */
  43. nframes_t _end; /* last sample from clip */
  44. Fl_Color _color; /* color of waveform */
  45. Fl_Color _box_color; /* color of background (box) */
  46. Drag *_drag;
  47. public:
  48. Track_Widget ( )
  49. {
  50. _track = NULL;
  51. _offset = _start = _end = 0;
  52. _drag = NULL;
  53. }
  54. virtual ~Track_Widget ( )
  55. {
  56. redraw();
  57. _track->remove( this );
  58. _selection.remove( this );
  59. }
  60. bool selected ( void )
  61. {
  62. return ::find( _selection.begin(), _selection.end(), this ) != _selection.end();
  63. }
  64. void select ( void )
  65. {
  66. if ( selected() )
  67. return;
  68. _selection.push_back( this );
  69. _selection.sort( sort_func );
  70. redraw();
  71. }
  72. void deselect ( void )
  73. {
  74. _selection.remove( this );
  75. redraw();
  76. }
  77. static void
  78. delete_selected ( void )
  79. {
  80. while ( _selection.size() )
  81. delete _selection.front();
  82. }
  83. static Track_Widget *current ( void ) { return _current; }
  84. void
  85. offset ( nframes_t where )
  86. {
  87. if ( ! selected() )
  88. {
  89. redraw();
  90. _offset = where;
  91. }
  92. else
  93. {
  94. long d = where - _offset;
  95. for ( list <Track_Widget *>::iterator i = _selection.begin(); i != _selection.end(); i++ )
  96. {
  97. (*i)->redraw();
  98. if ( d < 0 )
  99. (*i)->_offset -= 0 - d;
  100. else
  101. (*i)->_offset += d;
  102. }
  103. }
  104. }
  105. int dispatch ( int m );
  106. Fl_Group * parent ( void ) const { return _track; }
  107. int scroll_x ( void ) const { return timeline->ts_to_x( timeline->xoffset ); }
  108. nframes_t scroll_ts ( void ) const { return timeline->xoffset; }
  109. virtual int y ( void ) const { return _track->y(); }
  110. virtual int h ( void ) const { return _track->h(); }
  111. /* used by regions */
  112. virtual int x ( void ) const { return _offset < timeline->xoffset ? _track->x() - 1 : min( 32767, _track->x() + timeline->ts_to_x( _offset - timeline->xoffset ) ); }
  113. /* use this as x() when you need to draw lines between widgets */
  114. int line_x ( void ) const
  115. {
  116. return _offset < timeline->xoffset ? max( -32768, _track->x() - timeline->ts_to_x( timeline->xoffset - _offset )) : min( 32767, _track->x() + timeline->ts_to_x( _offset - timeline->xoffset ) );
  117. }
  118. virtual int w ( void ) const
  119. {
  120. int tx = timeline->ts_to_x( _offset );
  121. int rw;
  122. if ( tx < scroll_x() )
  123. rw = abs_w() - (scroll_x() - tx);
  124. else
  125. rw = abs_w();
  126. return min( rw, _track->w() );
  127. }
  128. int abs_x ( void ) const { return timeline->ts_to_x( _offset ); }
  129. virtual int abs_w ( void ) const { return timeline->ts_to_x( _end - _start ); }
  130. Fl_Color color ( void ) { return _color; }
  131. Fl_Color box_color ( void ) { return _box_color; }
  132. Track * track ( void ) const { return _track; }
  133. void track ( Track *t ) { _track = t; }
  134. nframes_t offset ( void ) const { return _offset; }
  135. // void offset ( nframes_t o ) { _offset = o; }
  136. void end ( nframes_t v ) { _end = v; }
  137. nframes_t end ( void ) const { return _end; }
  138. void start ( nframes_t v ) { _start = v; }
  139. nframes_t start ( void ) const { return _start; }
  140. virtual nframes_t length ( void ) const { return _end - _start; }
  141. virtual Fl_Boxtype box ( void ) const { return FL_UP_BOX; }
  142. virtual Fl_Align align ( void ) const { return (Fl_Align)0; }
  143. virtual void
  144. redraw ( void )
  145. {
  146. if ( ! (align() & FL_ALIGN_INSIDE) )
  147. {
  148. // FIXME: to better..
  149. _track->redraw();
  150. }
  151. else
  152. _track->damage( FL_DAMAGE_EXPOSE, x(), y(), w(), h() );
  153. }
  154. /* just draw a simple box */
  155. virtual void
  156. draw_box ( int X, int Y, int W, int H )
  157. {
  158. if ( x() > X + W || x() + w() < X )
  159. return;
  160. fl_draw_box( box(), x(), y(), w(), h(), _box_color );
  161. }
  162. virtual void
  163. draw ( int X, int Y, int W, int H )
  164. {
  165. if ( x() > X + W || x() + w() < X )
  166. return;
  167. draw_box( X, Y, W, H );
  168. }
  169. bool
  170. operator< ( const Track_Widget & rhs )
  171. {
  172. return _offset < rhs._offset;
  173. }
  174. virtual void draw_label ( const char *label, Fl_Align align, Fl_Color color=(Fl_Color)0 );
  175. virtual int handle ( int m );
  176. static bool
  177. sort_func ( Track_Widget *lhs, Track_Widget *rhs )
  178. {
  179. return *lhs < *rhs;
  180. }
  181. };