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.

162 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. int _beats_per_bar;
  60. float _beats_per_minute;
  61. int
  62. ts_to_x( nframes_t ts )
  63. {
  64. // assert( ts / fpp > 0 );
  65. return ts / fpp;
  66. }
  67. nframes_t
  68. x_to_ts ( int x )
  69. {
  70. return x * fpp;
  71. }
  72. float
  73. beats_per_minute ( void ) const
  74. {
  75. // TODO: this should check a tempo map.
  76. return _beats_per_minute;
  77. }
  78. float
  79. beats_per_minute ( nframes_t when ) const
  80. {
  81. for ( list <tempo_event>::const_reverse_iterator i = tempo_points.rbegin();
  82. i != tempo_points.rend(); i++ )
  83. {
  84. if ( i->timestamp < when )
  85. return i->beats_per_minute;
  86. }
  87. return _beats_per_minute;
  88. }
  89. void
  90. beats_per_minute ( nframes_t when, float bpm )
  91. {
  92. tempo_event t;
  93. t.timestamp = when;
  94. t.beats_per_minute = bpm;
  95. tempo_points.push_back( t );
  96. }
  97. /* /\* return the offset of the closest measure line to /t/ *\/ */
  98. /* nframes_t */
  99. /* snap ( nframes t ) */
  100. /* { */
  101. /* } */
  102. /* draw appropriate measure lines inside the given bounding box */
  103. void
  104. draw_measure_lines ( int X, int Y, int W, int H, Fl_Color color )
  105. {
  106. fl_line_style( FL_DASH, 2 );
  107. fl_color( fl_color_average( FL_BLACK, color, 0.65f ) );
  108. // int measure = ts_to_x( sample_rate * 60 / beats_per_minute() );
  109. int measure;
  110. for ( int x = X; x < X + W; ++x )
  111. {
  112. measure = ts_to_x( (double)(sample_rate * 60) / beats_per_minute( x_to_ts( x ) + xoffset ));
  113. if ( 0 == (ts_to_x( xoffset ) + x) % measure )
  114. fl_line( x, Y, x, Y + H );
  115. }
  116. fl_line_style( FL_SOLID, 0 );
  117. }
  118. };
  119. extern Timeline timeline;