# HG changeset patch # User Chris Cannam # Date 1161031343 0 # Node ID 60ba218a54bb4397ce4e2b6bbdb4f92e889629d8 # Parent 0703252c9fe8935f2ee9e93ad4561b519efa0dc4 * Use RangeMappers in various places in plugin parameters, layer properties, playback parameters &c diff -r 0703252c9fe8 -r 60ba218a54bb base/PropertyContainer.cpp --- a/base/PropertyContainer.cpp Mon Oct 16 13:13:57 2006 +0000 +++ b/base/PropertyContainer.cpp Mon Oct 16 20:42:23 2006 +0000 @@ -56,6 +56,12 @@ return QString(); } +RangeMapper * +PropertyContainer::getNewPropertyRangeMapper(const PropertyName &) const +{ + return 0; +} + void PropertyContainer::setProperty(const PropertyName &name, int) { diff -r 0703252c9fe8 -r 60ba218a54bb base/PropertyContainer.h --- a/base/PropertyContainer.h Mon Oct 16 13:13:57 2006 +0000 +++ b/base/PropertyContainer.h Mon Oct 16 20:42:23 2006 +0000 @@ -23,6 +23,7 @@ #include class PlayParameters; +class RangeMapper; class PropertyContainer : public QObject { @@ -84,6 +85,16 @@ virtual QString getPropertyValueLabel(const PropertyName &, int value) const; + /** + * If the given property is a RangeProperty, return a new + * RangeMapper object mapping its integer range onto an underlying + * floating point value range for human-intelligible display, if + * appropriate. The RangeMapper should be allocated with new, and + * the caller takes responsibility for deleting it. Return NULL + * (as in the default implementation) if there is no such mapping. + */ + virtual RangeMapper *getNewPropertyRangeMapper(const PropertyName &) const; + virtual QString getPropertyContainerName() const = 0; virtual QString getPropertyContainerIconName() const = 0; diff -r 0703252c9fe8 -r 60ba218a54bb base/RangeMapper.cpp --- a/base/RangeMapper.cpp Mon Oct 16 13:13:57 2006 +0000 +++ b/base/RangeMapper.cpp Mon Oct 16 20:42:23 2006 +0000 @@ -36,20 +36,26 @@ int LinearRangeMapper::getPositionForValue(float value) const { - int position = lrintf(((value - m_minval) / (m_maxval - m_minval)) - * (m_maxpos - m_minpos)); + int position = m_minpos + + lrintf(((value - m_minval) / (m_maxval - m_minval)) + * (m_maxpos - m_minpos)); if (position < m_minpos) position = m_minpos; if (position > m_maxpos) position = m_maxpos; + std::cerr << "LinearRangeMapper::getPositionForValue: " << value << " -> " + << position << " (minpos " << m_minpos << ", maxpos " << m_maxpos << ", minval " << m_minval << ", maxval " << m_maxval << ")" << std::endl; return position; } float LinearRangeMapper::getValueForPosition(int position) const { - float value = ((float(position - m_minpos) / float(m_maxpos - m_minpos)) - * (m_maxval - m_minval)); + float value = m_minval + + ((float(position - m_minpos) / float(m_maxpos - m_minpos)) + * (m_maxval - m_minval)); if (value < m_minval) value = m_minval; if (value > m_maxval) value = m_maxval; + std::cerr << "LinearRangeMapper::getValueForPosition: " << position << " -> " + << value << " (minpos " << m_minpos << ", maxpos " << m_maxpos << ", minval " << m_minval << ", maxval " << m_maxval << ")" << std::endl; return value; } @@ -58,6 +64,7 @@ QString unit) : m_minpos(minpos), m_maxpos(maxpos), + m_ratio(ratio), m_minlog(minlog), m_unit(unit) { @@ -75,7 +82,7 @@ if (position < m_minpos) position = m_minpos; if (position > m_maxpos) position = m_maxpos; std::cerr << "LogRangeMapper::getPositionForValue: " << value << " -> " - << position << std::endl; + << position << " (minpos " << m_minpos << ", maxpos " << m_maxpos << ", ratio " << m_ratio << ", minlog " << m_minlog << ")" << std::endl; return position; } @@ -83,8 +90,8 @@ LogRangeMapper::getValueForPosition(int position) const { float value = powf(10, (position - m_minpos) / m_ratio + m_minlog); - std::cerr << "LogRangeMapper::getPositionForValue: " << position << " -> " - << value << std::endl; + std::cerr << "LogRangeMapper::getValueForPosition: " << position << " -> " + << value << " (minpos " << m_minpos << ", maxpos " << m_maxpos << ", ratio " << m_ratio << ", minlog " << m_minlog << ")" << std::endl; return value; }