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.

271 lines
6.9KB

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