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

TimeTrack drawing not dependent on EnvelopeEditor...

... after a static function is moved from EnvelopeEditor to Envelope
This commit is contained in:
Paul Licameli
2019-06-05 14:03:59 -04:00
parent a99b746520
commit 63350d8573
6 changed files with 55 additions and 55 deletions

View File

@@ -1455,3 +1455,46 @@ void Envelope::testMe()
checkResult( 18, NextPointAfter( 0 ), 5 );
checkResult( 19, NextPointAfter( 5 ), 10 );
}
#include "ZoomInfo.h"
void Envelope::GetValues
( const Envelope &env,
double alignedTime, double sampleDur,
double *buffer, int bufferLen, int leftOffset,
const ZoomInfo &zoomInfo )
{
// Getting many envelope values, corresponding to pixel columns, which may
// not be uniformly spaced in time when there is a fisheye.
double prevDiscreteTime=0.0, prevSampleVal=0.0, nextSampleVal=0.0;
for ( int xx = 0; xx < bufferLen; ++xx ) {
auto time = zoomInfo.PositionToTime( xx, -leftOffset );
if ( sampleDur <= 0 )
// Sample interval not defined (as for time track)
buffer[xx] = env.GetValue( time );
else {
// The level of zoom-in may resolve individual samples.
// If so, then instead of evaluating the envelope directly,
// we draw a piecewise curve with knees at each sample time.
// This actually makes clearer what happens as you drag envelope
// points and make discontinuities.
auto leftDiscreteTime = alignedTime +
sampleDur * floor( ( time - alignedTime ) / sampleDur );
if ( xx == 0 || leftDiscreteTime != prevDiscreteTime ) {
prevDiscreteTime = leftDiscreteTime;
prevSampleVal =
env.GetValue( prevDiscreteTime, sampleDur );
nextSampleVal =
env.GetValue( prevDiscreteTime + sampleDur, sampleDur );
}
auto ratio = ( time - leftDiscreteTime ) / sampleDur;
if ( env.GetExponential() )
buffer[ xx ] = exp(
( 1.0 - ratio ) * log( prevSampleVal )
+ ratio * log( nextSampleVal ) );
else
buffer[ xx ] =
( 1.0 - ratio ) * prevSampleVal + ratio * nextSampleVal;
}
}
}