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.

164 lines
4.2KB

  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 "Clip.H"
  23. #include <math.h>
  24. #include <assert.h>
  25. #include <FL/fl_draw.H>
  26. #include <list>
  27. using std::list;
  28. class timestamped
  29. {
  30. public:
  31. nframes_t timestamp;
  32. bool
  33. operator< ( const timestamped &rhs ) const { return timestamp < rhs.timestamp; }
  34. };
  35. struct Timeline {
  36. struct tempo_event : timestamped
  37. {
  38. float beats_per_minute;
  39. };
  40. struct signature_event : timestamped
  41. {
  42. int beats_per_bar;
  43. int beat_type;
  44. };
  45. enum snap_flags_e {
  46. SNAP_TO_REGION,
  47. SNAP_TO_BAR,
  48. SNAP_TO_BEAT
  49. } snap_to;
  50. list <tempo_event> tempo_points;
  51. list <signature_event> signature_points;
  52. Fl_Scroll *scroll;
  53. Fl_Pack *tracks;
  54. Fl_Scrollbar *scrollbar;
  55. float fpp; /* frames per pixel */
  56. // nframes_t fpp;
  57. nframes_t sample_rate;
  58. nframes_t xoffset;
  59. nframes_t length;
  60. int _beats_per_bar;
  61. float _beats_per_minute;
  62. int
  63. ts_to_x( nframes_t ts )
  64. {
  65. // assert( ts / fpp > 0 );
  66. return ts / fpp;
  67. }
  68. nframes_t
  69. x_to_ts ( int x )
  70. {
  71. return x * fpp;
  72. }
  73. float
  74. beats_per_minute ( void ) const
  75. {
  76. // TODO: this should check a tempo map.
  77. return _beats_per_minute;
  78. }
  79. float
  80. beats_per_minute ( nframes_t when ) const
  81. {
  82. for ( list <tempo_event>::const_reverse_iterator i = tempo_points.rbegin();
  83. i != tempo_points.rend(); i++ )
  84. {
  85. if ( i->timestamp < when )
  86. return i->beats_per_minute;
  87. }
  88. return _beats_per_minute;
  89. }
  90. void
  91. beats_per_minute ( nframes_t when, float bpm )
  92. {
  93. tempo_event t;
  94. t.timestamp = when;
  95. t.beats_per_minute = bpm;
  96. tempo_points.push_back( t );
  97. }
  98. /* /\* return the offset of the closest measure line to /t/ *\/ */
  99. /* nframes_t */
  100. /* snap ( nframes t ) */
  101. /* { */
  102. /* } */
  103. /* draw appropriate measure lines inside the given bounding box */
  104. void
  105. draw_measure_lines ( int X, int Y, int W, int H, Fl_Color color )
  106. {
  107. fl_line_style( FL_DASH, 2 );
  108. fl_color( fl_color_average( FL_BLACK, color, 0.65f ) );
  109. // int measure = ts_to_x( sample_rate * 60 / beats_per_minute() );
  110. int measure;
  111. for ( int x = X; x < X + W; ++x )
  112. {
  113. measure = ts_to_x( (double)(sample_rate * 60) / beats_per_minute( x_to_ts( x ) + xoffset ));
  114. if ( 0 == (ts_to_x( xoffset ) + x) % measure )
  115. fl_line( x, Y, x, Y + H );
  116. }
  117. fl_line_style( FL_SOLID, 0 );
  118. }
  119. };
  120. extern Timeline timeline;