changeset 63:ba405e5e69d3

* Add auto-normalize option to waveform layer * Various fixes to display of dB/metered levels in waveform layer. Still need to fix to ensure they don't waste half the display * Add mix channels option to waveform layer * Use multiple transforms menus, one per transform type -- not sure about this * Give centroid plugin two outputs, for log and linear frequency weightings * Show scale units from plugin in time-value display
author Chris Cannam
date Wed, 29 Mar 2006 12:35:17 +0000
parents 33285f426852
children 4d59dc469b0f
files transform/FeatureExtractionPluginTransform.cpp transform/RealTimePluginTransform.cpp transform/RealTimePluginTransform.h transform/TransformFactory.cpp transform/TransformFactory.h
diffstat 5 files changed, 81 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/transform/FeatureExtractionPluginTransform.cpp	Tue Mar 28 23:57:32 2006 +0000
+++ b/transform/FeatureExtractionPluginTransform.cpp	Wed Mar 29 12:35:17 2006 +0000
@@ -130,8 +130,11 @@
 	       m_descriptor->sampleType ==
 	       FeatureExtractionPlugin::OutputDescriptor::VariableSampleRate) {
 	
-	m_output = new SparseTimeValueModel(modelRate, modelResolution,
-					    minValue, maxValue, false);
+        SparseTimeValueModel *model = new SparseTimeValueModel
+            (modelRate, modelResolution, minValue, maxValue, false);
+        model->setScaleUnits(outputs[m_outputFeatureNo].unit.c_str());
+
+        m_output = model;
 
     } else {
 	
--- a/transform/RealTimePluginTransform.cpp	Tue Mar 28 23:57:32 2006 +0000
+++ b/transform/RealTimePluginTransform.cpp	Wed Mar 29 12:35:17 2006 +0000
@@ -28,6 +28,7 @@
 RealTimePluginTransform::RealTimePluginTransform(Model *inputModel,
                                                  QString pluginId,
                                                  QString configurationXml,
+                                                 QString units,
                                                  int output) :
     Transform(inputModel),
     m_plugin(0),
@@ -66,9 +67,13 @@
         return;
     }
 	
-    m_output = new SparseTimeValueModel(input->getSampleRate(),
-                                        1024, //!!!
-                                        0.0, 0.0, false);
+    SparseTimeValueModel *model = new SparseTimeValueModel
+        (input->getSampleRate(), 1024, //!!!
+         0.0, 0.0, false);
+
+    if (units != "") model->setScaleUnits(units);
+
+    m_output = model;
 }
 
 RealTimePluginTransform::~RealTimePluginTransform()
--- a/transform/RealTimePluginTransform.h	Tue Mar 28 23:57:32 2006 +0000
+++ b/transform/RealTimePluginTransform.h	Wed Mar 29 12:35:17 2006 +0000
@@ -27,6 +27,7 @@
     RealTimePluginTransform(Model *inputModel,
 			    QString plugin,
 			    QString configurationXml = "",
+                            QString units = "",
 			    int output = 0);
     virtual ~RealTimePluginTransform();
 
--- a/transform/TransformFactory.cpp	Tue Mar 28 23:57:32 2006 +0000
+++ b/transform/TransformFactory.cpp	Wed Mar 29 12:35:17 2006 +0000
@@ -24,6 +24,9 @@
 #include "widgets/PluginParameterDialog.h"
 
 #include <iostream>
+#include <set>
+
+#include <QRegExp>
 
 TransformFactory *
 TransformFactory::m_instance = new TransformFactory;
@@ -52,6 +55,25 @@
     return list;
 }
 
+std::vector<QString>
+TransformFactory::getAllTransformTypes()
+{
+    if (m_transforms.empty()) populateTransforms();
+
+    std::set<QString> types;
+    for (TransformDescriptionMap::const_iterator i = m_transforms.begin();
+	 i != m_transforms.end(); ++i) {
+        types.insert(i->second.type);
+    }
+
+    std::vector<QString> rv;
+    for (std::set<QString>::iterator i = types.begin(); i != types.end(); ++i) {
+        rv.push_back(*i);
+    }
+
+    return rv;
+}
+
 void
 TransformFactory::populateTransforms()
 {
@@ -134,6 +156,7 @@
 
 	    QString userDescription;
             QString friendlyName;
+            QString units = outputs[j].unit.c_str();
 
 	    if (outputs.size() == 1) {
 		userDescription = pluginDescription;
@@ -149,10 +172,12 @@
                                  !plugin->getParameterDescriptors().empty());
 
 	    transforms[transformName] = 
-                TransformDesc(transformName,
+                TransformDesc(tr("Analysis Plugin"),
+                              transformName,
                               userDescription,
                               friendlyName,
                               plugin->getMaker().c_str(),
+                              units,
                               configurable);
 	}
     }
@@ -164,6 +189,8 @@
     std::vector<QString> plugs =
 	RealTimePluginFactory::getAllPluginIdentifiers();
 
+    QRegExp unitRE("[\\[\\(]([A-Za-z0-9/]+)[\\)\\]]$");
+
     for (size_t i = 0; i < plugs.size(); ++i) {
         
 	QString pluginId = plugs[i];
@@ -195,27 +222,42 @@
 
 	    QString transformName = QString("%1:%2").arg(pluginId).arg(j);
 	    QString userDescription;
+            QString units;
 
 	    if (j < descriptor->controlOutputPortNames.size() &&
                 descriptor->controlOutputPortNames[j] != "") {
+
+                QString portName = descriptor->controlOutputPortNames[j].c_str();
+
 		userDescription = tr("%1: %2")
                     .arg(pluginDescription)
-                    .arg(descriptor->controlOutputPortNames[j].c_str());
+                    .arg(portName);
+
+                if (unitRE.indexIn(portName) >= 0) {
+                    units = unitRE.cap(1);
+                }
+
 	    } else if (descriptor->controlOutputPortCount > 1) {
+
 		userDescription = tr("%1: Output %2")
 		    .arg(pluginDescription)
 		    .arg(j + 1);
+
 	    } else {
+
                 userDescription = pluginDescription;
             }
 
+
             bool configurable = (descriptor->parameterCount > 0);
 
 	    transforms[transformName] = 
-                TransformDesc(transformName,
+                TransformDesc(tr("Real-Time Plugin"),
+                              transformName,
                               userDescription,
                               userDescription,
                               descriptor->maker.c_str(),
+                              units,
                               configurable);
 	}
     }
@@ -237,6 +279,14 @@
     } else return "";
 }
 
+QString
+TransformFactory::getTransformUnits(TransformName name)
+{
+    if (m_transforms.find(name) != m_transforms.end()) {
+	return m_transforms[name].units;
+    } else return "";
+}
+
 bool
 TransformFactory::isTransformConfigurable(TransformName name)
 {
@@ -307,6 +357,7 @@
         transform = new RealTimePluginTransform(inputModel,
                                                 id,
                                                 configurationXml,
+                                                getTransformUnits(name),
                                                 output.toInt());
     } else {
         std::cerr << "TransformFactory::createTransform: Unknown transform "
--- a/transform/TransformFactory.h	Tue Mar 28 23:57:32 2006 +0000
+++ b/transform/TransformFactory.h	Wed Mar 29 12:35:17 2006 +0000
@@ -34,25 +34,31 @@
     // human readable.  In principle it doesn't have to be unique, but
     // the factory will add suffixes to ensure that it is, all the
     // same (just to avoid user confusion).  The friendly name is a
-    // shorter version of the description.
+    // shorter version of the description.  The type is also intended
+    // to be user-readable, for use in menus.
 
     struct TransformDesc {
         TransformDesc() { }
-	TransformDesc(TransformName _name, QString _description,
+	TransformDesc(QString _type, TransformName _name, QString _description,
                       QString _friendlyName, QString _maker,
-                      bool _configurable) :
-	    name(_name), description(_description), friendlyName(_friendlyName),
-            maker(_maker), configurable(_configurable) { }
+                      QString _units, bool _configurable) :
+	    type(_type), name(_name), description(_description),
+            friendlyName(_friendlyName),
+            maker(_maker), units(_units), configurable(_configurable) { }
+        QString type;
 	TransformName name;
 	QString description;
         QString friendlyName;
         QString maker;
+        QString units;
         bool configurable;
     };
     typedef std::vector<TransformDesc> TransformList;
 
     TransformList getAllTransforms();
 
+    std::vector<QString> getAllTransformTypes();
+
     /**
      * Get a configuration XML string for the given transform (by
      * asking the user, most likely).  Returns true if the transform
@@ -88,6 +94,8 @@
      */
     QString getTransformFriendlyName(TransformName name);
 
+    QString getTransformUnits(TransformName name);
+
     /**
      * Return true if the transform has any configurable parameters,
      * i.e. if getConfigurationForTransform can ever return a non-trivial