17 return std::make_shared<PendingTracks>(
project);
33 , mTrackListSubscription { mTracks.Subscribe(
35 switch (event.mType) {
58std::pair<Track *, Channel *>
60 Track &track,
size_t channelIndex)
const
67 const auto pred = [
id = track.
GetId()](
const auto &pTrack){
68 return pTrack->GetId() ==
id; };
74 const auto &channels = pTrack->Channels();
75 const auto size = channels.size();
78 assert(channelIndex <
size);
79 auto channelIter = channels.begin();
80 std::advance(channelIter, std::min<int>(channelIndex,
size - 1));
81 return { pTrack, (*channelIter).get() };
94 return pChannel ? *pChannel : channel;
106 return pTrack ? *pTrack : track;
115std::pair<const Track *, const Channel*>
117 const Track &track,
size_t channelIndex)
const
119 auto pTrack = &track;
123 const auto pred = [
id = track.
GetId()](
const auto &pTrack){
124 return pTrack->GetId() ==
id; };
130 if (
const auto it2 = std::find_if(
mTracks.
begin(), end2, pred)
135 const auto &channels = pTrack->Channels();
136 const auto size = channels.size();
139 assert(channelIndex <
size);
141 auto channelIter = channels.begin();
142 std::advance(channelIter, std::min<int>(channelIndex,
size - 1));
143 return { pTrack, (*channelIter).get() };
159 return pChannel ? *pChannel : channel;
165 return pTrack ? *pTrack : track;
188 if (pendingTrack && src) {
198 std::vector<std::shared_ptr<Track>> *pAdded)
208 const auto pTrack = *it;
210 if (pTrack->GetId() ==
TrackId{}) {
216 pAdded->push_back(
nullptr);
222 while (!pAdded->empty() && !pAdded->back())
229 std::vector<std::shared_ptr<Track>> additions;
245 std::vector<std::shared_ptr<Track>> reinstated;
247 for (
const auto pendingTrack : *updated)
248 pendingTrack->ReparentAllAttachments();
250 while (!updated->empty()) {
251 auto iter = updated->begin();
252 auto pendingTrack = *iter;
262 reinstated.push_back(pendingTrack->SharedPointer());
263 updated->Remove(*pendingTrack);
268 for (
auto &pendingTrack : reinstated)
270 mTracks.
Add(move(pendingTrack)), result =
true;
275 for (
auto &pendingTrack : additions) {
295 return t->GetId() == TrackId{};
static const AudacityProject::AttachedObjects::RegisteredFactory sPendingTracksKey
declares abstract base class Track, TrackList, and iterators over TrackList
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
ChannelGroup & GetChannelGroup()
Channel object's lifetime is assumed to be nested in its Track's.
size_t GetChannelIndex() const
Client code makes static instance from a factory of attachments; passes it to Get or Find as a retrie...
CallbackReturn Publish(const TrackListEvent &message)
Send a message to connected callbacks.
bool HasPendingTracks() const
Track * RegisterPendingChangedTrack(Updater updater, Track *src)
Start a deferred update of the project.
std::pair< Track *, Channel * > DoSubstitutePendingChangedChannel(Track &track, size_t channelIndex) const
const Track & SubstituteOriginalTrack(const Track &track) const
Track & SubstitutePendingChangedTrack(Track &track) const
std::shared_ptr< TrackList > mPendingUpdates
std::vector< Updater > mUpdaters
static PendingTracks & Get(AudacityProject &project)
PendingTracks(AudacityProject &project)
void UpdatePendingTracks()
Channel & SubstitutePendingChangedChannel(Channel &channel) const
std::function< void(Track &dest, const Track &src)> Updater
void ClearPendingTracks(std::vector< std::shared_ptr< Track > > *pAdded=nullptr)
Forget pending track additions and changes;.
void RegisterPendingNewTracks(TrackList &&list)
bool ApplyPendingTracks()
Change the state of the project.
std::pair< const Track *, const Channel * > DoSubstituteOriginalChannel(const Track &track, size_t channelIndex) const
const Channel & SubstituteOriginalChannel(const Channel &channel) const
Abstract base class for an object holding data associated with points on a time axis.
virtual Holder Duplicate(DuplicateOptions={}) const
public nonvirtual duplication function that invokes Clone()
An in-session identifier of track objects across undo states. It does not persist between sessions.
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
void Insert(const Track *before, const Track::Holder &pSrc, bool assignIds=false)
Moves *pSrc to position where before is located. If before is nullptr the track is appended.
void Append(TrackList &&list, bool assignIds=true)
Remove all tracks from list and put them at the end of this
auto Any() -> TrackIterRange< TrackType >
Track::Holder ReplaceOne(Track &t, TrackList &&with)
Track::Holder Remove(Track &track)
Remove a track and return it.
Track * FindById(TrackId id)
AudacityProject * GetOwner()
TrackKind * Add(const std::shared_ptr< TrackKind > &t, bool assignIds=true)
static TrackListHolder Temporary(AudacityProject *pProject, const Track::Holder &pTrack={})
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
std::optional< LogWindowUpdater > pUpdater
const char * end(const char *str) noexcept
"finally" as in The C++ Programming Language, 4th ed., p. 358 Useful for defining ad-hoc RAII actions...
Choices when duplicating a track.
DuplicateOptions ShallowCopyAttachments() &&
Notification of changes in individual tracks of TrackList, or of TrackList's composition.
@ RESIZING
Posted when some track changed its height.
@ DELETION
Posted when a track has been deleted from a tracklist. Also posted when one track replaces another.
@ ADDITION
Posted when a track has been added to a tracklist. Also posted when one track replaces another.
@ PERMUTED
Posted when tracks are reordered but otherwise unchanged.