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.

377 lines
9.2KB

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