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.

233 lines
6.0KB

  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. #include "Timeline.H"
  19. #include "Tempo_Track.H"
  20. #include "Time_Track.H"
  21. #include "Audio_Track.H"
  22. #include <FL/Fl_Scrollbar.H>
  23. void
  24. cb_hscroll ( Fl_Widget *w, void *v )
  25. {
  26. Scalebar *sb = (Scalebar*)w;
  27. if ( sb->zoom_changed() )
  28. {
  29. timeline->fpp = sb->zoom() * 1;
  30. int maxx = timeline->ts_to_x( timeline->length );
  31. sb->range( 0, maxx );
  32. timeline->redraw();
  33. }
  34. else
  35. {
  36. timeline->position( sb->value() );
  37. }
  38. printf( "%lu\n", timeline->xoffset );
  39. }
  40. void
  41. cb_vscroll ( Fl_Widget *w, void *v )
  42. {
  43. Fl_Scrollbar *sb = (Fl_Scrollbar*)w;
  44. timeline->tracks->position( timeline->tracks->x(), (timeline->rulers->y() + timeline->rulers->h()) - sb->value() );
  45. timeline->yposition = sb->value();
  46. // timeline->vscroll->range( 0, timeline->tracks->h() - timeline->h() - timeline->rulers->h() );
  47. sb->value( sb->value(), 30, 0, min( timeline->tracks->h(), timeline->tracks->h() - timeline->h() - timeline->rulers->h() ) );
  48. timeline->damage( FL_DAMAGE_SCROLL );
  49. }
  50. Timeline::Timeline ( int X, int Y, int W, int H, const char* L ) : Fl_Group( X, Y, W, H, L )
  51. {
  52. xoffset = 0;
  53. {
  54. Scalebar *o = new Scalebar( X, H - 18, W - 18, 18 );
  55. o->range( 0, 48000 * 2 );
  56. o->zoom_range( 2, 8192 );
  57. o->zoom( 256 );
  58. o->type( FL_HORIZONTAL );
  59. o->callback( cb_hscroll, 0 );
  60. hscroll = o;
  61. }
  62. {
  63. Fl_Scrollbar *o = new Fl_Scrollbar( W - 18, Y, 18, H - 18 );
  64. o->type( FL_VERTICAL );
  65. o->step( 10 );
  66. o->callback( cb_vscroll, 0 );
  67. vscroll = o;
  68. }
  69. {
  70. Fl_Pack *o = new Fl_Pack( 0, 0, W - vscroll->w(), H - hscroll->h(), "rulers" );
  71. o->type( Fl_Pack::VERTICAL );
  72. {
  73. Tempo_Track *o = new Tempo_Track( 0, 0, 800, 24 );
  74. o->color( FL_RED );
  75. o->add( new Tempo_Point( 0, 120 ) );
  76. o->add( new Tempo_Point( 56000, 250 ) );
  77. tempo_track = o;
  78. o->end();
  79. }
  80. {
  81. Time_Track *o = new Time_Track( 0, 24, 800, 24 );
  82. o->color( fl_color_average( FL_RED, FL_WHITE, 0.50f ) );
  83. o->add( new Time_Point( 0, 4, 4 ) );
  84. o->add( new Time_Point( 345344, 6, 8 ) );
  85. time_track = o;
  86. o->end();
  87. }
  88. o->size( o->w(), o->child( 0 )->h() * o->children() );
  89. rulers = o;
  90. o->end();
  91. }
  92. {
  93. /* Fl_Scroll *o = new Fl_Scroll( 0, 24 * 2, 800, 600 - (24 * 3) ); */
  94. /* o->type( Fl_Scroll::VERTICAL_ALWAYS ); */
  95. sample_rate = 44100;
  96. fpp = 256;
  97. _beats_per_minute = 120;
  98. length = sample_rate * 60 * 2;
  99. {
  100. Fl_Pack *o = new Fl_Pack( X, rulers->y() + rulers->h(), W - vscroll->w(), 5000 );
  101. o->type( Fl_Pack::VERTICAL );
  102. o->spacing( 10 );
  103. Track *l = NULL;
  104. for ( int i = 16; i--; )
  105. {
  106. Track *o = new Audio_Track( 0, 0, 800, 100 );
  107. o->prev( l );
  108. if ( l )
  109. l->next( o );
  110. l = o;
  111. o->end();
  112. }
  113. tracks = o;
  114. o->end();
  115. }
  116. /* scroll = o; */
  117. /* o->end(); */
  118. }
  119. vscroll->range( 0, tracks->h() );
  120. redraw();
  121. end();
  122. }
  123. float
  124. Timeline::beats_per_minute ( nframes_t when ) const
  125. {
  126. return tempo_track->beats_per_minute( when );
  127. }
  128. int
  129. Timeline::beats_per_bar ( nframes_t when ) const
  130. {
  131. time_sig t = time_track->time( when );
  132. return t.beats_per_bar;
  133. }
  134. void
  135. Timeline::beats_per_minute ( nframes_t when, float bpm )
  136. {
  137. tempo_track->add( new Tempo_Point( when, bpm ) );
  138. }
  139. /* draw appropriate measure lines inside the given bounding box */
  140. void
  141. Timeline::draw_measure_lines ( int X, int Y, int W, int H, Fl_Color color )
  142. {
  143. fl_line_style( FL_DASH, 2 );
  144. Fl_Color beat = fl_color_average( FL_BLACK, color, 0.65f );
  145. Fl_Color bar = fl_color_average( FL_RED, color, 0.65f );
  146. // int measure = ts_to_x( sample_rate * 60 / beats_per_minute() );
  147. int measure;
  148. for ( int x = X; x < X + W; ++x )
  149. {
  150. measure = ts_to_x( (double)(sample_rate * 60) / beats_per_minute( x_to_ts( x ) + xoffset ));
  151. int bpb = beats_per_bar( x_to_ts( x ) + xoffset );
  152. if ( 0 == (x / measure) % bpb )
  153. {
  154. if ( measure * bpb < 8 )
  155. break;
  156. fl_color( bar );
  157. }
  158. else
  159. {
  160. if ( measure < 8 )
  161. continue;
  162. fl_color( beat );
  163. }
  164. if ( 0 == (ts_to_x( xoffset ) + x) % measure )
  165. fl_line( x, Y, x, Y + H );
  166. }
  167. fl_line_style( FL_SOLID, 0 );
  168. }