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.

277 lines
8.5KB

  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 <algorithm>
  21. using namespace std;
  22. /* Base class for virtual widget on a track */
  23. class Track_Widget
  24. {
  25. protected:
  26. Track *_track; /* track this region belongs to */
  27. nframes_t _offset; /* where on the timeline */
  28. nframes_t _start; /* first sample from clip */
  29. nframes_t _end; /* last sample from clip */
  30. bool _selected;
  31. Fl_Color _color; /* color of waveform */
  32. Fl_Color _box_color; /* color of background (box) */
  33. public:
  34. Track_Widget ( )
  35. {
  36. _track = NULL;
  37. _offset = _start = _end = 0;
  38. _selected = false;
  39. }
  40. Fl_Group * parent ( void ) const { return _track; }
  41. int scroll_x ( void ) const { return timeline->ts_to_x( timeline->xoffset ); }
  42. nframes_t scroll_ts ( void ) const { return timeline->xoffset; }
  43. int y ( void ) const { return _track->y(); }
  44. int h ( void ) const { return _track->h(); }
  45. int x ( void ) const { return _offset < timeline->xoffset ? -1 : min( 32767, _track->x() + timeline->ts_to_x( _offset - timeline->xoffset ) ); }
  46. virtual int w ( void ) const
  47. {
  48. int tx = timeline->ts_to_x( _offset );
  49. int rw;
  50. if ( tx < scroll_x() )
  51. rw = abs_w() - (scroll_x() - tx);
  52. else
  53. rw = abs_w();
  54. return min( rw, _track->w() );
  55. }
  56. int abs_x ( void ) const { return timeline->ts_to_x( timeline->xoffset ); }
  57. virtual int abs_w ( void ) const { return timeline->ts_to_x( _end - _start ); }
  58. Fl_Color color ( void ) { return _color; }
  59. Fl_Color box_color ( void ) { return _box_color; }
  60. Track * track ( void ) const { return _track; }
  61. void track ( Track *t ) { _track = t; }
  62. nframes_t offset ( void ) const { return _offset; }
  63. void offset ( nframes_t o ) { _offset = o; }
  64. void end ( nframes_t v ) { _end = v; }
  65. nframes_t end ( void ) const { return _end; }
  66. void start ( nframes_t v ) { _start = v; }
  67. nframes_t start ( void ) const { return _start; }
  68. virtual nframes_t length ( void ) const { return _end - _start; }
  69. virtual Fl_Boxtype box ( void ) const { return FL_UP_BOX; }
  70. virtual Fl_Align align ( void ) const { return (Fl_Align)0; }
  71. virtual void
  72. redraw ( void )
  73. {
  74. if ( ! (align() & FL_ALIGN_INSIDE) )
  75. {
  76. // FIXME: to better..
  77. _track->redraw();
  78. }
  79. else
  80. _track->damage( FL_DAMAGE_EXPOSE, x(), y(), w(), h() );
  81. }
  82. /* just draw a simple box */
  83. virtual void
  84. draw_box ( int X, int Y, int W, int H )
  85. {
  86. fl_draw_box( box(), x(), y(), w(), h(), _box_color );
  87. }
  88. virtual void
  89. draw ( int X, int Y, int W, int H )
  90. {
  91. draw_box( X, Y, W, H );
  92. }
  93. virtual void
  94. draw_label ( const char *label, Fl_Align align )
  95. {
  96. int X, Y;
  97. X = x();
  98. Y = y();
  99. /* FIXME: why do we have to to this here? why doesn't Fl_Lable::draw take care of this stuff? */
  100. if ( ! (align & FL_ALIGN_INSIDE) )
  101. {
  102. if ( align & FL_ALIGN_RIGHT )
  103. {
  104. X += w();
  105. align = (Fl_Align)((align & ~FL_ALIGN_RIGHT) | FL_ALIGN_LEFT);
  106. }
  107. if ( align & FL_ALIGN_BOTTOM )
  108. {
  109. Y += h();
  110. align = (Fl_Align)((align & ~FL_ALIGN_BOTTOM) | FL_ALIGN_TOP);
  111. }
  112. }
  113. /* fl_font( FL_HELVETICA, 14 ); */
  114. /* fl_color( FL_BLACK ); */
  115. /* fl_draw( label, X + 2, Y + 2, w(), h(), align ); */
  116. /* fl_color( FL_WHITE ); */
  117. /* fl_draw( label, X, Y, w(), h(), align ); */
  118. /* for some reasone FL_SHADOW_LABLE doesn't always use
  119. * black for the shadow color...so we can't rely on it. */
  120. Fl_Label lab;
  121. lab.color = FL_WHITE;
  122. lab.type = FL_SHADOW_LABEL;
  123. lab.value = label;
  124. lab.font = FL_HELVETICA;
  125. lab.size = 14;
  126. int W = w();
  127. int H = h();
  128. if ( align & FL_ALIGN_INSIDE )
  129. {
  130. X += Fl::box_dx( box() );
  131. Y += Fl::box_dy( box() );
  132. W -= Fl::box_dw( box() );
  133. H -= Fl::box_dh( box() );
  134. }
  135. if ( align & FL_ALIGN_CLIP ) fl_push_clip( X, Y, W, H );
  136. int dx = 0;
  137. if ( abs_x() < scroll_x() )
  138. dx = min( 32767, scroll_x() - abs_x() );
  139. lab.draw( X - dx, Y, W, H, align );
  140. if ( align & FL_ALIGN_CLIP ) fl_pop_clip();
  141. }
  142. /* base hanlde just does basic dragging */
  143. virtual int
  144. handle ( int m )
  145. {
  146. static int ox, oy;
  147. int X = Fl::event_x();
  148. int Y = Fl::event_y();
  149. switch ( m )
  150. {
  151. case FL_PUSH:
  152. {
  153. ox = x() - X;
  154. oy = y() - Y;
  155. if ( Fl::event_state() & FL_CTRL &&
  156. Fl::event_button() == 3 )
  157. {
  158. redraw();
  159. _track->queue_delete( this );
  160. return 0;
  161. }
  162. return 1;
  163. }
  164. case FL_RELEASE:
  165. fl_cursor( FL_CURSOR_DEFAULT );
  166. return 1;
  167. case FL_DRAG:
  168. {
  169. redraw();
  170. if ( ox + X >= _track->x() )
  171. {
  172. int nx = ox + X;
  173. _offset = timeline->x_to_ts( nx ) + timeline->xoffset;
  174. _track->snap( this );
  175. }
  176. // _track->redraw();
  177. fl_cursor( FL_CURSOR_MOVE );
  178. if ( X >= _track->x() + _track->w() ||
  179. X <= _track->x() )
  180. {
  181. /* this drag needs to scroll */
  182. nframes_t pos = timeline->xoffset;
  183. nframes_t d = timeline->x_to_ts( 100 );
  184. if ( X <= _track->x() )
  185. {
  186. if ( pos > d )
  187. pos -= d;
  188. else
  189. pos = 0;
  190. }
  191. else
  192. pos += d;
  193. timeline->position( timeline->ts_to_x( pos ) );
  194. // timeline->tracks->redraw();
  195. }
  196. return 1;
  197. }
  198. default:
  199. return 0;
  200. }
  201. }
  202. bool
  203. operator< ( const Track_Widget & rhs )
  204. {
  205. return _offset < rhs._offset;
  206. }
  207. };