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.

234 lines
6.3KB

  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. void draw_measure_lines ( int X, int Y, int W, int H, Fl_Color color );
  77. /** set scroll position */
  78. void
  79. position ( int X )
  80. {
  81. _old_xposition = xoffset;
  82. xoffset = x_to_ts( X );
  83. damage( FL_DAMAGE_SCROLL );
  84. /* rulers->damage( FL_DAMAGE_SCROLL ); */
  85. /* tracks->damage( FL_DAMAGE_SCROLL ); */
  86. }
  87. #define FOR_CHILDREN_OF( name, ind ) \
  88. for ( int i = (name) ->children(); i-- && ( (ind) = (name) ->child( i ) ); )
  89. static void
  90. draw_clip ( void * v, int X, int Y, int W, int H )
  91. {
  92. Timeline *tl = (Timeline *)v;
  93. // printf( "draw_clip: %d,%d %dx%d\n", X, Y, W, H );
  94. fl_push_clip( X, Y, W, H );
  95. fl_color( rand() );
  96. fl_rectf( X, Y, X + W, Y + H );
  97. tl->draw_child( *tl->tracks );
  98. tl->draw_child( *tl->rulers );
  99. fl_pop_clip();
  100. }
  101. void
  102. draw ( void )
  103. {
  104. int X, Y, W, H;
  105. X = tracks->x() + Fl::box_dx( tracks->child( 0 )->box() ) + 1;
  106. Y = tracks->y();
  107. W = tracks->w() - Fl::box_dw( tracks->child( 0 )->box() ) - 1;
  108. H = tracks->h();
  109. /* fl_color( FL_RED ); */
  110. /* fl_rect( X, Y, X + W, Y + H ); */
  111. if ( damage() & FL_DAMAGE_ALL )
  112. {
  113. /* fl_push_clip( x(), y(), w() - vscroll->w(), h() - hscroll->h() ); */
  114. /* Fl_Group::draw(); */
  115. /* fl_pop_clip(); */
  116. /* draw_child( *hscroll ); */
  117. /* draw_child( *vscroll ); */
  118. fl_push_clip( rulers->x(), rulers->y(), rulers->w(), rulers->h() );
  119. draw_child( *rulers );
  120. fl_pop_clip();
  121. fl_push_clip( tracks->x(), rulers->y() + rulers->h(), tracks->w(), h() - hscroll->h() );
  122. draw_child( *tracks );
  123. fl_pop_clip();
  124. draw_child( *hscroll );
  125. draw_child( *vscroll );
  126. return;
  127. }
  128. if ( damage() & FL_DAMAGE_SCROLL )
  129. {
  130. int dx = ts_to_x( _old_xposition ) - ts_to_x( xoffset );
  131. int dy = _old_yposition - yposition;
  132. if ( ! dy )
  133. fl_scroll( X, rulers->y(), W, rulers->h(), dx, 0, draw_clip, this );
  134. Y = rulers->y() + rulers->h();
  135. H = h() - rulers->h() - hscroll->h();
  136. fl_scroll( X, Y, W, H, dx, dy, draw_clip, this );
  137. _old_xposition = xoffset;
  138. _old_yposition = yposition;
  139. }
  140. if ( damage() & FL_DAMAGE_CHILD )
  141. {
  142. fl_push_clip( rulers->x(), rulers->y(), rulers->w(), rulers->h() );
  143. update_child( *rulers );
  144. fl_pop_clip();
  145. fl_push_clip( tracks->x(), rulers->y() + rulers->h(), tracks->w(), h() - rulers->h() - hscroll->h() );
  146. update_child( *tracks );
  147. fl_pop_clip();
  148. update_child( *hscroll );
  149. update_child( *vscroll );
  150. }
  151. }
  152. int handle ( int m )
  153. {
  154. switch ( m )
  155. {
  156. case FL_MOUSEWHEEL:
  157. {
  158. if ( hscroll->handle( m ) )
  159. return 1;
  160. return vscroll->handle( m );
  161. }
  162. default:
  163. return Fl_Group::handle( m );
  164. }
  165. }
  166. };