Audacity 3.2.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Friends | List of all members
Track Class Referenceabstract

Abstract base class for an object holding data associated with points on a time axis. More...

#include <Track.h>

Inheritance diagram for Track:
[legend]
Collaboration diagram for Track:
[legend]

Classes

struct  DuplicateOptions
 Choices when duplicating a track. More...
 
struct  ProtectedCreationArg
 Empty argument passed to some public constructors. More...
 
struct  TypeInfo
 
struct  TypeNames
 Names of a track type for various purposes. More...
 

Public Types

using AttachedObjects = ::AttachedTrackObjects
 Alias for my base type. More...
 
using Holder = std::shared_ptr< Track >
 
- Public Types inherited from ClientData::Site< Host, ClientData, ObjectCopyingPolicy, Pointer, ObjectLockingPolicy, RegistryLockingPolicy >
using DataType = ClientData
 
using DataPointer = Pointer< ClientData >
 
using DataFactory = std::function< DataPointer(Host &) >
 Type of function from which RegisteredFactory is constructed; it builds attachments. More...
 
- Public Types inherited from ChannelGroup
enum class  LinkType : int { None = 0 , Group = 2 , Aligned }
 For two tracks describes the type of the linkage. More...
 
using Attachments = ChannelGroupAttachments
 
using Interval = WideChannelGroupInterval
 

Public Member Functions

TrackId GetId () const
 
template<typename Subclass = Track>
std::shared_ptr< Subclass > SharedPointer ()
 
template<typename Subclass = const Track>
auto SharedPointer () const -> std::enable_if_t< std::is_const_v< Subclass >, std::shared_ptr< Subclass > >
 
virtual const TypeInfoGetTypeInfo () const =0
 
virtual const TypeNamesGetTypeNames () const
 
virtual bool SupportsBasicEditing () const
 Whether this track type implements cut-copy-paste; by default, true. More...
 
virtual Holder PasteInto (AudacityProject &project, TrackList &list) const =0
 
virtual bool LinkConsistencyFix (bool doFix=true)
 Check consistency of channel groups, and maybe fix it. More...
 
bool LinkConsistencyCheck ()
 Do the non-mutating part of consistency fix only and return status. More...
 
bool HasOwner () const
 
std::shared_ptr< TrackListGetOwner () const
 
LinkType GetLinkType () const noexcept
 
 Track ()
 
 Track (const Track &orig, ProtectedCreationArg &&)
 
Trackoperator= (const Track &orig)=delete
 
virtual ~Track ()
 
void Init (const Track &orig)
 
virtual Holder Duplicate (DuplicateOptions={}) const
 public nonvirtual duplication function that invokes Clone() More...
 
void ReparentAllAttachments ()
 
const wxString & GetName () const
 Name is always the same for all channels of a group. More...
 
void SetName (const wxString &n)
 
bool GetSelected () const
 Selectedness is always the same for all channels of a group. More...
 
virtual void SetSelected (bool s)
 
virtual Holder Cut (double t0, double t1)=0
 Create tracks and modify this track. More...
 
virtual Holder Copy (double t0, double t1, bool forClipboard=true) const =0
 Create new tracks and don't modify this track. More...
 
virtual void Clear (double t0, double t1)=0
 
virtual void Paste (double t, const Track &src)=0
 Weak precondition allows overrides to replicate one channel into many. More...
 
virtual void SyncLockAdjust (double oldT1, double newT1)
 
virtual void Silence (double t0, double t1, ProgressReporter reportProgress={})=0
 
virtual void InsertSilence (double t, double len)=0
 
bool SameKindAs (const Track &track) const
 
template<typename R = void, typename ... Functions>
TypeSwitch (const Functions &...functions)
 
template<typename R = void, typename ... Functions>
TypeSwitch (const Functions &...functions) const
 
virtual void WriteXML (XMLWriter &xmlFile) const =0
 
virtual std::optional< TranslatableStringGetErrorOpening () const
 
void Notify (bool allChannels, int code=-1)
 
bool Any () const
 
bool IsSelected () const
 
bool IsLeader () const
 
void AdjustPositions ()
 
void WriteCommonXMLAttributes (XMLWriter &xmlFile, bool includeNameAndSelected=true) const
 
bool HandleCommonXMLAttribute (const std::string_view &attr, const XMLAttributeValueView &valueView)
 
- Public Member Functions inherited from XMLTagHandler
 XMLTagHandler ()
 
virtual ~XMLTagHandler ()
 
virtual bool HandleXMLTag (const std::string_view &tag, const AttributesList &attrs)=0
 
virtual void HandleXMLEndTag (const std::string_view &WXUNUSED(tag))
 
virtual void HandleXMLContent (const std::string_view &WXUNUSED(content))
 
virtual XMLTagHandlerHandleXMLChild (const std::string_view &tag)=0
 
void ReadXMLEndTag (const char *tag)
 
void ReadXMLContent (const char *s, int len)
 
XMLTagHandlerReadXMLChild (const char *tag)
 
- Public Member Functions inherited from ClientData::Site< Host, ClientData, ObjectCopyingPolicy, Pointer, ObjectLockingPolicy, RegistryLockingPolicy >
 ~Site ()
 
 Site ()
 
 Site (const Site &other)
 
Siteoperator= (const Site &other)
 
 Site (Site &&other)
 
Siteoperator= (Site &&other)
 
size_t size () const
 How many attachment pointers are in the Site. More...
 
template<typename Subclass = ClientData>
Subclass & Get (const RegisteredFactory &key)
 Get reference to an attachment, creating on demand if not present, down-cast it to Subclass. More...
 
template<typename Subclass = const ClientData>
auto Get (const RegisteredFactory &key) const -> std::enable_if_t< std::is_const< Subclass >::value, Subclass & >
 Get reference to an attachment, creating on demand if not present, down-cast it to Subclass. More...
 
template<typename Subclass = ClientData>
Subclass * Find (const RegisteredFactory &key)
 Get a (bare) pointer to an attachment, or null, down-cast it to Subclass *; will not create on demand. More...
 
template<typename Subclass = const ClientData>
auto Find (const RegisteredFactory &key) const -> std::enable_if_t< std::is_const< Subclass >::value, Subclass * >
 Get a (bare) pointer to an attachment, or null, down-cast it to Subclass *; will not create on demand. More...
 
template<typename ReplacementPointer >
void Assign (const RegisteredFactory &key, ReplacementPointer &&replacement)
 Reassign Site's pointer to ClientData. More...
 
- Public Member Functions inherited from ChannelGroup
virtual ~ChannelGroup ()
 
double GetStartTime () const
 Get the minimum of Start() values of intervals, or 0 when none. More...
 
double GetEndTime () const
 Get the maximum of End() values of intervals, or 0 when none. More...
 
void ShiftBy (double t)
 Change start time by given duration. More...
 
virtual void ShiftBy (double t0, double delta)=0
 Shift all intervals that starts after t0 by delta seconds. More...
 
virtual void MoveTo (double o)=0
 Change start time to given time point. More...
 
virtual size_t NChannels () const =0
 Report the number of channels. More...
 
template<typename ChannelType = Channel>
std::shared_ptr< ChannelType > GetChannel (size_t iChannel)
 Retrieve a channel, cast to the given type. More...
 
template<typename ChannelType = const Channel>
auto GetChannel (size_t iChannel) const -> std::enable_if_t< std::is_const_v< ChannelType >, std::shared_ptr< ChannelType > >
 
template<typename ChannelType = Channel>
IteratorRange< ChannelIterator< ChannelType > > Channels ()
 Get range of channels with mutative access. More...
 
template<typename ChannelType = const Channel>
auto Channels () const -> std::enable_if_t< std::is_const_v< ChannelType >, IteratorRange< ChannelIterator< ChannelType > > >
 Get range of channels with read-only access. More...
 
std::shared_ptr< ChannelNthChannel (size_t nChannel)
 
std::shared_ptr< const ChannelNthChannel (size_t nChannel) const
 
virtual size_t NIntervals () const =0
 Report the number of intervals. More...
 
template<typename IntervalType = Interval>
std::shared_ptr< IntervalType > GetInterval (size_t iInterval)
 Retrieve an interval, cast to the given type. More...
 
template<typename IntervalType = const Interval>
auto GetInterval (size_t iInterval) const -> std::enable_if_t< std::is_const_v< IntervalType >, std::shared_ptr< IntervalType > >
 
template<typename IntervalType = Interval>
IteratorRange< IntervalIterator< IntervalType > > Intervals ()
 Get range of intervals with mutative access. More...
 
template<typename IntervalType = const Interval>
auto Intervals () const -> std::enable_if_t< std::is_const_v< IntervalType >, IteratorRange< IntervalIterator< IntervalType > > >
 Get range of intervals with read-only access. More...
 

Static Public Member Functions

template<typename Subclass = Track>
static std::shared_ptr< Subclass > SharedPointer (Track *pTrack)
 
template<typename Subclass = const Track>
static std::shared_ptr< Subclass > SharedPointer (const Track *pTrack)
 
static const TypeInfoClassTypeInfo ()
 
static void CopyAttachments (Track &dst, const Track &src, bool deep)
 Copy (deep) or just share (!deep) AttachedTrackObjects. More...
 
- Static Public Member Functions inherited from ClientData::Site< Host, ClientData, ObjectCopyingPolicy, Pointer, ObjectLockingPolicy, RegistryLockingPolicy >
static size_t numFactories ()
 How many static factories have been registered with this specialization of Site. More...
 

Protected Member Functions

void SetLinkType (LinkType linkType, bool completeList=true)
 
- Protected Member Functions inherited from ClientData::Site< Host, ClientData, ObjectCopyingPolicy, Pointer, ObjectLockingPolicy, RegistryLockingPolicy >
template<typename Function >
void ForEach (const Function &function)
 Invoke function on each ClientData object that has been created in this. More...
 
template<typename Function >
void ForEach (const Function &function) const
 Invoke function on each ClientData object that has been created in this. More...
 
template<typename Function >
void ForCorresponding (Site &other, const Function &function, bool create=true)
 
template<typename Function >
ClientData * FindIf (const Function &function)
 Return pointer to first attachment in this that is not null and satisfies a predicate, or nullptr. More...
 
template<typename Function >
const ClientData * FindIf (const Function &function) const
 Return pointer to first attachment in this that is not null and satisfies a predicate, or nullptr. More...
 
template<typename Function >
void EraseIf (const Function &function)
 Erase attached objects satisfying a predicate. More...
 
void BuildAll ()
 For each RegisteredFactory, if the corresponding attachment is absent in this, build and store it. More...
 
- Protected Member Functions inherited from ChannelGroup
virtual std::shared_ptr< ChannelDoGetChannel (size_t iChannel)=0
 
virtual std::shared_ptr< IntervalDoGetInterval (size_t iInterval)=0
 Retrieve an interval. More...
 

Protected Attributes

std::weak_ptr< TrackListmList
 
TrackNodePointer mNode {}
 Holds iterator to self, so that TrackList::Find can be constant-time. More...
 

Private Member Functions

void SetId (TrackId id)
 
void DoSetLinkType (LinkType linkType, bool completeList=true)
 
TrackGetLinkedTrack () const
 
bool HasLinkedTrack () const noexcept
 During file loading only, true for leaders of multichannel groups. More...
 
TrackNodePointer GetNode () const
 Retrieve mNode with debug checks. More...
 
void SetOwner (const std::weak_ptr< TrackList > &list, TrackNodePointer node)
 Update mNode when Track is added to TrackList, or removed from it. More...
 
virtual Holder Clone (bool backup) const =0
 
void CopyGroupProperties (const Track &other)
 

Private Attributes

TrackId mId
 Identifies the track only in-session, not persistently. More...
 
wxString mName
 
LinkType mLinkType { LinkType::None }
 
bool mSelected { false }
 

Friends

class TrackList
 
template<typename T >
std::enable_if_t< std::is_pointer_v< T >, T > track_cast (Track *track)
 Encapsulate the checked down-casting of track pointers. More...
 
template<typename T >
std::enable_if_t< std::is_pointer_v< T > &&std::is_const_v< std::remove_pointer_t< T > >, T > track_cast (const Track *track)
 Encapsulate the checked down-casting of track pointers. More...
 

Detailed Description

Abstract base class for an object holding data associated with points on a time axis.

Fundamental data object of Audacity, displayed in the TrackPanel. Classes derived form it include the WaveTrack, NoteTrack, LabelTrack and TimeTrack.

Definition at line 105 of file Track.h.

Member Typedef Documentation

◆ AttachedObjects

Alias for my base type.

Definition at line 134 of file Track.h.

◆ Holder

using Track::Holder = std::shared_ptr<Track>

Definition at line 202 of file Track.h.

Constructor & Destructor Documentation

◆ Track() [1/2]

Track::Track ( )

Definition at line 38 of file Track.cpp.

39{
40}

◆ Track() [2/2]

Track::Track ( const Track orig,
ProtectedCreationArg &&   
)

Definition at line 42 of file Track.cpp.

43{
44}

◆ ~Track()

Track::~Track ( )
virtual

Definition at line 117 of file Track.cpp.

118{
119}

Member Function Documentation

◆ AdjustPositions()

void Track::AdjustPositions ( )

Definition at line 844 of file Track.cpp.

845{
846 auto pList = mList.lock();
847 if (pList) {
848 pList->RecalcPositions(mNode);
849 pList->ResizingEvent(mNode);
850 }
851}
std::weak_ptr< TrackList > mList
Definition: Track.h:127
TrackNodePointer mNode
Holds iterator to self, so that TrackList::Find can be constant-time.
Definition: Track.h:129

References mList, and mNode.

◆ Any()

bool Track::Any ( ) const

Definition at line 255 of file Track.cpp.

256 { return true; }

Referenced by LoudnessBase::AllocBuffers(), TrackList::Channels_(), ProjectAudioManager::DoRecord(), TrackList::EmptyRange(), ExportUtils::FindExportWaveTracks(), MakeTransportTracks(), anonymous_namespace{LabelMenus.cpp}::OnPasteNewLabel(), and TrackList::Size().

Here is the caller graph for this function:

◆ ClassTypeInfo()

auto Track::ClassTypeInfo ( )
static

Definition at line 790 of file Track.cpp.

791{
792 static Track::TypeInfo info{
793 { "generic", "generic", XO("Generic Track") }, false };
794 return info;
795}
XO("Cut/Copy/Paste")

References XO().

Referenced by AudioTrack::ClassTypeInfo(), and typeInfo().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Clear()

virtual void Track::Clear ( double  t0,
double  t1 
)
pure virtual

May assume precondition: t0 <= t1

Implemented in LabelTrack, NoteTrack, TimeTrack, and WaveTrack.

Referenced by anonymous_namespace{LabelMenus.cpp}::OnDeleteLabels(), and SyncLockAdjust().

Here is the caller graph for this function:

◆ Clone()

virtual Holder Track::Clone ( bool  backup) const
privatepure virtual

Subclass responsibility implements only a part of Duplicate(), copying the track data proper (not associated data such as for groups and views) including TrackId

Parameters
backupwhether the duplication is for backup purposes while opening a project, instead of other editing operations
Postcondition
result tracks have same TrackIds as the channels of this

Implemented in LabelTrack, NoteTrack, TimeTrack, and WaveTrack.

◆ Copy()

virtual Holder Track::Copy ( double  t0,
double  t1,
bool  forClipboard = true 
) const
pure virtual

Create new tracks and don't modify this track.

Returns
non-NULL or else throw Note that subclasses may want to distinguish tracks stored in a clipboard from those stored in a project May assume precondition: t0 <= t1 Should invoke Track::Init

Implemented in TimeTrack, LabelTrack, NoteTrack, and WaveTrack.

◆ CopyAttachments()

void Track::CopyAttachments ( Track dst,
const Track src,
bool  deep 
)
static

Copy (deep) or just share (!deep) AttachedTrackObjects.

Definition at line 94 of file Track.cpp.

95{
96 if (!deep) {
97 // Share the satellites with the original, though they do not point
98 // back to the duplicate track
99 AttachedTrackObjects &attachments = dst;
100 attachments = src; // shallow copy
101 }
102 else
103 src.AttachedTrackObjects::ForEach([&](auto &attachment){
104 // Copy view state that might be important to undo/redo
105 attachment.CopyTo(dst);
106 });
107}
Utility to register hooks into a host class that attach client data.
Definition: ClientData.h:229

Referenced by WaveTrack::EmptyCopy().

Here is the caller graph for this function:

◆ CopyGroupProperties()

void Track::CopyGroupProperties ( const Track other)
private

Definition at line 145 of file Track.cpp.

146{
147 mName = other.mName;
148 mSelected = other.mSelected;
149}
bool mSelected
Definition: Track.h:440
wxString mName
Definition: Track.h:437

References mName, and mSelected.

Referenced by Init().

Here is the caller graph for this function:

◆ Cut()

virtual Holder Track::Cut ( double  t0,
double  t1 
)
pure virtual

Create tracks and modify this track.

Returns
non-NULL or else throw May assume precondition: t0 <= t1

Implemented in LabelTrack, NoteTrack, TimeTrack, and WaveTrack.

Referenced by SyncLockAdjust().

Here is the caller graph for this function:

◆ DoSetLinkType()

void Track::DoSetLinkType ( LinkType  linkType,
bool  completeList = true 
)
private
Parameters
completeListonly influences debug build consistency checking

Definition at line 151 of file Track.cpp.

152{
153 auto oldType = GetLinkType();
154 if (linkType == oldType)
155 // No change
156 return;
157
158 if (oldType == LinkType::None) {
159 // Becoming linked
160
161 // First ensure that the previous does not link to this
162 if (auto partner = GetLinkedTrack())
163 partner->mLinkType = LinkType::None;
164 assert(!GetLinkedTrack());
165
166 // Change my link type
167 mLinkType = linkType;
168
169 // Keep link consistency, while still in un-zipped state
170 if (auto partner = GetLinkedTrack()) {
171 partner->mLinkType = LinkType::None;
172 partner->CopyGroupProperties(*this);
173 }
174 }
175 else if (linkType == LinkType::None) {
176 // Becoming unlinked
177 if (HasLinkedTrack()) {
178 if (auto partner = GetLinkedTrack()) {
179 // Make independent copy of group data in the partner, which should
180 // have had none
181 ChannelGroupAttachments &base = *partner;
182 // Intentional slice assignment deep-copies the attachment array:
183 base = *this;
184 partner->CopyGroupProperties(*this);
185 partner->mLinkType = LinkType::None;
186 }
187 }
189 }
190 else
191 // Remaining linked, changing the type
192 mLinkType = linkType;
193
194 // Assertion checks only in a debug build, does not have side effects!
195 assert(!completeList || LinkConsistencyCheck());
196}
LinkType mLinkType
Definition: Track.h:439
bool HasLinkedTrack() const noexcept
During file loading only, true for leaders of multichannel groups.
Definition: Track.cpp:224
Track * GetLinkedTrack() const
Definition: Track.cpp:198
LinkType GetLinkType() const noexcept
Definition: Track.cpp:853
bool LinkConsistencyCheck()
Do the non-mutating part of consistency fix only and return status.
Definition: Track.h:225

References GetLinkedTrack(), GetLinkType(), HasLinkedTrack(), LinkConsistencyCheck(), mLinkType, and ChannelGroup::None.

Referenced by SetLinkType().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Duplicate()

auto Track::Duplicate ( DuplicateOptions  options = {}) const
virtual

public nonvirtual duplication function that invokes Clone()

Definition at line 109 of file Track.cpp.

110{
111 // invoke "virtual constructor" to copy track object proper:
112 auto result = Clone(options.backup);
113 CopyAttachments(*result, *this, !options.shallowCopyAttachments);
114 return result;
115}
virtual Holder Clone(bool backup) const =0
static void CopyAttachments(Track &dst, const Track &src, bool deep)
Copy (deep) or just share (!deep) AttachedTrackObjects.
Definition: Track.cpp:94

Referenced by ProjectFileManager::ReadProjectFile(), and PendingTracks::RegisterPendingChangedTrack().

Here is the caller graph for this function:

◆ GetErrorOpening()

std::optional< TranslatableString > Track::GetErrorOpening ( ) const
virtual

Returns nonempty if an error was encountered while trying to open the track from XML

May assume consistency of stereo channel grouping and examine other channels

Reimplemented in WaveTrack.

Definition at line 229 of file Track.cpp.

230{
231 return {};
232}

◆ GetId()

TrackId Track::GetId ( ) const
inline

Definition at line 136 of file Track.h.

136{ return mId; }
TrackId mId
Identifies the track only in-session, not persistently.
Definition: Track.h:124

Referenced by PendingTracks::DoSubstituteOriginalChannel(), and PendingTracks::DoSubstitutePendingChangedChannel().

Here is the caller graph for this function:

◆ GetLinkedTrack()

Track * Track::GetLinkedTrack ( ) const
private

Definition at line 198 of file Track.cpp.

199{
200 auto pList = GetOwner();
201 if (!pList)
202 return nullptr;
203
204 if (!pList->isNull(mNode)) {
205 if (HasLinkedTrack()) {
206 auto next = pList->getNext( mNode );
207 if ( !pList->isNull( next ) )
208 return next->get();
209 }
210
211 if (mNode != pList->ListOfTracks::begin()) {
212 auto prev = pList->getPrev( mNode );
213 if ( !pList->isNull( prev ) ) {
214 auto track = prev->get();
215 if (track && track->HasLinkedTrack())
216 return track;
217 }
218 }
219 }
220
221 return nullptr;
222}
std::shared_ptr< TrackList > GetOwner() const
Definition: Track.h:230

References GetOwner(), HasLinkedTrack(), and mNode.

Referenced by DoSetLinkType(), TrackList::GetPrev(), IsLeader(), and LinkConsistencyFix().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetLinkType()

Track::LinkType Track::GetLinkType ( ) const
noexcept

Definition at line 853 of file Track.cpp.

854{
855 return mLinkType;
856}

References mLinkType.

Referenced by DoSetLinkType(), and WaveTrack::LinkConsistencyFix().

Here is the caller graph for this function:

◆ GetName()

const wxString & Track::GetName ( ) const

◆ GetNode()

TrackNodePointer Track::GetNode ( ) const
private

Retrieve mNode with debug checks.

Definition at line 122 of file Track.cpp.

123{
124 return mNode;
125}

References mNode.

Referenced by TrackList::GetNext(), TrackList::GetPrev(), TrackList::MoveDown(), TrackList::MoveUp(), and TrackList::ReplaceOne().

Here is the caller graph for this function:

◆ GetOwner()

std::shared_ptr< TrackList > Track::GetOwner ( ) const
inline

◆ GetSelected()

bool Track::GetSelected ( ) const

◆ GetTypeInfo()

virtual const TypeInfo & Track::GetTypeInfo ( ) const
pure virtual

Implemented in LabelTrack, NoteTrack, SampleTrack, WritableSampleTrack, TimeTrack, and WaveTrack.

Referenced by SameKindAs().

Here is the caller graph for this function:

◆ GetTypeNames()

virtual const TypeNames & Track::GetTypeNames ( ) const
inlinevirtual

Definition at line 196 of file Track.h.

197 { return GetTypeInfo().names; }
virtual const TypeInfo & GetTypeInfo() const =0
TypeNames names
Definition: Track.h:181

◆ HandleCommonXMLAttribute()

bool Track::HandleCommonXMLAttribute ( const std::string_view &  attr,
const XMLAttributeValueView valueView 
)

Definition at line 819 of file Track.cpp.

821{
822 long nValue = -1;
823
824 bool handled = false;
825 AttachedTrackObjects::ForEach([&](auto &attachment){
826 handled = handled || attachment.HandleXMLAttribute( attr, valueView );
827 });
828 if (handled)
829 ;
830 // Note that the per-group properties of name and selectedness may have
831 // been written redundantly for each channel, and values for the last
832 // channel will be the last ones assigned
833 else if (attr == "name") {
834 SetName(valueView.ToWString());
835 return true;
836 }
837 else if (attr == "isSelected" && valueView.TryGet(nValue)) {
838 this->SetSelected(nValue != 0);
839 return true;
840 }
841 return false;
842}
void ForEach(const Function &function)
Invoke function on each ClientData object that has been created in this.
Definition: ClientData.h:389
virtual void SetSelected(bool s)
Definition: Track.cpp:83
void SetName(const wxString &n)
Definition: Track.cpp:69
wxString ToWString() const
Convert the view value to wxString.
bool TryGet(bool &value) const noexcept
Try to get a boolean value from the view.

References ClientData::Site< Host, ClientData, ObjectCopyingPolicy, Pointer, ObjectLockingPolicy, RegistryLockingPolicy >::ForEach(), SetName(), SetSelected(), XMLAttributeValueView::ToWString(), and XMLAttributeValueView::TryGet().

Referenced by LabelTrack::HandleXMLTag(), NoteTrack::HandleXMLTag(), TimeTrack::HandleXMLTag(), and WaveTrack::HandleXMLTag().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HasLinkedTrack()

bool Track::HasLinkedTrack ( ) const
privatenoexcept

During file loading only, true for leaders of multichannel groups.

Definition at line 224 of file Track.cpp.

225{
226 return mLinkType != LinkType::None;
227}

References mLinkType, and ChannelGroup::None.

Referenced by DoSetLinkType(), GetLinkedTrack(), TrackList::GetNext(), TrackList::GetPrev(), IsLeader(), and LinkConsistencyFix().

Here is the caller graph for this function:

◆ HasOwner()

bool Track::HasOwner ( ) const
inline

Definition at line 228 of file Track.h.

228{ return static_cast<bool>(GetOwner());}

◆ Init()

void Track::Init ( const Track orig)

Definition at line 47 of file Track.cpp.

48{
49 mId = orig.mId;
50 ChannelGroupAttachments &base = *this;
51 // Intentional slice assignment deep-copies the attachment array:
52 base = orig;
54 mLinkType = orig.mLinkType;
55}
void CopyGroupProperties(const Track &other)
Definition: Track.cpp:145

References CopyGroupProperties(), mId, and mLinkType.

Referenced by TimeTrack::Init(), and WaveTrack::Init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ InsertSilence()

virtual void Track::InsertSilence ( double  t,
double  len 
)
pure virtual

May assume precondition: t0 <= t1

Implemented in LabelTrack, NoteTrack, TimeTrack, and WaveTrack.

◆ IsLeader()

bool Track::IsLeader ( ) const

Definition at line 261 of file Track.cpp.

262{
263 return !GetLinkedTrack() || HasLinkedTrack();
264}

References GetLinkedTrack(), and HasLinkedTrack().

Referenced by TrackList::Any(), TrackList::Find(), WaveTrack::LinkConsistencyFix(), and LinkConsistencyFix().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsSelected()

bool Track::IsSelected ( ) const

Definition at line 258 of file Track.cpp.

259 { return GetSelected(); }
bool GetSelected() const
Selectedness is always the same for all channels of a group.
Definition: Track.cpp:78

References GetSelected().

Referenced by ProjectAudioManager::ChooseExistingRecordingTracks(), anonymous_namespace{TrackMenus.cpp}::DoPanTracks(), ExportUtils::FindExportWaveTracks(), SyncLock::IsSelectedOrSyncLockSelected(), SyncLock::IsSyncLockSelected(), MakeTransportTracks(), SelectActions::Handler::OnSelectSyncLockSel(), TruncSilenceBase::ProcessIndependently(), and TrackList::Selected().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LinkConsistencyCheck()

bool Track::LinkConsistencyCheck ( )
inline

Do the non-mutating part of consistency fix only and return status.

Definition at line 225 of file Track.h.

226 { return const_cast<Track*>(this)->LinkConsistencyFix(false); }
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:110
virtual bool LinkConsistencyFix(bool doFix=true)
Check consistency of channel groups, and maybe fix it.
Definition: Track.cpp:266

Referenced by DoSetLinkType().

Here is the caller graph for this function:

◆ LinkConsistencyFix()

bool Track::LinkConsistencyFix ( bool  doFix = true)
virtual

Check consistency of channel groups, and maybe fix it.

Parameters
doFixwhether to make any changes to correct inconsistencies
Precondition
!doFix || IsLeader()
Returns
true if no inconsistencies were found

Reimplemented in WaveTrack.

Definition at line 266 of file Track.cpp.

267{
268 assert(!doFix || IsLeader());
269 // Sanity checks for linked tracks; unsetting the linked property
270 // doesn't fix the problem, but it likely leaves us with orphaned
271 // sample blocks instead of much worse problems.
272 bool err = false;
273 if (HasLinkedTrack()) {
274 if (auto link = GetLinkedTrack()) {
275 // A linked track's partner should never itself be linked
276 if (link->HasLinkedTrack()) {
277 err = true;
278 if (doFix) {
279 wxLogWarning(
280 L"Left track %s had linked right track %s with extra right "
281 "track link.\n Removing extra link from right track.",
282 GetName(), link->GetName());
283 link->SetLinkType(LinkType::None);
284 }
285 }
286 }
287 else {
288 err = true;
289 if (doFix) {
290 wxLogWarning(
291 L"Track %s had link to NULL track. Setting it to not be linked.",
292 GetName());
294 }
295 }
296 }
297 return ! err;
298}
void SetLinkType(LinkType linkType, bool completeList=true)
Definition: Track.cpp:136
const wxString & GetName() const
Name is always the same for all channels of a group.
Definition: Track.cpp:64
bool IsLeader() const
Definition: Track.cpp:261

References GetLinkedTrack(), GetName(), HasLinkedTrack(), IsLeader(), ChannelGroup::None, and SetLinkType().

Referenced by WaveTrack::LinkConsistencyFix().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Notify()

void Track::Notify ( bool  allChannels,
int  code = -1 
)

Definition at line 234 of file Track.cpp.

235{
236 auto pList = mList.lock();
237 if (pList)
238 pList->DataEvent(SharedPointer(), allChannels, code);
239}
std::shared_ptr< Subclass > SharedPointer()
Definition: Track.h:146

References mList, and SharedPointer().

Referenced by PlayableTrack::SetMute(), SetName(), WaveTrack::SetPan(), PlayableTrack::SetSolo(), NoteTrack::SetVelocity(), and WaveTrack::SetVolume().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=()

Track & Track::operator= ( const Track orig)
delete

◆ Paste()

virtual void Track::Paste ( double  t,
const Track src 
)
pure virtual

Weak precondition allows overrides to replicate one channel into many.

Precondition
SameKindAs(src)
src.NChannels() == 1 || src.NChannels() == NChannels()

Implemented in LabelTrack, NoteTrack, TimeTrack, WaveTrack, and WaveTrack.

Referenced by SyncLockAdjust().

Here is the caller graph for this function:

◆ PasteInto()

virtual Holder Track::PasteInto ( AudacityProject project,
TrackList list 
) const
pure virtual

Find or create the destination track for a paste, maybe in a different project

Parameters
listto which any newly created tracks are added; but left unchanged if an existing track is found in the project instead
Returns
A smart pointer to a track

Implemented in LabelTrack, NoteTrack, TimeTrack, and WaveTrack.

Referenced by anonymous_namespace{EditMenus.cpp}::DoPasteNothingSelected().

Here is the caller graph for this function:

◆ ReparentAllAttachments()

void Track::ReparentAllAttachments ( )

Definition at line 57 of file Track.cpp.

58{
59 this->AttachedTrackObjects::ForEach([&](auto &attachment){
60 attachment.Reparent(this->SharedPointer());
61 });
62}

References ClientData::Site< Host, ClientData, ObjectCopyingPolicy, Pointer, ObjectLockingPolicy, RegistryLockingPolicy >::ForEach(), and SharedPointer().

Here is the call graph for this function:

◆ SameKindAs()

bool Track::SameKindAs ( const Track track) const
inline

Definition at line 373 of file Track.h.

374 { return &GetTypeInfo() == &track.GetTypeInfo(); }

References GetTypeInfo().

Referenced by TrackShifter::CommonMayMigrateTo(), anonymous_namespace{TimeShiftHandle.cpp}::FindCorrespondence(), and anonymous_namespace{EditMenus.cpp}::FitsInto().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetId()

void Track::SetId ( TrackId  id)
inlineprivate

Definition at line 138 of file Track.h.

138{ mId = id; }
int id

References id.

Referenced by TrackList::DoAddToHead().

Here is the caller graph for this function:

◆ SetLinkType()

void Track::SetLinkType ( LinkType  linkType,
bool  completeList = true 
)
protected
Parameters
completeListonly influences debug build consistency checking

Definition at line 136 of file Track.cpp.

137{
138 DoSetLinkType(linkType, completeList);
139 if (const auto pList = mList.lock()) {
140 pList->RecalcPositions(mNode);
141 pList->ResizingEvent(mNode);
142 }
143}
void DoSetLinkType(LinkType linkType, bool completeList=true)
Definition: Track.cpp:151

References DoSetLinkType(), mList, and mNode.

Referenced by WaveTrack::HandleXMLTag(), WaveTrack::LinkConsistencyFix(), LinkConsistencyFix(), and WaveTrack::ZipClips().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetName()

void Track::SetName ( const wxString &  n)

Definition at line 69 of file Track.cpp.

70{
71 auto &name = mName;
72 if (name != n) {
73 name = n;
74 Notify(true);
75 }
76}
wxString name
Definition: TagsEditor.cpp:166
void Notify(bool allChannels, int code=-1)
Definition: Track.cpp:234

References mName, name, and Notify().

Referenced by SetTrackStatusCommand::ApplyInner(), TimeTrack::CleanState(), HandleCommonXMLAttribute(), anonymous_namespace{ImportMIDI.cpp}::ImportMIDI(), TimeTrack::Init(), ModifiedAnalysisTrack::ModifiedAnalysisTrack(), and NoteTrack::NoteTrack().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetOwner()

void Track::SetOwner ( const std::weak_ptr< TrackList > &  list,
TrackNodePointer  node 
)
private

Update mNode when Track is added to TrackList, or removed from it.

Definition at line 127 of file Track.cpp.

129{
130 // BUG: When using this function to clear an owner, we may need to clear
131 // focused track too. Otherwise focus could remain on an invisible (or deleted) track.
132 mList = list;
133 mNode = node;
134}

References mList, and mNode.

Referenced by TrackList::DoAddToHead(), TrackList::Permute(), and TrackList::ReplaceOne().

Here is the caller graph for this function:

◆ SetSelected()

void Track::SetSelected ( bool  s)
virtual

Reimplemented in LabelTrack.

Definition at line 83 of file Track.cpp.

84{
85 auto &selected = mSelected;
86 if (selected != s) {
87 selected = s;
88 auto pList = mList.lock();
89 if (pList)
90 pList->SelectionEvent(*this);
91 }
92}

References mList, and mSelected.

Referenced by SetTrackStatusCommand::ApplyInner(), anonymous_namespace{EditMenus.cpp}::DoPasteNothingSelected(), HandleCommonXMLAttribute(), anonymous_namespace{LabelMenus.cpp}::OnPasteNewLabel(), SelectionState::SelectTrack(), and LabelTrack::SetSelected().

Here is the caller graph for this function:

◆ SharedPointer() [1/4]

template<typename Subclass = Track>
std::shared_ptr< Subclass > Track::SharedPointer ( )
inline

Definition at line 146 of file Track.h.

147 {
148 // shared_from_this is injected into class scope by base class
149 // std::enable_shared_from_this<Track>
150 return std::static_pointer_cast<Subclass>( shared_from_this() );
151 }

Referenced by SelectionState::ChangeSelectionOnShiftClick(), DEFINE_ATTACHED_VIRTUAL_OVERRIDE(), CommonChannelCell::DoFindTrack(), WaveChannelView::DoGetAffordance(), TimeShiftHandle::DoSlideVertical(), TimeShiftHandle::Drag(), TrackFocus::GetFocus(), ClipMoveState::Init(), Notify(), StereoToMono::ProcessOne(), ReparentAllAttachments(), SelectionState::SelectTrack(), TrackFocus::Set(), TrackFocus::SetFocus(), SharedPointer(), and RealtimeEffectPanel::ShowPanel().

Here is the caller graph for this function:

◆ SharedPointer() [2/4]

template<typename Subclass = const Track>
auto Track::SharedPointer ( ) const -> std::enable_if_t< std::is_const_v<Subclass>, std::shared_ptr<Subclass> >
inline

Definition at line 154 of file Track.h.

158 {
159 // shared_from_this is injected into class scope by base class
160 // std::enable_shared_from_this<Track>
161 return std::static_pointer_cast<Subclass>( shared_from_this() );
162 }

◆ SharedPointer() [3/4]

template<typename Subclass = const Track>
static std::shared_ptr< Subclass > Track::SharedPointer ( const Track pTrack)
inlinestatic

Definition at line 170 of file Track.h.

171 { return pTrack ? pTrack->SharedPointer<Subclass>() : nullptr; }

References SharedPointer().

Here is the call graph for this function:

◆ SharedPointer() [4/4]

template<typename Subclass = Track>
static std::shared_ptr< Subclass > Track::SharedPointer ( Track pTrack)
inlinestatic

Definition at line 166 of file Track.h.

167 { return pTrack ? pTrack->SharedPointer<Subclass>() : nullptr; }

References SharedPointer().

Here is the call graph for this function:

◆ Silence()

virtual void Track::Silence ( double  t0,
double  t1,
ProgressReporter  reportProgress = {} 
)
pure virtual

Implemented in WaveTrack, LabelTrack, NoteTrack, and TimeTrack.

◆ SupportsBasicEditing()

bool Track::SupportsBasicEditing ( ) const
virtual

Whether this track type implements cut-copy-paste; by default, true.

Reimplemented in TimeTrack.

Definition at line 797 of file Track.cpp.

798{
799 return true;
800}

Referenced by SelectActions::Handler::OnCursorTrackEnd(), SelectActions::Handler::OnCursorTrackStart(), anonymous_namespace{EditMenus.cpp}::OnCut(), SelectActions::Handler::OnSelectSyncLockSel(), and anonymous_namespace{EditMenus.cpp}::OnSplitCut().

Here is the caller graph for this function:

◆ SyncLockAdjust()

void Track::SyncLockAdjust ( double  oldT1,
double  newT1 
)
virtual

This can be used to adjust a sync-lock selected track when the selection is replaced by one of a different length.

Reimplemented in LabelTrack, and WaveTrack.

Definition at line 241 of file Track.cpp.

242{
243 const auto endTime = GetEndTime();
244 if (newT1 > oldT1 && oldT1 > endTime)
245 return;
246 if (newT1 > oldT1) {
247 auto cutChannels = Cut(oldT1, endTime);
248 Paste(newT1, *cutChannels);
249 }
250 else if (newT1 < oldT1)
251 // Remove from the track
252 Clear(newT1, oldT1);
253}
double GetEndTime() const
Get the maximum of End() values of intervals, or 0 when none.
Definition: Channel.cpp:61
virtual void Paste(double t, const Track &src)=0
Weak precondition allows overrides to replicate one channel into many.
virtual void Clear(double t0, double t1)=0
virtual Holder Cut(double t0, double t1)=0
Create tracks and modify this track.

References Clear(), Cut(), ChannelGroup::GetEndTime(), and Paste().

Here is the call graph for this function:

◆ TypeSwitch() [1/2]

template<typename R = void, typename ... Functions>
R Track::TypeSwitch ( const Functions &...  functions)
inline

Do a TypeSwitch on this track, among all subtypes enumerated up to the point of the call

Definition at line 381 of file Track.h.

382 {
383 struct Here : TrackTypeTag {};
384 // List more derived classes later
385 using TrackTypes =
387 return TypeSwitch::VDispatch<R, TrackTypes>(*this, functions...);
388 }
typename Accumulate< 0 >::type type

Referenced by SetEnvelopeCommand::ApplyInner(), AutoDuckBase::Init(), anonymous_namespace{LabelMenus.cpp}::OnCopyLabels(), anonymous_namespace{LabelMenus.cpp}::OnCutLabels(), anonymous_namespace{LabelMenus.cpp}::OnDeleteLabels(), anonymous_namespace{LabelMenus.cpp}::OnDisjoinLabels(), anonymous_namespace{LabelMenus.cpp}::OnJoinLabels(), anonymous_namespace{EditMenus.cpp}::OnPaste(), anonymous_namespace{LabelMenus.cpp}::OnSilenceLabels(), anonymous_namespace{LabelMenus.cpp}::OnSplitCutLabels(), anonymous_namespace{LabelMenus.cpp}::OnSplitDeleteLabels(), anonymous_namespace{LabelMenus.cpp}::OnSplitLabels(), LabelTrack::Paste(), NoteTrack::Paste(), TimeTrack::Paste(), LabelTrack::PasteOver(), and NyquistBase::ProcessOne().

Here is the caller graph for this function:

◆ TypeSwitch() [2/2]

template<typename R = void, typename ... Functions>
R Track::TypeSwitch ( const Functions &...  functions) const
inline

Do a TypeSwitch on this track, among all subtypes enumerated up to the point of the call

Definition at line 392 of file Track.h.

393 {
394 struct Here : TrackTypeTag {};
395 // List more derived classes later
396 using namespace TypeList;
397 using TrackTypes = Map_t<Fn<std::add_const_t>,
399 return TypeSwitch::VDispatch<R, TrackTypes>(*this, functions...);
400 }
Utilities for compile-time type manipulation. Some terminology as in Lisp.
Definition: TypeList.h:22
typename Map< Metafunction, TypeList >::type Map_t
Definition: TypeList.h:262

◆ WriteCommonXMLAttributes()

void Track::WriteCommonXMLAttributes ( XMLWriter xmlFile,
bool  includeNameAndSelected = true 
) const

Definition at line 803 of file Track.cpp.

805{
806 if (includeNameAndSelected) {
807 // May write name and selectedness redundantly for right channels,
808 // but continue doing that in case the file is opened in Audacity 3.1.x
809 // which does not have unique ChannelGroupData for the track
810 xmlFile.WriteAttr(wxT("name"), GetName());
811 xmlFile.WriteAttr(wxT("isSelected"), this->GetSelected());
812 }
813 AttachedTrackObjects::ForEach([&](auto &attachment){
814 attachment.WriteXMLAttributes( xmlFile );
815 });
816}
wxT("CloseDown"))
void WriteAttr(const wxString &name, const Identifier &value)
Definition: XMLWriter.h:36

References ClientData::Site< Host, ClientData, ObjectCopyingPolicy, Pointer, ObjectLockingPolicy, RegistryLockingPolicy >::ForEach(), GetName(), GetSelected(), XMLWriter::WriteAttr(), and wxT().

Referenced by LabelTrack::WriteXML(), and TimeTrack::WriteXML().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteXML()

virtual void Track::WriteXML ( XMLWriter xmlFile) const
pure virtual

Implemented in LabelTrack, NoteTrack, TimeTrack, and WaveTrack.

Referenced by ProjectFileIO::WriteXML().

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ track_cast [1/2]

template<typename T >
std::enable_if_t< std::is_pointer_v< T > && std::is_const_v< std::remove_pointer_t< T > >, T > track_cast ( const Track track)
friend

Encapsulate the checked down-casting of track pointers.

Eliminates possibility of error – and not quietly casting away const

Typical usage:

if (auto wt = track_cast<const WaveTrack*>(track)) { ... }

This overload for const pointers can cast only to other const pointer types.

Definition at line 497 of file Track.h.

498{
499 using BareType = std::remove_pointer_t< T >;
500 if (track &&
501 BareType::ClassTypeInfo().IsBaseOf(track->GetTypeInfo() ))
502 return reinterpret_cast<T>(track);
503 else
504 return nullptr;
505}

◆ track_cast [2/2]

template<typename T >
std::enable_if_t< std::is_pointer_v< T >, T > track_cast ( Track track)
friend

Encapsulate the checked down-casting of track pointers.

Eliminates possibility of error – and not quietly casting away const

Typical usage:

if (auto wt = track_cast<const WaveTrack*>(track)) { ... }

Definition at line 480 of file Track.h.

481{
482 using BareType = std::remove_pointer_t< T >;
483 if (track &&
484 BareType::ClassTypeInfo().IsBaseOf(track->GetTypeInfo() ))
485 return reinterpret_cast<T>(track);
486 else
487 return nullptr;
488}

◆ TrackList

friend class TrackList
friend

Definition at line 121 of file Track.h.

Member Data Documentation

◆ mId

TrackId Track::mId
private

Identifies the track only in-session, not persistently.

Definition at line 124 of file Track.h.

Referenced by Init().

◆ mLinkType

LinkType Track::mLinkType { LinkType::None }
private

Definition at line 439 of file Track.h.

Referenced by DoSetLinkType(), GetLinkType(), HasLinkedTrack(), and Init().

◆ mList

std::weak_ptr<TrackList> Track::mList
protected

Back pointer to owning TrackList

Definition at line 127 of file Track.h.

Referenced by AdjustPositions(), Notify(), SetLinkType(), SetOwner(), and SetSelected().

◆ mName

wxString Track::mName
private

Definition at line 437 of file Track.h.

Referenced by CopyGroupProperties(), GetName(), and SetName().

◆ mNode

TrackNodePointer Track::mNode {}
protected

Holds iterator to self, so that TrackList::Find can be constant-time.

Definition at line 129 of file Track.h.

Referenced by AdjustPositions(), GetLinkedTrack(), GetNode(), SetLinkType(), and SetOwner().

◆ mSelected

bool Track::mSelected { false }
private

Definition at line 440 of file Track.h.

Referenced by CopyGroupProperties(), GetSelected(), and SetSelected().


The documentation for this class was generated from the following files: