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.

271 lines
7.6KB

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