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

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

#include <LabelTrack.h>

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

Classes

struct  Interval
 

Public Types

using Holder = std::shared_ptr< LabelTrack >
 
- Public Types inherited from Track
using AttachedObjects = ::AttachedTrackObjects
 Alias for my base type. More...
 
using Holder = std::shared_ptr< Track >
 
- Public Types inherited from ClientData::Site< Host, ClientData, ObjectCopyingPolicy, Pointer, ObjectLockingPolicy, RegistryLockingPolicy >
using DataType = ClientData
 
using DataPointer = Pointer< ClientData >
 
using DataFactory = std::function< DataPointer(Host &) >
 Type of function from which RegisteredFactory is constructed; it builds attachments. More...
 
- Public Types inherited from ChannelGroup
enum class  LinkType : int { None = 0 , Group = 2 , Aligned }
 For two tracks describes the type of the linkage. More...
 
using Attachments = ClientData::Site< ChannelGroupData, ClientData::Cloneable<>, ClientData::DeepCopying >
 
using Interval = WideChannelGroupInterval
 
- Public Types inherited from Channel
using Interval = ChannelInterval
 
- Public Types inherited from Observer::Publisher< struct LabelTrackEvent >
using message_type = struct LabelTrackEvent
 
using CallbackReturn = std::conditional_t< true, void, bool >
 
using Callback = std::function< CallbackReturn(const struct LabelTrackEvent &) >
 Type of functions that can be connected to the Publisher. More...
 

Public Member Functions

 LabelTrack ()
 
 LabelTrack (const LabelTrack &orig, ProtectedCreationArg &&)
 
virtual ~LabelTrack ()
 
void SetLabel (size_t iLabel, const LabelStruct &newLabel)
 
void MoveTo (double dOffset) override
 Change start time to given time point. More...
 
void SetSelected (bool s) override
 
bool HandleXMLTag (const std::string_view &tag, const AttributesList &attrs) override
 
XMLTagHandlerHandleXMLChild (const std::string_view &tag) override
 
void WriteXML (XMLWriter &xmlFile) const override
 
TrackListHolder Cut (double t0, double t1) override
 Create tracks and modify this track. More...
 
TrackListHolder Copy (double t0, double t1, bool forClipboard=true) const override
 Create new tracks and don't modify this track. More...
 
void Clear (double t0, double t1) override
 
void Paste (double t, const Track &src) override
 Weak precondition allows overrides to replicate one channel into many. More...
 
bool Repeat (double t0, double t1, int n)
 
void SyncLockAdjust (double oldT1, double newT1) override
 
void Silence (double t0, double t1, ProgressReporter reportProgress={}) override
 
void InsertSilence (double t, double len) override
 
void Import (wxTextFile &f)
 Import labels, handling files with or without end-times. More...
 
void Export (wxTextFile &f) const
 Export labels including label start and end-times. More...
 
int GetNumLabels () const
 
const LabelStructGetLabel (int index) const
 
const LabelArrayGetLabels () const
 
void OnLabelAdded (const wxString &title, int pos)
 
int AddLabel (const SelectedRegion &region, const wxString &title)
 
void DeleteLabel (int index)
 
bool PasteOver (double t, const Track &src)
 
void ShiftLabelsOnInsert (double length, double pt)
 
void ChangeLabelsOnReverse (double b, double e)
 
void ScaleLabels (double b, double e, double change)
 
double AdjustTimeStampOnScale (double t, double b, double e, double change)
 
void WarpLabels (const TimeWarper &warper)
 
wxString GetTextOfLabels (double t0, double t1) const
 
int FindNextLabel (const SelectedRegion &currentSelection)
 
int FindPrevLabel (const SelectedRegion &currentSelection)
 
const TypeInfoGetTypeInfo () const override
 
Track::Holder PasteInto (AudacityProject &project, TrackList &list) const override
 
std::shared_ptr< IntervalMakeInterval (size_t index)
 
void SortLabels ()
 
size_t NIntervals () const override
 Report the number of intervals. More...
 
- Public Member Functions inherited from UniqueChannelTrack< Base >
size_t NChannels () const override
 Report the number of channels. More...
 
std::shared_ptr< ChannelDoGetChannel (size_t iChannel) override
 Retrieve a channel. More...
 
- Public Member Functions inherited from Track
TrackId GetId () const
 
template<typename Subclass = Track>
std::shared_ptr< Subclass > SharedPointer ()
 
template<typename Subclass = const Track>
auto SharedPointer () const -> std::enable_if_t< std::is_const_v< Subclass >, std::shared_ptr< Subclass > >
 
std::shared_ptr< TrackSubstitutePendingChangedTrack ()
 
std::shared_ptr< const TrackSubstitutePendingChangedTrack () const
 
std::shared_ptr< const TrackSubstituteOriginalTrack () const
 
virtual const TypeInfoGetTypeInfo () const =0
 
virtual const TypeNamesGetTypeNames () const
 
virtual bool SupportsBasicEditing () const
 Whether this track type implements cut-copy-paste; by default, true. More...
 
virtual Holder PasteInto (AudacityProject &project, TrackList &list) const =0
 
virtual bool LinkConsistencyFix (bool doFix=true)
 Check consistency of channel groups, and maybe fix it. More...
 
bool LinkConsistencyCheck ()
 Do the non-mutating part of consistency fix only and return status. More...
 
bool HasOwner () const
 
std::shared_ptr< TrackListGetOwner () const
 
TrackListGetHolder () const
 
LinkType GetLinkType () const noexcept
 
ChannelGroupDataGetGroupData ()
 
const ChannelGroupDataGetGroupData () const
 May make group data on demand, but consider that logically const. More...
 
 Track ()
 
 Track (const Track &orig, ProtectedCreationArg &&)
 
Trackoperator= (const Track &orig)=delete
 
virtual ~Track ()
 
void Init (const Track &orig)
 
virtual TrackListHolder Duplicate () const
 public nonvirtual duplication function that invokes Clone() More...
 
const wxString & GetName () const
 Name is always the same for all channels of a group. More...
 
void SetName (const wxString &n)
 
bool GetSelected () const
 Selectedness is always the same for all channels of a group. More...
 
virtual void SetSelected (bool s)
 
void OnProjectTempoChange (double newTempo)
 method to set project tempo on track More...
 
virtual TrackListHolder Cut (double t0, double t1)=0
 Create tracks and modify this track. More...
 
virtual TrackListHolder Copy (double t0, double t1, bool forClipboard=true) const =0
 Create new tracks and don't modify this track. More...
 
virtual void Clear (double t0, double t1)=0
 
virtual void Paste (double t, const Track &src)=0
 Weak precondition allows overrides to replicate one channel into many. More...
 
void Paste (double t, const TrackList &src)
 
virtual void SyncLockAdjust (double oldT1, double newT1)
 
virtual void Silence (double t0, double t1, ProgressReporter reportProgress={})=0
 
virtual void InsertSilence (double t, double len)=0
 
bool SameKindAs (const Track &track) const
 
template<typename R = void, typename ... Functions>
TypeSwitch (const Functions &...functions)
 
template<typename R = void, typename ... Functions>
TypeSwitch (const Functions &...functions) const
 
virtual void WriteXML (XMLWriter &xmlFile) const =0
 
virtual std::optional< TranslatableStringGetErrorOpening () const
 
void Notify (bool allChannels, int code=-1)
 
bool Any () const
 
bool IsSelected () const
 
bool IsLeader () const override
 
bool IsSelectedLeader () const
 
void AdjustPositions ()
 
void WriteCommonXMLAttributes (XMLWriter &xmlFile, bool includeNameAndSelected=true) const
 
bool HandleCommonXMLAttribute (const std::string_view &attr, const XMLAttributeValueView &valueView)
 
const std::optional< double > & GetProjectTempo () const
 
- Public Member Functions inherited from XMLTagHandler
 XMLTagHandler ()
 
virtual ~XMLTagHandler ()
 
virtual bool HandleXMLTag (const std::string_view &tag, const AttributesList &attrs)=0
 
virtual void HandleXMLEndTag (const std::string_view &WXUNUSED(tag))
 
virtual void HandleXMLContent (const std::string_view &WXUNUSED(content))
 
virtual XMLTagHandlerHandleXMLChild (const std::string_view &tag)=0
 
void ReadXMLEndTag (const char *tag)
 
void ReadXMLContent (const char *s, int len)
 
XMLTagHandlerReadXMLChild (const char *tag)
 
- Public Member Functions inherited from ClientData::Site< Host, ClientData, ObjectCopyingPolicy, Pointer, ObjectLockingPolicy, RegistryLockingPolicy >
 ~Site ()
 
 Site ()
 
 Site (const Site &other)
 
Siteoperator= (const Site &other)
 
 Site (Site &&other)
 
Siteoperator= (Site &&other)
 
size_t size () const
 How many attachment pointers are in the Site. More...
 
template<typename Subclass = ClientData>
Subclass & Get (const RegisteredFactory &key)
 Get reference to an attachment, creating on demand if not present, down-cast it to Subclass. More...
 
template<typename Subclass = const ClientData>
auto Get (const RegisteredFactory &key) const -> std::enable_if_t< std::is_const< Subclass >::value, Subclass & >
 Get reference to an attachment, creating on demand if not present, down-cast it to Subclass. More...
 
template<typename Subclass = ClientData>
Subclass * Find (const RegisteredFactory &key)
 Get a (bare) pointer to an attachment, or null, down-cast it to Subclass *; will not create on demand. More...
 
template<typename Subclass = const ClientData>
auto Find (const RegisteredFactory &key) const -> std::enable_if_t< std::is_const< Subclass >::value, Subclass * >
 Get a (bare) pointer to an attachment, or null, down-cast it to Subclass *; will not create on demand. More...
 
template<typename ReplacementPointer >
void Assign (const RegisteredFactory &key, ReplacementPointer &&replacement)
 Reassign Site's pointer to ClientData. More...
 
- Public Member Functions inherited from ChannelGroup
virtual ~ChannelGroup ()
 
double GetStartTime () const
 Get the minimum of Start() values of intervals, or 0 when none. More...
 
double GetEndTime () const
 Get the maximum of End() values of intervals, or 0 when none. More...
 
void ShiftBy (double t)
 Change start time by given duration. More...
 
virtual void MoveTo (double o)=0
 Change start time to given time point. More...
 
virtual bool IsLeader () const =0
 
ChannelGroupDataGetGroupData ()
 Make attachment site on demand as needed. More...
 
const ChannelGroupDataGetGroupData () const
 
ChannelGroupDataFindGroupData ()
 Do not make attachment site on demand if absent. More...
 
const ChannelGroupDataFindGroupData () const
 Do not make attachment site on demand if absent. More...
 
void Init (const ChannelGroup &other)
 Copy, including cloning of attached objects. More...
 
void DestroyGroupData ()
 Leave all attachments null. More...
 
std::unique_ptr< ChannelGroupDataDetachGroupData ()
 Move attachments out. More...
 
void AssignGroupData (std::unique_ptr< ChannelGroupData > pGroupData)
 Replace any previous attachments. More...
 
template<typename ChannelType = Channel>
std::shared_ptr< ChannelType > GetChannel (size_t iChannel)
 Retrieve a channel, cast to the given type. More...
 
template<typename ChannelType = const Channel>
auto GetChannel (size_t iChannel) const -> std::enable_if_t< std::is_const_v< ChannelType >, std::shared_ptr< ChannelType > >
 
template<typename ChannelType = Channel>
IteratorRange< ChannelIterator< ChannelType > > Channels ()
 Get range of channels with mutative access. More...
 
template<typename ChannelType = const Channel>
auto Channels () const -> std::enable_if_t< std::is_const_v< ChannelType >, IteratorRange< ChannelIterator< ChannelType > > >
 Get range of channels with read-only access. More...
 
template<typename IntervalType = Interval>
std::shared_ptr< IntervalType > GetInterval (size_t iInterval)
 Retrieve an interval, cast to the given type. More...
 
template<typename IntervalType = const Interval>
auto GetInterval (size_t iInterval) const -> std::enable_if_t< std::is_const_v< IntervalType >, std::shared_ptr< IntervalType > >
 
template<typename IntervalType = Interval>
IteratorRange< IntervalIterator< IntervalType > > Intervals ()
 Get range of intervals with mutative access. More...
 
template<typename IntervalType = const Interval>
auto Intervals () const -> std::enable_if_t< std::is_const_v< IntervalType >, IteratorRange< IntervalIterator< IntervalType > > >
 Get range of intervals with read-only access. More...
 
- Public Member Functions inherited from Channel
virtual ~Channel ()
 
ChannelGroupGetChannelGroup ()
 Channel object's lifetime is assumed to be nested in its Track's. More...
 
const ChannelGroupGetChannelGroup () const
 Channel object's lifetime is assumed to be nested in its Track's. More...
 
size_t GetChannelIndex () const
 
size_t ReallyGetChannelIndex () const
 
size_t NIntervals () const
 Report the number of intervals. More...
 
template<typename IntervalType = Interval>
std::shared_ptr< IntervalType > GetInterval (size_t iInterval)
 Retrieve an interval, cast to the given type. More...
 
template<typename IntervalType = const Interval>
auto GetInterval (size_t iInterval) const -> std::enable_if_t< std::is_const_v< IntervalType >, std::shared_ptr< IntervalType > >
 
template<typename IntervalType = Interval>
IteratorRange< IntervalIterator< IntervalType > > Intervals ()
 Get range of intervals with mutative access. More...
 
template<typename IntervalType = const Interval>
auto Intervals () const -> std::enable_if_t< std::is_const_v< IntervalType >, IteratorRange< IntervalIterator< IntervalType > > >
 Get range of intervals with read-only access. More...
 
- Public Member Functions inherited from Observer::Publisher< struct LabelTrackEvent >
 Publisher (ExceptionPolicy *pPolicy=nullptr, Alloc a={})
 Constructor supporting type-erased custom allocation/deletion. More...
 
 Publisher (Publisher &&)=default
 
Publisheroperator= (Publisher &&)=default
 
Subscription Subscribe (Callback callback)
 Connect a callback to the Publisher; later-connected are called earlier. More...
 
Subscription Subscribe (Object &obj, Return(Object::*callback)(Args...))
 Overload of Subscribe takes an object and pointer-to-member-function. More...
 

Static Public Member Functions

static wxString GetDefaultName ()
 
static LabelTrackNew (AudacityProject &project)
 
static LabelTrackCreate (TrackList &trackList, const wxString &name)
 Create a new LabelTrack with specified name and append it to the trackList. More...
 
static LabelTrackCreate (TrackList &trackList)
 Create a new LabelTrack with unique default name and append it to the trackList. More...
 
static const TypeInfoClassTypeInfo ()
 
- Static Public Member Functions inherited from Track
template<typename Subclass = Track>
static std::shared_ptr< Subclass > SharedPointer (Track *pTrack)
 
template<typename Subclass = const Track>
static std::shared_ptr< Subclass > SharedPointer (const Track *pTrack)
 
static const TypeInfoClassTypeInfo ()
 
- Static Public Member Functions inherited from ClientData::Site< Host, ClientData, ObjectCopyingPolicy, Pointer, ObjectLockingPolicy, RegistryLockingPolicy >
static size_t numFactories ()
 How many static factories have been registered with this specialization of Site. More...
 

Private Member Functions

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

Private Attributes

LabelArray mLabels
 
double mClipLen
 
int miLastLabel
 

Additional Inherited Members

- Static Public Attributes inherited from Observer::Publisher< struct LabelTrackEvent >
static constexpr bool notifies_all
 
- Protected Member Functions inherited from UniqueChannelTrack< Base >
ChannelGroupDoGetChannelGroup () const override
 Subclass must override. More...
 
- Protected Member Functions inherited from Track
void SetLinkType (LinkType linkType, bool completeList=true)
 
virtual void DoOnProjectTempoChange (const std::optional< double > &oldTempo, double newTempo)=0
 
- Protected Member Functions inherited from ClientData::Site< Host, ClientData, ObjectCopyingPolicy, Pointer, ObjectLockingPolicy, RegistryLockingPolicy >
template<typename Function >
void ForEach (const Function &function)
 Invoke function on each ClientData object that has been created in this. More...
 
template<typename Function >
void ForEach (const Function &function) const
 Invoke function on each ClientData object that has been created in this. More...
 
template<typename Function >
ClientData * FindIf (const Function &function)
 Return pointer to first attachment in this that is not null and satisfies a predicate, or nullptr. More...
 
template<typename Function >
const ClientData * FindIf (const Function &function) const
 Return pointer to first attachment in this that is not null and satisfies a predicate, or nullptr. More...
 
void BuildAll ()
 For each RegisteredFactory, if the corresponding attachment is absent in this, build and store it. More...
 
virtual std::shared_ptr< ChannelDoGetChannel (size_t iChannel)=0
 Retrieve a channel. More...
 
virtual std::shared_ptr< IntervalDoGetInterval (size_t iInterval)=0
 Retrieve an interval. More...
 
- Protected Member Functions inherited from Channel
virtual ChannelGroupDoGetChannelGroup () const =0
 Subclass must override. More...
 
virtual ChannelGroupReallyDoGetChannelGroup () const
 This is temporary! It defaults to call the above. More...
 
- Protected Member Functions inherited from Observer::Publisher< struct LabelTrackEvent >
CallbackReturn Publish (const struct LabelTrackEvent &message)
 Send a message to connected callbacks. More...
 
- Protected Attributes inherited from Track
std::weak_ptr< TrackListmList
 
TrackNodePointer mNode {}
 Holds iterator to self, so that TrackList::Find can be constant-time. More...
 
int mIndex
 0-based position of this track in its TrackList More...
 

Detailed Description

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

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

Definition at line 84 of file LabelTrack.h.

Member Typedef Documentation

◆ Holder

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

Definition at line 117 of file LabelTrack.h.

Constructor & Destructor Documentation

◆ LabelTrack() [1/2]

LabelTrack::LabelTrack ( )

Definition at line 89 of file LabelTrack.cpp.

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

◆ LabelTrack() [2/2]

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

Definition at line 96 of file LabelTrack.cpp.

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

References mLabels, and LabelStruct::selectedRegion.

◆ ~LabelTrack()

LabelTrack::~LabelTrack ( )
virtual

Definition at line 162 of file LabelTrack.cpp.

163{
164}

Member Function Documentation

◆ AddLabel()

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

Definition at line 971 of file LabelTrack.cpp.

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

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

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

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

◆ AdjustTimeStampOnScale()

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

Definition at line 275 of file LabelTrack.cpp.

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

Referenced by ScaleLabels().

Here is the caller graph for this function:

◆ ChangeLabelsOnReverse()

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

Definition at line 251 of file LabelTrack.cpp.

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

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

Here is the call graph for this function:

◆ ClassTypeInfo()

auto LabelTrack::ClassTypeInfo ( )
static

Definition at line 118 of file LabelTrack.cpp.

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

References typeInfo().

Here is the call graph for this function:

◆ Clear()

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

May assume precondition: t0 <= t1

Precondition
IsLeader()

Implements Track.

Definition at line 188 of file LabelTrack.cpp.

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

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

Referenced by Cut(), and SyncLockAdjust().

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

◆ Clone()

TrackListHolder LabelTrack::Clone ( ) const
overrideprivatevirtual

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

Parameters
unstretchIntervalIf set, this time interval's stretching must be applied.
Precondition
!unstretchInterval.has_value() || unstretchInterval->first < unstretchInterval->second
IsLeader()
Postcondition
result: NChannels() == result->NChannels()

Implements Track.

Definition at line 345 of file LabelTrack.cpp.

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

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

Here is the call graph for this function:

◆ Copy()

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

Create new tracks and don't modify this track.

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

Implements Track.

Definition at line 731 of file LabelTrack.cpp.

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

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

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

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

◆ Create() [1/2]

LabelTrack * LabelTrack::Create ( TrackList trackList)
static

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

Returns
New LabelTrack with unique default name

Definition at line 84 of file LabelTrack.cpp.

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

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

Here is the call graph for this function:

◆ Create() [2/2]

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

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

Returns
New LabelTrack with custom name

Definition at line 76 of file LabelTrack.cpp.

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

References TrackList::Add(), and name.

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

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

◆ Cut()

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

Create tracks and modify this track.

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

Implements Track.

Definition at line 709 of file LabelTrack.cpp.

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

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

Here is the call graph for this function:

◆ DeleteLabel()

void LabelTrack::DeleteLabel ( int  index)

Definition at line 990 of file LabelTrack.cpp.

991{
992 wxASSERT((index < (int)mLabels.size()));
993 auto iter = mLabels.begin() + index;
994 const auto title = iter->title;
995 mLabels.erase(iter);
996
998 this->SharedPointer<LabelTrack>(), title, index, -1 });
999}

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

Referenced by Clear(), and Silence().

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

◆ DoGetInterval()

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

Retrieve an interval.

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

Implements ChannelGroup.

Definition at line 148 of file LabelTrack.cpp.

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

References MakeInterval().

Here is the call graph for this function:

◆ DoOnProjectTempoChange()

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

Implements Track.

Definition at line 176 of file LabelTrack.cpp.

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

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

Here is the call graph for this function:

◆ Export()

void LabelTrack::Export ( wxTextFile &  f) const

Export labels including label start and end-times.

Definition at line 586 of file LabelTrack.cpp.

587{
588 // PRL: to do: export other selection fields
589 for (auto &labelStruct: mLabels)
590 labelStruct.Export(f);
591}

References mLabels.

◆ FindNextLabel()

int LabelTrack::FindNextLabel ( const SelectedRegion currentSelection)

Definition at line 1056 of file LabelTrack.cpp.

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

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

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

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

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

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

◆ GetDefaultName()

wxString LabelTrack::GetDefaultName ( )
static

Definition at line 63 of file LabelTrack.cpp.

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

References _.

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

Here is the caller graph for this function:

◆ GetLabel()

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

Definition at line 966 of file LabelTrack.cpp.

967{
968 return &mLabels[index];
969}

References mLabels.

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

Here is the caller graph for this function:

◆ GetLabels()

const LabelArray & LabelTrack::GetLabels ( ) const
inline

Definition at line 146 of file LabelTrack.h.

146{ return mLabels; }

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

Here is the caller graph for this function:

◆ GetNumLabels()

int LabelTrack::GetNumLabels ( ) const

Definition at line 961 of file LabelTrack.cpp.

962{
963 return mLabels.size();
964}

References mLabels.

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

Here is the caller graph for this function:

◆ GetTextOfLabels()

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

Definition at line 1037 of file LabelTrack.cpp.

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

References mLabels.

◆ GetTypeInfo()

auto LabelTrack::GetTypeInfo ( ) const
overridevirtual

Implements Track.

Definition at line 113 of file LabelTrack.cpp.

114{
115 return typeInfo();
116}

References typeInfo().

Here is the call graph for this function:

◆ HandleXMLChild()

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

Implements XMLTagHandler.

Definition at line 679 of file LabelTrack.cpp.

680{
681 if (tag == "label")
682 return this;
683 else
684 return NULL;
685}

◆ HandleXMLTag()

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

Implements XMLTagHandler.

Definition at line 618 of file LabelTrack.cpp.

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

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

Here is the call graph for this function:

◆ Import()

void LabelTrack::Import ( wxTextFile &  f)

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

Definition at line 594 of file LabelTrack.cpp.

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

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

Here is the call graph for this function:

◆ InsertSilence()

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

May assume precondition: t0 <= t1

Precondition
IsLeader()

Implements Track.

Definition at line 946 of file LabelTrack.cpp.

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

References Track::IsLeader(), and mLabels.

Here is the call graph for this function:

◆ MakeInterval()

auto LabelTrack::MakeInterval ( size_t  index)

Definition at line 138 of file LabelTrack.cpp.

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

References label.

Referenced by DoGetInterval().

Here is the caller graph for this function:

◆ MoveTo()

void LabelTrack::MoveTo ( double  o)
overridevirtual

Change start time to given time point.

Implements ChannelGroup.

Definition at line 166 of file LabelTrack.cpp.

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

References mLabels.

Referenced by ModifiedAnalysisTrack::ModifiedAnalysisTrack().

Here is the caller graph for this function:

◆ New()

LabelTrack * LabelTrack::New ( AudacityProject project)
static

Definition at line 68 of file LabelTrack.cpp.

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

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

Here is the call graph for this function:

◆ NIntervals()

size_t LabelTrack::NIntervals ( ) const
overridevirtual

Report the number of intervals.

Implements ChannelGroup.

Definition at line 133 of file LabelTrack.cpp.

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

References mLabels.

◆ OnLabelAdded()

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

◆ Paste()

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

Weak precondition allows overrides to replicate one channel into many.

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

Implements Track.

Definition at line 812 of file LabelTrack.cpp.

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

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

Referenced by EffectRepeat::Process().

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

◆ PasteInto()

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

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

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

Implements Track.

Definition at line 123 of file LabelTrack.cpp.

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

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

Here is the call graph for this function:

◆ PasteOver()

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

Definition at line 783 of file LabelTrack.cpp.

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

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

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

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

Referenced by EffectRepeat::Process().

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

◆ ScaleLabels()

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

Definition at line 266 of file LabelTrack.cpp.

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

References AdjustTimeStampOnScale(), and mLabels.

Here is the call graph for this function:

◆ SetLabel()

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

Definition at line 153 of file LabelTrack.cpp.

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

References mLabels.

◆ SetSelected()

void LabelTrack::SetSelected ( bool  s)
overridevirtual

Reimplemented from Track.

Definition at line 336 of file LabelTrack.cpp.

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

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

Here is the call graph for this function:

◆ ShiftLabelsOnInsert()

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

Definition at line 238 of file LabelTrack.cpp.

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

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

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

Here is the caller graph for this function:

◆ Silence()

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

Implements Track.

Definition at line 899 of file LabelTrack.cpp.

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

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

Here is the call graph for this function:

◆ SortLabels()

void LabelTrack::SortLabels ( )

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

Definition at line 1005 of file LabelTrack.cpp.

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

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

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

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

◆ SyncLockAdjust()

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

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

Precondition
IsLeader()

Reimplemented from Track.

Definition at line 881 of file LabelTrack.cpp.

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

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

Here is the call graph for this function:

◆ WarpLabels()

void LabelTrack::WarpLabels ( const TimeWarper warper)

Definition at line 294 of file LabelTrack.cpp.

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

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

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

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

◆ WriteXML()

void LabelTrack::WriteXML ( XMLWriter xmlFile) const
overridevirtual

Implements Track.

Definition at line 687 of file LabelTrack.cpp.

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

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

Here is the call graph for this function:

Member Data Documentation

◆ mClipLen

double LabelTrack::mClipLen
private

Definition at line 206 of file LabelTrack.h.

◆ miLastLabel

int LabelTrack::miLastLabel
private

Definition at line 208 of file LabelTrack.h.

Referenced by FindNextLabel(), and FindPrevLabel().

◆ mLabels

LabelArray LabelTrack::mLabels
private

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