From 91614d9aa16206d6f6131cee5d4ed165f7912aca Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Sat, 17 May 2008 00:14:26 -0500 Subject: [PATCH] Snap trims as well. --- Timeline/Audio_Region.C | 4 ++-- Timeline/Sequence_Region.C | 10 ++++++++++ Timeline/Sequence_Widget.H | 14 ++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Timeline/Audio_Region.C b/Timeline/Audio_Region.C index 017e490..a77e501 100644 --- a/Timeline/Audio_Region.C +++ b/Timeline/Audio_Region.C @@ -865,6 +865,8 @@ Audio_Region::write ( nframes_t nframes ) bool Audio_Region::finalize ( nframes_t frame ) { + _range.length = frame - _range.start; + log_end(); _clip->close(); @@ -872,8 +874,6 @@ Audio_Region::finalize ( nframes_t frame ) /* FIXME: should we attempt to truncate the file? */ - _range.length = frame - _range.start; - redraw(); return true; diff --git a/Timeline/Sequence_Region.C b/Timeline/Sequence_Region.C index eaac0e8..2835ea9 100644 --- a/Timeline/Sequence_Region.C +++ b/Timeline/Sequence_Region.C @@ -92,6 +92,11 @@ Sequence_Region::trim ( enum trim_e t, int X ) _r->trim_left( 0 - td ); + nframes_t f; + /* snap to beat/bar lines */ + if ( timeline->nearest_line( _r->start, &f ) ) + _r->set_left( f ); + break; } case RIGHT: @@ -109,6 +114,11 @@ Sequence_Region::trim ( enum trim_e t, int X ) _r->trim_right( 0 - td ); + nframes_t f; + /* snap to beat/bar lines */ + if ( timeline->nearest_line( _r->start + _r->length, &f ) ) + _r->set_right( f ); + break; } default: diff --git a/Timeline/Sequence_Widget.H b/Timeline/Sequence_Widget.H index c0bc0dd..91e0711 100644 --- a/Timeline/Sequence_Widget.H +++ b/Timeline/Sequence_Widget.H @@ -62,6 +62,20 @@ struct Range length += n; } + void + set_left ( nframes_t f ) + { + offset += f - start; + length -= f - start; + start = f; + } + + void + set_right ( nframes_t f ) + { + length = f - start; + } + Range ( ) : start( 0 ), offset( 0 ), length( 0 ) { }