comparison base/ZoomLevel.h @ 1550:1ae6a19464a7 zoom-double

Messing with non-integer zoom ratios. But I don't think this is going anywhere as it stands
author Chris Cannam
date Mon, 08 Oct 2018 13:39:40 +0100
parents 8f9e9cff141d
children
comparison
equal deleted inserted replaced
1547:32400727bcbd 1550:1ae6a19464a7
29 FramesPerPixel, // zoomed out (as in classic SV) 29 FramesPerPixel, // zoomed out (as in classic SV)
30 PixelsPerFrame // zoomed in beyond 1-1 (interpolating the waveform) 30 PixelsPerFrame // zoomed in beyond 1-1 (interpolating the waveform)
31 }; 31 };
32 32
33 Zone zone; 33 Zone zone;
34 int level; 34 double level;
35 35
36 ZoomLevel() : zone(FramesPerPixel), level(1) { } 36 ZoomLevel() : zone(FramesPerPixel), level(1) { }
37 ZoomLevel(Zone z, int lev) : zone(z), level(lev) { } 37 ZoomLevel(Zone z, double lev) : zone(z), level(lev) { }
38 38
39 bool operator<(const ZoomLevel &other) const { 39 bool operator<(const ZoomLevel &other) const {
40 if (zone == FramesPerPixel) { 40 if (zone == FramesPerPixel) {
41 if (other.zone == zone) { 41 if (other.zone == zone) {
42 return level < other.level; 42 return level < other.level;
105 /** Return a ZoomLevel that approximates the given ratio of pixels 105 /** Return a ZoomLevel that approximates the given ratio of pixels
106 * to frames. 106 * to frames.
107 */ 107 */
108 static ZoomLevel fromRatio(int pixels, sv_frame_t frames) { 108 static ZoomLevel fromRatio(int pixels, sv_frame_t frames) {
109 if (pixels < frames) { 109 if (pixels < frames) {
110 return { FramesPerPixel, int(round(double(frames)/pixels)) }; 110 return { FramesPerPixel, round(double(frames)/pixels) };
111 } else { 111 } else {
112 int r = int(round(pixels/double(frames))); 112 double r = round(pixels/double(frames));
113 if (r > 1) { 113 if (r > 1) {
114 return { PixelsPerFrame, r }; 114 return { PixelsPerFrame, r };
115 } else { 115 } else {
116 return { FramesPerPixel, 1 }; 116 return { FramesPerPixel, 1 };
117 } 117 }