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.

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