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.

300 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. public:
  52. Fl_Input * name_field;
  53. Fl_Button *record_button;
  54. Fl_Button *mute_button;
  55. Fl_Button *solo_button;
  56. Fl_Menu_Button *take_menu;
  57. Fl_Group *controls;
  58. Fl_Pack *pack;
  59. Fl_Pack *control;
  60. Fl_Pack *takes;
  61. vector <Port> input;
  62. vector <Port> output; /* output ports... */
  63. Playback_DS *playback_ds;
  64. Record_DS *record_ds;
  65. const char *class_name ( void ) { return "Track"; }
  66. void set ( char **sa )
  67. {
  68. for ( int i = 0; sa[i]; ++i )
  69. {
  70. char *s = sa[i];
  71. strtok( s, " " );
  72. char *v = s + strlen( s ) + 1;
  73. if ( *v == '"' )
  74. {
  75. v++;
  76. v[ strlen( v ) - 2 ] = '\0';
  77. }
  78. if ( ! strcmp( s, ":h" ) )
  79. {
  80. size( atoi( v ) );
  81. Fl_Widget::size( w(), height() );
  82. }
  83. else if ( ! strcmp( s, ":selected" ) )
  84. _selected = atoi( v );
  85. // else if ( ! strcmp( s, ":armed"
  86. else if ( ! strcmp( s, ":name" ) )
  87. {
  88. _name = strdup( v );
  89. name_field->value( _name );
  90. }
  91. else if ( ! strcmp( s, ":track" ) )
  92. {
  93. int i;
  94. sscanf( v, "%X", &i );
  95. Sequence *t = (Sequence*)Loggable::find( i );
  96. assert( t );
  97. track( t );
  98. }
  99. free( s );
  100. }
  101. free( sa );
  102. }
  103. char ** get ( void )
  104. {
  105. char **sa = (char**)malloc( sizeof( char* ) * (1 + 5) );
  106. int i = 0;
  107. asprintf( &sa[ i++ ], ":name \"%s\"", _name ? _name : "" );
  108. asprintf( &sa[ i++ ], ":track 0x%X", track() ? track()->id() : 0 );
  109. asprintf( &sa[ i++ ], ":selected %d", _selected );
  110. // asprintf( &sa[ i++ ], ":record %d", record_button->value() );
  111. /* asprintf( &sa[ i++ ], ":solo %d", solo_button->value() ); */
  112. /* asprintf( &sa[ i++ ], ":mute %d", mute_button->value() ); */
  113. asprintf( &sa[ i++ ], ":h %d", size() );
  114. // asprintf( &sa[ i++ ], ":gain %f", _scale );
  115. sa[ i ] = NULL;
  116. return sa;
  117. }
  118. /* for loggable */
  119. static Loggable *
  120. create ( char **sa )
  121. {
  122. Track *r = new Track( 0, 0, 1, 1 );
  123. r->set( sa );
  124. return (Loggable *)r;
  125. }
  126. void
  127. draw ( void )
  128. {
  129. if ( _selected )
  130. {
  131. Fl_Color c = color();
  132. color( FL_RED );
  133. Fl_Group::draw();
  134. color( c );
  135. }
  136. else
  137. Fl_Group::draw();
  138. if ( ! name_field->visible() )
  139. {
  140. fl_color( FL_WHITE );
  141. fl_font( FL_HELVETICA, 14 );
  142. fl_draw( name_field->value(), name_field->x(), name_field->y(), name_field->w(), name_field->h(), FL_ALIGN_CENTER );
  143. }
  144. }
  145. void add_control( Sequence *t );
  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 ) free( _name );
  162. _name = strdup( name );
  163. name_field->value( _name );
  164. }
  165. const char * name ( void ) const { return _name; }
  166. bool mute ( void ) const { return mute_button->value(); }
  167. bool solo ( void ) const { return solo_button->value(); }
  168. bool armed ( void ) const { return record_button->value(); }
  169. bool selected ( void ) const { return _selected; }
  170. static void cb_input_field ( Fl_Widget *w, void *v );
  171. void cb_input_field ( void );
  172. static void cb_button ( Fl_Widget *w, void *v );
  173. void cb_button ( Fl_Widget *w );
  174. static int width ( void ) { return 150; }
  175. void track( Sequence * t );
  176. Sequence * track ( void ) { return _track; }
  177. void add ( Sequence * t )
  178. {
  179. takes->insert( *t, 0 );
  180. if ( ! t->name() )
  181. {
  182. char pat[20];
  183. snprintf( pat, sizeof( pat ), "%d", takes->children() );
  184. t->name( strdup( pat ) );
  185. take_menu->add( t->name() );
  186. }
  187. }
  188. void remote ( Sequence *t )
  189. {
  190. takes->remove( t );
  191. // take_menu->remove( t->name() );
  192. }
  193. int handle ( int m )
  194. {
  195. switch ( m )
  196. {
  197. case FL_MOUSEWHEEL:
  198. {
  199. if ( ! Fl::event_shift() )
  200. return 0;
  201. int d = Fl::event_dy();
  202. printf( "%d\n", d );
  203. if ( d < 0 )
  204. size( size() - 1 );
  205. else
  206. size( size() + 1 );
  207. return 1;
  208. }
  209. default:
  210. return Fl_Group::handle( m );
  211. }
  212. }
  213. /* Engine */
  214. nframes_t process ( nframes_t nframes );
  215. void seek ( nframes_t frame );
  216. void record ( nframes_t nframes );
  217. void write ( sample_t *buf, nframes_t nframes );
  218. void stop ( nframes_t nframes );
  219. };
  220. #endif