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