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.

277 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. #pragma once
  19. #include <FL/Fl.H>
  20. #include "Sequence.H"
  21. #include <FL/Fl_Group.H>
  22. #include <FL/Fl_Input.H>
  23. #include <FL/Fl_Button.H>
  24. #include <FL/Fl_Menu_Button.H>
  25. #include <FL/Fl_Pack.H>
  26. #include <FL/Fl_Box.H>
  27. #include <FL/fl_draw.H>
  28. #include "Loggable.H"
  29. /* TODO: rename this to Audio_Track or something since it's clearly audio specific. */
  30. #include <vector>
  31. using std::vector;
  32. #include "Port.H"
  33. class Playback_DS;
  34. class Record_DS;
  35. class Port;
  36. class Region;
  37. class Track : public Fl_Group, public Loggable
  38. {
  39. public:
  40. Track ( int X, int Y, int W, int H, const char *L = 0 );
  41. ~Track ( );
  42. private:
  43. // Sequence * _track;
  44. char *_name;
  45. bool _selected;
  46. bool _show_all_takes;
  47. int _size;
  48. enum { AUDIO } _type;
  49. Sequence *_track;
  50. Region *_capture; /* capture region */
  51. bool create_outputs ( int n );
  52. bool create_inputs ( int n );
  53. Track ( ) : Fl_Group( 0, 0, 1, 1 )
  54. {
  55. }
  56. public:
  57. Fl_Input * name_field;
  58. Fl_Button *record_button;
  59. Fl_Button *mute_button;
  60. Fl_Button *solo_button;
  61. Fl_Menu_Button *take_menu;
  62. Fl_Group *controls;
  63. Fl_Pack *pack;
  64. Fl_Pack *control;
  65. Fl_Pack *takes;
  66. vector <Port> input;
  67. vector <Port> output; /* output ports... */
  68. Playback_DS *playback_ds;
  69. Record_DS *record_ds;
  70. const char *class_name ( void ) { return "Track"; }
  71. void
  72. set ( Log_Entry &e )
  73. {
  74. for ( int i = 0; e.size(); ++i )
  75. {
  76. const char *s, *v;
  77. e.get( i, &s, &v );
  78. if ( ! strcmp( s, ":h" ) )
  79. {
  80. size( atoi( v ) );
  81. Fl_Widget::size( w(), height() );
  82. }
  83. else if ( ! strcmp( s, ":s" ) )
  84. _selected = atoi( v );
  85. // else if ( ! strcmp( s, ":armed"
  86. else if ( ! strcmp( s, ":n" ) )
  87. {
  88. _name = strdup( v );
  89. name_field->value( _name );
  90. }
  91. else if ( ! strcmp( s, ":t" ) )
  92. {
  93. int i;
  94. sscanf( v, "%X", &i );
  95. if ( i )
  96. {
  97. Sequence *t = (Sequence*)Loggable::find( i );
  98. assert( t );
  99. track( t );
  100. }
  101. }
  102. }
  103. }
  104. void
  105. get ( Log_Entry &e )
  106. {
  107. e.add( ":n", _name );
  108. e.add( ":t", track() );
  109. e.add( ":s", _selected );
  110. e.add( ":h", size() );
  111. }
  112. /* for loggable */
  113. LOG_CREATE_FUNC( Track );
  114. void
  115. draw ( void )
  116. {
  117. if ( _selected )
  118. {
  119. Fl_Color c = color();
  120. color( FL_RED );
  121. Fl_Group::draw();
  122. color( c );
  123. }
  124. else
  125. Fl_Group::draw();
  126. if ( ! name_field->visible() )
  127. {
  128. fl_color( FL_WHITE );
  129. fl_font( FL_HELVETICA, 14 );
  130. fl_draw( name_field->value(), name_field->x(), name_field->y(), name_field->w(), name_field->h(), FL_ALIGN_CENTER );
  131. }
  132. }
  133. void add_control( Sequence *t );
  134. int size ( void ) const { return _size; }
  135. void resize ( void );
  136. void size ( int v );
  137. int height ( void ) const
  138. {
  139. static int table[] = { 30, 80, 150, 300 };
  140. return table[ _size ];
  141. }
  142. void show_all_takes ( bool b )
  143. {
  144. _show_all_takes = b;
  145. resize();
  146. }
  147. void name ( const char *name )
  148. {
  149. if ( _name ) free( _name );
  150. _name = strdup( name );
  151. name_field->value( _name );
  152. }
  153. const char * name ( void ) const { return _name; }
  154. bool mute ( void ) const { return mute_button->value(); }
  155. bool solo ( void ) const { return solo_button->value(); }
  156. bool armed ( void ) const { return record_button->value(); }
  157. bool selected ( void ) const { return _selected; }
  158. static void cb_input_field ( Fl_Widget *w, void *v );
  159. void cb_input_field ( void );
  160. static void cb_button ( Fl_Widget *w, void *v );
  161. void cb_button ( Fl_Widget *w );
  162. static int width ( void ) { return 150; }
  163. void track( Sequence * t );
  164. Sequence * track ( void ) { return _track; }
  165. void add ( Sequence * t )
  166. {
  167. takes->insert( *t, 0 );
  168. if ( ! t->name() )
  169. {
  170. char pat[20];
  171. snprintf( pat, sizeof( pat ), "%d", takes->children() );
  172. t->name( strdup( pat ) );
  173. take_menu->add( t->name() );
  174. }
  175. }
  176. void remote ( Sequence *t )
  177. {
  178. takes->remove( t );
  179. // take_menu->remove( t->name() );
  180. }
  181. int handle ( int m )
  182. {
  183. switch ( m )
  184. {
  185. case FL_MOUSEWHEEL:
  186. {
  187. if ( ! Fl::event_shift() )
  188. return 0;
  189. int d = Fl::event_dy();
  190. printf( "%d\n", d );
  191. if ( d < 0 )
  192. size( size() - 1 );
  193. else
  194. size( size() + 1 );
  195. return 1;
  196. }
  197. default:
  198. return Fl_Group::handle( m );
  199. }
  200. }
  201. /* Engine */
  202. nframes_t process ( nframes_t nframes );
  203. void seek ( nframes_t frame );
  204. void record ( nframes_t nframes );
  205. void write ( sample_t *buf, nframes_t nframes );
  206. void stop ( nframes_t nframes );
  207. };