Audacity 3.2.0
LabelTrack.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 LabelTrack.h
6
7 Dominic Mazzoni
8 James Crook
9 Jun Wan
10
11**********************************************************************/
12
13#ifndef _LABELTRACK_
14#define _LABELTRACK_
15
16#include "SelectedRegion.h"
17#include "Track.h"
18
19#include <wx/event.h> // to inherit
20
21class wxTextFile;
22
23class AudacityProject;
24class TimeWarper;
25
26class LabelTrack;
27struct LabelTrackHit;
29
30class AUDACITY_DLL_API LabelStruct
31{
32public:
33 LabelStruct() = default;
34 // Copies region
35 LabelStruct(const SelectedRegion& region, const wxString &aTitle);
36 // Copies region but then overwrites other times
37 LabelStruct(const SelectedRegion& region, double t0, double t1,
38 const wxString &aTitle);
39 const SelectedRegion &getSelectedRegion() const { return selectedRegion; }
40 double getDuration() const { return selectedRegion.duration(); }
41 double getT0() const { return selectedRegion.t0(); }
42 double getT1() const { return selectedRegion.t1(); }
43 // Returns true iff the label got inverted:
44 bool AdjustEdge( int iEdge, double fNewTime);
45 void MoveLabel( int iEdge, double fNewTime);
46
48 static LabelStruct Import(wxTextFile &file, int &index);
49
50 void Export(wxTextFile &file) const;
51
54 {
60 ENDS_IN_LABEL
61 };
62
67 TimeRelations RegionRelation(double reg_t0, double reg_t1,
68 const LabelTrack *parent = NULL) const;
69
70public:
72 wxString title;
73 mutable int width{};
74
75// Working storage for on-screen layout.
76 mutable int x{};
77 mutable int x1{};
78 mutable int xText{};
79 mutable int y{};
80
81 bool updated{};
82};
83
84using LabelArray = std::vector<LabelStruct>;
85
86class AUDACITY_DLL_API LabelTrack final
87 : public Track
88 , public wxEvtHandler
89{
90 public:
91 static wxString GetDefaultName();
92
93 // Construct and also build all attachments
94 static LabelTrack *New(AudacityProject &project);
95
100 static LabelTrack* Create(TrackList& trackList, const wxString& name);
101
106 static LabelTrack* Create(TrackList& trackList);
107
108 LabelTrack();
109 LabelTrack(const LabelTrack &orig);
110
111 virtual ~ LabelTrack();
112
113 void SetLabel( size_t iLabel, const LabelStruct &newLabel );
114
115 void SetOffset(double dOffset) override;
116
117 void SetSelected(bool s) override;
118
119 double GetOffset() const override;
120 double GetStartTime() const override;
121 double GetEndTime() const override;
122
123 using Holder = std::shared_ptr<LabelTrack>;
124
125private:
126 Track::Holder Clone() const override;
127
128public:
129 bool HandleXMLTag(const std::string_view& tag, const AttributesList& attrs) override;
130 XMLTagHandler *HandleXMLChild(const std::string_view& tag) override;
131 void WriteXML(XMLWriter &xmlFile) const override;
132
133 Track::Holder Cut (double t0, double t1) override;
134 Track::Holder Copy (double t0, double t1, bool forClipboard = true) const override;
135 void Clear(double t0, double t1) override;
136 void Paste(double t, const Track * src) override;
137 bool Repeat(double t0, double t1, int n);
138 void SyncLockAdjust(double oldT1, double newT1) override;
139
140 void Silence(double t0, double t1) override;
141 void InsertSilence(double t, double len) override;
142
143 void Import(wxTextFile & f);
144 void Export(wxTextFile & f) const;
145
146 int GetNumLabels() const;
147 const LabelStruct *GetLabel(int index) const;
148 const LabelArray &GetLabels() const { return mLabels; }
149
150 void OnLabelAdded( const wxString &title, int pos );
151 //This returns the index of the label we just added.
152 int AddLabel(const SelectedRegion &region, const wxString &title);
153
154 //This deletes the label at given index.
155 void DeleteLabel(int index);
156
157 // This pastes labels without shifting existing ones
158 bool PasteOver(double t, const Track *src);
159
160 // PRL: These functions were not used because they were not overrides! Was that right?
161 //Track::Holder SplitCut(double b, double e) /* not override */;
162 //bool SplitDelete(double b, double e) /* not override */;
163
164 void ShiftLabelsOnInsert(double length, double pt);
165 void ChangeLabelsOnReverse(double b, double e);
166 void ScaleLabels(double b, double e, double change);
167 double AdjustTimeStampOnScale(double t, double b, double e, double change);
168 void WarpLabels(const TimeWarper &warper);
169
170 // Returns tab-separated text of all labels completely within given region
171 wxString GetTextOfLabels(double t0, double t1) const;
172
173 int FindNextLabel(const SelectedRegion& currentSelection);
174 int FindPrevLabel(const SelectedRegion& currentSelection);
175
176 const TypeInfo &GetTypeInfo() const override;
177 static const TypeInfo &ClassTypeInfo();
178
179 Track::Holder PasteInto( AudacityProject & ) const override;
180
182 size_t index;
183 explicit IntervalData(size_t index) : index{index} {};
184 };
185 ConstInterval MakeInterval ( size_t index ) const;
186 Interval MakeInterval ( size_t index );
187 ConstIntervals GetIntervals() const override;
188 Intervals GetIntervals() override;
189
190 public:
191 void SortLabels();
192
193 private:
195
196 // Set in copied label tracks
197 double mClipLen;
198
199 int miLastLabel; // used by FindNextLabel and FindPrevLabel
200};
201
203
204struct LabelTrackEvent : public wxEvent
205{
206 explicit
208 wxEventType commandType, const std::shared_ptr<LabelTrack> &pTrack,
209 const wxString &title,
210 int formerPosition,
211 int presentPosition
212 )
213 : wxEvent{ 0, commandType }
214 , mpTrack{ pTrack }
215 , mTitle{ title }
216 , mFormerPosition{ formerPosition }
217 , mPresentPosition{ presentPosition }
218 {}
219
220 LabelTrackEvent( const LabelTrackEvent& ) = default;
221 wxEvent *Clone() const override {
222 // wxWidgets will own the event object
223 return safenew LabelTrackEvent(*this); }
224
225 const std::weak_ptr<Track> mpTrack;
226
227 // invalid for selection events
228 wxString mTitle;
229
230 // invalid for addition and selection events
232
233 // invalid for deletion and selection events
235};
236
237// Posted when a label is added.
239 EVT_LABELTRACK_ADDITION, LabelTrackEvent);
240
241// Posted when a label is deleted.
243 EVT_LABELTRACK_DELETION, LabelTrackEvent);
244
245// Posted when a label is repositioned in the sequence of labels.
247 EVT_LABELTRACK_PERMUTED, LabelTrackEvent);
248
249// Posted when the track is selected or unselected.
251 EVT_LABELTRACK_SELECTION, LabelTrackEvent);
252#endif
const TranslatableString name
Definition: Distortion.cpp:82
std::vector< LabelStruct > LabelArray
Definition: LabelTrack.h:84
ENUMERATE_TRACK_TYPE(LabelTrack)
wxDECLARE_EXPORTED_EVENT(AUDACITY_DLL_API, EVT_LABELTRACK_ADDITION, LabelTrackEvent)
#define safenew
Definition: MemoryX.h:10
static const auto title
declares abstract base class Track, TrackList, and iterators over TrackList
std::vector< Attribute > AttributesList
Definition: XMLTagHandler.h:40
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:89
Main class to control the export function.
A LabelStruct holds information for ONE label in a LabelTrack.
Definition: LabelTrack.h:31
const SelectedRegion & getSelectedRegion() const
Definition: LabelTrack.h:39
double getT1() const
Definition: LabelTrack.h:42
TimeRelations
Relationships between selection region and labels.
Definition: LabelTrack.h:54
@ BEGINS_IN_LABEL
Definition: LabelTrack.h:59
@ SURROUNDS_LABEL
Definition: LabelTrack.h:57
LabelStruct()=default
double getT0() const
Definition: LabelTrack.h:41
wxString title
Definition: LabelTrack.h:72
SelectedRegion selectedRegion
Definition: LabelTrack.h:71
double getDuration() const
Definition: LabelTrack.h:40
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:89
double mClipLen
Definition: LabelTrack.h:197
const LabelArray & GetLabels() const
Definition: LabelTrack.h:148
std::shared_ptr< LabelTrack > Holder
Definition: LabelTrack.h:123
int miLastLabel
Definition: LabelTrack.h:199
void OnLabelAdded(const wxString &title, int pos)
LabelArray mLabels
Definition: LabelTrack.h:194
Defines a selected portion of a project.
Transforms one point in time to another point. For example, a time stretching effect might use one to...
Definition: TimeWarper.h:62
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:225
std::shared_ptr< Track > Holder
Definition: Track.h:361
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:1330
This class is an interface which should be implemented by classes which wish to be able to load and s...
Definition: XMLTagHandler.h:42
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
Definition: XMLWriter.h:26
IntervalData(size_t index)
Definition: LabelTrack.h:183
LabelTrackEvent(const LabelTrackEvent &)=default
const std::weak_ptr< Track > mpTrack
Definition: LabelTrack.h:225
wxString mTitle
Definition: LabelTrack.h:228
LabelTrackEvent(wxEventType commandType, const std::shared_ptr< LabelTrack > &pTrack, const wxString &title, int formerPosition, int presentPosition)
Definition: LabelTrack.h:207
wxEvent * Clone() const override
Definition: LabelTrack.h:221
Optional extra information about an interval, appropriate to a subtype of Track.
Definition: Track.h:172