1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-20 14:20:06 +02:00

Simplify iterations over WaveClips outside of WaveTrack/WaveClip; ...

... also add some const qualifiers
This commit is contained in:
Paul Licameli 2016-02-19 19:58:30 -05:00 committed by Paul Licameli
parent cb7872f980
commit b548e641ae
14 changed files with 41 additions and 89 deletions

View File

@ -73,12 +73,6 @@ bool CrossFader::CrossFadeMix(samplePtr buffer, sampleFormat format, sampleCount
//we should use one of the size len, because this has already //we should use one of the size len, because this has already
//been determined to be good in Mixer //been determined to be good in Mixer
//Get a pointer to the sequence in each clip.
WaveClip * tmpclip = NULL;
WaveClipList::compatibility_iterator it;
//Go through each clip, adding it to the total in the appropriate way. //Go through each clip, adding it to the total in the appropriate way.
//this could be 'optimized' by getting all of the sequences and then //this could be 'optimized' by getting all of the sequences and then
@ -94,10 +88,8 @@ bool CrossFader::CrossFadeMix(samplePtr buffer, sampleFormat format, sampleCount
unsigned int i = 0; unsigned int i = 0;
//Now, go through the clips and load up the vectors. //Now, go through the clips and load up the vectors.
for(it = mClips.GetFirst(); it; it = it->GetNext()) for(const auto &tmpclip: mClips)
{ {
tmpclip = it->GetData();
tmpSequence[i] = tmpclip->GetSequence(); tmpSequence[i] = tmpclip->GetSequence();

View File

@ -62,16 +62,13 @@ static void GetAllSeqBlocks(AudacityProject *project,
Track *t = iter.First(); Track *t = iter.First();
while (t) { while (t) {
if (t->GetKind() == Track::Wave) { if (t->GetKind() == Track::Wave) {
WaveTrack *waveTrack = (WaveTrack *)t; WaveTrack *waveTrack = static_cast<WaveTrack*>(t);
WaveClipList::compatibility_iterator node = waveTrack->GetClipIterator(); for(const auto &clip : waveTrack->GetClips()) {
while(node) {
WaveClip *clip = node->GetData();
Sequence *sequence = clip->GetSequence(); Sequence *sequence = clip->GetSequence();
BlockArray &blocks = sequence->GetBlockArray(); BlockArray &blocks = sequence->GetBlockArray();
int i; int i;
for (i = 0; i < (int)blocks.size(); i++) for (i = 0; i < (int)blocks.size(); i++)
outBlocks->push_back(&blocks[i]); outBlocks->push_back(&blocks[i]);
node = node->GetNext();
} }
} }
t = iter.Next(); t = iter.Next();

View File

@ -1230,14 +1230,9 @@ void AudacityProject::RedrawProject(const bool bForceWaveTracks /*= false*/)
{ {
if (pTrack->GetKind() == Track::Wave) if (pTrack->GetKind() == Track::Wave)
{ {
WaveTrack* pWaveTrack = (WaveTrack*)pTrack; WaveTrack* pWaveTrack = static_cast<WaveTrack*>(pTrack);
WaveClipList::compatibility_iterator node = pWaveTrack->GetClipIterator(); for (const auto &clip: pWaveTrack->GetClips())
while (node)
{
WaveClip *clip = node->GetData();
clip->MarkChanged(); clip->MarkChanged();
node = node->GetNext();
}
} }
pTrack = iter.Next(); pTrack = iter.Next();
} }
@ -2954,10 +2949,8 @@ void AudacityProject::OpenFile(const wxString &fileNameArg, bool addtohistory)
if (t->GetKind() == Track::Wave) if (t->GetKind() == Track::Wave)
{ {
// Only wave tracks have a notion of "changed". // Only wave tracks have a notion of "changed".
for (WaveClipList::compatibility_iterator clipIter = ((WaveTrack*)t)->GetClipIterator(); for (const auto &clip: static_cast<WaveTrack*>(t)->GetClips())
clipIter; clip->MarkChanged();
clipIter=clipIter->GetNext())
clipIter->GetData()->MarkChanged();
} }
t = iter.Next(); t = iter.Next();
} }

View File

@ -128,11 +128,9 @@ void SnapManager::Reinit()
} }
else if (track->GetKind() == Track::Wave) else if (track->GetKind() == Track::Wave)
{ {
WaveTrack *waveTrack = (WaveTrack *)track; WaveTrack *waveTrack = static_cast<WaveTrack *>(track);
WaveClipList::compatibility_iterator it; for (const auto &clip: waveTrack->GetClips())
for (it = waveTrack->GetClipIterator(); it; it = it->GetNext())
{ {
WaveClip *clip = it->GetData();
if (mClipExclusions) if (mClipExclusions)
{ {
bool skip = false; bool skip = false;

View File

@ -450,9 +450,9 @@ void TrackArtist::DrawTrack(const Track * t,
switch (t->GetKind()) { switch (t->GetKind()) {
case Track::Wave: case Track::Wave:
{ {
WaveTrack* wt = (WaveTrack*)t; const WaveTrack* wt = static_cast<const WaveTrack*>(t);
for (WaveClipList::compatibility_iterator it=wt->GetClipIterator(); it; it=it->GetNext()) { for (const auto &clip : wt->GetClips()) {
it->GetData()->ClearDisplayRect(); clip->ClearDisplayRect();
} }
bool muted = (hasSolo || t->GetMute()) && !t->GetSolo(); bool muted = (hasSolo || t->GetMute()) && !t->GetSolo();
@ -1471,9 +1471,8 @@ void TrackArtist::DrawWaveform(const WaveTrack *track,
DrawBackgroundWithSelection(&dc, rect, track, blankSelectedBrush, blankBrush, DrawBackgroundWithSelection(&dc, rect, track, blankSelectedBrush, blankBrush,
selectedRegion, zoomInfo); selectedRegion, zoomInfo);
for (WaveClipList::compatibility_iterator it = for (const auto &clip: track->GetClips())
const_cast<WaveTrack*>(track)->GetClipIterator(); it; it = it->GetNext()) DrawClipWaveform(track, clip, dc, rect, selectedRegion, zoomInfo,
DrawClipWaveform(track, it->GetData(), dc, rect, selectedRegion, zoomInfo,
drawEnvelope, bigPoints, drawEnvelope, bigPoints,
dB, muted); dB, muted);
@ -2011,9 +2010,8 @@ void TrackArtist::DrawSpectrum(const WaveTrack *track,
selectedRegion, zoomInfo); selectedRegion, zoomInfo);
WaveTrackCache cache(track); WaveTrackCache cache(track);
for (WaveClipList::compatibility_iterator it = for (const auto &clip: track->GetClips()) {
const_cast<WaveTrack*>(track)->GetClipIterator(); it; it = it->GetNext()) { DrawClipSpectrum(cache, clip, dc, rect, selectedRegion, zoomInfo);
DrawClipSpectrum(cache, it->GetData(), dc, rect, selectedRegion, zoomInfo);
} }
} }

View File

@ -3422,12 +3422,8 @@ void TrackPanel::AddClipsToCaptured(Track *t, double t0, double t1)
{ {
if (t->GetKind() == Track::Wave) if (t->GetKind() == Track::Wave)
{ {
WaveClipList::compatibility_iterator it = for(const auto &clip: static_cast<WaveTrack*>(t)->GetClips())
((WaveTrack *)t)->GetClipIterator();
while (it)
{ {
WaveClip *clip = it->GetData();
if ( ! clip->AfterClip(t0) && ! clip->BeforeClip(t1) ) if ( ! clip->AfterClip(t0) && ! clip->BeforeClip(t1) )
{ {
// Avoid getting clips that were already captured // Avoid getting clips that were already captured
@ -3442,7 +3438,6 @@ void TrackPanel::AddClipsToCaptured(Track *t, double t0, double t1)
if (newClip) if (newClip)
mCapturedClipArray.push_back(TrackClip(t, clip)); mCapturedClipArray.push_back(TrackClip(t, clip));
} }
it = it->GetNext();
} }
} }
else else

View File

@ -94,11 +94,10 @@ void UndoManager::CalculateSpaceUsage()
while (wt) while (wt)
{ {
// Scan all clips within current track // Scan all clips within current track
WaveClipList::compatibility_iterator it = wt->GetClipIterator(); for(const auto &clip: wt->GetClips())
while (it)
{ {
// Scan all blockfiles within current clip // Scan all blockfiles within current clip
BlockArray *blocks = it->GetData()->GetSequenceBlockArray(); BlockArray *blocks = clip->GetSequenceBlockArray();
for (const auto &block : *blocks) for (const auto &block : *blocks)
{ {
BlockFile *file = block.f; BlockFile *file = block.f;
@ -113,8 +112,6 @@ void UndoManager::CalculateSpaceUsage()
// Add file to current set // Add file to current set
cur->insert(file); cur->insert(file);
} }
it = it->GetNext();
} }
wt = (WaveTrack *) iter.Next(); wt = (WaveTrack *) iter.Next();

View File

@ -2631,9 +2631,8 @@ void WaveTrack::FillSortedClipArray(WaveClipArray& clips) const
{ {
clips.Empty(); clips.Empty();
for (WaveClipList::compatibility_iterator it = for (const auto &clip: GetClips())
const_cast<WaveTrack*>(this)->GetClipIterator(); it; it=it->GetNext()) clips.Add(clip);
clips.Add(it->GetData());
clips.Sort(SortClipArrayCmpFunc); clips.Sort(SortClipArrayCmpFunc);
} }

View File

@ -333,9 +333,9 @@ class AUDACITY_DLL_API WaveTrack final : public Track {
*/ */
double LongSamplesToTime(sampleCount pos) const; double LongSamplesToTime(sampleCount pos) const;
// Get access to the clips in the tracks. This is used by // Get access to the clips in the tracks.
// track artists and also by TrackPanel when sliding...it would const WaveClipList &GetClips() const { return mClips; }
// be cleaner if this could be removed, though...
WaveClipList::compatibility_iterator GetClipIterator() { return mClips.GetFirst(); } WaveClipList::compatibility_iterator GetClipIterator() { return mClips.GetFirst(); }
// Create NEW clip and add it to this track. Returns a pointer // Create NEW clip and add it to this track. Returns a pointer

View File

@ -1162,13 +1162,11 @@ bool EffectEqualization::ProcessOne(int count, WaveTrack * t,
//Find the bits of clips that need replacing //Find the bits of clips that need replacing
std::vector<std::pair<double, double> > clipStartEndTimes; std::vector<std::pair<double, double> > clipStartEndTimes;
std::vector<std::pair<double, double> > clipRealStartEndTimes; //the above may be truncated due to a clip being partially selected std::vector<std::pair<double, double> > clipRealStartEndTimes; //the above may be truncated due to a clip being partially selected
for (WaveClipList::compatibility_iterator it=t->GetClipIterator(); it; it=it->GetNext()) for (const auto &clip : t->GetClips())
{ {
WaveClip *clip;
double clipStartT; double clipStartT;
double clipEndT; double clipEndT;
clip = it->GetData();
clipStartT = clip->GetStartTime(); clipStartT = clip->GetStartTime();
clipEndT = clip->GetEndTime(); clipEndT = clip->GetEndTime();
if( clipEndT <= startT ) if( clipEndT <= startT )

View File

@ -520,13 +520,11 @@ bool EffectEqualization48x::ProcessTail(WaveTrack * t, WaveTrack * output, sampl
//Find the bits of clips that need replacing //Find the bits of clips that need replacing
std::vector<std::pair<double, double> > clipStartEndTimes; std::vector<std::pair<double, double> > clipStartEndTimes;
std::vector<std::pair<double, double> > clipRealStartEndTimes; //the above may be truncated due to a clip being partially selected std::vector<std::pair<double, double> > clipRealStartEndTimes; //the above may be truncated due to a clip being partially selected
for (WaveClipList::compatibility_iterator it=t->GetClipIterator(); it; it=it->GetNext()) for (const auto &clip: t->GetClips())
{ {
WaveClip *clip;
double clipStartT; double clipStartT;
double clipEndT; double clipEndT;
clip = it->GetData();
clipStartT = clip->GetStartTime(); clipStartT = clip->GetStartTime();
clipEndT = clip->GetEndTime(); clipEndT = clip->GetEndTime();
if( clipEndT <= startT ) if( clipEndT <= startT )

View File

@ -112,9 +112,10 @@ bool EffectReverse::ProcessOneWave(int count, WaveTrack * track, sampleCount sta
// STEP 1: // STEP 1:
// If a reverse selection begins and/or ends at the inside of a clip // If a reverse selection begins and/or ends at the inside of a clip
// perform a split at the start and/or end of the reverse selection // perform a split at the start and/or end of the reverse selection
WaveClipList::compatibility_iterator node = track->GetClipIterator(); const auto &clips = track->GetClips();
while (node) { // Beware, the array grows as we loop over it. Use integer subscripts, not iterators.
WaveClip *clip = node->GetData(); for (int ii = 0; ii < clips.size(); ++ii) {
const auto &clip = clips[ii];
sampleCount clipStart = clip->GetStartSample(); sampleCount clipStart = clip->GetStartSample();
sampleCount clipEnd = clip->GetEndSample(); sampleCount clipEnd = clip->GetEndSample();
if (clipStart < start && clipEnd > start && clipEnd <= end) { // the reverse selection begins at the inside of a clip if (clipStart < start && clipEnd > start && clipEnd <= end) { // the reverse selection begins at the inside of a clip
@ -131,7 +132,6 @@ bool EffectReverse::ProcessOneWave(int count, WaveTrack * track, sampleCount sta
splitTime = track->LongSamplesToTime(end); splitTime = track->LongSamplesToTime(end);
track->SplitAt(splitTime); track->SplitAt(splitTime);
} }
node = node->GetNext();
} }
//STEP 2: //STEP 2:
@ -192,29 +192,26 @@ bool EffectReverse::ProcessOneWave(int count, WaveTrack * track, sampleCount sta
clip = track->RemoveAndReturnClip(clip); // detach the clip from track clip = track->RemoveAndReturnClip(clip); // detach the clip from track
clip->SetOffset(track->LongSamplesToTime(track->TimeToLongSamples(offsetStartTime))); // align time to a sample and set offset clip->SetOffset(track->LongSamplesToTime(track->TimeToLongSamples(offsetStartTime))); // align time to a sample and set offset
revClips.Append(clip); revClips.push_back(clip);
} }
} }
else if (clipStart >= end) { // clip is after the selection region else if (clipStart >= end) { // clip is after the selection region
clip = track->RemoveAndReturnClip(clip); // simply remove and append to otherClips clip = track->RemoveAndReturnClip(clip); // simply remove and append to otherClips
otherClips.Append(clip); otherClips.push_back(clip);
} }
} }
// STEP 3: Append the clips from // STEP 3: Append the clips from
// revClips and otherClips back to the track // revClips and otherClips back to the track
size_t revClipsCount = revClips.GetCount(); // the last clip of revClips is appended to the track first
for (i = 0; i < revClipsCount; i++) { // PRL: I don't think that matters, the sequence of storage of clips in the track
WaveClipList::compatibility_iterator node = revClips.Item(revClipsCount - 1 - i); // the last clip of revClips is appended to the track first // is not elsewhere assumed to be by time
WaveClip *clip = node->GetData(); for (auto it = revClips.rbegin(), end = revClips.rend(); it != end; ++it)
track->AddClip(clip); track->AddClip(*it);
}
for (i = 0; i < otherClips.GetCount(); i++) { for (const auto &clip : otherClips)
WaveClipList::compatibility_iterator node = otherClips.Item(i); track->AddClip(clip);
track->AddClip(node->GetData());
}
return rValue; return rValue;
} }

View File

@ -178,15 +178,11 @@ void ODComputeSummaryTask::Update()
{ {
if(mWaveTracks[j]) if(mWaveTracks[j])
{ {
WaveClip *clip;
BlockArray *blocks; BlockArray *blocks;
Sequence *seq; Sequence *seq;
//gather all the blockfiles that we should process in the wavetrack. //gather all the blockfiles that we should process in the wavetrack.
WaveClipList::compatibility_iterator node = mWaveTracks[j]->GetClipIterator(); for (const auto &clip : mWaveTracks[j]->GetClips()) {
while(node) {
clip = node->GetData();
seq = clip->GetSequence(); seq = clip->GetSequence();
//This lock may be way too big since the whole file is one sequence. //This lock may be way too big since the whole file is one sequence.
//TODO: test for large files and find a way to break it down. //TODO: test for large files and find a way to break it down.
@ -223,7 +219,6 @@ void ODComputeSummaryTask::Update()
tempBlocks.insert(tempBlocks.begin() + insertCursor++, odpcmaFile); tempBlocks.insert(tempBlocks.begin() + insertCursor++, odpcmaFile);
} }
} }
node = node->GetNext();
} }
} }
} }

View File

@ -136,15 +136,11 @@ void ODDecodeTask::Update()
{ {
if(mWaveTracks[j]) if(mWaveTracks[j])
{ {
WaveClip *clip;
BlockArray *blocks; BlockArray *blocks;
Sequence *seq; Sequence *seq;
//gather all the blockfiles that we should process in the wavetrack. //gather all the blockfiles that we should process in the wavetrack.
WaveClipList::compatibility_iterator node = mWaveTracks[j]->GetClipIterator(); for (const auto &clip : mWaveTracks[j]->GetClips()) {
while(node) {
clip = node->GetData();
seq = clip->GetSequence(); seq = clip->GetSequence();
//TODO:this lock is way to big since the whole file is one sequence. find a way to break it down. //TODO:this lock is way to big since the whole file is one sequence. find a way to break it down.
seq->LockDeleteUpdateMutex(); seq->LockDeleteUpdateMutex();
@ -179,7 +175,6 @@ void ODDecodeTask::Update()
} }
seq->UnlockDeleteUpdateMutex(); seq->UnlockDeleteUpdateMutex();
node = node->GetNext();
} }
} }
} }