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.

228 lines
7.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. // 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. Fl_Color color ( void ) { return _color; }
  57. Fl_Color box_color ( void ) { return _box_color; }
  58. Track * track ( void ) const { return _track; }
  59. void track ( Track *t ) { _track = t; }
  60. nframes_t offset ( void ) const { return _offset; }
  61. void offset ( nframes_t o ) { _offset = o; }
  62. void end ( nframes_t v ) { _end = v; }
  63. nframes_t end ( void ) const { return _end; }
  64. void start ( nframes_t v ) { _start = v; }
  65. nframes_t start ( void ) const { return _start; }
  66. virtual nframes_t length ( void ) const { return _end - _start; }
  67. /* just draw a simple box */
  68. virtual void
  69. draw ( int X, int Y, int W, int H )
  70. {
  71. fl_draw_box( FL_FLAT_BOX, x(), y(), w(), y(), _box_color );
  72. }
  73. /* base hanlde just does basic dragging */
  74. virtual int
  75. handle ( int m )
  76. {
  77. static int ox, oy;
  78. int X = Fl::event_x();
  79. int Y = Fl::event_y();
  80. switch ( m )
  81. {
  82. case FL_PUSH:
  83. {
  84. ox = x() - X;
  85. oy = y() - Y;
  86. return 1;
  87. }
  88. case FL_RELEASE:
  89. fl_cursor( FL_CURSOR_DEFAULT );
  90. return 1;
  91. case FL_DRAG:
  92. {
  93. if ( ox + X >= _track->x() )
  94. {
  95. int nx = ox + X;
  96. _offset = timeline.x_to_ts( nx ) + timeline.xoffset;
  97. _track->snap( this );
  98. }
  99. _track->redraw();
  100. fl_cursor( FL_CURSOR_MOVE );
  101. return 1;
  102. }
  103. default:
  104. return 0;
  105. }
  106. }
  107. bool
  108. operator< ( const Track_Widget & rhs )
  109. {
  110. return _offset < rhs._offset;
  111. }
  112. };
  113. class Tempo_Point : public Track_Widget
  114. {
  115. float _tempo;
  116. static Fl_Boxtype box ( void ) { return FL_UP_BOX; }
  117. public:
  118. Tempo_Point ( )
  119. {
  120. _tempo = 120;
  121. _offset = 0;
  122. _start = 0;
  123. _end = 300;
  124. }
  125. Tempo_Point ( nframes_t when, float bpm )
  126. {
  127. _tempo = bpm;
  128. _offset = when;
  129. _start = 0;
  130. _end = 300;
  131. }
  132. int w ( void ) const { return 10; }
  133. nframes_t length ( void ) const { return timeline.x_to_ts( w() ); }
  134. void
  135. draw ( int X, int Y, int W, int H )
  136. {
  137. if ( x() < 0 )
  138. return;
  139. fl_draw_box( box(), x(), Y, w(), H, _box_color );
  140. char pat[40];
  141. snprintf( pat, 40, "%.1f", _tempo );
  142. fl_font( FL_HELVETICA, 14 );
  143. fl_color( FL_BLACK );
  144. fl_draw( pat, x() + w() + 1, Y + 1, w(), h(), FL_ALIGN_LEFT );
  145. fl_color( FL_WHITE );
  146. fl_draw( pat, x() + w(), Y, w(), h(), FL_ALIGN_LEFT );
  147. }
  148. };
  149. class Region : public Track_Widget
  150. {
  151. Clip *_clip; /* clip this region represents */
  152. float _scale; /* amplitude adjustment */
  153. static Fl_Boxtype _box;
  154. static Fl_Color _selection_color;
  155. static Fl_Color selection_color ( void ) { return _selection_color; }
  156. static void selection_color ( Fl_Color v ) { _selection_color = v; }
  157. static Fl_Boxtype box ( void ) { return _box; }
  158. enum trim_e { NO, LEFT, RIGHT };
  159. void trim ( enum trim_e t, int X );
  160. void init ( void );
  161. public:
  162. Region ( const Region & rhs );
  163. Region ( Clip *c );
  164. int handle ( int m );
  165. void draw ( int X, int Y, int W, int H );
  166. void resize ( void );
  167. };