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.

399 lines
9.3KB

  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.H"
  19. #include "Transport.H"
  20. #include "Playback_DS.H"
  21. #include "Record_DS.H"
  22. #include "Engine.H"
  23. #include "Port.H"
  24. void
  25. Track::cb_input_field ( Fl_Widget *w, void *v )
  26. {
  27. ((Track*)v)->cb_input_field();
  28. }
  29. void
  30. Track::cb_button ( Fl_Widget *w, void *v )
  31. {
  32. ((Track*)v)->cb_button( w );
  33. }
  34. void
  35. Track::cb_input_field ( void )
  36. {
  37. log_start();
  38. if ( _name )
  39. free( _name );
  40. _name = strdup( name_field->value() );
  41. log_end();
  42. }
  43. void
  44. Track::cb_button ( Fl_Widget *w )
  45. {
  46. printf( "FIXME: inform mixer here\n" );
  47. if ( w == record_button )
  48. {
  49. /* FIXME: wrong place for this! */
  50. if ( record_button->value() )
  51. record_ds->start( transport.frame );
  52. else
  53. record_ds->stop( transport.frame );
  54. }
  55. else
  56. if ( w == take_menu )
  57. {
  58. int v = take_menu->value();
  59. switch ( v )
  60. {
  61. case 0: /* show all takes */
  62. show_all_takes( take_menu->menu()[ v ].value() );
  63. return;
  64. case 1: /* new */
  65. track( track()->clone_empty() );
  66. return;
  67. }
  68. const char *s = take_menu->menu()[ v ].text;
  69. for ( int i = takes->children(); i--; )
  70. {
  71. Sequence *t = (Sequence*)takes->child( i );
  72. if ( ! strcmp( s, t->name() ) )
  73. {
  74. track( t );
  75. redraw();
  76. break;
  77. }
  78. }
  79. }
  80. }
  81. Track::Track ( int X, int Y, int W, int H, const char *L ) :
  82. Fl_Group ( X, Y, W, H, L )
  83. {
  84. _track = NULL;
  85. _name = NULL;
  86. _selected = false;
  87. _show_all_takes = false;
  88. _size = 1;
  89. labeltype( FL_NO_LABEL );
  90. Fl_Group::size( w(), height() );
  91. Track *o = this;
  92. o->box( FL_THIN_UP_BOX );
  93. {
  94. Fl_Group *o = new Fl_Group( 2, 2, 149, 70 );
  95. o->color( ( Fl_Color ) 53 );
  96. {
  97. Fl_Input *o = name_field = new Fl_Input( 2, 2, 144, 24 );
  98. o->color( ( Fl_Color ) 33 );
  99. o->labeltype( FL_NO_LABEL );
  100. o->labelcolor( FL_GRAY0 );
  101. o->textcolor( 32 );
  102. o->callback( cb_input_field, (void*)this );
  103. o->hide();
  104. }
  105. {
  106. Fl_Group *o = controls = new Fl_Group( 2, 28, 149, 24 );
  107. {
  108. Fl_Button *o = record_button =
  109. new Fl_Button( 6, 28, 26, 24, "@circle" );
  110. o->type( 1 );
  111. o->box( FL_THIN_UP_BOX );
  112. o->color( FL_LIGHT1 );
  113. o->selection_color( FL_RED );
  114. o->labelsize( 8 );
  115. o->callback( cb_button, this );
  116. }
  117. {
  118. Fl_Button *o = mute_button =
  119. new Fl_Button( 35, 28, 26, 24, "m" );
  120. o->type( 1 );
  121. o->box( FL_THIN_UP_BOX );
  122. o->color( FL_LIGHT1 );
  123. o->labelsize( 11 );
  124. o->callback( cb_button, this );
  125. }
  126. {
  127. Fl_Button *o = solo_button =
  128. new Fl_Button( 66, 28, 26, 24, "s" );
  129. o->type( 1 );
  130. o->box( FL_THIN_UP_BOX );
  131. o->color( FL_LIGHT1 );
  132. o->labelsize( 11 );
  133. o->callback( cb_button, this );
  134. }
  135. {
  136. Fl_Menu_Button *o = take_menu =
  137. new Fl_Menu_Button( 97, 28, 47, 24, "T" );
  138. o->box( FL_THIN_UP_BOX );
  139. o->color( FL_LIGHT1 );
  140. o->align( FL_ALIGN_LEFT | FL_ALIGN_INSIDE );
  141. o->callback( cb_button, this );
  142. o->add( "Show all takes", 0, 0, 0, FL_MENU_TOGGLE );
  143. o->add( "New", 0, 0, 0, FL_MENU_DIVIDER );
  144. }
  145. o->end();
  146. }
  147. {
  148. Fl_Box *o = new Fl_Box( 0, 76, 149, 38 );
  149. o->box( FL_FLAT_BOX );
  150. Fl_Group::current()->resizable( o );
  151. }
  152. o->size( Track::width(), h() );
  153. o->end();
  154. }
  155. {
  156. Fl_Pack *o = pack = new Fl_Pack( width(), 0, 1006, 115 );
  157. o->labeltype( FL_NO_LABEL );
  158. o->resize( x() + width(), y(), w() - width(), h() );
  159. Fl_Group::current()->resizable( o );
  160. {
  161. Fl_Pack *o = control = new Fl_Pack( width(), 0, pack->w(), 115 );
  162. o->end();
  163. }
  164. {
  165. Fl_Pack *o = takes = new Fl_Pack( width(), 0, pack->w(), 115 );
  166. o->end();
  167. o->hide();
  168. }
  169. o->end();
  170. }
  171. end();
  172. if ( L )
  173. name( L );
  174. /* FIXME: should be configurable, but where? */
  175. create_outputs( 2 );
  176. create_inputs( 2 );
  177. playback_ds = new Playback_DS( this, engine->frame_rate(), engine->nframes(), output.size() );
  178. record_ds = new Record_DS( this, engine->frame_rate(), engine->nframes(), input.size() );
  179. log_create();
  180. }
  181. Track::~Track ( )
  182. {
  183. log_destroy();
  184. }
  185. static int pack_visible( Fl_Pack *p )
  186. {
  187. int v = 0;
  188. for ( int i = p->children(); i--; )
  189. if ( p->child( i )->visible() )
  190. v++;
  191. return v;
  192. }
  193. /* adjust size of widget and children */
  194. void
  195. Track::resize ( void )
  196. {
  197. for ( int i = takes->children(); i--; )
  198. takes->child( i )->size( w(), height() );
  199. for ( int i = control->children(); i--; )
  200. control->child( i )->size( w(), height() );
  201. if ( _show_all_takes )
  202. {
  203. takes->show();
  204. Fl_Group::size( w(), height() * ( 1 + takes->children() + pack_visible( control ) ) );
  205. }
  206. else
  207. {
  208. takes->hide();
  209. Fl_Group::size( w(), height() * ( 1 + pack_visible( control ) ) );
  210. }
  211. if ( track() )
  212. track()->size( w(), height() );
  213. if ( controls->y() + controls->h() > y() + h() )
  214. controls->hide();
  215. else
  216. controls->show();
  217. parent()->redraw();
  218. }
  219. void
  220. Track::size ( int v )
  221. {
  222. if ( v < 0 || v > 3 )
  223. return;
  224. _size = v;
  225. resize();
  226. }
  227. void
  228. Track::track( Sequence * t )
  229. {
  230. // t->size( 1, h() );
  231. if ( track() )
  232. add( track() );
  233. // takes->insert( *track(), 0 );
  234. _track = t;
  235. pack->insert( *t, 0 );
  236. resize();
  237. }
  238. void
  239. Track::add_control( Sequence *t )
  240. {
  241. control->add( t );
  242. resize();
  243. }
  244. /**********/
  245. /* Engine */
  246. /**********/
  247. bool
  248. Track::create_outputs ( int n )
  249. {
  250. char pname[256];
  251. for ( int i = 0; i < n; ++i )
  252. {
  253. snprintf( pname, sizeof( pname ), "%s/out-%d", name(), i + 1 );
  254. output.push_back( Port( strdup( pname ), Port::Output ) );
  255. }
  256. /* FIXME: bogus */
  257. return true;
  258. }
  259. bool
  260. Track::create_inputs ( int n )
  261. {
  262. char pname[256];
  263. for ( int i = 0; i < n; ++i )
  264. {
  265. snprintf( pname, sizeof( pname ), "%s/in-%d", name(), i + 1 );
  266. input.push_back( Port( strdup( pname ), Port::Input ) );
  267. }
  268. /* FIXME: bogus */
  269. return true;
  270. }
  271. /* THREAD: RT */
  272. nframes_t
  273. Track::process ( nframes_t nframes )
  274. {
  275. if ( playback_ds )
  276. {
  277. record_ds->process( nframes );
  278. return playback_ds->process( nframes );
  279. }
  280. else
  281. return 0;
  282. }
  283. /* THREAD: RT */
  284. void
  285. Track::seek ( nframes_t frame )
  286. {
  287. if ( playback_ds )
  288. return playback_ds->seek( frame );
  289. }
  290. /* FIXME: what about theading issues with this region/audiofile being
  291. accessible from the UI thread? Need locking? */
  292. #include "Region.H"
  293. /* THREAD: IO */
  294. /** create capture region and prepare to record */
  295. void
  296. Track::record ( nframes_t frame )
  297. {
  298. assert( _capture == NULL );
  299. /* FIXME: hack */
  300. Audio_File *af = Audio_File_SF::create( "testing.wav", 48000, input.size(), "Wav/24" );
  301. _capture = new Region( af, track(), frame );
  302. /* FIXME: wrong place for this */
  303. _capture->_r->end = 0;
  304. }
  305. /* THREAD: IO */
  306. /** write a block to the (already opened) capture file */
  307. void
  308. Track::write ( sample_t *buf, nframes_t nframes )
  309. {
  310. _capture->write( buf, nframes );
  311. }
  312. /* THREAD: IO */
  313. void
  314. Track::stop ( nframes_t nframes )
  315. {
  316. _capture = NULL;
  317. }