diff transform/TransformFactory.cpp @ 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 3086ff194ea0
children 4d59dc469b0f
line wrap: on
line diff
--- 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 "