mirror of
https://github.com/cookiengineer/audacity
synced 2025-08-06 07:09:39 +02:00
Consistency among the methods of SyncLockedTracksIterator...
A sync-lock group is a maximal sub-sequence of the tracks, containing: one or more wave tracks (and/or Note tracks, if MIDI is enabled), and zero or more label tracks. (These are not exhaustive of all of the types of tracks.) So redefine Next(), Prev(), and Last() carefully to implement this intention.
This commit is contained in:
parent
f296c768d5
commit
c439ceba03
@ -578,11 +578,26 @@ SyncLockedTracksIterator::SyncLockedTracksIterator(TrackList * val)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
bool IsSyncLockableNonLabelTrack( const Track *pTrack )
|
||||||
|
{
|
||||||
|
if ( pTrack->GetKind() == Track::Wave )
|
||||||
|
return true;
|
||||||
|
#ifdef USE_MIDI
|
||||||
|
else if ( pTrack->GetKind() == Track::Note )
|
||||||
|
return true;
|
||||||
|
#endif
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Track *SyncLockedTracksIterator::StartWith(Track * member)
|
Track *SyncLockedTracksIterator::StartWith(Track * member)
|
||||||
{
|
{
|
||||||
Track *t = NULL;
|
Track *t = NULL;
|
||||||
|
|
||||||
// A sync-locked group consists of any positive number of wave tracks followed by any
|
// A sync-locked group consists of any positive number of wave (or note)
|
||||||
|
// tracks followed by any
|
||||||
// non-negative number of label tracks. Step back through any label tracks,
|
// non-negative number of label tracks. Step back through any label tracks,
|
||||||
// and then through the wave tracks above them.
|
// and then through the wave tracks above them.
|
||||||
|
|
||||||
@ -590,11 +605,7 @@ Track *SyncLockedTracksIterator::StartWith(Track * member)
|
|||||||
member = l->GetPrev(member);
|
member = l->GetPrev(member);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (member && (member->GetKind() == Track::Wave
|
while (member && IsSyncLockableNonLabelTrack(member)) {
|
||||||
#ifdef USE_MIDI
|
|
||||||
|| member->GetKind() == Track::Note
|
|
||||||
#endif
|
|
||||||
)) {
|
|
||||||
t = member;
|
t = member;
|
||||||
member = l->GetPrev(member);
|
member = l->GetPrev(member);
|
||||||
}
|
}
|
||||||
@ -609,33 +620,38 @@ Track *SyncLockedTracksIterator::StartWith(Track * member)
|
|||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SyncLockedTracksIterator::IsGoodNextTrack(const Track *t) const
|
||||||
|
{
|
||||||
|
if (!t)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const bool isLabel = ( t->GetKind() == Track::Label );
|
||||||
|
const bool isSyncLockable = IsSyncLockableNonLabelTrack( t );
|
||||||
|
|
||||||
|
if ( !( isLabel || isSyncLockable ) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mInLabelSection && !isLabel) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
Track *SyncLockedTracksIterator::Next(bool skiplinked)
|
Track *SyncLockedTracksIterator::Next(bool skiplinked)
|
||||||
{
|
{
|
||||||
Track *t = TrackListIterator::Next(skiplinked);
|
Track *t = TrackListIterator::Next(skiplinked);
|
||||||
|
|
||||||
//
|
|
||||||
// Ways to end a sync-locked group
|
|
||||||
//
|
|
||||||
|
|
||||||
// End of tracks
|
|
||||||
if (!t)
|
if (!t)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
// In the label section, encounter a non-label track
|
if ( ! IsGoodNextTrack(t) ) {
|
||||||
if (mInLabelSection && t->GetKind() != Track::Label) {
|
|
||||||
l->setNull(cur);
|
l->setNull(cur);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
// This code block stops a group when a NoteTrack is encountered
|
|
||||||
#ifndef USE_MIDI
|
mInLabelSection = ( t->GetKind() == Track::Label );
|
||||||
// Encounter a non-wave non-label track
|
|
||||||
if (t->GetKind() != Track::Wave && t->GetKind() != Track::Label) {
|
|
||||||
l->setNull(cur);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
// Otherwise, check if we're in the label section
|
|
||||||
mInLabelSection = (t->GetKind() == Track::Label);
|
|
||||||
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
@ -652,20 +668,20 @@ Track *SyncLockedTracksIterator::Prev(bool skiplinked)
|
|||||||
if (!t)
|
if (!t)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
// In wave section, encounter a label track
|
const bool isLabel = ( t->GetKind() == Track::Label );
|
||||||
if (!mInLabelSection && t->GetKind() == Track::Label) {
|
const bool isSyncLockable = IsSyncLockableNonLabelTrack( t );
|
||||||
|
|
||||||
|
if ( !( isLabel || isSyncLockable ) ) {
|
||||||
l->setNull(cur);
|
l->setNull(cur);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
#ifndef USE_MIDI
|
|
||||||
// Encounter a non-wave non-label track
|
if ( !mInLabelSection && isLabel ) {
|
||||||
if (t->GetKind() != Track::Wave && t->GetKind() != Track::Label) {
|
|
||||||
l->setNull(cur);
|
l->setNull(cur);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
// Otherwise, check if we're in the label section
|
mInLabelSection = isLabel;
|
||||||
mInLabelSection = (t->GetKind() == Track::Label);
|
|
||||||
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
@ -677,18 +693,9 @@ Track *SyncLockedTracksIterator::Last(bool skiplinked)
|
|||||||
|
|
||||||
Track *t = cur->get();
|
Track *t = cur->get();
|
||||||
|
|
||||||
while (l->GetNext(t)) {
|
while (const auto next = l->GetNext(t, skiplinked)) {
|
||||||
// Check if this is the last track in the sync-locked group.
|
if ( ! IsGoodNextTrack(next) )
|
||||||
int nextKind = l->GetNext(t)->GetKind();
|
|
||||||
if (mInLabelSection && nextKind != Track::Label)
|
|
||||||
break;
|
break;
|
||||||
if (nextKind != Track::Label && nextKind != Track::Wave
|
|
||||||
#ifdef USE_MIDI
|
|
||||||
&& nextKind != Track::Note
|
|
||||||
#endif
|
|
||||||
)
|
|
||||||
break;
|
|
||||||
|
|
||||||
t = Next(skiplinked);
|
t = Next(skiplinked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -382,6 +382,7 @@ class AUDACITY_DLL_API SyncLockedTracksIterator final : public TrackListIterator
|
|||||||
Track *Last(bool skiplinked = false) override;
|
Track *Last(bool skiplinked = false) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool IsGoodNextTrack(const Track *t) const;
|
||||||
bool mInLabelSection;
|
bool mInLabelSection;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user