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. #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. timeline->damage( FL_DAMAGE_SCROLL );
  48. }
  49. Timeline::Timeline ( int X, int Y, int W, int H, const char* L ) : Fl_Group( X, Y, W, H, L )
  50. {
  51. xoffset = 0;
  52. {
  53. Scalebar *o = new Scalebar( X, H - 18, W - 18, 18 );
  54. o->range( 0, 48000 * 2 );
  55. o->zoom_range( 2, 8192 );
  56. o->zoom( 256 );
  57. o->type( FL_HORIZONTAL );
  58. o->callback( cb_hscroll, 0 );
  59. hscroll = o;
  60. }
  61. {
  62. Fl_Scrollbar *o = new Fl_Scrollbar( W - 18, Y, 18, H - 18 );
  63. o->type( FL_VERTICAL );
  64. o->step( 10 );
  65. o->callback( cb_vscroll, 0 );
  66. vscroll = o;
  67. }
  68. {
  69. Fl_Pack *o = new Fl_Pack( 0, 0, W - vscroll->w(), H - hscroll->h(), "rulers" );
  70. o->type( Fl_Pack::VERTICAL );
  71. {
  72. Tempo_Track *o = new Tempo_Track( 0, 0, 800, 24 );
  73. o->color( FL_RED );
  74. o->add( new Tempo_Point( 0, 120 ) );
  75. o->add( new Tempo_Point( 56000, 250 ) );
  76. tempo_track = o;
  77. o->end();
  78. }
  79. {
  80. Time_Track *o = new Time_Track( 0, 24, 800, 24 );
  81. o->color( fl_color_average( FL_RED, FL_WHITE, 0.50f ) );
  82. o->add( new Time_Point( 0, 4, 4 ) );
  83. o->add( new Time_Point( 345344, 6, 8 ) );
  84. time_track = o;
  85. o->end();
  86. }
  87. o->size( o->w(), o->child( 0 )->h() * o->children() );
  88. rulers = o;
  89. o->end();
  90. }
  91. {
  92. /* Fl_Scroll *o = new Fl_Scroll( 0, 24 * 2, 800, 600 - (24 * 3) ); */
  93. /* o->type( Fl_Scroll::VERTICAL_ALWAYS ); */
  94. sample_rate = 44100;
  95. fpp = 256;
  96. _beats_per_minute = 120;
  97. length = sample_rate * 60 * 2;
  98. {
  99. Fl_Pack *o = new Fl_Pack( X, rulers->y() + rulers->h(), W - vscroll->w(), 5000 );
  100. o->type( Fl_Pack::VERTICAL );
  101. o->spacing( 10 );
  102. Track *l = NULL;
  103. for ( int i = 16; i--; )
  104. {
  105. Track *o = new Audio_Track( 0, 0, 800, 100 );
  106. o->prev( l );
  107. if ( l )
  108. l->next( o );
  109. l = o;
  110. o->end();
  111. }
  112. tracks = o;
  113. o->end();
  114. }
  115. /* scroll = o; */
  116. /* o->end(); */
  117. }
  118. vscroll->range( 0, tracks->h() );
  119. redraw();
  120. end();
  121. }
  122. float
  123. Timeline::beats_per_minute ( nframes_t when ) const
  124. {
  125. return tempo_track->beats_per_minute( when );
  126. }
  127. void
  128. Timeline::beats_per_minute ( nframes_t when, float bpm )
  129. {
  130. tempo_track->add( new Tempo_Point( when, bpm ) );
  131. }
  132. /* draw appropriate measure lines inside the given bounding box */
  133. void
  134. Timeline::draw_measure_lines ( int X, int Y, int W, int H, Fl_Color color )
  135. {
  136. fl_line_style( FL_DASH, 2 );
  137. fl_color( fl_color_average( FL_BLACK, color, 0.65f ) );
  138. // int measure = ts_to_x( sample_rate * 60 / beats_per_minute() );
  139. int measure;
  140. for ( int x = X; x < X + W; ++x )
  141. {
  142. measure = ts_to_x( (double)(sample_rate * 60) / beats_per_minute( x_to_ts( x ) + xoffset ));
  143. /* don't bother with lines this close together */
  144. if ( measure < 4 )
  145. break;
  146. if ( 0 == (ts_to_x( xoffset ) + x) % measure )
  147. fl_line( x, Y, x, Y + H );
  148. }
  149. fl_line_style( FL_SOLID, 0 );
  150. }