changeset 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 86766fef5467
files base/PropertyContainer.cpp base/PropertyContainer.h base/RangeMapper.cpp
diffstat 3 files changed, 31 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- 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) 
 {
--- 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 <vector>
 
 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;
 
--- 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;
 }