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 ShiftBy (double t0, double delta) override
 Shift all intervals that starts after t0 by delta seconds. 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 ShiftBy (double t0, double delta)=0
 Shift all intervals that starts after t0 by delta seconds. More...
 
virtual void MoveTo (double o)=0
 Change start time to given time point. More...
 
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 95 of file LabelTrack.h.

Member Typedef Documentation

◆ Holder

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

Definition at line 129 of file LabelTrack.h.

Constructor & Destructor Documentation

◆ LabelTrack() [1/2]

LabelTrack::LabelTrack ( )

Definition at line 122 of file LabelTrack.cpp.

124 , mClipLen{ 0.0 }
125 , miLastLabel{ -1 }
126{
127}
double mClipLen
Definition: LabelTrack.h:225
int miLastLabel
Definition: LabelTrack.h:227
Generates overrides of channel-related functions.
Definition: Track.h:450

◆ LabelTrack() [2/2]

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

Definition at line 129 of file LabelTrack.cpp.

130 : UniqueChannelTrack{ orig, std::move(a) }
131 , mClipLen{ 0.0 }
132{
133 for (auto &original: orig.mLabels) {
134 LabelStruct l { original.selectedRegion, original.title };
135 mLabels.push_back(l);
136 }
137}
A LabelStruct holds information for ONE label in a LabelTrack.
Definition: LabelTrack.h:40
SelectedRegion selectedRegion
Definition: LabelTrack.h:80
LabelArray mLabels
Definition: LabelTrack.h:222

References mLabels, and LabelStruct::selectedRegion.

◆ ~LabelTrack()

LabelTrack::~LabelTrack ( )
virtual

Definition at line 192 of file LabelTrack.cpp.

193{
194}

Member Function Documentation

◆ AddLabel()

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

Definition at line 1074 of file LabelTrack.cpp.

1076{
1077 LabelStruct l { selectedRegion, title };
1078
1079 int len = mLabels.size();
1080 int pos = 0;
1081
1082 while (pos < len && mLabels[pos].getT0() < selectedRegion.t0())
1083 pos++;
1084
1085 mLabels.insert(mLabels.begin() + pos, l);
1086
1088 this->SharedPointer<LabelTrack>(), title, -1, pos });
1089
1090 return pos;
1091}
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 FindClippingBase::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 304 of file LabelTrack.cpp.

305{
306//t is the time stamp we'll be changing
307//b and e are the selection start and end
308
309 if (t < b){
310 return t;
311 }else if (t > e){
312 double shift = (e-b)*change - (e-b);
313 return t + shift;
314 }else{
315 double shift = (t-b)*change - (t-b);
316 return t + shift;
317 }
318}

Referenced by ScaleLabels().

Here is the caller graph for this function:

◆ ChangeLabelsOnReverse()

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

Definition at line 280 of file LabelTrack.cpp.

281{
282 for (auto &labelStruct: mLabels) {
283 if (labelStruct.RegionRelation(b, e, this) ==
285 {
286 double aux = b + (e - labelStruct.getT1());
287 labelStruct.selectedRegion.setTimes(
288 aux,
289 e - (labelStruct.getT0() - b));
290 }
291 }
292 SortLabels();
293}
@ SURROUNDS_LABEL
Definition: LabelTrack.h:66
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 151 of file LabelTrack.cpp.

152{
153 return typeInfo();
154}
static const Track::TypeInfo & typeInfo()
Definition: LabelTrack.cpp:139

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

219{
220 // May DELETE labels, so use subscripts to iterate
221 for (size_t i = 0; i < mLabels.size(); ++i) {
222 auto &labelStruct = mLabels[i];
224 labelStruct.RegionRelation(b, e, this);
225 if (relation == LabelStruct::BEFORE_LABEL)
226 labelStruct.selectedRegion.move(- (e-b));
227 else if (relation == LabelStruct::SURROUNDS_LABEL) {
228 DeleteLabel( i );
229 --i;
230 }
231 else if (relation == LabelStruct::ENDS_IN_LABEL)
232 labelStruct.selectedRegion.setTimes(
233 b,
234 labelStruct.getT1() - (e - b));
235 else if (relation == LabelStruct::BEGINS_IN_LABEL)
236 labelStruct.selectedRegion.setT1(b);
237 else if (relation == LabelStruct::WITHIN_LABEL)
238 labelStruct.selectedRegion.moveT1( - (e-b));
239 }
240}
TimeRelations
Relationships between selection region and labels.
Definition: LabelTrack.h:63
@ BEGINS_IN_LABEL
Definition: LabelTrack.h:68
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 374 of file LabelTrack.cpp.

375{
376 auto result = std::make_shared<LabelTrack>(*this, ProtectedCreationArg{});
377 result->Init(*this);
378 return result;
379}

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

838{
839 auto tmp = std::make_shared<LabelTrack>();
840 tmp->Init(*this);
841 const auto lt = static_cast<LabelTrack*>(tmp.get());
842
843 for (auto &labelStruct: mLabels) {
845 labelStruct.RegionRelation(t0, t1, this);
846 if (relation == LabelStruct::SURROUNDS_LABEL) {
847 LabelStruct l {
848 labelStruct.selectedRegion,
849 labelStruct.getT0() - t0,
850 labelStruct.getT1() - t0,
851 labelStruct.title
852 };
853 lt->mLabels.push_back(l);
854 }
855 else if (relation == LabelStruct::WITHIN_LABEL) {
856 LabelStruct l {
857 labelStruct.selectedRegion,
858 0,
859 t1-t0,
860 labelStruct.title
861 };
862 lt->mLabels.push_back(l);
863 }
864 else if (relation == LabelStruct::BEGINS_IN_LABEL) {
865 LabelStruct l {
866 labelStruct.selectedRegion,
867 0,
868 labelStruct.getT1() - t0,
869 labelStruct.title
870 };
871 lt->mLabels.push_back(l);
872 }
873 else if (relation == LabelStruct::ENDS_IN_LABEL) {
874 LabelStruct l {
875 labelStruct.selectedRegion,
876 labelStruct.getT0() - t0,
877 t1 - t0,
878 labelStruct.title
879 };
880 lt->mLabels.push_back(l);
881 }
882 }
883 lt->mClipLen = (t1 - t0);
884
885 return tmp;
886}
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:98

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 RepeatBase::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 117 of file LabelTrack.cpp.

118{
119 return Create(trackList, trackList.MakeUniqueTrackName(GetDefaultName()));
120}
static LabelTrack * Create(TrackList &trackList, const wxString &name)
Create a new LabelTrack with specified name and append it to the trackList.
Definition: LabelTrack.cpp:109
static wxString GetDefaultName()
Definition: LabelTrack.cpp:96
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 109 of file LabelTrack.cpp.

110{
111 auto track = std::make_shared<LabelTrack>();
112 track->SetName(name);
113 trackList.Add(track);
114 return track.get();
115}
wxString name
Definition: TagsEditor.cpp:166
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 816 of file LabelTrack.cpp.

817{
818 auto tmp = Copy(t0, t1);
819 Clear(t0, t1);
820 return tmp;
821}
Track::Holder Copy(double t0, double t1, bool forClipboard=true) const override
Create new tracks and don't modify this track.
Definition: LabelTrack.cpp:837
void Clear(double t0, double t1) override
Definition: LabelTrack.cpp:218

References Clear(), and Copy().

Here is the call graph for this function:

◆ DeleteLabel()

void LabelTrack::DeleteLabel ( int  index)

Definition at line 1093 of file LabelTrack.cpp.

1094{
1095 wxASSERT((index < (int)mLabels.size()));
1096 auto iter = mLabels.begin() + index;
1097 const auto title = iter->title;
1098 mLabels.erase(iter);
1099
1101 this->SharedPointer<LabelTrack>(), title, index, -1 });
1102}

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

179{
180 return MakeInterval(iInterval);
181}
std::shared_ptr< Interval > MakeInterval(size_t index)
Definition: LabelTrack.cpp:170

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

673{
675 f.AddLine(wxT("WEBVTT"));
676 f.AddLine(wxT(""));
677 }
678
679 // PRL: to do: export other selection fields
680 int index = 0;
681 for (auto &labelStruct: mLabels)
682 labelStruct.Export(f, format, index++);
683}
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 1159 of file LabelTrack.cpp.

1160{
1161 int i = -1;
1162
1163 if (!mLabels.empty()) {
1164 int len = (int) mLabels.size();
1165 if (miLastLabel >= 0 && miLastLabel + 1 < len
1166 && currentRegion.t0() == mLabels[miLastLabel].getT0()
1167 && currentRegion.t0() == mLabels[miLastLabel + 1].getT0() ) {
1168 i = miLastLabel + 1;
1169 }
1170 else {
1171 i = 0;
1172 if (currentRegion.t0() < mLabels[len - 1].getT0()) {
1173 while (i < len &&
1174 mLabels[i].getT0() <= currentRegion.t0()) {
1175 i++;
1176 }
1177 }
1178 }
1179 }
1180
1181 miLastLabel = i;
1182 return i;
1183}

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

1186{
1187 int i = -1;
1188
1189 if (!mLabels.empty()) {
1190 int len = (int) mLabels.size();
1191 if (miLastLabel > 0 && miLastLabel < len
1192 && currentRegion.t0() == mLabels[miLastLabel].getT0()
1193 && currentRegion.t0() == mLabels[miLastLabel - 1].getT0() ) {
1194 i = miLastLabel - 1;
1195 }
1196 else {
1197 i = len - 1;
1198 if (currentRegion.t0() > mLabels[0].getT0()) {
1199 while (i >=0 &&
1200 mLabels[i].getT0() >= currentRegion.t0()) {
1201 i--;
1202 }
1203 }
1204 }
1205 }
1206
1207 miLastLabel = i;
1208 return i;
1209}

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

686{
688 if (fileName.Right(4).CmpNoCase(wxT(".srt")) == 0) {
690 } else if (fileName.Right(4).CmpNoCase(wxT(".vtt")) == 0) {
692 }
693 return format;
694}
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 96 of file LabelTrack.cpp.

97{
98 return _("Labels");
99}
#define _(s)
Definition: Internat.h:73

References _.

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

Here is the caller graph for this function:

◆ GetLabel()

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

Definition at line 1069 of file LabelTrack.cpp.

1070{
1071 return &mLabels[index];
1072}

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

160{ 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 1064 of file LabelTrack.cpp.

1065{
1066 return mLabels.size();
1067}

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

1141{
1142 bool firstLabel = true;
1143 wxString retVal;
1144
1145 for (auto &labelStruct: mLabels) {
1146 if (labelStruct.getT0() >= t0 &&
1147 labelStruct.getT1() <= t1)
1148 {
1149 if (!firstLabel)
1150 retVal += '\t';
1151 firstLabel = false;
1152 retVal += labelStruct.title;
1153 }
1154 }
1155
1156 return retVal;
1157}

References mLabels.

◆ GetTypeInfo()

auto LabelTrack::GetTypeInfo ( ) const
overridevirtual

Implements Track.

Definition at line 146 of file LabelTrack.cpp.

147{
148 return typeInfo();
149}

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

788{
789 if (tag == "label")
790 return this;
791 else
792 return NULL;
793}

◆ HandleXMLTag()

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

Implements XMLTagHandler.

Definition at line 726 of file LabelTrack.cpp.

727{
728 if (tag == "label") {
729
730 SelectedRegion selectedRegion;
731 wxString title;
732
733 // loop through attrs, which is a null-terminated list of
734 // attribute-value pairs
735 for (auto pair : attrs)
736 {
737 auto attr = pair.first;
738 auto value = pair.second;
739
740 if (selectedRegion.HandleXMLAttribute(attr, value, "t", "t1"))
741 ;
742 // Bug 1905 no longer applies, as valueView has no limits anyway
743 else if (attr == "title")
744 title = value.ToWString();
745
746 } // while
747
748 // Handle files created by Audacity 1.1. Labels in Audacity 1.1
749 // did not have separate start- and end-times.
750 // PRL: this superfluous now, given class SelectedRegion's internal
751 // consistency guarantees
752 //if (selectedRegion.t1() < 0)
753 // selectedRegion.collapseToT0();
754
755 LabelStruct l { selectedRegion, title };
756 mLabels.push_back(l);
757
758 return true;
759 }
760 else if (tag == "labeltrack") {
761 long nValue = -1;
762 for (auto pair : attrs)
763 {
764 auto attr = pair.first;
765 auto value = pair.second;
766
767 if (this->Track::HandleCommonXMLAttribute(attr, value))
768 ;
769 else if (attr == "numlabels" && value.TryGet(nValue))
770 {
771 if (nValue < 0)
772 {
773 wxLogWarning(wxT("Project shows negative number of labels: %d"), nValue);
774 return false;
775 }
776 mLabels.clear();
777 mLabels.reserve(nValue);
778 }
779 }
780
781 return true;
782 }
783
784 return false;
785}
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 697 of file LabelTrack.cpp.

698{
700 BasicUI::ShowMessageBox( XO("Importing WebVTT files is not currently supported.") );
701 return;
702 }
703
704 int lines = in.GetLineCount();
705
706 mLabels.clear();
707 mLabels.reserve(lines);
708
709 //Currently, we expect a tag file to have two values and a label
710 //on each line. If the second token is not a number, we treat
711 //it as a single-value label.
712 bool error = false;
713 for (int index = 0; index < lines;) {
714 try {
715 // Let LabelStruct::Import advance index
716 LabelStruct l { LabelStruct::Import(in, index, format) };
717 mLabels.push_back(l);
718 }
719 catch(const LabelStruct::BadFormatException&) { error = true; }
720 }
721 if (error)
722 BasicUI::ShowMessageBox( XO("One or more saved labels could not be read.") );
723 SortLabels();
724}
XO("Cut/Copy/Paste")
static LabelStruct Import(wxTextFile &file, int &index, LabelFormat format)
Definition: LabelTrack.cpp:420
MessageBoxResult ShowMessageBox(const TranslatableString &message, MessageBoxOptions options={})
Show a modal message box with either Ok or Yes and No, and optionally Cancel.
Definition: BasicUI.h:287

References anonymous_namespace{ExportPCM.cpp}::format, LabelStruct::Import(), mLabels, BasicUI::ShowMessageBox(), 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 1050 of file LabelTrack.cpp.

1051{
1052 for (auto &labelStruct: mLabels) {
1053 double t0 = labelStruct.getT0();
1054 double t1 = labelStruct.getT1();
1055 if (t0 >= t)
1056 t0 += len;
1057
1058 if (t1 >= t)
1059 t1 += len;
1060 labelStruct.selectedRegion.setTimes(t0, t1);
1061 }
1062}

References mLabels.

◆ MakeInterval()

auto LabelTrack::MakeInterval ( size_t  index)

Definition at line 170 of file LabelTrack.cpp.

171{
172 if (index >= mLabels.size())
173 return {};
174 return std::make_shared<Interval>(*this, index);
175}

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

198{
199 if (!mLabels.empty()) {
200 const auto offset = origin - mLabels[0].selectedRegion.t0();
201 for (auto &labelStruct: mLabels) {
202 labelStruct.selectedRegion.move(offset);
203 }
204 }
205}

References mLabels.

Referenced by ModifiedAnalysisTrack::ModifiedAnalysisTrack().

Here is the caller graph for this function:

◆ New()

LabelTrack * LabelTrack::New ( AudacityProject project)
static

Definition at line 101 of file LabelTrack.cpp.

102{
103 auto &tracks = TrackList::Get( project );
104 auto result = tracks.Add(std::make_shared<LabelTrack>());
105 result->AttachedTrackObjects::BuildAll();
106 return result;
107}
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 165 of file LabelTrack.cpp.

166{
167 return mLabels.size();
168}

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

919{
920 bool bOk = src.TypeSwitch<bool>([&](const LabelTrack &lt) {
921 double shiftAmt = lt.mClipLen > 0.0 ? lt.mClipLen : lt.GetEndTime();
922
923 ShiftLabelsOnInsert(shiftAmt, t);
924 PasteOver(t, src);
925
926 return true;
927 });
928
929 if (!bOk)
930 // THROW_INCONSISTENCY_EXCEPTION; // ?
931 (void)0;// intentionally do nothing
932}
void ShiftLabelsOnInsert(double length, double pt)
Definition: LabelTrack.cpp:267
bool PasteOver(double t, const Track &src)
Definition: LabelTrack.cpp:889
R TypeSwitch(const Functions &...functions)
Definition: Track.h:381

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

Referenced by RepeatBase::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 156 of file LabelTrack.cpp.

157{
158 auto pNewTrack = std::make_shared<LabelTrack>();
159 pNewTrack->Init(*this);
160 pNewTrack->Paste(0.0, *this);
161 list.Add(pNewTrack);
162 return pNewTrack;
163}

References TrackList::Add().

Here is the call graph for this function:

◆ PasteOver()

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

Definition at line 889 of file LabelTrack.cpp.

890{
891 auto result = src.TypeSwitch<bool>([&](const LabelTrack &sl) {
892 int len = mLabels.size();
893 int pos = 0;
894
895 while (pos < len && mLabels[pos].getT0() < t)
896 pos++;
897
898 for (auto &labelStruct: sl.mLabels) {
899 LabelStruct l {
900 labelStruct.selectedRegion,
901 labelStruct.getT0() + t,
902 labelStruct.getT1() + t,
903 labelStruct.title
904 };
905 mLabels.insert(mLabels.begin() + pos++, l);
906 }
907
908 return true;
909 });
910
911 if (!result)
912 // THROW_INCONSISTENCY_EXCEPTION; // ?
913 (void)0;// intentionally do nothing
914
915 return result;
916}

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

936{
937 // Sanity-check the arguments
938 if (n < 0 || t1 < t0)
939 return false;
940
941 double tLen = t1 - t0;
942
943 // Insert space for the repetitions
944 ShiftLabelsOnInsert(tLen * n, t1);
945
946 // mLabels may resize as we iterate, so use subscripting
947 for (unsigned int i = 0; i < mLabels.size(); ++i)
948 {
950 mLabels[i].RegionRelation(t0, t1, this);
951 if (relation == LabelStruct::SURROUNDS_LABEL)
952 {
953 // Label is completely inside the selection; duplicate it in each
954 // repeat interval
955 unsigned int pos = i; // running label insertion position in mLabels
956
957 for (int j = 1; j <= n; j++)
958 {
959 const LabelStruct &label = mLabels[i];
960 LabelStruct l {
961 label.selectedRegion,
962 label.getT0() + j * tLen,
963 label.getT1() + j * tLen,
964 label.title
965 };
966
967 // Figure out where to insert
968 while (pos < mLabels.size() &&
969 mLabels[pos].getT0() < l.getT0())
970 pos++;
971 mLabels.insert(mLabels.begin() + pos, l);
972 }
973 }
974 else if (relation == LabelStruct::BEGINS_IN_LABEL)
975 {
976 // Label ends inside the selection; ShiftLabelsOnInsert() hasn't touched
977 // it, and we need to extend it through to the last repeat interval
978 mLabels[i].selectedRegion.moveT1(n * tLen);
979 }
980
981 // Other cases have already been handled by ShiftLabelsOnInsert()
982 }
983
984 return true;
985}
TranslatableString label
Definition: TagsEditor.cpp:165

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

Referenced by RepeatBase::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 295 of file LabelTrack.cpp.

296{
297 for (auto &labelStruct: mLabels) {
298 labelStruct.selectedRegion.setTimes(
299 AdjustTimeStampOnScale(labelStruct.getT0(), b, e, change),
300 AdjustTimeStampOnScale(labelStruct.getT1(), b, e, change));
301 }
302}
double AdjustTimeStampOnScale(double t, double b, double e, double change)
Definition: LabelTrack.cpp:304

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

184{
185 if( iLabel >= mLabels.size() ) {
186 wxASSERT( false );
187 mLabels.resize( iLabel + 1 );
188 }
189 mLabels[ iLabel ] = newLabel;
190}

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

366{
367 bool selected = GetSelected();
369 if ( selected != GetSelected() )
371 this->SharedPointer<LabelTrack>(), {}, -1, -1 });
372}
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:

◆ ShiftBy()

void LabelTrack::ShiftBy ( double  t0,
double  delta 
)
overridevirtual

Shift all intervals that starts after t0 by delta seconds.

Implements ChannelGroup.

Definition at line 207 of file LabelTrack.cpp.

208{
209 if (mLabels.empty())
210 return;
211 for (auto &labelStruct: mLabels)
212 {
213 if(labelStruct.selectedRegion.t0() >= t0)
214 labelStruct.selectedRegion.move(delta);
215 }
216}

References mLabels.

◆ ShiftLabelsOnInsert()

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

Definition at line 267 of file LabelTrack.cpp.

268{
269 for (auto &labelStruct: mLabels) {
271 labelStruct.RegionRelation(pt, pt, this);
272
273 if (relation == LabelStruct::BEFORE_LABEL)
274 labelStruct.selectedRegion.move(length);
275 else if (relation == LabelStruct::WITHIN_LABEL)
276 labelStruct.selectedRegion.moveT1(length);
277 }
278}

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

1005{
1006 int len = mLabels.size();
1007
1008 // mLabels may resize as we iterate, so use subscripting
1009 for (int i = 0; i < len; ++i) {
1011 mLabels[i].RegionRelation(t0, t1, this);
1012 if (relation == LabelStruct::WITHIN_LABEL)
1013 {
1014 // Split label around the selection
1015 const LabelStruct &label = mLabels[i];
1016 LabelStruct l {
1017 label.selectedRegion,
1018 t1,
1019 label.getT1(),
1020 label.title
1021 };
1022
1023 mLabels[i].selectedRegion.setT1(t0);
1024
1025 // This might not be the right place to insert, but we sort at the end
1026 ++i;
1027 mLabels.insert(mLabels.begin() + i, l);
1028 }
1029 else if (relation == LabelStruct::ENDS_IN_LABEL)
1030 {
1031 // Beginning of label to selection end
1032 mLabels[i].selectedRegion.setT0(t1);
1033 }
1034 else if (relation == LabelStruct::BEGINS_IN_LABEL)
1035 {
1036 // End of label to selection beginning
1037 mLabels[i].selectedRegion.setT1(t0);
1038 }
1039 else if (relation == LabelStruct::SURROUNDS_LABEL)
1040 {
1041 DeleteLabel( i );
1042 len--;
1043 i--;
1044 }
1045 }
1046
1047 SortLabels();
1048}

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

1109{
1110 const auto begin = mLabels.begin();
1111 const auto nn = (int)mLabels.size();
1112 int i = 1;
1113 while (true)
1114 {
1115 // Find the next disorder
1116 while (i < nn && mLabels[i - 1].getT0() <= mLabels[i].getT0())
1117 ++i;
1118 if (i >= nn)
1119 break;
1120
1121 // Where must element i sink to? At most i - 1, maybe less
1122 int j = i - 2;
1123 while( (j >= 0) && (mLabels[j].getT0() > mLabels[i].getT0()) )
1124 --j;
1125 ++j;
1126
1127 // Now fix the disorder
1129 begin + j,
1130 begin + i,
1131 begin + i + 1
1132 );
1133
1134 // Let listeners update their stored indices
1136 this->SharedPointer<LabelTrack>(), mLabels[j].title, i, j });
1137 }
1138}
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 987 of file LabelTrack.cpp.

988{
989 if (newT1 > oldT1) {
990 // Insert space within the track
991
992 if (oldT1 > GetEndTime())
993 return;
994
995 //Clear(oldT1, newT1);
996 ShiftLabelsOnInsert(newT1 - oldT1, oldT1);
997 }
998 else if (newT1 < oldT1) {
999 // Remove from the track
1000 Clear(newT1, oldT1);
1001 }
1002}
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 323 of file LabelTrack.cpp.

323 {
324 for (auto &labelStruct: mLabels) {
325 labelStruct.selectedRegion.setTimes(
326 warper.Warp(labelStruct.getT0()),
327 warper.Warp(labelStruct.getT1()));
328 }
329
330 // This should not be needed, assuming the warper is nondecreasing, but
331 // let's not assume too much.
332 SortLabels();
333}
virtual double Warp(double originalTime) const =0

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

Referenced by ChangeSpeedBase::ProcessLabelTrack(), and SBSMSBase::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 795 of file LabelTrack.cpp.

797{
798 int len = mLabels.size();
799
800 xmlFile.StartTag(wxT("labeltrack"));
801 this->Track::WriteCommonXMLAttributes( xmlFile );
802 xmlFile.WriteAttr(wxT("numlabels"), len);
803
804 for (auto &labelStruct: mLabels) {
805 xmlFile.StartTag(wxT("label"));
806 labelStruct.getSelectedRegion()
807 .WriteXMLAttributes(xmlFile, "t", "t1");
808 // PRL: to do: write other selection fields
809 xmlFile.WriteAttr(wxT("title"), labelStruct.title);
810 xmlFile.EndTag(wxT("label"));
811 }
812
813 xmlFile.EndTag(wxT("labeltrack"));
814}
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 225 of file LabelTrack.h.

◆ miLastLabel

int LabelTrack::miLastLabel
private

Definition at line 227 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: