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.

213 lines
6.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 "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. /* Base class for virtual widget on a track */
  27. class Track_Widget : public Loggable
  28. {
  29. static list <Track_Widget *> _selection; /* all the widgets making up the selection */
  30. static Track_Widget * _current; /* the widget initiating events that affect the selection */
  31. protected:
  32. Track *_track; /* track this region belongs to */
  33. nframes_t _offset; /* where on the timeline */
  34. nframes_t _start; /* first sample from clip */
  35. nframes_t _end; /* last sample from clip */
  36. Fl_Color _color; /* color of waveform */
  37. Fl_Color _box_color; /* color of background (box) */
  38. struct Drag
  39. {
  40. /* mouse coords at start of drag */
  41. int x;
  42. int y;
  43. int state;
  44. Drag( int X, int Y ) : x( X ), y( Y ) { state = 0; }
  45. };
  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. _selection.push_back( this );
  67. }
  68. void deselect ( void )
  69. {
  70. _selection.remove( this );
  71. }
  72. static void
  73. delete_selected ( void )
  74. {
  75. while ( _selection.size() )
  76. delete _selection.front();
  77. }
  78. static Track_Widget *current ( void ) { return _current; }
  79. void
  80. offset ( nframes_t where )
  81. {
  82. if ( ! selected() )
  83. {
  84. redraw();
  85. _offset = where;
  86. }
  87. else
  88. {
  89. long d = where - _offset;
  90. for ( list <Track_Widget *>::iterator i = _selection.begin(); i != _selection.end(); i++ )
  91. {
  92. (*i)->redraw();
  93. if ( d < 0 )
  94. (*i)->_offset -= 0 - d;
  95. else
  96. (*i)->_offset += d;
  97. }
  98. }
  99. }
  100. int dispatch ( int m );
  101. Fl_Group * parent ( void ) const { return _track; }
  102. int scroll_x ( void ) const { return timeline->ts_to_x( timeline->xoffset ); }
  103. nframes_t scroll_ts ( void ) const { return timeline->xoffset; }
  104. int y ( void ) const { return _track->y(); }
  105. int h ( void ) const { return _track->h(); }
  106. int x ( void ) const { return _offset < timeline->xoffset ? _track->x() - 1 : min( 32767, _track->x() + timeline->ts_to_x( _offset - timeline->xoffset ) ); }
  107. virtual int w ( void ) const
  108. {
  109. int tx = timeline->ts_to_x( _offset );
  110. int rw;
  111. if ( tx < scroll_x() )
  112. rw = abs_w() - (scroll_x() - tx);
  113. else
  114. rw = abs_w();
  115. return min( rw, _track->w() );
  116. }
  117. int abs_x ( void ) const { return timeline->ts_to_x( _offset ); }
  118. virtual int abs_w ( void ) const { return timeline->ts_to_x( _end - _start ); }
  119. Fl_Color color ( void ) { return _color; }
  120. Fl_Color box_color ( void ) { return _box_color; }
  121. Track * track ( void ) const { return _track; }
  122. void track ( Track *t ) { _track = t; }
  123. nframes_t offset ( void ) const { return _offset; }
  124. // void offset ( nframes_t o ) { _offset = o; }
  125. void end ( nframes_t v ) { _end = v; }
  126. nframes_t end ( void ) const { return _end; }
  127. void start ( nframes_t v ) { _start = v; }
  128. nframes_t start ( void ) const { return _start; }
  129. virtual nframes_t length ( void ) const { return _end - _start; }
  130. virtual Fl_Boxtype box ( void ) const { return FL_UP_BOX; }
  131. virtual Fl_Align align ( void ) const { return (Fl_Align)0; }
  132. virtual void
  133. redraw ( void )
  134. {
  135. if ( ! (align() & FL_ALIGN_INSIDE) )
  136. {
  137. // FIXME: to better..
  138. _track->redraw();
  139. }
  140. else
  141. _track->damage( FL_DAMAGE_EXPOSE, x(), y(), w(), h() );
  142. }
  143. /* just draw a simple box */
  144. virtual void
  145. draw_box ( int X, int Y, int W, int H )
  146. {
  147. fl_draw_box( box(), x(), y(), w(), h(), _box_color );
  148. }
  149. virtual void
  150. draw ( int X, int Y, int W, int H )
  151. {
  152. draw_box( X, Y, W, H );
  153. }
  154. bool
  155. operator< ( const Track_Widget & rhs )
  156. {
  157. return _offset < rhs._offset;
  158. }
  159. virtual void draw_label ( const char *label, Fl_Align align );
  160. virtual int handle ( int m );
  161. };