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.

328 lines
8.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. #include "Track_Header.H"
  19. #include "Playback_DS.H"
  20. #include "Record_DS.H"
  21. #include "Engine.H"
  22. #include "Port.H"
  23. void
  24. Track_Header::cb_input_field ( Fl_Widget *w, void *v )
  25. {
  26. ((Track_Header*)v)->cb_input_field();
  27. }
  28. void
  29. Track_Header::cb_button ( Fl_Widget *w, void *v )
  30. {
  31. ((Track_Header*)v)->cb_button( w );
  32. }
  33. void
  34. Track_Header::cb_input_field ( void )
  35. {
  36. log_start();
  37. if ( _name )
  38. free( _name );
  39. _name = strdup( name_field->value() );
  40. log_end();
  41. }
  42. void
  43. Track_Header::cb_button ( Fl_Widget *w )
  44. {
  45. printf( "FIXME: inform mixer here\n" );
  46. if ( w == record_button )
  47. {
  48. }
  49. else
  50. if ( w == take_menu )
  51. {
  52. int v = take_menu->value();
  53. switch ( v )
  54. {
  55. case 0: /* show all takes */
  56. show_all_takes( take_menu->menu()[ v ].value() );
  57. return;
  58. case 1: /* new */
  59. track( track()->clone_empty() );
  60. return;
  61. }
  62. const char *s = take_menu->menu()[ v ].text;
  63. for ( int i = takes->children(); i--; )
  64. {
  65. Track *t = (Track*)takes->child( i );
  66. if ( ! strcmp( s, t->name() ) )
  67. {
  68. track( t );
  69. redraw();
  70. break;
  71. }
  72. }
  73. }
  74. }
  75. Track_Header::Track_Header ( int X, int Y, int W, int H, const char *L ) :
  76. Fl_Group ( X, Y, W, H, L )
  77. {
  78. _track = NULL;
  79. _name = NULL;
  80. _selected = false;
  81. _show_all_takes = false;
  82. _size = 1;
  83. {
  84. char pname[40];
  85. static int no = 0, ni = 0;
  86. snprintf( pname, sizeof( pname ), "out-%d", no++ );
  87. output.push_back( Port( strdup( pname ), Port::Output ) );
  88. snprintf( pname, sizeof( pname ), "in-%d", ni++ );
  89. input.push_back( Port( strdup( pname ), Port::Input ) );
  90. }
  91. playback_ds = new Playback_DS( this, engine->frame_rate(), engine->nframes(), 1 );
  92. record_ds = new Record_DS( this, engine->frame_rate(), engine->nframes(), 1 );
  93. Fl_Group::size( w(), height() );
  94. Track_Header *o = this;
  95. o->box( FL_THIN_UP_BOX );
  96. {
  97. Fl_Group *o = new Fl_Group( 2, 2, 149, 70 );
  98. o->color( ( Fl_Color ) 53 );
  99. {
  100. Fl_Input *o = name_field = new Fl_Input( 2, 2, 144, 24 );
  101. o->color( ( Fl_Color ) 33 );
  102. o->labeltype( FL_NO_LABEL );
  103. o->labelcolor( FL_GRAY0 );
  104. o->textcolor( 32 );
  105. o->callback( cb_input_field, (void*)this );
  106. }
  107. {
  108. Fl_Group *o = controls = new Fl_Group( 2, 28, 149, 24 );
  109. {
  110. Fl_Button *o = record_button =
  111. new Fl_Button( 6, 28, 26, 24, "@circle" );
  112. o->type( 1 );
  113. o->box( FL_THIN_UP_BOX );
  114. o->color( FL_LIGHT1 );
  115. o->selection_color( FL_RED );
  116. o->labelsize( 8 );
  117. o->callback( cb_button, this );
  118. }
  119. {
  120. Fl_Button *o = mute_button =
  121. new Fl_Button( 35, 28, 26, 24, "m" );
  122. o->type( 1 );
  123. o->box( FL_THIN_UP_BOX );
  124. o->color( FL_LIGHT1 );
  125. o->labelsize( 11 );
  126. o->callback( cb_button, this );
  127. }
  128. {
  129. Fl_Button *o = solo_button =
  130. new Fl_Button( 66, 28, 26, 24, "s" );
  131. o->type( 1 );
  132. o->box( FL_THIN_UP_BOX );
  133. o->color( FL_LIGHT1 );
  134. o->labelsize( 11 );
  135. o->callback( cb_button, this );
  136. }
  137. {
  138. Fl_Menu_Button *o = take_menu =
  139. new Fl_Menu_Button( 97, 28, 47, 24, "T" );
  140. o->box( FL_THIN_UP_BOX );
  141. o->color( FL_LIGHT1 );
  142. o->align( FL_ALIGN_LEFT | FL_ALIGN_INSIDE );
  143. o->callback( cb_button, this );
  144. o->add( "Show all takes", 0, 0, 0, FL_MENU_TOGGLE );
  145. o->add( "New", 0, 0, 0, FL_MENU_DIVIDER );
  146. }
  147. o->end();
  148. }
  149. {
  150. Fl_Box *o = new Fl_Box( 0, 76, 149, 38 );
  151. o->box( FL_FLAT_BOX );
  152. Fl_Group::current()->resizable( o );
  153. }
  154. o->size( Track_Header::width(), h() );
  155. o->end();
  156. }
  157. {
  158. Fl_Pack *o = pack = new Fl_Pack( width(), 0, 1006, 115 );
  159. o->labeltype( FL_NO_LABEL );
  160. o->resize( x() + width(), y(), w() - width(), h() );
  161. Fl_Group::current()->resizable( o );
  162. {
  163. Fl_Pack *o = control = new Fl_Pack( width(), 0, pack->w(), 115 );
  164. o->end();
  165. }
  166. {
  167. Fl_Pack *o = takes = new Fl_Pack( width(), 0, pack->w(), 115 );
  168. o->end();
  169. o->hide();
  170. }
  171. o->end();
  172. }
  173. end();
  174. log_create();
  175. }
  176. Track_Header::~Track_Header ( )
  177. {
  178. log_destroy();
  179. }
  180. static int pack_visible( Fl_Pack *p )
  181. {
  182. int v = 0;
  183. for ( int i = p->children(); i--; )
  184. if ( p->child( i )->visible() )
  185. v++;
  186. return v;
  187. }
  188. /* adjust size of widget and children */
  189. void
  190. Track_Header::resize ( void )
  191. {
  192. for ( int i = takes->children(); i--; )
  193. takes->child( i )->size( w(), height() );
  194. for ( int i = control->children(); i--; )
  195. control->child( i )->size( w(), height() );
  196. if ( _show_all_takes )
  197. {
  198. takes->show();
  199. Fl_Group::size( w(), height() * ( 1 + takes->children() + pack_visible( control ) ) );
  200. }
  201. else
  202. {
  203. takes->hide();
  204. Fl_Group::size( w(), height() * ( 1 + pack_visible( control ) ) );
  205. }
  206. if ( track() )
  207. track()->size( w(), height() );
  208. if ( controls->y() + controls->h() > y() + h() )
  209. controls->hide();
  210. else
  211. controls->show();
  212. parent()->redraw();
  213. }
  214. void
  215. Track_Header::size ( int v )
  216. {
  217. if ( v < 0 || v > 3 )
  218. return;
  219. _size = v;
  220. resize();
  221. }
  222. void
  223. Track_Header::track( Track * t )
  224. {
  225. // t->size( 1, h() );
  226. if ( track() )
  227. add( track() );
  228. // takes->insert( *track(), 0 );
  229. _track = t;
  230. pack->insert( *t, 0 );
  231. resize();
  232. }
  233. void
  234. Track_Header::add_control( Track *t )
  235. {
  236. control->add( t );
  237. resize();
  238. }
  239. /**********/
  240. /* Engine */
  241. /**********/
  242. /* THREAD: RT */
  243. nframes_t
  244. Track_Header::process ( nframes_t nframes )
  245. {
  246. if ( playback_ds )
  247. {
  248. record_ds->process( nframes );
  249. return playback_ds->process( nframes );
  250. }
  251. else
  252. return 0;
  253. }
  254. /* THREAD: RT */
  255. void
  256. Track_Header::seek ( nframes_t frame )
  257. {
  258. if ( playback_ds )
  259. return playback_ds->seek( frame );
  260. }