From 99937affb9beb5455a6906ba52537472b0ca9609 Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Thu, 22 Jan 2009 22:47:55 -0600 Subject: [PATCH] Clean up region trimming code. --- Timeline/Sequence_Region.C | 83 +++++++++++++++++--------------------- Timeline/Sequence_Region.H | 3 ++ 2 files changed, 40 insertions(+), 46 deletions(-) diff --git a/Timeline/Sequence_Region.C b/Timeline/Sequence_Region.C index 67584f6..b73822a 100644 --- a/Timeline/Sequence_Region.C +++ b/Timeline/Sequence_Region.C @@ -66,70 +66,61 @@ Sequence_Region::set ( Log_Entry &e ) } void -Sequence_Region::trim ( enum trim_e t, int X ) +Sequence_Region::trim_left ( nframes_t where ) { + long td = where - _r->start; - X -= sequence()->x(); - redraw(); - - switch ( t ) - { - case LEFT: - { -/* if ( d < 0 ) */ -/* // _track->damage( FL_DAMAGE_EXPOSE, x() + d, y(), 1 - d, h() ); */ -/* _track->damage( FL_DAMAGE_EXPOSE, x(), y(), w(), h() ); */ -/* else */ -/* _track->damage( FL_DAMAGE_EXPOSE, x(), y(), d, h() ); */ - - int d = X - ( abs_x() - scroll_x() ); + if ( td < 0 && _r->offset < (nframes_t)( 0 - td ) ) + td = 0 - _r->offset; - long td = timeline->x_to_ts( d ); + if ( td > 0 && (nframes_t)td >= _r->length ) + td = _r->length - timeline->x_to_ts( 1 ); - if ( td < 0 && _r->offset < (nframes_t)( 0 - td ) ) - td = 0 - _r->offset; + _r->trim_left( 0 - td ); - if ( td > 0 && (nframes_t)td >= _r->length ) - td = _r->length - timeline->x_to_ts( 1 ); + nframes_t f = _r->start; -// td = _r->length - timeline->x_to_ts( 1 ); + /* snap to beat/bar lines */ + if ( timeline->nearest_line( &f ) ) + _r->set_left( f ); - _r->trim_left( 0 - td ); - - nframes_t f = _r->start; - - /* snap to beat/bar lines */ - if ( timeline->nearest_line( &f ) ) - _r->set_left( f ); +} - break; - } - case RIGHT: - { - int d = (( abs_x() - scroll_x() ) + abs_w() ) - X; +void +Sequence_Region::trim_right ( nframes_t where ) +{ + long td = ( _r->start + _r->length ) - where; -/* _track->damage( FL_DAMAGE_EXPOSE, x() + w(), y(), d, h() ); */ + if ( td >= 0 && _r->length < (nframes_t)td ) + td = _r->length - timeline->x_to_ts( 1 ); - long td = timeline->x_to_ts( d ); + _r->trim_right( 0 - td ); -// printf( "%li %li\n", td, _r->length - _r->offset ); + nframes_t f = _r->start + _r->length; - if ( td >= 0 && _r->length < (nframes_t)td ) - td = _r->length - timeline->x_to_ts( 1 ); + /* snap to beat/bar lines */ + if ( timeline->nearest_line( &f ) ) + _r->set_right( f ); - _r->trim_right( 0 - td ); +} - nframes_t f = _r->start + _r->length; +void +Sequence_Region::trim ( enum trim_e t, int X ) +{ + redraw(); - /* snap to beat/bar lines */ - if ( timeline->nearest_line( &f ) ) - _r->set_right( f ); + nframes_t where = timeline->x_to_offset( X ); + switch ( t ) + { + case LEFT: + trim_left( where ); + break; + case RIGHT: + trim_right( where ); break; - } default: - return; - + break; } } diff --git a/Timeline/Sequence_Region.H b/Timeline/Sequence_Region.H index 10d144a..c09dbbd 100644 --- a/Timeline/Sequence_Region.H +++ b/Timeline/Sequence_Region.H @@ -45,6 +45,9 @@ public: LOG_NAME_FUNC( Region ); + void trim_right ( nframes_t where ); + void trim_left ( nframes_t where ); + enum trim_e { NO, LEFT, RIGHT }; void trim ( enum trim_e t, int X );