11#ifndef __AUDACITY_TRACK__
12#define __AUDACITY_TRACK__
20#include <wx/longlong.h>
32#pragma warning(disable:4284)
56#define ENUMERATE_TRACK_TYPE(T) ENUMERATE_TYPE(TrackTypeTag, T)
60 std::enable_if_t< std::is_pointer_v<T>, T >
65 std::is_pointer_v<T> &&
66 std::is_const_v< std::remove_pointer_t< T > >,
108 ,
public std::enable_shared_from_this<Track>
145 template<
typename Sub
class = Track>
150 return std::static_pointer_cast<Subclass>( shared_from_this() );
153 template<
typename Sub
class = const Track>
156 std::is_const_v<Subclass>,
std::shared_ptr<Subclass>
161 return std::static_pointer_cast<Subclass>( shared_from_this() );
165 template<
typename Sub
class = Track>
167 {
return pTrack ? pTrack->
SharedPointer<Subclass>() :
nullptr; }
169 template<
typename Sub
class = const Track>
171 {
return pTrack ? pTrack->
SharedPointer<Subclass>() :
nullptr; }
182 bool concrete =
false;
187 for (
auto pInfo = &other;
195 static const TypeInfo &ClassTypeInfo();
197 {
return GetTypeInfo().names; }
200 virtual bool SupportsBasicEditing()
const;
222 virtual bool LinkConsistencyFix(
bool doFix =
true);
226 {
return const_cast<Track*
>(
this)->LinkConsistencyFix(
false); }
228 bool HasOwner()
const {
return static_cast<bool>(GetOwner());}
230 std::shared_ptr<TrackList>
GetOwner()
const {
return mList.lock(); }
232 LinkType GetLinkType() const noexcept;
239 void SetLinkType(LinkType linkType,
bool completeList = true);
245 void DoSetLinkType(LinkType linkType,
bool completeList = true);
247 Track* GetLinkedTrack() const;
249 bool HasLinkedTrack() const noexcept;
260 Track(const
Track &orig, ProtectedCreationArg&&);
268 static
void CopyAttachments(
Track &dst, const
Track &src,
bool deep);
273 : shallowCopyAttachments{ false }
285 { shallowCopyAttachments =
true;
return std::move(*
this); }
289 { backup =
true;
return std::move(*
this); }
293 virtual Holder
Duplicate(DuplicateOptions = {})
const;
295 void ReparentAllAttachments();
298 const wxString &GetName()
const;
299 void SetName(
const wxString &n );
302 bool GetSelected()
const;
303 virtual void SetSelected(
bool s);
322 virtual Holder Copy(
double t0,
double t1,
bool forClipboard =
true)
328 virtual void Clear(
double t0,
double t1) = 0;
339 virtual void SyncLockAdjust(
double oldT1,
double newT1);
362 friend std::enable_if_t< std::is_pointer_v<T>, T >
365 friend std::enable_if_t<
366 std::is_pointer_v<T> &&
367 std::is_const_v< std::remove_pointer_t< T > >,
380 template<
typename R = void,
typename ...Functions>
383 struct Here : TrackTypeTag {};
387 return TypeSwitch::VDispatch<R, TrackTypes>(*
this, functions...);
391 template<
typename R = void,
typename ...Functions>
394 struct Here : TrackTypeTag {};
399 return TypeSwitch::VDispatch<R, TrackTypes>(*
this, functions...);
410 virtual std::optional<TranslatableString> GetErrorOpening()
const;
415 void Notify(
bool allChannels,
int code = -1);
421 bool IsSelected()
const;
422 bool IsLeader()
const;
425 void AdjustPositions();
428 void WriteCommonXMLAttributes(
429 XMLWriter &xmlFile,
bool includeNameAndSelected =
true)
const;
435 void CopyGroupProperties(
const Track &other);
440 bool mSelected{
false };
446template<
typename Base = Track>
459 return { this->shared_from_this(), alias };
465 const Track &track = *
this;
466 return const_cast<Track&
>(track);
479 inline std::enable_if_t< std::is_pointer_v<T>, T >
482 using BareType = std::remove_pointer_t< T >;
484 BareType::ClassTypeInfo().IsBaseOf(track->
GetTypeInfo() ))
485 return reinterpret_cast<T
>(track);
493 inline std::enable_if_t<
494 std::is_pointer_v<T> && std::is_const_v< std::remove_pointer_t< T > >,
499 using BareType = std::remove_pointer_t< T >;
501 BareType::ClassTypeInfo().IsBaseOf(track->
GetTypeInfo() ))
502 return reinterpret_cast<T
>(track);
520 :
public ValueIterator< TrackType *, std::bidirectional_iterator_tag >
525 std::add_pointer_t< std::add_const_t< std::remove_pointer_t<TrackType> > >
536 ,
mPred( std::move(pred) )
546 template <
typename Predicate2 >
555 template <
typename TrackType2 >
558 std::is_base_of_v< TrackType, TrackType2 > &&
559 (!
std::is_const_v<TrackType> ||
560 std::is_const_v<TrackType2>),
568 {
return this->
mPred; }
622 return static_cast< TrackType *
>( &**this->
mIter );
631 std::advance(
copy, amount );
661 const auto pTrack = track_cast< TrackType * >( &**this->
mIter );
692 template<
typename Predicate2 >
695 const auto &pred1 = this->first.GetPredicate();
697 const auto &newPred = pred1
698 ? Function{ [=] (
typename Function::argument_type track) {
699 return pred1(track) && pred2(track);
703 this->first.Filter( newPred ),
704 this->second.Filter( newPred )
710 template<
typename R,
typename C >
713 return this->
operator + ( std::mem_fn( pmf ) );
718 template<
typename Predicate2 >
722 typename TrackIterRange::iterator::FunctionType::argument_type;
723 auto neg = [=] (ArgumentType track) {
return !pred2( track ); };
729 template<
typename R,
typename C >
732 return this->
operator + ( std::not1( std::mem_fn( pmf ) ) );
735 template<
typename TrackType2 >
746 auto newBegin = this->
find( pTrack );
751 { newBegin.mIter, newBegin.mIter, this->second.mEnd,
752 this->first.GetPredicate() },
753 { newBegin.mIter, this->second.mIter, this->second.mEnd,
754 this->second.GetPredicate() }
760 const auto newEnd = this->
reversal().find( pTrack ).base();
765 { this->first.mBegin, this->first.mIter, newEnd.mIter,
766 this->first.GetPredicate() },
767 { this->first.mBegin, newEnd.mIter, newEnd.mIter,
768 this->second.GetPredicate() }
776 [=](
const Track *pTrack){
return pExcluded == pTrack; } );
780 template<
typename ...Functions >
781 void Visit(
const Functions &...functions)
783 for (
auto track : *
this)
784 track->TypeSwitch(functions...);
789 template<
typename Flag,
typename ...Functions >
792 if (
flag )
for (
auto track : *
this) {
793 track->TypeSwitch(functions...);
829 const std::weak_ptr<Track> &pTrack = {},
int extra = -1)
848 ,
public std::enable_shared_from_this<TrackList>
852 using ListOfTracks::push_back;
896 wxString MakeUniqueTrackName(
const wxString& baseTrackName)
const;
949 template <
typename TrackType = Track >
956 template <
typename TrackType = const Track >
958 ->
std::enable_if_t<
std::is_const_v<TrackType>,
966 template <
typename TrackType = Track>
972 template <
typename TrackType = const Track>
980 template<
typename TrackType>
984 return pTrack->GetOwner()->template Tracks<TrackType>()
990 Track *DoAddToHead(
const std::shared_ptr<Track> &t);
991 Track *DoAdd(
const std::shared_ptr<Track> &t,
bool assignIds);
993 template<
typename TrackType,
typename InTrackType >
1015 template<
typename TrackType >
1019 return Channels_<TrackType>(pTrack->GetOwner()->Find(pTrack));
1036 void Permute(
const std::vector<Track *> &
tracks);
1041 template<
typename TrackKind>
1043 {
return static_cast<TrackKind*
>(DoAddToHead(t)); }
1047 template<
typename TrackKind>
1048 TrackKind *
Add(
const std::shared_ptr<TrackKind> &t,
1049 bool assignIds =
true)
1050 {
return static_cast<TrackKind*
>(DoAdd(t, assignIds)); }
1067 void Clear(
bool sendEvent =
true);
1069 bool CanMoveUp(
Track &t)
const;
1070 bool CanMoveDown(
Track &t)
const;
1072 bool MoveUp(
Track &t);
1073 bool MoveDown(
Track &t);
1074 bool Move(
Track &t,
bool up) {
return up ? MoveUp(t) : MoveDown(t); }
1078 template <
typename Sub
class>
1079 std::shared_ptr<Subclass>
Lock(
const std::weak_ptr<Subclass> &wTrack)
1081 auto pTrack = wTrack.lock();
1083 auto pList = pTrack->mList.lock();
1084 if (pTrack &&
this == pList.get())
1128 typename TrackType =
Track,
1135 auto b = getBegin(), e = getEnd();
1136 return { { b, b, e, pred }, { b, e, e, pred } };
1141 typename TrackType =
const Track,
1146 -> std::enable_if_t< std::is_const_v<TrackType>,
1150 auto b =
const_cast<TrackList*
>(
this)->getBegin();
1151 auto e =
const_cast<TrackList*
>(
this)->getEnd();
1152 return { { b, b, e, pred }, { b, e, e, pred } };
1155 Track *GetPrev(
Track &,
bool linked =
false)
const;
1156 Track *GetNext(
Track &,
bool linked =
false)
const;
1158 template <
typename TrackType >
1162 auto b =
const_cast<TrackList*
>(
this)->getBegin();
1163 auto e =
const_cast<TrackList*
>(
this)->getEnd();
1164 return { b, iter, e };
1167 template <
typename TrackType >
1171 auto e =
const_cast<TrackList*
>(
this)->getEnd();
1196 if (p == getBegin())
1207 void SelectionEvent(
Track &track);
1210 const std::shared_ptr<Track> &pTrack,
bool allChannels,
int code );
1211 void DeletionEvent(std::weak_ptr<Track> node,
bool duringReplace);
1226 bool mAssignsIds{
true };
Abstract class ChannelGroup with two discrete iterable dimensions, channels and intervals; subclasses...
std::vector< Track * > TrackArray
ClientData::Site< Track, TrackAttachment, ClientData::ShallowCopying, std::shared_ptr > AttachedTrackObjects
Template generated base class for Track lets it host opaque UI related objects.
std::function< void(double)> ProgressReporter
#define ENUMERATE_TRACK_TYPE(T)
Empty class which will have subclasses.
ListOfTracks::iterator TrackNodePointer
std::list< std::shared_ptr< Track > > ListOfTracks
std::enable_if_t< std::is_pointer_v< T >, T > track_cast(Track *track)
Encapsulate the checked down-casting of track pointers.
std::shared_ptr< TrackList > TrackListHolder
abstract base class for structures that user interface associates with tracks
Make a list of all distinct types so far mentioned in calls of a certain macro.
#define BEGIN_TYPE_ENUMERATION(Tag)
Dispatch to one of a set of functions by the run-time type of an object.
Append(Adapt< My >([](My &table) { return(WaveChannelSubViews::numFactories() > 1) ? std::make_unique< Entry >("MultiView", Entry::CheckItem, OnMultiViewID, XXO("&Multi-view"), POPUP_MENU_FN(OnMultiView), table, [](PopupMenuHandler &handler, wxMenu &menu, int id){ auto &table=static_cast< WaveTrackMenuTable & >(handler);auto &track=table.FindWaveTrack();const auto &view=WaveChannelView::GetFirst(track);menu.Check(id, view.GetMultiView());}) :nullptr;}))
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
double GetEndTime() const
Get the maximum of End() values of intervals, or 0 when none.
double GetStartTime() const
Get the minimum of Start() values of intervals, or 0 when none.
LinkType
For two tracks describes the type of the linkage.
Utility to register hooks into a host class that attach client data.
Site & operator=(const Site &other)
Subclass * DoFind(Locked< DataContainer > &data, const RegisteredFactory &key)
An object that sends messages to an open-ended list of subscribed callbacks.
Abstract base class for an object holding data associated with points on a time axis.
virtual Holder Clone(bool backup) const =0
virtual void Paste(double t, const Track &src)=0
Weak precondition allows overrides to replicate one channel into many.
virtual Holder PasteInto(AudacityProject &project, TrackList &list) const =0
bool SameKindAs(const Track &track) const
virtual Holder Copy(double t0, double t1, bool forClipboard=true) const =0
Create new tracks and don't modify this track.
virtual const TypeInfo & GetTypeInfo() const =0
virtual void InsertSilence(double t, double len)=0
std::shared_ptr< TrackList > GetOwner() const
R TypeSwitch(const Functions &...functions)
static std::shared_ptr< Subclass > SharedPointer(Track *pTrack)
virtual const TypeNames & GetTypeNames() const
auto SharedPointer() const -> std::enable_if_t< std::is_const_v< Subclass >, std::shared_ptr< Subclass > >
std::shared_ptr< Subclass > SharedPointer()
virtual void Clear(double t0, double t1)=0
std::shared_ptr< Track > Holder
virtual void WriteXML(XMLWriter &xmlFile) const =0
R TypeSwitch(const Functions &...functions) const
virtual void Silence(double t0, double t1, ProgressReporter reportProgress={})=0
std::weak_ptr< TrackList > mList
static std::shared_ptr< Subclass > SharedPointer(const Track *pTrack)
bool LinkConsistencyCheck()
Do the non-mutating part of consistency fix only and return status.
virtual Holder Cut(double t0, double t1)=0
Create tracks and modify this track.
TrackId mId
Identifies the track only in-session, not persistently.
An in-session identifier of track objects across undo states. It does not persist between sessions.
bool operator!=(const TrackId &other) const
bool operator<(const TrackId &other) const
bool operator==(const TrackId &other) const
Iterator over only members of a TrackList of the specified subtype, optionally filtered by a predicat...
const FunctionType & GetPredicate() const
TrackNodePointer mIter
Current position.
TrackType * operator*() const
Safe to call even when at the end.
TrackIter & operator--()
Safe to call even when at the beginning.
friend bool operator!=(TrackIter a, TrackIter b)
Compares only current positions, assuming same beginnings and ends.
auto Filter() const -> std::enable_if_t< std::is_base_of_v< TrackType, TrackType2 > &&(!std::is_const_v< TrackType >||std::is_const_v< TrackType2 >), TrackIter< TrackType2 > >
Return an iterator for a subclass of TrackType (and not removing const) with same predicate.
TrackNodePointer mBegin
Allows end of reverse iteration to be detected without comparison to other TrackIter.
friend bool operator==(TrackIter a, TrackIter b)
Compares only current positions, assuming same beginnings and ends.
TrackIter Filter(const Predicate2 &pred2) const
Return an iterator that replaces the predicate.
TrackIter & operator++()
Safe to call even when at the end.
std::function< bool(std::add_pointer_t< std::add_const_t< std::remove_pointer_t< TrackType > > >) > FunctionType
Type of predicate taking pointer to const TrackType.
TrackIter advance(long amount) const
This might be called operator + , but it's not constant-time as with a random access iterator.
FunctionType mPred
Optional filter
TrackIter(TrackNodePointer begin, TrackNodePointer iter, TrackNodePointer end, FunctionType pred={})
Constructor, usually not called directly except by methods of TrackList.
bool valid() const
Test satisfaction of the invariant, while initializing, incrementing, or decrementing.
TrackNodePointer mEnd
Allows end of iteration to be detected without comparison to other TrackIter.
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
const_reverse_iterator crbegin() const
std::shared_ptr< Subclass > Lock(const std::weak_ptr< Subclass > &wTrack)
static auto SingletonRange(TrackType *pTrack) -> TrackIterRange< TrackType >
auto Selected() const -> std::enable_if_t< std::is_const_v< TrackType >, TrackIterRange< TrackType > >
const_reverse_iterator rend() const
std::reverse_iterator< const_iterator > const_reverse_iterator
const_iterator End() const
This private function still iterates channels not tracks.
const_iterator begin() const
TrackNodePointer getBegin() const
auto Tracks(const Pred &pred={}) const -> std::enable_if_t< std::is_const_v< TrackType >, TrackIterRange< TrackType > >
TrackIter< const Track > Find(const Track *pTrack) const
auto Tracks(const Pred &pred={}) -> TrackIterRange< TrackType >
bool isNull(TrackNodePointer p) const
bool Move(Track &t, bool up)
const_reverse_iterator crend() const
TrackNodePointer getNext(TrackNodePointer p) const
Move an iterator to the next node, if any; else stay at end.
auto Any() -> TrackIterRange< TrackType >
TrackNodePointer getEnd() const
TrackIter< TrackType > EndIterator() const
auto Any() const -> std::enable_if_t< std::is_const_v< TrackType >, TrackIterRange< TrackType > >
reverse_iterator rbegin()
static TrackIterRange< TrackType > Channels_(TrackIter< InTrackType > iter1)
const AudacityProject * GetOwner() const
std::reverse_iterator< iterator > reverse_iterator
const_iterator cend() const
auto Selected() -> TrackIterRange< TrackType >
iterator Begin()
This private function still iterates channels not tracks.
const_iterator cbegin() const
const_iterator Begin() const
This private function still iterates channels not tracks.
iterator End()
This private function still iterates channels not tracks.
AudacityProject * GetOwner()
TrackIter< TrackType > MakeTrackIterator(TrackNodePointer iter) const
TrackList(const TrackList &that)=delete
TrackList(TrackList &&that)=delete
TrackKind * Add(const std::shared_ptr< TrackKind > &t, bool assignIds=true)
TrackNodePointer getPrev(TrackNodePointer p) const
Move an iterator to the previous node, if any; else wrap to end.
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
const_reverse_iterator rbegin() const
TrackKind * AddToHead(const std::shared_ptr< TrackKind > &t)
Add a Track, giving it a fresh id if this is not temporary.
const_iterator end() const
Holds a msgid for the translation catalog; may also bind format arguments.
typename Accumulate< 0 >::type type
Generates overrides of channel-related functions.
std::shared_ptr< Channel > DoGetChannel(size_t iChannel) override
size_t NChannels() const override
Report the number of channels.
ChannelGroup & DoGetChannelGroup() const override
Subclass must override.
A view into an attribute value. The class does not take the ownership of the data.
This class is an interface which should be implemented by classes which wish to be able to load and s...
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
PROJECT_FILE_IO_API void Remove(const FilePath &path)
PROJECT_FILE_IO_API wxString Find(const FilePath &path)
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
@ ShallowCopying
copy pointers only; won't compile for std::unique_ptr
Utilities for compile-time type manipulation. Some terminology as in Lisp.
typename Map< Metafunction, TypeList >::type Map_t
std::vector< std::vector< float > > Duplicate(const std::vector< float > &audio, size_t numChannels)
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
const char * end(const char *str) noexcept
const char * begin(const char *str) noexcept
void copy(const T *src, T *dst, int32_t n)
A convenient default parameter for class template Site.
A convenience for use with range-for.
iterator find(const T &t) const
IteratorRange< reverse_iterator > reversal() const
TrackIter< TrackType > end() const
TrackIter< TrackType > begin() const
Choices when duplicating a track.
bool shallowCopyAttachments
if true, then share AttachedTrackObjects
bool backup
passed to Track::Clone()
DuplicateOptions ShallowCopyAttachments() &&
DuplicateOptions Backup() &&
Empty argument passed to some public constructors.
bool IsBaseOf(const TypeInfo &other) const
const TypeInfo * pBaseInfo
Names of a track type for various purposes.
wxString info
short, like "wave", in macro output, not internationalized
TranslatableString name
long, like "Wave Track"
wxString property
short, like "wave", as a Lisp symbol property, not internationalized
Range between two TrackIters, usable in range-for statements, and with Visit member functions.
TrackIterRange EndingAfter(const Track *pTrack) const
void VisitWhile(Flag &flag, const Functions &...functions)
See Track::TypeSwitch.
TrackIterRange operator+(const Predicate2 &pred2) const
TrackIterRange(const TrackIter< TrackType > &begin, const TrackIter< TrackType > &end)
void Visit(const Functions &...functions)
See Track::TypeSwitch.
TrackIterRange< TrackType2 > Filter() const
TrackIterRange Excluding(const TrackType *pExcluded) const
TrackIterRange operator-(const Predicate2 &pred2) const
TrackIterRange StartingWith(const Track *pTrack) const
Notification of changes in individual tracks of TrackList, or of TrackList's composition.
TrackListEvent(const TrackListEvent &)=default
const std::weak_ptr< Track > mpTrack
@ RESIZING
Posted when some track changed its height.
@ SELECTION_CHANGE
Posted when the set of selected tracks changes.
@ 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.
@ TRACK_DATA_CHANGE
Posted when certain fields of a track change.
TrackListEvent(Type type, const std::weak_ptr< Track > &pTrack={}, int extra=-1)
Select only the subsequence of the type list satisfying the predicate.
A convenience for defining iterators that return rvalue types, so that they cooperate correctly with ...