From b17623720e2d19d5d02dbcdb2f44315ab4a98406 Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Thu, 29 May 2008 15:54:05 -0500 Subject: [PATCH] Change the way project length is calculated. --- Timeline/Sequence.C | 27 ++++++++--------- Timeline/Sequence_Widget.C | 2 +- Timeline/Timeline.C | 61 +++++++++++++++++--------------------- Timeline/Timeline.H | 8 ++--- 4 files changed, 46 insertions(+), 52 deletions(-) diff --git a/Timeline/Sequence.C b/Timeline/Sequence.C index 801c3fd..b1a6ba6 100644 --- a/Timeline/Sequence.C +++ b/Timeline/Sequence.C @@ -181,28 +181,27 @@ Sequence::remove_selected ( void ) void Sequence::handle_widget_change ( nframes_t start, nframes_t length ) { - timeline->update_length( start + 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 +{ + nframes_t l = 0; -/* /\** calculate the length of this sequence by looking at the end of the */ -/* * least widget it contains *\/ */ -/* nframes_t */ -/* Sequence::length ( void ) const */ -/* { */ + for ( list ::const_iterator r = _widgets.begin(); r != _widgets.end(); ++r ) + l = max( l, (*r)->start() + (*r)->length() ); -/* if ( _widgets.size() ) */ -/* return _widgets.back().start() + _widgets.back().length(); */ -/* else */ -/* return 0; */ - -/* } */ + return l; +} Sequence_Widget * Sequence::event_widget ( void ) { nframes_t ets = timeline->xoffset + timeline->x_to_ts( Fl::event_x() - x() ); - for ( list ::const_reverse_iterator r = _widgets.rbegin(); r != _widgets.rend(); r++ ) + for ( list ::const_reverse_iterator r = _widgets.rbegin(); r != _widgets.rend(); ++r ) if ( ets > (*r)->start() && ets < (*r)->start() + (*r)->length() && Fl::event_y() >= (*r)->y() && Fl::event_y() <= (*r)->y() + (*r)->h() ) return (*r); @@ -216,7 +215,7 @@ Sequence::select_range ( int X, int W ) nframes_t sts = x_to_offset( X ); nframes_t ets = sts + timeline->x_to_ts( W ); - for ( list ::const_reverse_iterator r = _widgets.rbegin(); r != _widgets.rend(); r++ ) + for ( list ::const_reverse_iterator r = _widgets.rbegin(); r != _widgets.rend(); ++r ) if ( ! ( (*r)->start() > ets || (*r)->start() + (*r)->length() < sts ) ) (*r)->select(); } diff --git a/Timeline/Sequence_Widget.C b/Timeline/Sequence_Widget.C index d474517..a3d8a0f 100644 --- a/Timeline/Sequence_Widget.C +++ b/Timeline/Sequence_Widget.C @@ -413,7 +413,7 @@ Sequence_Widget::handle ( int m ) timeline->xposition( timeline->ts_to_x( pos ) ); - timeline->update_length( start() + length() ); +// timeline->update_length( start() + length() ); /* FIXME: why isn't this enough? */ // sequence()->redraw(); diff --git a/Timeline/Timeline.C b/Timeline/Timeline.C index 4cec1c8..b8846ac 100644 --- a/Timeline/Timeline.C +++ b/Timeline/Timeline.C @@ -110,7 +110,7 @@ Timeline::adjust_vscroll ( void ) void Timeline::adjust_hscroll ( void ) { - hscroll->value( ts_to_x( xoffset ), tracks->w() - Track::width(), 0, ts_to_x( _length ) ); + hscroll->value( ts_to_x( xoffset ), tracks->w() - Track::width(), 0, ts_to_x( length() ) ); } void @@ -140,10 +140,10 @@ Timeline::cb_scroll ( Fl_Widget *w ) _fpp = hscroll->zoom(); const int tw = tracks->w() - Track::width(); -// hscroll->value( ts_to_x( xoffset ), tw, 0, ts_to_x( _length ) ); +// 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 ) ); + tw, 0, ts_to_x( length() ) ); redraw(); } @@ -358,10 +358,10 @@ 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; +// length() = sample_rate() * 60 * 2; /* FIXME: hack */ - _length = x_to_ts( W ); +// length() = x_to_ts( W ); { Fl_Pack *o = new Fl_Pack( X, rulers->y() + rulers->h(), W - vscroll->w(), 1 ); @@ -678,7 +678,7 @@ 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() ); */ +/* X = min( X, ts_to_x( length() ) - tracks->w() - Track::width() ); */ xoffset = x_to_ts( X ); @@ -729,6 +729,16 @@ Timeline::resize ( int X, int Y, int W, int H ) vscroll->size( vscroll->w(), H - 18 ); } +void +Timeline::draw_cursors ( void ) const +{ + if ( p1 != p2 ) + { + draw_cursor( p1, FL_BLUE, draw_full_arrow_symbol ); + draw_cursor( p2, FL_GREEN, draw_full_arrow_symbol ); + } +} + void Timeline::draw ( void ) { @@ -761,12 +771,7 @@ Timeline::draw ( void ) draw_child( *hscroll ); draw_child( *vscroll ); - - if ( p1 != p2 ) - { - draw_cursor( p1, FL_BLUE, draw_full_arrow_symbol ); - draw_cursor( p2, FL_GREEN, draw_full_arrow_symbol ); - } + draw_cursors(); redraw_overlay(); @@ -805,12 +810,8 @@ Timeline::draw ( void ) update_child( *hscroll ); update_child( *vscroll ); + draw_cursors(); - if ( p1 != p2 ) - { - draw_cursor( p1, FL_BLUE, draw_full_arrow_symbol ); - draw_cursor( p2, FL_GREEN, draw_full_arrow_symbol ); - } } done: @@ -823,7 +824,7 @@ done: void -Timeline::draw_cursor ( nframes_t frame, Fl_Color color, void (*symbol)(Fl_Color) ) +Timeline::draw_cursor ( nframes_t frame, Fl_Color color, void (*symbol)(Fl_Color) ) const { // int x = ( ts_to_x( frame ) - ts_to_x( xoffset ) ) + tracks->x() + Track::width(); @@ -869,6 +870,7 @@ void Timeline::draw_playhead ( void ) { draw_cursor( transport->frame, FL_RED, draw_full_arrow_symbol ); + draw_cursor( length(), FL_BLACK, draw_full_arrow_symbol ); } void @@ -994,24 +996,17 @@ Timeline::handle_scroll ( int m ) return 0; } -void -Timeline::update_length ( nframes_t l ) +nframes_t +Timeline::length ( void ) const { - _length = max( _length, l ); + nframes_t l = 0; - adjust_hscroll(); + for ( int i = tracks->children(); i--; ) + l = max( l, ((Track*)tracks->child( i ))->sequence()->length() ); -/* nframes_t l = 0; */ - -/* for ( int i = tracks->children(); i-- ; ) */ -/* { */ -/* Track *t = (Track*)tracks->child( i ); */ - -/* l = max( l, t->sequence()->length() ); */ -/* } */ - -/* _length = l; */ +// adjust_hscroll(); + return l; } int @@ -1200,7 +1195,7 @@ Timeline::zoom ( float secs ) void Timeline::zoom_fit ( void ) { - zoom( _length / (float)sample_rate() ); + zoom( length() / (float)sample_rate() ); } Track * diff --git a/Timeline/Timeline.H b/Timeline/Timeline.H index 82cf57f..a08af26 100644 --- a/Timeline/Timeline.H +++ b/Timeline/Timeline.H @@ -103,7 +103,6 @@ class Timeline : public Fl_Overlay_Window, public RWLock void menu_cb ( Fl_Menu_ *m ); int _fpp; /* frames per pixel, power of two */ - nframes_t _length; nframes_t p1, p2; /* cursors */ @@ -144,8 +143,8 @@ public: void update_tempomap ( void ); nframes_t fpp ( void ) const { return 1 << _fpp; } - nframes_t length ( void ) const { return _length; } - void update_length ( nframes_t l ); + + nframes_t length ( void ) const; 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; } @@ -166,7 +165,8 @@ public: void xposition ( int X ); void yposition ( int Y ); - void draw_cursor ( nframes_t frame, Fl_Color color, void (*symbol)(Fl_Color) ); + void draw_cursor ( nframes_t frame, Fl_Color color, void (*symbol)(Fl_Color) ) const; + void draw_cursors ( void ) const; void draw_playhead ( void ); void redraw_playhead ( void ); void resize ( int X, int Y, int W, int H );