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.

263 lines
8.1KB

  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. /* just draw a simple box */
  71. virtual void
  72. draw_box ( int X, int Y, int W, int H )
  73. {
  74. fl_draw_box( box(), x(), y(), w(), y(), _box_color );
  75. }
  76. virtual void
  77. draw ( int X, int Y, int W, int H )
  78. {
  79. draw_box( X, Y, W, H );
  80. }
  81. virtual void
  82. draw_label ( const char *label, Fl_Align align )
  83. {
  84. int X, Y;
  85. X = x();
  86. Y = y();
  87. /* FIXME: why do we have to to this here? why doesn't Fl_Lable::draw take care of this stuff? */
  88. if ( ! (align & FL_ALIGN_INSIDE) )
  89. {
  90. if ( align & FL_ALIGN_RIGHT )
  91. {
  92. X += w();
  93. align = (Fl_Align)((align & ~FL_ALIGN_RIGHT) | FL_ALIGN_LEFT);
  94. }
  95. if ( align & FL_ALIGN_BOTTOM )
  96. {
  97. Y += h();
  98. align = (Fl_Align)((align & ~FL_ALIGN_BOTTOM) | FL_ALIGN_TOP);
  99. }
  100. }
  101. /* fl_font( FL_HELVETICA, 14 ); */
  102. /* fl_color( FL_BLACK ); */
  103. /* fl_draw( label, X + 2, Y + 2, w(), h(), align ); */
  104. /* fl_color( FL_WHITE ); */
  105. /* fl_draw( label, X, Y, w(), h(), align ); */
  106. /* for some reasone FL_SHADOW_LABLE doesn't always use
  107. * black for the shadow color...so we can't rely on it. */
  108. Fl_Label lab;
  109. lab.color = FL_WHITE;
  110. lab.type = FL_SHADOW_LABEL;
  111. lab.value = label;
  112. lab.font = FL_HELVETICA;
  113. lab.size = 14;
  114. int W = w();
  115. int H = h();
  116. if ( align & FL_ALIGN_INSIDE )
  117. {
  118. X += Fl::box_dx( box() );
  119. Y += Fl::box_dy( box() );
  120. W -= Fl::box_dw( box() );
  121. H -= Fl::box_dh( box() );
  122. }
  123. if ( align & FL_ALIGN_CLIP ) fl_push_clip( X, Y, W, H );
  124. int dx = 0;
  125. int tx = timeline.ts_to_x( _offset );
  126. if ( tx < scroll_x() )
  127. dx = min( 32767, scroll_x() - tx );
  128. lab.draw( X - dx, Y, W, H, align );
  129. if ( align & FL_ALIGN_CLIP ) fl_pop_clip();
  130. }
  131. /* base hanlde just does basic dragging */
  132. virtual int
  133. handle ( int m )
  134. {
  135. static int ox, oy;
  136. int X = Fl::event_x();
  137. int Y = Fl::event_y();
  138. switch ( m )
  139. {
  140. case FL_PUSH:
  141. {
  142. ox = x() - X;
  143. oy = y() - Y;
  144. if ( Fl::event_state() & FL_CTRL &&
  145. Fl::event_button() == 3 )
  146. {
  147. _track->queue_delete( this );
  148. return 0;
  149. }
  150. return 1;
  151. }
  152. case FL_RELEASE:
  153. fl_cursor( FL_CURSOR_DEFAULT );
  154. return 1;
  155. case FL_DRAG:
  156. {
  157. if ( ox + X >= _track->x() )
  158. {
  159. int nx = ox + X;
  160. _offset = timeline.x_to_ts( nx ) + timeline.xoffset;
  161. _track->snap( this );
  162. }
  163. _track->redraw();
  164. fl_cursor( FL_CURSOR_MOVE );
  165. if ( X >= _track->x() + _track->w() ||
  166. X <= _track->x() )
  167. {
  168. /* this drag needs to scroll */
  169. nframes_t pos = timeline.xoffset;
  170. nframes_t d = timeline.x_to_ts( 100 );
  171. if ( X <= _track->x() )
  172. {
  173. if ( pos > d )
  174. pos -= d;
  175. else
  176. pos = 0;
  177. }
  178. else
  179. pos += d;
  180. timeline.xoffset = pos;
  181. timeline.tracks->redraw();
  182. }
  183. return 1;
  184. }
  185. default:
  186. return 0;
  187. }
  188. }
  189. bool
  190. operator< ( const Track_Widget & rhs )
  191. {
  192. return _offset < rhs._offset;
  193. }
  194. };