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

View File

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