diff --git a/libraries/lib-track/PendingTracks.cpp b/libraries/lib-track/PendingTracks.cpp index e115d3ea3c48..df6b6c6ef73f 100644 --- a/libraries/lib-track/PendingTracks.cpp +++ b/libraries/lib-track/PendingTracks.cpp @@ -51,7 +51,7 @@ PendingTracks::~PendingTracks() = default; void PendingTracks::RegisterPendingNewTracks(TrackList &&list) { - mTracks.RegisterPendingNewTracks(std::move(list)); + mTracks.Append(std::move(list), false); } namespace { diff --git a/libraries/lib-track/Track.cpp b/libraries/lib-track/Track.cpp index b88f04fac2ff..9cdb941a2aaa 100644 --- a/libraries/lib-track/Track.cpp +++ b/libraries/lib-track/Track.cpp @@ -605,7 +605,7 @@ Track *TrackList::DoAddToHead(const std::shared_ptr &t) return front().get(); } -Track *TrackList::DoAdd(const std::shared_ptr &t) +Track *TrackList::DoAdd(const std::shared_ptr &t, bool assignIds) { if (!ListOfTracks::empty()) { auto &pLast = *ListOfTracks::rbegin(); @@ -624,7 +624,7 @@ Track *TrackList::DoAdd(const std::shared_ptr &t) auto n = getPrev( getEnd() ); t->SetOwner(shared_from_this(), n); - if (mAssignsIds) + if (mAssignsIds && assignIds) t->SetId(TrackId{ ++sCounter }); RecalcPositions(n); AdditionEvent(n); @@ -1316,24 +1316,14 @@ TrackListHolder TrackList::Temporary(AudacityProject *pProject, return tempList; } -void TrackList::Append(TrackList &&list) +void TrackList::Append(TrackList &&list, bool assignIds) { auto iter = list.ListOfTracks::begin(), end = list.ListOfTracks::end(); while (iter != end) { auto pTrack = *iter; iter = list.erase(iter); - this->Add(pTrack); - } -} - -void TrackList::RegisterPendingNewTracks(TrackList&& list) -{ - for(auto it = list.ListOfTracks::begin(); it != list.ListOfTracks::end();) - { - Add(*it); - (*it)->SetId({}); - it = list.erase(it); + this->Add(pTrack, assignIds); } } diff --git a/libraries/lib-track/Track.h b/libraries/lib-track/Track.h index 453b23b6fb6f..88775801e649 100644 --- a/libraries/lib-track/Track.h +++ b/libraries/lib-track/Track.h @@ -1118,7 +1118,7 @@ class TRACK_API TrackList final private: Track *DoAddToHead(const std::shared_ptr &t); - Track *DoAdd(const std::shared_ptr &t); + Track *DoAdd(const std::shared_ptr &t, bool assignIds); template< typename TrackType, typename InTrackType > static TrackIterRange< TrackType > @@ -1175,14 +1175,17 @@ class TRACK_API TrackList final Track *FindById( TrackId id ); - /// Add a Track, giving it a fresh id + /// Add a Track, giving it a fresh id if `this` is not temporary template - TrackKind *AddToHead( const std::shared_ptr< TrackKind > &t ) - { return static_cast< TrackKind* >( DoAddToHead( t ) ); } + TrackKind *AddToHead( const std::shared_ptr &t ) + { return static_cast(DoAddToHead(t)); } + /// Add a Track, giving it a fresh id if `this` is not temporary and + /// assignIds is true template - TrackKind *Add( const std::shared_ptr< TrackKind > &t ) - { return static_cast< TrackKind* >( DoAdd( t ) ); } + TrackKind *Add(const std::shared_ptr &t, + bool assignIds = true) + { return static_cast(DoAdd(t, assignIds)); } //! Removes linkage if track belongs to a group std::vector UnlinkChannels(Track& track); @@ -1280,16 +1283,11 @@ class TRACK_API TrackList final } //! Remove all tracks from `list` and put them at the end of `this` - void Append(TrackList &&list); - - // Like RegisterPendingChangedTrack, but for a list of new tracks, - // not a replacement track. Caller - // supplies the list, and there are no updates. - // Pending tracks will have an unassigned TrackId. - // Pending new tracks WILL occur in iterations, always after actual - // tracks, and in the sequence that they were added. They can be - // distinguished from actual tracks by TrackId. - void RegisterPendingNewTracks(TrackList &&list); + /*! + @param assignIds ignored if `this` is a temporary list; else if false, + suppresses TrackId assignment + */ + void Append(TrackList &&list, bool assignIds = true); //! Remove first channel group (if any) from `list` and put it at the end of //! `this`