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.

213 lines
6.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. #pragma once
  19. #include <FL/Fl_Scroll.H>
  20. #include <FL/Fl_Pack.H>
  21. #include <FL/Fl_Scrollbar.H>
  22. #include <FL/Fl_Widget.H>
  23. #include <FL/fl_draw.H>
  24. #include "Scalebar.H"
  25. /* FIXME: this class needs a lot of cleaning up. Too many public
  26. * members etc. */
  27. /* #include "Audio_File.H" // just for nframes_t */
  28. #include "types.h"
  29. #include <math.h>
  30. #include <assert.h>
  31. class Timeline;
  32. extern Timeline *timeline;
  33. #include "Sequence.H"
  34. struct BBT;
  35. class Tempo_Sequence;
  36. class Time_Sequence;
  37. class Annotation_Sequence;
  38. class Track;
  39. // disables double-buffering to make unnecessary redrawing more apparent
  40. // #define DEBUG_TIMELINE_DRAWING
  41. #ifndef DEBUG_TIMELINE_DRAWING
  42. #include <Fl/Fl_Overlay_Window.H>
  43. #else
  44. #include <FL/Fl_Single_Window.H>
  45. #define Fl_Overlay_Window Fl_Single_Window
  46. #define redraw_overlay()
  47. #endif
  48. struct position_info;
  49. struct Rectangle
  50. {
  51. int x;
  52. int y;
  53. int w;
  54. int h;
  55. Rectangle ( ) : x( 0 ), y( 0 ), w( 0 ), h( 0 ) {}
  56. Rectangle ( int X, int Y, int W, int H ) : x( X ), y( Y ), w( W ), h( H ) {}
  57. };
  58. #include "Engine.H" // for sample_rate()
  59. // class Engine;
  60. #include "RWLock.H"
  61. class Timeline : public Fl_Overlay_Window, public RWLock
  62. {
  63. static void draw_clip ( void * v, int X, int Y, int W, int H );
  64. int _old_xposition;
  65. int _old_yposition;
  66. Rectangle _selection;
  67. Fl_Scroll *scroll;
  68. Fl_Pack *tracks;
  69. Fl_Pack *rulers;
  70. Scalebar *hscroll;
  71. Fl_Scrollbar *vscroll;
  72. void adjust_vscroll ( void );
  73. static void cb_scroll ( Fl_Widget *w, void *v );
  74. void cb_scroll ( Fl_Widget *w );
  75. int _fpp; /* frames per pixel, power of two */
  76. nframes_t _length;
  77. nframes_t p1, p2; /* cursors */
  78. /* not permitted */
  79. Timeline ( const Timeline &rhs );
  80. Timeline & operator = ( const Timeline &rhs );
  81. std::list <const Sequence_Widget*> _tempomap;
  82. public:
  83. enum snap_e {
  84. Bars,
  85. Beats,
  86. None
  87. };
  88. static bool draw_with_measure_lines;
  89. static snap_e snap_to;
  90. static bool snap_magnetic;
  91. static bool follow_playhead;
  92. static bool center_playhead;
  93. Tempo_Sequence *tempo_track;
  94. Time_Sequence *time_track;
  95. Annotation_Sequence *ruler_track;
  96. nframes_t xoffset;
  97. int _yposition;
  98. Timeline ( int X, int Y, int W, int H, const char *L=0 );
  99. void update_tempomap ( void );
  100. nframes_t fpp ( void ) const { return 1 << _fpp; }
  101. nframes_t length ( void ) const { return _length; }
  102. nframes_t sample_rate ( void ) const { return engine->sample_rate(); }
  103. int ts_to_x( nframes_t ts ) const { return ts >> _fpp; }
  104. nframes_t x_to_ts ( int x ) const { return x << _fpp; }
  105. nframes_t x_to_offset ( int x ) const;
  106. float beats_per_minute ( nframes_t when ) const;
  107. int beats_per_bar ( nframes_t when ) const;
  108. void beats_per_minute ( nframes_t when, float bpm );
  109. void time ( nframes_t when, int bpb, int beat_type );
  110. bool nearest_line ( nframes_t when, nframes_t *f ) const;
  111. typedef void (measure_line_callback)( nframes_t frame, const BBT & bbt, void *arg );
  112. position_info solve_tempomap ( nframes_t when ) const;
  113. void draw_measure_lines ( int X, int Y, int W, int H, Fl_Color color );
  114. void draw_measure_BBT ( int X, int Y, int W, int H, Fl_Color color );
  115. position_info render_tempomap ( nframes_t start, nframes_t length, measure_line_callback *cb, void *arg ) const;
  116. void xposition ( int X );
  117. void yposition ( int Y );
  118. void draw_cursor ( nframes_t frame, Fl_Color color );
  119. void draw_playhead ( void );
  120. void redraw_playhead ( void );
  121. void resize ( int X, int Y, int W, int H );
  122. void draw ( void );
  123. void draw_overlay ( void );
  124. int handle ( int m );
  125. static void update_cb ( void *arg );
  126. void select( const Rectangle &r );
  127. Track * track_under ( int Y );
  128. void delete_selected ( void );
  129. void select_none ( void );
  130. void add_track ( Track *track );
  131. void remove_track ( Track *track );
  132. int total_input_buffer_percent ( void );
  133. int total_output_buffer_percent ( void );
  134. int total_playback_xruns ( void );
  135. int total_capture_xruns ( void );
  136. bool record ( void );
  137. void stop ( void );
  138. void zoom ( float secs );
  139. void zoom_in ( void );
  140. void zoom_out ( void );
  141. void zoom_fit ( void );
  142. private:
  143. friend class Engine; // FIXME: only Engine::process() needs to be friended.x
  144. Track * track_by_name ( const char *name );
  145. char * get_unique_track_name ( const char *name );
  146. /* Engine */
  147. nframes_t process ( nframes_t nframes );
  148. void seek ( nframes_t frame );
  149. int seek_pending ( void );
  150. };