forked from Sneeds-Feed-and-Seed/sneedacity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathViewInfo.cpp
248 lines (209 loc) · 5.53 KB
/
ViewInfo.cpp
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/**********************************************************************
Sneedacity: A Digital Audio Editor
ViewInfo.cpp
Paul Licameli
**********************************************************************/
#include "ViewInfo.h"
#include <algorithm>
#include "Prefs.h"
#include "Project.h"
#include "xml/XMLWriter.h"
#include "prefs/TracksBehaviorsPrefs.h"
#include "xml/XMLWriter.h"
wxDEFINE_EVENT( EVT_SELECTED_REGION_CHANGE, SelectedRegionEvent );
SelectedRegionEvent::SelectedRegionEvent(
wxEventType commandType, NotifyingSelectedRegion *pReg )
: wxEvent{ 0, commandType }
, pRegion{ pReg }
{}
wxEvent *SelectedRegionEvent::Clone() const
{
return safenew SelectedRegionEvent{ *this };
}
bool NotifyingSelectedRegion::HandleXMLAttribute
(const wxChar *attr, const wxChar *value,
const wxChar *legacyT0Name, const wxChar *legacyT1Name)
{
auto result = mRegion.HandleXMLAttribute(
attr, value, legacyT0Name, legacyT1Name );
if ( result )
Notify( true );
return result;
}
NotifyingSelectedRegion& NotifyingSelectedRegion::operator =
( const SelectedRegion &other )
{
if ( mRegion != other ) {
mRegion = other;
Notify();
}
return *this;
}
bool NotifyingSelectedRegion::setTimes(double t0, double t1)
{
bool result = false;
if ( mRegion.t0() != t0 || mRegion.t1() != t1 ) {
result = mRegion.setTimes( t0, t1 );
Notify();
}
return result;
}
bool NotifyingSelectedRegion::setT0(double t, bool maySwap)
{
bool result = false;
if ( mRegion.t0() != t ) {
result = mRegion.setT0( t, maySwap );
Notify();
}
return result;
}
bool NotifyingSelectedRegion::setT1(double t, bool maySwap)
{
bool result = false;
if ( mRegion.t1() != t ) {
result = mRegion.setT1( t, maySwap );
Notify();
}
return result;
}
void NotifyingSelectedRegion::collapseToT0()
{
if ( mRegion.t0() != mRegion.t1() ) {
mRegion.collapseToT0();
Notify();
}
}
void NotifyingSelectedRegion::collapseToT1()
{
if ( mRegion.t0() != mRegion.t1() ) {
mRegion.collapseToT1();
Notify();
}
}
void NotifyingSelectedRegion::move(double delta)
{
if (delta != 0) {
mRegion.move( delta );
Notify();
}
}
bool NotifyingSelectedRegion::setFrequencies(double f0, double f1)
{
bool result = false;
if ( mRegion.f0() != f0 || mRegion.f1() != f1 ) {
result = mRegion.setFrequencies( f0, f1 );
Notify();
}
return result;
}
bool NotifyingSelectedRegion::setF0(double f, bool maySwap)
{
bool result = false;
if ( mRegion.f0() != f ) {
result = mRegion.setF0( f, maySwap );
Notify();
}
return result;
}
bool NotifyingSelectedRegion::setF1(double f, bool maySwap)
{
bool result = false;
if ( mRegion.f1() != f ) {
result = mRegion.setF1( f, maySwap );
Notify();
}
return result;
}
void NotifyingSelectedRegion::Notify( bool delayed )
{
SelectedRegionEvent evt{ EVT_SELECTED_REGION_CHANGE, this };
if ( delayed )
QueueEvent( evt.Clone() );
else
ProcessEvent( evt );
}
static const SneedacityProject::AttachedObjects::RegisteredFactory key{
[]( SneedacityProject &project ) {
return std::make_unique<ViewInfo>(0.0, 1.0, ZoomInfo::GetDefaultZoom());
}
};
ViewInfo &ViewInfo::Get( SneedacityProject &project )
{
return project.AttachedObjects::Get< ViewInfo >( key );
}
const ViewInfo &ViewInfo::Get( const SneedacityProject &project )
{
return Get( const_cast< SneedacityProject & >( project ) );
}
ViewInfo::ViewInfo(double start, double screenDuration, double pixelsPerSecond)
: ZoomInfo(start, pixelsPerSecond)
, selectedRegion()
, total(screenDuration)
, sbarH(0)
, sbarScreen(1)
, sbarTotal(1)
, sbarScale(1.0)
, scrollStep(16)
, bUpdateTrackIndicator(true)
, bScrollBeyondZero(false)
{
UpdatePrefs();
}
void ViewInfo::UpdateSelectedPrefs( int id )
{
if (id == UpdateScrollPrefsID())
gPrefs->Read(wxT("/GUI/AutoScroll"), &bUpdateTrackIndicator,
true);
ZoomInfo::UpdateSelectedPrefs( id );
}
void ViewInfo::UpdatePrefs()
{
ZoomInfo::UpdatePrefs();
#ifdef EXPERIMENTAL_SCROLLING_LIMITS
gPrefs->Read(TracksBehaviorsPrefs::ScrollingPreferenceKey(), &bScrollBeyondZero,
TracksBehaviorsPrefs::ScrollingPreferenceDefault());
#endif
gPrefs->Read(wxT("/GUI/AdjustSelectionEdges"), &bAdjustSelectionEdges,
true);
UpdateSelectedPrefs( UpdateScrollPrefsID() );
}
void ViewInfo::SetBeforeScreenWidth(wxInt64 beforeWidth, wxInt64 screenWidth, double lowerBoundTime)
{
h =
std::max(lowerBoundTime,
std::min(total - screenWidth / zoom,
beforeWidth / zoom));
}
void ViewInfo::WriteXMLAttributes(XMLWriter &xmlFile) const
// may throw
{
selectedRegion.WriteXMLAttributes(xmlFile, wxT("sel0"), wxT("sel1"));
xmlFile.WriteAttr(wxT("vpos"), vpos);
xmlFile.WriteAttr(wxT("h"), h, 10);
xmlFile.WriteAttr(wxT("zoom"), zoom, 10);
}
bool ViewInfo::ReadXMLAttribute(const wxChar *attr, const wxChar *value)
{
if (selectedRegion.HandleXMLAttribute(attr, value, wxT("sel0"), wxT("sel1")))
return true;
if (!wxStrcmp(attr, wxT("vpos"))) {
long longVpos;
wxString(value).ToLong(&longVpos);
vpos = (int)(longVpos);
return true;
}
if (!wxStrcmp(attr, wxT("h"))) {
Internat::CompatibleToDouble(value, &h);
return true;
}
if (!wxStrcmp(attr, wxT("zoom"))) {
Internat::CompatibleToDouble(value, &zoom);
return true;
}
return false;
}
int ViewInfo::UpdateScrollPrefsID()
{
static int value = wxNewId();
return value;
}