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.

257 lines
7.2KB

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