From 43e561982b436f4594d11543cdfe9b0d5300b48f Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Wed, 28 May 2008 20:31:06 -0500 Subject: [PATCH] Work on timeline menu actions. --- Timeline/Sequence.C | 4 ++-- Timeline/Sequence_Region.C | 10 +++++---- Timeline/Timeline.C | 46 ++++++++++++++++++++++++++++++-------- Timeline/Timeline.H | 2 +- 4 files changed, 46 insertions(+), 16 deletions(-) diff --git a/Timeline/Sequence.C b/Timeline/Sequence.C index d342d3f..12149a9 100644 --- a/Timeline/Sequence.C +++ b/Timeline/Sequence.C @@ -291,10 +291,10 @@ Sequence::snap ( Sequence_Widget *r ) } } - nframes_t f; + nframes_t f = r->start(); /* snap to beat/bar lines */ - if ( timeline->nearest_line( r->start(), &f ) ) + if ( timeline->nearest_line( &f ) ) r->start( f ); } diff --git a/Timeline/Sequence_Region.C b/Timeline/Sequence_Region.C index 0af0e4d..c9efb59 100644 --- a/Timeline/Sequence_Region.C +++ b/Timeline/Sequence_Region.C @@ -92,9 +92,10 @@ Sequence_Region::trim ( enum trim_e t, int X ) _r->trim_left( 0 - td ); - nframes_t f; + nframes_t f = _r->start; + /* snap to beat/bar lines */ - if ( timeline->nearest_line( _r->start, &f ) ) + if ( timeline->nearest_line( &f ) ) _r->set_left( f ); break; @@ -114,9 +115,10 @@ Sequence_Region::trim ( enum trim_e t, int X ) _r->trim_right( 0 - td ); - nframes_t f; + nframes_t f = _r->start + _r->length; + /* snap to beat/bar lines */ - if ( timeline->nearest_line( _r->start + _r->length, &f ) ) + if ( timeline->nearest_line( &f ) ) _r->set_right( f ); break; diff --git a/Timeline/Timeline.C b/Timeline/Timeline.C index c3aeada..007d77e 100644 --- a/Timeline/Timeline.C +++ b/Timeline/Timeline.C @@ -208,12 +208,12 @@ Timeline::menu_cb ( Fl_Widget *w ) } else if ( ! strcmp( picked, "Playhead to mouse" ) ) { - int X = Fl::event_x() - Track::width(); + int X = Fl::event_x() - Track::width(); - if ( X > 0 ) - { - transport->locate( xoffset + x_to_ts( X ) ); - } + if ( X > 0 ) + { + transport->locate( xoffset + x_to_ts( X ) ); + } } else if ( ! strcmp( picked, "P1 to mouse" ) ) { @@ -222,7 +222,7 @@ Timeline::menu_cb ( Fl_Widget *w ) if ( X > 0 ) { p1 = xoffset + x_to_ts( X ); - } + } /* FIXME: only needs to damage the location of the old cursor! */ redraw(); @@ -239,6 +239,24 @@ Timeline::menu_cb ( Fl_Widget *w ) /* FIXME: only needs to damage the location of the old cursor! */ redraw(); } + else if ( ! strcmp( picked, "Playhead left" ) ) + { +#warning unimplemented + } + else if ( ! strcmp( picked, "Playhead right" ) ) + { +#warning unimplemented + } + else if ( ! strcmp( picked, "Swap P1 and playhead" ) ) + { + nframes_t t = transport->frame; + + transport->locate( p1 ); + + p1 = t; + + redraw(); + } else WARNING( "programming error: Unknown menu item" ); } @@ -267,6 +285,9 @@ Timeline::Timeline ( int X, int Y, int W, int H, const char* L ) : Fl_Overlay_Wi menu->add( "Playhead to mouse", 'p', &Timeline::menu_cb, this ); menu->add( "P1 to mouse", '[', &Timeline::menu_cb, this ); menu->add( "P2 to mouse", ']', &Timeline::menu_cb, this ); + menu->add( "Playhead left", FL_CTRL + FL_Up, &Timeline::menu_cb, this ); + menu->add( "Playhead right", FL_CTRL + FL_Down, &Timeline::menu_cb, this ); + menu->add( "Swap P1 and playhead", FL_CTRL + '[', &Timeline::menu_cb, this ); { Scalebar *o = new Scalebar( X, Y + H - 18, W - 18, 18 ); @@ -441,17 +462,24 @@ nearest_line_cb ( nframes_t frame, const BBT &bbt, void *arg ) the nearest measure line to /when/. Returns true if the new value of *frame is valid, false otherwise. */ bool -Timeline::nearest_line ( nframes_t when, nframes_t *frame ) const +Timeline::nearest_line ( nframes_t *frame ) const { if ( snap_to == None ) return false; + nframes_t when = *frame; + nearest_line_arg n = { when, -1 }; render_tempomap( when - x_to_ts( w() >> 1 ), x_to_ts( w() ), nearest_line_cb, &n ); - *frame = n.closest; - return *frame != (nframes_t)-1; + if ( n.closest == (nframes_t)-1 ) + return false; + else + { + *frame = n.closest; + return true; + } } diff --git a/Timeline/Timeline.H b/Timeline/Timeline.H index ed99bae..cdf9be9 100644 --- a/Timeline/Timeline.H +++ b/Timeline/Timeline.H @@ -154,7 +154,7 @@ public: int beats_per_bar ( nframes_t when ) const; void beats_per_minute ( nframes_t when, float bpm ); void time ( nframes_t when, int bpb, int beat_type ); - bool nearest_line ( nframes_t when, nframes_t *f ) const; + bool nearest_line ( nframes_t *f ) const; typedef void (measure_line_callback)( nframes_t frame, const BBT & bbt, void *arg );