diff --git a/src/Envelope.cpp b/src/Envelope.cpp index 2d702cb8a..24aa15daf 100644 --- a/src/Envelope.cpp +++ b/src/Envelope.cpp @@ -754,7 +754,7 @@ void Envelope::CollapseRegion( double t0, double t1, double sampleDur ) // envelope point applies to the first sample, but the t=tracklen // envelope point applies one-past the last actual sample. // t0 should be in the domain of this; if not, it is trimmed. -void Envelope::Paste( double t0, const Envelope *e, double sampleDur ) +void Envelope::PasteEnvelope( double t0, const Envelope *e, double sampleDur ) // NOFAIL-GUARANTEE { const bool wasEmpty = (this->mEnv.size() == 0); @@ -774,7 +774,8 @@ void Envelope::Paste( double t0, const Envelope *e, double sampleDur ) return; } - // Make t0 relative and trim it to the domain of this + // Make t0 relative to the offset of the envelope we are pasting into, + // and trim it to the domain of this t0 = std::min( mTrackLen, std::max( 0.0, t0 - mOffset ) ); // Adjust if the insertion point rounds off near a discontinuity in this @@ -812,7 +813,13 @@ void Envelope::Paste( double t0, const Envelope *e, double sampleDur ) for ( size_t index = insertAt, last = insertAt + otherSize; index < last; ++index ) { auto &point = mEnv[ index ]; - point.SetT( point.GetT() + otherOffset + t0 ); + // The mOffset of the envelope-pasted-from is irrelevant. + // The GetT() times in it are relative to its start. + // The new GetT() times are relative to the envelope-pasted-to start. + // We are pasting at t0 relative to the envelope-pasted-to start. + // Hence we adjust by just t0. + // Bug 1844 was that we also adjusted by the envelope-pasted-from offset. + point.SetT( point.GetT() + /*otherOffset +*/ t0 ); } // Treat removable discontinuities diff --git a/src/Envelope.h b/src/Envelope.h index 1381301ad..03663467d 100644 --- a/src/Envelope.h +++ b/src/Envelope.h @@ -131,7 +131,9 @@ public: // Envelope has no notion of rate and control point times are not quantized; // but a tolerance is needed in the Paste routine, and better to inform it // of an appropriate number, than use hidden arbitrary constants. - void Paste(double t0, const Envelope *e, double sampleDur); + // The function is called 'PasteEnvelope' rather than 'Paste' to make it + // easier to find where it is used in source code. + void PasteEnvelope(double t0, const Envelope *e, double sampleDur); void InsertSpace(double t0, double tlen); diff --git a/src/TimeTrack.cpp b/src/TimeTrack.cpp index 3862cabaf..99476a652 100644 --- a/src/TimeTrack.cpp +++ b/src/TimeTrack.cpp @@ -124,7 +124,7 @@ void TimeTrack::Paste(double t, const Track * src) return; auto sampleTime = 1.0 / GetActiveProject()->GetRate(); - mEnvelope->Paste + mEnvelope->PasteEnvelope (t, static_cast(src)->mEnvelope.get(), sampleTime); } diff --git a/src/WaveClip.cpp b/src/WaveClip.cpp index 990e34a8c..a1688508e 100644 --- a/src/WaveClip.cpp +++ b/src/WaveClip.cpp @@ -1625,7 +1625,7 @@ void WaveClip::Paste(double t0, const WaveClip* other) // Assume NOFAIL-GUARANTEE in the remaining MarkChanged(); auto sampleTime = 1.0 / GetRate(); - mEnvelope->Paste + mEnvelope->PasteEnvelope (s0.as_double()/mRate + mOffset, pastedClip->mEnvelope.get(), sampleTime); OffsetCutLines(t0, pastedClip->GetEndTime() - pastedClip->GetStartTime());