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.

143 lines
4.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. Timeline::Timeline ( int X, int Y, int W, int H, const char* L ) : Fl_Group( X, Y, W, H, L )
  23. {
  24. xoffset = 0;
  25. {
  26. Fl_Pack *o = new Fl_Pack( 0, 0, 800, 600, "rulers" );
  27. o->type( Fl_Pack::VERTICAL );
  28. {
  29. Tempo_Track *o = new Tempo_Track( 0, 0, 800, 24 );
  30. o->color( FL_RED );
  31. o->add( new Tempo_Point( 0, 120 ) );
  32. o->add( new Tempo_Point( 56000, 250 ) );
  33. tempo_track = o;
  34. o->end();
  35. }
  36. {
  37. Time_Track *o = new Time_Track( 0, 24, 800, 24 );
  38. o->color( fl_color_average( FL_RED, FL_WHITE, 0.50f ) );
  39. o->add( new Time_Point( 0, 4, 4 ) );
  40. o->add( new Time_Point( 345344, 6, 8 ) );
  41. time_track = o;
  42. o->end();
  43. }
  44. rulers = o;
  45. o->end();
  46. }
  47. {
  48. Fl_Scroll *o = new Fl_Scroll( 0, 24 * 2, 800, 600 - (24 * 3) );
  49. o->type( Fl_Scroll::VERTICAL_ALWAYS );
  50. sample_rate = 44100;
  51. fpp = 256;
  52. _beats_per_minute = 120;
  53. length = sample_rate * 60 * 2;
  54. {
  55. Fl_Pack *o = new Fl_Pack( 0, 0, 800, 5000 );
  56. o->type( Fl_Pack::VERTICAL );
  57. o->spacing( 10 );
  58. Track *l = NULL;
  59. for ( int i = 6; i--; )
  60. {
  61. Track *o = new Audio_Track( 0, 0, 800, 100 );
  62. o->prev( l );
  63. if ( l )
  64. l->next( o );
  65. l = o;
  66. o->end();
  67. }
  68. tracks = o;
  69. o->end();
  70. }
  71. scroll = o;
  72. o->end();
  73. }
  74. redraw();
  75. end();
  76. }
  77. float
  78. Timeline::beats_per_minute ( nframes_t when ) const
  79. {
  80. return tempo_track->beats_per_minute( when );
  81. }
  82. void
  83. Timeline::beats_per_minute ( nframes_t when, float bpm )
  84. {
  85. tempo_track->add( new Tempo_Point( when, bpm ) );
  86. }
  87. /* draw appropriate measure lines inside the given bounding box */
  88. void
  89. Timeline::draw_measure_lines ( int X, int Y, int W, int H, Fl_Color color )
  90. {
  91. fl_line_style( FL_DASH, 2 );
  92. fl_color( fl_color_average( FL_BLACK, color, 0.65f ) );
  93. // int measure = ts_to_x( sample_rate * 60 / beats_per_minute() );
  94. int measure;
  95. for ( int x = X; x < X + W; ++x )
  96. {
  97. measure = ts_to_x( (double)(sample_rate * 60) / beats_per_minute( x_to_ts( x ) + xoffset ));
  98. /* don't bother with lines this close together */
  99. if ( measure < 4 )
  100. break;
  101. if ( 0 == (ts_to_x( xoffset ) + x) % measure )
  102. fl_line( x, Y, x, Y + H );
  103. }
  104. fl_line_style( FL_SOLID, 0 );
  105. }