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 : hpos{ start }
23 , zoom{ pixelsPerSecond }
24{
25}
26
28{
29}
30
35 int64 origin
36 , bool // ignoreFisheye
37) const
38{
39 return hpos + (position - origin) / zoom;
40}
41
42
44auto ZoomInfo::TimeToPosition(double projectTime,
45 int64 origin
46 , bool // ignoreFisheye
47) const -> int64
48{
49 double t = 0.5 + zoom * (projectTime - hpos) + origin ;
50 if( t < INT64_MIN )
51 return INT64_MIN;
52 if( t > INT64_MAX )
53 return INT64_MAX;
54 t = floor( t );
55 return t;
56}
57
58// This always ignores the fisheye. Use with caution!
59// You should prefer to call TimeToPosition twice, for endpoints, and take the difference!
60double ZoomInfo::TimeRangeToPixelWidth(double timeRange) const
61{
62 return timeRange * zoom;
63}
64
66{
67 return zoom < gMaxZoom;
68}
69
71{
72 return zoom > gMinZoom;
73}
74
75double ZoomInfo::GetZoom( ) const { return zoom;};
76
77double ZoomInfo::GetAbsoluteOffset(double offset) const
78{
79 return std::floor(0.5 + hpos * zoom + offset);
80}
81
83{
84 return gMaxZoom;
85};
86double ZoomInfo::GetMinZoom( ) { return gMinZoom;};
87
88void ZoomInfo::SetZoom(double pixelsPerSecond)
89{
90 zoom = std::max(gMinZoom, std::min(gMaxZoom, pixelsPerSecond));
91}
92
93void ZoomInfo::ZoomBy(double multiplier)
94{
95 SetZoom(zoom * multiplier);
96}
97
100{
101 ZoomInfo::Intervals results;
102 results.reserve(2);
103
104 const int64 rightmost(origin + (0.5 + width));
105 assert(origin <= rightmost);
106 {
107 results.push_back(Interval(origin, zoom, false));
108 }
109
110 if (origin < rightmost)
111 results.push_back(Interval(rightmost, 0, false));
112 assert(!results.empty() && results[0].position == origin);
113 return results;
114}
int min(int a, int b)
double GetAbsoluteOffset(double offset) const
Definition: ZoomInfo.cpp:77
double PositionToTime(int64 position, int64 origin=0, bool ignoreFisheye=false) const
Definition: ZoomInfo.cpp:34
bool ZoomInAvailable() const
Definition: ZoomInfo.cpp:65
double TimeRangeToPixelWidth(double timeRange) const
Definition: ZoomInfo.cpp:60
Intervals FindIntervals(int64 width, int64 origin=0) const
Definition: ZoomInfo.cpp:99
std::vector< Interval > Intervals
Definition: ZoomInfo.h:144
double zoom
pixels per second
Definition: ZoomInfo.h:58
int64 TimeToPosition(double time, int64 origin=0, bool ignoreFisheye=false) const
STM: Converts a project time to screen x position.
Definition: ZoomInfo.cpp:44
static double GetMaxZoom()
Definition: ZoomInfo.cpp:82
ZoomInfo(double start, double pixelsPerSecond)
Definition: ZoomInfo.cpp:21
std::int64_t int64
Definition: ZoomInfo.h:41
bool ZoomOutAvailable() const
Definition: ZoomInfo.cpp:70
~ZoomInfo()
Definition: ZoomInfo.cpp:27
double GetZoom() const
Definition: ZoomInfo.cpp:75
double hpos
Leftmost visible timeline position in seconds.
Definition: ZoomInfo.h:54
static double GetMinZoom()
Definition: ZoomInfo.cpp:86
void SetZoom(double pixelsPerSecond)
Definition: ZoomInfo.cpp:88
void ZoomBy(double multiplier)
Definition: ZoomInfo.cpp:93
static const double gMinZoom
Definition: ZoomInfo.cpp:18
static const double gMaxZoom
Definition: ZoomInfo.cpp:17