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.

279 lines
7.0KB

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