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.

236 lines
6.4KB

  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 <FL/Fl_Scroll.H>
  20. #include <FL/Fl_Pack.H>
  21. #include <FL/Fl_Scrollbar.H>
  22. #include <FL/Fl_Widget.H>
  23. #include "Scalebar.H"
  24. #include "Audio_File.H" // just for nframes_t
  25. #include <math.h>
  26. #include <assert.h>
  27. #include <FL/fl_draw.H>
  28. class Timeline;
  29. extern Timeline *timeline;
  30. #include "Track.H"
  31. // #include "Tempo_Track.H"
  32. class Tempo_Track;
  33. class Time_Track;
  34. // #include "Tempo_Point.H"
  35. // #include "Region.H"
  36. #include <list>
  37. using std::list;
  38. struct Timeline : public Fl_Group
  39. {
  40. int _old_xposition;
  41. int _old_yposition;
  42. enum snap_flags_e {
  43. SNAP_TO_REGION,
  44. SNAP_TO_BAR,
  45. SNAP_TO_BEAT
  46. } snap_to;
  47. Fl_Scroll *scroll;
  48. Fl_Pack *tracks;
  49. Fl_Pack *rulers;
  50. Scalebar *hscroll;
  51. Fl_Scrollbar *vscroll;
  52. Tempo_Track *tempo_track;
  53. Time_Track *time_track;
  54. float fpp; /* frames per pixel */
  55. // nframes_t fpp;
  56. nframes_t sample_rate;
  57. nframes_t xoffset;
  58. nframes_t length;
  59. int yposition;
  60. int _beats_per_bar;
  61. float _beats_per_minute;
  62. Timeline ( int X, int Y, int W, int H, const char *L=0 );
  63. int
  64. ts_to_x( nframes_t ts )
  65. {
  66. // assert( ts / fpp > 0 );
  67. return ts / fpp;
  68. }
  69. nframes_t
  70. x_to_ts ( int x )
  71. {
  72. return x * fpp;
  73. }
  74. float beats_per_minute ( nframes_t when ) const;
  75. void beats_per_minute ( nframes_t when, float bpm );
  76. int beats_per_bar ( nframes_t when ) const;
  77. void draw_measure_lines ( int X, int Y, int W, int H, Fl_Color color );
  78. /** set scroll position */
  79. void
  80. position ( int X )
  81. {
  82. _old_xposition = xoffset;
  83. xoffset = x_to_ts( X );
  84. damage( FL_DAMAGE_SCROLL );
  85. /* rulers->damage( FL_DAMAGE_SCROLL ); */
  86. /* tracks->damage( FL_DAMAGE_SCROLL ); */
  87. }
  88. #define FOR_CHILDREN_OF( name, ind ) \
  89. for ( int i = (name) ->children(); i-- && ( (ind) = (name) ->child( i ) ); )
  90. static void
  91. draw_clip ( void * v, int X, int Y, int W, int H )
  92. {
  93. Timeline *tl = (Timeline *)v;
  94. // printf( "draw_clip: %d,%d %dx%d\n", X, Y, W, H );
  95. fl_push_clip( X, Y, W, H );
  96. fl_color( rand() );
  97. fl_rectf( X, Y, X + W, Y + H );
  98. tl->draw_child( *tl->tracks );
  99. tl->draw_child( *tl->rulers );
  100. fl_pop_clip();
  101. }
  102. void
  103. draw ( void )
  104. {
  105. int X, Y, W, H;
  106. X = tracks->x() + Fl::box_dx( tracks->child( 0 )->box() ) + 1;
  107. Y = tracks->y();
  108. W = tracks->w() - Fl::box_dw( tracks->child( 0 )->box() ) - 1;
  109. H = tracks->h();
  110. /* fl_color( FL_RED ); */
  111. /* fl_rect( X, Y, X + W, Y + H ); */
  112. if ( damage() & FL_DAMAGE_ALL )
  113. {
  114. /* fl_push_clip( x(), y(), w() - vscroll->w(), h() - hscroll->h() ); */
  115. /* Fl_Group::draw(); */
  116. /* fl_pop_clip(); */
  117. /* draw_child( *hscroll ); */
  118. /* draw_child( *vscroll ); */
  119. fl_push_clip( rulers->x(), rulers->y(), rulers->w(), rulers->h() );
  120. draw_child( *rulers );
  121. fl_pop_clip();
  122. fl_push_clip( tracks->x(), rulers->y() + rulers->h(), tracks->w(), h() - hscroll->h() );
  123. draw_child( *tracks );
  124. fl_pop_clip();
  125. draw_child( *hscroll );
  126. draw_child( *vscroll );
  127. return;
  128. }
  129. if ( damage() & FL_DAMAGE_SCROLL )
  130. {
  131. int dx = ts_to_x( _old_xposition ) - ts_to_x( xoffset );
  132. int dy = _old_yposition - yposition;
  133. if ( ! dy )
  134. fl_scroll( X, rulers->y(), W, rulers->h(), dx, 0, draw_clip, this );
  135. Y = rulers->y() + rulers->h();
  136. H = h() - rulers->h() - hscroll->h();
  137. fl_scroll( X, Y, W, H, dx, dy, draw_clip, this );
  138. _old_xposition = xoffset;
  139. _old_yposition = yposition;
  140. }
  141. if ( damage() & FL_DAMAGE_CHILD )
  142. {
  143. fl_push_clip( rulers->x(), rulers->y(), rulers->w(), rulers->h() );
  144. update_child( *rulers );
  145. fl_pop_clip();
  146. fl_push_clip( tracks->x(), rulers->y() + rulers->h(), tracks->w(), h() - rulers->h() - hscroll->h() );
  147. update_child( *tracks );
  148. fl_pop_clip();
  149. update_child( *hscroll );
  150. update_child( *vscroll );
  151. }
  152. }
  153. int handle ( int m )
  154. {
  155. switch ( m )
  156. {
  157. case FL_MOUSEWHEEL:
  158. {
  159. if ( hscroll->handle( m ) )
  160. return 1;
  161. return vscroll->handle( m );
  162. }
  163. default:
  164. return Fl_Group::handle( m );
  165. }
  166. }
  167. };