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.

240 lines
6.4KB

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