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.

1107 lines
26KB

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