comparison base/RangeMapper.cpp @ 190:60ba218a54bb

* Use RangeMappers in various places in plugin parameters, layer properties, playback parameters &c
author Chris Cannam
date Mon, 16 Oct 2006 20:42:23 +0000
parents 0703252c9fe8
children 91fdc752e540
comparison
equal deleted inserted replaced
189:0703252c9fe8 190:60ba218a54bb
34 } 34 }
35 35
36 int 36 int
37 LinearRangeMapper::getPositionForValue(float value) const 37 LinearRangeMapper::getPositionForValue(float value) const
38 { 38 {
39 int position = lrintf(((value - m_minval) / (m_maxval - m_minval)) 39 int position = m_minpos +
40 * (m_maxpos - m_minpos)); 40 lrintf(((value - m_minval) / (m_maxval - m_minval))
41 * (m_maxpos - m_minpos));
41 if (position < m_minpos) position = m_minpos; 42 if (position < m_minpos) position = m_minpos;
42 if (position > m_maxpos) position = m_maxpos; 43 if (position > m_maxpos) position = m_maxpos;
44 std::cerr << "LinearRangeMapper::getPositionForValue: " << value << " -> "
45 << position << " (minpos " << m_minpos << ", maxpos " << m_maxpos << ", minval " << m_minval << ", maxval " << m_maxval << ")" << std::endl;
43 return position; 46 return position;
44 } 47 }
45 48
46 float 49 float
47 LinearRangeMapper::getValueForPosition(int position) const 50 LinearRangeMapper::getValueForPosition(int position) const
48 { 51 {
49 float value = ((float(position - m_minpos) / float(m_maxpos - m_minpos)) 52 float value = m_minval +
50 * (m_maxval - m_minval)); 53 ((float(position - m_minpos) / float(m_maxpos - m_minpos))
54 * (m_maxval - m_minval));
51 if (value < m_minval) value = m_minval; 55 if (value < m_minval) value = m_minval;
52 if (value > m_maxval) value = m_maxval; 56 if (value > m_maxval) value = m_maxval;
57 std::cerr << "LinearRangeMapper::getValueForPosition: " << position << " -> "
58 << value << " (minpos " << m_minpos << ", maxpos " << m_maxpos << ", minval " << m_minval << ", maxval " << m_maxval << ")" << std::endl;
53 return value; 59 return value;
54 } 60 }
55 61
56 LogRangeMapper::LogRangeMapper(int minpos, int maxpos, 62 LogRangeMapper::LogRangeMapper(int minpos, int maxpos,
57 float ratio, float minlog, 63 float ratio, float minlog,
58 QString unit) : 64 QString unit) :
59 m_minpos(minpos), 65 m_minpos(minpos),
60 m_maxpos(maxpos), 66 m_maxpos(maxpos),
67 m_ratio(ratio),
61 m_minlog(minlog), 68 m_minlog(minlog),
62 m_unit(unit) 69 m_unit(unit)
63 { 70 {
64 assert(m_maxpos != m_minpos); 71 assert(m_maxpos != m_minpos);
65 72
73 int position = lrintf(((mapped - m_minlog) / (m_maxlog - m_minlog)) 80 int position = lrintf(((mapped - m_minlog) / (m_maxlog - m_minlog))
74 * (m_maxpos - m_minpos)); 81 * (m_maxpos - m_minpos));
75 if (position < m_minpos) position = m_minpos; 82 if (position < m_minpos) position = m_minpos;
76 if (position > m_maxpos) position = m_maxpos; 83 if (position > m_maxpos) position = m_maxpos;
77 std::cerr << "LogRangeMapper::getPositionForValue: " << value << " -> " 84 std::cerr << "LogRangeMapper::getPositionForValue: " << value << " -> "
78 << position << std::endl; 85 << position << " (minpos " << m_minpos << ", maxpos " << m_maxpos << ", ratio " << m_ratio << ", minlog " << m_minlog << ")" << std::endl;
79 return position; 86 return position;
80 } 87 }
81 88
82 float 89 float
83 LogRangeMapper::getValueForPosition(int position) const 90 LogRangeMapper::getValueForPosition(int position) const
84 { 91 {
85 float value = powf(10, (position - m_minpos) / m_ratio + m_minlog); 92 float value = powf(10, (position - m_minpos) / m_ratio + m_minlog);
86 std::cerr << "LogRangeMapper::getPositionForValue: " << position << " -> " 93 std::cerr << "LogRangeMapper::getValueForPosition: " << position << " -> "
87 << value << std::endl; 94 << value << " (minpos " << m_minpos << ", maxpos " << m_maxpos << ", ratio " << m_ratio << ", minlog " << m_minlog << ")" << std::endl;
88 return value; 95 return value;
89 } 96 }
90 97