mirror of
https://github.com/cookiengineer/audacity
synced 2025-10-21 22:12:58 +02:00
Define consistency check for Envelope, to be used in Paste
This commit is contained in:
@@ -56,6 +56,55 @@ Envelope::~Envelope()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Envelope::ConsistencyCheck()
|
||||||
|
{
|
||||||
|
bool consistent = true;
|
||||||
|
|
||||||
|
bool disorder;
|
||||||
|
do {
|
||||||
|
disorder = false;
|
||||||
|
for ( size_t ii = 0, count = mEnv.size(); ii < count; ) {
|
||||||
|
// Find range of points with equal T
|
||||||
|
const double thisT = mEnv[ii].GetT();
|
||||||
|
double nextT;
|
||||||
|
auto nextI = ii + 1;
|
||||||
|
while ( nextI < count && thisT == ( nextT = mEnv[nextI].GetT() ) )
|
||||||
|
++nextI;
|
||||||
|
|
||||||
|
if ( nextI < count && nextT < thisT )
|
||||||
|
disorder = true;
|
||||||
|
|
||||||
|
while ( nextI - ii > 2 ) {
|
||||||
|
// too many coincident time values
|
||||||
|
if (ii == mDragPoint || nextI - 1 == mDragPoint)
|
||||||
|
// forgivable
|
||||||
|
;
|
||||||
|
else {
|
||||||
|
consistent = false;
|
||||||
|
// repair it
|
||||||
|
Delete( nextI - 2 );
|
||||||
|
if (mDragPoint >= nextI - 2)
|
||||||
|
--mDragPoint;
|
||||||
|
--nextI, --count;
|
||||||
|
// wxLogError
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ii = nextI;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (disorder) {
|
||||||
|
consistent = false;
|
||||||
|
// repair it
|
||||||
|
std::stable_sort( mEnv.begin(), mEnv.end(),
|
||||||
|
[]( const EnvPoint &a, const EnvPoint &b )
|
||||||
|
{ return a.GetT() < b.GetT(); } );
|
||||||
|
}
|
||||||
|
} while ( disorder );
|
||||||
|
|
||||||
|
return consistent;
|
||||||
|
}
|
||||||
|
|
||||||
/// Rescale function for time tracks (could also be used for other tracks though).
|
/// Rescale function for time tracks (could also be used for other tracks though).
|
||||||
/// This is used to load old time track project files where the envelope used a 0 to 1
|
/// This is used to load old time track project files where the envelope used a 0 to 1
|
||||||
/// range instead of storing the actual time track values. This function will change the range of the envelope
|
/// range instead of storing the actual time track values. This function will change the range of the envelope
|
||||||
|
@@ -86,7 +86,11 @@ public:
|
|||||||
|
|
||||||
void Initialize(int numPoints);
|
void Initialize(int numPoints);
|
||||||
|
|
||||||
virtual ~ Envelope();
|
virtual ~Envelope();
|
||||||
|
|
||||||
|
// Return true if violations of point ordering invariants were detected
|
||||||
|
// and repaired
|
||||||
|
bool ConsistencyCheck();
|
||||||
|
|
||||||
double GetOffset() const { return mOffset; }
|
double GetOffset() const { return mOffset; }
|
||||||
double GetTrackLen() const { return mTrackLen; }
|
double GetTrackLen() const { return mTrackLen; }
|
||||||
|
Reference in New Issue
Block a user