forked from Sneeds-Feed-and-Seed/sneedacity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZoomInfo.cpp
126 lines (101 loc) · 2.82 KB
/
ZoomInfo.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
/**********************************************************************
Sneedacity: A Digital Audio Editor
ZoomInfo.cpp
Paul Licameli split from ViewInfo.cpp
**********************************************************************/
#include "ZoomInfo.h"
#include "prefs/GUISettings.h"
namespace {
static const double gMaxZoom = 6000000;
static const double gMinZoom = 0.001;
}
ZoomInfo::ZoomInfo(double start, double pixelsPerSecond)
: vpos(0)
, h(start)
, zoom(pixelsPerSecond)
{
UpdatePrefs();
}
ZoomInfo::~ZoomInfo()
{
}
void ZoomInfo::UpdatePrefs()
{
dBr = gPrefs->Read(ENV_DB_KEY, ENV_DB_RANGE);
}
/// Converts a position (mouse X coordinate) to
/// project time, in seconds. Needs the left edge of
/// the track as an additional parameter.
double ZoomInfo::PositionToTime(wxInt64 position,
wxInt64 origin
, bool // ignoreFisheye
) const
{
return h + (position - origin) / zoom;
}
/// STM: Converts a project time to screen x position.
wxInt64 ZoomInfo::TimeToPosition(double projectTime,
wxInt64 origin
, bool // ignoreFisheye
) const
{
double t = 0.5 + zoom * (projectTime - h) + origin ;
if( t < wxINT64_MIN )
return wxINT64_MIN;
if( t > wxINT64_MAX )
return wxINT64_MAX;
t = floor( t );
return t;
}
// This always ignores the fisheye. Use with caution!
// You should prefer to call TimeToPosition twice, for endpoints, and take the difference!
double ZoomInfo::TimeRangeToPixelWidth(double timeRange) const
{
return timeRange * zoom;
}
bool ZoomInfo::ZoomInAvailable() const
{
return zoom < gMaxZoom;
}
bool ZoomInfo::ZoomOutAvailable() const
{
return zoom > gMinZoom;
}
double ZoomInfo::GetZoom( ) const { return zoom;};
double ZoomInfo::GetMaxZoom( ) { return gMaxZoom;};
double ZoomInfo::GetMinZoom( ) { return gMinZoom;};
void ZoomInfo::SetZoom(double pixelsPerSecond)
{
zoom = std::max(gMinZoom, std::min(gMaxZoom, pixelsPerSecond));
// DA: Avoids stuck in snap-to
#ifdef EXPERIMENTAL_DA
// Disable snapping if user zooms in a long way.
// Helps stop users be trapped in snap-to.
// The level chosen is in sample viewing range with samples
// still quite close together.
if( zoom > (gMaxZoom * 0.06 ))
{
SneedacityProject * project = GetActiveProject();
if( project )
project->OnSnapToOff();
}
#endif
}
void ZoomInfo::ZoomBy(double multiplier)
{
SetZoom(zoom * multiplier);
}
void ZoomInfo::FindIntervals
(double /*rate*/, Intervals &results, wxInt64 width, wxInt64 origin) const
{
results.clear();
results.reserve(2);
const wxInt64 rightmost(origin + (0.5 + width));
wxASSERT(origin <= rightmost);
{
results.push_back(Interval(origin, zoom, false));
}
if (origin < rightmost)
results.push_back(Interval(rightmost, 0, false));
wxASSERT(!results.empty() && results[0].position == origin);
}