diff --git a/Timeline/Audio_Sequence.C b/Timeline/Audio_Sequence.C index 5f77598..d590db4 100644 --- a/Timeline/Audio_Sequence.C +++ b/Timeline/Audio_Sequence.C @@ -126,6 +126,8 @@ deurlify ( char *url ) void Audio_Sequence::handle_widget_change ( nframes_t start, nframes_t length ) { + Sequence::handle_widget_change( start, length ); + /* a region has changed. we may need to rebuffer... */ /* trigger rebuffer */ diff --git a/Timeline/Sequence.C b/Timeline/Sequence.C index a5e81f6..1c4c0e6 100644 --- a/Timeline/Sequence.C +++ b/Timeline/Sequence.C @@ -176,6 +176,26 @@ Sequence::remove_selected ( void ) } +void +Sequence::handle_widget_change ( nframes_t start, nframes_t length ) +{ + timeline->update_length( start + length ); +} + + +/* /\** calculate the length of this sequence by looking at the end of the */ +/* * least widget it contains *\/ */ +/* nframes_t */ +/* Sequence::length ( void ) const */ +/* { */ + +/* if ( _widgets.size() ) */ +/* return _widgets.back().start() + _widgets.back().length(); */ +/* else */ +/* return 0; */ + +/* } */ + Sequence_Widget * Sequence::event_widget ( void ) { diff --git a/Timeline/Sequence.H b/Timeline/Sequence.H index 0b1a0e6..daf84c9 100644 --- a/Timeline/Sequence.H +++ b/Timeline/Sequence.H @@ -67,7 +67,7 @@ public: /* child classes should implement this if they need to take special action when a widget is changed/moved/resized. /start/ and /length/ define the affected region */ - virtual void handle_widget_change ( nframes_t start, nframes_t length ) { (void)(start + length); } + virtual void handle_widget_change ( nframes_t start, nframes_t length ); /* welcome to C++ */ LOG_NAME_FUNC( Sequence ); @@ -115,6 +115,8 @@ public: Sequence_Widget * overlaps ( Sequence_Widget *r ); + nframes_t length ( void ) const; + virtual Sequence * clone ( void ) { assert( 0 ); diff --git a/Timeline/Sequence_Widget.C b/Timeline/Sequence_Widget.C index f70c0dc..6db33cf 100644 --- a/Timeline/Sequence_Widget.C +++ b/Timeline/Sequence_Widget.C @@ -384,6 +384,8 @@ Sequence_Widget::handle ( int m ) timeline->xposition( timeline->ts_to_x( pos ) ); + timeline->update_length( start() + length() ); + /* FIXME: why isn't this enough? */ // sequence()->redraw(); timeline->redraw(); diff --git a/Timeline/Tempo_Sequence.C b/Timeline/Tempo_Sequence.C index ecacd8c..0f98e28 100644 --- a/Timeline/Tempo_Sequence.C +++ b/Timeline/Tempo_Sequence.C @@ -20,8 +20,10 @@ #include "Tempo_Sequence.H" void -Tempo_Sequence::handle_widget_change ( nframes_t, nframes_t ) +Tempo_Sequence::handle_widget_change ( nframes_t start, nframes_t length ) { + Sequence::handle_widget_change( start, length ); + sort(); timeline->update_tempomap(); timeline->redraw(); diff --git a/Timeline/Time_Sequence.C b/Timeline/Time_Sequence.C index 712b473..0907a16 100644 --- a/Timeline/Time_Sequence.C +++ b/Timeline/Time_Sequence.C @@ -20,8 +20,10 @@ #include "Time_Sequence.H" void -Time_Sequence::handle_widget_change ( nframes_t, nframes_t ) +Time_Sequence::handle_widget_change ( nframes_t start, nframes_t length ) { + Sequence::handle_widget_change( start, length ); + sort(); timeline->update_tempomap(); timeline->redraw(); diff --git a/Timeline/Timeline.C b/Timeline/Timeline.C index 95cc874..c3aeada 100644 --- a/Timeline/Timeline.C +++ b/Timeline/Timeline.C @@ -107,6 +107,12 @@ Timeline::adjust_vscroll ( void ) vscroll->value( _yposition, h() - rulers->h() - hscroll->h(), 0, pack_visible_height( tracks ) ); } +void +Timeline::adjust_hscroll ( void ) +{ + hscroll->value( ts_to_x( xoffset ), tracks->w() - Track::width(), 0, ts_to_x( _length ) ); +} + void Timeline::cb_scroll ( Fl_Widget *w, void *v ) { @@ -135,6 +141,7 @@ Timeline::cb_scroll ( Fl_Widget *w ) const int tw = tracks->w() - Track::width(); // hscroll->value( ts_to_x( xoffset ), tw, 0, ts_to_x( _length ) ); + hscroll->value( max( 0, ts_to_x( under_mouse ) - ( Fl::event_x() - tracks->x() - Track::width() ) ), tw, 0, ts_to_x( _length ) ); @@ -333,8 +340,9 @@ Timeline::Timeline ( int X, int Y, int W, int H, const char* L ) : Fl_Overlay_Wi // sample_rate() = engine->sample_rate(); _fpp = 8; // _length = sample_rate() * 60 * 2; + /* FIXME: hack */ - _length = -1; + _length = x_to_ts( W ); { Fl_Pack *o = new Fl_Pack( X, rulers->y() + rulers->h(), W - vscroll->w(), 1 ); @@ -643,8 +651,8 @@ Timeline::xposition ( int X ) { // _old_xposition = xoffset; - /* FIXME: shouldn't have to do this... */ - X = min( X, ts_to_x( _length ) - tracks->w() - Track::width() ); +/* /\* FIXME: shouldn't have to do this... *\/ */ +/* X = min( X, ts_to_x( _length ) - tracks->w() - Track::width() ); */ xoffset = x_to_ts( X ); @@ -960,6 +968,26 @@ Timeline::handle_scroll ( int m ) return 0; } +void +Timeline::update_length ( nframes_t l ) +{ + _length = max( _length, l ); + + adjust_hscroll(); + +/* nframes_t l = 0; */ + +/* for ( int i = tracks->children(); i-- ; ) */ +/* { */ +/* Track *t = (Track*)tracks->child( i ); */ + +/* l = max( l, t->sequence()->length() ); */ +/* } */ + +/* _length = l; */ + +} + int Timeline::handle ( int m ) { diff --git a/Timeline/Timeline.H b/Timeline/Timeline.H index dfd1eae..ed99bae 100644 --- a/Timeline/Timeline.H +++ b/Timeline/Timeline.H @@ -95,6 +95,7 @@ class Timeline : public Fl_Overlay_Window, public RWLock Fl_Scrollbar *vscroll; void adjust_vscroll ( void ); + void adjust_hscroll ( void ); static void cb_scroll ( Fl_Widget *w, void *v ); void cb_scroll ( Fl_Widget *w ); static void menu_cb ( Fl_Widget *w, void *v ); @@ -103,7 +104,6 @@ class Timeline : public Fl_Overlay_Window, public RWLock int _fpp; /* frames per pixel, power of two */ nframes_t _length; - nframes_t p1, p2; /* cursors */ /* not permitted */ @@ -144,6 +144,7 @@ public: nframes_t fpp ( void ) const { return 1 << _fpp; } nframes_t length ( void ) const { return _length; } + void update_length ( nframes_t l ); nframes_t sample_rate ( void ) const { return _sample_rate; } int ts_to_x( nframes_t ts ) const { return ts >> _fpp; } nframes_t x_to_ts ( int x ) const { return x << _fpp; }