Audacity 3.2.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
LabelTrack Class Referencefinal

A LabelTrack is a Track that holds labels (LabelStruct). More...

#include <LabelTrack.h>

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

Classes

struct  Interval
 

Public Types

using Holder = std::shared_ptr< LabelTrack >
 
- Public Types inherited from Track
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 = ClientData::Site< ChannelGroupData, ClientData::Cloneable<>, ClientData::DeepCopying >
 
using Interval = WideChannelGroupInterval
 
- Public Types inherited from Channel
using Interval = ChannelInterval
 
- Public Types inherited from Observer::Publisher< struct LabelTrackEvent >
using message_type = struct LabelTrackEvent
 
using CallbackReturn = std::conditional_t< true, void, bool >
 
using Callback = std::function< CallbackReturn(const struct LabelTrackEvent &) >
 Type of functions that can be connected to the Publisher. More...
 

Public Member Functions

 LabelTrack ()
 
 LabelTrack (const LabelTrack &orig, ProtectedCreationArg &&)
 
virtual ~LabelTrack ()
 
void SetLabel (size_t iLabel, const LabelStruct &newLabel)
 
void MoveTo (double dOffset) override
 Change start time to given time point. More...
 
void SetSelected (bool s) override
 
bool HandleXMLTag (const std::string_view &tag, const AttributesList &attrs) override
 
XMLTagHandlerHandleXMLChild (const std::string_view &tag) override
 
void WriteXML (XMLWriter &xmlFile) const override
 
TrackListHolder Cut (double t0, double t1) override
 Create tracks and modify this track. More...
 
TrackListHolder Copy (double t0, double t1, bool forClipboard=true) const override
 Create new tracks and don't modify this track. More...
 
void Clear (double t0, double t1) override
 
void Paste (double t, const Track &src) override
 Weak precondition allows overrides to replicate one channel into many. More...
 
bool Repeat (double t0, double t1, int n)
 
void SyncLockAdjust (double oldT1, double newT1) override
 
void Silence (double t0, double t1, ProgressReporter reportProgress={}) override
 
void InsertSilence (double t, double len) override
 
void Import (wxTextFile &f)
 Import labels, handling files with or without end-times. More...
 
void Export (wxTextFile &f) const
 Export labels including label start and end-times. More...
 
int GetNumLabels () const
 
const LabelStructGetLabel (int index) const
 
const LabelArrayGetLabels () const
 
void OnLabelAdded (const wxString &title, int pos)
 
int AddLabel (const SelectedRegion &region, const wxString &title)
 
void DeleteLabel (int index)
 
bool PasteOver (double t, const Track &src)
 
void ShiftLabelsOnInsert (double length, double pt)
 
void ChangeLabelsOnReverse (double b, double e)
 
void ScaleLabels (double b, double e, double change)
 
double AdjustTimeStampOnScale (double t, double b, double e, double change)
 
void WarpLabels (const TimeWarper &warper)
 
wxString GetTextOfLabels (double t0, double t1) const
 
int FindNextLabel (const SelectedRegion &currentSelection)
 
int FindPrevLabel (const SelectedRegion &currentSelection)
 
const TypeInfoGetTypeInfo () const override
 
Track::Holder PasteInto (AudacityProject &project, TrackList &list) const override
 
std::shared_ptr< IntervalMakeInterval (size_t index)
 
void SortLabels ()
 
size_t NIntervals () const override
 Report the number of intervals. More...
 
- Public Member Functions inherited from UniqueChannelTrack< Base >
size_t NChannels () const override
 Report the number of channels. More...
 
std::shared_ptr< ChannelDoGetChannel (size_t iChannel) override
 Retrieve a channel. More...
 
- Public Member Functions inherited from Track
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 > >
 
std::shared_ptr< TrackSubstitutePendingChangedTrack ()
 
std::shared_ptr< const TrackSubstitutePendingChangedTrack () const
 
std::shared_ptr< const TrackSubstituteOriginalTrack () const
 
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
 
TrackListGetHolder () const
 
LinkType GetLinkType () const noexcept
 
ChannelGroupDataGetGroupData ()
 
const ChannelGroupDataGetGroupData () const
 May make group data on demand, but consider that logically const. More...
 
 Track ()
 
 Track (const Track &orig, ProtectedCreationArg &&)
 
Trackoperator= (const Track &orig)=delete
 
virtual ~Track ()
 
void Init (const Track &orig)
 
virtual TrackListHolder 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)
 
void OnProjectTempoChange (double newTempo)
 method to set project tempo on track More...
 
virtual TrackListHolder Cut (double t0, double t1)=0
 Create tracks and modify this track. More...
 
virtual TrackListHolder 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...
 
void Paste (double t, const TrackList &src)
 
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 override
 
bool IsSelectedLeader () const
 
void AdjustPositions ()
 
void WriteCommonXMLAttributes (XMLWriter &xmlFile, bool includeNameAndSelected=true) const
 
bool HandleCommonXMLAttribute (const std::string_view &attr, const XMLAttributeValueView &valueView)
 
const std::optional< double > & GetProjectTempo () const
 
- 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 MoveTo (double o)=0
 Change start time to given time point. More...
 
virtual bool IsLeader () const =0
 
ChannelGroupDataGetGroupData ()
 Make attachment site on demand as needed. More...
 
const ChannelGroupDataGetGroupData () const
 
ChannelGroupDataFindGroupData ()
 Do not make attachment site on demand if absent. More...
 
const ChannelGroupDataFindGroupData () const
 Do not make attachment site on demand if absent. More...
 
void Init (const ChannelGroup &other)
 Copy, including cloning of attached objects. More...
 
void DestroyGroupData ()
 Leave all attachments null. More...
 
std::unique_ptr< ChannelGroupDataDetachGroupData ()
 Move attachments out. More...
 
void AssignGroupData (std::unique_ptr< ChannelGroupData > pGroupData)
 Replace any previous attachments. 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...
 
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...
 
- Public Member Functions inherited from Channel
virtual ~Channel ()
 
ChannelGroupGetChannelGroup ()
 Channel object's lifetime is assumed to be nested in its Track's. More...
 
const ChannelGroupGetChannelGroup () const
 Channel object's lifetime is assumed to be nested in its Track's. More...
 
size_t GetChannelIndex () const
 
size_t ReallyGetChannelIndex () const
 
size_t NIntervals () const
 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...
 
- Public Member Functions inherited from Observer::Publisher< struct LabelTrackEvent >
 Publisher (ExceptionPolicy *pPolicy=nullptr, Alloc a={})
 Constructor supporting type-erased custom allocation/deletion. More...
 
 Publisher (Publisher &&)=default
 
Publisheroperator= (Publisher &&)=default
 
Subscription Subscribe (Callback callback)
 Connect a callback to the Publisher; later-connected are called earlier. More...
 
Subscription Subscribe (Object &obj, Return(Object::*callback)(Args...))
 Overload of Subscribe takes an object and pointer-to-member-function. More...
 

Static Public Member Functions

static wxString GetDefaultName ()
 
static LabelTrackNew (AudacityProject &project)
 
static LabelTrackCreate (TrackList &trackList, const wxString &name)
 Create a new LabelTrack with specified name and append it to the trackList. More...
 
static LabelTrackCreate (TrackList &trackList)
 Create a new LabelTrack with unique default name and append it to the trackList. More...
 
static const TypeInfoClassTypeInfo ()
 
- Static Public Member Functions inherited from Track
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 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...
 

Private Member Functions

TrackListHolder Clone (bool backup) const override
 
void DoOnProjectTempoChange (const std::optional< double > &oldTempo, double newTempo) override
 
std::shared_ptr< WideChannelGroupIntervalDoGetInterval (size_t iInterval) override
 Retrieve an interval. More...
 

Private Attributes

LabelArray mLabels
 
double mClipLen
 
int miLastLabel
 

Additional Inherited Members

- Static Public Attributes inherited from Observer::Publisher< struct LabelTrackEvent >
static constexpr bool notifies_all
 
- Protected Member Functions inherited from UniqueChannelTrack< Base >
ChannelGroupDoGetChannelGroup () const override
 Subclass must override. More...
 
- Protected Member Functions inherited from Track
void SetLinkType (LinkType linkType, bool completeList=true)
 
virtual void DoOnProjectTempoChange (const std::optional< double > &oldTempo, double newTempo)=0
 
- 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 >
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...
 
void BuildAll ()
 For each RegisteredFactory, if the corresponding attachment is absent in this, build and store it. More...
 
virtual std::shared_ptr< ChannelDoGetChannel (size_t iChannel)=0
 Retrieve a channel. More...
 
virtual std::shared_ptr< IntervalDoGetInterval (size_t iInterval)=0
 Retrieve an interval. More...
 
- Protected Member Functions inherited from Channel
virtual ChannelGroupDoGetChannelGroup () const =0
 Subclass must override. More...
 
virtual ChannelGroupReallyDoGetChannelGroup () const
 This is temporary! It defaults to call the above. More...
 
- Protected Member Functions inherited from Observer::Publisher< struct LabelTrackEvent >
CallbackReturn Publish (const struct LabelTrackEvent &message)
 Send a message to connected callbacks. More...
 
- Protected Attributes inherited from Track
std::weak_ptr< TrackListmList
 
TrackNodePointer mNode {}
 Holds iterator to self, so that TrackList::Find can be constant-time. More...
 
int mIndex
 0-based position of this track in its TrackList More...
 

Detailed Description

A LabelTrack is a Track that holds labels (LabelStruct).

These are used to annotate a waveform. Each label has a start time and an end time. The text of the labels is editable and the positions of the end points are draggable.

Definition at line 84 of file LabelTrack.h.

Member Typedef Documentation

◆ Holder

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

Definition at line 117 of file LabelTrack.h.

Constructor & Destructor Documentation

◆ LabelTrack() [1/2]

LabelTrack::LabelTrack ( )

Definition at line 89 of file LabelTrack.cpp.

91 , mClipLen{ 0.0 }
92 , miLastLabel{ -1 }
93{
94}
double mClipLen
Definition: LabelTrack.h:206
int miLastLabel
Definition: LabelTrack.h:208
Generates overrides of channel-related functions.
Definition: Track.h:508

◆ LabelTrack() [2/2]

LabelTrack::LabelTrack ( const LabelTrack orig,
ProtectedCreationArg &&  a 
)

Definition at line 96 of file LabelTrack.cpp.

97 : UniqueChannelTrack{ orig, std::move(a) }
98 , mClipLen{ 0.0 }
99{
100 for (auto &original: orig.mLabels) {
101 LabelStruct l { original.selectedRegion, original.title };
102 mLabels.push_back(l);
103 }
104}
A LabelStruct holds information for ONE label in a LabelTrack.
Definition: LabelTrack.h:29
SelectedRegion selectedRegion
Definition: LabelTrack.h:69
LabelArray mLabels
Definition: LabelTrack.h:203

References mLabels, and LabelStruct::selectedRegion.

◆ ~LabelTrack()

LabelTrack::~LabelTrack ( )
virtual

Definition at line 162 of file LabelTrack.cpp.

163{
164}

Member Function Documentation

◆ AddLabel()

int LabelTrack::AddLabel ( const SelectedRegion region,
const wxString &  title 
)

Definition at line 975 of file LabelTrack.cpp.

977{
978 LabelStruct l { selectedRegion, title };
979
980 int len = mLabels.size();
981 int pos = 0;
982
983 while (pos < len && mLabels[pos].getT0() < selectedRegion.t0())
984 pos++;
985
986 mLabels.insert(mLabels.begin() + pos, l);
987
989 this->SharedPointer<LabelTrack>(), title, -1, pos });
990
991 return pos;
992}
static const auto title
CallbackReturn Publish(const struct LabelTrackEvent &message)
Send a message to connected callbacks.
Definition: Observer.h:207

References LabelTrackEvent::Addition, mLabels, Observer::Publisher< struct LabelTrackEvent >::Publish(), SelectedRegion::t0(), and title.

Referenced by VampEffect::AddFeatures(), and EffectFindClipping::ProcessOne().

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

◆ AdjustTimeStampOnScale()

double LabelTrack::AdjustTimeStampOnScale ( double  t,
double  b,
double  e,
double  change 
)

Definition at line 275 of file LabelTrack.cpp.

276{
277//t is the time stamp we'll be changing
278//b and e are the selection start and end
279
280 if (t < b){
281 return t;
282 }else if (t > e){
283 double shift = (e-b)*change - (e-b);
284 return t + shift;
285 }else{
286 double shift = (t-b)*change - (t-b);
287 return t + shift;
288 }
289}

Referenced by ScaleLabels().

Here is the caller graph for this function:

◆ ChangeLabelsOnReverse()

void LabelTrack::ChangeLabelsOnReverse ( double  b,
double  e 
)

Definition at line 251 of file LabelTrack.cpp.

252{
253 for (auto &labelStruct: mLabels) {
254 if (labelStruct.RegionRelation(b, e, this) ==
256 {
257 double aux = b + (e - labelStruct.getT1());
258 labelStruct.selectedRegion.setTimes(
259 aux,
260 e - (labelStruct.getT0() - b));
261 }
262 }
263 SortLabels();
264}
@ SURROUNDS_LABEL
Definition: LabelTrack.h:55
void SortLabels()

References mLabels, SortLabels(), and LabelStruct::SURROUNDS_LABEL.

Here is the call graph for this function:

◆ ClassTypeInfo()

auto LabelTrack::ClassTypeInfo ( )
static

Definition at line 118 of file LabelTrack.cpp.

119{
120 return typeInfo();
121}
static const Track::TypeInfo & typeInfo()
Definition: LabelTrack.cpp:106

References typeInfo().

Here is the call graph for this function:

◆ Clear()

void LabelTrack::Clear ( double  t0,
double  t1 
)
overridevirtual

May assume precondition: t0 <= t1

Precondition
IsLeader()

Implements Track.

Definition at line 188 of file LabelTrack.cpp.

189{
190 assert(IsLeader());
191 // May DELETE labels, so use subscripts to iterate
192 for (size_t i = 0; i < mLabels.size(); ++i) {
193 auto &labelStruct = mLabels[i];
195 labelStruct.RegionRelation(b, e, this);
196 if (relation == LabelStruct::BEFORE_LABEL)
197 labelStruct.selectedRegion.move(- (e-b));
198 else if (relation == LabelStruct::SURROUNDS_LABEL) {
199 DeleteLabel( i );
200 --i;
201 }
202 else if (relation == LabelStruct::ENDS_IN_LABEL)
203 labelStruct.selectedRegion.setTimes(
204 b,
205 labelStruct.getT1() - (e - b));
206 else if (relation == LabelStruct::BEGINS_IN_LABEL)
207 labelStruct.selectedRegion.setT1(b);
208 else if (relation == LabelStruct::WITHIN_LABEL)
209 labelStruct.selectedRegion.moveT1( - (e-b));
210 }
211}
TimeRelations
Relationships between selection region and labels.
Definition: LabelTrack.h:52
@ BEGINS_IN_LABEL
Definition: LabelTrack.h:57
void DeleteLabel(int index)
Definition: LabelTrack.cpp:994
bool IsLeader() const override
Definition: Track.cpp:291

References LabelStruct::BEFORE_LABEL, LabelStruct::BEGINS_IN_LABEL, DeleteLabel(), LabelStruct::ENDS_IN_LABEL, Track::IsLeader(), mLabels, LabelStruct::SURROUNDS_LABEL, and LabelStruct::WITHIN_LABEL.

Referenced by Cut(), and SyncLockAdjust().

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

◆ Clone()

TrackListHolder LabelTrack::Clone ( bool  backup) const
overrideprivatevirtual

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

Parameters
unstretchIntervalIf set, this time interval's stretching must be applied.
Precondition
!unstretchInterval.has_value() || unstretchInterval->first < unstretchInterval->second
IsLeader()
Parameters
backupwhether the duplication is for backup purposes while opening a project, instead of other editing operations
Postcondition
result: NChannels() == result->NChannels()

Implements Track.

Definition at line 345 of file LabelTrack.cpp.

346{
347 assert(IsLeader());
348 auto result = std::make_shared<LabelTrack>(*this, ProtectedCreationArg{});
349 result->Init(*this);
350 return TrackList::Temporary(nullptr, result, nullptr);
351}
static TrackListHolder Temporary(AudacityProject *pProject, const Track::Holder &left={}, const Track::Holder &right={})
Definition: Track.cpp:1418

References Track::IsLeader(), and TrackList::Temporary().

Here is the call graph for this function:

◆ Copy()

TrackListHolder LabelTrack::Copy ( double  t0,
double  t1,
bool  forClipboard = true 
) const
overridevirtual

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
Precondition
IsLeader
Postcondition
result: result->NChannels() == NChannels()

Implements Track.

Definition at line 735 of file LabelTrack.cpp.

736{
737 auto tmp = std::make_shared<LabelTrack>();
738 tmp->Init(*this);
739 const auto lt = static_cast<LabelTrack*>(tmp.get());
740
741 for (auto &labelStruct: mLabels) {
743 labelStruct.RegionRelation(t0, t1, this);
744 if (relation == LabelStruct::SURROUNDS_LABEL) {
745 LabelStruct l {
746 labelStruct.selectedRegion,
747 labelStruct.getT0() - t0,
748 labelStruct.getT1() - t0,
749 labelStruct.title
750 };
751 lt->mLabels.push_back(l);
752 }
753 else if (relation == LabelStruct::WITHIN_LABEL) {
754 LabelStruct l {
755 labelStruct.selectedRegion,
756 0,
757 t1-t0,
758 labelStruct.title
759 };
760 lt->mLabels.push_back(l);
761 }
762 else if (relation == LabelStruct::BEGINS_IN_LABEL) {
763 LabelStruct l {
764 labelStruct.selectedRegion,
765 0,
766 labelStruct.getT1() - t0,
767 labelStruct.title
768 };
769 lt->mLabels.push_back(l);
770 }
771 else if (relation == LabelStruct::ENDS_IN_LABEL) {
772 LabelStruct l {
773 labelStruct.selectedRegion,
774 labelStruct.getT0() - t0,
775 t1 - t0,
776 labelStruct.title
777 };
778 lt->mLabels.push_back(l);
779 }
780 }
781 lt->mClipLen = (t1 - t0);
782
783 return TrackList::Temporary(nullptr, tmp, nullptr);
784}
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:87

References LabelStruct::BEGINS_IN_LABEL, LabelStruct::ENDS_IN_LABEL, mLabels, LabelStruct::selectedRegion, LabelStruct::SURROUNDS_LABEL, TrackList::Temporary(), and LabelStruct::WITHIN_LABEL.

Referenced by Cut(), ModifiedAnalysisTrack::ModifiedAnalysisTrack(), and EffectRepeat::Process().

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

◆ Create() [1/2]

LabelTrack * LabelTrack::Create ( TrackList trackList)
static

Create a new LabelTrack with unique default name and append it to the trackList.

Returns
New LabelTrack with unique default name

Definition at line 84 of file LabelTrack.cpp.

85{
86 return Create(trackList, trackList.MakeUniqueTrackName(GetDefaultName()));
87}
static LabelTrack * Create(TrackList &trackList, const wxString &name)
Create a new LabelTrack with specified name and append it to the trackList.
Definition: LabelTrack.cpp:76
static wxString GetDefaultName()
Definition: LabelTrack.cpp:63
wxString MakeUniqueTrackName(const wxString &baseTrackName) const
Returns string that contains baseTrackName, but is guaranteed to be unique among other tracks in that...
Definition: Track.cpp:411

References Create(), GetDefaultName(), and TrackList::MakeUniqueTrackName().

Here is the call graph for this function:

◆ Create() [2/2]

LabelTrack * LabelTrack::Create ( TrackList trackList,
const wxString &  name 
)
static

Create a new LabelTrack with specified name and append it to the trackList.

Returns
New LabelTrack with custom name

Definition at line 76 of file LabelTrack.cpp.

77{
78 auto track = std::make_shared<LabelTrack>();
79 track->SetName(name);
80 trackList.Add(track);
81 return track.get();
82}
const TranslatableString name
Definition: Distortion.cpp:76
TrackKind * Add(const std::shared_ptr< TrackKind > &t)
Definition: Track.h:1201

References TrackList::Add(), and name.

Referenced by AddedAnalysisTrack::AddedAnalysisTrack(), Create(), anonymous_namespace{LabelMenus.cpp}::DoAddLabel(), anonymous_namespace{DropoutDetector.cpp}::DropoutSubscription::DropoutSubscription(), anonymous_namespace{LabelMenus.cpp}::OnNewLabelTrack(), and anonymous_namespace{LabelMenus.cpp}::OnPasteNewLabel().

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

◆ Cut()

TrackListHolder LabelTrack::Cut ( double  t0,
double  t1 
)
overridevirtual

Create tracks and modify this track.

Returns
non-NULL or else throw May assume precondition: t0 <= t1
Precondition
IsLeader()
Postcondition
result: result->NChannels() == NChannels()

Implements Track.

Definition at line 713 of file LabelTrack.cpp.

714{
715 assert(IsLeader());
716 auto tmp = Copy(t0, t1);
717 Clear(t0, t1);
718 return tmp;
719}
TrackListHolder Copy(double t0, double t1, bool forClipboard=true) const override
Create new tracks and don't modify this track.
Definition: LabelTrack.cpp:735
void Clear(double t0, double t1) override
Definition: LabelTrack.cpp:188

References Clear(), Copy(), and Track::IsLeader().

Here is the call graph for this function:

◆ DeleteLabel()

void LabelTrack::DeleteLabel ( int  index)

Definition at line 994 of file LabelTrack.cpp.

995{
996 wxASSERT((index < (int)mLabels.size()));
997 auto iter = mLabels.begin() + index;
998 const auto title = iter->title;
999 mLabels.erase(iter);
1000
1002 this->SharedPointer<LabelTrack>(), title, index, -1 });
1003}

References LabelTrackEvent::Deletion, mLabels, Observer::Publisher< struct LabelTrackEvent >::Publish(), and title.

Referenced by Clear(), and Silence().

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

◆ DoGetInterval()

std::shared_ptr< WideChannelGroupInterval > LabelTrack::DoGetInterval ( size_t  iInterval)
overrideprivatevirtual

Retrieve an interval.

Postcondition
result: !(iInterval < NIntervals()) || result

Implements ChannelGroup.

Definition at line 148 of file LabelTrack.cpp.

149{
150 return MakeInterval(iInterval);
151}
std::shared_ptr< Interval > MakeInterval(size_t index)
Definition: LabelTrack.cpp:138

References MakeInterval().

Here is the call graph for this function:

◆ DoOnProjectTempoChange()

void LabelTrack::DoOnProjectTempoChange ( const std::optional< double > &  oldTempo,
double  newTempo 
)
overrideprivatevirtual
Precondition
IsLeader()

Implements Track.

Definition at line 176 of file LabelTrack.cpp.

178{
179 assert(IsLeader());
180 if (!oldTempo.has_value())
181 return;
182 const auto ratio = *oldTempo / newTempo;
183 for (auto& label : mLabels)
184 label.selectedRegion.setTimes(
185 label.getT0() * ratio, label.getT1() * ratio);
186}
TranslatableString label
Definition: TagsEditor.cpp:165

References Track::IsLeader(), label, and mLabels.

Here is the call graph for this function:

◆ Export()

void LabelTrack::Export ( wxTextFile &  f) const

Export labels including label start and end-times.

Definition at line 590 of file LabelTrack.cpp.

591{
592 // PRL: to do: export other selection fields
593 for (auto &labelStruct: mLabels)
594 labelStruct.Export(f);
595}

References mLabels.

◆ FindNextLabel()

int LabelTrack::FindNextLabel ( const SelectedRegion currentSelection)

Definition at line 1060 of file LabelTrack.cpp.

1061{
1062 int i = -1;
1063
1064 if (!mLabels.empty()) {
1065 int len = (int) mLabels.size();
1066 if (miLastLabel >= 0 && miLastLabel + 1 < len
1067 && currentRegion.t0() == mLabels[miLastLabel].getT0()
1068 && currentRegion.t0() == mLabels[miLastLabel + 1].getT0() ) {
1069 i = miLastLabel + 1;
1070 }
1071 else {
1072 i = 0;
1073 if (currentRegion.t0() < mLabels[len - 1].getT0()) {
1074 while (i < len &&
1075 mLabels[i].getT0() <= currentRegion.t0()) {
1076 i++;
1077 }
1078 }
1079 }
1080 }
1081
1082 miLastLabel = i;
1083 return i;
1084}

References miLastLabel, mLabels, and SelectedRegion::t0().

Referenced by anonymous_namespace{TransportMenus.cpp}::DoMoveToLabel().

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

◆ FindPrevLabel()

int LabelTrack::FindPrevLabel ( const SelectedRegion currentSelection)

Definition at line 1086 of file LabelTrack.cpp.

1087{
1088 int i = -1;
1089
1090 if (!mLabels.empty()) {
1091 int len = (int) mLabels.size();
1092 if (miLastLabel > 0 && miLastLabel < len
1093 && currentRegion.t0() == mLabels[miLastLabel].getT0()
1094 && currentRegion.t0() == mLabels[miLastLabel - 1].getT0() ) {
1095 i = miLastLabel - 1;
1096 }
1097 else {
1098 i = len - 1;
1099 if (currentRegion.t0() > mLabels[0].getT0()) {
1100 while (i >=0 &&
1101 mLabels[i].getT0() >= currentRegion.t0()) {
1102 i--;
1103 }
1104 }
1105 }
1106 }
1107
1108 miLastLabel = i;
1109 return i;
1110}

References miLastLabel, mLabels, and SelectedRegion::t0().

Referenced by anonymous_namespace{TransportMenus.cpp}::DoMoveToLabel().

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

◆ GetDefaultName()

wxString LabelTrack::GetDefaultName ( )
static

Definition at line 63 of file LabelTrack.cpp.

64{
65 return _("Labels");
66}
#define _(s)
Definition: Internat.h:73

References _.

Referenced by Create(), and NyquistEffect::ProcessOne().

Here is the caller graph for this function:

◆ GetLabel()

const LabelStruct * LabelTrack::GetLabel ( int  index) const

Definition at line 970 of file LabelTrack.cpp.

971{
972 return &mLabels[index];
973}

References mLabels.

Referenced by LabelDialog::AddLabels(), and anonymous_namespace{TransportMenus.cpp}::DoMoveToLabel().

Here is the caller graph for this function:

◆ GetLabels()

const LabelArray & LabelTrack::GetLabels ( ) const
inline

Definition at line 146 of file LabelTrack.h.

146{ return mLabels; }

Referenced by LabelTrackView::OverATextBox(), LabelTrackView::OverGlyph(), and GetInfoCommand::SendLabels().

Here is the caller graph for this function:

◆ GetNumLabels()

int LabelTrack::GetNumLabels ( ) const

Definition at line 965 of file LabelTrack.cpp.

966{
967 return mLabels.size();
968}

References mLabels.

Referenced by LabelDialog::AddLabels(), and anonymous_namespace{TransportMenus.cpp}::DoMoveToLabel().

Here is the caller graph for this function:

◆ GetTextOfLabels()

wxString LabelTrack::GetTextOfLabels ( double  t0,
double  t1 
) const

Definition at line 1041 of file LabelTrack.cpp.

1042{
1043 bool firstLabel = true;
1044 wxString retVal;
1045
1046 for (auto &labelStruct: mLabels) {
1047 if (labelStruct.getT0() >= t0 &&
1048 labelStruct.getT1() <= t1)
1049 {
1050 if (!firstLabel)
1051 retVal += '\t';
1052 firstLabel = false;
1053 retVal += labelStruct.title;
1054 }
1055 }
1056
1057 return retVal;
1058}

References mLabels.

◆ GetTypeInfo()

auto LabelTrack::GetTypeInfo ( ) const
overridevirtual

Implements Track.

Definition at line 113 of file LabelTrack.cpp.

114{
115 return typeInfo();
116}

References typeInfo().

Here is the call graph for this function:

◆ HandleXMLChild()

XMLTagHandler * LabelTrack::HandleXMLChild ( const std::string_view &  tag)
overridevirtual

Implements XMLTagHandler.

Definition at line 683 of file LabelTrack.cpp.

684{
685 if (tag == "label")
686 return this;
687 else
688 return NULL;
689}

◆ HandleXMLTag()

bool LabelTrack::HandleXMLTag ( const std::string_view &  tag,
const AttributesList attrs 
)
overridevirtual

Implements XMLTagHandler.

Definition at line 622 of file LabelTrack.cpp.

623{
624 if (tag == "label") {
625
626 SelectedRegion selectedRegion;
627 wxString title;
628
629 // loop through attrs, which is a null-terminated list of
630 // attribute-value pairs
631 for (auto pair : attrs)
632 {
633 auto attr = pair.first;
634 auto value = pair.second;
635
636 if (selectedRegion.HandleXMLAttribute(attr, value, "t", "t1"))
637 ;
638 // Bug 1905 no longer applies, as valueView has no limits anyway
639 else if (attr == "title")
640 title = value.ToWString();
641
642 } // while
643
644 // Handle files created by Audacity 1.1. Labels in Audacity 1.1
645 // did not have separate start- and end-times.
646 // PRL: this superfluous now, given class SelectedRegion's internal
647 // consistency guarantees
648 //if (selectedRegion.t1() < 0)
649 // selectedRegion.collapseToT0();
650
651 LabelStruct l { selectedRegion, title };
652 mLabels.push_back(l);
653
654 return true;
655 }
656 else if (tag == "labeltrack") {
657 long nValue = -1;
658 for (auto pair : attrs)
659 {
660 auto attr = pair.first;
661 auto value = pair.second;
662
663 if (this->Track::HandleCommonXMLAttribute(attr, value))
664 ;
665 else if (attr == "numlabels" && value.TryGet(nValue))
666 {
667 if (nValue < 0)
668 {
669 wxLogWarning(wxT("Project shows negative number of labels: %d"), nValue);
670 return false;
671 }
672 mLabels.clear();
673 mLabels.reserve(nValue);
674 }
675 }
676
677 return true;
678 }
679
680 return false;
681}
wxT("CloseDown"))
Defines a selected portion of a project.
bool HandleXMLAttribute(const std::string_view &attr, const XMLAttributeValueView &value, const char *legacyT0Name=sDefaultT0Name, const char *legacyT1Name=sDefaultT1Name)
bool HandleCommonXMLAttribute(const std::string_view &attr, const XMLAttributeValueView &valueView)
Definition: Track.cpp:1235

References Track::HandleCommonXMLAttribute(), SelectedRegion::HandleXMLAttribute(), mLabels, title, and wxT().

Here is the call graph for this function:

◆ Import()

void LabelTrack::Import ( wxTextFile &  f)

Import labels, handling files with or without end-times.

Definition at line 598 of file LabelTrack.cpp.

599{
600 int lines = in.GetLineCount();
601
602 mLabels.clear();
603 mLabels.reserve(lines);
604
605 //Currently, we expect a tag file to have two values and a label
606 //on each line. If the second token is not a number, we treat
607 //it as a single-value label.
608 bool error = false;
609 for (int index = 0; index < lines;) {
610 try {
611 // Let LabelStruct::Import advance index
612 LabelStruct l { LabelStruct::Import(in, index) };
613 mLabels.push_back(l);
614 }
615 catch(const LabelStruct::BadFormatException&) { error = true; }
616 }
617 if (error)
618 ::AudacityMessageBox( XO("One or more saved labels could not be read.") );
619 SortLabels();
620}
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
XO("Cut/Copy/Paste")
static LabelStruct Import(wxTextFile &file, int &index)
Definition: LabelTrack.cpp:425

References AudacityMessageBox(), LabelStruct::Import(), mLabels, SortLabels(), and XO().

Here is the call graph for this function:

◆ InsertSilence()

void LabelTrack::InsertSilence ( double  t,
double  len 
)
overridevirtual

May assume precondition: t0 <= t1

Precondition
IsLeader()

Implements Track.

Definition at line 950 of file LabelTrack.cpp.

951{
952 assert(IsLeader());
953 for (auto &labelStruct: mLabels) {
954 double t0 = labelStruct.getT0();
955 double t1 = labelStruct.getT1();
956 if (t0 >= t)
957 t0 += len;
958
959 if (t1 >= t)
960 t1 += len;
961 labelStruct.selectedRegion.setTimes(t0, t1);
962 }
963}

References Track::IsLeader(), and mLabels.

Here is the call graph for this function:

◆ MakeInterval()

auto LabelTrack::MakeInterval ( size_t  index)

Definition at line 138 of file LabelTrack.cpp.

139{
140 if (index >= mLabels.size())
141 return {};
142 auto &label = mLabels[index];
143 return std::make_shared<Interval>(
144 *this, label.getT0(), label.getT1(), index);
145}

References label.

Referenced by DoGetInterval().

Here is the caller graph for this function:

◆ MoveTo()

void LabelTrack::MoveTo ( double  o)
overridevirtual

Change start time to given time point.

Implements ChannelGroup.

Definition at line 166 of file LabelTrack.cpp.

167{
168 if (!mLabels.empty()) {
169 const auto offset = origin - mLabels[0].selectedRegion.t0();
170 for (auto &labelStruct: mLabels) {
171 labelStruct.selectedRegion.move(offset);
172 }
173 }
174}

References mLabels.

Referenced by ModifiedAnalysisTrack::ModifiedAnalysisTrack().

Here is the caller graph for this function:

◆ New()

LabelTrack * LabelTrack::New ( AudacityProject project)
static

Definition at line 68 of file LabelTrack.cpp.

69{
70 auto &tracks = TrackList::Get( project );
71 auto result = tracks.Add(std::make_shared<LabelTrack>());
72 result->AttachedTrackObjects::BuildAll();
73 return result;
74}
const auto tracks
const auto project
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:347

References TrackList::Get(), project, and tracks.

Here is the call graph for this function:

◆ NIntervals()

size_t LabelTrack::NIntervals ( ) const
overridevirtual

Report the number of intervals.

Implements ChannelGroup.

Definition at line 133 of file LabelTrack.cpp.

134{
135 return mLabels.size();
136}

References mLabels.

◆ OnLabelAdded()

void LabelTrack::OnLabelAdded ( const wxString &  title,
int  pos 
)

◆ Paste()

void LabelTrack::Paste ( double  t,
const Track src 
)
overridevirtual

Weak precondition allows overrides to replicate one channel into many.

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

Implements Track.

Definition at line 816 of file LabelTrack.cpp.

817{
818 bool bOk = src.TypeSwitch<bool>([&](const LabelTrack &lt) {
819 double shiftAmt = lt.mClipLen > 0.0 ? lt.mClipLen : lt.GetEndTime();
820
821 ShiftLabelsOnInsert(shiftAmt, t);
822 PasteOver(t, src);
823
824 return true;
825 });
826
827 if (!bOk)
828 // THROW_INCONSISTENCY_EXCEPTION; // ?
829 (void)0;// intentionally do nothing
830}
void ShiftLabelsOnInsert(double length, double pt)
Definition: LabelTrack.cpp:238
bool PasteOver(double t, const Track &src)
Definition: LabelTrack.cpp:787
R TypeSwitch(const Functions &...functions)
Definition: Track.h:436

References PasteOver(), ShiftLabelsOnInsert(), and Track::TypeSwitch().

Referenced by EffectRepeat::Process().

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

◆ PasteInto()

Track::Holder LabelTrack::PasteInto ( AudacityProject project,
TrackList list 
) const
overridevirtual

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

Precondition
IsLeader()
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 leader track

Implements Track.

Definition at line 123 of file LabelTrack.cpp.

124{
125 assert(IsLeader());
126 auto pNewTrack = std::make_shared<LabelTrack>();
127 pNewTrack->Init(*this);
128 pNewTrack->Paste(0.0, *this);
129 list.Add(pNewTrack);
130 return pNewTrack;
131}

References TrackList::Add(), and Track::IsLeader().

Here is the call graph for this function:

◆ PasteOver()

bool LabelTrack::PasteOver ( double  t,
const Track src 
)

Definition at line 787 of file LabelTrack.cpp.

788{
789 auto result = src.TypeSwitch<bool>([&](const LabelTrack &sl) {
790 int len = mLabels.size();
791 int pos = 0;
792
793 while (pos < len && mLabels[pos].getT0() < t)
794 pos++;
795
796 for (auto &labelStruct: sl.mLabels) {
797 LabelStruct l {
798 labelStruct.selectedRegion,
799 labelStruct.getT0() + t,
800 labelStruct.getT1() + t,
801 labelStruct.title
802 };
803 mLabels.insert(mLabels.begin() + pos++, l);
804 }
805
806 return true;
807 });
808
809 if (!result)
810 // THROW_INCONSISTENCY_EXCEPTION; // ?
811 (void)0;// intentionally do nothing
812
813 return result;
814}

References mLabels, LabelStruct::selectedRegion, and Track::TypeSwitch().

Referenced by Paste().

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

◆ Repeat()

bool LabelTrack::Repeat ( double  t0,
double  t1,
int  n 
)

Definition at line 833 of file LabelTrack.cpp.

834{
835 // Sanity-check the arguments
836 if (n < 0 || t1 < t0)
837 return false;
838
839 double tLen = t1 - t0;
840
841 // Insert space for the repetitions
842 ShiftLabelsOnInsert(tLen * n, t1);
843
844 // mLabels may resize as we iterate, so use subscripting
845 for (unsigned int i = 0; i < mLabels.size(); ++i)
846 {
848 mLabels[i].RegionRelation(t0, t1, this);
849 if (relation == LabelStruct::SURROUNDS_LABEL)
850 {
851 // Label is completely inside the selection; duplicate it in each
852 // repeat interval
853 unsigned int pos = i; // running label insertion position in mLabels
854
855 for (int j = 1; j <= n; j++)
856 {
857 const LabelStruct &label = mLabels[i];
858 LabelStruct l {
859 label.selectedRegion,
860 label.getT0() + j * tLen,
861 label.getT1() + j * tLen,
862 label.title
863 };
864
865 // Figure out where to insert
866 while (pos < mLabels.size() &&
867 mLabels[pos].getT0() < l.getT0())
868 pos++;
869 mLabels.insert(mLabels.begin() + pos, l);
870 }
871 }
872 else if (relation == LabelStruct::BEGINS_IN_LABEL)
873 {
874 // Label ends inside the selection; ShiftLabelsOnInsert() hasn't touched
875 // it, and we need to extend it through to the last repeat interval
876 mLabels[i].selectedRegion.moveT1(n * tLen);
877 }
878
879 // Other cases have already been handled by ShiftLabelsOnInsert()
880 }
881
882 return true;
883}

References LabelStruct::BEGINS_IN_LABEL, label, mLabels, ShiftLabelsOnInsert(), and LabelStruct::SURROUNDS_LABEL.

Referenced by EffectRepeat::Process().

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

◆ ScaleLabels()

void LabelTrack::ScaleLabels ( double  b,
double  e,
double  change 
)

Definition at line 266 of file LabelTrack.cpp.

267{
268 for (auto &labelStruct: mLabels) {
269 labelStruct.selectedRegion.setTimes(
270 AdjustTimeStampOnScale(labelStruct.getT0(), b, e, change),
271 AdjustTimeStampOnScale(labelStruct.getT1(), b, e, change));
272 }
273}
double AdjustTimeStampOnScale(double t, double b, double e, double change)
Definition: LabelTrack.cpp:275

References AdjustTimeStampOnScale(), and mLabels.

Here is the call graph for this function:

◆ SetLabel()

void LabelTrack::SetLabel ( size_t  iLabel,
const LabelStruct newLabel 
)

Definition at line 153 of file LabelTrack.cpp.

154{
155 if( iLabel >= mLabels.size() ) {
156 wxASSERT( false );
157 mLabels.resize( iLabel + 1 );
158 }
159 mLabels[ iLabel ] = newLabel;
160}

References mLabels.

◆ SetSelected()

void LabelTrack::SetSelected ( bool  s)
overridevirtual

Reimplemented from Track.

Definition at line 336 of file LabelTrack.cpp.

337{
338 bool selected = GetSelected();
340 if ( selected != GetSelected() )
342 this->SharedPointer<LabelTrack>(), {}, -1, -1 });
343}
bool GetSelected() const
Selectedness is always the same for all channels of a group.
Definition: Track.cpp:70
virtual void SetSelected(bool s)
Definition: Track.cpp:75

References Track::GetSelected(), Observer::Publisher< struct LabelTrackEvent >::Publish(), LabelTrackEvent::Selection, and Track::SetSelected().

Here is the call graph for this function:

◆ ShiftLabelsOnInsert()

void LabelTrack::ShiftLabelsOnInsert ( double  length,
double  pt 
)

Definition at line 238 of file LabelTrack.cpp.

239{
240 for (auto &labelStruct: mLabels) {
242 labelStruct.RegionRelation(pt, pt, this);
243
244 if (relation == LabelStruct::BEFORE_LABEL)
245 labelStruct.selectedRegion.move(length);
246 else if (relation == LabelStruct::WITHIN_LABEL)
247 labelStruct.selectedRegion.moveT1(length);
248 }
249}

References LabelStruct::BEFORE_LABEL, mLabels, and LabelStruct::WITHIN_LABEL.

Referenced by Paste(), Repeat(), and SyncLockAdjust().

Here is the caller graph for this function:

◆ Silence()

void LabelTrack::Silence ( double  t0,
double  t1,
ProgressReporter  reportProgress = {} 
)
overridevirtual
Precondition
IsLeader()

Implements Track.

Definition at line 903 of file LabelTrack.cpp.

904{
905 assert(IsLeader());
906 int len = mLabels.size();
907
908 // mLabels may resize as we iterate, so use subscripting
909 for (int i = 0; i < len; ++i) {
911 mLabels[i].RegionRelation(t0, t1, this);
912 if (relation == LabelStruct::WITHIN_LABEL)
913 {
914 // Split label around the selection
915 const LabelStruct &label = mLabels[i];
916 LabelStruct l {
917 label.selectedRegion,
918 t1,
919 label.getT1(),
920 label.title
921 };
922
923 mLabels[i].selectedRegion.setT1(t0);
924
925 // This might not be the right place to insert, but we sort at the end
926 ++i;
927 mLabels.insert(mLabels.begin() + i, l);
928 }
929 else if (relation == LabelStruct::ENDS_IN_LABEL)
930 {
931 // Beginning of label to selection end
932 mLabels[i].selectedRegion.setT0(t1);
933 }
934 else if (relation == LabelStruct::BEGINS_IN_LABEL)
935 {
936 // End of label to selection beginning
937 mLabels[i].selectedRegion.setT1(t0);
938 }
939 else if (relation == LabelStruct::SURROUNDS_LABEL)
940 {
941 DeleteLabel( i );
942 len--;
943 i--;
944 }
945 }
946
947 SortLabels();
948}

References LabelStruct::BEGINS_IN_LABEL, DeleteLabel(), LabelStruct::ENDS_IN_LABEL, Track::IsLeader(), label, mLabels, SortLabels(), LabelStruct::SURROUNDS_LABEL, and LabelStruct::WITHIN_LABEL.

Here is the call graph for this function:

◆ SortLabels()

void LabelTrack::SortLabels ( )

Sorts the labels in order of their starting times. This function is called often (whilst dragging a label) We expect them to be very nearly in order, so insertion sort (with a linear search) is a reasonable choice.

Definition at line 1009 of file LabelTrack.cpp.

1010{
1011 const auto begin = mLabels.begin();
1012 const auto nn = (int)mLabels.size();
1013 int i = 1;
1014 while (true)
1015 {
1016 // Find the next disorder
1017 while (i < nn && mLabels[i - 1].getT0() <= mLabels[i].getT0())
1018 ++i;
1019 if (i >= nn)
1020 break;
1021
1022 // Where must element i sink to? At most i - 1, maybe less
1023 int j = i - 2;
1024 while( (j >= 0) && (mLabels[j].getT0() > mLabels[i].getT0()) )
1025 --j;
1026 ++j;
1027
1028 // Now fix the disorder
1030 begin + j,
1031 begin + i,
1032 begin + i + 1
1033 );
1034
1035 // Let listeners update their stored indices
1037 this->SharedPointer<LabelTrack>(), mLabels[j].title, i, j });
1038 }
1039}
auto begin(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:150
void rotate(const float *oldPhase, const float *newPhase, std::complex< float > *dst, int32_t n)
Definition: VectorOps.h:140

References PackedArray::begin(), mLabels, LabelTrackEvent::Permutation, Observer::Publisher< struct LabelTrackEvent >::Publish(), and staffpad::vo::rotate().

Referenced by ChangeLabelsOnReverse(), Import(), Silence(), and WarpLabels().

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

◆ SyncLockAdjust()

void LabelTrack::SyncLockAdjust ( double  oldT1,
double  newT1 
)
overridevirtual

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

Precondition
IsLeader()

Reimplemented from Track.

Definition at line 885 of file LabelTrack.cpp.

886{
887 assert(IsLeader());
888 if (newT1 > oldT1) {
889 // Insert space within the track
890
891 if (oldT1 > GetEndTime())
892 return;
893
894 //Clear(oldT1, newT1);
895 ShiftLabelsOnInsert(newT1 - oldT1, oldT1);
896 }
897 else if (newT1 < oldT1) {
898 // Remove from the track
899 Clear(newT1, oldT1);
900 }
901}
double GetEndTime() const
Get the maximum of End() values of intervals, or 0 when none.
Definition: Channel.cpp:135

References Clear(), ChannelGroup::GetEndTime(), Track::IsLeader(), and ShiftLabelsOnInsert().

Here is the call graph for this function:

◆ WarpLabels()

void LabelTrack::WarpLabels ( const TimeWarper warper)

Definition at line 294 of file LabelTrack.cpp.

294 {
295 for (auto &labelStruct: mLabels) {
296 labelStruct.selectedRegion.setTimes(
297 warper.Warp(labelStruct.getT0()),
298 warper.Warp(labelStruct.getT1()));
299 }
300
301 // This should not be needed, assuming the warper is nondecreasing, but
302 // let's not assume too much.
303 SortLabels();
304}
virtual double Warp(double originalTime) const =0

References mLabels, SortLabels(), and TimeWarper::Warp().

Referenced by EffectChangeSpeed::ProcessLabelTrack(), and EffectSBSMS::ProcessLabelTrack().

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

◆ WriteXML()

void LabelTrack::WriteXML ( XMLWriter xmlFile) const
overridevirtual

Implements Track.

Definition at line 691 of file LabelTrack.cpp.

693{
694 assert(IsLeader());
695 int len = mLabels.size();
696
697 xmlFile.StartTag(wxT("labeltrack"));
698 this->Track::WriteCommonXMLAttributes( xmlFile );
699 xmlFile.WriteAttr(wxT("numlabels"), len);
700
701 for (auto &labelStruct: mLabels) {
702 xmlFile.StartTag(wxT("label"));
703 labelStruct.getSelectedRegion()
704 .WriteXMLAttributes(xmlFile, "t", "t1");
705 // PRL: to do: write other selection fields
706 xmlFile.WriteAttr(wxT("title"), labelStruct.title);
707 xmlFile.EndTag(wxT("label"));
708 }
709
710 xmlFile.EndTag(wxT("labeltrack"));
711}
void WriteCommonXMLAttributes(XMLWriter &xmlFile, bool includeNameAndSelected=true) const
Definition: Track.cpp:1219
virtual void StartTag(const wxString &name)
Definition: XMLWriter.cpp:79
void WriteAttr(const wxString &name, const Identifier &value)
Definition: XMLWriter.h:36
virtual void EndTag(const wxString &name)
Definition: XMLWriter.cpp:102

References Track::WriteCommonXMLAttributes(), and wxT().

Here is the call graph for this function:

Member Data Documentation

◆ mClipLen

double LabelTrack::mClipLen
private

Definition at line 206 of file LabelTrack.h.

◆ miLastLabel

int LabelTrack::miLastLabel
private

Definition at line 208 of file LabelTrack.h.

Referenced by FindNextLabel(), and FindPrevLabel().

◆ mLabels

LabelArray LabelTrack::mLabels
private

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