comparison base/RangeMapper.h @ 1038:cc27f35aa75c cxx11

Introducing the signed 64-bit frame index type, and fixing build failures from inclusion of -Wconversion with -Werror. Not finished yet.
author Chris Cannam
date Tue, 03 Mar 2015 15:18:24 +0000
parents 12a6140b3ae0
children 932487fe515a
comparison
equal deleted inserted replaced
1037:bf0e5944289b 1038:cc27f35aa75c
29 /** 29 /**
30 * Return the position that maps to the given value, rounding to 30 * Return the position that maps to the given value, rounding to
31 * the nearest position and clamping to the minimum and maximum 31 * the nearest position and clamping to the minimum and maximum
32 * extents of the mapper's positional range. 32 * extents of the mapper's positional range.
33 */ 33 */
34 virtual int getPositionForValue(float value) const = 0; 34 virtual int getPositionForValue(double value) const = 0;
35 35
36 /** 36 /**
37 * Return the position that maps to the given value, rounding to 37 * Return the position that maps to the given value, rounding to
38 * the nearest position, without clamping. That is, whatever 38 * the nearest position, without clamping. That is, whatever
39 * mapping function is in use will be projected even outside the 39 * mapping function is in use will be projected even outside the
40 * minimum and maximum extents of the mapper's positional 40 * minimum and maximum extents of the mapper's positional
41 * range. (The mapping outside that range is not guaranteed to be 41 * range. (The mapping outside that range is not guaranteed to be
42 * exact, except if the mapper is a linear one.) 42 * exact, except if the mapper is a linear one.)
43 */ 43 */
44 virtual int getPositionForValueUnclamped(float value) const = 0; 44 virtual int getPositionForValueUnclamped(double value) const = 0;
45 45
46 /** 46 /**
47 * Return the value mapped from the given position, clamping to 47 * Return the value mapped from the given position, clamping to
48 * the minimum and maximum extents of the mapper's value range. 48 * the minimum and maximum extents of the mapper's value range.
49 */ 49 */
50 virtual float getValueForPosition(int position) const = 0; 50 virtual double getValueForPosition(int position) const = 0;
51 51
52 /** 52 /**
53 * Return the value mapped from the given positionq, without 53 * Return the value mapped from the given positionq, without
54 * clamping. That is, whatever mapping function is in use will be 54 * clamping. That is, whatever mapping function is in use will be
55 * projected even outside the minimum and maximum extents of the 55 * projected even outside the minimum and maximum extents of the
56 * mapper's value range. (The mapping outside that range is not 56 * mapper's value range. (The mapping outside that range is not
57 * guaranteed to be exact, except if the mapper is a linear one.) 57 * guaranteed to be exact, except if the mapper is a linear one.)
58 */ 58 */
59 virtual float getValueForPositionUnclamped(int position) const = 0; 59 virtual double getValueForPositionUnclamped(int position) const = 0;
60 60
61 /** 61 /**
62 * Get the unit of the mapper's value range. 62 * Get the unit of the mapper's value range.
63 */ 63 */
64 virtual QString getUnit() const { return ""; } 64 virtual QString getUnit() const { return ""; }
73 * minpos->maxpos. minval and minpos must be less than maxval and 73 * minpos->maxpos. minval and minpos must be less than maxval and
74 * maxpos respectively. If inverted is true, the range will be 74 * maxpos respectively. If inverted is true, the range will be
75 * mapped "backwards" (minval to maxpos and maxval to minpos). 75 * mapped "backwards" (minval to maxpos and maxval to minpos).
76 */ 76 */
77 LinearRangeMapper(int minpos, int maxpos, 77 LinearRangeMapper(int minpos, int maxpos,
78 float minval, float maxval, 78 double minval, double maxval,
79 QString unit = "", bool inverted = false); 79 QString unit = "", bool inverted = false);
80 80
81 virtual int getPositionForValue(float value) const; 81 virtual int getPositionForValue(double value) const;
82 virtual int getPositionForValueUnclamped(float value) const; 82 virtual int getPositionForValueUnclamped(double value) const;
83 83
84 virtual float getValueForPosition(int position) const; 84 virtual double getValueForPosition(int position) const;
85 virtual float getValueForPositionUnclamped(int position) const; 85 virtual double getValueForPositionUnclamped(int position) const;
86 86
87 virtual QString getUnit() const { return m_unit; } 87 virtual QString getUnit() const { return m_unit; }
88 88
89 protected: 89 protected:
90 int m_minpos; 90 int m_minpos;
91 int m_maxpos; 91 int m_maxpos;
92 float m_minval; 92 double m_minval;
93 float m_maxval; 93 double m_maxval;
94 QString m_unit; 94 QString m_unit;
95 bool m_inverted; 95 bool m_inverted;
96 }; 96 };
97 97
98 class LogRangeMapper : public RangeMapper 98 class LogRangeMapper : public RangeMapper
105 * minpos must be less than maxval and maxpos respectively. If 105 * minpos must be less than maxval and maxpos respectively. If
106 * inverted is true, the range will be mapped "backwards" (minval 106 * inverted is true, the range will be mapped "backwards" (minval
107 * to maxpos and maxval to minpos). 107 * to maxpos and maxval to minpos).
108 */ 108 */
109 LogRangeMapper(int minpos, int maxpos, 109 LogRangeMapper(int minpos, int maxpos,
110 float minval, float maxval, 110 double minval, double maxval,
111 QString m_unit = "", bool inverted = false); 111 QString m_unit = "", bool inverted = false);
112 112
113 static void convertRatioMinLog(float ratio, float minlog, 113 static void convertRatioMinLog(double ratio, double minlog,
114 int minpos, int maxpos, 114 int minpos, int maxpos,
115 float &minval, float &maxval); 115 double &minval, double &maxval);
116 116
117 static void convertMinMax(int minpos, int maxpos, 117 static void convertMinMax(int minpos, int maxpos,
118 float minval, float maxval, 118 double minval, double maxval,
119 float &ratio, float &minlog); 119 double &ratio, double &minlog);
120 120
121 virtual int getPositionForValue(float value) const; 121 virtual int getPositionForValue(double value) const;
122 virtual int getPositionForValueUnclamped(float value) const; 122 virtual int getPositionForValueUnclamped(double value) const;
123 123
124 virtual float getValueForPosition(int position) const; 124 virtual double getValueForPosition(int position) const;
125 virtual float getValueForPositionUnclamped(int position) const; 125 virtual double getValueForPositionUnclamped(int position) const;
126 126
127 virtual QString getUnit() const { return m_unit; } 127 virtual QString getUnit() const { return m_unit; }
128 128
129 protected: 129 protected:
130 int m_minpos; 130 int m_minpos;
131 int m_maxpos; 131 int m_maxpos;
132 float m_ratio; 132 double m_ratio;
133 float m_minlog; 133 double m_minlog;
134 float m_maxlog; 134 double m_maxlog;
135 QString m_unit; 135 QString m_unit;
136 bool m_inverted; 136 bool m_inverted;
137 }; 137 };
138 138
139 class InterpolatingRangeMapper : public RangeMapper 139 class InterpolatingRangeMapper : public RangeMapper
140 { 140 {
141 public: 141 public:
142 typedef std::map<float, int> CoordMap; 142 typedef std::map<double, int> CoordMap;
143 143
144 /** 144 /**
145 * Given a series of (value, position) coordinate mappings, 145 * Given a series of (value, position) coordinate mappings,
146 * construct a range mapper that maps arbitrary values, in the 146 * construct a range mapper that maps arbitrary values, in the
147 * range between minimum and maximum of the provided values, onto 147 * range between minimum and maximum of the provided values, onto
160 * this is not the case. 160 * this is not the case.
161 */ 161 */
162 InterpolatingRangeMapper(CoordMap pointMappings, 162 InterpolatingRangeMapper(CoordMap pointMappings,
163 QString unit); 163 QString unit);
164 164
165 virtual int getPositionForValue(float value) const; 165 virtual int getPositionForValue(double value) const;
166 virtual int getPositionForValueUnclamped(float value) const; 166 virtual int getPositionForValueUnclamped(double value) const;
167 167
168 virtual float getValueForPosition(int position) const; 168 virtual double getValueForPosition(int position) const;
169 virtual float getValueForPositionUnclamped(int position) const; 169 virtual double getValueForPositionUnclamped(int position) const;
170 170
171 virtual QString getUnit() const { return m_unit; } 171 virtual QString getUnit() const { return m_unit; }
172 172
173 protected: 173 protected:
174 CoordMap m_mappings; 174 CoordMap m_mappings;
175 std::map<int, float> m_reverse; 175 std::map<int, double> m_reverse;
176 QString m_unit; 176 QString m_unit;
177 177
178 template <typename T> 178 template <typename T>
179 float interpolate(T *mapping, float v) const; 179 double interpolate(T *mapping, double v) const;
180 }; 180 };
181 181
182 class AutoRangeMapper : public RangeMapper 182 class AutoRangeMapper : public RangeMapper
183 { 183 {
184 public: 184 public:
186 Interpolating, 186 Interpolating,
187 StraightLine, 187 StraightLine,
188 Logarithmic, 188 Logarithmic,
189 }; 189 };
190 190
191 typedef std::map<float, int> CoordMap; 191 typedef std::map<double, int> CoordMap;
192 192
193 /** 193 /**
194 * Given a series of (value, position) coordinate mappings, 194 * Given a series of (value, position) coordinate mappings,
195 * construct a range mapper that maps arbitrary values, in the 195 * construct a range mapper that maps arbitrary values, in the
196 * range between minimum and maximum of the provided values, onto 196 * range between minimum and maximum of the provided values, onto
233 /** 233 /**
234 * Return the mapping type in use. 234 * Return the mapping type in use.
235 */ 235 */
236 MappingType getType() const { return m_type; } 236 MappingType getType() const { return m_type; }
237 237
238 virtual int getPositionForValue(float value) const; 238 virtual int getPositionForValue(double value) const;
239 virtual int getPositionForValueUnclamped(float value) const; 239 virtual int getPositionForValueUnclamped(double value) const;
240 240
241 virtual float getValueForPosition(int position) const; 241 virtual double getValueForPosition(int position) const;
242 virtual float getValueForPositionUnclamped(int position) const; 242 virtual double getValueForPositionUnclamped(int position) const;
243 243
244 virtual QString getUnit() const { return m_unit; } 244 virtual QString getUnit() const { return m_unit; }
245 245
246 protected: 246 protected:
247 MappingType m_type; 247 MappingType m_type;