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.

1102 lines
25KB

  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. /* A Track is a container for various sequences; the sequence, the
  19. * takes (inactive sequences), annotation sequences, control
  20. * sequences */
  21. /* TODO: split into Track and Audio_Track (and maybe later Video_Track
  22. * and MIDI_Track */
  23. #include <sys/time.h>
  24. #include "Track.H"
  25. #include "Transport.H"
  26. #include "../FL/Fl_Sometimes_Input.H"
  27. #include "../FL/Fl_Sometimes_Pack.H"
  28. #include <FL/fl_ask.H>
  29. #include <FL/Fl_Color_Chooser.H>
  30. #include <FL/Fl.H>
  31. #include "FL/Fl_Scalepack.H"
  32. #include "FL/Fl_Blink_Button.H"
  33. #include "Engine/Engine.H" // for lock()
  34. #include "Control_Sequence.H"
  35. #include "Annotation_Sequence.H"
  36. #include "Track_Header.H"
  37. #include "const.h"
  38. #include "debug.h"
  39. #include <FL/Fl_Menu_Button.H>
  40. #include "FL/menu_popup.H"
  41. static Fl_Color
  42. random_color ( void )
  43. {
  44. return fl_rgb_color( rand() % 255, rand() % 255, rand() % 255 );
  45. }
  46. static Fl_Menu_Button _menu( 0, 0, 0, 0, "Track" );
  47. int Track::_soloing = 0;
  48. const char *Track::capture_format = "Wav 24";
  49. bool Track::colored_tracks = true;
  50. Track::Track ( const char *L, int channels ) :
  51. Fl_Group ( 0, 0, 0, 0, 0 )
  52. {
  53. init();
  54. if ( L )
  55. name( L );
  56. color( random_color() );
  57. configure_inputs( channels );
  58. configure_outputs( channels );
  59. log_create();
  60. }
  61. Track::Track ( ) : Fl_Group( 0, 0, 1, 1 )
  62. {
  63. init();
  64. timeline->add_track( this );
  65. }
  66. Track::~Track ( )
  67. {
  68. Loggable::block_start();
  69. /* must destroy sequences first to preserve proper log order */
  70. takes->clear();
  71. control->clear();
  72. annotation->clear();
  73. delete sequence();
  74. takes = NULL;
  75. control = NULL;
  76. annotation = NULL;
  77. log_destroy();
  78. /* ensure that soloing accounting is performed */
  79. solo( false );
  80. timeline->remove_track( this );
  81. /* give up our ports */
  82. configure_inputs( 0 );
  83. configure_outputs( 0 );
  84. _sequence = NULL;
  85. if ( _name )
  86. free( _name );
  87. Loggable::block_end();
  88. }
  89. void
  90. Track::init ( void )
  91. {
  92. _row = 0;
  93. _sequence = NULL;
  94. _name = NULL;
  95. _selected = false;
  96. _size = 1;
  97. record_ds = NULL;
  98. playback_ds = NULL;
  99. labeltype( FL_NO_LABEL );
  100. // clear_visible_focus();
  101. Fl_Group::size( timeline->w(), height() );
  102. Track *o = this;
  103. o->box( FL_FLAT_BOX );
  104. {
  105. Track_Header *o = new Track_Header( x(), y(), w(), h() );
  106. name_field = o->name_input;
  107. record_button = o->rec_button;
  108. mute_button = o->mute_button;
  109. solo_button = o->solo_button;
  110. menu_button = o->menu_button;
  111. show_all_takes_button = o->show_all_takes_button;
  112. overlay_controls_button = o->overlay_controls_button;
  113. name_field->callback( cb_button, this );
  114. record_button->callback( cb_button, this );
  115. mute_button->callback( cb_button, this );
  116. solo_button->callback( cb_button, this );
  117. show_all_takes_button->callback( cb_button, this );
  118. overlay_controls_button->callback( cb_button, this );
  119. menu_button->callback( cb_button, this );
  120. resizable( o );
  121. // o->color( (Fl_Color)53 );
  122. }
  123. {
  124. /* this pack holds the active sequence, annotation sequence, control sequences and takes */
  125. Fl_Pack *o = pack = new Fl_Pack( x(), y(), w(), h() );
  126. o->type( Fl_Pack::VERTICAL );
  127. o->labeltype( FL_NO_LABEL );
  128. /* o->resize( x() + width(), y(), w() - width(), h() ); */
  129. /* resizable( o ); */
  130. {
  131. Fl_Pack *o = annotation = new Fl_Pack( 0, 0, pack->w(), 1 );
  132. o->type( Fl_Pack::VERTICAL );
  133. o->end();
  134. }
  135. {
  136. {
  137. Fl_Group *o = controls_heading = new Fl_Group( 0, 0, pack->w(), 10 );
  138. o->box( FL_FLAT_BOX );
  139. o->color( fl_color_add_alpha( fl_rgb_color( 1,1,1 ), 127 ) );
  140. {
  141. Fl_Box *o = new Fl_Box( 0,0, Track::width(), 10 );
  142. o->label( "Controls" );
  143. o->align( FL_ALIGN_RIGHT | FL_ALIGN_INSIDE );
  144. o->labelsize( 10 );
  145. }
  146. o->hide();
  147. o->end();
  148. o->resizable( 0 );
  149. }
  150. {
  151. Fl_Sometimes_Pack *o = control = new Fl_Sometimes_Pack( 0, 0, pack->w(), 1 );
  152. o->spacing( 1 );
  153. o->box( FL_NO_BOX );
  154. o->color( FL_BACKGROUND_COLOR );
  155. o->type( Fl_Pack::VERTICAL );
  156. o->pack( true );
  157. o->hide();
  158. o->align( FL_ALIGN_TOP | FL_ALIGN_LEFT );
  159. o->end();
  160. }
  161. }
  162. {
  163. {
  164. Fl_Group *o = takes_heading = new Fl_Group( 0, 0, pack->w(), 10 );
  165. o->box( FL_FLAT_BOX );
  166. o->color( fl_color_add_alpha( fl_rgb_color( 1,1,1 ), 127 ) );
  167. {
  168. Fl_Box *o = new Fl_Box( 0,0, Track::width(), 10 );
  169. o->label( "Takes" );
  170. o->align( FL_ALIGN_RIGHT | FL_ALIGN_INSIDE );
  171. o->labelsize( 10 );
  172. }
  173. o->hide();
  174. o->end();
  175. o->resizable( 0 );
  176. }
  177. {
  178. Fl_Pack *o = takes = new Fl_Pack( 0, 0, pack->w(), 1 );
  179. o->type( Fl_Pack::VERTICAL );
  180. o->end();
  181. o->hide();
  182. o->align( FL_ALIGN_TOP | FL_ALIGN_LEFT );
  183. }
  184. }
  185. o->end();
  186. }
  187. end();
  188. }
  189. void
  190. Track::set ( Log_Entry &e )
  191. {
  192. for ( int i = 0; i < e.size(); ++i )
  193. {
  194. const char *s, *v;
  195. e.get( i, &s, &v );
  196. if ( ! strcmp( s, ":height" ) )
  197. {
  198. size( atoi( v ) );
  199. adjust_size();
  200. }
  201. else if ( ! strcmp( s, ":selected" ) )
  202. _selected = atoi( v );
  203. // else if ( ! strcmp( s, ":armed"
  204. else if ( ! strcmp( s, ":name" ) )
  205. name( v );
  206. else if ( ! strcmp( s, ":inputs" ) )
  207. configure_inputs( atoi( v ) );
  208. else if ( ! strcmp( s, ":outputs" ) )
  209. configure_outputs( atoi( v ) );
  210. else if ( ! strcmp( s, ":color" ) )
  211. {
  212. color( (Fl_Color)atoll( v ) );
  213. redraw();
  214. }
  215. else if ( ! strcmp( s, ":show-all-takes" ) )
  216. show_all_takes( atoi( v ) );
  217. else if ( ! strcmp( s, ":overlay-controls" ) )
  218. overlay_controls( atoi( v ) );
  219. else if ( ! strcmp( s, ":solo" ) )
  220. solo( atoi( v ) );
  221. else if ( ! strcmp( s, ":mute" ) )
  222. mute( atoi( v ) );
  223. else if ( ! strcmp( s, ":arm" ) )
  224. armed( atoi( v ) );
  225. else if ( ! strcmp( s, ":sequence" ) )
  226. {
  227. int i;
  228. sscanf( v, "%X", &i );
  229. if ( i )
  230. {
  231. Audio_Sequence *t = (Audio_Sequence*)Loggable::find( i );
  232. /* FIXME: our track might not have been
  233. * defined yet... what should we do about this
  234. * chicken/egg problem? */
  235. if ( t )
  236. {
  237. // assert( t );
  238. sequence( t );
  239. }
  240. }
  241. }
  242. else if ( ! strcmp( s, ":row" ) )
  243. row( atoi( v ) );
  244. }
  245. }
  246. void
  247. Track::get ( Log_Entry &e ) const
  248. {
  249. e.add( ":name", _name );
  250. e.add( ":sequence", sequence() );
  251. e.add( ":selected", _selected );
  252. e.add( ":color", (unsigned long)color());
  253. }
  254. void
  255. Track::get_unjournaled ( Log_Entry &e ) const
  256. {
  257. e.add( ":height", size() );
  258. e.add( ":inputs", input.size() );
  259. e.add( ":outputs", output.size() );
  260. e.add( ":show-all-takes", show_all_takes() );
  261. e.add( ":overlay-controls", overlay_controls() );
  262. e.add( ":armed", armed() );
  263. e.add( ":mute", mute() );
  264. e.add( ":solo", solo() );
  265. e.add( ":row", timeline->find_track( this ) );
  266. }
  267. int
  268. Track::row ( void ) const
  269. {
  270. return _row;
  271. }
  272. void
  273. Track::row ( int n )
  274. {
  275. _row = n;
  276. }
  277. void
  278. Track::log_children ( void ) const
  279. {
  280. log_create();
  281. for ( int i = 0; i < control->children(); i++ )
  282. ((Sequence*)control->child( i ))->log_children();
  283. for ( int i = 0; i < annotation->children(); i++ )
  284. ((Sequence*)annotation->child( i ))->log_children();
  285. for ( int i = takes->children(); i--; )
  286. ((Sequence*)takes->child( i ))->log_children();
  287. sequence()->log_children();
  288. }
  289. void
  290. Track::solo ( bool b )
  291. {
  292. if ( b && ! solo_button->value() )
  293. ++_soloing;
  294. else if ( ! b && solo_button->value() )
  295. --_soloing;
  296. solo_button->value( b );
  297. }
  298. void
  299. Track::cb_button ( Fl_Widget *w, void *v )
  300. {
  301. ((Track*)v)->cb_button( w );
  302. }
  303. void
  304. Track::cb_button ( Fl_Widget *w )
  305. {
  306. Logger log(this);
  307. if ( w == name_field )
  308. {
  309. name( name_field->value() );
  310. }
  311. else if ( w == record_button )
  312. {
  313. }
  314. else if ( w == mute_button )
  315. {
  316. }
  317. else if ( w == solo_button )
  318. {
  319. if ( solo_button->value() )
  320. ++_soloing;
  321. else
  322. --_soloing;
  323. }
  324. else if ( w == show_all_takes_button )
  325. {
  326. show_all_takes( show_all_takes_button->value() );
  327. }
  328. else if ( w == overlay_controls_button )
  329. {
  330. overlay_controls( overlay_controls_button->value() );
  331. }
  332. else if ( w == menu_button )
  333. {
  334. menu_popup( &menu(), menu_button->x(), menu_button->y() );
  335. }
  336. }
  337. static int pack_visible( Fl_Pack *p )
  338. {
  339. int v = 0;
  340. for ( int i = p->children(); i--; )
  341. if ( p->child( i )->visible() )
  342. v++;
  343. return v;
  344. }
  345. /* adjust size of widget and children */
  346. void
  347. Track::adjust_size ( void )
  348. {
  349. for ( int i = takes->children(); i--; )
  350. takes->child( i )->size( w(), height() );
  351. for ( int i = annotation->children(); i--; )
  352. annotation->child( i )->size( w(), 24 );
  353. for ( int i = control->children(); i--; )
  354. control->child( i )->size( w(), height() );
  355. if ( overlay_controls() )
  356. {
  357. for ( int i = 0; i < control->children(); i++ )
  358. {
  359. Control_Sequence *o = (Control_Sequence*)control->child(i);
  360. if ( i != 0 )
  361. o->box( FL_NO_BOX );
  362. o->header()->hide();
  363. }
  364. control->pack( false );
  365. }
  366. else
  367. {
  368. for ( int i = 0; i < control->children(); i++ )
  369. {
  370. Control_Sequence *o = (Control_Sequence*)control->child(i);
  371. o->box( FL_FLAT_BOX );
  372. o->header()->show();
  373. }
  374. control->pack( true );
  375. }
  376. int TY = 0;
  377. if ( annotation->children() )
  378. {
  379. annotation->show();
  380. TY += 24 * pack_visible( annotation );
  381. }
  382. else
  383. annotation->hide();
  384. /* height of the sequence */
  385. TY += height();
  386. if ( control->children() )
  387. {
  388. int TH;
  389. /* calculate height of control pack */
  390. if ( overlay_controls() )
  391. TH = height() * (control->children() ? 1 : 0);
  392. else
  393. TH = height() * pack_visible( control );
  394. TY += TH;
  395. control->show();
  396. controls_heading->show();
  397. }
  398. else
  399. {
  400. control->hide();
  401. controls_heading->hide();
  402. }
  403. if ( show_all_takes() )
  404. {
  405. /* calculate height of takes pack */
  406. const int TH = height() * takes->children();
  407. TY += TH;
  408. takes->show();
  409. takes_heading->show();
  410. }
  411. else
  412. {
  413. takes_heading->hide();
  414. takes->hide();
  415. }
  416. if ( takes_heading->visible() )
  417. TY += takes_heading->h();
  418. if ( controls_heading->visible() )
  419. TY += controls_heading->h();
  420. int TH;
  421. if ( ! size() )
  422. {
  423. takes->hide();
  424. control->hide();
  425. TH = height();
  426. }
  427. else
  428. TH = TY;
  429. Fl_Group::size( w(), TH );
  430. if ( sequence() )
  431. sequence()->size( w(), height() );
  432. /* FIXME: why is this necessary? */
  433. if ( parent() )
  434. parent()->parent()->redraw();
  435. }
  436. void
  437. Track::name ( const char *name )
  438. {
  439. if ( _name )
  440. free( _name );
  441. _name = timeline->get_unique_track_name(name);
  442. if ( name_field )
  443. name_field->value( _name );
  444. update_port_names();
  445. }
  446. const char *
  447. Track::name ( void ) const
  448. {
  449. return _name;
  450. }
  451. void
  452. Track::size ( int v )
  453. {
  454. if ( v < 0 || v > 3 )
  455. return;
  456. _size = v;
  457. adjust_size();
  458. }
  459. void
  460. Track::add ( Audio_Sequence * t )
  461. {
  462. t->track( this );
  463. takes->insert( *t, 0 );
  464. /* show the take header */
  465. t->child(0)->show();
  466. t->color( fl_color_average( FL_BLACK, FL_GRAY, 0.25f ) );
  467. t->labeltype( FL_ENGRAVED_LABEL );
  468. }
  469. void
  470. Track::remove ( Audio_Sequence *t )
  471. {
  472. if ( ! takes )
  473. return;
  474. if ( sequence() == t )
  475. {
  476. pack->remove( t );
  477. if ( takes->children() )
  478. sequence( (Audio_Sequence*)takes->child( 0 ) );
  479. else
  480. /* FIXME: should this ever happen? */
  481. _sequence = NULL;
  482. }
  483. else
  484. takes->remove( t );
  485. /* delete t; */
  486. adjust_size();
  487. }
  488. void
  489. Track::remove ( Annotation_Sequence *t )
  490. {
  491. if ( ! annotation )
  492. return;
  493. annotation->remove( t );
  494. adjust_size();
  495. }
  496. void
  497. Track::remove ( Control_Sequence *t )
  498. {
  499. if ( ! control )
  500. return;
  501. engine->lock();
  502. control->remove( t );
  503. engine->unlock();
  504. adjust_size();
  505. }
  506. void
  507. Track::sequence ( Audio_Sequence * t )
  508. {
  509. if ( sequence() == t )
  510. {
  511. DMESSAGE( "Attempt to set sequence twice" );
  512. return;
  513. }
  514. t->track( this );
  515. if ( sequence() )
  516. add( sequence() );
  517. _sequence = t;
  518. /* insert following the annotation pack */
  519. pack->insert( *t, 1 );
  520. /* hide the take header */
  521. t->child(0)->hide();
  522. t->color( FL_GRAY );
  523. t->labeltype( FL_NO_LABEL );
  524. adjust_size();
  525. }
  526. void
  527. Track::add ( Control_Sequence *t )
  528. {
  529. DMESSAGE( "adding control sequence" );
  530. engine->lock();
  531. t->track( this );
  532. t->color( random_color() );
  533. // control->insert( *t, 0 );
  534. control->add( t );
  535. engine->unlock();
  536. adjust_size();
  537. }
  538. void
  539. Track::add ( Annotation_Sequence *t )
  540. {
  541. DMESSAGE( "adding annotation sequence" );
  542. t->track( this );
  543. annotation->add( t );
  544. adjust_size();
  545. }
  546. /** add all widget on this track falling within the given rectangle to
  547. the selection. */
  548. void
  549. Track::select ( int X, int Y, int W, int H,
  550. bool include_control, bool merge_control )
  551. {
  552. Sequence *t = sequence();
  553. X -= Track::width();
  554. if ( ! ( t->y() > Y + H || t->y() + t->h() < Y ) )
  555. t->select_range( X, W );
  556. else
  557. include_control = true;
  558. if ( include_control )
  559. for ( int i = control->children(); i--; )
  560. {
  561. Control_Sequence *c = (Control_Sequence*)control->child( i );
  562. if ( merge_control ||
  563. ( c->y() >= Y && c->y() + c->h() <= Y + H ) )
  564. c->select_range( X, W );
  565. }
  566. }
  567. void
  568. Track::menu_cb ( Fl_Widget *w, void *v )
  569. {
  570. ((Track*)v)->menu_cb( (Fl_Menu_*) w );
  571. }
  572. void
  573. Track::menu_cb ( const Fl_Menu_ *m )
  574. {
  575. char picked[256];
  576. m->item_pathname( picked, sizeof( picked ) );
  577. DMESSAGE( "Picked: %s", picked );
  578. Logger log( this );
  579. if ( ! strcmp( picked, "Type/Mono" ) )
  580. {
  581. configure_inputs( 1 );
  582. configure_outputs( 1 );
  583. }
  584. else if ( ! strcmp( picked, "Type/Stereo" ) )
  585. {
  586. configure_inputs( 2 );
  587. configure_outputs( 2 );
  588. }
  589. else if ( ! strcmp( picked, "Type/Quad" ) )
  590. {
  591. configure_inputs( 4 );
  592. configure_outputs( 4 );
  593. }
  594. else if ( ! strcmp( picked, "Type/..." ) )
  595. {
  596. const char *s = fl_input( "How many channels?", "3" );
  597. if ( s )
  598. {
  599. int c = atoi( s );
  600. if ( c <= 0 || c > 10 )
  601. fl_alert( "Invalid number of channels." );
  602. else
  603. {
  604. configure_inputs( c );
  605. configure_outputs( c );
  606. }
  607. }
  608. }
  609. else if ( ! strcmp( picked, "/Add Control" ) )
  610. {
  611. /* add audio track */
  612. char *name = get_unique_control_name( "Control" );
  613. new Control_Sequence( this, name );
  614. }
  615. else if ( ! strcmp( picked, "/Overlay controls" ) )
  616. {
  617. overlay_controls( ! m->mvalue()->value() );
  618. }
  619. else if ( ! strcmp( picked, "/Add Annotation" ) )
  620. {
  621. add( new Annotation_Sequence( this ) );
  622. }
  623. else if ( ! strcmp( picked, "/Color" ) )
  624. {
  625. unsigned char r, g, b;
  626. Fl::get_color( color(), r, g, b );
  627. if ( fl_color_chooser( "Track Color", r, g, b ) )
  628. {
  629. color( fl_rgb_color( r, g, b ) );
  630. }
  631. redraw();
  632. }
  633. else if ( ! strcmp( picked, "Flags/Record" ) )
  634. {
  635. armed( m->mvalue()->flags & FL_MENU_VALUE );
  636. }
  637. else if ( ! strcmp( picked, "Flags/Mute" ) )
  638. {
  639. mute( m->mvalue()->flags & FL_MENU_VALUE );
  640. }
  641. else if ( ! strcmp( picked, "Flags/Solo" ) )
  642. {
  643. solo( m->mvalue()->flags & FL_MENU_VALUE );
  644. }
  645. else if ( ! strcmp( picked, "Size/Small" ) )
  646. {
  647. size( 0 );
  648. }
  649. else if ( ! strcmp( picked, "Size/Medium" ) )
  650. {
  651. size( 1 );
  652. }
  653. else if ( ! strcmp( picked, "Size/Large" ) )
  654. {
  655. size( 2 );
  656. }
  657. else if ( ! strcmp( picked, "Size/Huge" ) )
  658. {
  659. size( 3 );
  660. }
  661. else if ( ! strcmp( picked, "/Remove" ) )
  662. {
  663. int r = fl_choice( "Are you certain you want to remove track \"%s\"?", "Cancel", NULL, "Remove", name() );
  664. if ( r == 2 )
  665. {
  666. timeline->remove_track( this );
  667. Fl::delete_widget( this );
  668. }
  669. }
  670. else if ( ! strcmp( picked, "/Rename" ) )
  671. {
  672. ((Fl_Sometimes_Input*)name_field)->take_focus();
  673. }
  674. else if ( ! strcmp( picked, "/Move Up" ) )
  675. {
  676. timeline->move_track_up( this );
  677. }
  678. else if ( ! strcmp( picked, "/Move Down" ) )
  679. {
  680. timeline->move_track_down( this );
  681. }
  682. else if ( !strcmp( picked, "Takes/Show all takes" ) )
  683. {
  684. show_all_takes( ! m->mvalue()->value() );
  685. }
  686. else if ( !strcmp( picked, "Takes/New" ) )
  687. {
  688. sequence( (Audio_Sequence*)sequence()->clone_empty() );
  689. }
  690. else if ( !strcmp( picked, "Takes/Remove" ) )
  691. {
  692. if ( takes->children() )
  693. {
  694. Loggable::block_start();
  695. Audio_Sequence *s = sequence();
  696. sequence( (Audio_Sequence*)takes->child( 0 ) );
  697. delete s;
  698. Loggable::block_end();
  699. }
  700. }
  701. else if ( !strcmp( picked, "Takes/Remove others" ))
  702. {
  703. if ( takes->children() )
  704. {
  705. Loggable::block_start();
  706. takes->clear();
  707. Loggable::block_end();
  708. }
  709. }
  710. else if ( !strncmp( picked, "Takes/", sizeof( "Takes/" ) - 1 ) )
  711. {
  712. Audio_Sequence* s = (Audio_Sequence*)m->mvalue()->user_data();
  713. sequence( s );
  714. }
  715. }
  716. /** retrun a pointer to the control sequence named /name/, or NULL if no control sequence is named /name/ */
  717. Control_Sequence *
  718. Track::control_by_name ( const char *name )
  719. {
  720. for ( int i = control->children(); i-- ; )
  721. {
  722. Control_Sequence *t = (Control_Sequence*)control->child( i );
  723. if ( t->name() && name && ! strcmp( name, t->name() ) )
  724. return t;
  725. }
  726. return NULL;
  727. }
  728. /** return a malloc'd string representing a unique name for a new control sequence */
  729. char *
  730. Track::get_unique_control_name ( const char *name )
  731. {
  732. char pat[256];
  733. strcpy( pat, name );
  734. for ( int i = 1; control_by_name( pat ); ++i )
  735. snprintf( pat, sizeof( pat ), "%s.%d", name, i );
  736. return strdup( pat );
  737. }
  738. /** build the context menu */
  739. Fl_Menu_Button &
  740. Track::menu ( void ) const
  741. {
  742. int c = output.size();
  743. int s = size();
  744. _menu.clear();
  745. _menu.add( "Takes/Show all takes", 0, 0, 0, FL_MENU_TOGGLE | ( show_all_takes() ? FL_MENU_VALUE : 0 ) );
  746. _menu.add( "Takes/New", 0, 0, 0 );
  747. if ( takes->children() )
  748. {
  749. _menu.add( "Takes/Remove", 0, 0, 0 );
  750. _menu.add( "Takes/Remove others", 0, 0, 0, FL_MENU_DIVIDER );
  751. for ( int i = 0; i < takes->children(); ++i )
  752. {
  753. Sequence *s = (Sequence *)takes->child( i );
  754. char n[256];
  755. snprintf( n, sizeof(n), "Takes/%s", s->name() );
  756. _menu.add( n, 0, 0, s);
  757. }
  758. }
  759. _menu.add( "Type/Mono", 0, 0, 0, FL_MENU_RADIO | ( c == 1 ? FL_MENU_VALUE : 0 ) );
  760. _menu.add( "Type/Stereo", 0, 0, 0, FL_MENU_RADIO | ( c == 2 ? FL_MENU_VALUE : 0 ));
  761. _menu.add( "Type/Quad", 0, 0, 0, FL_MENU_RADIO | ( c == 4 ? FL_MENU_VALUE : 0 ) );
  762. _menu.add( "Type/...", 0, 0, 0, FL_MENU_RADIO | ( c == 3 || c > 4 ? FL_MENU_VALUE : 0 ) );
  763. _menu.add( "Overlay controls", 0, 0, 0, FL_MENU_TOGGLE | ( overlay_controls() ? FL_MENU_VALUE : 0 ) );
  764. _menu.add( "Add Control", 0, 0, 0 );
  765. _menu.add( "Add Annotation", 0, 0, 0 );
  766. _menu.add( "Color", 0, 0, 0 );
  767. _menu.add( "Rename", FL_CTRL + 'n', 0, 0 );
  768. _menu.add( "Size/Small", FL_ALT + '1', 0, 0, FL_MENU_RADIO | ( s == 0 ? FL_MENU_VALUE : 0 ) );
  769. _menu.add( "Size/Medium", FL_ALT + '2', 0, 0, FL_MENU_RADIO | ( s == 1 ? FL_MENU_VALUE : 0 ) );
  770. _menu.add( "Size/Large", FL_ALT + '3', 0, 0, FL_MENU_RADIO | ( s == 2 ? FL_MENU_VALUE : 0 ) );
  771. _menu.add( "Size/Huge", FL_ALT + '4', 0, 0, FL_MENU_RADIO | ( s == 3 ? FL_MENU_VALUE : 0 ) );
  772. _menu.add( "Flags/Record", FL_CTRL + 'r', 0, 0, FL_MENU_TOGGLE | ( armed() ? FL_MENU_VALUE : 0 ) );
  773. _menu.add( "Flags/Mute", FL_CTRL + 'm', 0, 0, FL_MENU_TOGGLE | ( mute() ? FL_MENU_VALUE : 0 ) );
  774. _menu.add( "Flags/Solo", FL_CTRL + 's', 0, 0, FL_MENU_TOGGLE | ( solo() ? FL_MENU_VALUE : 0 ) );
  775. _menu.add( "Move Up", FL_SHIFT + '1', 0, 0 );
  776. _menu.add( "Move Down", FL_SHIFT + '2', 0, 0 );
  777. _menu.add( "Remove", 0, 0, 0 ); // transport->rolling ? FL_MENU_INACTIVE : 0 );
  778. _menu.callback( &Track::menu_cb, (void*)this );
  779. return _menu;
  780. }
  781. #include "FL/event_name.H"
  782. #include "FL/test_press.H"
  783. void
  784. Track::draw ( void )
  785. {
  786. fl_push_clip( x(), y(), w(), h() );
  787. Fl_Color saved_color = color();
  788. if ( ! Track::colored_tracks )
  789. color( FL_GRAY );
  790. if ( _selected )
  791. {
  792. Fl_Color c = color();
  793. color( FL_RED );
  794. Fl_Group::draw();
  795. color( c );
  796. }
  797. else
  798. Fl_Group::draw();
  799. if ( ! Track::colored_tracks )
  800. color( saved_color );
  801. fl_pop_clip();
  802. }
  803. int
  804. Track::handle ( int m )
  805. {
  806. /* if ( m != FL_NO_EVENT ) */
  807. /* DMESSAGE( "%s", event_name( m ) ); */
  808. switch ( m )
  809. {
  810. case FL_KEYBOARD:
  811. {
  812. Fl_Menu_Button * men = &menu();
  813. if ( Fl::event_key() == FL_Menu )
  814. {
  815. menu_popup( men );
  816. return 1;
  817. }
  818. else
  819. return men->test_shortcut() || Fl_Group::handle( m );
  820. }
  821. case FL_MOUSEWHEEL:
  822. {
  823. Logger log( this );
  824. if ( ! Fl::event_shift() )
  825. return Fl_Group::handle( m );
  826. int d = Fl::event_dy();
  827. if ( d < 0 )
  828. size( size() - 1 );
  829. else
  830. size( size() + 1 );
  831. return 1;
  832. }
  833. case FL_PUSH:
  834. {
  835. Logger log( this );
  836. if ( Fl_Group::handle( m ) )
  837. return 1;
  838. if ( test_press( FL_BUTTON3 ) && Fl::event_x() < Track::width() )
  839. {
  840. menu_popup( &menu() );
  841. return 1;
  842. }
  843. return 0;
  844. }
  845. default:
  846. return Fl_Group::handle( m );
  847. }
  848. return 0;
  849. }
  850. void
  851. Track::connect_osc ( void )
  852. {
  853. for ( int j = control->children(); j--; )
  854. {
  855. Control_Sequence *c = (Control_Sequence*)control->child( j );
  856. c->connect_osc();
  857. }
  858. }
  859. void
  860. Track::process_osc ( void )
  861. {
  862. for ( int j = control->children(); j--; )
  863. {
  864. Control_Sequence *c = (Control_Sequence*)control->child( j );
  865. c->process_osc();
  866. }
  867. }