Audacity 3.2.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | 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 = ChannelGroupAttachments
 
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
 
Track::Holder Cut (double t0, double t1) override
 Create tracks and modify this track. More...
 
Track::Holder 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, LabelFormat format)
 Import labels, handling files with or without end-times. More...
 
void Export (wxTextFile &f, LabelFormat format) 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
 
- 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 > >
 
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 MoveTo (double o)=0
 Change start time to given time point. 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
 
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 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 LabelFormat FormatForFileName (const wxString &fileName)
 
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 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...
 

Static Public Attributes

static const FileNames::FileType SubripFiles { XO("SubRip text file"), { wxT("srt") }, true }
 
static const FileNames::FileType WebVTTFiles { XO("WebVTT file"), { wxT("vtt") }, true }
 
- Static Public Attributes inherited from Observer::Publisher< struct LabelTrackEvent >
static constexpr bool notifies_all
 

Private Member Functions

Track::Holder Clone (bool backup) const override
 
std::shared_ptr< WideChannelGroupIntervalDoGetInterval (size_t iInterval) override
 Retrieve an interval. More...
 

Private Attributes

LabelArray mLabels
 
double mClipLen
 
int miLastLabel
 

Additional Inherited Members

- 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)
 
- 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...
 
virtual std::shared_ptr< ChannelDoGetChannel (size_t iChannel)=0
 
virtual std::shared_ptr< IntervalDoGetInterval (size_t iInterval)=0
 Retrieve an interval. More...
 
virtual ChannelGroupDoGetChannelGroup () const =0
 Subclass must override. 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...
 

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 92 of file LabelTrack.h.

Member Typedef Documentation

◆ Holder

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

Definition at line 125 of file LabelTrack.h.

Constructor & Destructor Documentation

◆ LabelTrack() [1/2]

LabelTrack::LabelTrack ( )

Definition at line 108 of file LabelTrack.cpp.

110 , mClipLen{ 0.0 }
111 , miLastLabel{ -1 }
112{
113}
double mClipLen
Definition: LabelTrack.h:221
int miLastLabel
Definition: LabelTrack.h:223
Generates overrides of channel-related functions.
Definition: Track.h:450

◆ LabelTrack() [2/2]

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

Definition at line 115 of file LabelTrack.cpp.

116 : UniqueChannelTrack{ orig, std::move(a) }
117 , mClipLen{ 0.0 }
118{
119 for (auto &original: orig.mLabels) {
120 LabelStruct l { original.selectedRegion, original.title };
121 mLabels.push_back(l);
122 }
123}
A LabelStruct holds information for ONE label in a LabelTrack.
Definition: LabelTrack.h:37
SelectedRegion selectedRegion
Definition: LabelTrack.h:77
LabelArray mLabels
Definition: LabelTrack.h:218

References mLabels, and LabelStruct::selectedRegion.

◆ ~LabelTrack()

LabelTrack::~LabelTrack ( )
virtual

Definition at line 178 of file LabelTrack.cpp.

179{
180}

Member Function Documentation

◆ AddLabel()

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

Definition at line 1093 of file LabelTrack.cpp.

1095{
1096 LabelStruct l { selectedRegion, title };
1097
1098 int len = mLabels.size();
1099 int pos = 0;
1100
1101 while (pos < len && mLabels[pos].getT0() < selectedRegion.t0())
1102 pos++;
1103
1104 mLabels.insert(mLabels.begin() + pos, l);
1105
1107 this->SharedPointer<LabelTrack>(), title, -1, pos });
1108
1109 return pos;
1110}
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 278 of file LabelTrack.cpp.

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

Referenced by ScaleLabels().

Here is the caller graph for this function:

◆ ChangeLabelsOnReverse()

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

Definition at line 254 of file LabelTrack.cpp.

255{
256 for (auto &labelStruct: mLabels) {
257 if (labelStruct.RegionRelation(b, e, this) ==
259 {
260 double aux = b + (e - labelStruct.getT1());
261 labelStruct.selectedRegion.setTimes(
262 aux,
263 e - (labelStruct.getT0() - b));
264 }
265 }
266 SortLabels();
267}
@ SURROUNDS_LABEL
Definition: LabelTrack.h:63
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 137 of file LabelTrack.cpp.

138{
139 return typeInfo();
140}
static const Track::TypeInfo & typeInfo()
Definition: LabelTrack.cpp:125

References typeInfo().

Here is the call graph for this function:

◆ Clear()

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

May assume precondition: t0 <= t1

Implements Track.

Definition at line 192 of file LabelTrack.cpp.

193{
194 // May DELETE labels, so use subscripts to iterate
195 for (size_t i = 0; i < mLabels.size(); ++i) {
196 auto &labelStruct = mLabels[i];
198 labelStruct.RegionRelation(b, e, this);
199 if (relation == LabelStruct::BEFORE_LABEL)
200 labelStruct.selectedRegion.move(- (e-b));
201 else if (relation == LabelStruct::SURROUNDS_LABEL) {
202 DeleteLabel( i );
203 --i;
204 }
205 else if (relation == LabelStruct::ENDS_IN_LABEL)
206 labelStruct.selectedRegion.setTimes(
207 b,
208 labelStruct.getT1() - (e - b));
209 else if (relation == LabelStruct::BEGINS_IN_LABEL)
210 labelStruct.selectedRegion.setT1(b);
211 else if (relation == LabelStruct::WITHIN_LABEL)
212 labelStruct.selectedRegion.moveT1( - (e-b));
213 }
214}
TimeRelations
Relationships between selection region and labels.
Definition: LabelTrack.h:60
@ BEGINS_IN_LABEL
Definition: LabelTrack.h:65
void DeleteLabel(int index)

References LabelStruct::BEFORE_LABEL, LabelStruct::BEGINS_IN_LABEL, DeleteLabel(), LabelStruct::ENDS_IN_LABEL, 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()

Track::Holder 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) 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

Implements Track.

Definition at line 348 of file LabelTrack.cpp.

349{
350 auto result = std::make_shared<LabelTrack>(*this, ProtectedCreationArg{});
351 result->Init(*this);
352 return result;
353}

◆ Copy()

Track::Holder 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

Implements Track.

Definition at line 856 of file LabelTrack.cpp.

857{
858 auto tmp = std::make_shared<LabelTrack>();
859 tmp->Init(*this);
860 const auto lt = static_cast<LabelTrack*>(tmp.get());
861
862 for (auto &labelStruct: mLabels) {
864 labelStruct.RegionRelation(t0, t1, this);
865 if (relation == LabelStruct::SURROUNDS_LABEL) {
866 LabelStruct l {
867 labelStruct.selectedRegion,
868 labelStruct.getT0() - t0,
869 labelStruct.getT1() - t0,
870 labelStruct.title
871 };
872 lt->mLabels.push_back(l);
873 }
874 else if (relation == LabelStruct::WITHIN_LABEL) {
875 LabelStruct l {
876 labelStruct.selectedRegion,
877 0,
878 t1-t0,
879 labelStruct.title
880 };
881 lt->mLabels.push_back(l);
882 }
883 else if (relation == LabelStruct::BEGINS_IN_LABEL) {
884 LabelStruct l {
885 labelStruct.selectedRegion,
886 0,
887 labelStruct.getT1() - t0,
888 labelStruct.title
889 };
890 lt->mLabels.push_back(l);
891 }
892 else if (relation == LabelStruct::ENDS_IN_LABEL) {
893 LabelStruct l {
894 labelStruct.selectedRegion,
895 labelStruct.getT0() - t0,
896 t1 - t0,
897 labelStruct.title
898 };
899 lt->mLabels.push_back(l);
900 }
901 }
902 lt->mClipLen = (t1 - t0);
903
904 return tmp;
905}
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:95

References LabelStruct::BEGINS_IN_LABEL, LabelStruct::ENDS_IN_LABEL, mLabels, LabelStruct::selectedRegion, LabelStruct::SURROUNDS_LABEL, and LabelStruct::WITHIN_LABEL.

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

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 103 of file LabelTrack.cpp.

104{
105 return Create(trackList, trackList.MakeUniqueTrackName(GetDefaultName()));
106}
static LabelTrack * Create(TrackList &trackList, const wxString &name)
Create a new LabelTrack with specified name and append it to the trackList.
Definition: LabelTrack.cpp:95
static wxString GetDefaultName()
Definition: LabelTrack.cpp:82
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:369

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 95 of file LabelTrack.cpp.

96{
97 auto track = std::make_shared<LabelTrack>();
98 track->SetName(name);
99 trackList.Add(track);
100 return track.get();
101}
const TranslatableString name
Definition: Distortion.cpp:76
TrackKind * Add(const std::shared_ptr< TrackKind > &t, bool assignIds=true)
Definition: Track.h:1048

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()

Track::Holder LabelTrack::Cut ( double  t0,
double  t1 
)
overridevirtual

Create tracks and modify this track.

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

Implements Track.

Definition at line 835 of file LabelTrack.cpp.

836{
837 auto tmp = Copy(t0, t1);
838 Clear(t0, t1);
839 return tmp;
840}
Track::Holder Copy(double t0, double t1, bool forClipboard=true) const override
Create new tracks and don't modify this track.
Definition: LabelTrack.cpp:856
void Clear(double t0, double t1) override
Definition: LabelTrack.cpp:192

References Clear(), and Copy().

Here is the call graph for this function:

◆ DeleteLabel()

void LabelTrack::DeleteLabel ( int  index)

Definition at line 1112 of file LabelTrack.cpp.

1113{
1114 wxASSERT((index < (int)mLabels.size()));
1115 auto iter = mLabels.begin() + index;
1116 const auto title = iter->title;
1117 mLabels.erase(iter);
1118
1120 this->SharedPointer<LabelTrack>(), title, index, -1 });
1121}

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 164 of file LabelTrack.cpp.

165{
166 return MakeInterval(iInterval);
167}
std::shared_ptr< Interval > MakeInterval(size_t index)
Definition: LabelTrack.cpp:156

References MakeInterval().

Here is the call graph for this function:

◆ Export()

void LabelTrack::Export ( wxTextFile &  f,
LabelFormat  format 
) const

Export labels including label start and end-times.

Definition at line 691 of file LabelTrack.cpp.

692{
694 f.AddLine(wxT("WEBVTT"));
695 f.AddLine(wxT(""));
696 }
697
698 // PRL: to do: export other selection fields
699 int index = 0;
700 for (auto &labelStruct: mLabels)
701 labelStruct.Export(f, format, index++);
702}
wxT("CloseDown"))

References anonymous_namespace{ExportPCM.cpp}::format, mLabels, WEBVTT, and wxT().

Here is the call graph for this function:

◆ FindNextLabel()

int LabelTrack::FindNextLabel ( const SelectedRegion currentSelection)

Definition at line 1178 of file LabelTrack.cpp.

1179{
1180 int i = -1;
1181
1182 if (!mLabels.empty()) {
1183 int len = (int) mLabels.size();
1184 if (miLastLabel >= 0 && miLastLabel + 1 < len
1185 && currentRegion.t0() == mLabels[miLastLabel].getT0()
1186 && currentRegion.t0() == mLabels[miLastLabel + 1].getT0() ) {
1187 i = miLastLabel + 1;
1188 }
1189 else {
1190 i = 0;
1191 if (currentRegion.t0() < mLabels[len - 1].getT0()) {
1192 while (i < len &&
1193 mLabels[i].getT0() <= currentRegion.t0()) {
1194 i++;
1195 }
1196 }
1197 }
1198 }
1199
1200 miLastLabel = i;
1201 return i;
1202}

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 1204 of file LabelTrack.cpp.

1205{
1206 int i = -1;
1207
1208 if (!mLabels.empty()) {
1209 int len = (int) mLabels.size();
1210 if (miLastLabel > 0 && miLastLabel < len
1211 && currentRegion.t0() == mLabels[miLastLabel].getT0()
1212 && currentRegion.t0() == mLabels[miLastLabel - 1].getT0() ) {
1213 i = miLastLabel - 1;
1214 }
1215 else {
1216 i = len - 1;
1217 if (currentRegion.t0() > mLabels[0].getT0()) {
1218 while (i >=0 &&
1219 mLabels[i].getT0() >= currentRegion.t0()) {
1220 i--;
1221 }
1222 }
1223 }
1224 }
1225
1226 miLastLabel = i;
1227 return i;
1228}

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:

◆ FormatForFileName()

LabelFormat LabelTrack::FormatForFileName ( const wxString &  fileName)
static

Definition at line 704 of file LabelTrack.cpp.

705{
707 if (fileName.Right(4).CmpNoCase(wxT(".srt")) == 0) {
709 } else if (fileName.Right(4).CmpNoCase(wxT(".vtt")) == 0) {
711 }
712 return format;
713}
LabelFormat
Definition: LabelTrack.h:30

References anonymous_namespace{ExportPCM.cpp}::format, SUBRIP, TEXT, WEBVTT, and wxT().

Referenced by LabelDialog::OnExport(), anonymous_namespace{FileMenus.cpp}::OnExportLabels(), LabelDialog::OnImport(), and anonymous_namespace{FileMenus.cpp}::OnImportLabels().

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

◆ GetDefaultName()

wxString LabelTrack::GetDefaultName ( )
static

Definition at line 82 of file LabelTrack.cpp.

83{
84 return _("Labels");
85}
#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 1088 of file LabelTrack.cpp.

1089{
1090 return &mLabels[index];
1091}

References mLabels.

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

Here is the caller graph for this function:

◆ GetLabels()

const LabelArray & LabelTrack::GetLabels ( ) const
inline

Definition at line 156 of file LabelTrack.h.

156{ return mLabels; }

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

Here is the caller graph for this function:

◆ GetNumLabels()

int LabelTrack::GetNumLabels ( ) const

Definition at line 1083 of file LabelTrack.cpp.

1084{
1085 return mLabels.size();
1086}

References mLabels.

Referenced by LabelDialog::AddLabels(), DEFINE_ATTACHED_VIRTUAL_OVERRIDE(), 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 1159 of file LabelTrack.cpp.

1160{
1161 bool firstLabel = true;
1162 wxString retVal;
1163
1164 for (auto &labelStruct: mLabels) {
1165 if (labelStruct.getT0() >= t0 &&
1166 labelStruct.getT1() <= t1)
1167 {
1168 if (!firstLabel)
1169 retVal += '\t';
1170 firstLabel = false;
1171 retVal += labelStruct.title;
1172 }
1173 }
1174
1175 return retVal;
1176}

References mLabels.

◆ GetTypeInfo()

auto LabelTrack::GetTypeInfo ( ) const
overridevirtual

Implements Track.

Definition at line 132 of file LabelTrack.cpp.

133{
134 return typeInfo();
135}

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 806 of file LabelTrack.cpp.

807{
808 if (tag == "label")
809 return this;
810 else
811 return NULL;
812}

◆ HandleXMLTag()

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

Implements XMLTagHandler.

Definition at line 745 of file LabelTrack.cpp.

746{
747 if (tag == "label") {
748
749 SelectedRegion selectedRegion;
750 wxString title;
751
752 // loop through attrs, which is a null-terminated list of
753 // attribute-value pairs
754 for (auto pair : attrs)
755 {
756 auto attr = pair.first;
757 auto value = pair.second;
758
759 if (selectedRegion.HandleXMLAttribute(attr, value, "t", "t1"))
760 ;
761 // Bug 1905 no longer applies, as valueView has no limits anyway
762 else if (attr == "title")
763 title = value.ToWString();
764
765 } // while
766
767 // Handle files created by Audacity 1.1. Labels in Audacity 1.1
768 // did not have separate start- and end-times.
769 // PRL: this superfluous now, given class SelectedRegion's internal
770 // consistency guarantees
771 //if (selectedRegion.t1() < 0)
772 // selectedRegion.collapseToT0();
773
774 LabelStruct l { selectedRegion, title };
775 mLabels.push_back(l);
776
777 return true;
778 }
779 else if (tag == "labeltrack") {
780 long nValue = -1;
781 for (auto pair : attrs)
782 {
783 auto attr = pair.first;
784 auto value = pair.second;
785
786 if (this->Track::HandleCommonXMLAttribute(attr, value))
787 ;
788 else if (attr == "numlabels" && value.TryGet(nValue))
789 {
790 if (nValue < 0)
791 {
792 wxLogWarning(wxT("Project shows negative number of labels: %d"), nValue);
793 return false;
794 }
795 mLabels.clear();
796 mLabels.reserve(nValue);
797 }
798 }
799
800 return true;
801 }
802
803 return false;
804}
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:819

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

Here is the call graph for this function:

◆ Import()

void LabelTrack::Import ( wxTextFile &  f,
LabelFormat  format 
)

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

Definition at line 716 of file LabelTrack.cpp.

717{
719 ::AudacityMessageBox( XO("Importing WebVTT files is not currently supported.") );
720 return;
721 }
722
723 int lines = in.GetLineCount();
724
725 mLabels.clear();
726 mLabels.reserve(lines);
727
728 //Currently, we expect a tag file to have two values and a label
729 //on each line. If the second token is not a number, we treat
730 //it as a single-value label.
731 bool error = false;
732 for (int index = 0; index < lines;) {
733 try {
734 // Let LabelStruct::Import advance index
735 LabelStruct l { LabelStruct::Import(in, index, format) };
736 mLabels.push_back(l);
737 }
738 catch(const LabelStruct::BadFormatException&) { error = true; }
739 }
740 if (error)
741 ::AudacityMessageBox( XO("One or more saved labels could not be read.") );
742 SortLabels();
743}
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, LabelFormat format)
Definition: LabelTrack.cpp:439

References AudacityMessageBox(), anonymous_namespace{ExportPCM.cpp}::format, LabelStruct::Import(), mLabels, SortLabels(), WEBVTT, and XO().

Here is the call graph for this function:

◆ InsertSilence()

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

May assume precondition: t0 <= t1

Implements Track.

Definition at line 1069 of file LabelTrack.cpp.

1070{
1071 for (auto &labelStruct: mLabels) {
1072 double t0 = labelStruct.getT0();
1073 double t1 = labelStruct.getT1();
1074 if (t0 >= t)
1075 t0 += len;
1076
1077 if (t1 >= t)
1078 t1 += len;
1079 labelStruct.selectedRegion.setTimes(t0, t1);
1080 }
1081}

References mLabels.

◆ MakeInterval()

auto LabelTrack::MakeInterval ( size_t  index)

Definition at line 156 of file LabelTrack.cpp.

157{
158 if (index >= mLabels.size())
159 return {};
160 return std::make_shared<Interval>(*this, index);
161}

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 182 of file LabelTrack.cpp.

183{
184 if (!mLabels.empty()) {
185 const auto offset = origin - mLabels[0].selectedRegion.t0();
186 for (auto &labelStruct: mLabels) {
187 labelStruct.selectedRegion.move(offset);
188 }
189 }
190}

References mLabels.

Referenced by ModifiedAnalysisTrack::ModifiedAnalysisTrack().

Here is the caller graph for this function:

◆ New()

LabelTrack * LabelTrack::New ( AudacityProject project)
static

Definition at line 87 of file LabelTrack.cpp.

88{
89 auto &tracks = TrackList::Get( project );
90 auto result = tracks.Add(std::make_shared<LabelTrack>());
91 result->AttachedTrackObjects::BuildAll();
92 return result;
93}
const auto tracks
const auto project
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:314

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 151 of file LabelTrack.cpp.

152{
153 return mLabels.size();
154}

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
SameKindAs(src)
src.NChannels() == 1 || src.NChannels() == NChannels()

Implements Track.

Definition at line 937 of file LabelTrack.cpp.

938{
939 bool bOk = src.TypeSwitch<bool>([&](const LabelTrack &lt) {
940 double shiftAmt = lt.mClipLen > 0.0 ? lt.mClipLen : lt.GetEndTime();
941
942 ShiftLabelsOnInsert(shiftAmt, t);
943 PasteOver(t, src);
944
945 return true;
946 });
947
948 if (!bOk)
949 // THROW_INCONSISTENCY_EXCEPTION; // ?
950 (void)0;// intentionally do nothing
951}
void ShiftLabelsOnInsert(double length, double pt)
Definition: LabelTrack.cpp:241
bool PasteOver(double t, const Track &src)
Definition: LabelTrack.cpp:908
R TypeSwitch(const Functions &...functions)
Definition: Track.h:381

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

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

Implements Track.

Definition at line 142 of file LabelTrack.cpp.

143{
144 auto pNewTrack = std::make_shared<LabelTrack>();
145 pNewTrack->Init(*this);
146 pNewTrack->Paste(0.0, *this);
147 list.Add(pNewTrack);
148 return pNewTrack;
149}

References TrackList::Add().

Here is the call graph for this function:

◆ PasteOver()

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

Definition at line 908 of file LabelTrack.cpp.

909{
910 auto result = src.TypeSwitch<bool>([&](const LabelTrack &sl) {
911 int len = mLabels.size();
912 int pos = 0;
913
914 while (pos < len && mLabels[pos].getT0() < t)
915 pos++;
916
917 for (auto &labelStruct: sl.mLabels) {
918 LabelStruct l {
919 labelStruct.selectedRegion,
920 labelStruct.getT0() + t,
921 labelStruct.getT1() + t,
922 labelStruct.title
923 };
924 mLabels.insert(mLabels.begin() + pos++, l);
925 }
926
927 return true;
928 });
929
930 if (!result)
931 // THROW_INCONSISTENCY_EXCEPTION; // ?
932 (void)0;// intentionally do nothing
933
934 return result;
935}

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 954 of file LabelTrack.cpp.

955{
956 // Sanity-check the arguments
957 if (n < 0 || t1 < t0)
958 return false;
959
960 double tLen = t1 - t0;
961
962 // Insert space for the repetitions
963 ShiftLabelsOnInsert(tLen * n, t1);
964
965 // mLabels may resize as we iterate, so use subscripting
966 for (unsigned int i = 0; i < mLabels.size(); ++i)
967 {
969 mLabels[i].RegionRelation(t0, t1, this);
970 if (relation == LabelStruct::SURROUNDS_LABEL)
971 {
972 // Label is completely inside the selection; duplicate it in each
973 // repeat interval
974 unsigned int pos = i; // running label insertion position in mLabels
975
976 for (int j = 1; j <= n; j++)
977 {
978 const LabelStruct &label = mLabels[i];
979 LabelStruct l {
980 label.selectedRegion,
981 label.getT0() + j * tLen,
982 label.getT1() + j * tLen,
983 label.title
984 };
985
986 // Figure out where to insert
987 while (pos < mLabels.size() &&
988 mLabels[pos].getT0() < l.getT0())
989 pos++;
990 mLabels.insert(mLabels.begin() + pos, l);
991 }
992 }
993 else if (relation == LabelStruct::BEGINS_IN_LABEL)
994 {
995 // Label ends inside the selection; ShiftLabelsOnInsert() hasn't touched
996 // it, and we need to extend it through to the last repeat interval
997 mLabels[i].selectedRegion.moveT1(n * tLen);
998 }
999
1000 // Other cases have already been handled by ShiftLabelsOnInsert()
1001 }
1002
1003 return true;
1004}
TranslatableString label
Definition: TagsEditor.cpp:165

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 269 of file LabelTrack.cpp.

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

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 169 of file LabelTrack.cpp.

170{
171 if( iLabel >= mLabels.size() ) {
172 wxASSERT( false );
173 mLabels.resize( iLabel + 1 );
174 }
175 mLabels[ iLabel ] = newLabel;
176}

References mLabels.

Referenced by DEFINE_ATTACHED_VIRTUAL_OVERRIDE().

Here is the caller graph for this function:

◆ SetSelected()

void LabelTrack::SetSelected ( bool  s)
overridevirtual

Reimplemented from Track.

Definition at line 339 of file LabelTrack.cpp.

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

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 241 of file LabelTrack.cpp.

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

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

Implements Track.

Definition at line 1023 of file LabelTrack.cpp.

1024{
1025 int len = mLabels.size();
1026
1027 // mLabels may resize as we iterate, so use subscripting
1028 for (int i = 0; i < len; ++i) {
1030 mLabels[i].RegionRelation(t0, t1, this);
1031 if (relation == LabelStruct::WITHIN_LABEL)
1032 {
1033 // Split label around the selection
1034 const LabelStruct &label = mLabels[i];
1035 LabelStruct l {
1036 label.selectedRegion,
1037 t1,
1038 label.getT1(),
1039 label.title
1040 };
1041
1042 mLabels[i].selectedRegion.setT1(t0);
1043
1044 // This might not be the right place to insert, but we sort at the end
1045 ++i;
1046 mLabels.insert(mLabels.begin() + i, l);
1047 }
1048 else if (relation == LabelStruct::ENDS_IN_LABEL)
1049 {
1050 // Beginning of label to selection end
1051 mLabels[i].selectedRegion.setT0(t1);
1052 }
1053 else if (relation == LabelStruct::BEGINS_IN_LABEL)
1054 {
1055 // End of label to selection beginning
1056 mLabels[i].selectedRegion.setT1(t0);
1057 }
1058 else if (relation == LabelStruct::SURROUNDS_LABEL)
1059 {
1060 DeleteLabel( i );
1061 len--;
1062 i--;
1063 }
1064 }
1065
1066 SortLabels();
1067}

References LabelStruct::BEGINS_IN_LABEL, DeleteLabel(), LabelStruct::ENDS_IN_LABEL, 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 1127 of file LabelTrack.cpp.

1128{
1129 const auto begin = mLabels.begin();
1130 const auto nn = (int)mLabels.size();
1131 int i = 1;
1132 while (true)
1133 {
1134 // Find the next disorder
1135 while (i < nn && mLabels[i - 1].getT0() <= mLabels[i].getT0())
1136 ++i;
1137 if (i >= nn)
1138 break;
1139
1140 // Where must element i sink to? At most i - 1, maybe less
1141 int j = i - 2;
1142 while( (j >= 0) && (mLabels[j].getT0() > mLabels[i].getT0()) )
1143 --j;
1144 ++j;
1145
1146 // Now fix the disorder
1148 begin + j,
1149 begin + i,
1150 begin + i + 1
1151 );
1152
1153 // Let listeners update their stored indices
1155 this->SharedPointer<LabelTrack>(), mLabels[j].title, i, j });
1156 }
1157}
const char * begin(const char *str) noexcept
Definition: StringUtils.h:101
void rotate(const float *oldPhase, const float *newPhase, std::complex< float > *dst, int32_t n)
Definition: VectorOps.h:140

References details::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.

Reimplemented from Track.

Definition at line 1006 of file LabelTrack.cpp.

1007{
1008 if (newT1 > oldT1) {
1009 // Insert space within the track
1010
1011 if (oldT1 > GetEndTime())
1012 return;
1013
1014 //Clear(oldT1, newT1);
1015 ShiftLabelsOnInsert(newT1 - oldT1, oldT1);
1016 }
1017 else if (newT1 < oldT1) {
1018 // Remove from the track
1019 Clear(newT1, oldT1);
1020 }
1021}
double GetEndTime() const
Get the maximum of End() values of intervals, or 0 when none.
Definition: Channel.cpp:61

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

Here is the call graph for this function:

◆ WarpLabels()

void LabelTrack::WarpLabels ( const TimeWarper warper)

Definition at line 297 of file LabelTrack.cpp.

297 {
298 for (auto &labelStruct: mLabels) {
299 labelStruct.selectedRegion.setTimes(
300 warper.Warp(labelStruct.getT0()),
301 warper.Warp(labelStruct.getT1()));
302 }
303
304 // This should not be needed, assuming the warper is nondecreasing, but
305 // let's not assume too much.
306 SortLabels();
307}
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 814 of file LabelTrack.cpp.

816{
817 int len = mLabels.size();
818
819 xmlFile.StartTag(wxT("labeltrack"));
820 this->Track::WriteCommonXMLAttributes( xmlFile );
821 xmlFile.WriteAttr(wxT("numlabels"), len);
822
823 for (auto &labelStruct: mLabels) {
824 xmlFile.StartTag(wxT("label"));
825 labelStruct.getSelectedRegion()
826 .WriteXMLAttributes(xmlFile, "t", "t1");
827 // PRL: to do: write other selection fields
828 xmlFile.WriteAttr(wxT("title"), labelStruct.title);
829 xmlFile.EndTag(wxT("label"));
830 }
831
832 xmlFile.EndTag(wxT("labeltrack"));
833}
void WriteCommonXMLAttributes(XMLWriter &xmlFile, bool includeNameAndSelected=true) const
Definition: Track.cpp:803
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 221 of file LabelTrack.h.

◆ miLastLabel

int LabelTrack::miLastLabel
private

Definition at line 223 of file LabelTrack.h.

Referenced by FindNextLabel(), and FindPrevLabel().

◆ mLabels

LabelArray LabelTrack::mLabels
private

◆ SubripFiles

const FileNames::FileType LabelTrack::SubripFiles { XO("SubRip text file"), { wxT("srt") }, true }
static

◆ WebVTTFiles

const FileNames::FileType LabelTrack::WebVTTFiles { XO("WebVTT file"), { wxT("vtt") }, true }
static

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