1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-02 08:59:28 +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;
}
}
}

View File

@ -83,6 +83,15 @@ public:
virtual ~Envelope();
/** \brief Get many envelope points for pixel columns at once,
* but don't assume uniform time per pixel.
*/
static void GetValues
( const Envelope &env,
double aligned_time, double sampleDur,
double *buffer, int bufferLen, int leftOffset,
const ZoomInfo &zoomInfo);
// Return true if violations of point ordering invariants were detected
// and repaired
bool ConsistencyCheck();

View File

@ -103,48 +103,6 @@ void EnvelopeEditor::DrawPoints
}
}
void EnvelopeEditor::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;
}
}
}
EnvelopeEditor::EnvelopeEditor(Envelope &envelope, bool mirrored)
: mEnvelope(envelope)
, mMirrored(mirrored)

View File

@ -29,15 +29,6 @@ public:
bool dB, double dBRange,
float zoomMin, float zoomMax, bool mirrored);
/** \brief Get many envelope points for pixel columns at once,
* but don't assume uniform time per pixel.
*/
static void GetValues
( const Envelope &env,
double aligned_time, double sampleDur,
double *buffer, int bufferLen, int leftOffset,
const ZoomInfo &zoomInfo);
EnvelopeEditor(Envelope &envelope, bool mirrored);
~EnvelopeEditor();

View File

@ -25,7 +25,6 @@
#include "AColor.h"
#include "widgets/Ruler.h"
#include "Envelope.h"
#include "EnvelopeEditor.h"
#include "Prefs.h"
#include "Project.h"
#include "ProjectSettings.h"
@ -316,7 +315,7 @@ void TimeTrack::Draw
mRuler->Draw(dc, GetEnvelope());
Doubles envValues{ size_t(mid.width) };
EnvelopeEditor::GetValues( *GetEnvelope(),
Envelope::GetValues( *GetEnvelope(),
0, 0, envValues.get(), mid.width, 0, zoomInfo );
wxPen &pen = highlight ? AColor::uglyPen : AColor::envelopePen;

View File

@ -1816,7 +1816,7 @@ void TrackArt::DrawClipWaveform(TrackPanelDrawingContext &context,
std::vector<double> vEnv(mid.width);
double *const env = &vEnv[0];
EnvelopeEditor::GetValues( *clip->GetEnvelope(),
Envelope::GetValues( *clip->GetEnvelope(),
tOffset,
// PRL: change back to make envelope evaluate only at sample times
@ -1956,7 +1956,7 @@ void TrackArt::DrawClipWaveform(TrackPanelDrawingContext &context,
if (!showIndividualSamples) {
std::vector<double> vEnv2(rectPortion.width);
double *const env2 = &vEnv2[0];
EnvelopeEditor::GetValues( *clip->GetEnvelope(),
Envelope::GetValues( *clip->GetEnvelope(),
tOffset,
// PRL: change back to make envelope evaluate only at sample times