From 9c683a4f19dd069a2d8f2099103dd0bfa730f35c Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Tue, 2 May 2017 20:58:18 -0400 Subject: [PATCH] Rename some member functions of Envelope --- src/Envelope.cpp | 48 ++++++++++++++++++------------------ src/Envelope.h | 10 ++++---- src/TimeTrack.cpp | 14 +++++------ src/WaveTrack.cpp | 16 ++++++------ src/effects/Equalization.cpp | 48 ++++++++++++++++++------------------ 5 files changed, 68 insertions(+), 68 deletions(-) diff --git a/src/Envelope.cpp b/src/Envelope.cpp index f039393a9..6710fc45f 100644 --- a/src/Envelope.cpp +++ b/src/Envelope.cpp @@ -60,7 +60,7 @@ Envelope::~Envelope() /// and rescale all envelope points accordingly (unlike SetRange, which clamps the envelope points to the NEW range). /// @minValue - the NEW minimum value /// @maxValue - the NEW maximum value -void Envelope::Rescale(double minValue, double maxValue) +void Envelope::RescaleValues(double minValue, double maxValue) { double oldMinValue = mMinValue; double oldMaxValue = mMaxValue; @@ -499,7 +499,7 @@ bool EnvelopeEditor::HandleMouseButtonDown(const wxMouseEvent & event, wxRect & double newVal = ValueOfPixel(clip_y, r.height, upper, dB, dBRange, zoomMin, zoomMax); - mEnvelope.SetDragPoint(mEnvelope.Insert(when - mEnvelope.GetOffset(), newVal)); + mEnvelope.SetDragPoint(mEnvelope.InsertOrReplace(when - mEnvelope.GetOffset(), newVal)); mDirty = true; } @@ -732,7 +732,7 @@ Old analysis of cases: //wxLogDebug(wxT("Case 1")); } else { - Insert(t0 + mTrackEpsilon, splitval); // Case 3: insert a point to maintain the envelope + InsertOrReplace(t0 + mTrackEpsilon, splitval); // Case 3: insert a point to maintain the envelope someToShift = true; //wxLogDebug(wxT("Case 3")); } @@ -744,21 +744,21 @@ Old analysis of cases: //wxLogDebug(wxT("Case 2")); } else { // Case 4: - Insert(t0 - mTrackEpsilon, splitval); // insert a point to maintain the envelope + InsertOrReplace(t0 - mTrackEpsilon, splitval); // insert a point to maintain the envelope //wxLogDebug(wxT("Case 4")); } } else { if(onPoint) { // Case 7: move the point L and insert a NEW one to the R mEnv[pos].SetT(mEnv[pos].GetT() - mTrackEpsilon); - Insert(t0 + mTrackEpsilon, splitval); + InsertOrReplace(t0 + mTrackEpsilon, splitval); someToShift = true; //wxLogDebug(wxT("Case 7")); } else { if( !beforeStart && !afterEnd ) {// Case 5: Insert points to L and R - Insert(t0 - mTrackEpsilon, splitval); - Insert(t0 + mTrackEpsilon, splitval); + InsertOrReplace(t0 - mTrackEpsilon, splitval); + InsertOrReplace(t0 + mTrackEpsilon, splitval); someToShift = true; //wxLogDebug(wxT("Case 5")); } @@ -805,13 +805,13 @@ Old analysis of cases: // calls for the start and end times will have no effect. const double leftval = e->GetValue(0 + e->mOffset); const double rightval = e->GetValue(e->mTrackLen + e->mOffset); - Insert(t0, leftval); - Insert(t0 + e->mTrackLen, rightval); + InsertOrReplace(t0, leftval); + InsertOrReplace(t0 + e->mTrackLen, rightval); } len = e->mEnv.size(); for (i = 0; i < len; i++) - Insert(t0 + e->mEnv[i].GetT(), e->mEnv[i].GetVal()); + InsertOrReplace(t0 + e->mEnv[i].GetT(), e->mEnv[i].GetVal()); /* if(len != 0) for (i = 0; i < mEnv.size(); i++) @@ -846,7 +846,7 @@ void Envelope::RemoveUnneededPoints(double time, double tolerence) bool bExcludePoint = true; if( fabs(val -val1) > tolerence ) { - Insert(when, val); // put it back, we needed it + InsertOrReplace(when, val); // put it back, we needed it //Insert may have modified instead of inserting, if two points were at the same time. // in which case len needs to shrink i and len, because the array size decreased. @@ -872,7 +872,7 @@ void Envelope::InsertSpace(double t0, double tlen) mTrackLen += tlen; } -int Envelope::Move(double when, double value) +int Envelope::Reassign(double when, double value) { int len = mEnv.size(); if (len == 0) @@ -939,7 +939,7 @@ void Envelope::GetPoints(double *bufferWhen, * @param value the envelope value to use at the given point. * @return the index of the NEW envelope point within array of envelope points. */ -int Envelope::Insert(double when, double value) +int Envelope::InsertOrReplace(double when, double value) { #if defined(__WXDEBUG__) // in debug builds, do a spot of argument checking @@ -1566,7 +1566,7 @@ void Envelope::testMe() { double t0=0, t1=0; - SetInterpolateDB(false); + SetExponential(false); Flatten(0.5); checkResult( 1, Integral(0.0,100.0), 50); @@ -1578,14 +1578,14 @@ void Envelope::testMe() checkResult( 5, Integral(-20.0,-10.0), 5); Flatten(0.5); - Insert( 5.0, 0.5 ); + InsertOrReplace( 5.0, 0.5 ); checkResult( 6, Integral(0.0,100.0), 50); checkResult( 7, Integral(-10.0,10.0), 10); Flatten(0.0); - Insert( 0.0, 0.0 ); - Insert( 5.0, 1.0 ); - Insert( 10.0, 0.0 ); + InsertOrReplace( 0.0, 0.0 ); + InsertOrReplace( 5.0, 1.0 ); + InsertOrReplace( 10.0, 0.0 ); t0 = 10.0 - .1; t1 = 10.0 + .1; double result = Integral(0.0,t1); @@ -1595,9 +1595,9 @@ void Envelope::testMe() checkResult( 8, result - resulta - resultb, 0); Flatten(0.0); - Insert( 0.0, 0.0 ); - Insert( 5.0, 1.0 ); - Insert( 10.0, 0.0 ); + InsertOrReplace( 0.0, 0.0 ); + InsertOrReplace( 5.0, 1.0 ); + InsertOrReplace( 10.0, 0.0 ); t0 = 10.0 - .1; t1 = 10.0 + .1; checkResult( 9, Integral(0.0,t1), 5); @@ -1605,9 +1605,9 @@ void Envelope::testMe() checkResult( 11, Integral(t0,t1), .001); mEnv.clear(); - Insert( 0.0, 0.0 ); - Insert( 5.0, 1.0 ); - Insert( 10.0, 0.0 ); + InsertOrReplace( 0.0, 0.0 ); + InsertOrReplace( 5.0, 1.0 ); + InsertOrReplace( 10.0, 0.0 ); checkResult( 12, NumberOfPointsAfter( -1 ), 3 ); checkResult( 13, NumberOfPointsAfter( 0 ), 2 ); checkResult( 14, NumberOfPointsAfter( 1 ), 2 ); diff --git a/src/Envelope.h b/src/Envelope.h index 71114f148..e16038f34 100644 --- a/src/Envelope.h +++ b/src/Envelope.h @@ -91,9 +91,8 @@ public: double GetOffset() const { return mOffset; } double GetTrackLen() const { return mTrackLen; } - bool GetInterpolateDB() { return mDB; } - void SetInterpolateDB(bool db) { mDB = db; } - void Rescale(double minValue, double maxValue); + bool GetExponential() const { return mDB; } + void SetExponential(bool db) { mDB = db; } void Flatten(double value); @@ -127,6 +126,7 @@ public: // Control void SetOffset(double newOffset); void SetTrackLen(double trackLen); + void RescaleValues(double minValue, double maxValue); // Accessors /** \brief Get envelope value at time t */ @@ -158,12 +158,12 @@ public: bool IsDirty() const; /** \brief Add a point at a particular spot */ - int Insert(double when, double value); + int InsertOrReplace(double when, double value); /** \brief Move a point at when to value * * Returns 0 if point moved, -1 if not found.*/ - int Move(double when, double value); + int Reassign(double when, double value); /** \brief DELETE a point by its position in array */ void Delete(int point); diff --git a/src/TimeTrack.cpp b/src/TimeTrack.cpp index 08313c374..4edfac787 100644 --- a/src/TimeTrack.cpp +++ b/src/TimeTrack.cpp @@ -136,11 +136,11 @@ Track::Holder TimeTrack::Duplicate() const bool TimeTrack::GetInterpolateLog() const { - return mEnvelope->GetInterpolateDB(); + return mEnvelope->GetExponential(); } void TimeTrack::SetInterpolateLog(bool interpolateLog) { - mEnvelope->SetInterpolateDB(interpolateLog); + mEnvelope->SetExponential(interpolateLog); } //Compute the (average) warp factor between two non-warped time points @@ -217,7 +217,7 @@ void TimeTrack::HandleXMLEndTag(const wxChar * WXUNUSED(tag)) if(mRescaleXMLValues) { mRescaleXMLValues = false; - mEnvelope->Rescale(mRangeLower, mRangeUpper); + mEnvelope->RescaleValues(mRangeLower, mRangeUpper); mEnvelope->SetRange(TIMETRACK_MIN, TIMETRACK_MAX); } } @@ -299,10 +299,10 @@ void TimeTrack::Draw(wxDC & dc, const wxRect & r, const ZoomInfo &zoomInfo) cons void TimeTrack::testMe() { GetEnvelope()->Flatten(0.0); - GetEnvelope()->Insert( 0.0, 0.2 ); - GetEnvelope()->Insert( 5.0 - 0.001, 0.2 ); - GetEnvelope()->Insert( 5.0 + 0.001, 1.3 ); - GetEnvelope()->Insert( 10.0, 1.3 ); + GetEnvelope()->InsertOrReplace(0.0, 0.2); + GetEnvelope()->InsertOrReplace(5.0 - 0.001, 0.2); + GetEnvelope()->InsertOrReplace(5.0 + 0.001, 1.3); + GetEnvelope()->InsertOrReplace(10.0, 1.3); double value1 = GetEnvelope()->Integral(2.0, 13.0); double expected1 = (5.0 - 2.0) * 0.2 + (13.0 - 5.0) * 1.3; diff --git a/src/WaveTrack.cpp b/src/WaveTrack.cpp index da0973d84..7e32b7775 100644 --- a/src/WaveTrack.cpp +++ b/src/WaveTrack.cpp @@ -1145,13 +1145,13 @@ void WaveTrack::HandleClear(double t0, double t1, if (clip->WithinClip(t0)) { // start of region within clip val = clip->GetEnvelope()->GetValue(t0); - newClip->GetEnvelope()->Insert(t0 - clip->GetOffset() - 1.0/clip->GetRate(), val); - } - if (clip->WithinClip(t1)) { - // end of region within clip + newClip->GetEnvelope()->InsertOrReplace(t0 - clip->GetOffset() - 1.0 / clip->GetRate(), val); + } + if (clip->WithinClip(t1)) + { // end of region within clip val = clip->GetEnvelope()->GetValue(t1); - newClip->GetEnvelope()->Insert(t1 - clip->GetOffset(), val); - } + newClip->GetEnvelope()->InsertOrReplace(t1 - clip->GetOffset(), val); + } } newClip->Clear(t0,t1); newClip->GetEnvelope()->RemoveUnneededPoints(t0); @@ -2393,8 +2393,8 @@ void WaveTrack::SplitAt(double t) //make two envelope points to preserve the value. //handle the case where we split on the 1st sample (without this we hit an assert) if(t - 1.0/c->GetRate() >= c->GetOffset()) - c->GetEnvelope()->Insert(t - c->GetOffset() - 1.0/c->GetRate(), val); // frame end points - c->GetEnvelope()->Insert(t - c->GetOffset(), val); + c->GetEnvelope()->InsertOrReplace(t - c->GetOffset() - 1.0 / c->GetRate(), val); // frame end points + c->GetEnvelope()->InsertOrReplace(t - c->GetOffset(), val); auto newClip = make_movable( *c, mDirManager, true ); c->Clear(t, c->GetEndTime()); newClip->Clear(c->GetStartTime(), t); diff --git a/src/effects/Equalization.cpp b/src/effects/Equalization.cpp index ba869b119..ec95cefe4 100644 --- a/src/effects/Equalization.cpp +++ b/src/effects/Equalization.cpp @@ -1651,7 +1651,7 @@ void EffectEqualization::setCurve(int currentCurve) when = (log10(std::max((double) loFreqI, when)) - loLog)/denom; } value = mCurves[currentCurve].points[0].dB; - env->Insert(std::min(1.0, std::max(0.0, when)), value); + env->InsertOrReplace(std::min(1.0, std::max(0.0, when)), value); ForceRecalc(); return; } @@ -1670,7 +1670,7 @@ void EffectEqualization::setCurve(int currentCurve) when = mCurves[currentCurve].points[pointCount].Freq / mHiFreq; value = mCurves[currentCurve].points[pointCount].dB; if(when <= 1) { - env->Insert(when, value); + env->InsertOrReplace(when, value); } else { // There are more points at higher freqs, so interpolate next one then stop. @@ -1680,7 +1680,7 @@ void EffectEqualization::setCurve(int currentCurve) double lastDB = mCurves[currentCurve].points[pointCount-1].dB; double nextDB = mCurves[currentCurve].points[pointCount].dB; value = lastDB + ((nextDB - lastDB) * ((mHiFreq - lastF) / (nextF - lastF))); - env->Insert(when, value); + env->InsertOrReplace(when, value); break; } } @@ -1702,7 +1702,7 @@ void EffectEqualization::setCurve(int currentCurve) // All points below 20 Hz, so just use final point. when = 0.0; value = mCurves[currentCurve].points[numPoints-1].dB; - env->Insert(when, value); + env->InsertOrReplace(when, value); ForceRecalc(); return; } @@ -1717,7 +1717,7 @@ void EffectEqualization::setCurve(int currentCurve) double nextDB = mCurves[currentCurve].points[firstAbove20Hz].dB; when = 0.0; value = nextDB - ((nextDB - prevDB) * ((nextF - loLog) / (nextF - prevF))); - env->Insert(when, value); + env->InsertOrReplace(when, value); } // Now get the rest. @@ -1729,7 +1729,7 @@ void EffectEqualization::setCurve(int currentCurve) when = (flog - loLog)/denom; value = mCurves[currentCurve].points[pointCount].dB; if(when <= 1.0) { - env->Insert(when, value); + env->InsertOrReplace(when, value); } else { // This looks weird when adjusting curve in Draw mode if @@ -1748,7 +1748,7 @@ void EffectEqualization::setCurve(int currentCurve) double logLastF = log10(mCurves[currentCurve].points[pointCount-1].Freq); double lastDB = mCurves[currentCurve].points[pointCount-1].dB; value = lastDB + ((value - lastDB) * ((log10(mHiFreq) - logLastF) / (flog - logLastF))); - env->Insert(when, value); + env->InsertOrReplace(when, value); break; } } @@ -2177,7 +2177,7 @@ void EffectEqualization::UpdateGraphic() { when = freq/mHiFreq; value = mLinEnvelope->GetValue(when); - mLinEnvelope->Insert(when, value); + mLinEnvelope->InsertOrReplace(when, value); } EnvLinToLog(); @@ -2249,14 +2249,14 @@ void EffectEqualization::EnvLogToLin(void) mLinEnvelope->Flatten(0.); mLinEnvelope->SetTrackLen(1.0); mLogEnvelope->GetPoints( when.get(), value.get(), numPoints ); - mLinEnvelope->Move(0., value[0]); + mLinEnvelope->Reassign(0., value[0]); double loLog = log10(20.); double hiLog = log10(mHiFreq); double denom = hiLog - loLog; for (size_t i = 0; i < numPoints; i++) - mLinEnvelope->Insert(pow( 10., ((when[i] * denom) + loLog))/mHiFreq , value[i]); - mLinEnvelope->Move(1., value[numPoints-1]); + mLinEnvelope->InsertOrReplace(pow( 10., ((when[i] * denom) + loLog))/mHiFreq , value[i]); + mLinEnvelope->Reassign(1., value[numPoints-1]); } void EffectEqualization::EnvLinToLog(void) @@ -2273,7 +2273,7 @@ void EffectEqualization::EnvLinToLog(void) mLogEnvelope->Flatten(0.); mLogEnvelope->SetTrackLen(1.0); mLinEnvelope->GetPoints( when.get(), value.get(), numPoints ); - mLogEnvelope->Move(0., value[0]); + mLogEnvelope->Reassign(0., value[0]); double loLog = log10(20.); double hiLog = log10(mHiFreq); double denom = hiLog - loLog; @@ -2286,16 +2286,16 @@ void EffectEqualization::EnvLinToLog(void) // Caution: on Linux, when when == 20, the log calulation rounds // to just under zero, which causes an assert error. double flog = (log10(when[i]*mHiFreq)-loLog)/denom; - mLogEnvelope->Insert(std::max(0.0, flog) , value[i]); + mLogEnvelope->InsertOrReplace(std::max(0.0, flog) , value[i]); } else { //get the first point as close as we can to the last point requested changed = true; double v = value[i]; - mLogEnvelope->Insert(0., v); + mLogEnvelope->InsertOrReplace(0., v); } } - mLogEnvelope->Move(1., value[numPoints-1]); + mLogEnvelope->Reassign(1., value[numPoints - 1]); if(changed) EnvelopeUpdated(mLogEnvelope.get(), false); @@ -2448,10 +2448,10 @@ void EffectEqualization::GraphicEQ(Envelope *env) } } if(mWhens[i]<=0.) - env->Move( 0., value ); - env->Insert( mWhens[i], value ); + env->Reassign(0., value); + env->InsertOrReplace( mWhens[i], value ); } - env->Move( 1., value ); + env->Reassign( 1., value ); break; } @@ -2492,10 +2492,10 @@ void EffectEqualization::GraphicEQ(Envelope *env) } } if(mWhens[i]<=0.) - env->Move( 0., value ); - env->Insert( mWhens[i], value ); + env->Reassign(0., value); + env->InsertOrReplace( mWhens[i], value ); } - env->Move( 1., value ); + env->Reassign( 1., value ); break; } @@ -2506,7 +2506,7 @@ void EffectEqualization::GraphicEQ(Envelope *env) spline(mWhenSliders, mEQVals, mBandsInUse+1, y2); for(double xf=0; xf<1.; xf+=1./NUM_PTS) { - env->Insert(xf, splint(mWhenSliders, mEQVals, mBandsInUse+1, y2, xf)); + env->InsertOrReplace(xf, splint(mWhenSliders, mEQVals, mBandsInUse+1, y2, xf)); } break; } @@ -2735,9 +2735,9 @@ void EffectEqualization::OnInvert(wxCommandEvent & WXUNUSED(event)) // Inverts a for (size_t i = 0; i < numPoints; i++) { if(lin) - mLinEnvelope->Move(when[i] , -value[i]); + mLinEnvelope->Reassign(when[i] , -value[i]); else - mLogEnvelope->Move(when[i] , -value[i]); + mLogEnvelope->Reassign(when[i] , -value[i]); } // copy it back to the other one (just in case)