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.

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