1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-16 08:34:10 +02:00

Correct envelope update for Join that includes a gap between clips

This commit is contained in:
Paul Licameli 2017-05-06 00:57:38 -04:00
parent a9160cf803
commit 327e5d8557
3 changed files with 36 additions and 4 deletions

View File

@ -1607,7 +1607,7 @@ void WaveClip::Paste(double t0, const WaveClip* other)
mCutLines.push_back(std::move(holder));
}
void WaveClip::InsertSilence(double t, double len)
void WaveClip::InsertSilence( double t, double len, double *pEnvelopeValue )
// STRONG-GUARANTEE
{
sampleCount s0;
@ -1619,10 +1619,35 @@ void WaveClip::InsertSilence(double t, double len)
// use NOFAIL-GUARANTEE
OffsetCutLines(t, len);
GetEnvelope()->InsertSpace(t, len);
const auto sampleTime = 1.0 / GetRate();
auto pEnvelope = GetEnvelope();
if ( pEnvelopeValue ) {
// Preserve limit value at the end
auto oldLen = pEnvelope->GetTrackLen();
auto oldT = pEnvelope->GetOffset() + oldLen;
auto newLen = oldLen + len;
pEnvelope->InsertOrReplace( oldT, pEnvelope->GetValue( oldT ) );
// Ramp across the silence to the given value
pEnvelope->SetTrackLen( newLen );
pEnvelope->InsertOrReplace
( pEnvelope->GetOffset() + newLen, *pEnvelopeValue );
}
else
pEnvelope->InsertSpace( t, len );
MarkChanged();
}
void WaveClip::AppendSilence( double len, double envelopeValue )
// STRONG-GUARANTEE
{
auto t = GetEndTime();
InsertSilence( t, len, &envelopeValue );
}
void WaveClip::Clear(double t0, double t1)
// STRONG-GUARANTEE
{

View File

@ -321,7 +321,11 @@ public:
/** Insert silence - note that this is an efficient operation for large
* amounts of silence */
void InsertSilence(double t, double len);
void InsertSilence( double t, double len, double *pEnvelopeValue = nullptr );
/** Insert silence at the end, and causes the envelope to ramp
linearly to the given value */
void AppendSilence( double len, double envelopeValue );
/// Get access to cut lines list
WaveClipHolders &GetCutLines() { return mCutLines; }

View File

@ -1564,12 +1564,15 @@ void WaveTrack::Join(double t0, double t1)
if (clip->GetOffset() - t > (1.0 / mRate)) {
double addedSilence = (clip->GetOffset() - t);
//printf("Adding %.6f seconds of silence\n");
newClip->InsertSilence(t, addedSilence);
auto offset = clip->GetOffset();
auto value = clip->GetEnvelope()->GetValue( offset );
newClip->AppendSilence( addedSilence, value );
t += addedSilence;
}
//printf("Pasting at %.6f\n", t);
newClip->Paste(t, clip);
t = newClip->GetEndTime();
auto it = FindClip(mClips, clip);