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.

310 lines
9.0KB

  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. // class Track;
  20. // #include "Waveform.H"
  21. #include "Clip.H"
  22. #include "Track.H"
  23. #include "Timeline.H"
  24. #include <algorithm>
  25. using namespace std;
  26. /* Regions are "virtual" FLTK widgets; this is necessary because the
  27. * dimensions of real FLTK widgets are limited to 16-bits, which is
  28. * far too little for our purposes */
  29. /* Base class for virtual widget on a track */
  30. class Track_Widget
  31. {
  32. protected:
  33. Track *_track; /* track this region belongs to */
  34. nframes_t _offset; /* where on the timeline */
  35. nframes_t _start; /* first sample from clip */
  36. nframes_t _end; /* last sample from clip */
  37. bool _selected;
  38. Fl_Color _color; /* color of waveform */
  39. Fl_Color _box_color; /* color of background (box) */
  40. public:
  41. Track_Widget ( )
  42. {
  43. _track = NULL;
  44. _offset = _start = _end = 0;
  45. _selected = false;
  46. }
  47. Fl_Group * parent ( void ) const { return _track; }
  48. int scroll_x ( void ) const { return timeline.ts_to_x( timeline.xoffset ); }
  49. nframes_t scroll_ts ( void ) const { return timeline.xoffset; }
  50. int y ( void ) const { return _track->y(); }
  51. int h ( void ) const { return _track->h(); }
  52. int x ( void ) const { return _offset < timeline.xoffset ? -1 : min( 32767, _track->x() + timeline.ts_to_x( _offset - timeline.xoffset ) ); }
  53. // int x ( void ) const { return (short)( _track->x() + timeline.ts_to_x( _offset - timeline.xoffset )); }
  54. virtual int w ( void ) const { return timeline.ts_to_x( _end - _start ); }
  55. // int w ( void ) const { return timeline.ts_to_x( (_end - _start) - ( timeline.xoffset - _offset) ); }
  56. int abs_x ( void ) const { return timeline.ts_to_x( timeline.xoffset ); }
  57. 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 ( 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_label ( const char *label, Fl_Align align )
  78. {
  79. int X, Y;
  80. X = x();
  81. Y = y();
  82. /* FIXME: why do we have to to this here? why doesn't Fl_Lable::draw take care of this stuff? */
  83. if ( ! (align & FL_ALIGN_INSIDE) )
  84. {
  85. if ( align & FL_ALIGN_RIGHT )
  86. {
  87. X += w();
  88. align = (Fl_Align)((align & ~FL_ALIGN_RIGHT) | FL_ALIGN_LEFT);
  89. }
  90. if ( align & FL_ALIGN_BOTTOM )
  91. {
  92. Y += h();
  93. align = (Fl_Align)((align & ~FL_ALIGN_BOTTOM) | FL_ALIGN_TOP);
  94. }
  95. }
  96. /* fl_font( FL_HELVETICA, 14 ); */
  97. /* fl_color( FL_BLACK ); */
  98. /* fl_draw( label, X + 2, Y + 2, w(), h(), align ); */
  99. /* fl_color( FL_WHITE ); */
  100. /* fl_draw( label, X, Y, w(), h(), align ); */
  101. /* for some reasone FL_SHADOW_LABLE doesn't always use
  102. * black for the shadow color...so we can't rely on it. */
  103. Fl_Label lab;
  104. lab.color = FL_WHITE;
  105. lab.type = FL_SHADOW_LABEL;
  106. lab.value = label;
  107. lab.font = FL_HELVETICA;
  108. lab.size = 14;
  109. int W = w();
  110. int H = h();
  111. if ( align & FL_ALIGN_INSIDE )
  112. {
  113. X += Fl::box_dx( box() );
  114. Y += Fl::box_dy( box() );
  115. W -= Fl::box_dw( box() );
  116. H -= Fl::box_dh( box() );
  117. }
  118. if ( align & FL_ALIGN_CLIP ) fl_push_clip( X, Y, W, H );
  119. int dx = 0;
  120. int tx = timeline.ts_to_x( _offset );
  121. if ( tx < scroll_x() )
  122. dx = min( 32767, scroll_x() - tx );
  123. lab.draw( X - dx, Y, W, H, align );
  124. if ( align & FL_ALIGN_CLIP ) fl_pop_clip();
  125. }
  126. /* base hanlde just does basic dragging */
  127. virtual int
  128. handle ( int m )
  129. {
  130. static int ox, oy;
  131. int X = Fl::event_x();
  132. int Y = Fl::event_y();
  133. switch ( m )
  134. {
  135. case FL_PUSH:
  136. {
  137. ox = x() - X;
  138. oy = y() - Y;
  139. return 1;
  140. }
  141. case FL_RELEASE:
  142. fl_cursor( FL_CURSOR_DEFAULT );
  143. return 1;
  144. case FL_DRAG:
  145. {
  146. if ( ox + X >= _track->x() )
  147. {
  148. int nx = ox + X;
  149. _offset = timeline.x_to_ts( nx ) + timeline.xoffset;
  150. _track->snap( this );
  151. }
  152. _track->redraw();
  153. fl_cursor( FL_CURSOR_MOVE );
  154. return 1;
  155. }
  156. default:
  157. return 0;
  158. }
  159. }
  160. bool
  161. operator< ( const Track_Widget & rhs )
  162. {
  163. return _offset < rhs._offset;
  164. }
  165. };
  166. class Track_Point : public Track_Widget
  167. {
  168. protected:
  169. char *_label;
  170. public:
  171. int w ( void ) const { return 10; }
  172. nframes_t length ( void ) const { return timeline.x_to_ts( w() ); }
  173. Track_Point ( )
  174. {
  175. _label = NULL;
  176. }
  177. void
  178. draw ( int X, int Y, int W, int H )
  179. {
  180. if ( x() < 0 )
  181. return;
  182. Track_Widget::draw( x(), Y, w(), H );
  183. draw_label( _label, FL_ALIGN_RIGHT );
  184. }
  185. };
  186. class Tempo_Point : public Track_Point
  187. {
  188. float _tempo;
  189. void
  190. _make_label ( void )
  191. {
  192. if ( ! _label )
  193. _label = new char[40];
  194. snprintf( _label, 40, "%.1f", _tempo );
  195. }
  196. public:
  197. Tempo_Point ( nframes_t when, float bpm )
  198. {
  199. _tempo = bpm;
  200. _offset = when;
  201. _make_label();
  202. }
  203. ~Tempo_Point ( )
  204. { if ( _label ) delete[] _label; }
  205. };
  206. class Region : public Track_Widget
  207. {
  208. Clip *_clip; /* clip this region represents */
  209. float _scale; /* amplitude adjustment */
  210. static Fl_Boxtype _box;
  211. static Fl_Color _selection_color;
  212. static Fl_Color selection_color ( void ) { return _selection_color; }
  213. static void selection_color ( Fl_Color v ) { _selection_color = v; }
  214. enum trim_e { NO, LEFT, RIGHT };
  215. void trim ( enum trim_e t, int X );
  216. void init ( void );
  217. public:
  218. Fl_Boxtype box ( void ) const { return Region::_box; }
  219. Region ( const Region & rhs );
  220. Region ( Clip *c );
  221. int handle ( int m );
  222. void draw ( int X, int Y, int W, int H );
  223. void resize ( void );
  224. void normalize ( void );
  225. };