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.

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