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.

1298 lines
31KB

  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. extern char *instance_name;
  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. _capture_offset = 0;
  93. _row = 0;
  94. _sequence = NULL;
  95. _name = NULL;
  96. _selected = false;
  97. _size = 1;
  98. record_ds = NULL;
  99. playback_ds = NULL;
  100. labeltype( FL_NO_LABEL );
  101. // clear_visible_focus();
  102. Fl_Group::size( timeline->w(), height() );
  103. Track *o = this;
  104. o->box( FL_FLAT_BOX );
  105. {
  106. Track_Header *o = new Track_Header( x(), y(), w(), h() );
  107. name_field = o->name_input;
  108. record_button = o->rec_button;
  109. mute_button = o->mute_button;
  110. solo_button = o->solo_button;
  111. menu_button = o->menu_button;
  112. show_all_takes_button = o->show_all_takes_button;
  113. overlay_controls_button = o->overlay_controls_button;
  114. name_field->callback( cb_button, this );
  115. record_button->callback( cb_button, this );
  116. mute_button->callback( cb_button, this );
  117. solo_button->callback( cb_button, this );
  118. show_all_takes_button->callback( cb_button, this );
  119. overlay_controls_button->callback( cb_button, this );
  120. menu_button->callback( cb_button, this );
  121. resizable( o );
  122. // o->color( (Fl_Color)53 );
  123. }
  124. {
  125. /* this pack holds the active sequence, annotation sequence, control sequences and takes */
  126. Fl_Pack *o = pack = new Fl_Pack( x(), y(), w(), h() );
  127. o->type( Fl_Pack::VERTICAL );
  128. o->labeltype( FL_NO_LABEL );
  129. /* o->resize( x() + width(), y(), w() - width(), h() ); */
  130. /* resizable( o ); */
  131. {
  132. Fl_Pack *o = annotation = new Fl_Pack( 0, 0, pack->w(), 1 );
  133. o->type( Fl_Pack::VERTICAL );
  134. o->end();
  135. }
  136. {
  137. {
  138. Fl_Group *o = controls_heading = new Fl_Group( 0, 0, pack->w(), 10 );
  139. o->box( FL_FLAT_BOX );
  140. o->color( fl_color_add_alpha( fl_rgb_color( 1,1,1 ), 127 ) );
  141. {
  142. Fl_Box *o = new Fl_Box( 0,0, Track::width(), 10 );
  143. o->label( "Controls" );
  144. o->align( FL_ALIGN_RIGHT | FL_ALIGN_INSIDE );
  145. o->labelsize( 10 );
  146. }
  147. o->hide();
  148. o->end();
  149. o->resizable( 0 );
  150. }
  151. {
  152. Fl_Sometimes_Pack *o = control = new Fl_Sometimes_Pack( 0, 0, pack->w(), 1 );
  153. o->spacing( 1 );
  154. o->box( FL_NO_BOX );
  155. o->color( FL_BACKGROUND_COLOR );
  156. o->type( Fl_Pack::VERTICAL );
  157. o->pack( true );
  158. o->hide();
  159. o->align( FL_ALIGN_TOP | FL_ALIGN_LEFT );
  160. o->end();
  161. }
  162. }
  163. {
  164. {
  165. Fl_Group *o = takes_heading = new Fl_Group( 0, 0, pack->w(), 10 );
  166. o->box( FL_FLAT_BOX );
  167. o->color( fl_color_add_alpha( fl_rgb_color( 1,1,1 ), 127 ) );
  168. {
  169. Fl_Box *o = new Fl_Box( 0,0, Track::width(), 10 );
  170. o->label( "Takes" );
  171. o->align( FL_ALIGN_RIGHT | FL_ALIGN_INSIDE );
  172. o->labelsize( 10 );
  173. }
  174. o->hide();
  175. o->end();
  176. o->resizable( 0 );
  177. }
  178. {
  179. Fl_Pack *o = takes = new Fl_Pack( 0, 0, pack->w(), 1 );
  180. o->type( Fl_Pack::VERTICAL );
  181. o->end();
  182. o->hide();
  183. o->align( FL_ALIGN_TOP | FL_ALIGN_LEFT );
  184. }
  185. }
  186. o->end();
  187. }
  188. end();
  189. }
  190. void
  191. Track::set ( Log_Entry &e )
  192. {
  193. for ( int i = 0; i < e.size(); ++i )
  194. {
  195. const char *s, *v;
  196. e.get( i, &s, &v );
  197. if ( ! strcmp( s, ":height" ) )
  198. {
  199. size( atoi( v ) );
  200. adjust_size();
  201. }
  202. else if ( ! strcmp( s, ":selected" ) )
  203. _selected = atoi( v );
  204. // else if ( ! strcmp( s, ":armed"
  205. else if ( ! strcmp( s, ":name" ) )
  206. name( v );
  207. else if ( ! strcmp( s, ":inputs" ) )
  208. configure_inputs( atoi( v ) );
  209. else if ( ! strcmp( s, ":outputs" ) )
  210. configure_outputs( atoi( v ) );
  211. else if ( ! strcmp( s, ":color" ) )
  212. {
  213. color( (Fl_Color)atoll( v ) );
  214. redraw();
  215. }
  216. else if ( ! strcmp( s, ":show-all-takes" ) )
  217. show_all_takes( atoi( v ) );
  218. else if ( ! strcmp( s, ":overlay-controls" ) )
  219. overlay_controls( atoi( v ) );
  220. else if ( ! strcmp( s, ":solo" ) )
  221. solo( atoi( v ) );
  222. else if ( ! strcmp( s, ":mute" ) )
  223. mute( atoi( v ) );
  224. else if ( ! strcmp( s, ":arm" ) )
  225. armed( atoi( v ) );
  226. else if ( ! strcmp( s, ":sequence" ) )
  227. {
  228. int i;
  229. sscanf( v, "%X", &i );
  230. if ( i )
  231. {
  232. Audio_Sequence *t = (Audio_Sequence*)Loggable::find( i );
  233. /* FIXME: our track might not have been
  234. * defined yet... what should we do about this
  235. * chicken/egg problem? */
  236. if ( t )
  237. {
  238. // assert( t );
  239. sequence( t );
  240. }
  241. }
  242. }
  243. else if ( ! strcmp( s, ":row" ) )
  244. row( atoi( v ) );
  245. }
  246. }
  247. void
  248. Track::get ( Log_Entry &e ) const
  249. {
  250. e.add( ":name", _name );
  251. e.add( ":sequence", sequence() );
  252. e.add( ":selected", _selected );
  253. e.add( ":color", (unsigned long)color());
  254. }
  255. void
  256. Track::get_unjournaled ( Log_Entry &e ) const
  257. {
  258. e.add( ":height", size() );
  259. e.add( ":inputs", input.size() );
  260. e.add( ":outputs", output.size() );
  261. e.add( ":show-all-takes", show_all_takes() );
  262. e.add( ":overlay-controls", overlay_controls() );
  263. e.add( ":armed", armed() );
  264. e.add( ":mute", mute() );
  265. e.add( ":solo", solo() );
  266. e.add( ":row", timeline->find_track( this ) );
  267. }
  268. int
  269. Track::row ( void ) const
  270. {
  271. return _row;
  272. }
  273. void
  274. Track::row ( int n )
  275. {
  276. _row = n;
  277. }
  278. void
  279. Track::log_children ( void ) const
  280. {
  281. log_create();
  282. for ( int i = 0; i < control->children(); i++ )
  283. ((Sequence*)control->child( i ))->log_children();
  284. for ( int i = 0; i < annotation->children(); i++ )
  285. ((Sequence*)annotation->child( i ))->log_children();
  286. for ( int i = takes->children(); i--; )
  287. ((Sequence*)takes->child( i ))->log_children();
  288. sequence()->log_children();
  289. }
  290. void
  291. Track::solo ( bool b )
  292. {
  293. if ( b && ! solo_button->value() )
  294. ++_soloing;
  295. else if ( ! b && solo_button->value() )
  296. --_soloing;
  297. solo_button->value( b );
  298. }
  299. void
  300. Track::cb_button ( Fl_Widget *w, void *v )
  301. {
  302. ((Track*)v)->cb_button( w );
  303. }
  304. void
  305. Track::cb_button ( Fl_Widget *w )
  306. {
  307. Logger log(this);
  308. if ( w == name_field )
  309. {
  310. name( name_field->value() );
  311. }
  312. else if ( w == record_button )
  313. {
  314. }
  315. else if ( w == mute_button )
  316. {
  317. }
  318. else if ( w == solo_button )
  319. {
  320. if ( solo_button->value() )
  321. ++_soloing;
  322. else
  323. --_soloing;
  324. }
  325. else if ( w == show_all_takes_button )
  326. {
  327. show_all_takes( show_all_takes_button->value() );
  328. }
  329. else if ( w == overlay_controls_button )
  330. {
  331. overlay_controls( overlay_controls_button->value() );
  332. }
  333. else if ( w == menu_button )
  334. {
  335. menu_popup( &menu(), menu_button->x(), menu_button->y() );
  336. }
  337. }
  338. static int pack_visible( Fl_Pack *p )
  339. {
  340. int v = 0;
  341. for ( int i = p->children(); i--; )
  342. if ( p->child( i )->visible() )
  343. v++;
  344. return v;
  345. }
  346. /* adjust size of widget and children */
  347. void
  348. Track::adjust_size ( void )
  349. {
  350. for ( int i = takes->children(); i--; )
  351. takes->child( i )->size( w(), height() );
  352. for ( int i = annotation->children(); i--; )
  353. annotation->child( i )->size( w(), 24 );
  354. for ( int i = control->children(); i--; )
  355. control->child( i )->size( w(), height() );
  356. if ( overlay_controls() )
  357. {
  358. for ( int i = 0; i < control->children(); i++ )
  359. {
  360. Control_Sequence *o = (Control_Sequence*)control->child(i);
  361. if ( i != 0 )
  362. o->box( FL_NO_BOX );
  363. o->header()->hide();
  364. }
  365. control->pack( false );
  366. }
  367. else
  368. {
  369. for ( int i = 0; i < control->children(); i++ )
  370. {
  371. Control_Sequence *o = (Control_Sequence*)control->child(i);
  372. o->box( FL_FLAT_BOX );
  373. o->header()->show();
  374. }
  375. control->pack( true );
  376. }
  377. int TY = 0;
  378. if ( annotation->children() )
  379. {
  380. annotation->show();
  381. TY += 24 * pack_visible( annotation );
  382. }
  383. else
  384. annotation->hide();
  385. /* height of the sequence */
  386. TY += height();
  387. if ( control->children() )
  388. {
  389. int TH;
  390. /* calculate height of control pack */
  391. if ( overlay_controls() )
  392. TH = height() * (control->children() ? 1 : 0);
  393. else
  394. TH = height() * pack_visible( control );
  395. TY += TH;
  396. control->show();
  397. controls_heading->show();
  398. }
  399. else
  400. {
  401. control->hide();
  402. controls_heading->hide();
  403. }
  404. if ( show_all_takes() )
  405. {
  406. /* calculate height of takes pack */
  407. const int TH = height() * takes->children();
  408. TY += TH;
  409. takes->show();
  410. takes_heading->show();
  411. }
  412. else
  413. {
  414. takes_heading->hide();
  415. takes->hide();
  416. }
  417. if ( takes_heading->visible() )
  418. TY += takes_heading->h();
  419. if ( controls_heading->visible() )
  420. TY += controls_heading->h();
  421. int TH;
  422. if ( ! size() )
  423. {
  424. takes->hide();
  425. control->hide();
  426. TH = height();
  427. }
  428. else
  429. TH = TY;
  430. Fl_Group::size( w(), TH );
  431. if ( sequence() )
  432. sequence()->size( w(), height() );
  433. /* FIXME: why is this necessary? */
  434. if ( parent() )
  435. parent()->parent()->redraw();
  436. }
  437. void
  438. Track::name ( const char *name )
  439. {
  440. if ( _name )
  441. free( _name );
  442. _name = timeline->get_unique_track_name(name);
  443. if ( name_field )
  444. name_field->value( _name );
  445. update_port_names();
  446. }
  447. const char *
  448. Track::name ( void ) const
  449. {
  450. return _name;
  451. }
  452. void
  453. Track::size ( int v )
  454. {
  455. if ( v < 0 || v > 4 )
  456. return;
  457. _size = v;
  458. adjust_size();
  459. }
  460. void
  461. Track::add ( Audio_Sequence * t )
  462. {
  463. t->track( this );
  464. takes->insert( *t, 0 );
  465. /* show the take header */
  466. t->child(0)->show();
  467. t->color( fl_color_average( FL_BLACK, FL_GRAY, 0.25f ) );
  468. t->labeltype( FL_ENGRAVED_LABEL );
  469. }
  470. void
  471. Track::remove ( Audio_Sequence *t )
  472. {
  473. if ( ! takes )
  474. return;
  475. if ( sequence() == t )
  476. {
  477. pack->remove( t );
  478. if ( takes->children() )
  479. sequence( (Audio_Sequence*)takes->child( 0 ) );
  480. else
  481. /* FIXME: should this ever happen? */
  482. _sequence = NULL;
  483. }
  484. else
  485. takes->remove( t );
  486. /* delete t; */
  487. adjust_size();
  488. }
  489. void
  490. Track::remove ( Annotation_Sequence *t )
  491. {
  492. if ( ! annotation )
  493. return;
  494. annotation->remove( t );
  495. adjust_size();
  496. }
  497. void
  498. Track::remove ( Control_Sequence *t )
  499. {
  500. if ( ! control )
  501. return;
  502. control->remove( t );
  503. adjust_size();
  504. }
  505. void
  506. Track::sequence ( Audio_Sequence * t )
  507. {
  508. if ( sequence() == t )
  509. {
  510. DMESSAGE( "Attempt to set sequence twice" );
  511. return;
  512. }
  513. t->track( this );
  514. if ( sequence() )
  515. add( sequence() );
  516. _sequence = t;
  517. /* insert following the annotation pack */
  518. pack->insert( *t, 1 );
  519. /* hide the take header */
  520. t->child(0)->hide();
  521. t->color( FL_GRAY );
  522. t->labeltype( FL_NO_LABEL );
  523. adjust_size();
  524. }
  525. void
  526. Track::add ( Control_Sequence *t )
  527. {
  528. DMESSAGE( "adding control sequence" );
  529. t->track( this );
  530. t->color( random_color() );
  531. // control->insert( *t, 0 );
  532. control->add( t );
  533. adjust_size();
  534. }
  535. void
  536. Track::add ( Annotation_Sequence *t )
  537. {
  538. DMESSAGE( "adding annotation sequence" );
  539. t->track( this );
  540. annotation->add( t );
  541. adjust_size();
  542. }
  543. /** add all widget on this track falling within the given rectangle to
  544. the selection. */
  545. void
  546. Track::select ( int X, int Y, int W, int H,
  547. bool include_control, bool merge_control )
  548. {
  549. Sequence *t = sequence();
  550. X -= Track::width();
  551. if ( ! ( t->y() > Y + H || t->y() + t->h() < Y ) )
  552. t->select_range( X, W );
  553. else
  554. include_control = true;
  555. if ( include_control )
  556. for ( int i = control->children(); i--; )
  557. {
  558. Control_Sequence *c = (Control_Sequence*)control->child( i );
  559. if ( merge_control ||
  560. ( c->y() >= Y && c->y() + c->h() <= Y + H ) )
  561. c->select_range( X, W );
  562. }
  563. }
  564. void
  565. Track::menu_cb ( Fl_Widget *w, void *v )
  566. {
  567. ((Track*)v)->menu_cb( (Fl_Menu_*) w );
  568. }
  569. void
  570. Track::command_configure_channels ( int n )
  571. {
  572. /* due to locking this should only be invoked by direct user action */
  573. timeline->track_lock.wrlock();
  574. configure_inputs( n );
  575. configure_outputs( n );
  576. timeline->track_lock.unlock();
  577. }
  578. void
  579. Track::menu_cb ( const Fl_Menu_ *m )
  580. {
  581. char picked[256];
  582. m->item_pathname( picked, sizeof( picked ) );
  583. DMESSAGE( "Picked: %s", picked );
  584. Logger log( this );
  585. if ( ! strcmp( picked, "Type/Mono" ) )
  586. {
  587. command_configure_channels( 1 );
  588. }
  589. else if ( ! strcmp( picked, "Type/Stereo" ) )
  590. {
  591. command_configure_channels( 2 );
  592. }
  593. else if ( ! strcmp( picked, "Type/Quad" ) )
  594. {
  595. command_configure_channels( 4 );
  596. }
  597. else if ( ! strcmp( picked, "Type/..." ) )
  598. {
  599. const char *s = fl_input( "How many channels?", "3" );
  600. if ( s )
  601. {
  602. int c = atoi( s );
  603. if ( c <= 0 || c > 10 )
  604. fl_alert( "Invalid number of channels." );
  605. else
  606. {
  607. command_configure_channels(c);
  608. }
  609. }
  610. }
  611. else if ( ! strcmp( picked, "/Add Control" ) )
  612. {
  613. /* add audio track */
  614. char *name = get_unique_control_name( "Control" );
  615. timeline->track_lock.wrlock();
  616. new Control_Sequence( this, name );
  617. timeline->track_lock.unlock();
  618. }
  619. else if ( ! strcmp( picked, "/Overlay controls" ) )
  620. {
  621. overlay_controls( ! m->mvalue()->value() );
  622. }
  623. else if ( ! strcmp( picked, "/Add Annotation" ) )
  624. {
  625. add( new Annotation_Sequence( this ) );
  626. }
  627. else if ( ! strcmp( picked, "/Color" ) )
  628. {
  629. unsigned char r, g, b;
  630. Fl::get_color( color(), r, g, b );
  631. if ( fl_color_chooser( "Track Color", r, g, b ) )
  632. {
  633. color( fl_rgb_color( r, g, b ) );
  634. }
  635. redraw();
  636. }
  637. else if ( ! strcmp( picked, "Flags/Record" ) )
  638. {
  639. armed( m->mvalue()->flags & FL_MENU_VALUE );
  640. }
  641. else if ( ! strcmp( picked, "Flags/Mute" ) )
  642. {
  643. mute( m->mvalue()->flags & FL_MENU_VALUE );
  644. }
  645. else if ( ! strcmp( picked, "Flags/Solo" ) )
  646. {
  647. solo( m->mvalue()->flags & FL_MENU_VALUE );
  648. }
  649. else if ( ! strcmp( picked, "Size/Small" ) )
  650. {
  651. size( 0 );
  652. }
  653. else if ( ! strcmp( picked, "Size/Medium" ) )
  654. {
  655. size( 1 );
  656. }
  657. else if ( ! strcmp( picked, "Size/Large" ) )
  658. {
  659. size( 2 );
  660. }
  661. else if ( ! strcmp( picked, "Size/Huge" ) )
  662. {
  663. size( 3 );
  664. }
  665. else if ( ! strcmp( picked, "Size/Enormous" ) )
  666. {
  667. size( 4 );
  668. }
  669. else if ( ! strcmp( picked, "/Remove" ) )
  670. {
  671. int r = fl_choice( "Are you certain you want to remove track \"%s\"?", "Cancel", NULL, "Remove", name() );
  672. if ( r == 2 )
  673. {
  674. timeline->command_remove_track( this );
  675. Fl::delete_widget( this );
  676. }
  677. }
  678. else if ( ! strcmp( picked, "/Rename" ) )
  679. {
  680. ((Fl_Sometimes_Input*)name_field)->take_focus();
  681. }
  682. else if ( ! strcmp( picked, "/Move Up" ) )
  683. {
  684. timeline->command_move_track_up( this );
  685. }
  686. else if ( ! strcmp( picked, "/Move Down" ) )
  687. {
  688. timeline->command_move_track_down( this );
  689. }
  690. else if ( !strcmp( picked, "Takes/Show all takes" ) )
  691. {
  692. show_all_takes( ! m->mvalue()->value() );
  693. }
  694. else if ( !strcmp( picked, "Takes/New" ) )
  695. {
  696. timeline->track_lock.wrlock();
  697. sequence( (Audio_Sequence*)sequence()->clone_empty() );
  698. timeline->track_lock.unlock();
  699. }
  700. else if ( !strcmp( picked, "Takes/Remove" ) )
  701. {
  702. if ( takes->children() )
  703. {
  704. Loggable::block_start();
  705. timeline->track_lock.wrlock();
  706. Audio_Sequence *s = sequence();
  707. sequence( (Audio_Sequence*)takes->child( 0 ) );
  708. delete s;
  709. timeline->track_lock.unlock();
  710. Loggable::block_end();
  711. }
  712. }
  713. else if ( !strcmp( picked, "Takes/Remove others" ))
  714. {
  715. if ( takes->children() )
  716. {
  717. Loggable::block_start();
  718. takes->clear();
  719. Loggable::block_end();
  720. }
  721. }
  722. else if ( !strncmp( picked, "Takes/", sizeof( "Takes/" ) - 1 ) )
  723. {
  724. Audio_Sequence* s = (Audio_Sequence*)m->mvalue()->user_data();
  725. timeline->track_lock.wrlock();
  726. sequence( s );
  727. timeline->track_lock.unlock();
  728. }
  729. }
  730. /** retrun a pointer to the control sequence named /name/, or NULL if no control sequence is named /name/ */
  731. Control_Sequence *
  732. Track::control_by_name ( const char *name )
  733. {
  734. for ( int i = control->children(); i-- ; )
  735. {
  736. Control_Sequence *t = (Control_Sequence*)control->child( i );
  737. if ( t->name() && name && ! strcmp( name, t->name() ) )
  738. return t;
  739. }
  740. return NULL;
  741. }
  742. /** return a malloc'd string representing a unique name for a new control sequence */
  743. char *
  744. Track::get_unique_control_name ( const char *name )
  745. {
  746. char pat[256];
  747. strcpy( pat, name );
  748. for ( int i = 1; control_by_name( pat ); ++i )
  749. snprintf( pat, sizeof( pat ), "%s.%d", name, i );
  750. return strdup( pat );
  751. }
  752. /** build the context menu */
  753. Fl_Menu_Button &
  754. Track::menu ( void ) const
  755. {
  756. int c = output.size();
  757. int s = size();
  758. _menu.clear();
  759. _menu.add( "Takes/Show all takes", 0, 0, 0, FL_MENU_TOGGLE | ( show_all_takes() ? FL_MENU_VALUE : 0 ) );
  760. _menu.add( "Takes/New", 0, 0, 0 );
  761. if ( takes->children() )
  762. {
  763. _menu.add( "Takes/Remove", 0, 0, 0 );
  764. _menu.add( "Takes/Remove others", 0, 0, 0, FL_MENU_DIVIDER );
  765. for ( int i = 0; i < takes->children(); ++i )
  766. {
  767. Sequence *s = (Sequence *)takes->child( i );
  768. char n[256];
  769. snprintf( n, sizeof(n), "Takes/%s", s->name() );
  770. _menu.add( n, 0, 0, s);
  771. }
  772. }
  773. _menu.add( "Type/Mono", 0, 0, 0, FL_MENU_RADIO | ( c == 1 ? FL_MENU_VALUE : 0 ) );
  774. _menu.add( "Type/Stereo", 0, 0, 0, FL_MENU_RADIO | ( c == 2 ? FL_MENU_VALUE : 0 ));
  775. _menu.add( "Type/Quad", 0, 0, 0, FL_MENU_RADIO | ( c == 4 ? FL_MENU_VALUE : 0 ) );
  776. _menu.add( "Type/...", 0, 0, 0, FL_MENU_RADIO | ( c == 3 || c > 4 ? FL_MENU_VALUE : 0 ) );
  777. _menu.add( "Overlay controls", 0, 0, 0, FL_MENU_TOGGLE | ( overlay_controls() ? FL_MENU_VALUE : 0 ) );
  778. _menu.add( "Add Control", 0, 0, 0 );
  779. _menu.add( "Add Annotation", 0, 0, 0 );
  780. _menu.add( "Color", 0, 0, 0 );
  781. _menu.add( "Rename", FL_CTRL + 'n', 0, 0 );
  782. _menu.add( "Size/Small", FL_ALT + '1', 0, 0, FL_MENU_RADIO | ( s == 0 ? FL_MENU_VALUE : 0 ) );
  783. _menu.add( "Size/Medium", FL_ALT + '2', 0, 0, FL_MENU_RADIO | ( s == 1 ? FL_MENU_VALUE : 0 ) );
  784. _menu.add( "Size/Large", FL_ALT + '3', 0, 0, FL_MENU_RADIO | ( s == 2 ? FL_MENU_VALUE : 0 ) );
  785. _menu.add( "Size/Huge", FL_ALT + '4', 0, 0, FL_MENU_RADIO | ( s == 3 ? FL_MENU_VALUE : 0 ) );
  786. _menu.add( "Size/Enormous", FL_ALT + '5', 0, 0, FL_MENU_RADIO | ( s == 4 ? FL_MENU_VALUE : 0 ) );
  787. _menu.add( "Flags/Record", FL_CTRL + 'r', 0, 0, FL_MENU_TOGGLE | ( armed() ? FL_MENU_VALUE : 0 ) );
  788. _menu.add( "Flags/Mute", FL_CTRL + 'm', 0, 0, FL_MENU_TOGGLE | ( mute() ? FL_MENU_VALUE : 0 ) );
  789. _menu.add( "Flags/Solo", FL_CTRL + 's', 0, 0, FL_MENU_TOGGLE | ( solo() ? FL_MENU_VALUE : 0 ) );
  790. _menu.add( "Move Up", FL_SHIFT + '1', 0, 0 );
  791. _menu.add( "Move Down", FL_SHIFT + '2', 0, 0 );
  792. _menu.add( "Remove", 0, 0, 0 ); // transport->rolling ? FL_MENU_INACTIVE : 0 );
  793. _menu.callback( &Track::menu_cb, (void*)this );
  794. return _menu;
  795. }
  796. #include "FL/event_name.H"
  797. #include "FL/test_press.H"
  798. static Fl_Widget *receptive_to_drop = NULL;
  799. void
  800. Track::draw ( void )
  801. {
  802. fl_push_clip( x(), y(), w(), h() );
  803. Fl_Color saved_color = color();
  804. if ( ! Track::colored_tracks )
  805. color( FL_GRAY );
  806. if ( _selected )
  807. {
  808. Fl_Color c = color();
  809. color( FL_RED );
  810. Fl_Group::draw();
  811. color( c );
  812. }
  813. else
  814. Fl_Group::draw();
  815. if ( ((Track_Header*)child(0))->input_connector_handle == receptive_to_drop )
  816. {
  817. Fl_Widget *o = ((Track_Header*)child(0))->input_connector_handle;
  818. fl_draw_box( FL_OVAL_BOX, o->x(), o->y(), o->w(), o->h(), fl_color_add_alpha( FL_GREEN, 127 ) );
  819. }
  820. if ( ! Track::colored_tracks )
  821. color( saved_color );
  822. fl_pop_clip();
  823. }
  824. int
  825. Track::handle ( int m )
  826. {
  827. /* if ( m != FL_NO_EVENT ) */
  828. /* DMESSAGE( "%s", event_name( m ) ); */
  829. static Fl_Widget *dragging = NULL;
  830. switch ( m )
  831. {
  832. case FL_DND_ENTER:
  833. case FL_DND_LEAVE:
  834. case FL_DND_DRAG:
  835. case FL_DND_RELEASE:
  836. case FL_PASTE:
  837. if ( Fl::event_x() > Track::width() )
  838. return sequence()->handle(m);
  839. default:
  840. break;
  841. }
  842. switch ( m )
  843. {
  844. case FL_KEYBOARD:
  845. {
  846. Fl_Menu_Button * men = &menu();
  847. if ( Fl::event_key() == FL_Menu )
  848. {
  849. menu_popup( men );
  850. return 1;
  851. }
  852. else
  853. return men->test_shortcut() || Fl_Group::handle( m );
  854. }
  855. case FL_MOUSEWHEEL:
  856. {
  857. Logger log( this );
  858. if ( ! Fl::event_alt() )
  859. return Fl_Group::handle( m );
  860. int d = Fl::event_dy();
  861. if ( d < 0 )
  862. size( size() - 1 );
  863. else
  864. size( size() + 1 );
  865. return 1;
  866. }
  867. case FL_PUSH:
  868. {
  869. if ( Fl::event_button1() && Fl::event_inside( ((Track_Header*)child(0))->color_box ) )
  870. {
  871. dragging = this;
  872. return 1;
  873. }
  874. if ( Fl::event_button1() && Fl::event_inside( ((Track_Header*)child(0))->output_connector_handle ) )
  875. return 1;
  876. Logger log( this );
  877. if ( Fl_Group::handle( m ) )
  878. return 1;
  879. if ( test_press( FL_BUTTON3 ) && Fl::event_x() < Track::width() )
  880. {
  881. menu_popup( &menu() );
  882. return 1;
  883. }
  884. return 0;
  885. }
  886. /* we have to prevent Fl_Group::handle() from getting these, otherwise it will mess up Fl::belowmouse() */
  887. case FL_ENTER:
  888. case FL_LEAVE:
  889. case FL_MOVE:
  890. if ( Fl::event_x() >= Track::width() )
  891. {
  892. return Fl_Group::handle(m);
  893. }
  894. return 1;
  895. case FL_DND_ENTER:
  896. return 1;
  897. case FL_DND_LEAVE:
  898. if ( ! Fl::event_inside(this) && this == receptive_to_drop )
  899. {
  900. receptive_to_drop = 0;
  901. redraw();
  902. Fl::selection_owner(0);
  903. }
  904. return 1;
  905. case FL_RELEASE:
  906. if ( dragging == this )
  907. {
  908. dragging = NULL;
  909. timeline->insert_track( this, timeline->event_inside() );
  910. return 1;
  911. }
  912. return Fl_Group::handle( m );
  913. break;
  914. case FL_DND_RELEASE:
  915. receptive_to_drop = 0;
  916. redraw();
  917. Fl::selection_owner(0);
  918. return 1;
  919. case FL_DND_DRAG:
  920. {
  921. if ( receptive_to_drop == ((Track_Header*)child(0))->input_connector_handle )
  922. return 1;
  923. if ( Fl::event_inside( ((Track_Header*)child(0))->input_connector_handle )
  924. && receptive_to_drop != ((Track_Header*)child(0))->input_connector_handle )
  925. {
  926. receptive_to_drop = ((Track_Header*)child(0))->input_connector_handle;
  927. redraw();
  928. return 1;
  929. }
  930. else
  931. {
  932. receptive_to_drop = NULL;
  933. redraw();
  934. return 0;
  935. }
  936. }
  937. case FL_PASTE:
  938. {
  939. receptive_to_drop = 0;
  940. redraw();
  941. if (! Fl::event_inside( ((Track_Header*)child(0))->input_connector_handle ) )
  942. return 0;
  943. /* NOW we get the text... */
  944. const char *text = Fl::event_text();
  945. DMESSAGE( "Got drop text \"%s\"",text);
  946. if ( strncmp( text, "jack.port://", strlen( "jack.port://" ) ) )
  947. {
  948. return 0;
  949. }
  950. std::vector<std::string> port_names;
  951. char *port_name;
  952. int end;
  953. while ( sscanf( text, "jack.port://%a[^\r\n]\r\n%n", &port_name, &end ) > 0 )
  954. {
  955. DMESSAGE( "Scanning %s", port_name );
  956. port_names.push_back( port_name );
  957. free(port_name );
  958. text += end;
  959. }
  960. for ( unsigned int i = 0; i < input.size() && i < port_names.size(); i++)
  961. {
  962. const char *pn = port_names[i].c_str();
  963. JACK::Port *ji = &input[i];
  964. if ( ji->connected_to( pn ) )
  965. {
  966. DMESSAGE( "Disconnecting from \"%s\"", pn );
  967. ji->disconnect( pn );
  968. }
  969. else
  970. {
  971. DMESSAGE( "Connecting to %s", pn );
  972. ji->connect( pn );
  973. }
  974. }
  975. Fl::selection_owner(0);
  976. return 1;
  977. }
  978. case FL_DRAG:
  979. {
  980. if ( this != Fl::selection_owner() &&
  981. Fl::event_inside( ((Track_Header*)child(0))->output_connector_handle ) )
  982. {
  983. char *s = (char*)malloc(256);
  984. s[0] = 0;
  985. for ( unsigned int i = 0; i < output.size(); ++i )
  986. {
  987. char *s2;
  988. asprintf(&s2, "jack.port://%s:%s\r\n", instance_name, output[i].name() );
  989. s = (char*)realloc( s, strlen( s ) + strlen( s2 ) + 1 );
  990. strcat( s, s2 );
  991. free( s2 );
  992. }
  993. Fl::copy(s, strlen(s) + 1, 0);
  994. Fl::selection_owner(this);
  995. free( s );
  996. Fl::dnd();
  997. return 1;
  998. }
  999. else
  1000. {
  1001. return 1;
  1002. }
  1003. }
  1004. default:
  1005. return Fl_Group::handle( m );
  1006. }
  1007. return 0;
  1008. }
  1009. void
  1010. Track::connect_osc ( void )
  1011. {
  1012. for ( int j = control->children(); j--; )
  1013. {
  1014. Control_Sequence *c = (Control_Sequence*)control->child( j );
  1015. c->connect_osc();
  1016. }
  1017. }
  1018. void
  1019. Track::update_osc_connection_state ( void )
  1020. {
  1021. for ( int j = control->children(); j--; )
  1022. {
  1023. Control_Sequence *c = (Control_Sequence*)control->child( j );
  1024. c->update_osc_connection_state();
  1025. }
  1026. }
  1027. void
  1028. Track::process_osc ( void )
  1029. {
  1030. for ( int j = control->children(); j--; )
  1031. {
  1032. Control_Sequence *c = (Control_Sequence*)control->child( j );
  1033. c->process_osc();
  1034. }
  1035. }