1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-10-21 14:02:57 +02:00

Envelope::SetTrackLen adds a point only when none was present...

... And if points were present, keeps only the leftmost.
This commit is contained in:
Paul Licameli
2017-05-09 18:38:06 -04:00
parent 6c2c2733f9
commit bcc0bed29a
3 changed files with 12 additions and 7 deletions

View File

@@ -1090,17 +1090,21 @@ void Envelope::SetOffset(double newOffset)
mOffset = newOffset;
}
void Envelope::SetTrackLen(double trackLen)
void Envelope::SetTrackLen( double trackLen, double sampleTime )
// NOFAIL-GUARANTEE
{
// Preserve the right-side limit at trackLen.
bool needPoint = ( trackLen < mTrackLen );
// Preserve the left-side limit at trackLen.
auto range = EqualRange( trackLen, sampleTime );
bool needPoint = ( range.first == range.second && trackLen < mTrackLen );
double value;
if ( needPoint )
value = GetValueRelative( trackLen );
mTrackLen = trackLen;
int newLen = EqualRange( trackLen, 0 ).second;
// Shrink the array.
// If more than one point already at the end, keep only the first of them.
int newLen = std::min( 1 + range.first, range.second );
mEnv.resize( newLen );
if ( needPoint )