1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-09-17 16:50:26 +02:00

Iterate over all clips of a track, including cutlines, where needed

This commit is contained in:
Paul Licameli 2016-08-13 16:06:00 -04:00
parent 6909bdf398
commit 84a6456788
5 changed files with 78 additions and 5 deletions

View File

@ -63,7 +63,7 @@ static void GetAllSeqBlocks(AudacityProject *project,
while (t) { while (t) {
if (t->GetKind() == Track::Wave) { if (t->GetKind() == Track::Wave) {
WaveTrack *waveTrack = static_cast<WaveTrack*>(t); WaveTrack *waveTrack = static_cast<WaveTrack*>(t);
for(const auto &clip : waveTrack->GetClips()) { for(const auto &clip : waveTrack->GetAllClips()) {
Sequence *sequence = clip->GetSequence(); Sequence *sequence = clip->GetSequence();
BlockArray &blocks = sequence->GetBlockArray(); BlockArray &blocks = sequence->GetBlockArray();
int i; int i;

View File

@ -94,7 +94,7 @@ void UndoManager::CalculateSpaceUsage()
while (wt) while (wt)
{ {
// Scan all clips within current track // Scan all clips within current track
for(const auto &clip: wt->GetClips()) for(const auto &clip : wt->GetAllClips())
{ {
// Scan all blockfiles within current clip // Scan all blockfiles within current clip
BlockArray *blocks = clip->GetSequenceBlockArray(); BlockArray *blocks = clip->GetSequenceBlockArray();

View File

@ -333,11 +333,84 @@ 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. // Get access to the (visible) clips in the tracks, in unspecified order
// (not necessarioy sequenced in time).
WaveClipHolders &GetClips() { return mClips; } WaveClipHolders &GetClips() { return mClips; }
const WaveClipConstHolders &GetClips() const const WaveClipConstHolders &GetClips() const
{ return reinterpret_cast< const WaveClipConstHolders& >( mClips ); } { return reinterpret_cast< const WaveClipConstHolders& >( mClips ); }
// Get access to all clips (in some unspecified sequence),
// including those hidden in cutlines.
class AllClipsIterator
: public std::iterator< std::forward_iterator_tag, WaveClip* >
{
public:
// Constructs an "end" iterator
AllClipsIterator () {}
// Construct a "begin" iterator
explicit AllClipsIterator( WaveTrack &track )
{
push( track.mClips );
}
WaveClip *operator * () const
{
if (mStack.empty())
return nullptr;
else
return mStack.back().first->get();
}
AllClipsIterator &operator ++ ()
{
// The unspecified sequence is a post-order, but there is no
// promise whether sister nodes are ordered in time.
if ( !mStack.empty() ) {
auto &pair = mStack.back();
if ( ++pair.first == pair.second ) {
mStack.pop_back();
}
else
push( (*pair.first)->GetCutLines() );
}
return *this;
}
// Define == well enough to serve for loop termination test
friend bool operator ==
(const AllClipsIterator &a, const AllClipsIterator &b)
{ return a.mStack.empty() == b.mStack.empty(); }
friend bool operator !=
(const AllClipsIterator &a, const AllClipsIterator &b)
{ return !( a == b ); }
private:
void push( WaveClipHolders &clips )
{
auto pClips = &clips;
while (!pClips->empty()) {
auto first = pClips->begin();
mStack.push_back( Pair( first, pClips->end() ) );
pClips = &(*first)->GetCutLines();
}
}
using Iterator = WaveClipHolders::iterator;
using Pair = std::pair< Iterator, Iterator >;
using Stack = std::vector< Pair >;
Stack mStack;
};
IteratorRange< AllClipsIterator > GetAllClips()
{
return { AllClipsIterator{ *this }, AllClipsIterator{ } };
}
// Create NEW clip and add it to this track. Returns a pointer // Create NEW clip and add it to this track. Returns a pointer
// to the newly created clip. // to the newly created clip.
WaveClip* CreateClip(); WaveClip* CreateClip();

View File

@ -182,7 +182,7 @@ void ODComputeSummaryTask::Update()
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.
for (const auto &clip : mWaveTracks[j]->GetClips()) { for (const auto &clip : mWaveTracks[j]->GetAllClips()) {
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.

View File

@ -140,7 +140,7 @@ void ODDecodeTask::Update()
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.
for (const auto &clip : mWaveTracks[j]->GetClips()) { for (const auto &clip : mWaveTracks[j]->GetAllClips()) {
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();