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.

303 lines
7.8KB

  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. #ifndef Track_H
  19. #define Track_H
  20. #include <FL/Fl.H>
  21. #include "Sequence.H"
  22. #include <FL/Fl_Group.H>
  23. #include <FL/Fl_Input.H>
  24. #include <FL/Fl_Button.H>
  25. #include <FL/Fl_Menu_Button.H>
  26. #include <FL/Fl_Pack.H>
  27. #include <FL/Fl_Box.H>
  28. #include <FL/fl_draw.H>
  29. #include "Loggable.H"
  30. // #include "Port.H"
  31. /* TODO: rename this to Audio_Sequence_Header or something since it's clearly audio specific. */
  32. #include <vector>
  33. using std::vector;
  34. class Playback_DS;
  35. class Record_DS;
  36. class Port;
  37. class Track : public Fl_Group, public Loggable
  38. {
  39. public:
  40. Track ( int X, int Y, int W, int H, const char *L = 0 );
  41. ~Track ( );
  42. private:
  43. // Sequence * _track;
  44. char *_name;
  45. bool _selected;
  46. bool _show_all_takes;
  47. int _size;
  48. enum { AUDIO } _type;
  49. Sequence *_track;
  50. Region *_capture; /* capture region */
  51. bool create_outputs ( int n );
  52. bool create_inputs ( int n );
  53. public:
  54. Fl_Input * name_field;
  55. Fl_Button *record_button;
  56. Fl_Button *mute_button;
  57. Fl_Button *solo_button;
  58. Fl_Menu_Button *take_menu;
  59. Fl_Group *controls;
  60. Fl_Pack *pack;
  61. Fl_Pack *control;
  62. Fl_Pack *takes;
  63. vector <Port> input;
  64. vector <Port> output; /* output ports... */
  65. Playback_DS *playback_ds;
  66. Record_DS *record_ds;
  67. const char *class_name ( void ) { return "Track"; }
  68. void set ( char **sa )
  69. {
  70. for ( int i = 0; sa[i]; ++i )
  71. {
  72. char *s = sa[i];
  73. strtok( s, " " );
  74. char *v = s + strlen( s ) + 1;
  75. if ( *v == '"' )
  76. {
  77. v++;
  78. v[ strlen( v ) - 2 ] = '\0';
  79. }
  80. if ( ! strcmp( s, ":h" ) )
  81. {
  82. size( atoi( v ) );
  83. Fl_Widget::size( w(), height() );
  84. }
  85. else if ( ! strcmp( s, ":selected" ) )
  86. _selected = atoi( v );
  87. // else if ( ! strcmp( s, ":armed"
  88. else if ( ! strcmp( s, ":name" ) )
  89. {
  90. _name = strdup( v );
  91. name_field->value( _name );
  92. }
  93. else if ( ! strcmp( s, ":track" ) )
  94. {
  95. int i;
  96. sscanf( v, "%X", &i );
  97. Sequence *t = (Sequence*)Loggable::find( i );
  98. assert( t );
  99. track( t );
  100. }
  101. free( s );
  102. }
  103. free( sa );
  104. }
  105. char ** get ( void )
  106. {
  107. char **sa = (char**)malloc( sizeof( char* ) * (1 + 5) );
  108. int i = 0;
  109. asprintf( &sa[ i++ ], ":name \"%s\"", _name ? _name : "" );
  110. asprintf( &sa[ i++ ], ":track 0x%X", track() ? track()->id() : 0 );
  111. asprintf( &sa[ i++ ], ":selected %d", _selected );
  112. // asprintf( &sa[ i++ ], ":record %d", record_button->value() );
  113. /* asprintf( &sa[ i++ ], ":solo %d", solo_button->value() ); */
  114. /* asprintf( &sa[ i++ ], ":mute %d", mute_button->value() ); */
  115. asprintf( &sa[ i++ ], ":h %d", size() );
  116. // asprintf( &sa[ i++ ], ":gain %f", _scale );
  117. sa[ i ] = NULL;
  118. return sa;
  119. }
  120. /* for loggable */
  121. static Loggable *
  122. create ( char **sa )
  123. {
  124. Track *r = new Track( 0, 0, 1, 1 );
  125. r->set( sa );
  126. return (Loggable *)r;
  127. }
  128. void
  129. draw ( void )
  130. {
  131. if ( _selected )
  132. {
  133. Fl_Color c = color();
  134. color( FL_RED );
  135. Fl_Group::draw();
  136. color( c );
  137. }
  138. else
  139. Fl_Group::draw();
  140. if ( ! name_field->visible() )
  141. {
  142. fl_color( FL_WHITE );
  143. fl_font( FL_HELVETICA, 14 );
  144. fl_draw( name_field->value(), name_field->x(), name_field->y(), name_field->w(), name_field->h(), FL_ALIGN_CENTER );
  145. }
  146. }
  147. void add_control( Sequence *t );
  148. int size ( void ) const { return _size; }
  149. void resize ( void );
  150. void size ( int v );
  151. int height ( void ) const
  152. {
  153. static int table[] = { 30, 80, 150, 300 };
  154. return table[ _size ];
  155. }
  156. void show_all_takes ( bool b )
  157. {
  158. _show_all_takes = b;
  159. resize();
  160. }
  161. void name ( const char *name )
  162. {
  163. if ( _name ) free( _name );
  164. _name = strdup( name );
  165. name_field->value( _name );
  166. }
  167. const char * name ( void ) const { return _name; }
  168. bool mute ( void ) const { return mute_button->value(); }
  169. bool solo ( void ) const { return solo_button->value(); }
  170. bool armed ( void ) const { return record_button->value(); }
  171. bool selected ( void ) const { return _selected; }
  172. static void cb_input_field ( Fl_Widget *w, void *v );
  173. void cb_input_field ( void );
  174. static void cb_button ( Fl_Widget *w, void *v );
  175. void cb_button ( Fl_Widget *w );
  176. static int width ( void ) { return 150; }
  177. void track( Sequence * t );
  178. Sequence * track ( void ) { return _track; }
  179. void add ( Sequence * t )
  180. {
  181. takes->insert( *t, 0 );
  182. if ( ! t->name() )
  183. {
  184. char pat[20];
  185. snprintf( pat, sizeof( pat ), "%d", takes->children() );
  186. t->name( strdup( pat ) );
  187. take_menu->add( t->name() );
  188. }
  189. }
  190. void remote ( Sequence *t )
  191. {
  192. takes->remove( t );
  193. // take_menu->remove( t->name() );
  194. }
  195. int handle ( int m )
  196. {
  197. switch ( m )
  198. {
  199. case FL_MOUSEWHEEL:
  200. {
  201. if ( ! Fl::event_shift() )
  202. return 0;
  203. int d = Fl::event_dy();
  204. printf( "%d\n", d );
  205. if ( d < 0 )
  206. size( size() - 1 );
  207. else
  208. size( size() + 1 );
  209. return 1;
  210. }
  211. default:
  212. return Fl_Group::handle( m );
  213. }
  214. }
  215. /* Engine */
  216. nframes_t process ( nframes_t nframes );
  217. void seek ( nframes_t frame );
  218. void record ( nframes_t nframes );
  219. void write ( sample_t *buf, nframes_t nframes );
  220. void stop ( nframes_t nframes );
  221. };
  222. #endif