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#include "FileNames.h"
19
20class wxTextFile;
21
22class AudacityProject;
23class TimeWarper;
24
25class LabelTrack;
26struct LabelTrackHit;
28
29enum class LabelFormat
30{
31 TEXT,
32 SUBRIP,
33 WEBVTT,
34};
35
36LABEL_TRACK_API
38
39class LABEL_TRACK_API LabelStruct
40{
41public:
42 LabelStruct() = default;
43 // Copies region
44 LabelStruct(const SelectedRegion& region, const wxString &aTitle);
45 // Copies region but then overwrites other times
46 LabelStruct(const SelectedRegion& region, double t0, double t1,
47 const wxString &aTitle);
48 const SelectedRegion &getSelectedRegion() const { return selectedRegion; }
49 double getDuration() const { return selectedRegion.duration(); }
50 double getT0() const { return selectedRegion.t0(); }
51 double getT1() const { return selectedRegion.t1(); }
52 // Returns true iff the label got inverted:
53 bool AdjustEdge( int iEdge, double fNewTime);
54 void MoveLabel( int iEdge, double fNewTime);
55
57 static LabelStruct Import(wxTextFile &file, int &index, LabelFormat format);
58
59 void Export(wxTextFile &file, LabelFormat format, int index) const;
60
63 {
69 ENDS_IN_LABEL
70 };
71
76 TimeRelations RegionRelation(double reg_t0, double reg_t1,
77 const LabelTrack *parent = NULL) const;
78
79public:
81 wxString title;
82 mutable int width{};
83
84// Working storage for on-screen layout.
85 mutable int x{};
86 mutable int x1{};
87 mutable int xText{};
88 mutable int y{};
89
90 bool updated{};
91};
92
93using LabelArray = std::vector<LabelStruct>;
94
95class LABEL_TRACK_API LabelTrack final
96 : public UniqueChannelTrack<>
97 , public Observer::Publisher<struct LabelTrackEvent>
98{
99 public:
100 static wxString GetDefaultName();
101
102 // Construct and also build all attachments
103 static LabelTrack *New(AudacityProject &project);
104
109 static LabelTrack* Create(TrackList& trackList, const wxString& name);
110
115 static LabelTrack* Create(TrackList& trackList);
116
117 LabelTrack();
119
120 virtual ~ LabelTrack();
121
122 void SetLabel( size_t iLabel, const LabelStruct &newLabel );
123
124 void MoveTo(double dOffset) override;
125 void ShiftBy(double t0, double delta) override;
126
127 void SetSelected(bool s) override;
128
129 using Holder = std::shared_ptr<LabelTrack>;
130
133
134private:
135 Track::Holder Clone(bool backup) const override;
136
137public:
138 bool HandleXMLTag(const std::string_view& tag, const AttributesList& attrs) override;
139 XMLTagHandler *HandleXMLChild(const std::string_view& tag) override;
140 void WriteXML(XMLWriter &xmlFile) const override;
141
142 Track::Holder Cut(double t0, double t1) override;
143 Track::Holder Copy(double t0, double t1, bool forClipboard = true)
144 const override;
145 void Clear(double t0, double t1) override;
146 void Paste(double t, const Track &src) override;
147 bool Repeat(double t0, double t1, int n);
148 void SyncLockAdjust(double oldT1, double newT1) override;
149
150 void
151 Silence(double t0, double t1, ProgressReporter reportProgress = {}) override;
152 void InsertSilence(double t, double len) override;
153
154 static LabelFormat FormatForFileName(const wxString & fileName);
155 void Import(wxTextFile & f, LabelFormat format);
156 void Export(wxTextFile & f, LabelFormat format) const;
157
158 int GetNumLabels() const;
159 const LabelStruct *GetLabel(int index) const;
160 const LabelArray &GetLabels() const { return mLabels; }
161
162 void OnLabelAdded( const wxString &title, int pos );
163 //This returns the index of the label we just added.
164 int AddLabel(const SelectedRegion &region, const wxString &title);
165
166 //This deletes the label at given index.
167 void DeleteLabel(int index);
168
169 // This pastes labels without shifting existing ones
170 bool PasteOver(double t, const Track &src);
171
172 // PRL: These functions were not used because they were not overrides! Was that right?
173 //Track::Holder SplitCut(double b, double e) /* not override */;
174 //bool SplitDelete(double b, double e) /* not override */;
175
176 void ShiftLabelsOnInsert(double length, double pt);
177 void ChangeLabelsOnReverse(double b, double e);
178 void ScaleLabels(double b, double e, double change);
179 double AdjustTimeStampOnScale(double t, double b, double e, double change);
180 void WarpLabels(const TimeWarper &warper);
181
182 // Returns tab-separated text of all labels completely within given region
183 wxString GetTextOfLabels(double t0, double t1) const;
184
185 int FindNextLabel(const SelectedRegion& currentSelection);
186 int FindPrevLabel(const SelectedRegion& currentSelection);
187
188 const TypeInfo &GetTypeInfo() const override;
189 static const TypeInfo &ClassTypeInfo();
190
192 const override;
193
195 Interval(const LabelTrack &track, size_t index
196 ) : mpTrack{ track.SharedPointer<const LabelTrack>() }
197 , index{ index }
198 {}
199
200 ~Interval() override;
201 double Start() const override;
202 double End() const override;
203 size_t NChannels() const override;
204 std::shared_ptr<ChannelInterval> DoGetChannel(size_t iChannel) override;
205
206 size_t index;
207 private:
209 const std::shared_ptr<const LabelTrack> mpTrack;
210 };
211 std::shared_ptr<Interval> MakeInterval(size_t index);
212
213public:
214 void SortLabels();
215
216 size_t NIntervals() const override;
217
218private:
219 std::shared_ptr<WideChannelGroupInterval> DoGetInterval(size_t iInterval)
220 override;
221
223
224 // Set in copied label tracks
225 double mClipLen;
226
227 int miLastLabel; // used by FindNextLabel and FindPrevLabel
228};
229
231
233{
234 enum Type {
240
241 const std::weak_ptr<Track> mpTrack;
242
243 // invalid for selection events
244 wxString mTitle;
245
246 // invalid for addition and selection events
248
249 // invalid for deletion and selection events
251
252 LabelTrackEvent( Type type, const std::shared_ptr<LabelTrack> &pTrack,
253 const wxString &title,
254 int formerPosition,
255 int presentPosition)
256 : type{ type }
257 , mpTrack{ pTrack }
258 , mTitle{ title }
259 , mFormerPosition{ formerPosition }
260 , mPresentPosition{ presentPosition }
261 {}
262};
263
264#endif
LABEL_TRACK_API EnumSetting< bool > LabelStyleSetting
Definition: LabelTrack.cpp:51
std::vector< LabelStruct > LabelArray
Definition: LabelTrack.h:93
ENUMERATE_TRACK_TYPE(LabelTrack)
LabelFormat
Definition: LabelTrack.h:30
static const auto title
wxString name
Definition: TagsEditor.cpp:166
const auto project
declares abstract base class Track, TrackList, and iterators over TrackList
std::function< void(double)> ProgressReporter
Definition: Track.h:48
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:90
Main class to control the export function.
A LabelStruct holds information for ONE label in a LabelTrack.
Definition: LabelTrack.h:40
const SelectedRegion & getSelectedRegion() const
Definition: LabelTrack.h:48
double getT1() const
Definition: LabelTrack.h:51
TimeRelations
Relationships between selection region and labels.
Definition: LabelTrack.h:63
@ BEGINS_IN_LABEL
Definition: LabelTrack.h:68
@ SURROUNDS_LABEL
Definition: LabelTrack.h:66
LabelStruct()=default
double getT0() const
Definition: LabelTrack.h:50
wxString title
Definition: LabelTrack.h:81
SelectedRegion selectedRegion
Definition: LabelTrack.h:80
double getDuration() const
Definition: LabelTrack.h:49
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:98
double mClipLen
Definition: LabelTrack.h:225
static const FileNames::FileType WebVTTFiles
Definition: LabelTrack.h:132
static const FileNames::FileType SubripFiles
Definition: LabelTrack.h:131
const LabelArray & GetLabels() const
Definition: LabelTrack.h:160
std::shared_ptr< LabelTrack > Holder
Definition: LabelTrack.h:129
int miLastLabel
Definition: LabelTrack.h:227
void OnLabelAdded(const wxString &title, int pos)
LabelArray mLabels
Definition: LabelTrack.h:222
An object that sends messages to an open-ended list of subscribed callbacks.
Definition: Observer.h:108
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:110
std::shared_ptr< Track > Holder
Definition: Track.h:202
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:850
Generates overrides of channel-related functions.
Definition: Track.h:450
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:25
const std::shared_ptr< const LabelTrack > mpTrack
Definition: LabelTrack.h:209
Interval(const LabelTrack &track, size_t index)
Definition: LabelTrack.h:195
LabelTrackEvent(Type type, const std::shared_ptr< LabelTrack > &pTrack, const wxString &title, int formerPosition, int presentPosition)
Definition: LabelTrack.h:252
const std::weak_ptr< Track > mpTrack
Definition: LabelTrack.h:241
wxString mTitle
Definition: LabelTrack.h:244
enum LabelTrackEvent::Type type
Empty argument passed to some public constructors.
Definition: Track.h:117