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.

286 lines
7.3KB

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