From 99795a4f56198729f04279c14eafb76d544bc5b2 Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Mon, 12 May 2008 11:23:55 -0500 Subject: [PATCH] Move range trimming math into Range class. --- Timeline/Sequence_Region.C | 11 +++++------ Timeline/Sequence_Widget.H | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/Timeline/Sequence_Region.C b/Timeline/Sequence_Region.C index a489259..eaac0e8 100644 --- a/Timeline/Sequence_Region.C +++ b/Timeline/Sequence_Region.C @@ -90,9 +90,8 @@ Sequence_Region::trim ( enum trim_e t, int X ) // td = _r->length - timeline->x_to_ts( 1 ); - _r->offset += td; - _r->start += td; - _r->length -= td; + _r->trim_left( 0 - td ); + break; } case RIGHT: @@ -106,9 +105,9 @@ Sequence_Region::trim ( enum trim_e t, int X ) // printf( "%li %li\n", td, _r->length - _r->offset ); if ( td >= 0 && _r->length < (nframes_t)td ) - _r->length = timeline->x_to_ts( 1 ); - else - _r->length -= td; + td = _r->length - timeline->x_to_ts( 1 ); + + _r->trim_right( 0 - td ); break; } diff --git a/Timeline/Sequence_Widget.H b/Timeline/Sequence_Widget.H index 0946dfe..ca3306e 100644 --- a/Timeline/Sequence_Widget.H +++ b/Timeline/Sequence_Widget.H @@ -40,13 +40,40 @@ struct Drag Drag( int X, int Y, nframes_t start=0 ) : x( X ), y( Y ), start( start ) { state = 0; } }; +/* most common position description. /offset/ is only used by Regions, +but it's more convenient to have it here */ struct Range { nframes_t start; /* where on the timeline */ nframes_t offset; /* first sample from clip */ nframes_t length; /* total number of samples */ + + void + trim_left ( long n ) + { + start -= n; + offset -= n; + length += n; + } + + void + trim_right ( long n ) + { + length += n; + } }; +/* Used by time/tempo points or any other child of Sequence_Widget + which must be locked to a point in musical time rather than wallclock + time. Bar and beat start at 1. */ +struct BBT +{ + unsigned short bar; + unsigned char beat; + unsigned short tick; +}; + + /* Base class for virtual widget on a track */ class Sequence_Widget : public Loggable {