From e5dc8928dcc3a26bbd878d85682e9dbc1fd6f492 Mon Sep 17 00:00:00 2001 From: James Crook Date: Mon, 2 Mar 2020 18:07:34 +0000 Subject: [PATCH] Bug 2288 - Audio clips may overlap --- src/WaveClip.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/WaveClip.cpp b/src/WaveClip.cpp index 8c5a6e9d7..32e0d008c 100644 --- a/src/WaveClip.cpp +++ b/src/WaveClip.cpp @@ -451,10 +451,15 @@ sampleCount WaveClip::GetNumSamples() const return mSequence->GetNumSamples(); } +// Bug 2288 allowed overlapping clips. +// This was a classic fencepost error. +// We are within the clip if start < t <= end. +// Note that BeforeClip and AfterClip must be consistent +// with this definition. bool WaveClip::WithinClip(double t) const { auto ts = (sampleCount)floor(t * mRate + 0.5); - return ts > GetStartSample() && ts < GetEndSample() + mAppendBufferLen; + return ts > GetStartSample() && ts <= GetEndSample() + mAppendBufferLen; } bool WaveClip::BeforeClip(double t) const @@ -466,7 +471,7 @@ bool WaveClip::BeforeClip(double t) const bool WaveClip::AfterClip(double t) const { auto ts = (sampleCount)floor(t * mRate + 0.5); - return ts >= GetEndSample() + mAppendBufferLen; + return ts > GetEndSample() + mAppendBufferLen; } ///Delete the wave cache - force redraw. Thread-safe