Mercurial > hg > svcore
comparison base/BaseTypes.h @ 1324:d4a28d1479a8 zoom
Some hackery toward having a zoomlevel type
author | Chris Cannam |
---|---|
date | Mon, 12 Dec 2016 15:18:52 +0000 |
parents | cafd65fc411b |
children | 710e6250a401 |
comparison
equal
deleted
inserted
replaced
1323:4dbb7a7c9c28 | 1324:d4a28d1479a8 |
---|---|
10 published by the Free Software Foundation; either version 2 of the | 10 published by the Free Software Foundation; either version 2 of the |
11 License, or (at your option) any later version. See the file | 11 License, or (at your option) any later version. See the file |
12 COPYING included with this distribution for more information. | 12 COPYING included with this distribution for more information. |
13 */ | 13 */ |
14 | 14 |
15 #ifndef BASE_TYPES_H | 15 #ifndef SV_BASE_TYPES_H |
16 #define BASE_TYPES_H | 16 #define SV_BASE_TYPES_H |
17 | 17 |
18 #include <cstdint> | 18 #include <cstdint> |
19 | 19 |
20 /** Frame index, the unit of our time axis. This is signed because the | 20 /** Frame index, the unit of our time axis. This is signed because the |
21 axis conceptually extends below zero: zero represents the start of | 21 axis conceptually extends below zero: zero represents the start of |
44 or (unsigned) int types, so we might as well have a type that can | 44 or (unsigned) int types, so we might as well have a type that can |
45 represent both. Storage size isn't an issue anyway. | 45 represent both. Storage size isn't an issue anyway. |
46 */ | 46 */ |
47 typedef double sv_samplerate_t; | 47 typedef double sv_samplerate_t; |
48 | 48 |
49 | |
50 /** Display zoom level. Can be an integer number of samples per pixel, | |
51 * or an integer number of pixels per sample. | |
52 */ | |
53 struct ZoomLevel { | |
54 | |
55 enum Zone { | |
56 FramesPerPixel, // zoomed out (as in classic SV) | |
57 PixelsPerFrame // zoomed in beyond 1-1 (interpolating the waveform) | |
58 }; | |
59 Zone zone; | |
60 int level; | |
61 | |
62 bool operator<(const ZoomLevel &other) const { | |
63 if (zone == FramesPerPixel) { | |
64 if (other.zone == zone) { | |
65 return level < other.level; | |
66 } else { | |
67 return false; | |
68 } | |
69 } else { | |
70 if (other.zone == zone) { | |
71 return level > other.level; | |
72 } else { | |
73 return false; | |
74 } | |
75 } | |
76 } | |
77 | |
78 ZoomLevel incremented() const { | |
79 if (zone == FramesPerPixel) { | |
80 return { zone, level + 1 }; | |
81 } else if (level == 1) { | |
82 return { FramesPerPixel, 2 }; | |
83 } else if (level == 2) { | |
84 return { FramesPerPixel, 1 }; | |
85 } else { | |
86 return { zone, level - 1 }; | |
87 } | |
88 } | |
89 | |
90 ZoomLevel decremented() const { | |
91 if (zone == PixelsPerFrame) { | |
92 return { zone, level + 1 }; | |
93 } else if (level == 1) { | |
94 return { PixelsPerFrame, 2 }; | |
95 } else { | |
96 return { zone, level - 1 }; | |
97 } | |
98 } | |
99 }; | |
100 | |
49 #endif | 101 #endif |
50 | 102 |