forked from Sneeds-Feed-and-Seed/sneedacity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLabelTrack.h
228 lines (173 loc) · 7.04 KB
/
LabelTrack.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/**********************************************************************
Sneedacity: A Digital Audio Editor
LabelTrack.h
Dominic Mazzoni
James Crook
Jun Wan
**********************************************************************/
#ifndef _LABELTRACK_
#define _LABELTRACK_
#include "SelectedRegion.h"
#include "Track.h"
class wxTextFile;
class SneedacityProject;
class NotifyingSelectedRegion;
class TimeWarper;
struct LabelTrackHit;
struct TrackPanelDrawingContext;
class SNEEDACITY_DLL_API LabelStruct
{
public:
LabelStruct() = default;
// Copies region
LabelStruct(const SelectedRegion& region, const wxString &aTitle);
// Copies region but then overwrites other times
LabelStruct(const SelectedRegion& region, double t0, double t1,
const wxString &aTitle);
const SelectedRegion &getSelectedRegion() const { return selectedRegion; }
double getDuration() const { return selectedRegion.duration(); }
double getT0() const { return selectedRegion.t0(); }
double getT1() const { return selectedRegion.t1(); }
// Returns true iff the label got inverted:
bool AdjustEdge( int iEdge, double fNewTime);
void MoveLabel( int iEdge, double fNewTime);
struct BadFormatException {};
static LabelStruct Import(wxTextFile &file, int &index);
void Export(wxTextFile &file) const;
/// Relationships between selection region and labels
enum TimeRelations
{
BEFORE_LABEL,
AFTER_LABEL,
SURROUNDS_LABEL,
WITHIN_LABEL,
BEGINS_IN_LABEL,
ENDS_IN_LABEL
};
/// Returns relationship between a region described and this label; if
/// parent is set, it will consider point labels at the very beginning
/// and end of parent to be within a region that borders them (this makes
/// it possible to DELETE capture all labels with a Select All).
TimeRelations RegionRelation(double reg_t0, double reg_t1,
const LabelTrack *parent = NULL) const;
public:
SelectedRegion selectedRegion;
wxString title; /// Text of the label.
mutable int width{}; /// width of the text in pixels.
// Working storage for on-screen layout.
mutable int x{}; /// Pixel position of left hand glyph
mutable int x1{}; /// Pixel position of right hand glyph
mutable int xText{}; /// Pixel position of left hand side of text box
mutable int y{}; /// Pixel position of label.
bool updated{}; /// flag to tell if the label times were updated
};
using LabelArray = std::vector<LabelStruct>;
class SNEEDACITY_DLL_API LabelTrack final
: public Track
, public wxEvtHandler
{
public:
LabelTrack();
LabelTrack(const LabelTrack &orig);
virtual ~ LabelTrack();
void SetLabel( size_t iLabel, const LabelStruct &newLabel );
void SetOffset(double dOffset) override;
void SetSelected(bool s) override;
double GetOffset() const override;
double GetStartTime() const override;
double GetEndTime() const override;
using Holder = std::shared_ptr<LabelTrack>;
private:
Track::Holder Clone() const override;
public:
bool HandleXMLTag(const wxChar *tag, const wxChar **attrs) override;
XMLTagHandler *HandleXMLChild(const wxChar *tag) override;
void WriteXML(XMLWriter &xmlFile) const override;
Track::Holder Cut (double t0, double t1) override;
Track::Holder Copy (double t0, double t1, bool forClipboard = true) const override;
void Clear(double t0, double t1) override;
void Paste(double t, const Track * src) override;
bool Repeat(double t0, double t1, int n);
void SyncLockAdjust(double oldT1, double newT1) override;
void Silence(double t0, double t1) override;
void InsertSilence(double t, double len) override;
void Import(wxTextFile & f);
void Export(wxTextFile & f) const;
int GetNumLabels() const;
const LabelStruct *GetLabel(int index) const;
const LabelArray &GetLabels() const { return mLabels; }
void OnLabelAdded( const wxString &title, int pos );
//This returns the index of the label we just added.
int AddLabel(const SelectedRegion ®ion, const wxString &title);
//This deletes the label at given index.
void DeleteLabel(int index);
// This pastes labels without shifting existing ones
bool PasteOver(double t, const Track *src);
// PRL: These functions were not used because they were not overrides! Was that right?
//Track::Holder SplitCut(double b, double e) /* not override */;
//bool SplitDelete(double b, double e) /* not override */;
void ShiftLabelsOnInsert(double length, double pt);
void ChangeLabelsOnReverse(double b, double e);
void ScaleLabels(double b, double e, double change);
double AdjustTimeStampOnScale(double t, double b, double e, double change);
void WarpLabels(const TimeWarper &warper);
// Returns tab-separated text of all labels completely within given region
wxString GetTextOfLabels(double t0, double t1) const;
int FindNextLabel(const SelectedRegion& currentSelection);
int FindPrevLabel(const SelectedRegion& currentSelection);
Track::Holder PasteInto( SneedacityProject & ) const override;
struct IntervalData final : Track::IntervalData {
size_t index;
explicit IntervalData(size_t index) : index{index} {};
};
ConstInterval MakeInterval ( size_t index ) const;
Interval MakeInterval ( size_t index );
ConstIntervals GetIntervals() const override;
Intervals GetIntervals() override;
public:
void SortLabels();
private:
TrackKind GetKind() const override { return TrackKind::Label; }
LabelArray mLabels;
// Set in copied label tracks
double mClipLen;
int miLastLabel; // used by FindNextLabel and FindPrevLabel
};
struct LabelTrackEvent : TrackListEvent
{
explicit
LabelTrackEvent(
wxEventType commandType, const std::shared_ptr<LabelTrack> &pTrack,
const wxString &title,
int formerPosition,
int presentPosition
)
: TrackListEvent{ commandType, pTrack }
, mTitle{ title }
, mFormerPosition{ formerPosition }
, mPresentPosition{ presentPosition }
{}
LabelTrackEvent( const LabelTrackEvent& ) = default;
wxEvent *Clone() const override {
// wxWidgets will own the event object
return safenew LabelTrackEvent(*this); }
// invalid for selection events
wxString mTitle;
// invalid for addition and selection events
int mFormerPosition{ -1 };
// invalid for deletion and selection events
int mPresentPosition{ -1 };
};
// Posted when a label is added.
wxDECLARE_EXPORTED_EVENT(SNEEDACITY_DLL_API,
EVT_LABELTRACK_ADDITION, LabelTrackEvent);
// Posted when a label is deleted.
wxDECLARE_EXPORTED_EVENT(SNEEDACITY_DLL_API,
EVT_LABELTRACK_DELETION, LabelTrackEvent);
// Posted when a label is repositioned in the sequence of labels.
wxDECLARE_EXPORTED_EVENT(SNEEDACITY_DLL_API,
EVT_LABELTRACK_PERMUTED, LabelTrackEvent);
// Posted when the track is selected or unselected.
wxDECLARE_EXPORTED_EVENT(SNEEDACITY_DLL_API,
EVT_LABELTRACK_SELECTION, LabelTrackEvent);
#endif