Skip to content

Commit

Permalink
Eliminate TrackList::RegisterPendingNewTracks
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Licameli committed Oct 23, 2023
1 parent f27c3e1 commit 88c28db
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 31 deletions.
2 changes: 1 addition & 1 deletion libraries/lib-track/PendingTracks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ PendingTracks::~PendingTracks() = default;

void PendingTracks::RegisterPendingNewTracks(TrackList &&list)
{
mTracks.RegisterPendingNewTracks(std::move(list));
mTracks.Append(std::move(list), false);
}

namespace {
Expand Down
18 changes: 4 additions & 14 deletions libraries/lib-track/Track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ Track *TrackList::DoAddToHead(const std::shared_ptr<Track> &t)
return front().get();
}

Track *TrackList::DoAdd(const std::shared_ptr<Track> &t)
Track *TrackList::DoAdd(const std::shared_ptr<Track> &t, bool assignIds)
{
if (!ListOfTracks::empty()) {
auto &pLast = *ListOfTracks::rbegin();
Expand All @@ -624,7 +624,7 @@ Track *TrackList::DoAdd(const std::shared_ptr<Track> &t)
auto n = getPrev( getEnd() );

t->SetOwner(shared_from_this(), n);
if (mAssignsIds)
if (mAssignsIds && assignIds)
t->SetId(TrackId{ ++sCounter });
RecalcPositions(n);
AdditionEvent(n);
Expand Down Expand Up @@ -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);
}
}

Expand Down
30 changes: 14 additions & 16 deletions libraries/lib-track/Track.h
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ class TRACK_API TrackList final

private:
Track *DoAddToHead(const std::shared_ptr<Track> &t);
Track *DoAdd(const std::shared_ptr<Track> &t);
Track *DoAdd(const std::shared_ptr<Track> &t, bool assignIds);

template< typename TrackType, typename InTrackType >
static TrackIterRange< TrackType >
Expand Down Expand Up @@ -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<typename TrackKind>
TrackKind *AddToHead( const std::shared_ptr< TrackKind > &t )
{ return static_cast< TrackKind* >( DoAddToHead( t ) ); }
TrackKind *AddToHead( const std::shared_ptr<TrackKind> &t )
{ return static_cast<TrackKind*>(DoAddToHead(t)); }

/// Add a Track, giving it a fresh id if `this` is not temporary and
/// assignIds is true
template<typename TrackKind>
TrackKind *Add( const std::shared_ptr< TrackKind > &t )
{ return static_cast< TrackKind* >( DoAdd( t ) ); }
TrackKind *Add(const std::shared_ptr<TrackKind> &t,
bool assignIds = true)
{ return static_cast<TrackKind*>(DoAdd(t, assignIds)); }

//! Removes linkage if track belongs to a group
std::vector<Track*> UnlinkChannels(Track& track);
Expand Down Expand Up @@ -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`
Expand Down

0 comments on commit 88c28db

Please sign in to comment.