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.

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