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.

941 lines
22KB

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