Audacity  3.0.3
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 
12 #include "ZoomInfo.h"
13 
14 
15 
16 #include "prefs/GUISettings.h"
17 
18 namespace {
19 static const double gMaxZoom = 6000000;
20 static const double gMinZoom = 0.001;
21 }
22 
23 ZoomInfo::ZoomInfo(double start, double pixelsPerSecond)
24  : vpos(0)
25  , h(start)
26  , zoom(pixelsPerSecond)
27 {
28  UpdatePrefs();
29 }
30 
32 {
33 }
34 
36 {
38 }
39 
43 double ZoomInfo::PositionToTime(wxInt64 position,
44  wxInt64 origin
45  , bool // ignoreFisheye
46 ) const
47 {
48  return h + (position - origin) / zoom;
49 }
50 
51 
53 wxInt64 ZoomInfo::TimeToPosition(double projectTime,
54  wxInt64 origin
55  , bool // ignoreFisheye
56 ) const
57 {
58  double t = 0.5 + zoom * (projectTime - h) + origin ;
59  if( t < wxINT64_MIN )
60  return wxINT64_MIN;
61  if( t > wxINT64_MAX )
62  return wxINT64_MAX;
63  t = floor( t );
64  return t;
65 }
66 
67 // This always ignores the fisheye. Use with caution!
68 // You should prefer to call TimeToPosition twice, for endpoints, and take the difference!
69 double ZoomInfo::TimeRangeToPixelWidth(double timeRange) const
70 {
71  return timeRange * zoom;
72 }
73 
75 {
76  return zoom < gMaxZoom;
77 }
78 
80 {
81  return zoom > gMinZoom;
82 }
83 
84 double ZoomInfo::GetZoom( ) const { return zoom;};
85 double ZoomInfo::GetMaxZoom( ) { return gMaxZoom;};
86 double ZoomInfo::GetMinZoom( ) { return gMinZoom;};
87 
88 void ZoomInfo::SetZoom(double pixelsPerSecond)
89 {
90  zoom = std::max(gMinZoom, std::min(gMaxZoom, pixelsPerSecond));
91 // DA: Avoids stuck in snap-to
92 #ifdef EXPERIMENTAL_DA
93  // Disable snapping if user zooms in a long way.
94  // Helps stop users be trapped in snap-to.
95  // The level chosen is in sample viewing range with samples
96  // still quite close together.
97  if( zoom > (gMaxZoom * 0.06 ))
98  {
99  AudacityProject * project = GetActiveProject();
100  if( project )
101  project->OnSnapToOff();
102  }
103 #endif
104 }
105 
106 void ZoomInfo::ZoomBy(double multiplier)
107 {
108  SetZoom(zoom * multiplier);
109 }
110 
112  (double /*rate*/, Intervals &results, wxInt64 width, wxInt64 origin) const
113 {
114  results.clear();
115  results.reserve(2);
116 
117  const wxInt64 rightmost(origin + (0.5 + width));
118  wxASSERT(origin <= rightmost);
119  {
120  results.push_back(Interval(origin, zoom, false));
121  }
122 
123  if (origin < rightmost)
124  results.push_back(Interval(rightmost, 0, false));
125  wxASSERT(!results.empty() && results[0].position == origin);
126 }
ZoomInfo::GetMinZoom
static double GetMinZoom()
Definition: ZoomInfo.cpp:86
ZoomInfo::GetZoom
double GetZoom() const
Definition: ZoomInfo.cpp:84
anonymous_namespace{ZoomInfo.cpp}::gMaxZoom
static const double gMaxZoom
Definition: ZoomInfo.cpp:19
ZoomInfo::UpdatePrefs
void UpdatePrefs() override
Definition: ZoomInfo.cpp:35
gPrefs
FileConfig * gPrefs
Definition: Prefs.cpp:68
ENV_DB_RANGE
#define ENV_DB_RANGE
Definition: GUISettings.h:16
GetActiveProject
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:107
ZoomInfo::ZoomInfo
ZoomInfo(double start, double pixelsPerSecond)
Definition: ZoomInfo.cpp:23
ZoomInfo::TimeToPosition
wxInt64 TimeToPosition(double time, wxInt64 origin=0, bool ignoreFisheye=false) const
STM: Converts a project time to screen x position.
Definition: ZoomInfo.cpp:53
ZoomInfo::Interval
Definition: ZoomInfo.h:139
ZoomInfo::GetMaxZoom
static double GetMaxZoom()
Definition: ZoomInfo.cpp:85
anonymous_namespace{ZoomInfo.cpp}::gMinZoom
static const double gMinZoom
Definition: ZoomInfo.cpp:20
ZoomInfo.h
ZoomInfo::ZoomInAvailable
bool ZoomInAvailable() const
Definition: ZoomInfo.cpp:74
ZoomInfo::ZoomOutAvailable
bool ZoomOutAvailable() const
Definition: ZoomInfo.cpp:79
ZoomInfo::SetZoom
void SetZoom(double pixelsPerSecond)
Definition: ZoomInfo.cpp:88
ZoomInfo::~ZoomInfo
~ZoomInfo()
Definition: ZoomInfo.cpp:31
ZoomInfo::ZoomBy
void ZoomBy(double multiplier)
Definition: ZoomInfo.cpp:106
ENV_DB_KEY
#define ENV_DB_KEY
Definition: GUISettings.h:15
ZoomInfo::FindIntervals
void FindIntervals(double rate, Intervals &results, wxInt64 width, wxInt64 origin=0) const
Definition: ZoomInfo.cpp:112
GUISettings.h
min
int min(int a, int b)
Definition: CompareAudioCommand.cpp:106
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:112
ZoomInfo::zoom
double zoom
Definition: ZoomInfo.h:63
ZoomInfo::Intervals
std::vector< Interval > Intervals
Definition: ZoomInfo.h:144
ZoomInfo::dBr
float dBr
Definition: ZoomInfo.h:66
ZoomInfo::h
double h
Definition: ZoomInfo.h:60
ZoomInfo::PositionToTime
double PositionToTime(wxInt64 position, wxInt64 origin=0, bool ignoreFisheye=false) const
Definition: ZoomInfo.cpp:43
ZoomInfo::TimeRangeToPixelWidth
double TimeRangeToPixelWidth(double timeRange) const
Definition: ZoomInfo.cpp:69