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 UniqueChannelTrack<>
86 , public Observer::Publisher<struct LabelTrackEvent>
87{
88 public:
89 static wxString GetDefaultName();
90
91 // Construct and also build all attachments
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 MoveTo(double dOffset) override;
114
115 void SetSelected(bool s) override;
116
117 using Holder = std::shared_ptr<LabelTrack>;
118
119private:
120 TrackListHolder Clone(bool backup) const override;
121 void DoOnProjectTempoChange(
122 const std::optional<double>& oldTempo, double newTempo) override;
123
124public:
125 bool HandleXMLTag(const std::string_view& tag, const AttributesList& attrs) override;
126 XMLTagHandler *HandleXMLChild(const std::string_view& tag) override;
127 void WriteXML(XMLWriter &xmlFile) const override;
128
129 TrackListHolder Cut(double t0, double t1) override;
130 TrackListHolder Copy(double t0, double t1, bool forClipboard = true)
131 const override;
132 void Clear(double t0, double t1) override;
133 void Paste(double t, const Track &src) override;
134 bool Repeat(double t0, double t1, int n);
135 void SyncLockAdjust(double oldT1, double newT1) override;
136
137 void
138 Silence(double t0, double t1, ProgressReporter reportProgress = {}) 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
178 const override;
179
181 Interval(const ChannelGroup &group,
182 double start, double end, size_t index
183 ) : WideChannelGroupInterval{ group, start, end }
184 , index{ index }
185 {}
186
187 ~Interval() override;
188 std::shared_ptr<ChannelInterval> DoGetChannel(size_t iChannel) override;
189
190 size_t index;
191 };
192 std::shared_ptr<Interval> MakeInterval(size_t index);
193
194public:
195 void SortLabels();
196
197 size_t NIntervals() const override;
198
199private:
200 std::shared_ptr<WideChannelGroupInterval> DoGetInterval(size_t iInterval)
201 override;
202
204
205 // Set in copied label tracks
206 double mClipLen;
207
208 int miLastLabel; // used by FindNextLabel and FindPrevLabel
209};
210
212
214{
215 enum Type {
221
222 const std::weak_ptr<Track> mpTrack;
223
224 // invalid for selection events
225 wxString mTitle;
226
227 // invalid for addition and selection events
229
230 // invalid for deletion and selection events
232
233 LabelTrackEvent( Type type, const std::shared_ptr<LabelTrack> &pTrack,
234 const wxString &title,
235 int formerPosition,
236 int presentPosition)
237 : type{ type }
238 , mpTrack{ pTrack }
239 , mTitle{ title }
240 , mFormerPosition{ formerPosition }
241 , mPresentPosition{ presentPosition }
242 {}
243};
244
245#endif
const TranslatableString name
Definition: Distortion.cpp:76
std::vector< LabelStruct > LabelArray
Definition: LabelTrack.h:82
ENUMERATE_TRACK_TYPE(LabelTrack)
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:53
std::shared_ptr< TrackList > TrackListHolder
Definition: Track.h:42
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:206
const LabelArray & GetLabels() const
Definition: LabelTrack.h:146
std::shared_ptr< LabelTrack > Holder
Definition: LabelTrack.h:117
int miLastLabel
Definition: LabelTrack.h:208
void OnLabelAdded(const wxString &title, int pos)
LabelArray mLabels
Definition: LabelTrack.h:203
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:122
std::shared_ptr< Track > Holder
Definition: Track.h:225
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:993
Generates overrides of channel-related functions.
Definition: Track.h:508
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
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159
Interval(const ChannelGroup &group, double start, double end, 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:233
const std::weak_ptr< Track > mpTrack
Definition: LabelTrack.h:222
wxString mTitle
Definition: LabelTrack.h:225
enum LabelTrackEvent::Type type
Empty argument passed to some public constructors.
Definition: Track.h:129