Make timeline 'length' dynamic.

This commit is contained in:
Jonathan Moore Liles 2008-05-27 18:47:47 -05:00
parent f0b0c455c7
commit c8eb82d124
8 changed files with 66 additions and 7 deletions

View File

@ -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 */

View File

@ -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 )
{

View File

@ -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 );

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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 )
{

View File

@ -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; }