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;};
77
78double ZoomInfo::GetAbsoluteOffset(double offset) const
79{
80 return std::floor(0.5 + h * zoom + offset);
81}
82
84{
85 return gMaxZoom;
86};
87double ZoomInfo::GetMinZoom( ) { return gMinZoom;};
88
89void ZoomInfo::SetZoom(double pixelsPerSecond)
90{
91 zoom = std::max(gMinZoom, std::min(gMaxZoom, pixelsPerSecond));
92// DA: Avoids stuck in snap-to
93#ifdef EXPERIMENTAL_DA
94 // Disable snapping if user zooms in a long way.
95 // Helps stop users be trapped in snap-to.
96 // The level chosen is in sample viewing range with samples
97 // still quite close together.
98 if( zoom > (gMaxZoom * 0.06 ))
99 {
101 if( project )
102 project->OnSnapToOff();
103 }
104#endif
105}
106
107void ZoomInfo::ZoomBy(double multiplier)
108{
109 SetZoom(zoom * multiplier);
110}
111
113 Intervals& results, int64 width, int64 origin) const
114{
115 results.clear();
116 results.reserve(2);
117
118 const int64 rightmost(origin + (0.5 + width));
119 assert(origin <= rightmost);
120 {
121 results.push_back(Interval(origin, zoom, false));
122 }
123
124 if (origin < rightmost)
125 results.push_back(Interval(rightmost, 0, false));
126 assert(!results.empty() && results[0].position == origin);
127}
AUDACITY_DLL_API std::weak_ptr< AudacityProject > GetActiveProject()
int min(int a, int b)
const auto project
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 GetAbsoluteOffset(double offset) const
Definition: ZoomInfo.cpp:78
double PositionToTime(int64 position, int64 origin=0, bool ignoreFisheye=false) const
Definition: ZoomInfo.cpp:35
void FindIntervals(Intervals &results, int64 width, int64 origin=0) const
Definition: ZoomInfo.cpp:112
bool ZoomInAvailable() const
Definition: ZoomInfo.cpp:66
double TimeRangeToPixelWidth(double timeRange) const
Definition: ZoomInfo.cpp:61
std::vector< Interval > Intervals
Definition: ZoomInfo.h:141
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:83
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:87
void SetZoom(double pixelsPerSecond)
Definition: ZoomInfo.cpp:89
void ZoomBy(double multiplier)
Definition: ZoomInfo.cpp:107
static const double gMinZoom
Definition: ZoomInfo.cpp:18
static const double gMaxZoom
Definition: ZoomInfo.cpp:17