diff --git a/src/CrossFade.cpp b/src/CrossFade.cpp index d959828be..f61a19f08 100644 --- a/src/CrossFade.cpp +++ b/src/CrossFade.cpp @@ -73,12 +73,6 @@ bool CrossFader::CrossFadeMix(samplePtr buffer, sampleFormat format, sampleCount //we should use one of the size len, because this has already //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. //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; //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(); diff --git a/src/Dependencies.cpp b/src/Dependencies.cpp index 4c489a679..0e59e73e5 100644 --- a/src/Dependencies.cpp +++ b/src/Dependencies.cpp @@ -62,16 +62,13 @@ static void GetAllSeqBlocks(AudacityProject *project, Track *t = iter.First(); while (t) { if (t->GetKind() == Track::Wave) { - WaveTrack *waveTrack = (WaveTrack *)t; - WaveClipList::compatibility_iterator node = waveTrack->GetClipIterator(); - while(node) { - WaveClip *clip = node->GetData(); + WaveTrack *waveTrack = static_cast(t); + for(const auto &clip : waveTrack->GetClips()) { Sequence *sequence = clip->GetSequence(); BlockArray &blocks = sequence->GetBlockArray(); int i; for (i = 0; i < (int)blocks.size(); i++) outBlocks->push_back(&blocks[i]); - node = node->GetNext(); } } t = iter.Next(); diff --git a/src/Project.cpp b/src/Project.cpp index 55f1063de..39ab6bbad 100644 --- a/src/Project.cpp +++ b/src/Project.cpp @@ -1230,14 +1230,9 @@ void AudacityProject::RedrawProject(const bool bForceWaveTracks /*= false*/) { if (pTrack->GetKind() == Track::Wave) { - WaveTrack* pWaveTrack = (WaveTrack*)pTrack; - WaveClipList::compatibility_iterator node = pWaveTrack->GetClipIterator(); - while (node) - { - WaveClip *clip = node->GetData(); + WaveTrack* pWaveTrack = static_cast(pTrack); + for (const auto &clip: pWaveTrack->GetClips()) clip->MarkChanged(); - node = node->GetNext(); - } } pTrack = iter.Next(); } @@ -2954,10 +2949,8 @@ void AudacityProject::OpenFile(const wxString &fileNameArg, bool addtohistory) if (t->GetKind() == Track::Wave) { // Only wave tracks have a notion of "changed". - for (WaveClipList::compatibility_iterator clipIter = ((WaveTrack*)t)->GetClipIterator(); - clipIter; - clipIter=clipIter->GetNext()) - clipIter->GetData()->MarkChanged(); + for (const auto &clip: static_cast(t)->GetClips()) + clip->MarkChanged(); } t = iter.Next(); } diff --git a/src/Snap.cpp b/src/Snap.cpp index a6a2c88c9..6ec7d34dd 100644 --- a/src/Snap.cpp +++ b/src/Snap.cpp @@ -128,11 +128,9 @@ void SnapManager::Reinit() } else if (track->GetKind() == Track::Wave) { - WaveTrack *waveTrack = (WaveTrack *)track; - WaveClipList::compatibility_iterator it; - for (it = waveTrack->GetClipIterator(); it; it = it->GetNext()) + WaveTrack *waveTrack = static_cast(track); + for (const auto &clip: waveTrack->GetClips()) { - WaveClip *clip = it->GetData(); if (mClipExclusions) { bool skip = false; diff --git a/src/TrackArtist.cpp b/src/TrackArtist.cpp index bceb6353f..723f45a42 100644 --- a/src/TrackArtist.cpp +++ b/src/TrackArtist.cpp @@ -450,9 +450,9 @@ void TrackArtist::DrawTrack(const Track * t, switch (t->GetKind()) { case Track::Wave: { - WaveTrack* wt = (WaveTrack*)t; - for (WaveClipList::compatibility_iterator it=wt->GetClipIterator(); it; it=it->GetNext()) { - it->GetData()->ClearDisplayRect(); + const WaveTrack* wt = static_cast(t); + for (const auto &clip : wt->GetClips()) { + clip->ClearDisplayRect(); } bool muted = (hasSolo || t->GetMute()) && !t->GetSolo(); @@ -1471,9 +1471,8 @@ void TrackArtist::DrawWaveform(const WaveTrack *track, DrawBackgroundWithSelection(&dc, rect, track, blankSelectedBrush, blankBrush, selectedRegion, zoomInfo); - for (WaveClipList::compatibility_iterator it = - const_cast(track)->GetClipIterator(); it; it = it->GetNext()) - DrawClipWaveform(track, it->GetData(), dc, rect, selectedRegion, zoomInfo, + for (const auto &clip: track->GetClips()) + DrawClipWaveform(track, clip, dc, rect, selectedRegion, zoomInfo, drawEnvelope, bigPoints, dB, muted); @@ -2011,9 +2010,8 @@ void TrackArtist::DrawSpectrum(const WaveTrack *track, selectedRegion, zoomInfo); WaveTrackCache cache(track); - for (WaveClipList::compatibility_iterator it = - const_cast(track)->GetClipIterator(); it; it = it->GetNext()) { - DrawClipSpectrum(cache, it->GetData(), dc, rect, selectedRegion, zoomInfo); + for (const auto &clip: track->GetClips()) { + DrawClipSpectrum(cache, clip, dc, rect, selectedRegion, zoomInfo); } } diff --git a/src/TrackPanel.cpp b/src/TrackPanel.cpp index bb8f488c3..a4fde3c55 100644 --- a/src/TrackPanel.cpp +++ b/src/TrackPanel.cpp @@ -3422,12 +3422,8 @@ void TrackPanel::AddClipsToCaptured(Track *t, double t0, double t1) { if (t->GetKind() == Track::Wave) { - WaveClipList::compatibility_iterator it = - ((WaveTrack *)t)->GetClipIterator(); - while (it) + for(const auto &clip: static_cast(t)->GetClips()) { - WaveClip *clip = it->GetData(); - if ( ! clip->AfterClip(t0) && ! clip->BeforeClip(t1) ) { // Avoid getting clips that were already captured @@ -3442,7 +3438,6 @@ void TrackPanel::AddClipsToCaptured(Track *t, double t0, double t1) if (newClip) mCapturedClipArray.push_back(TrackClip(t, clip)); } - it = it->GetNext(); } } else diff --git a/src/UndoManager.cpp b/src/UndoManager.cpp index 19ef54e70..3f18d9aba 100644 --- a/src/UndoManager.cpp +++ b/src/UndoManager.cpp @@ -94,11 +94,10 @@ void UndoManager::CalculateSpaceUsage() while (wt) { // Scan all clips within current track - WaveClipList::compatibility_iterator it = wt->GetClipIterator(); - while (it) + for(const auto &clip: wt->GetClips()) { // Scan all blockfiles within current clip - BlockArray *blocks = it->GetData()->GetSequenceBlockArray(); + BlockArray *blocks = clip->GetSequenceBlockArray(); for (const auto &block : *blocks) { BlockFile *file = block.f; @@ -113,8 +112,6 @@ void UndoManager::CalculateSpaceUsage() // Add file to current set cur->insert(file); } - - it = it->GetNext(); } wt = (WaveTrack *) iter.Next(); diff --git a/src/WaveTrack.cpp b/src/WaveTrack.cpp index 376d227bb..c275ce22b 100644 --- a/src/WaveTrack.cpp +++ b/src/WaveTrack.cpp @@ -2631,9 +2631,8 @@ void WaveTrack::FillSortedClipArray(WaveClipArray& clips) const { clips.Empty(); - for (WaveClipList::compatibility_iterator it = - const_cast(this)->GetClipIterator(); it; it=it->GetNext()) - clips.Add(it->GetData()); + for (const auto &clip: GetClips()) + clips.Add(clip); clips.Sort(SortClipArrayCmpFunc); } diff --git a/src/WaveTrack.h b/src/WaveTrack.h index b40dedb9a..c709949c1 100644 --- a/src/WaveTrack.h +++ b/src/WaveTrack.h @@ -333,9 +333,9 @@ class AUDACITY_DLL_API WaveTrack final : public Track { */ double LongSamplesToTime(sampleCount pos) const; - // Get access to the clips in the tracks. This is used by - // track artists and also by TrackPanel when sliding...it would - // be cleaner if this could be removed, though... + // Get access to the clips in the tracks. + const WaveClipList &GetClips() const { return mClips; } + WaveClipList::compatibility_iterator GetClipIterator() { return mClips.GetFirst(); } // Create NEW clip and add it to this track. Returns a pointer diff --git a/src/effects/Equalization.cpp b/src/effects/Equalization.cpp index 1cca30bf7..80252128a 100644 --- a/src/effects/Equalization.cpp +++ b/src/effects/Equalization.cpp @@ -1162,13 +1162,11 @@ bool EffectEqualization::ProcessOne(int count, WaveTrack * t, //Find the bits of clips that need replacing std::vector > clipStartEndTimes; std::vector > 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 clipEndT; - clip = it->GetData(); clipStartT = clip->GetStartTime(); clipEndT = clip->GetEndTime(); if( clipEndT <= startT ) diff --git a/src/effects/Equalization48x.cpp b/src/effects/Equalization48x.cpp index e844ea253..b7799d7da 100644 --- a/src/effects/Equalization48x.cpp +++ b/src/effects/Equalization48x.cpp @@ -520,13 +520,11 @@ bool EffectEqualization48x::ProcessTail(WaveTrack * t, WaveTrack * output, sampl //Find the bits of clips that need replacing std::vector > clipStartEndTimes; std::vector > 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 clipEndT; - clip = it->GetData(); clipStartT = clip->GetStartTime(); clipEndT = clip->GetEndTime(); if( clipEndT <= startT ) diff --git a/src/effects/Reverse.cpp b/src/effects/Reverse.cpp index 089bd4c4d..7f5d2bd73 100644 --- a/src/effects/Reverse.cpp +++ b/src/effects/Reverse.cpp @@ -112,9 +112,10 @@ bool EffectReverse::ProcessOneWave(int count, WaveTrack * track, sampleCount sta // STEP 1: // 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 - WaveClipList::compatibility_iterator node = track->GetClipIterator(); - while (node) { - WaveClip *clip = node->GetData(); + const auto &clips = track->GetClips(); + // Beware, the array grows as we loop over it. Use integer subscripts, not iterators. + for (int ii = 0; ii < clips.size(); ++ii) { + const auto &clip = clips[ii]; sampleCount clipStart = clip->GetStartSample(); sampleCount clipEnd = clip->GetEndSample(); 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); track->SplitAt(splitTime); } - node = node->GetNext(); } //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->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 clip = track->RemoveAndReturnClip(clip); // simply remove and append to otherClips - otherClips.Append(clip); + otherClips.push_back(clip); } } // STEP 3: Append the clips from // revClips and otherClips back to the track - size_t revClipsCount = revClips.GetCount(); - for (i = 0; i < revClipsCount; i++) { - WaveClipList::compatibility_iterator node = revClips.Item(revClipsCount - 1 - i); // the last clip of revClips is appended to the track first - WaveClip *clip = node->GetData(); - track->AddClip(clip); - } + // the last clip of revClips is appended to the track first + // PRL: I don't think that matters, the sequence of storage of clips in the track + // is not elsewhere assumed to be by time + for (auto it = revClips.rbegin(), end = revClips.rend(); it != end; ++it) + track->AddClip(*it); - for (i = 0; i < otherClips.GetCount(); i++) { - WaveClipList::compatibility_iterator node = otherClips.Item(i); - track->AddClip(node->GetData()); - } + for (const auto &clip : otherClips) + track->AddClip(clip); return rValue; } diff --git a/src/ondemand/ODComputeSummaryTask.cpp b/src/ondemand/ODComputeSummaryTask.cpp index 7a78101fe..88a2dfad1 100644 --- a/src/ondemand/ODComputeSummaryTask.cpp +++ b/src/ondemand/ODComputeSummaryTask.cpp @@ -178,15 +178,11 @@ void ODComputeSummaryTask::Update() { if(mWaveTracks[j]) { - WaveClip *clip; BlockArray *blocks; Sequence *seq; //gather all the blockfiles that we should process in the wavetrack. - WaveClipList::compatibility_iterator node = mWaveTracks[j]->GetClipIterator(); - - while(node) { - clip = node->GetData(); + for (const auto &clip : mWaveTracks[j]->GetClips()) { seq = clip->GetSequence(); //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. @@ -223,7 +219,6 @@ void ODComputeSummaryTask::Update() tempBlocks.insert(tempBlocks.begin() + insertCursor++, odpcmaFile); } } - node = node->GetNext(); } } } diff --git a/src/ondemand/ODDecodeTask.cpp b/src/ondemand/ODDecodeTask.cpp index d75fec73b..eac9b1c7f 100644 --- a/src/ondemand/ODDecodeTask.cpp +++ b/src/ondemand/ODDecodeTask.cpp @@ -136,15 +136,11 @@ void ODDecodeTask::Update() { if(mWaveTracks[j]) { - WaveClip *clip; BlockArray *blocks; Sequence *seq; //gather all the blockfiles that we should process in the wavetrack. - WaveClipList::compatibility_iterator node = mWaveTracks[j]->GetClipIterator(); - - while(node) { - clip = node->GetData(); + for (const auto &clip : mWaveTracks[j]->GetClips()) { seq = clip->GetSequence(); //TODO:this lock is way to big since the whole file is one sequence. find a way to break it down. seq->LockDeleteUpdateMutex(); @@ -179,7 +175,6 @@ void ODDecodeTask::Update() } seq->UnlockDeleteUpdateMutex(); - node = node->GetNext(); } } }