forked from Sneeds-Feed-and-Seed/sneedacity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathViewInfo.h
234 lines (178 loc) · 6.47 KB
/
ViewInfo.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
229
230
231
232
233
234
/**********************************************************************
Sneedacity: A Digital Audio Editor
ViewInfo.h
Dominic Mazzoni
**********************************************************************/
#ifndef __SNEEDACITY_VIEWINFO__
#define __SNEEDACITY_VIEWINFO__
#include <utility>
#include <vector>
#include <wx/event.h> // inherit wxEvtHandler
#include <wx/weakref.h> // member variable
#include "SelectedRegion.h"
#include <memory>
#include "ZoomInfo.h" // to inherit
class NotifyingSelectedRegion;
struct SelectedRegionEvent : public wxEvent
{
SelectedRegionEvent( wxEventType commandType,
NotifyingSelectedRegion *pRegion );
wxEvent *Clone() const override;
wxWeakRef< NotifyingSelectedRegion > pRegion;
};
// To do: distinguish time changes from frequency changes perhaps?
wxDECLARE_EXPORTED_EVENT( SNEEDACITY_DLL_API,
EVT_SELECTED_REGION_CHANGE, SelectedRegionEvent );
// This heavyweight wrapper of the SelectedRegion structure emits events
// on mutating operations, that other classes can listen for.
class SNEEDACITY_DLL_API NotifyingSelectedRegion : public wxEvtHandler
{
public:
// Expose SelectedRegion's const accessors
double t0 () const { return mRegion.t0(); }
double t1 () const { return mRegion.t1(); }
double f0 () const { return mRegion.f0(); }
double f1 () const { return mRegion.f1(); }
double fc () const { return mRegion.fc(); }
bool isPoint() const { return mRegion.isPoint(); }
double duration() const { return mRegion.duration(); }
// Writing and reading of persistent fields -- the read is mutating but
// does not emit events
void WriteXMLAttributes
(XMLWriter &xmlFile,
const wxChar *legacyT0Name, const wxChar *legacyT1Name) const
{ mRegion.WriteXMLAttributes(xmlFile, legacyT0Name, legacyT1Name); }
bool HandleXMLAttribute
(const wxChar *attr, const wxChar *value,
const wxChar *legacyT0Name, const wxChar *legacyT1Name);
// const-only access allows assignment from this into a SelectedRegion
// or otherwise passing it into a function taking const SelectedRegion&
operator const SelectedRegion & () const { return mRegion; }
// These are the event-emitting operations
NotifyingSelectedRegion& operator = ( const SelectedRegion &other );
// Returns true iff the bounds got swapped
bool setTimes(double t0, double t1);
// Returns true iff the bounds got swapped
bool setT0(double t, bool maySwap = true);
// Returns true iff the bounds got swapped
bool setT1(double t, bool maySwap = true);
void collapseToT0();
void collapseToT1();
void move(double delta);
// Returns true iff the bounds got swapped
bool setFrequencies(double f0, double f1);
// Returns true iff the bounds got swapped
bool setF0(double f, bool maySwap = true);
// Returns true iff the bounds got swapped
bool setF1(double f, bool maySwap = true);
private:
void Notify( bool delayed = false );
SelectedRegion mRegion;
};
// See big pictorial comment in TrackPanel.cpp for explanation of these numbers
enum : int {
// constants related to y coordinates in the track panel
kTopInset = 4,
kTopMargin = kTopInset + kBorderThickness,
kBottomMargin = kShadowThickness + kBorderThickness,
kSeparatorThickness = kBottomMargin + kTopMargin,
};
enum : int {
kTrackInfoBtnSize = 18, // widely used dimension, usually height
kTrackInfoSliderHeight = 25,
kTrackInfoSliderWidth = 84,
kTrackInfoSliderAllowance = 5,
kTrackInfoSliderExtra = 5,
};
class PlayRegion
{
public:
PlayRegion() = default;
PlayRegion( const PlayRegion& ) = delete;
PlayRegion &operator= ( const PlayRegion &that )
{
mLocked = that.mLocked;
// Guarantee the equivalent un-swapped order of endpoints
mStart = that.GetStart();
mEnd = that.GetEnd();
return *this;
}
bool Locked() const { return mLocked; }
void SetLocked( bool locked ) { mLocked = locked; }
bool Empty() const { return GetStart() == GetEnd(); }
double GetStart() const
{
if ( mEnd < 0 )
return mStart;
else
return std::min( mStart, mEnd );
}
double GetEnd() const
{
if ( mStart < 0 )
return mEnd;
else
return std::max( mStart, mEnd );
}
void SetStart( double start ) { mStart = start; }
void SetEnd( double end ) { mEnd = end; }
void SetTimes( double start, double end ) { mStart = start, mEnd = end; }
void Order()
{
if ( mStart >= 0 && mEnd >= 0 && mStart > mEnd)
std::swap( mStart, mEnd );
}
private:
// Times:
double mStart{ -1.0 };
double mEnd{ -1.0 };
bool mLocked{ false };
};
class SNEEDACITY_DLL_API ViewInfo final
: public wxEvtHandler, public ZoomInfo
{
public:
static ViewInfo &Get( SneedacityProject &project );
static const ViewInfo &Get( const SneedacityProject &project );
ViewInfo(double start, double screenDuration, double pixelsPerSecond);
ViewInfo( const ViewInfo & ) PROHIBITED;
ViewInfo &operator=( const ViewInfo & ) PROHIBITED;
int GetHeight() const { return mHeight; }
void SetHeight( int height ) { mHeight = height; }
static int UpdateScrollPrefsID();
void UpdatePrefs() override;
void UpdateSelectedPrefs( int id ) override;
double GetBeforeScreenWidth() const
{
return h * zoom;
}
void SetBeforeScreenWidth(wxInt64 beforeWidth, wxInt64 screenWidth, double lowerBoundTime = 0.0);
double GetTotalWidth() const
{ return total * zoom; }
// Current selection
NotifyingSelectedRegion selectedRegion;
PlayRegion playRegion;
// Scroll info
double total; // total width in secs
// Current horizontal scroll bar positions, in pixels
wxInt64 sbarH;
wxInt64 sbarScreen;
wxInt64 sbarTotal;
// Internal wxScrollbar positions are only int in range, so multiply
// the above values with the following member to get the actual
// scroll bar positions as reported by the horizontal wxScrollbar's members
// i.e. units are scroll increments per pixel
double sbarScale;
// Vertical scroll step
int scrollStep;
// Other stuff, mainly states (true or false) related to autoscroll and
// drawing the waveform. Maybe this should be put somewhere else?
bool bUpdateTrackIndicator;
bool bScrollBeyondZero;
bool bAdjustSelectionEdges;
void WriteXMLAttributes(XMLWriter &xmlFile) const;
bool ReadXMLAttribute(const wxChar *attr, const wxChar *value);
private:
int mHeight{ 0 };
};
#endif