changeset 356:ca3b91119482

* fix support for logarithmic hints in plugin parameters
author Chris Cannam
date Mon, 17 Dec 2007 12:32:28 +0000
parents d02f71281639
children b92513201610
files base/RangeMapper.cpp base/RangeMapper.h base/XmlExportable.cpp plugin/DSSIPluginInstance.cpp plugin/DSSIPluginInstance.h plugin/LADSPAPluginFactory.cpp plugin/LADSPAPluginInstance.cpp plugin/LADSPAPluginInstance.h plugin/RealTimePluginInstance.h
diffstat 9 files changed, 98 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/base/RangeMapper.cpp	Thu Dec 13 17:14:33 2007 +0000
+++ b/base/RangeMapper.cpp	Mon Dec 17 12:32:28 2007 +0000
@@ -60,27 +60,52 @@
 }
 
 LogRangeMapper::LogRangeMapper(int minpos, int maxpos,
-                               float ratio, float minlog,
+                               float minval, float maxval,
                                QString unit) :
     m_minpos(minpos),
     m_maxpos(maxpos),
-    m_ratio(ratio),
-    m_minlog(minlog),
     m_unit(unit)
 {
+    convertMinMax(minpos, maxpos, minval, maxval, m_minlog, m_ratio);
+
+    std::cerr << "LogRangeMapper: minpos " << minpos << ", maxpos "
+              << maxpos << ", minval " << minval << ", maxval "
+              << maxval << ", minlog " << m_minlog << ", ratio " << m_ratio
+              << ", unit " << unit.toStdString() << std::endl;
+
     assert(m_maxpos != m_minpos);
 
     m_maxlog = (m_maxpos - m_minpos) / m_ratio + m_minlog;
 }
 
+void
+LogRangeMapper::convertMinMax(int minpos, int maxpos,
+                              float minval, float maxval,
+                              float &minlog, float &ratio)
+{
+    static float thresh = powf(10, -10);
+    if (minval < thresh) minval = thresh;
+    minlog = log10f(minval);
+    ratio = (maxpos - minpos) / (log10f(maxval) - minlog);
+}
+
+void
+LogRangeMapper::convertRatioMinLog(float ratio, float minlog,
+                                   int minpos, int maxpos,
+                                   float &minval, float &maxval)
+{
+    minval = powf(10, minlog);
+    maxval = powf(10, (maxpos - minpos) / ratio + minlog);
+}
+
 int
 LogRangeMapper::getPositionForValue(float value) const
 {
     int position = (log10(value) - m_minlog) * m_ratio + m_minpos;
     if (position < m_minpos) position = m_minpos;
     if (position > m_maxpos) position = m_maxpos;
-//    std::cerr << "LogRangeMapper::getPositionForValue: " << value << " -> "
-//              << position << " (minpos " << m_minpos << ", maxpos " << m_maxpos << ", ratio " << m_ratio << ", minlog " << m_minlog << ")" << std::endl;
+    std::cerr << "LogRangeMapper::getPositionForValue: " << value << " -> "
+              << position << " (minpos " << m_minpos << ", maxpos " << m_maxpos << ", ratio " << m_ratio << ", minlog " << m_minlog << ")" << std::endl;
     return position;
 }
 
@@ -88,8 +113,8 @@
 LogRangeMapper::getValueForPosition(int position) const
 {
     float value = powf(10, (position - m_minpos) / m_ratio + m_minlog);
-//    std::cerr << "LogRangeMapper::getValueForPosition: " << position << " -> "
-//              << value << " (minpos " << m_minpos << ", maxpos " << m_maxpos << ", ratio " << m_ratio << ", minlog " << m_minlog << ")" << std::endl;
+    std::cerr << "LogRangeMapper::getValueForPosition: " << position << " -> "
+              << value << " (minpos " << m_minpos << ", maxpos " << m_maxpos << ", ratio " << m_ratio << ", minlog " << m_minlog << ")" << std::endl;
     return value;
 }
 
--- a/base/RangeMapper.h	Thu Dec 13 17:14:33 2007 +0000
+++ b/base/RangeMapper.h	Mon Dec 17 12:32:28 2007 +0000
@@ -54,9 +54,17 @@
 {
 public:
     LogRangeMapper(int minpos, int maxpos,
-                   float ratio, float minlog,
+                   float minval, float maxval,
                    QString m_unit = "");
 
+    static void convertRatioMinLog(float ratio, float minlog,
+                                   int minpos, int maxpos,
+                                   float &minval, float &maxval);
+
+    static void convertMinMax(int minpos, int maxpos,
+                              float minval, float maxval,
+                              float &ratio, float &minlog);
+
     virtual int getPositionForValue(float value) const;
     virtual float getValueForPosition(int position) const;
 
--- a/base/XmlExportable.cpp	Thu Dec 13 17:14:33 2007 +0000
+++ b/base/XmlExportable.cpp	Mon Dec 17 12:32:28 2007 +0000
@@ -25,7 +25,7 @@
 XmlExportable::toXmlString(QString indent,
                            QString extraAttributes) const
 {
-    std::cerr << "XmlExportable::toXmlString" << std::endl;
+//    std::cerr << "XmlExportable::toXmlString" << std::endl;
 
     QString s;
 
--- a/plugin/DSSIPluginInstance.cpp	Thu Dec 13 17:14:33 2007 +0000
+++ b/plugin/DSSIPluginInstance.cpp	Mon Dec 17 12:32:28 2007 +0000
@@ -831,6 +831,20 @@
     }
 }
 
+int
+DSSIPluginInstance::getParameterDisplayHint(unsigned int parameter) const
+{
+    if (parameter >= m_controlPortsIn.size()) return 0.0;
+
+    LADSPAPluginFactory *f = dynamic_cast<LADSPAPluginFactory *>(m_factory);
+    if (f) {
+	return f->getPortDisplayHint(m_descriptor->LADSPA_Plugin,
+                                     m_controlPortsIn[parameter].first);
+    } else {
+	return PortHint::NoHint;
+    }
+}
+
 std::string
 DSSIPluginInstance::configure(std::string key,
 			      std::string value)
--- a/plugin/DSSIPluginInstance.h	Thu Dec 13 17:14:33 2007 +0000
+++ b/plugin/DSSIPluginInstance.h	Mon Dec 17 12:32:28 2007 +0000
@@ -60,6 +60,7 @@
     virtual void setParameterValue(unsigned int parameter, float value);
     virtual float getParameterValue(unsigned int parameter) const;
     virtual float getParameterDefault(unsigned int parameter) const;
+    virtual int getParameterDisplayHint(unsigned int parameter) const;
 
     virtual ParameterList getParameterDescriptors() const;
     virtual float getParameter(std::string) const;
--- a/plugin/LADSPAPluginFactory.cpp	Thu Dec 13 17:14:33 2007 +0000
+++ b/plugin/LADSPAPluginFactory.cpp	Mon Dec 17 12:32:28 2007 +0000
@@ -151,6 +151,7 @@
 		
     if (LADSPA_IS_HINT_BOUNDED_BELOW(d)) {
 	float lb = descriptor->PortRangeHints[port].LowerBound;
+        std::cerr << "LADSPAPluginFactory::getPortMinimum: bounded below at " << lb << std::endl;
 	minimum = lb;
     } else if (LADSPA_IS_HINT_BOUNDED_ABOVE(d)) {
 	float ub = descriptor->PortRangeHints[port].UpperBound;
@@ -161,6 +162,10 @@
 	minimum *= m_sampleRate;
     }
 
+    if (LADSPA_IS_HINT_LOGARITHMIC(d)) {
+        if (minimum == 0.f) minimum = 1.f;
+    }
+
     return minimum;
 }
 
@@ -211,6 +216,17 @@
 
     bool logarithmic = LADSPA_IS_HINT_LOGARITHMIC(d);
     
+    float logmin = 0, logmax = 0;
+    if (logarithmic) {
+        float thresh = powf(10, -10);
+        if (minimum < thresh) logmin = -10;
+        else logmin = log10f(minimum);
+        if (maximum < thresh) logmax = -10;
+        else logmax = log10f(maximum);
+    }
+
+    std::cerr << "LADSPAPluginFactory::getPortDefault: hint = " << d << std::endl;
+
     if (!LADSPA_IS_HINT_HAS_DEFAULT(d)) {
 	
 	deft = minimum;
@@ -222,8 +238,7 @@
     } else if (LADSPA_IS_HINT_DEFAULT_LOW(d)) {
 	
 	if (logarithmic) {
-	    deft = powf(10, log10(minimum) * 0.75 +
-			    log10(maximum) * 0.25);
+	    deft = powf(10, logmin * 0.75 + logmax * 0.25);
 	} else {
 	    deft = minimum * 0.75 + maximum * 0.25;
 	}
@@ -231,8 +246,7 @@
     } else if (LADSPA_IS_HINT_DEFAULT_MIDDLE(d)) {
 	
 	if (logarithmic) {
-	    deft = powf(10, log10(minimum) * 0.5 +
-		   	    log10(maximum) * 0.5);
+	    deft = powf(10, logmin * 0.5 + logmax * 0.5);
 	} else {
 	    deft = minimum * 0.5 + maximum * 0.5;
 	}
@@ -240,8 +254,7 @@
     } else if (LADSPA_IS_HINT_DEFAULT_HIGH(d)) {
 	
 	if (logarithmic) {
-	    deft = powf(10, log10(minimum) * 0.25 +
-			    log10(maximum) * 0.75);
+	    deft = powf(10, logmin * 0.25 + logmax * 0.75);
 	} else {
 	    deft = minimum * 0.25 + maximum * 0.75;
 	}
@@ -271,10 +284,14 @@
 	
 	deft = minimum;
     }
+
+//!!! No -- the min and max have already been multiplied by the rate,
+//so it would happen twice if we did it here -- and e.g. DEFAULT_440
+//doesn't want to be multiplied by the rate either
     
-    if (LADSPA_IS_HINT_SAMPLE_RATE(d)) {
-	deft *= m_sampleRate;
-    }
+//    if (LADSPA_IS_HINT_SAMPLE_RATE(d)) {
+//	deft *= m_sampleRate;
+//    }
 
     return deft;
 }
--- a/plugin/LADSPAPluginInstance.cpp	Thu Dec 13 17:14:33 2007 +0000
+++ b/plugin/LADSPAPluginInstance.cpp	Mon Dec 17 12:32:28 2007 +0000
@@ -515,6 +515,19 @@
     }
 }
 
+int
+LADSPAPluginInstance::getParameterDisplayHint(unsigned int parameter) const
+{
+    if (parameter >= m_controlPortsIn.size()) return 0.0;
+
+    LADSPAPluginFactory *f = dynamic_cast<LADSPAPluginFactory *>(m_factory);
+    if (f) {
+	return f->getPortDisplayHint(m_descriptor, m_controlPortsIn[parameter].first);
+    } else {
+	return PortHint::NoHint;
+    }
+}
+
 void
 LADSPAPluginInstance::run(const Vamp::RealTime &)
 {
--- a/plugin/LADSPAPluginInstance.h	Thu Dec 13 17:14:33 2007 +0000
+++ b/plugin/LADSPAPluginInstance.h	Mon Dec 17 12:32:28 2007 +0000
@@ -56,6 +56,7 @@
     virtual void setParameterValue(unsigned int parameter, float value);
     virtual float getParameterValue(unsigned int parameter) const;
     virtual float getParameterDefault(unsigned int parameter) const;
+    virtual int getParameterDisplayHint(unsigned int parameter) const;
     
     virtual ParameterList getParameterDescriptors() const;
     virtual float getParameter(std::string) const;
--- a/plugin/RealTimePluginInstance.h	Thu Dec 13 17:14:33 2007 +0000
+++ b/plugin/RealTimePluginInstance.h	Mon Dec 17 12:32:28 2007 +0000
@@ -112,6 +112,7 @@
     virtual void setParameterValue(unsigned int parameter, float value) = 0;
     virtual float getParameterValue(unsigned int parameter) const = 0;
     virtual float getParameterDefault(unsigned int parameter) const = 0;
+    virtual int getParameterDisplayHint(unsigned int parameter) const = 0;
 
     virtual std::string configure(std::string /* key */, std::string /* value */) { return std::string(); }