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.

131 lines
3.8KB

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