mirror of
https://github.com/cookiengineer/audacity
synced 2025-05-18 14:14:57 +02:00
Minor refactoring for Track class
(cherry picked from audacity commit 96a4342e569e9a6d4158b3ec0729917de73a7cc5) Signed-off-by: akleja <storspov@gmail.com>
This commit is contained in:
parent
ddbd9ed0cd
commit
39d49be5b4
@ -196,14 +196,14 @@ void Track::DoSetLinked(bool l)
|
|||||||
mLinked = l;
|
mLinked = l;
|
||||||
}
|
}
|
||||||
|
|
||||||
Track *Track::GetLink() const
|
Track *Track::GetLinkedTrack() const
|
||||||
{
|
{
|
||||||
auto pList = mList.lock();
|
auto pList = mList.lock();
|
||||||
if (!pList)
|
if (!pList)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
if (!pList->isNull(mNode)) {
|
if (!pList->isNull(mNode)) {
|
||||||
if (mLinked) {
|
if (HasLinkedTrack()) {
|
||||||
auto next = pList->getNext( mNode );
|
auto next = pList->getNext( mNode );
|
||||||
if ( !pList->isNull( next ) )
|
if ( !pList->isNull( next ) )
|
||||||
return next.first->get();
|
return next.first->get();
|
||||||
@ -213,7 +213,7 @@ Track *Track::GetLink() const
|
|||||||
auto prev = pList->getPrev( mNode );
|
auto prev = pList->getPrev( mNode );
|
||||||
if ( !pList->isNull( prev ) ) {
|
if ( !pList->isNull( prev ) ) {
|
||||||
auto track = prev.first->get();
|
auto track = prev.first->get();
|
||||||
if (track && track->GetLinked())
|
if (track && track->HasLinkedTrack())
|
||||||
return track;
|
return track;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -222,6 +222,11 @@ Track *Track::GetLink() const
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Track::HasLinkedTrack() const noexcept
|
||||||
|
{
|
||||||
|
return mLinked;
|
||||||
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
inline bool IsSyncLockableNonLabelTrack( const Track *pTrack )
|
inline bool IsSyncLockableNonLabelTrack( const Track *pTrack )
|
||||||
{
|
{
|
||||||
@ -368,7 +373,9 @@ bool Track::IsSelectedOrSyncLockSelected() const
|
|||||||
{ return GetSelected() || IsSyncLockSelected(); }
|
{ return GetSelected() || IsSyncLockSelected(); }
|
||||||
|
|
||||||
bool Track::IsLeader() const
|
bool Track::IsLeader() const
|
||||||
{ return !GetLink() || GetLinked(); }
|
{
|
||||||
|
return !GetLinkedTrack() || HasLinkedTrack();
|
||||||
|
}
|
||||||
|
|
||||||
bool Track::IsSelectedLeader() const
|
bool Track::IsSelectedLeader() const
|
||||||
{ return IsSelected() && IsLeader(); }
|
{ return IsSelected() && IsLeader(); }
|
||||||
@ -378,7 +385,7 @@ void Track::FinishCopy
|
|||||||
{
|
{
|
||||||
if (dest) {
|
if (dest) {
|
||||||
dest->SetChannel(n->GetChannel());
|
dest->SetChannel(n->GetChannel());
|
||||||
dest->SetLinked(n->GetLinked());
|
dest->SetLinked(n->HasLinkedTrack());
|
||||||
dest->SetName(n->GetName());
|
dest->SetName(n->GetName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -389,30 +396,30 @@ bool Track::LinkConsistencyCheck()
|
|||||||
// doesn't fix the problem, but it likely leaves us with orphaned
|
// doesn't fix the problem, but it likely leaves us with orphaned
|
||||||
// sample blocks instead of much worse problems.
|
// sample blocks instead of much worse problems.
|
||||||
bool err = false;
|
bool err = false;
|
||||||
if (GetLinked())
|
if (HasLinkedTrack())
|
||||||
{
|
{
|
||||||
Track *l = GetLink();
|
auto link = GetLinkedTrack();
|
||||||
if (l)
|
if (link)
|
||||||
{
|
{
|
||||||
// A linked track's partner should never itself be linked
|
// A linked track's partner should never itself be linked
|
||||||
if (l->GetLinked())
|
if (link->HasLinkedTrack())
|
||||||
{
|
{
|
||||||
wxLogWarning(
|
wxLogWarning(
|
||||||
wxT("Left track %s had linked right track %s with extra right track link.\n Removing extra link from right track."),
|
wxT("Left track %s had linked right track %s with extra right track link.\n Removing extra link from right track."),
|
||||||
GetName(), l->GetName());
|
GetName(), link->GetName());
|
||||||
err = true;
|
err = true;
|
||||||
l->SetLinked(false);
|
link->SetLinked(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Channels should be left and right
|
// Channels should be left and right
|
||||||
if ( !( (GetChannel() == Track::LeftChannel &&
|
if ( !( (GetChannel() == Track::LeftChannel &&
|
||||||
l->GetChannel() == Track::RightChannel) ||
|
link->GetChannel() == Track::RightChannel) ||
|
||||||
(GetChannel() == Track::RightChannel &&
|
(GetChannel() == Track::RightChannel &&
|
||||||
l->GetChannel() == Track::LeftChannel) ) )
|
link->GetChannel() == Track::LeftChannel) ) )
|
||||||
{
|
{
|
||||||
wxLogWarning(
|
wxLogWarning(
|
||||||
wxT("Track %s and %s had left/right track links out of order. Setting tracks to not be linked."),
|
wxT("Track %s and %s had left/right track links out of order. Setting tracks to not be linked."),
|
||||||
GetName(), l->GetName());
|
GetName(), link->GetName());
|
||||||
err = true;
|
err = true;
|
||||||
SetLinked(false);
|
SetLinked(false);
|
||||||
}
|
}
|
||||||
@ -718,9 +725,9 @@ void TrackList::GroupChannels(
|
|||||||
;
|
;
|
||||||
if ( count == 0 ) {
|
if ( count == 0 ) {
|
||||||
auto unlink = [&] ( Track &tr ) {
|
auto unlink = [&] ( Track &tr ) {
|
||||||
if ( tr.GetLinked() ) {
|
if ( tr.HasLinkedTrack() ) {
|
||||||
if ( resetChannels ) {
|
if ( resetChannels ) {
|
||||||
auto link = tr.GetLink();
|
auto link = tr.GetLinkedTrack();
|
||||||
if ( link )
|
if ( link )
|
||||||
link->SetChannel( Track::MonoChannel );
|
link->SetChannel( Track::MonoChannel );
|
||||||
}
|
}
|
||||||
@ -826,7 +833,7 @@ Track *TrackList::GetNext(Track * t, bool linked) const
|
|||||||
if (t) {
|
if (t) {
|
||||||
auto node = t->GetNode();
|
auto node = t->GetNode();
|
||||||
if ( !isNull( node ) ) {
|
if ( !isNull( node ) ) {
|
||||||
if ( linked && t->GetLinked() )
|
if ( linked && t->HasLinkedTrack() )
|
||||||
node = getNext( node );
|
node = getNext( node );
|
||||||
|
|
||||||
if ( !isNull( node ) )
|
if ( !isNull( node ) )
|
||||||
@ -850,7 +857,7 @@ Track *TrackList::GetPrev(Track * t, bool linked) const
|
|||||||
if (linked) {
|
if (linked) {
|
||||||
prev = getPrev( node );
|
prev = getPrev( node );
|
||||||
if( !isNull( prev ) &&
|
if( !isNull( prev ) &&
|
||||||
!t->GetLinked() && t->GetLink() )
|
!t->HasLinkedTrack() && t->GetLinkedTrack() )
|
||||||
// Make it the first
|
// Make it the first
|
||||||
node = prev;
|
node = prev;
|
||||||
}
|
}
|
||||||
@ -864,7 +871,7 @@ Track *TrackList::GetPrev(Track * t, bool linked) const
|
|||||||
if (linked) {
|
if (linked) {
|
||||||
prev = getPrev( node );
|
prev = getPrev( node );
|
||||||
if( !isNull( prev ) &&
|
if( !isNull( prev ) &&
|
||||||
!(*node.first)->GetLinked() && (*node.first)->GetLink() )
|
!(*node.first)->HasLinkedTrack() && (*node.first)->GetLinkedTrack() )
|
||||||
node = prev;
|
node = prev;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1068,7 +1075,7 @@ void TrackList::UpdatePendingTracks()
|
|||||||
if (pendingTrack && src) {
|
if (pendingTrack && src) {
|
||||||
if (updater)
|
if (updater)
|
||||||
updater( *pendingTrack, *src );
|
updater( *pendingTrack, *src );
|
||||||
pendingTrack->DoSetLinked(src->GetLinked());
|
pendingTrack->DoSetLinked(src->HasLinkedTrack());
|
||||||
}
|
}
|
||||||
++pUpdater;
|
++pUpdater;
|
||||||
}
|
}
|
||||||
|
@ -367,12 +367,14 @@ public:
|
|||||||
std::shared_ptr<TrackList> GetOwner() const { return mList.lock(); }
|
std::shared_ptr<TrackList> GetOwner() const { return mList.lock(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Track *GetLink() const;
|
|
||||||
bool GetLinked () const { return mLinked; }
|
Track* GetLinkedTrack() const;
|
||||||
|
//! Returns true for leaders of multichannel groups
|
||||||
|
bool HasLinkedTrack() const noexcept;
|
||||||
|
|
||||||
friend WaveTrack; // WaveTrack needs to call SetLinked when reloading project
|
friend WaveTrack; // WaveTrack needs to call SetLinked when reloading project
|
||||||
void SetLinked (bool l);
|
void SetLinked (bool l);
|
||||||
|
|
||||||
void SetChannel(ChannelType c) { mChannel = c; }
|
void SetChannel(ChannelType c) { mChannel = c; }
|
||||||
private:
|
private:
|
||||||
// No need yet to make this virtual
|
// No need yet to make this virtual
|
||||||
|
Loading…
x
Reference in New Issue
Block a user