forked from Sneeds-Feed-and-Seed/sneedacity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZoomInfo.h
182 lines (141 loc) · 5.57 KB
/
ZoomInfo.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
/**********************************************************************
Sneedacity: A Digital Audio Editor
ZoomInfo.h
Paul Licameli split from ViewInfo.h
**********************************************************************/
#ifndef __SNEEDACITY_ZOOM_INFO__
#define __SNEEDACITY_ZOOM_INFO__
#include "ClientData.h" // to inherit
#include "Prefs.h" // to inherit
#ifdef __GNUC__
#define CONST
#else
#define CONST const
#endif
class SneedacityProject;
// See big pictorial comment in TrackPanel.cpp for explanation of these numbers
enum : int {
// Constants related to x coordinates in the track panel
kBorderThickness = 1,
kShadowThickness = 1,
kLeftInset = 4,
kRightInset = kLeftInset,
kLeftMargin = kLeftInset + kBorderThickness,
kRightMargin = kRightInset + kShadowThickness + kBorderThickness,
kTrackInfoWidth = 100 - kLeftMargin,
};
// The subset of ViewInfo information (other than selection)
// that is sufficient for purposes of TrackArtist,
// and for computing conversions between track times and pixel positions.
class SNEEDACITY_DLL_API ZoomInfo /* not final */
// Note that ViewInfo inherits from ZoomInfo but there are no virtual functions.
// That's okay if we pass always by reference and never copy, suffering "slicing."
: public ClientData::Base
, protected PrefsListener
{
public:
ZoomInfo(double start, double pixelsPerSecond);
~ZoomInfo();
// Be sure we don't slice
ZoomInfo(const ZoomInfo&) PROHIBITED;
ZoomInfo& operator= (const ZoomInfo&) PROHIBITED;
void UpdatePrefs() override;
int vpos; // vertical scroll pos
double h; // h pos in secs
protected:
double zoom; // pixels per second
public:
float dBr; // decibel scale range
// do NOT use this once to convert a pixel width to a duration!
// Instead, call twice to convert start and end times,
// and take the difference.
// origin specifies the pixel corresponding to time h
double PositionToTime(wxInt64 position,
wxInt64 origin = 0
, bool ignoreFisheye = false
) const;
// do NOT use this once to convert a duration to a pixel width!
// Instead, call twice to convert start and end positions,
// and take the difference.
// origin specifies the pixel corresponding to time h
wxInt64 TimeToPosition(double time,
wxInt64 origin = 0
, bool ignoreFisheye = false
) const;
// This always ignores the fisheye. Use with caution!
// You should prefer to call TimeToPosition twice, for endpoints, and take the difference!
double TimeRangeToPixelWidth(double timeRange) const;
double OffsetTimeByPixels(double time, wxInt64 offset, bool ignoreFisheye = false) const
{
return PositionToTime(offset + TimeToPosition(time, ignoreFisheye), ignoreFisheye);
}
int GetWidth() const { return mWidth; }
void SetWidth( int width ) { mWidth = width; }
int GetVRulerWidth() const { return mVRulerWidth; }
void SetVRulerWidth( int width ) { mVRulerWidth = width; }
int GetVRulerOffset() const { return kTrackInfoWidth + kLeftMargin; }
int GetLabelWidth() const { return GetVRulerOffset() + GetVRulerWidth(); }
int GetLeftOffset() const { return GetLabelWidth() + 1;}
int GetTracksUsableWidth() const
{
return
std::max( 0, GetWidth() - ( GetLeftOffset() + kRightMargin ) );
}
// Returns the time corresponding to the pixel column one past the track area
// (ignoring any fisheye)
double GetScreenEndTime() const
{
auto width = GetTracksUsableWidth();
return PositionToTime(width, 0, true);
}
bool ZoomInAvailable() const;
bool ZoomOutAvailable() const;
static double GetDefaultZoom()
{ return 44100.0 / 512.0; }
// Limits zoom to certain bounds
void SetZoom(double pixelsPerSecond);
// This function should not be used to convert positions to times and back
// Use TimeToPosition and PositionToTime and OffsetTimeByPixels instead
double GetZoom() const;
static double GetMaxZoom( );
static double GetMinZoom( );
// Limits zoom to certain bounds
// multipliers above 1.0 zoom in, below out
void ZoomBy(double multiplier);
struct Interval {
CONST wxInt64 position; CONST double averageZoom; CONST bool inFisheye;
Interval(wxInt64 p, double z, bool i)
: position(p), averageZoom(z), inFisheye(i) {}
};
typedef std::vector<Interval> Intervals;
// Find an increasing sequence of pixel positions. Each is the start
// of an interval, or is the end position.
// Each of the disjoint intervals should be drawn
// separately.
// It is guaranteed that there is at least one entry and the position of the
// first entry equals origin.
// @param origin specifies the pixel position corresponding to time ViewInfo::h.
void FindIntervals
(double rate, Intervals &results, wxInt64 width, wxInt64 origin = 0) const;
enum FisheyeState {
HIDDEN,
PINNED,
NUM_STATES,
};
FisheyeState GetFisheyeState() const
{ return HIDDEN; } // stub
// Return true if the mouse position is anywhere in the fisheye
// origin specifies the pixel corresponding to time h
bool InFisheye(wxInt64 /*position*/, wxInt64 WXUNUSED(origin = 0)) const
{return false;} // stub
// These accessors ignore the fisheye hiding state.
// Inclusive:
wxInt64 GetFisheyeLeftBoundary(wxInt64 WXUNUSED(origin = 0)) const
{return 0;} // stub
// Exclusive:
wxInt64 GetFisheyeRightBoundary(wxInt64 WXUNUSED(origin = 0)) const
{return 0;} // stub
int mWidth{ 0 };
int mVRulerWidth{ 36 };
};
#endif