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.

608 lines
15KB

  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 "Port.H" */
  21. #include "../FL/Fl_Sometimes_Input.H"
  22. #include <FL/fl_ask.H>
  23. #include <FL/Fl_Color_Chooser.H>
  24. // #include <FL/fl_draw.H>
  25. #include <FL/Fl.H>
  26. #include "Engine/Engine.H" // for lock()
  27. #include "Control_Sequence.H"
  28. #include "Annotation_Sequence.H"
  29. int Track::_soloing = 0;
  30. const char *Track::capture_format = "Wav 24";
  31. void
  32. Track::cb_input_field ( Fl_Widget *, void *v )
  33. {
  34. ((Track*)v)->cb_input_field();
  35. }
  36. void
  37. Track::cb_button ( Fl_Widget *w, void *v )
  38. {
  39. ((Track*)v)->cb_button( w );
  40. }
  41. void
  42. Track::cb_input_field ( void )
  43. {
  44. log_start();
  45. name( name_field->value() );
  46. log_end();
  47. }
  48. void
  49. Track::cb_button ( Fl_Widget *w )
  50. {
  51. if ( w == record_button )
  52. {
  53. }
  54. if ( w == mute_button )
  55. {
  56. }
  57. if ( w == solo_button )
  58. {
  59. if ( solo_button->value() )
  60. ++_soloing;
  61. else
  62. --_soloing;
  63. }
  64. else
  65. if ( w == take_menu )
  66. {
  67. int v = take_menu->value();
  68. switch ( v )
  69. {
  70. case 0: /* show all takes */
  71. show_all_takes( take_menu->menu()[ v ].value() );
  72. return;
  73. case 1: /* new */
  74. sequence( (Audio_Sequence*)sequence()->clone_empty() );
  75. return;
  76. }
  77. const char *s = take_menu->menu()[ v ].text;
  78. for ( int i = takes->children(); i--; )
  79. {
  80. Audio_Sequence *t = (Audio_Sequence*)takes->child( i );
  81. if ( ! strcmp( s, t->name() ) )
  82. {
  83. sequence( t );
  84. redraw();
  85. break;
  86. }
  87. }
  88. }
  89. }
  90. void
  91. Track::init ( void )
  92. {
  93. _sequence = NULL;
  94. _name = NULL;
  95. _selected = false;
  96. _show_all_takes = false;
  97. _size = 1;
  98. record_ds = NULL;
  99. playback_ds = NULL;
  100. labeltype( FL_NO_LABEL );
  101. Fl_Group::size( timeline->w(), height() );
  102. Track *o = this;
  103. o->box( FL_THIN_UP_BOX );
  104. {
  105. Fl_Group *o = new Fl_Group( 0, 0, 149, 70 );
  106. o->color( ( Fl_Color ) 53 );
  107. {
  108. Fl_Input *o = name_field = new Fl_Sometimes_Input( 2, 2, 144, 24 );
  109. o->color( FL_BACKGROUND_COLOR );
  110. o->labeltype( FL_NO_LABEL );
  111. o->labelcolor( FL_GRAY0 );
  112. o->textcolor( FL_FOREGROUND_COLOR );
  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, 72, 149, 38 );
  159. o->box( FL_NO_BOX );
  160. Fl_Group::current()->resizable( o );
  161. }
  162. o->size( Track::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. resizable( o );
  170. {
  171. // Fl_Pack *o = annotation = new Fl_Pack( width(), 0, pack->w(), 0 );
  172. Fl_Pack *o = annotation = new Fl_Pack( width(), 0, pack->w(), 1 );
  173. o->end();
  174. }
  175. {
  176. Fl_Pack *o = control = new Fl_Pack( width(), 0, pack->w(), 0 );
  177. o->end();
  178. }
  179. {
  180. Fl_Pack *o = takes = new Fl_Pack( width(), 0, pack->w(), 0 );
  181. o->end();
  182. o->hide();
  183. }
  184. o->end();
  185. }
  186. end();
  187. }
  188. Track::Track ( const char *L, int channels ) :
  189. Fl_Group ( 0, 0, 0, 0, 0 )
  190. {
  191. init();
  192. if ( L )
  193. name( L );
  194. color( (Fl_Color)rand() );
  195. configure_inputs( channels );
  196. configure_outputs( channels );
  197. log_create();
  198. }
  199. Track::~Track ( )
  200. {
  201. timeline->remove_track( this );
  202. /* give up our ports */
  203. configure_inputs( 0 );
  204. configure_outputs( 0 );
  205. /* controls too */
  206. for ( int i = control_out.size(); i--; )
  207. {
  208. control_out.back()->shutdown();
  209. delete control_out.back();
  210. control_out.pop_back();
  211. }
  212. log_destroy();
  213. if ( _name )
  214. free( _name );
  215. }
  216. static int pack_visible( Fl_Pack *p )
  217. {
  218. int v = 0;
  219. for ( int i = p->children(); i--; )
  220. if ( p->child( i )->visible() )
  221. v++;
  222. return v;
  223. }
  224. /* adjust size of widget and children */
  225. void
  226. Track::resize ( void )
  227. {
  228. for ( int i = takes->children(); i--; )
  229. takes->child( i )->size( w(), height() );
  230. for ( int i = annotation->children(); i--; )
  231. annotation->child( i )->size( w(), 24 );
  232. for ( int i = control->children(); i--; )
  233. control->child( i )->size( w(), height() );
  234. /* FIXME: hack! */
  235. if ( annotation->children() )
  236. annotation->show();
  237. else
  238. annotation->hide();
  239. if ( _show_all_takes )
  240. {
  241. takes->show();
  242. Fl_Group::size( w(), height() * ( 1 + takes->children() + pack_visible( control ) ) );
  243. }
  244. else
  245. {
  246. takes->hide();
  247. Fl_Group::size( w(), height() * ( 1 + pack_visible( control ) ) );
  248. }
  249. Fl_Group::size( w(), h() + ( ( 24 ) * pack_visible( annotation ) ) );
  250. if ( sequence() )
  251. sequence()->size( w(), height() );
  252. if ( controls->y() + controls->h() > y() + h() )
  253. controls->hide();
  254. else
  255. controls->show();
  256. /* FIXME: why is this necessary? */
  257. if ( parent() )
  258. parent()->parent()->redraw();
  259. }
  260. void
  261. Track::size ( int v )
  262. {
  263. if ( v < 0 || v > 3 )
  264. return;
  265. _size = v;
  266. resize();
  267. }
  268. void
  269. Track::add ( Audio_Sequence * t )
  270. {
  271. takes->insert( *t, 0 );
  272. if ( ! t->name() )
  273. {
  274. char pat[20];
  275. snprintf( pat, sizeof( pat ), "%d", takes->children() );
  276. t->name( strdup( pat ) );
  277. }
  278. take_menu->add( t->name() );
  279. t->labeltype( FL_ENGRAVED_LABEL );
  280. }
  281. void
  282. Track::remove ( Audio_Sequence *t )
  283. {
  284. timeline->wrlock();
  285. takes->remove( t );
  286. timeline->unlock();
  287. resize();
  288. // take_menu->remove( t->name() );
  289. }
  290. void
  291. Track::remove ( Annotation_Sequence *t )
  292. {
  293. annotation->remove( t );
  294. resize();
  295. }
  296. void
  297. Track::remove ( Control_Sequence *t )
  298. {
  299. engine->lock();
  300. control->remove( t );
  301. engine->unlock();
  302. resize();
  303. }
  304. void
  305. Track::sequence ( Audio_Sequence * t )
  306. {
  307. t->track( this );
  308. if ( sequence() )
  309. add( sequence() );
  310. _sequence = t;
  311. pack->insert( *t, 1 );
  312. t->labeltype( FL_NO_LABEL );
  313. resize();
  314. }
  315. void
  316. Track::add ( Control_Sequence *t )
  317. {
  318. DMESSAGE( "adding control sequence" );
  319. engine->lock();
  320. t->track( this );
  321. control->add( t );
  322. engine->unlock();
  323. resize();
  324. }
  325. void
  326. Track::add ( Annotation_Sequence *t )
  327. {
  328. DMESSAGE( "adding annotation sequence" );
  329. t->track( this );
  330. annotation->add( t );
  331. resize();
  332. }
  333. /** add all widget on this track falling within the given rectangle to
  334. the selection. */
  335. void
  336. Track::select ( int X, int Y, int W, int H,
  337. bool include_control, bool merge_control )
  338. {
  339. Sequence *t = sequence();
  340. if ( ! ( t->y() > Y + H || t->y() + t->h() < Y ) )
  341. t->select_range( X, W );
  342. else
  343. include_control = true;
  344. if ( include_control )
  345. for ( int i = control->children(); i--; )
  346. {
  347. Control_Sequence *c = (Control_Sequence*)control->child( i );
  348. if ( merge_control ||
  349. ( c->y() >= Y && c->y() + c->h() <= Y + H ) )
  350. c->select_range( X, W );
  351. }
  352. }
  353. void
  354. Track::draw ( void )
  355. {
  356. if ( _selected )
  357. {
  358. Fl_Color c = color();
  359. color( FL_RED );
  360. Fl_Group::draw();
  361. color( c );
  362. }
  363. else
  364. Fl_Group::draw();
  365. }
  366. #include "FL/event_name.H"
  367. #include "FL/test_press.H"
  368. int
  369. Track::handle ( int m )
  370. {
  371. /* if ( m != FL_NO_EVENT ) */
  372. /* DMESSAGE( "%s", event_name( m ) ); */
  373. switch ( m )
  374. {
  375. case FL_MOUSEWHEEL:
  376. {
  377. Logger log( this );
  378. if ( ! Fl::event_shift() )
  379. return 0;
  380. int d = Fl::event_dy();
  381. if ( d < 0 )
  382. size( size() - 1 );
  383. else
  384. size( size() + 1 );
  385. return 1;
  386. }
  387. case FL_PUSH:
  388. {
  389. Fl::event_key( 0 );
  390. Logger log( this );
  391. int X = Fl::event_x();
  392. int Y = Fl::event_y();
  393. if ( Fl_Group::handle( m ) )
  394. return 1;
  395. if ( test_press( FL_BUTTON3 ) && X < Track::width() )
  396. {
  397. int c = output.size();
  398. /* context menu */
  399. Fl_Menu_Item menu[] =
  400. {
  401. { "Type", 0, 0, 0, FL_SUBMENU },
  402. { "Mono", 0, 0, 0, FL_MENU_RADIO | ( c == 1 ? FL_MENU_VALUE : 0 ) },
  403. { "Stereo", 0, 0, 0, FL_MENU_RADIO | ( c == 2 ? FL_MENU_VALUE : 0 ) },
  404. { "Quad", 0, 0, 0, FL_MENU_RADIO | ( c == 4 ? FL_MENU_VALUE : 0 ) },
  405. { "...", 0, 0, 0, FL_MENU_RADIO | ( c == 3 || c > 4 ? FL_MENU_VALUE : 0 ) },
  406. { 0 },
  407. { "Add Control" },
  408. { "Add Annotation" },
  409. { "Color" },
  410. { "Remove", 0, 0, 0 }, // transport->rolling ? FL_MENU_INACTIVE : 0 },
  411. { 0 },
  412. };
  413. const Fl_Menu_Item *r = menu->popup( X, Y, "Track" );
  414. if ( r && r > &menu[ 0 ] )
  415. {
  416. if ( r < &menu[ 4 ] )
  417. {
  418. int c = r - &menu[1];
  419. int ca[] = { 1, 2, 4 };
  420. configure_inputs( ca[ c ] );
  421. configure_outputs( ca[ c ] );
  422. }
  423. else
  424. {
  425. if ( r == &menu[ 4 ] )
  426. {
  427. const char *s = fl_input( "How many channels?", "3" );
  428. int c = atoi( s );
  429. if ( c <= 0 || c > 10 )
  430. fl_alert( "Invalid number of channels." );
  431. else
  432. {
  433. configure_inputs( c );
  434. configure_outputs( c );
  435. }
  436. }
  437. else if ( r == &menu[ 6 ] )
  438. {
  439. new Control_Sequence( this );
  440. }
  441. else if ( r == &menu[ 7 ] )
  442. {
  443. add( new Annotation_Sequence( this ) );
  444. }
  445. else if ( r == &menu[ 8 ] )
  446. {
  447. unsigned char r, g, b;
  448. Fl::get_color( color(), r, g, b );
  449. if ( fl_color_chooser( "Track Color", r, g, b ) )
  450. {
  451. color( fl_rgb_color( r, g, b ) );
  452. }
  453. // color( fl_show_colormap( color() ) );
  454. redraw();
  455. }
  456. else if ( r == &menu[ 9 ] )
  457. {
  458. int r = fl_choice( "Are you certain you want to remove track \"%s\"?", "Cancel", NULL, "Remove", name() );
  459. if ( r == 2 )
  460. {
  461. timeline->remove_track( this );
  462. Fl::delete_widget( this );
  463. }
  464. }
  465. }
  466. return 1;
  467. }
  468. return 1;
  469. }
  470. return 0;
  471. }
  472. default:
  473. return Fl_Group::handle( m );
  474. }
  475. return 0;
  476. }