Audacity 3.2.0
ZoomInfo.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 ZoomInfo.cpp
6
7 Paul Licameli split from ViewInfo.cpp
8
9**********************************************************************/
10
11#include "ZoomInfo.h"
12#include "Decibels.h"
13
14#include <cmath>
15
16namespace {
17static const double gMaxZoom = 6000000;
18static const double gMinZoom = 0.001;
19}
20
21ZoomInfo::ZoomInfo(double start, double pixelsPerSecond)
22 : vpos(0)
23 , h(start)
24 , zoom(pixelsPerSecond)
25{
27}
28
30{
31}
32
34{
36}
37
41double ZoomInfo::PositionToTime(wxInt64 position,
42 wxInt64 origin
43 , bool // ignoreFisheye
44) const
45{
46 return h + (position - origin) / zoom;
47}
48
49
51wxInt64 ZoomInfo::TimeToPosition(double projectTime,
52 wxInt64 origin
53 , bool // ignoreFisheye
54) const
55{
56 double t = 0.5 + zoom * (projectTime - h) + origin ;
57 if( t < wxINT64_MIN )
58 return wxINT64_MIN;
59 if( t > wxINT64_MAX )
60 return wxINT64_MAX;
61 t = floor( t );
62 return t;
63}
64
65// This always ignores the fisheye. Use with caution!
66// You should prefer to call TimeToPosition twice, for endpoints, and take the difference!
67double ZoomInfo::TimeRangeToPixelWidth(double timeRange) const
68{
69 return timeRange * zoom;
70}
71
73{
74 return zoom < gMaxZoom;
75}
76
78{
79 return zoom > gMinZoom;
80}
81
82double ZoomInfo::GetZoom( ) const { return zoom;};
83double ZoomInfo::GetMaxZoom( ) { return gMaxZoom;};
84double ZoomInfo::GetMinZoom( ) { return gMinZoom;};
85
86void ZoomInfo::SetZoom(double pixelsPerSecond)
87{
88 zoom = std::max(gMinZoom, std::min(gMaxZoom, pixelsPerSecond));
89// DA: Avoids stuck in snap-to
90#ifdef EXPERIMENTAL_DA
91 // Disable snapping if user zooms in a long way.
92 // Helps stop users be trapped in snap-to.
93 // The level chosen is in sample viewing range with samples
94 // still quite close together.
95 if( zoom > (gMaxZoom * 0.06 ))
96 {
98 if( project )
99 project->OnSnapToOff();
100 }
101#endif
102}
103
104void ZoomInfo::ZoomBy(double multiplier)
105{
106 SetZoom(zoom * multiplier);
107}
108
110 (double /*rate*/, Intervals &results, wxInt64 width, wxInt64 origin) const
111{
112 results.clear();
113 results.reserve(2);
114
115 const wxInt64 rightmost(origin + (0.5 + width));
116 wxASSERT(origin <= rightmost);
117 {
118 results.push_back(Interval(origin, zoom, false));
119 }
120
121 if (origin < rightmost)
122 results.push_back(Interval(rightmost, 0, false));
123 wxASSERT(!results.empty() && results[0].position == origin);
124}
AUDACITY_DLL_API std::weak_ptr< AudacityProject > GetActiveProject()
int min(int a, int b)
IntSetting DecibelScaleCutoff
Negation of this value is the lowest dB level that should be shown in dB scales.
Definition: Decibels.cpp:12
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:89
bool Read(T *pVar) const
overload of Read returning a boolean that is true if the value was previously defined *‍/
Definition: Prefs.h:200
float dBr
Definition: ZoomInfo.h:66
bool ZoomInAvailable() const
Definition: ZoomInfo.cpp:72
double TimeRangeToPixelWidth(double timeRange) const
Definition: ZoomInfo.cpp:67
std::vector< Interval > Intervals
Definition: ZoomInfo.h:146
void FindIntervals(double rate, Intervals &results, wxInt64 width, wxInt64 origin=0) const
Definition: ZoomInfo.cpp:110
double zoom
Definition: ZoomInfo.h:63
static double GetMaxZoom()
Definition: ZoomInfo.cpp:83
ZoomInfo(double start, double pixelsPerSecond)
Definition: ZoomInfo.cpp:21
bool ZoomOutAvailable() const
Definition: ZoomInfo.cpp:77
void UpdatePrefs() override
Definition: ZoomInfo.cpp:33
double h
Definition: ZoomInfo.h:60
~ZoomInfo()
Definition: ZoomInfo.cpp:29
double PositionToTime(wxInt64 position, wxInt64 origin=0, bool ignoreFisheye=false) const
Definition: ZoomInfo.cpp:41
double GetZoom() const
Definition: ZoomInfo.cpp:82
static double GetMinZoom()
Definition: ZoomInfo.cpp:84
void SetZoom(double pixelsPerSecond)
Definition: ZoomInfo.cpp:86
void ZoomBy(double multiplier)
Definition: ZoomInfo.cpp:104
wxInt64 TimeToPosition(double time, wxInt64 origin=0, bool ignoreFisheye=false) const
STM: Converts a project time to screen x position.
Definition: ZoomInfo.cpp:51
static const double gMinZoom
Definition: ZoomInfo.cpp:18
static const double gMaxZoom
Definition: ZoomInfo.cpp:17