1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-12-18 14:41:20 +01:00

Added consistency checks for Sequence, hoisted out of inner loops.

This commit is contained in:
Paul Licameli
2016-02-03 12:56:21 -05:00
parent 7be911b7fb
commit 13f7d0a81b
3 changed files with 56 additions and 18 deletions

View File

@@ -283,6 +283,28 @@ RecordingRecoveryHandler::RecordingRecoveryHandler(AudacityProject* proj)
mNumChannels = -1;
}
int RecordingRecoveryHandler::FindTrack() const
{
WaveTrackArray tracks = mProject->GetTracks()->GetWaveTrackArray(false);
int index;
if (mAutoSaveIdent)
{
for (index = 0; index < (int)tracks.GetCount(); index++)
{
if (tracks[index]->GetAutoSaveIdent() == mAutoSaveIdent)
{
break;
}
}
}
else
{
index = tracks.GetCount() - mNumChannels + mChannel;
}
return index;
}
bool RecordingRecoveryHandler::HandleXMLTag(const wxChar *tag,
const wxChar **attrs)
{
@@ -296,23 +318,9 @@ bool RecordingRecoveryHandler::HandleXMLTag(const wxChar *tag,
return false;
}
// We need to find the track and sequence where the blockfile belongs
WaveTrackArray tracks = mProject->GetTracks()->GetWaveTrackArray(false);
int index;
if (mAutoSaveIdent)
{
for (index = 0; index < (int) tracks.GetCount(); index++)
{
if (tracks[index]->GetAutoSaveIdent() == mAutoSaveIdent)
{
break;
}
}
}
else
{
index = tracks.GetCount() - mNumChannels + mChannel;
}
int index = FindTrack();
// We need to find the track and sequence where the blockfile belongs
if (index < 0 || index >= (int) tracks.GetCount())
{
@@ -391,6 +399,29 @@ bool RecordingRecoveryHandler::HandleXMLTag(const wxChar *tag,
return true;
}
void RecordingRecoveryHandler::HandleXMLEndTag(const wxChar *tag)
{
if (wxStrcmp(tag, wxT("simpleblockfile")) == 0)
// Still in inner looop
return;
WaveTrackArray tracks = mProject->GetTracks()->GetWaveTrackArray(false);
int index = FindTrack();
// We need to find the track and sequence where the blockfile belongs
if (index < 0 || index >= (int)tracks.GetCount()) {
// This should only happen if there is a bug
wxASSERT(false);
}
else {
WaveTrack* track = tracks.Item(index);
WaveClip* clip = track->NewestOrNewClip();
Sequence* seq = clip->GetSequence();
seq->ConsistencyCheck(wxT("RecordingRecoveryHandler::HandleXMLEndTag"));
}
}
XMLTagHandler* RecordingRecoveryHandler::HandleXMLChild(const wxChar *tag)
{
if (wxStrcmp(tag, wxT("simpleblockfile")) == 0)

View File

@@ -46,12 +46,16 @@ class RecordingRecoveryHandler: public XMLTagHandler
public:
RecordingRecoveryHandler(AudacityProject* proj);
virtual bool HandleXMLTag(const wxChar *tag, const wxChar **attrs);
virtual void HandleXMLEndTag(const wxChar *tag);
virtual XMLTagHandler *HandleXMLChild(const wxChar *tag);
// This class only knows reading tags
virtual void WriteXML(XMLWriter & WXUNUSED(xmlFile)) { wxASSERT(false); }
private:
int FindTrack() const;
AudacityProject* mProject;
int mChannel;
int mNumChannels;

View File

@@ -461,7 +461,7 @@ bool Sequence::Copy(sampleCount s0, sampleCount s1, Sequence **dest)
DeleteSamples(buffer);
return true;
return ConsistencyCheck(wxT("Sequence::Copy()"));
}
bool Sequence::Paste(sampleCount s, const Sequence *src)
@@ -756,7 +756,7 @@ bool Sequence::AppendBlock(const SeqBlock &b)
mNumSamples += newBlock.f->GetLength();
// Don't do a consistency check here because this
// function gets called in an inner loop
// function gets called in an inner loop.
return true;
}
@@ -1870,6 +1870,9 @@ void Sequence::AppendBlockFile(BlockFile* blockFile)
mBlock.push_back(SeqBlock(blockFile, mNumSamples));
mNumSamples += blockFile->GetLength();
// PRL: I hoisted the intended consistency check out of the inner loop
// See RecordingRecoveryHandler::HandleXMLEndTag
#ifdef VERY_SLOW_CHECKING
ConsistencyCheck(wxT("AppendBlockFile"));
#endif