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
19class wxTextFile;
20
21class AudacityProject;
22class TimeWarper;
23
24class LabelTrack;
25struct LabelTrackHit;
27
28class AUDACITY_DLL_API LabelStruct
29{
30public:
31 LabelStruct() = default;
32 // Copies region
33 LabelStruct(const SelectedRegion& region, const wxString &aTitle);
34 // Copies region but then overwrites other times
35 LabelStruct(const SelectedRegion& region, double t0, double t1,
36 const wxString &aTitle);
37 const SelectedRegion &getSelectedRegion() const { return selectedRegion; }
38 double getDuration() const { return selectedRegion.duration(); }
39 double getT0() const { return selectedRegion.t0(); }
40 double getT1() const { return selectedRegion.t1(); }
41 // Returns true iff the label got inverted:
42 bool AdjustEdge( int iEdge, double fNewTime);
43 void MoveLabel( int iEdge, double fNewTime);
44
46 static LabelStruct Import(wxTextFile &file, int &index);
47
48 void Export(wxTextFile &file) const;
49
52 {
58 ENDS_IN_LABEL
59 };
60
65 TimeRelations RegionRelation(double reg_t0, double reg_t1,
66 const LabelTrack *parent = NULL) const;
67
68public:
70 wxString title;
71 mutable int width{};
72
73// Working storage for on-screen layout.
74 mutable int x{};
75 mutable int x1{};
76 mutable int xText{};
77 mutable int y{};
78
79 bool updated{};
80};
81
82using LabelArray = std::vector<LabelStruct>;
83
84class AUDACITY_DLL_API LabelTrack final
85 : public Track
86 , public Observer::Publisher<struct LabelTrackEvent>
87{
88 public:
89 static wxString GetDefaultName();
90
91 // Construct and also build all attachments
92 static LabelTrack *New(AudacityProject &project);
93
98 static LabelTrack* Create(TrackList& trackList, const wxString& name);
99
104 static LabelTrack* Create(TrackList& trackList);
105
106 LabelTrack();
108
109 virtual ~ LabelTrack();
110
111 void SetLabel( size_t iLabel, const LabelStruct &newLabel );
112
113 void SetOffset(double dOffset) override;
114
115 void SetSelected(bool s) override;
116
117 double GetOffset() const override;
118 double GetStartTime() const override;
119 double GetEndTime() const override;
120
121 using Holder = std::shared_ptr<LabelTrack>;
122
123private:
124 Track::Holder Clone() const override;
125
126public:
127 bool HandleXMLTag(const std::string_view& tag, const AttributesList& attrs) override;
128 XMLTagHandler *HandleXMLChild(const std::string_view& tag) override;
129 void WriteXML(XMLWriter &xmlFile) const override;
130
131 Track::Holder Cut (double t0, double t1) override;
132 Track::Holder Copy (double t0, double t1, bool forClipboard = true) const override;
133 void Clear(double t0, double t1) override;
134 void Paste(double t, const Track * src) override;
135 bool Repeat(double t0, double t1, int n);
136 void SyncLockAdjust(double oldT1, double newT1) override;
137
138 void Silence(double t0, double t1) override;
139 void InsertSilence(double t, double len) override;
140
141 void Import(wxTextFile & f);
142 void Export(wxTextFile & f) const;
143
144 int GetNumLabels() const;
145 const LabelStruct *GetLabel(int index) const;
146 const LabelArray &GetLabels() const { return mLabels; }
147
148 void OnLabelAdded( const wxString &title, int pos );
149 //This returns the index of the label we just added.
150 int AddLabel(const SelectedRegion &region, const wxString &title);
151
152 //This deletes the label at given index.
153 void DeleteLabel(int index);
154
155 // This pastes labels without shifting existing ones
156 bool PasteOver(double t, const Track *src);
157
158 // PRL: These functions were not used because they were not overrides! Was that right?
159 //Track::Holder SplitCut(double b, double e) /* not override */;
160 //bool SplitDelete(double b, double e) /* not override */;
161
162 void ShiftLabelsOnInsert(double length, double pt);
163 void ChangeLabelsOnReverse(double b, double e);
164 void ScaleLabels(double b, double e, double change);
165 double AdjustTimeStampOnScale(double t, double b, double e, double change);
166 void WarpLabels(const TimeWarper &warper);
167
168 // Returns tab-separated text of all labels completely within given region
169 wxString GetTextOfLabels(double t0, double t1) const;
170
171 int FindNextLabel(const SelectedRegion& currentSelection);
172 int FindPrevLabel(const SelectedRegion& currentSelection);
173
174 const TypeInfo &GetTypeInfo() const override;
175 static const TypeInfo &ClassTypeInfo();
176
177 Track::Holder PasteInto( AudacityProject & ) const override;
178
180 size_t index;
181 explicit IntervalData(size_t index) : index{index} {};
182 };
183 ConstInterval MakeInterval ( size_t index ) const;
184 Interval MakeInterval ( size_t index );
185 ConstIntervals GetIntervals() const override;
186 Intervals GetIntervals() override;
187
188 public:
189 void SortLabels();
190
191 private:
193
194 // Set in copied label tracks
195 double mClipLen;
196
197 int miLastLabel; // used by FindNextLabel and FindPrevLabel
198};
199
201
203{
204 enum Type {
210
211 const std::weak_ptr<Track> mpTrack;
212
213 // invalid for selection events
214 wxString mTitle;
215
216 // invalid for addition and selection events
218
219 // invalid for deletion and selection events
221
222 LabelTrackEvent( Type type, const std::shared_ptr<LabelTrack> &pTrack,
223 const wxString &title,
224 int formerPosition,
225 int presentPosition)
226 : type{ type }
227 , mpTrack{ pTrack }
228 , mTitle{ title }
229 , mFormerPosition{ formerPosition }
230 , mPresentPosition{ presentPosition }
231 {}
232};
233
234#endif
const TranslatableString name
Definition: Distortion.cpp:76
std::vector< LabelStruct > LabelArray
Definition: LabelTrack.h:82
ENUMERATE_TRACK_TYPE(LabelTrack)
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:90
Main class to control the export function.
A LabelStruct holds information for ONE label in a LabelTrack.
Definition: LabelTrack.h:29
const SelectedRegion & getSelectedRegion() const
Definition: LabelTrack.h:37
double getT1() const
Definition: LabelTrack.h:40
TimeRelations
Relationships between selection region and labels.
Definition: LabelTrack.h:52
@ BEGINS_IN_LABEL
Definition: LabelTrack.h:57
@ SURROUNDS_LABEL
Definition: LabelTrack.h:55
LabelStruct()=default
double getT0() const
Definition: LabelTrack.h:39
wxString title
Definition: LabelTrack.h:70
SelectedRegion selectedRegion
Definition: LabelTrack.h:69
double getDuration() const
Definition: LabelTrack.h:38
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:87
double mClipLen
Definition: LabelTrack.h:195
const LabelArray & GetLabels() const
Definition: LabelTrack.h:146
std::shared_ptr< LabelTrack > Holder
Definition: LabelTrack.h:121
int miLastLabel
Definition: LabelTrack.h:197
void OnLabelAdded(const wxString &title, int pos)
LabelArray mLabels
Definition: LabelTrack.h:192
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:162
std::shared_ptr< Track > Holder
Definition: Track.h:303
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:1212
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
IntervalData(size_t index)
Definition: LabelTrack.h:181
LabelTrackEvent(Type type, const std::shared_ptr< LabelTrack > &pTrack, const wxString &title, int formerPosition, int presentPosition)
Definition: LabelTrack.h:222
const std::weak_ptr< Track > mpTrack
Definition: LabelTrack.h:211
wxString mTitle
Definition: LabelTrack.h:214
enum LabelTrackEvent::Type type
Empty argument passed to some public constructors.
Definition: Track.h:169
Optional extra information about an interval, appropriate to a subtype of Track.
Definition: Track.h:109