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.

379 lines
9.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.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. {
  91. char pname[40];
  92. static int no = 0, ni = 0;
  93. snprintf( pname, sizeof( pname ), "out-%d", no++ );
  94. output.push_back( Port( strdup( pname ), Port::Output ) );
  95. snprintf( pname, sizeof( pname ), "in-%d", ni++ );
  96. input.push_back( Port( strdup( pname ), Port::Input ) );
  97. snprintf( pname, sizeof( pname ), "in-%d", ni++ );
  98. input.push_back( Port( strdup( pname ), Port::Input ) );
  99. }
  100. playback_ds = new Playback_DS( this, engine->frame_rate(), engine->nframes(), 1 );
  101. record_ds = new Record_DS( this, engine->frame_rate(), engine->nframes(), 2 );
  102. Fl_Group::size( w(), height() );
  103. Track *o = this;
  104. o->box( FL_THIN_UP_BOX );
  105. {
  106. Fl_Group *o = new Fl_Group( 2, 2, 149, 70 );
  107. o->color( ( Fl_Color ) 53 );
  108. {
  109. Fl_Input *o = name_field = new Fl_Input( 2, 2, 144, 24 );
  110. o->color( ( Fl_Color ) 33 );
  111. o->labeltype( FL_NO_LABEL );
  112. o->labelcolor( FL_GRAY0 );
  113. o->textcolor( 32 );
  114. o->callback( cb_input_field, (void*)this );
  115. o->hide();
  116. }
  117. {
  118. Fl_Group *o = controls = new Fl_Group( 2, 28, 149, 24 );
  119. {
  120. Fl_Button *o = record_button =
  121. new Fl_Button( 6, 28, 26, 24, "@circle" );
  122. o->type( 1 );
  123. o->box( FL_THIN_UP_BOX );
  124. o->color( FL_LIGHT1 );
  125. o->selection_color( FL_RED );
  126. o->labelsize( 8 );
  127. o->callback( cb_button, this );
  128. }
  129. {
  130. Fl_Button *o = mute_button =
  131. new Fl_Button( 35, 28, 26, 24, "m" );
  132. o->type( 1 );
  133. o->box( FL_THIN_UP_BOX );
  134. o->color( FL_LIGHT1 );
  135. o->labelsize( 11 );
  136. o->callback( cb_button, this );
  137. }
  138. {
  139. Fl_Button *o = solo_button =
  140. new Fl_Button( 66, 28, 26, 24, "s" );
  141. o->type( 1 );
  142. o->box( FL_THIN_UP_BOX );
  143. o->color( FL_LIGHT1 );
  144. o->labelsize( 11 );
  145. o->callback( cb_button, this );
  146. }
  147. {
  148. Fl_Menu_Button *o = take_menu =
  149. new Fl_Menu_Button( 97, 28, 47, 24, "T" );
  150. o->box( FL_THIN_UP_BOX );
  151. o->color( FL_LIGHT1 );
  152. o->align( FL_ALIGN_LEFT | FL_ALIGN_INSIDE );
  153. o->callback( cb_button, this );
  154. o->add( "Show all takes", 0, 0, 0, FL_MENU_TOGGLE );
  155. o->add( "New", 0, 0, 0, FL_MENU_DIVIDER );
  156. }
  157. o->end();
  158. }
  159. {
  160. Fl_Box *o = new Fl_Box( 0, 76, 149, 38 );
  161. o->box( FL_FLAT_BOX );
  162. Fl_Group::current()->resizable( o );
  163. }
  164. o->size( Track::width(), h() );
  165. o->end();
  166. }
  167. {
  168. Fl_Pack *o = pack = new Fl_Pack( width(), 0, 1006, 115 );
  169. o->labeltype( FL_NO_LABEL );
  170. o->resize( x() + width(), y(), w() - width(), h() );
  171. Fl_Group::current()->resizable( o );
  172. {
  173. Fl_Pack *o = control = new Fl_Pack( width(), 0, pack->w(), 115 );
  174. o->end();
  175. }
  176. {
  177. Fl_Pack *o = takes = new Fl_Pack( width(), 0, pack->w(), 115 );
  178. o->end();
  179. o->hide();
  180. }
  181. o->end();
  182. }
  183. end();
  184. if ( L )
  185. name( L );
  186. log_create();
  187. }
  188. Track::~Track ( )
  189. {
  190. log_destroy();
  191. }
  192. static int pack_visible( Fl_Pack *p )
  193. {
  194. int v = 0;
  195. for ( int i = p->children(); i--; )
  196. if ( p->child( i )->visible() )
  197. v++;
  198. return v;
  199. }
  200. /* adjust size of widget and children */
  201. void
  202. Track::resize ( void )
  203. {
  204. for ( int i = takes->children(); i--; )
  205. takes->child( i )->size( w(), height() );
  206. for ( int i = control->children(); i--; )
  207. control->child( i )->size( w(), height() );
  208. if ( _show_all_takes )
  209. {
  210. takes->show();
  211. Fl_Group::size( w(), height() * ( 1 + takes->children() + pack_visible( control ) ) );
  212. }
  213. else
  214. {
  215. takes->hide();
  216. Fl_Group::size( w(), height() * ( 1 + pack_visible( control ) ) );
  217. }
  218. if ( track() )
  219. track()->size( w(), height() );
  220. if ( controls->y() + controls->h() > y() + h() )
  221. controls->hide();
  222. else
  223. controls->show();
  224. parent()->redraw();
  225. }
  226. void
  227. Track::size ( int v )
  228. {
  229. if ( v < 0 || v > 3 )
  230. return;
  231. _size = v;
  232. resize();
  233. }
  234. void
  235. Track::track( Sequence * t )
  236. {
  237. // t->size( 1, h() );
  238. if ( track() )
  239. add( track() );
  240. // takes->insert( *track(), 0 );
  241. _track = t;
  242. pack->insert( *t, 0 );
  243. resize();
  244. }
  245. void
  246. Track::add_control( Sequence *t )
  247. {
  248. control->add( t );
  249. resize();
  250. }
  251. /**********/
  252. /* Engine */
  253. /**********/
  254. /* THREAD: RT */
  255. nframes_t
  256. Track::process ( nframes_t nframes )
  257. {
  258. if ( playback_ds )
  259. {
  260. record_ds->process( nframes );
  261. return playback_ds->process( nframes );
  262. }
  263. else
  264. return 0;
  265. }
  266. /* THREAD: RT */
  267. void
  268. Track::seek ( nframes_t frame )
  269. {
  270. if ( playback_ds )
  271. return playback_ds->seek( frame );
  272. }
  273. /* FIXME: what about theading issues with this region/audiofile being
  274. accessible from the UI thread? Need locking? */
  275. #include "Region.H"
  276. /* THREAD: IO */
  277. /** create capture region and prepare to record */
  278. void
  279. Track::record ( nframes_t frame )
  280. {
  281. assert( _capture == NULL );
  282. /* FIXME: hack */
  283. Audio_File *af = Audio_File_SF::create( "testing.wav", 48000, input.size(), "Wav/24" );
  284. _capture = new Region( af, track(), frame );
  285. /* FIXME: wrong place for this */
  286. _capture->_r->end = 0;
  287. }
  288. /* THREAD: IO */
  289. /** write a block to the (already opened) capture file */
  290. void
  291. Track::write ( sample_t *buf, nframes_t nframes )
  292. {
  293. _capture->write( buf, nframes );
  294. }
  295. /* THREAD: IO */
  296. void
  297. Track::stop ( nframes_t nframes )
  298. {
  299. _capture = NULL;
  300. }