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.

272 lines
7.1KB

  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
  77. if ( ! strcmp( s, ":selected" ) )
  78. _selected = atoi( v );
  79. else
  80. if ( ! strcmp( s, ":name" ) )
  81. {
  82. _name = strdup( v );
  83. name_field->value( _name );
  84. }
  85. else
  86. if ( ! strcmp( s, ":track" ) )
  87. {
  88. int i;
  89. sscanf( v, "%X", &i );
  90. Track *t = (Track*)Loggable::find( i );
  91. assert( t );
  92. track( t );
  93. }
  94. free( s );
  95. }
  96. free( sa );
  97. }
  98. char ** get ( void )
  99. {
  100. char **sa = (char**)malloc( sizeof( char* ) * (1 + 4) );
  101. int i = 0;
  102. asprintf( &sa[ i++ ], ":name \"%s\"", _name ? _name : "" );
  103. asprintf( &sa[ i++ ], ":track 0x%X", track() ? track()->id() : 0 );
  104. asprintf( &sa[ i++ ], ":selected %d", _selected );
  105. /* asprintf( &sa[ i++ ], ":record %d", record_button->value() ); */
  106. /* asprintf( &sa[ i++ ], ":solo %d", solo_button->value() ); */
  107. /* asprintf( &sa[ i++ ], ":mute %d", mute_button->value() ); */
  108. asprintf( &sa[ i++ ], ":h %d", size() );
  109. // asprintf( &sa[ i++ ], ":gain %f", _scale );
  110. sa[ i ] = NULL;
  111. return sa;
  112. }
  113. /* for loggable */
  114. static Loggable *
  115. create ( char **sa )
  116. {
  117. Track_Header *r = new Track_Header( 0, 0, 1, 1 );
  118. r->set( sa );
  119. return (Loggable *)r;
  120. }
  121. void
  122. draw ( void )
  123. {
  124. if ( _selected )
  125. {
  126. Fl_Color c = color();
  127. color( FL_RED );
  128. Fl_Group::draw();
  129. color( c );
  130. }
  131. else
  132. Fl_Group::draw();
  133. }
  134. void add_control( Track *t );
  135. int size ( void ) const { return _size; }
  136. void resize ( void );
  137. void size ( int v );
  138. int height ( void ) const
  139. {
  140. static int table[] = { 30, 80, 150, 300 };
  141. return table[ _size ];
  142. }
  143. void show_all_takes ( bool b )
  144. {
  145. _show_all_takes = b;
  146. resize();
  147. }
  148. const char * name ( void ) const { return _name; }
  149. bool mute ( void ) const { return mute_button->value(); }
  150. bool solo ( void ) const { return solo_button->value(); }
  151. bool arm ( void ) const { return record_button->value(); }
  152. bool selected ( void ) const { return _selected; }
  153. static void cb_input_field ( Fl_Widget *w, void *v );
  154. void cb_input_field ( void );
  155. static void cb_button ( Fl_Widget *w, void *v );
  156. void cb_button ( Fl_Widget *w );
  157. static int width ( void ) { return 150; }
  158. void track( Track * t );
  159. Track * track ( void ) { return _track; }
  160. void add ( Track * t )
  161. {
  162. takes->insert( *t, 0 );
  163. if ( ! t->name() )
  164. {
  165. char pat[20];
  166. snprintf( pat, sizeof( pat ), "%d", takes->children() );
  167. t->name( strdup( pat ) );
  168. take_menu->add( t->name() );
  169. }
  170. }
  171. void remote ( Track *t )
  172. {
  173. takes->remove( t );
  174. // take_menu->remove( t->name() );
  175. }
  176. int handle ( int m )
  177. {
  178. switch ( m )
  179. {
  180. case FL_MOUSEWHEEL:
  181. {
  182. if ( ! Fl::event_shift() )
  183. return 0;
  184. int d = Fl::event_dy();
  185. printf( "%d\n", d );
  186. if ( d < 0 )
  187. size( size() - 1 );
  188. else
  189. size( size() + 1 );
  190. return 1;
  191. }
  192. default:
  193. return Fl_Group::handle( m );
  194. }
  195. }
  196. /* Engine */
  197. nframes_t process ( nframes_t nframes );
  198. void seek ( nframes_t frame );
  199. };
  200. #endif