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.

208 lines
5.5KB

  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_position;
  41. enum snap_flags_e {
  42. SNAP_TO_REGION,
  43. SNAP_TO_BAR,
  44. SNAP_TO_BEAT
  45. } snap_to;
  46. Fl_Scroll *scroll;
  47. Fl_Pack *tracks;
  48. Fl_Pack *rulers;
  49. Scalebar *scrollbar;
  50. Tempo_Track *tempo_track;
  51. Time_Track *time_track;
  52. float fpp; /* frames per pixel */
  53. // nframes_t fpp;
  54. nframes_t sample_rate;
  55. nframes_t xoffset;
  56. nframes_t length;
  57. int _beats_per_bar;
  58. float _beats_per_minute;
  59. Timeline ( int X, int Y, int W, int H, const char *L=0 );
  60. int
  61. ts_to_x( nframes_t ts )
  62. {
  63. // assert( ts / fpp > 0 );
  64. return ts / fpp;
  65. }
  66. nframes_t
  67. x_to_ts ( int x )
  68. {
  69. return x * fpp;
  70. }
  71. float beats_per_minute ( nframes_t when ) const;
  72. void beats_per_minute ( nframes_t when, float bpm );
  73. void draw_measure_lines ( int X, int Y, int W, int H, Fl_Color color );
  74. /** set scroll position */
  75. void
  76. position ( int X )
  77. {
  78. _old_position = xoffset;
  79. xoffset = x_to_ts( X );
  80. damage( FL_DAMAGE_SCROLL );
  81. /* rulers->damage( FL_DAMAGE_SCROLL ); */
  82. /* tracks->damage( FL_DAMAGE_SCROLL ); */
  83. }
  84. #define FOR_CHILDREN_OF( name, ind ) \
  85. for ( int i = (name) ->children(); i-- && ( (ind) = (name) ->child( i ) ); )
  86. static void
  87. draw_clip ( void * v, int X, int Y, int W, int H )
  88. {
  89. Timeline *tl = (Timeline *)v;
  90. fl_push_clip( X, Y, W, H );
  91. fl_color( rand() );
  92. fl_rectf( X, Y, X + W, Y + H );
  93. // tl->tracks->redraw();
  94. tl->draw_child( *tl->rulers );
  95. tl->draw_child( *tl->tracks );
  96. // tl->tracks->draw();
  97. // tl->rulers->draw();
  98. /* FOR_CHILDREN_OF( tracks, o ) */
  99. /* { */
  100. /* tracks->draw_child( *o ); */
  101. /* tracks->draw_outside_label( *o ); */
  102. /* } */
  103. /* FOR_CHILDREN_OF( rulers, o ) */
  104. /* { */
  105. /* tracks->draw_child( o ); */
  106. /* tracks->draw_outside_label( o ); */
  107. /* } */
  108. fl_pop_clip();
  109. }
  110. void
  111. draw ( void )
  112. {
  113. int X, Y, W, H;
  114. X = tracks->x() + Fl::box_dx( tracks->child( 0 )->box() ) + 1;
  115. Y = tracks->y();
  116. W = tracks->w() - Fl::box_dw( tracks->child( 0 )->box() ) - 2;
  117. H = tracks->h();
  118. /* fl_color( FL_RED ); */
  119. /* fl_rect( X, Y, X + W, Y + H ); */
  120. if ( damage() & FL_DAMAGE_ALL )
  121. {
  122. Fl_Group::draw();
  123. /* draw_clip( this, X, tracks->y(), W, tracks->h() ); */
  124. /* draw_clip( this, X, rulers->y(), W, rulers->h() ); */
  125. return;
  126. }
  127. if ( damage() & FL_DAMAGE_SCROLL )
  128. {
  129. printf( "doing scroll\n" );
  130. int dx = ts_to_x( _old_position ) - ts_to_x( xoffset );
  131. fl_scroll( X, tracks->y(), W, tracks->h(), dx, 0, draw_clip, this );
  132. fl_scroll( X, rulers->y(), W, rulers->h(), dx, 0, draw_clip, this );
  133. _old_position = 0;
  134. }
  135. if ( damage() & FL_DAMAGE_CHILD )
  136. {
  137. Fl_Widget *o;
  138. FOR_CHILDREN_OF( this, o )
  139. this->update_child( *o );
  140. /* FOR_CHILDREN_OF( tracks, o ) */
  141. /* tracks->update_child( o ); */
  142. /* FOR_CHILDREN_OF( rulers, o ) */
  143. /* rulers->update_child( o ); */
  144. // fl_pop_clip()
  145. }
  146. }
  147. };