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.

282 lines
7.7KB

  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.H>
  20. #include "Sequence.H"
  21. #include <FL/Fl_Group.H>
  22. #include <FL/Fl_Input.H>
  23. #include <FL/Fl_Button.H>
  24. #include <FL/Fl_Menu_Button.H>
  25. #include <FL/Fl_Pack.H>
  26. #include <FL/Fl_Box.H>
  27. #include <FL/fl_draw.H>
  28. #include "Loggable.H"
  29. /* TODO: rename this to Audio_Track or something since it's clearly audio specific. */
  30. #include <vector>
  31. using std::vector;
  32. #include "Engine/Port.H"
  33. #include "Timeline.H"
  34. class Control_Sequence;
  35. class Annotation_Sequence;
  36. class Playback_DS;
  37. class Record_DS;
  38. class Port;
  39. class Audio_Region;
  40. class Audio_File;
  41. //class Audio_Sequence;
  42. #include "Audio_Sequence.H"
  43. class Track : public Fl_Group, public Loggable
  44. {
  45. /* not permitted */
  46. Track ( const Track &rhs );
  47. Track & operator= ( const Track &rhs );
  48. public:
  49. Track ( const char *L, int channels=1 );
  50. virtual ~Track ( );
  51. static bool soloing ( void ) { return _soloing; }
  52. static const char *capture_format;
  53. struct Capture
  54. {
  55. Audio_File *audio_file;
  56. Audio_Region *region;
  57. };
  58. private:
  59. static int _soloing;
  60. char *_name;
  61. bool _selected;
  62. bool _show_all_takes;
  63. int _size;
  64. enum { AUDIO } _type;
  65. Audio_Sequence *_sequence;
  66. bool configure_outputs ( int n );
  67. bool configure_inputs ( int n );
  68. void update_port_names ( void );
  69. const char *name_for_port( Port::type_e type, int n );
  70. Track ( ) : Fl_Group( 0, 0, 1, 1 )
  71. {
  72. init();
  73. timeline->add_track( this );
  74. }
  75. void init ( void );
  76. public:
  77. Fl_Input *name_field;
  78. Fl_Button *record_button;
  79. Fl_Button *mute_button;
  80. Fl_Button *solo_button;
  81. Fl_Menu_Button *take_menu;
  82. Fl_Group *controls;
  83. Fl_Pack *pack;
  84. Fl_Pack *annotation;
  85. Fl_Pack *control;
  86. Fl_Pack *takes;
  87. vector<Port> input; /* input ports... */
  88. vector<Port> output; /* output ports... */
  89. vector<Port*> control_out; /* control ports... */
  90. Playback_DS *playback_ds;
  91. Record_DS *record_ds;
  92. // const char *class_name ( void ) { return "Track"; }
  93. void
  94. set ( Log_Entry &e )
  95. {
  96. for ( int i = 0; i < e.size(); ++i )
  97. {
  98. const char *s, *v;
  99. e.get( i, &s, &v );
  100. if ( ! strcmp( s, ":height" ) )
  101. {
  102. size( atoi( v ) );
  103. // Fl_Widget::size( w(), height() );
  104. resize();
  105. }
  106. else if ( ! strcmp( s, ":selected" ) )
  107. _selected = atoi( v );
  108. // else if ( ! strcmp( s, ":armed"
  109. else if ( ! strcmp( s, ":name" ) )
  110. name( v );
  111. else if ( ! strcmp( s, ":inputs" ) )
  112. configure_inputs( atoi( v ) );
  113. else if ( ! strcmp( s, ":outputs" ) )
  114. configure_outputs( atoi( v ) );
  115. else if ( ! strcmp( s, ":color" ) )
  116. {
  117. color( (Fl_Color)atoll( v ) );
  118. redraw();
  119. }
  120. else if ( ! strcmp( s, ":sequence" ) )
  121. {
  122. int i;
  123. sscanf( v, "%X", &i );
  124. if ( i )
  125. {
  126. Audio_Sequence *t = (Audio_Sequence*)Loggable::find( i );
  127. /* FIXME: our track might not have been
  128. * defined yet... what should we do about this
  129. * chicken/egg problem? */
  130. if ( t )
  131. {
  132. // assert( t );
  133. sequence( t );
  134. }
  135. }
  136. }
  137. }
  138. }
  139. virtual void get ( Log_Entry &e ) const
  140. {
  141. e.add( ":name", _name );
  142. e.add( ":sequence", sequence() );
  143. e.add( ":selected", _selected );
  144. e.add( ":height", size() );
  145. e.add( ":inputs", input.size() );
  146. e.add( ":outputs", output.size() );
  147. e.add( ":color", (unsigned long)color());
  148. }
  149. /* for loggable */
  150. LOG_CREATE_FUNC( Track );
  151. void add ( Annotation_Sequence *t );
  152. void remove ( Annotation_Sequence *t );
  153. void add ( Control_Sequence *t );
  154. void add ( Audio_Sequence *t );
  155. void remove ( Audio_Sequence *t );
  156. void remove ( Control_Sequence *t );
  157. void select ( int X, int Y, int W, int H, bool include_control, bool merge_control );
  158. int size ( void ) const { return _size; }
  159. int ncontrols ( void ) { return controls->children(); }
  160. void resize ( void );
  161. void size ( int v );
  162. int height ( void ) const
  163. {
  164. static int table[] = { 30, 80, 150, 300 };
  165. return table[ _size ];
  166. }
  167. void show_all_takes ( bool b )
  168. {
  169. _show_all_takes = b;
  170. resize();
  171. }
  172. void name ( const char *name )
  173. {
  174. if ( _name )
  175. free( _name );
  176. _name = strdup( name );
  177. if ( name_field )
  178. name_field->value( _name );
  179. update_port_names();
  180. }
  181. const char * name ( void ) const { return _name; }
  182. bool mute ( void ) const { return mute_button->value(); }
  183. bool solo ( void ) const { return solo_button->value(); }
  184. bool armed ( void ) const { return record_button->value(); }
  185. bool selected ( void ) const { return _selected; }
  186. static void cb_input_field ( Fl_Widget *w, void *v );
  187. void cb_input_field ( void );
  188. static void cb_button ( Fl_Widget *w, void *v );
  189. void cb_button ( Fl_Widget *w );
  190. static int width ( void ) { return 150; }
  191. void sequence ( Audio_Sequence * t );
  192. Audio_Sequence * sequence ( void ) const { return _sequence; }
  193. void draw ( void );
  194. int handle ( int m );
  195. /* Engine */
  196. const Audio_Region *capture_region ( void ) const;
  197. void resize_buffers ( nframes_t nframes );
  198. nframes_t process ( nframes_t nframes );
  199. void seek ( nframes_t frame );
  200. void record ( Capture *c, nframes_t frame );
  201. void write ( Capture *c, sample_t *buf, nframes_t nframes );
  202. void finalize ( Capture *c, nframes_t frame );
  203. };