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
13#include <cassert>
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{
26}
27
29{
30}
31
36 int64 origin
37 , bool // ignoreFisheye
38) const
39{
40 return h + (position - origin) / zoom;
41}
42
43
45auto ZoomInfo::TimeToPosition(double projectTime,
46 int64 origin
47 , bool // ignoreFisheye
48) const -> int64
49{
50 double t = 0.5 + zoom * (projectTime - h) + origin ;
51 if( t < INT64_MIN )
52 return INT64_MIN;
53 if( t > INT64_MAX )
54 return INT64_MAX;
55 t = floor( t );
56 return t;
57}
58
59// This always ignores the fisheye. Use with caution!
60// You should prefer to call TimeToPosition twice, for endpoints, and take the difference!
61double ZoomInfo::TimeRangeToPixelWidth(double timeRange) const
62{
63 return timeRange * zoom;
64}
65
67{
68 return zoom < gMaxZoom;
69}
70
72{
73 return zoom > gMinZoom;
74}
75
76double ZoomInfo::GetZoom( ) const { return zoom;};
77double ZoomInfo::GetMaxZoom( ) { return gMaxZoom;};
78double ZoomInfo::GetMinZoom( ) { return gMinZoom;};
79
80void ZoomInfo::SetZoom(double pixelsPerSecond)
81{
82 zoom = std::max(gMinZoom, std::min(gMaxZoom, pixelsPerSecond));
83// DA: Avoids stuck in snap-to
84#ifdef EXPERIMENTAL_DA
85 // Disable snapping if user zooms in a long way.
86 // Helps stop users be trapped in snap-to.
87 // The level chosen is in sample viewing range with samples
88 // still quite close together.
89 if( zoom > (gMaxZoom * 0.06 ))
90 {
92 if( project )
93 project->OnSnapToOff();
94 }
95#endif
96}
97
98void ZoomInfo::ZoomBy(double multiplier)
99{
100 SetZoom(zoom * multiplier);
101}
102
104 (double /*rate*/, Intervals &results, int64 width, int64 origin) const
105{
106 results.clear();
107 results.reserve(2);
108
109 const int64 rightmost(origin + (0.5 + width));
110 assert(origin <= rightmost);
111 {
112 results.push_back(Interval(origin, zoom, false));
113 }
114
115 if (origin < rightmost)
116 results.push_back(Interval(rightmost, 0, false));
117 assert(!results.empty() && results[0].position == origin);
118}
AUDACITY_DLL_API std::weak_ptr< AudacityProject > GetActiveProject()
int min(int a, int b)
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
double PositionToTime(int64 position, int64 origin=0, bool ignoreFisheye=false) const
Definition: ZoomInfo.cpp:35
void FindIntervals(double rate, Intervals &results, int64 width, int64 origin=0) const
Definition: ZoomInfo.cpp:104
bool ZoomInAvailable() const
Definition: ZoomInfo.cpp:66
double TimeRangeToPixelWidth(double timeRange) const
Definition: ZoomInfo.cpp:61
std::vector< Interval > Intervals
Definition: ZoomInfo.h:136
double zoom
Definition: ZoomInfo.h:55
int64 TimeToPosition(double time, int64 origin=0, bool ignoreFisheye=false) const
STM: Converts a project time to screen x position.
Definition: ZoomInfo.cpp:45
static double GetMaxZoom()
Definition: ZoomInfo.cpp:77
ZoomInfo(double start, double pixelsPerSecond)
Definition: ZoomInfo.cpp:21
std::int64_t int64
Definition: ZoomInfo.h:41
bool ZoomOutAvailable() const
Definition: ZoomInfo.cpp:71
double h
Definition: ZoomInfo.h:52
~ZoomInfo()
Definition: ZoomInfo.cpp:28
double GetZoom() const
Definition: ZoomInfo.cpp:76
static double GetMinZoom()
Definition: ZoomInfo.cpp:78
void SetZoom(double pixelsPerSecond)
Definition: ZoomInfo.cpp:80
void ZoomBy(double multiplier)
Definition: ZoomInfo.cpp:98
static const double gMinZoom
Definition: ZoomInfo.cpp:18
static const double gMaxZoom
Definition: ZoomInfo.cpp:17