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.

226 lines
6.4KB

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