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.

275 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 "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. private:
  54. static int _soloing;
  55. char *_name;
  56. bool _selected;
  57. bool _show_all_takes;
  58. int _size;
  59. enum { AUDIO } _type;
  60. Audio_Sequence *_sequence;
  61. Audio_Region *_capture; /* capture region */
  62. Audio_File *_capture_af; /* capture write source */
  63. bool configure_outputs ( int n );
  64. bool configure_inputs ( int n );
  65. void update_port_names ( void );
  66. const char *name_for_port( Port::type_e type, int n );
  67. Track ( ) : Fl_Group( 0, 0, 1, 1 )
  68. {
  69. init();
  70. timeline->add_track( this );
  71. }
  72. void init ( void );
  73. public:
  74. Fl_Input *name_field;
  75. Fl_Button *record_button;
  76. Fl_Button *mute_button;
  77. Fl_Button *solo_button;
  78. Fl_Menu_Button *take_menu;
  79. Fl_Group *controls;
  80. Fl_Pack *pack;
  81. Fl_Pack *annotation;
  82. Fl_Pack *control;
  83. Fl_Pack *takes;
  84. vector<Port> input; /* input ports... */
  85. vector<Port> output; /* output ports... */
  86. vector<Port*> control_out; /* control ports... */
  87. Playback_DS *playback_ds;
  88. Record_DS *record_ds;
  89. // const char *class_name ( void ) { return "Track"; }
  90. void
  91. set ( Log_Entry &e )
  92. {
  93. for ( int i = 0; i < e.size(); ++i )
  94. {
  95. const char *s, *v;
  96. e.get( i, &s, &v );
  97. if ( ! strcmp( s, ":height" ) )
  98. {
  99. size( atoi( v ) );
  100. // Fl_Widget::size( w(), height() );
  101. resize();
  102. }
  103. else if ( ! strcmp( s, ":selected" ) )
  104. _selected = atoi( v );
  105. // else if ( ! strcmp( s, ":armed"
  106. else if ( ! strcmp( s, ":name" ) )
  107. name( v );
  108. else if ( ! strcmp( s, ":inputs" ) )
  109. configure_inputs( atoi( v ) );
  110. else if ( ! strcmp( s, ":outputs" ) )
  111. configure_outputs( atoi( v ) );
  112. else if ( ! strcmp( s, ":color" ) )
  113. {
  114. color( (Fl_Color)atoll( v ) );
  115. redraw();
  116. }
  117. else if ( ! strcmp( s, ":sequence" ) )
  118. {
  119. int i;
  120. sscanf( v, "%X", &i );
  121. if ( i )
  122. {
  123. Audio_Sequence *t = (Audio_Sequence*)Loggable::find( i );
  124. /* FIXME: our track might not have been
  125. * defined yet... what should we do about this
  126. * chicken/egg problem? */
  127. if ( t )
  128. {
  129. // assert( t );
  130. sequence( t );
  131. }
  132. }
  133. }
  134. }
  135. }
  136. virtual void get ( Log_Entry &e ) const
  137. {
  138. e.add( ":name", _name );
  139. e.add( ":sequence", sequence() );
  140. e.add( ":selected", _selected );
  141. e.add( ":height", size() );
  142. e.add( ":inputs", input.size() );
  143. e.add( ":outputs", output.size() );
  144. e.add( ":color", (unsigned long)color());
  145. }
  146. /* for loggable */
  147. LOG_CREATE_FUNC( Track );
  148. void add ( Annotation_Sequence *t );
  149. void remove ( Annotation_Sequence *t );
  150. void add ( Control_Sequence *t );
  151. void add ( Audio_Sequence *t );
  152. void remove ( Audio_Sequence *t );
  153. void remove ( Control_Sequence *t );
  154. void select ( int X, int Y, int W, int H, bool include_control, bool merge_control );
  155. int size ( void ) const { return _size; }
  156. void resize ( void );
  157. void size ( int v );
  158. int height ( void ) const
  159. {
  160. static int table[] = { 30, 80, 150, 300 };
  161. return table[ _size ];
  162. }
  163. void show_all_takes ( bool b )
  164. {
  165. _show_all_takes = b;
  166. resize();
  167. }
  168. void name ( const char *name )
  169. {
  170. if ( _name )
  171. free( _name );
  172. _name = strdup( name );
  173. if ( name_field )
  174. name_field->value( _name );
  175. update_port_names();
  176. }
  177. const char * name ( void ) const { return _name; }
  178. bool mute ( void ) const { return mute_button->value(); }
  179. bool solo ( void ) const { return solo_button->value(); }
  180. bool armed ( void ) const { return record_button->value(); }
  181. bool selected ( void ) const { return _selected; }
  182. static void cb_input_field ( Fl_Widget *w, void *v );
  183. void cb_input_field ( void );
  184. static void cb_button ( Fl_Widget *w, void *v );
  185. void cb_button ( Fl_Widget *w );
  186. static int width ( void ) { return 150; }
  187. void sequence ( Audio_Sequence * t );
  188. Audio_Sequence * sequence ( void ) const { return _sequence; }
  189. void draw ( void );
  190. int handle ( int m );
  191. const Audio_Region *capture ( void ) const { return _capture; }
  192. /* Engine */
  193. nframes_t process ( nframes_t nframes );
  194. void seek ( nframes_t frame );
  195. void record ( nframes_t nframes );
  196. void write ( sample_t *buf, nframes_t nframes );
  197. void stop ( nframes_t nframes );
  198. };