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.

321 lines
9.1KB

  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. #include "OSC_Thread.H"
  27. class Fl_Scroll;
  28. class Fl_Pack;
  29. class Fl_Scrollbar;
  30. class Fl_Widget;
  31. class Fl_Menu_Button;
  32. class Fl_Menu_;
  33. class Timeline;
  34. extern Timeline *timeline;
  35. struct BBT;
  36. class Tempo_Sequence;
  37. class Time_Sequence;
  38. class Annotation_Sequence;
  39. class Cursor_Sequence;
  40. class Track;
  41. class Sequence;
  42. class Sequence_Widget;
  43. class Cursor_Region;
  44. class Cursor_Point;
  45. class Fl_Panzoomer;
  46. namespace OSC { class Endpoint; }
  47. #define USE_WIDGET_FOR_TIMELINE
  48. #include <lo/lo.h>
  49. #ifndef USE_SINGLEBUFFERED_TIMELINE
  50. #include <FL/Fl_Overlay_Window.H>
  51. #else
  52. #include <FL/Fl_Single_Window.H>
  53. #endif
  54. struct position_info;
  55. struct Rectangle
  56. {
  57. int x;
  58. int y;
  59. int w;
  60. int h;
  61. Rectangle ( ) : x( 0 ), y( 0 ), w( 0 ), h( 0 ) {}
  62. Rectangle ( int X, int Y, int W, int H ) : x( X ), y( Y ), w( W ), h( H ) {}
  63. };
  64. #include "RWLock.H"
  65. #ifdef USE_WIDGET_FOR_TIMELINE
  66. class Timeline : public Fl_Group, public RWLock
  67. #else
  68. #ifndef USE_SINGLEBUFFERED_TIMELINE
  69. class Timeline : public Fl_Overlay_Window, public RWLock
  70. #else
  71. class Timeline : public Fl_Single_Window, public RWLock
  72. #endif
  73. #endif
  74. {
  75. static void draw_clip ( void * v, int X, int Y, int W, int H );
  76. static void draw_thumbnail_view( int X, int Y,int W, int H, void *v);
  77. void draw_thumbnail_view( int X, int Y,int W, int H) const;
  78. int _old_xposition;
  79. int _old_yposition;
  80. Rectangle _selection;
  81. Fl_Pack *tracks;
  82. Fl_Pack *rulers;
  83. Fl_Panzoomer *panzoomer;
  84. void adjust_panzoomer ( void );
  85. static void cb_scroll ( Fl_Widget *w, void *v );
  86. void cb_scroll ( Fl_Widget *w );
  87. static void menu_cb ( Fl_Widget *w, void *v );
  88. void menu_cb ( Fl_Menu_ *m );
  89. void fix_range ( void );
  90. int _fpp; /* frames per pixel, power of two */
  91. // nframes_t p1, p2; /* cursors */
  92. nframes_t _playhead;
  93. /* not permitted */
  94. Timeline ( const Timeline &rhs );
  95. Timeline & operator = ( const Timeline &rhs );
  96. std::list <const Sequence_Widget*> _tempomap;
  97. static void handle_peer_scan_complete ( void * v );
  98. void update_track_order ( void );
  99. void apply_track_order ( void );
  100. void insert_track ( Track *track, int n );
  101. public:
  102. OSC::Endpoint *osc;
  103. OSC_Thread *osc_thread;
  104. void process_osc ( void );
  105. #undef Bars
  106. #undef Beats
  107. #undef None
  108. enum snap_e {
  109. Bars,
  110. Beats,
  111. None
  112. };
  113. /* configuration values */
  114. static bool draw_with_measure_lines;
  115. static bool draw_with_cursor_overlay;
  116. static snap_e snap_to;
  117. static bool snapping_on_hold;
  118. static bool snap_magnetic;
  119. static bool follow_playhead;
  120. static bool center_playhead;
  121. static bool loop_playback;
  122. static bool automatically_create_takes;
  123. Tempo_Sequence *tempo_track;
  124. Time_Sequence *time_track;
  125. Annotation_Sequence *ruler_track;
  126. Cursor_Sequence *edit_cursor_track;
  127. Cursor_Sequence *punch_cursor_track;
  128. Cursor_Sequence *play_cursor_track;
  129. Fl_Menu_Button *menu;
  130. int _punched_in;
  131. nframes_t _punch_out_frame;
  132. nframes_t _punch_in_frame;
  133. bool _created_new_takes;
  134. nframes_t xoffset;
  135. nframes_t _sample_rate;
  136. Timeline ( int X, int Y, int W, int H, const char *L=0 );
  137. virtual ~Timeline ( );
  138. void update_tempomap ( void );
  139. const char *session_manager_name ( void );
  140. nframes_t fpp ( void ) const { return 1 << _fpp; }
  141. void range ( nframes_t start, nframes_t length );
  142. nframes_t range_start ( void ) const;
  143. nframes_t range_end ( void ) const;
  144. void range_start ( nframes_t n );
  145. void range_end ( nframes_t n );
  146. void reset_range ( void );
  147. nframes_t playback_home ( void ) const;
  148. nframes_t playback_end ( void ) const;
  149. // nframes_t playhead ( void ) const { return transport->frame; }
  150. nframes_t length ( void ) const;
  151. void sample_rate ( nframes_t r ) { _sample_rate = r; }
  152. nframes_t sample_rate ( void ) const { return _sample_rate; }
  153. int ts_to_x( nframes_t ts ) const { return ts >> _fpp; }
  154. nframes_t x_to_ts ( int x ) const { return x << _fpp; }
  155. nframes_t x_to_offset ( int x ) const;
  156. float beats_per_minute ( nframes_t when ) const;
  157. int beats_per_bar ( nframes_t when ) const;
  158. void beats_per_minute ( nframes_t when, float bpm );
  159. void time ( nframes_t when, int bpb, int beat_type );
  160. bool nearest_line ( nframes_t *f, bool snap=true ) const;
  161. bool next_line ( nframes_t *f, bool bar=false ) const;
  162. bool prev_line ( nframes_t *f, bool bar=false ) const;
  163. typedef void (measure_line_callback)( nframes_t frame, const BBT & bbt, void *arg );
  164. position_info solve_tempomap ( nframes_t when ) const;
  165. void draw_measure_lines ( int X, int Y, int W, int H );
  166. void draw_measure_BBT ( int X, int Y, int W, int H );
  167. position_info render_tempomap ( nframes_t start, nframes_t length, measure_line_callback *cb, void *arg ) const;
  168. void xposition ( int X );
  169. void draw_cursor ( nframes_t frame, Fl_Color color, void (*symbol)(Fl_Color) ) const;
  170. void draw_cursors ( Cursor_Sequence *o ) const;
  171. void draw_cursors ( void ) const;
  172. void draw_playhead ( void );
  173. void redraw_playhead ( void );
  174. void resize ( int X, int Y, int W, int H );
  175. void draw ( void );
  176. void draw_overlay ( void );
  177. int handle_scroll ( int m );
  178. int handle ( int m );
  179. static void update_cb ( void *arg );
  180. void select( const Rectangle &r );
  181. Track * track_under ( int Y );
  182. int nselected ( void ) const;
  183. void delete_selected ( void );
  184. void select_none ( void );
  185. void add_track ( Track *track );
  186. void remove_track ( Track *track );
  187. void move_track_up ( Track *track );
  188. void move_track_down ( Track *track );
  189. int find_track ( const Track * track ) const;
  190. int ntracks ( void ) const;
  191. void zoom ( float secs );
  192. void zoom_in ( void );
  193. void zoom_out ( void );
  194. void zoom_fit ( void );
  195. /* Engine */
  196. int total_input_buffer_percent ( void );
  197. int total_output_buffer_percent ( void );
  198. int total_playback_xruns ( void );
  199. int total_capture_xruns ( void );
  200. nframes_t total_output_latency ( void ) const;
  201. bool record ( void );
  202. void stop ( void );
  203. void punch_in ( nframes_t frame );
  204. void punch_out ( nframes_t frame );
  205. void wait_for_buffers ( void );
  206. bool seek_pending ( void );
  207. bool command_load ( const char *name, const char *display_name );
  208. bool command_new ( const char *name, const char *display_name );
  209. bool command_save ( void );
  210. void command_quit ( void );
  211. /* OSC */
  212. void connect_osc ( void );
  213. void discover_peers ( void );
  214. static void check_osc ( void * v );
  215. int init_osc ( const char *osc_port );
  216. static int osc_reply ( const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data );
  217. static int osc_non_hello ( const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data );
  218. void reply_to_finger ( lo_message msg );
  219. void add_cursor ( Cursor_Region *o );
  220. void add_cursor ( Cursor_Point *o );
  221. private:
  222. void add_take_for_armed_tracks();
  223. void resize_rulers ( void );
  224. static void snapshot ( void *v ) { ((Timeline*)v)->snapshot(); }
  225. void snapshot ( void );
  226. friend class Engine; // FIXME: only Engine::process() needs to be friended.x
  227. Track * track_by_name ( const char *name );
  228. char * get_unique_track_name ( const char *name );
  229. /* Engine */
  230. void resize_buffers ( nframes_t nframes );
  231. nframes_t process ( nframes_t nframes );
  232. void seek ( nframes_t frame );
  233. };