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.

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