changeset 167:53b9c7656798

* 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 48182241f594
children d4be66d61c04
files layer/SpectrogramLayer.cpp layer/SpectrogramLayer.h layer/SpectrumLayer.cpp layer/SpectrumLayer.h layer/WaveformLayer.cpp layer/WaveformLayer.h widgets/AudioDial.cpp widgets/AudioDial.h widgets/PluginParameterBox.cpp widgets/PluginParameterBox.h widgets/PropertyBox.cpp
diffstat 11 files changed, 152 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/layer/SpectrogramLayer.cpp	Mon Oct 16 13:13:57 2006 +0000
+++ b/layer/SpectrogramLayer.cpp	Mon Oct 16 20:42:23 2006 +0000
@@ -21,6 +21,7 @@
 #include "base/Window.h"
 #include "base/Pitch.h"
 #include "base/Preferences.h"
+#include "base/RangeMapper.h"
 
 #include <QPainter>
 #include <QImage>
@@ -428,6 +429,18 @@
     return tr("<unknown>");
 }
 
+RangeMapper *
+SpectrogramLayer::getNewPropertyRangeMapper(const PropertyName &name) const
+{
+    if (name == "Gain") {
+        return new LinearRangeMapper(-50, 50, -25, 25, tr("dB"));
+    }
+    if (name == "Threshold") {
+        return new LinearRangeMapper(-50, 0, -50, 0, tr("dB"));
+    }
+    return 0;
+}
+
 void
 SpectrogramLayer::setProperty(const PropertyName &name, int value)
 {
--- a/layer/SpectrogramLayer.h	Mon Oct 16 13:13:57 2006 +0000
+++ b/layer/SpectrogramLayer.h	Mon Oct 16 20:42:23 2006 +0000
@@ -81,6 +81,7 @@
 					   int *min, int *max) const;
     virtual QString getPropertyValueLabel(const PropertyName &,
 					  int value) const;
+    virtual RangeMapper *getNewPropertyRangeMapper(const PropertyName &) const;
     virtual void setProperty(const PropertyName &, int value);
 
     /**
--- a/layer/SpectrumLayer.cpp	Mon Oct 16 13:13:57 2006 +0000
+++ b/layer/SpectrumLayer.cpp	Mon Oct 16 20:42:23 2006 +0000
@@ -20,6 +20,7 @@
 #include "view/View.h"
 #include "base/AudioLevel.h"
 #include "base/Preferences.h"
+#include "base/RangeMapper.h"
 
 #include <QPainter>
 #include <QPainterPath>
@@ -352,6 +353,15 @@
     return tr("<unknown>");
 }
 
+RangeMapper *
+SpectrumLayer::getNewPropertyRangeMapper(const PropertyName &name) const
+{
+    if (name == "Gain") {
+        return new LinearRangeMapper(-50, 50, -25, 25, tr("dB"));
+    }
+    return 0;
+}
+
 void
 SpectrumLayer::setProperty(const PropertyName &name, int value)
 {
--- a/layer/SpectrumLayer.h	Mon Oct 16 13:13:57 2006 +0000
+++ b/layer/SpectrumLayer.h	Mon Oct 16 20:42:23 2006 +0000
@@ -47,6 +47,7 @@
 					   int *min, int *max) const;
     virtual QString getPropertyValueLabel(const PropertyName &,
 					  int value) const;
+    virtual RangeMapper *getNewPropertyRangeMapper(const PropertyName &) const;
     virtual void setProperty(const PropertyName &, int value);
     virtual void setProperties(const QXmlAttributes &);
 
--- a/layer/WaveformLayer.cpp	Mon Oct 16 13:13:57 2006 +0000
+++ b/layer/WaveformLayer.cpp	Mon Oct 16 20:42:23 2006 +0000
@@ -18,6 +18,7 @@
 #include "base/AudioLevel.h"
 #include "view/View.h"
 #include "base/Profiler.h"
+#include "base/RangeMapper.h"
 
 #include <QPainter>
 #include <QPixmap>
@@ -224,6 +225,15 @@
     return tr("<unknown>");
 }
 
+RangeMapper *
+WaveformLayer::getNewPropertyRangeMapper(const PropertyName &name) const
+{
+    if (name == "Gain") {
+        return new LinearRangeMapper(-50, 50, -25, 25, tr("dB"));
+    }
+    return 0;
+}
+
 void
 WaveformLayer::setProperty(const PropertyName &name, int value)
 {
--- a/layer/WaveformLayer.h	Mon Oct 16 13:13:57 2006 +0000
+++ b/layer/WaveformLayer.h	Mon Oct 16 20:42:23 2006 +0000
@@ -56,6 +56,7 @@
 					   int *min, int *max) const;
     virtual QString getPropertyValueLabel(const PropertyName &,
 					  int value) const;
+    virtual RangeMapper *getNewPropertyRangeMapper(const PropertyName &) const;
     virtual void setProperty(const PropertyName &, int value);
 
     /**
--- a/widgets/AudioDial.cpp	Mon Oct 16 13:13:57 2006 +0000
+++ b/widgets/AudioDial.cpp	Mon Oct 16 20:42:23 2006 +0000
@@ -37,6 +37,8 @@
 
 #include "AudioDial.h"
 
+#include "base/RangeMapper.h"
+
 #include <cmath>
 #include <iostream>
 
@@ -68,7 +70,8 @@
 AudioDial::AudioDial(QWidget *parent) :
     QDial(parent),
     m_knobColor(Qt::black), m_meterColor(Qt::white),
-    m_defaultValue(0)
+    m_defaultValue(0),
+    m_rangeMapper(0)
 {
     m_mouseDial = false;
     m_mousePressed = false;
@@ -78,6 +81,14 @@
 // Destructor.
 AudioDial::~AudioDial (void)
 {
+    delete m_rangeMapper;
+}
+
+
+void AudioDial::setRangeMapper(RangeMapper *mapper)
+{
+    delete m_rangeMapper;
+    m_rangeMapper = mapper;
 }
 
 
@@ -306,6 +317,13 @@
 }
 
 
+float AudioDial::mappedValue() const
+{
+    if (m_rangeMapper) return m_rangeMapper->getValueForPosition(value());
+    else return value();
+}
+
+
 // Alternate mouse behavior event handlers.
 void AudioDial::mousePressEvent(QMouseEvent *mouseEvent)
 {
@@ -328,7 +346,67 @@
     if (m_mouseDial) {
 	QDial::mouseDoubleClickEvent(mouseEvent);
     } else if (mouseEvent->button() == Qt::LeftButton) {
+
 	bool ok = false;
+
+        int newPosition = value();
+
+        if (m_rangeMapper) {
+
+            float min = m_rangeMapper->getValueForPosition(minimum());
+            float max = m_rangeMapper->getValueForPosition(maximum());
+
+            QString unit = m_rangeMapper->getUnit();
+
+            QString text;
+            if (objectName() != "") {
+                if (unit != "") {
+                    text = tr("New value for %1, from %2 to %3 %4:")
+                        .arg(objectName()).arg(min).arg(max).arg(unit);
+                } else {
+                    text = tr("New value for %1, from %2 to %3:")
+                        .arg(objectName()).arg(min).arg(max);
+                }
+            } else {
+                if (unit != "") {
+                    text = tr("Enter a new value from %1 to %2 %3:")
+                        .arg(min).arg(max).arg(unit);
+                } else {
+                    text = tr("Enter a new value from %1 to %2:")
+                        .arg(min).arg(max);
+                }
+            }
+
+            float newValue = QInputDialog::getDouble
+                (this,
+                 tr("Enter new value"),
+                 text,
+                 m_rangeMapper->getValueForPosition(value()),
+                 min,
+                 max,
+                 5, 
+                 &ok);
+
+            //!!! need to avoid this rounding by storing the float value
+
+            newPosition = m_rangeMapper->getPositionForValue(newValue);
+
+        } else {
+
+            newPosition = QInputDialog::getInteger
+                (this,
+                 tr("Enter new value"),
+                 tr("Enter a new value from %1 to %2:")
+                 .arg(minimum()).arg(maximum()),
+                 value(), minimum(), maximum(), pageStep(), &ok);
+        }
+
+        if (ok) {
+            setValue(newPosition);
+        }
+
+
+/*!!!
 	int newValue = QInputDialog::getInteger
 	    (this,
 	     tr("Enter new value"),
@@ -338,6 +416,7 @@
 	if (ok) {
 	    setValue(newValue);
 	}
+*/
     }
 }
 
--- a/widgets/AudioDial.h	Mon Oct 16 13:13:57 2006 +0000
+++ b/widgets/AudioDial.h	Mon Oct 16 20:42:23 2006 +0000
@@ -41,6 +41,8 @@
 #include <QDial>
 #include <map>
 
+class RangeMapper;
+
 /**
  * AudioDial is a nicer-looking QDial that by default reacts to mouse
  * movement on horizontal and vertical axes instead of in a radial
@@ -69,6 +71,10 @@
     const QColor& getMeterColor() const { return m_meterColor; }
     bool getMouseDial() const { return m_mouseDial; }
 
+    void setRangeMapper(RangeMapper *mapper); // I take ownership, will delete
+
+    float mappedValue() const;
+
 public slots:
     /**
      * Set the colour of the knob.  The default is to inherit the
@@ -111,6 +117,8 @@
     bool m_mouseDial;
     bool m_mousePressed;
     QPoint m_posMouse;
+
+    RangeMapper *m_rangeMapper;
 };
 
 
--- a/widgets/PluginParameterBox.cpp	Mon Oct 16 13:13:57 2006 +0000
+++ b/widgets/PluginParameterBox.cpp	Mon Oct 16 20:42:23 2006 +0000
@@ -19,6 +19,8 @@
 
 #include "plugin/PluginXml.h"
 
+#include "base/RangeMapper.h"
+
 #include <QDoubleSpinBox>
 #include <QGridLayout>
 #include <QComboBox>
@@ -150,7 +152,7 @@
         } else {
             
             AudioDial *dial = new AudioDial;
-            dial->setObjectName(name);
+            dial->setObjectName(description);
             dial->setMinimum(imin);
             dial->setMaximum(imax);
             dial->setPageStep(1);
@@ -159,6 +161,8 @@
             dial->setValue(lrintf((value - min) / qtz));
             dial->setFixedWidth(32);
             dial->setFixedHeight(32);
+            dial->setRangeMapper(new LinearRangeMapper
+                                 (imin, imax, min, max, unit));
             connect(dial, SIGNAL(valueChanged(int)),
                     this, SLOT(dialChanged(int)));
             m_layout->addWidget(dial, i + offset, 1);
@@ -179,6 +183,7 @@
         }
 
         m_params[name] = rec;
+        m_descriptionMap[description] = name;
     }
 }
 
@@ -188,6 +193,11 @@
     QObject *obj = sender();
     QString name = obj->objectName();
 
+    if (m_params.find(name) == m_params.end() &&
+        m_descriptionMap.find(name) != m_descriptionMap.end()) {
+        name = m_descriptionMap[name];
+    }
+
     if (m_params.find(name) == m_params.end()) {
         std::cerr << "WARNING: PluginParameterBox::dialChanged: Unknown parameter \"" << name.toStdString() << "\"" << std::endl;
         return;
@@ -225,6 +235,11 @@
     QObject *obj = sender();
     QString name = obj->objectName();
 
+    if (m_params.find(name) == m_params.end() &&
+        m_descriptionMap.find(name) != m_descriptionMap.end()) {
+        name = m_descriptionMap[name];
+    }
+
     if (m_params.find(name) == m_params.end()) {
         std::cerr << "WARNING: PluginParameterBox::checkBoxChanged: Unknown parameter \"" << name.toStdString() << "\"" << std::endl;
         return;
@@ -244,6 +259,11 @@
     QObject *obj = sender();
     QString name = obj->objectName();
 
+    if (m_params.find(name) == m_params.end() &&
+        m_descriptionMap.find(name) != m_descriptionMap.end()) {
+        name = m_descriptionMap[name];
+    }
+
     if (m_params.find(name) == m_params.end()) {
         std::cerr << "WARNING: PluginParameterBox::spinBoxChanged: Unknown parameter \"" << name.toStdString() << "\"" << std::endl;
         return;
--- a/widgets/PluginParameterBox.h	Mon Oct 16 13:13:57 2006 +0000
+++ b/widgets/PluginParameterBox.h	Mon Oct 16 20:42:23 2006 +0000
@@ -61,6 +61,7 @@
     };
 
     std::map<QString, ParamRec> m_params;
+    std::map<QString, QString> m_descriptionMap;
 };
 
 #endif
--- a/widgets/PropertyBox.cpp	Mon Oct 16 13:13:57 2006 +0000
+++ b/widgets/PropertyBox.cpp	Mon Oct 16 20:42:23 2006 +0000
@@ -20,6 +20,7 @@
 #include "base/PlayParameters.h"
 #include "layer/Layer.h"
 #include "base/UnitDatabase.h"
+#include "base/RangeMapper.h"
 
 #include "plugin/RealTimePluginFactory.h"
 #include "plugin/RealTimePluginInstance.h"
@@ -182,6 +183,9 @@
 	gainDial->setNotchesVisible(false);
 	gainDial->setToolTip(tr("Playback Level"));
 	gainDial->setDefaultValue(0);
+        gainDial->setObjectName(tr("Playback Level"));
+        gainDial->setRangeMapper(new LinearRangeMapper
+                                 (-50, 50, -25, 25, tr("dB")));
 	connect(gainDial, SIGNAL(valueChanged(int)),
 		this, SLOT(playGainDialChanged(int)));
 	connect(params, SIGNAL(playGainChanged(float)),
@@ -203,6 +207,7 @@
 	panDial->setNotchesVisible(false);
 	panDial->setToolTip(tr("Playback Pan / Balance"));
 	panDial->setDefaultValue(0);
+        gainDial->setObjectName(tr("Playback Pan / Balance"));
 	connect(panDial, SIGNAL(valueChanged(int)),
 		this, SLOT(playPanDialChanged(int)));
 	connect(params, SIGNAL(playPanChanged(float)),
@@ -318,6 +323,7 @@
 	    dial->setPageStep(1);
 	    dial->setNotchesVisible((max - min) <= 12);
 	    dial->setDefaultValue(value);
+            dial->setRangeMapper(m_container->getNewPropertyRangeMapper(name));
 	    connect(dial, SIGNAL(valueChanged(int)),
 		    this, SLOT(propertyControllerChanged(int)));