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 #include "ZoomInfo.h"
12 #include "Decibels.h"
13 
14 namespace {
15 static const double gMaxZoom = 6000000;
16 static const double gMinZoom = 0.001;
17 }
18 
19 ZoomInfo::ZoomInfo(double start, double pixelsPerSecond)
20  : vpos(0)
21  , h(start)
22  , zoom(pixelsPerSecond)
23 {
24  UpdatePrefs();
25 }
26 
28 {
29 }
30 
32 {
34 }
35 
39 double ZoomInfo::PositionToTime(wxInt64 position,
40  wxInt64 origin
41  , bool // ignoreFisheye
42 ) const
43 {
44  return h + (position - origin) / zoom;
45 }
46 
47 
49 wxInt64 ZoomInfo::TimeToPosition(double projectTime,
50  wxInt64 origin
51  , bool // ignoreFisheye
52 ) const
53 {
54  double t = 0.5 + zoom * (projectTime - h) + origin ;
55  if( t < wxINT64_MIN )
56  return wxINT64_MIN;
57  if( t > wxINT64_MAX )
58  return wxINT64_MAX;
59  t = floor( t );
60  return t;
61 }
62 
63 // This always ignores the fisheye. Use with caution!
64 // You should prefer to call TimeToPosition twice, for endpoints, and take the difference!
65 double ZoomInfo::TimeRangeToPixelWidth(double timeRange) const
66 {
67  return timeRange * zoom;
68 }
69 
71 {
72  return zoom < gMaxZoom;
73 }
74 
76 {
77  return zoom > gMinZoom;
78 }
79 
80 double ZoomInfo::GetZoom( ) const { return zoom;};
81 double ZoomInfo::GetMaxZoom( ) { return gMaxZoom;};
82 double ZoomInfo::GetMinZoom( ) { return gMinZoom;};
83 
84 void ZoomInfo::SetZoom(double pixelsPerSecond)
85 {
86  zoom = std::max(gMinZoom, std::min(gMaxZoom, pixelsPerSecond));
87 // DA: Avoids stuck in snap-to
88 #ifdef EXPERIMENTAL_DA
89  // Disable snapping if user zooms in a long way.
90  // Helps stop users be trapped in snap-to.
91  // The level chosen is in sample viewing range with samples
92  // still quite close together.
93  if( zoom > (gMaxZoom * 0.06 ))
94  {
95  AudacityProject * project = GetActiveProject();
96  if( project )
97  project->OnSnapToOff();
98  }
99 #endif
100 }
101 
102 void ZoomInfo::ZoomBy(double multiplier)
103 {
104  SetZoom(zoom * multiplier);
105 }
106 
108  (double /*rate*/, Intervals &results, wxInt64 width, wxInt64 origin) const
109 {
110  results.clear();
111  results.reserve(2);
112 
113  const wxInt64 rightmost(origin + (0.5 + width));
114  wxASSERT(origin <= rightmost);
115  {
116  results.push_back(Interval(origin, zoom, false));
117  }
118 
119  if (origin < rightmost)
120  results.push_back(Interval(rightmost, 0, false));
121  wxASSERT(!results.empty() && results[0].position == origin);
122 }
ZoomInfo::GetMinZoom
static double GetMinZoom()
Definition: ZoomInfo.cpp:82
ZoomInfo::GetZoom
double GetZoom() const
Definition: ZoomInfo.cpp:80
anonymous_namespace{ZoomInfo.cpp}::gMaxZoom
static const double gMaxZoom
Definition: ZoomInfo.cpp:15
ZoomInfo::UpdatePrefs
void UpdatePrefs() override
Definition: ZoomInfo.cpp:31
ZoomInfo::ZoomInfo
ZoomInfo(double start, double pixelsPerSecond)
Definition: ZoomInfo.cpp:19
GetActiveProject
AUDACITY_DLL_API std::weak_ptr< AudacityProject > GetActiveProject()
Definition: ActiveProject.cpp:24
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:49
ZoomInfo::Interval
Definition: ZoomInfo.h:141
ZoomInfo::GetMaxZoom
static double GetMaxZoom()
Definition: ZoomInfo.cpp:81
Setting::Read
bool Read(T *pVar) const
overload of Read returning a boolean that is true if the value was previously defined *‍/
Definition: Prefs.h:128
anonymous_namespace{ZoomInfo.cpp}::gMinZoom
static const double gMinZoom
Definition: ZoomInfo.cpp:16
ZoomInfo.h
ZoomInfo::ZoomInAvailable
bool ZoomInAvailable() const
Definition: ZoomInfo.cpp:70
ZoomInfo::ZoomOutAvailable
bool ZoomOutAvailable() const
Definition: ZoomInfo.cpp:75
ZoomInfo::SetZoom
void SetZoom(double pixelsPerSecond)
Definition: ZoomInfo.cpp:84
ZoomInfo::~ZoomInfo
~ZoomInfo()
Definition: ZoomInfo.cpp:27
ZoomInfo::ZoomBy
void ZoomBy(double multiplier)
Definition: ZoomInfo.cpp:102
Decibels.h
DecibelScaleCutoff
IntSetting DecibelScaleCutoff
Negation of this value is the lowest dB level that should be shown in dB scales.
Definition: Decibels.cpp:12
ZoomInfo::FindIntervals
void FindIntervals(double rate, Intervals &results, wxInt64 width, wxInt64 origin=0) const
Definition: ZoomInfo.cpp:108
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:92
ZoomInfo::zoom
double zoom
Definition: ZoomInfo.h:63
ZoomInfo::Intervals
std::vector< Interval > Intervals
Definition: ZoomInfo.h:146
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:39
ZoomInfo::TimeRangeToPixelWidth
double TimeRangeToPixelWidth(double timeRange) const
Definition: ZoomInfo.cpp:65