comparison base/RangeMapper.cpp @ 1203:932487fe515a 3.0-integration

Introduce labels in RangeMapper and use them in AudioDial, though only for tooltip at present. Make use of this for spectrogram magic -81dB/-Inf threshold. Also introduce static strings for inf/pi and use where appropriate.
author Chris Cannam
date Fri, 05 Aug 2016 17:48:52 +0100
parents 6f7a440b6218
children 48e9f538e6e9
comparison
equal deleted inserted replaced
1202:3b84f9bd0048 1203:932487fe515a
21 21
22 #include <iostream> 22 #include <iostream>
23 23
24 LinearRangeMapper::LinearRangeMapper(int minpos, int maxpos, 24 LinearRangeMapper::LinearRangeMapper(int minpos, int maxpos,
25 double minval, double maxval, 25 double minval, double maxval,
26 QString unit, bool inverted) : 26 QString unit, bool inverted,
27 std::map<int, QString> labels) :
27 m_minpos(minpos), 28 m_minpos(minpos),
28 m_maxpos(maxpos), 29 m_maxpos(maxpos),
29 m_minval(minval), 30 m_minval(minval),
30 m_maxval(maxval), 31 m_maxval(maxval),
31 m_unit(unit), 32 m_unit(unit),
32 m_inverted(inverted) 33 m_inverted(inverted),
34 m_labels(labels)
33 { 35 {
34 assert(m_maxval != m_minval); 36 assert(m_maxval != m_minval);
35 assert(m_maxpos != m_minpos); 37 assert(m_maxpos != m_minpos);
36 } 38 }
37 39
70 double value = m_minval + 72 double value = m_minval +
71 ((double(position - m_minpos) / double(m_maxpos - m_minpos)) 73 ((double(position - m_minpos) / double(m_maxpos - m_minpos))
72 * (m_maxval - m_minval)); 74 * (m_maxval - m_minval));
73 // cerr << "getValueForPositionUnclamped(" << position << "): minval " << m_minval << ", maxval " << m_maxval << ", value " << value << endl; 75 // cerr << "getValueForPositionUnclamped(" << position << "): minval " << m_minval << ", maxval " << m_maxval << ", value " << value << endl;
74 return value; 76 return value;
77 }
78
79 QString
80 LinearRangeMapper::getLabel(int position) const
81 {
82 if (m_labels.find(position) != m_labels.end()) {
83 return m_labels.at(position);
84 } else {
85 return "";
86 }
75 } 87 }
76 88
77 LogRangeMapper::LogRangeMapper(int minpos, int maxpos, 89 LogRangeMapper::LogRangeMapper(int minpos, int maxpos,
78 double minval, double maxval, 90 double minval, double maxval,
79 QString unit, bool inverted) : 91 QString unit, bool inverted) :