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.

212 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. Drag( int X, int Y ) : x( X ), y( Y ) {}
  44. };
  45. Drag *_drag;
  46. public:
  47. Track_Widget ( )
  48. {
  49. _track = NULL;
  50. _offset = _start = _end = 0;
  51. _drag = NULL;
  52. }
  53. virtual ~Track_Widget ( )
  54. {
  55. redraw();
  56. _track->remove( this );
  57. _selection.remove( this );
  58. }
  59. bool selected ( void )
  60. {
  61. return ::find( _selection.begin(), _selection.end(), this ) != _selection.end();
  62. }
  63. void select ( void )
  64. {
  65. _selection.push_back( this );
  66. }
  67. void deselect ( void )
  68. {
  69. _selection.remove( this );
  70. }
  71. static void
  72. delete_selected ( void )
  73. {
  74. while ( _selection.size() )
  75. delete _selection.front();
  76. }
  77. static Track_Widget *current ( void ) { return _current; }
  78. void
  79. offset ( nframes_t where )
  80. {
  81. if ( ! selected() )
  82. {
  83. redraw();
  84. _offset = where;
  85. }
  86. else
  87. {
  88. long d = where - _offset;
  89. for ( list <Track_Widget *>::iterator i = _selection.begin(); i != _selection.end(); i++ )
  90. {
  91. (*i)->redraw();
  92. if ( d < 0 )
  93. (*i)->_offset -= 0 - d;
  94. else
  95. (*i)->_offset += d;
  96. }
  97. }
  98. }
  99. int dispatch ( int m );
  100. Fl_Group * parent ( void ) const { return _track; }
  101. int scroll_x ( void ) const { return timeline->ts_to_x( timeline->xoffset ); }
  102. nframes_t scroll_ts ( void ) const { return timeline->xoffset; }
  103. int y ( void ) const { return _track->y(); }
  104. int h ( void ) const { return _track->h(); }
  105. int x ( void ) const { return _offset < timeline->xoffset ? _track->x() - 1 : min( 32767, _track->x() + timeline->ts_to_x( _offset - timeline->xoffset ) ); }
  106. virtual int w ( void ) const
  107. {
  108. int tx = timeline->ts_to_x( _offset );
  109. int rw;
  110. if ( tx < scroll_x() )
  111. rw = abs_w() - (scroll_x() - tx);
  112. else
  113. rw = abs_w();
  114. return min( rw, _track->w() );
  115. }
  116. int abs_x ( void ) const { return timeline->ts_to_x( _offset ); }
  117. virtual int abs_w ( void ) const { return timeline->ts_to_x( _end - _start ); }
  118. Fl_Color color ( void ) { return _color; }
  119. Fl_Color box_color ( void ) { return _box_color; }
  120. Track * track ( void ) const { return _track; }
  121. void track ( Track *t ) { _track = t; }
  122. nframes_t offset ( void ) const { return _offset; }
  123. // void offset ( nframes_t o ) { _offset = o; }
  124. void end ( nframes_t v ) { _end = v; }
  125. nframes_t end ( void ) const { return _end; }
  126. void start ( nframes_t v ) { _start = v; }
  127. nframes_t start ( void ) const { return _start; }
  128. virtual nframes_t length ( void ) const { return _end - _start; }
  129. virtual Fl_Boxtype box ( void ) const { return FL_UP_BOX; }
  130. virtual Fl_Align align ( void ) const { return (Fl_Align)0; }
  131. virtual void
  132. redraw ( void )
  133. {
  134. if ( ! (align() & FL_ALIGN_INSIDE) )
  135. {
  136. // FIXME: to better..
  137. _track->redraw();
  138. }
  139. else
  140. _track->damage( FL_DAMAGE_EXPOSE, x(), y(), w(), h() );
  141. }
  142. /* just draw a simple box */
  143. virtual void
  144. draw_box ( int X, int Y, int W, int H )
  145. {
  146. fl_draw_box( box(), x(), y(), w(), h(), _box_color );
  147. }
  148. virtual void
  149. draw ( int X, int Y, int W, int H )
  150. {
  151. draw_box( X, Y, W, H );
  152. }
  153. bool
  154. operator< ( const Track_Widget & rhs )
  155. {
  156. return _offset < rhs._offset;
  157. }
  158. virtual void draw_label ( const char *label, Fl_Align align );
  159. virtual int handle ( int m );
  160. };