1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-05 14:18:53 +02:00

Bug842: rescale clip offsets, envelope times when setting track rate

This commit is contained in:
Paul Licameli 2017-05-04 08:32:23 -04:00
parent e36070e671
commit d2acf1f3e5
4 changed files with 24 additions and 2 deletions

View File

@ -1038,6 +1038,21 @@ void Envelope::SetTrackLen(double trackLen)
}
}
void Envelope::RescaleTimes( double newLength )
// NOFAIL-GUARANTEE
{
if ( mTrackLen == 0 ) {
for ( auto &point : mEnv )
point.SetT( 0 );
}
else {
auto ratio = newLength / mTrackLen;
for ( auto &point : mEnv )
point.SetT( point.GetT() * ratio );
}
mTrackLen = newLength;
}
// Accessors
double Envelope::GetValue(double t) const
{

View File

@ -127,6 +127,7 @@ public:
void SetOffset(double newOffset);
void SetTrackLen(double trackLen);
void RescaleValues(double minValue, double maxValue);
void RescaleTimes( double newLength );
// Accessors
/** \brief Get envelope value at time t */

View File

@ -1832,7 +1832,8 @@ void WaveClip::Unlock()
void WaveClip::SetRate(int rate)
{
mRate = rate;
UpdateEnvelopeTrackLen();
auto newLength = mSequence->GetNumSamples().as_double() / mRate;
mEnvelope->RescaleTimes( newLength );
MarkChanged();
}

View File

@ -394,9 +394,14 @@ double WaveTrack::GetRate() const
void WaveTrack::SetRate(double newRate)
{
wxASSERT( newRate > 0 );
newRate = std::max( 1.0, newRate );
auto ratio = mRate / newRate;
mRate = (int) newRate;
for (const auto &clip : mClips)
for (const auto &clip : mClips) {
clip->SetRate((int)newRate);
clip->SetOffset( clip->GetOffset() * ratio );
}
}
float WaveTrack::GetGain() const