1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-17 16:40:07 +02:00

Remove pointer back to Envelope from EnvPoint

This commit is contained in:
Paul Licameli 2017-05-07 19:16:19 -04:00
parent 2e7f806e90
commit 01b99f2849
2 changed files with 22 additions and 30 deletions

View File

@ -74,7 +74,7 @@ void Envelope::RescaleValues(double minValue, double maxValue)
// rescale all points // rescale all points
for( unsigned int i = 0; i < mEnv.size(); i++ ) { for( unsigned int i = 0; i < mEnv.size(); i++ ) {
factor = (mEnv[i].GetVal() - oldMinValue) / (oldMaxValue - oldMinValue); factor = (mEnv[i].GetVal() - oldMinValue) / (oldMaxValue - oldMinValue);
mEnv[i].SetVal(mMinValue + (mMaxValue - mMinValue) * factor); mEnv[i].SetVal( this, mMinValue + (mMaxValue - mMinValue) * factor );
} }
} }
@ -112,13 +112,13 @@ void Envelope::SetDragPointValid(bool valid)
// off screen and at default height. // off screen and at default height.
// temporary state when dragging only! // temporary state when dragging only!
mEnv[mDragPoint].SetT(big); mEnv[mDragPoint].SetT(big);
mEnv[mDragPoint].SetVal(mDefaultValue); mEnv[mDragPoint].SetVal( this, mDefaultValue );
return; return;
} }
else if ( mDragPoint + 1 == size ) { else if ( mDragPoint + 1 == size ) {
// Put the point at the height of the last point, but also off screen. // Put the point at the height of the last point, but also off screen.
mEnv[mDragPoint].SetT(big); mEnv[mDragPoint].SetT(big);
mEnv[mDragPoint].SetVal(mEnv[ size - 1 ].GetVal()); mEnv[mDragPoint].SetVal( this, mEnv[ size - 1 ].GetVal() );
} }
else { else {
// Place it exactly on its right neighbour. // Place it exactly on its right neighbour.
@ -126,7 +126,7 @@ void Envelope::SetDragPointValid(bool valid)
// a light dot, as if it were deleted. // a light dot, as if it were deleted.
const auto &neighbor = mEnv[mDragPoint + 1]; const auto &neighbor = mEnv[mDragPoint + 1];
mEnv[mDragPoint].SetT(neighbor.GetT()); mEnv[mDragPoint].SetT(neighbor.GetT());
mEnv[mDragPoint].SetVal(neighbor.GetVal()); mEnv[mDragPoint].SetVal( this, neighbor.GetVal() );
} }
} }
} }
@ -154,7 +154,7 @@ void Envelope::MoveDragPoint(double newWhen, double value)
// This might temporary violate the constraint that at most two // This might temporary violate the constraint that at most two
// points share a time value. // points share a time value.
dragPoint.SetT(tt); dragPoint.SetT(tt);
dragPoint.SetVal(value); dragPoint.SetVal( this, value );
} }
void Envelope::ClearDragPoint() void Envelope::ClearDragPoint()
@ -171,12 +171,12 @@ void Envelope::SetRange(double minValue, double maxValue) {
mMaxValue = maxValue; mMaxValue = maxValue;
mDefaultValue = ClampValue(mDefaultValue); mDefaultValue = ClampValue(mDefaultValue);
for( unsigned int i = 0; i < mEnv.size(); i++ ) for( unsigned int i = 0; i < mEnv.size(); i++ )
mEnv[i].SetVal(mEnv[i].GetVal()); // this clamps the value to the NEW range mEnv[i].SetVal( this, mEnv[i].GetVal() ); // this clamps the value to the NEW range
} }
EnvPoint *Envelope::AddPointAtEnd( double t, double val ) EnvPoint *Envelope::AddPointAtEnd( double t, double val )
{ {
mEnv.push_back(EnvPoint(this, t, val)); mEnv.push_back( EnvPoint{ t, val } );
return &mEnv.back(); return &mEnv.back();
} }
@ -898,7 +898,7 @@ int Envelope::Reassign(double when, double value)
if (i >= len || when < mEnv[i].GetT()) if (i >= len || when < mEnv[i].GetT())
return -1; return -1;
mEnv[i].SetVal(value); mEnv[i].SetVal( this, value );
return 0; return 0;
} }
@ -978,15 +978,12 @@ int Envelope::InsertOrReplaceRelative(double when, double value)
while (i < len && when > mEnv[i].GetT()) while (i < len && when > mEnv[i].GetT())
i++; i++;
if(i < len && when == mEnv[i].GetT()) { if(i < len && when == mEnv[i].GetT())
// modify existing // modify existing
mEnv[i].SetVal(value); mEnv[i].SetVal( this, value );
}
else { else {
// Add NEW // Add NEW
EnvPoint e(this, when, value); EnvPoint e{ when, value };
if (i < len) { if (i < len) {
Insert(i, e); Insert(i, e);
} else { } else {
@ -1007,7 +1004,7 @@ std::pair<int, int> Envelope::EqualRange( double when, double sampleTime ) const
auto end = mEnv.end(); auto end = mEnv.end();
auto first = std::lower_bound( auto first = std::lower_bound(
begin, end, begin, end,
EnvPoint{ const_cast<Envelope*>( this ), when - tolerance, 0.0 }, EnvPoint{ when - tolerance, 0.0 },
[]( const EnvPoint &point1, const EnvPoint &point2 ) []( const EnvPoint &point1, const EnvPoint &point2 )
{ return point1.GetT() < point2.GetT(); } { return point1.GetT() < point2.GetT(); }
); );

View File

@ -36,12 +36,13 @@ class ZoomInfo;
class EnvPoint final : public XMLTagHandler { class EnvPoint final : public XMLTagHandler {
public: public:
inline EnvPoint(Envelope *envelope, double t, double val); EnvPoint() {}
inline EnvPoint( double t, double val ) : mT{ t }, mVal{ val } {}
double GetT() const { return mT; } double GetT() const { return mT; }
void SetT(double t) { mT = t; } void SetT(double t) { mT = t; }
double GetVal() const { return mVal; } double GetVal() const { return mVal; }
inline void SetVal(double val); inline void SetVal( Envelope *pEnvelope, double val );
bool HandleXMLTag(const wxChar *tag, const wxChar **attrs) override bool HandleXMLTag(const wxChar *tag, const wxChar **attrs) override
{ {
@ -52,7 +53,7 @@ public:
if (!wxStrcmp(attr, wxT("t"))) if (!wxStrcmp(attr, wxT("t")))
SetT(Internat::CompatibleToDouble(value)); SetT(Internat::CompatibleToDouble(value));
else if (!wxStrcmp(attr, wxT("val"))) else if (!wxStrcmp(attr, wxT("val")))
SetVal(Internat::CompatibleToDouble(value)); SetVal( nullptr, Internat::CompatibleToDouble(value) );
} }
return true; return true;
} }
@ -66,9 +67,8 @@ public:
} }
private: private:
Envelope *mEnvelope; double mT {};
double mT; double mVal {};
double mVal;
}; };
@ -243,16 +243,11 @@ private:
mutable int mSearchGuess { -2 }; mutable int mSearchGuess { -2 };
}; };
inline EnvPoint::EnvPoint(Envelope *envelope, double t, double val) inline void EnvPoint::SetVal( Envelope *pEnvelope, double val )
{ {
mEnvelope = envelope; if ( pEnvelope )
mT = t; val = pEnvelope->ClampValue(val);
mVal = mEnvelope->ClampValue(val); mVal = val;
}
inline void EnvPoint::SetVal(double val)
{
mVal = mEnvelope->ClampValue(val);
} }
// A class that holds state for the duration of dragging // A class that holds state for the duration of dragging