changeset 487:c45e6c6722e0

* Use enum for transform type instead of trying to do dumb things like compare translated strings
author Chris Cannam
date Fri, 21 Nov 2008 13:37:35 +0000
parents 4c000e196bf1
children 1c66e199e7d9
files transform/TransformDescription.h transform/TransformFactory.cpp transform/TransformFactory.h
diffstat 3 files changed, 45 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/transform/TransformDescription.h	Thu Nov 20 14:58:52 2008 +0000
+++ b/transform/TransformDescription.h	Fri Nov 21 13:37:35 2008 +0000
@@ -45,8 +45,16 @@
 
 struct TransformDescription
 {
+    enum Type {
+        Analysis,    // e.g. vamp plugin output
+        Effects,     // e.g. ladspa plugin with audio in and out
+        EffectsData, // e.g. control output of ladspa plugin
+        Generator,   // e.g. audio out of ladspa plugin with no audio in
+        UnknownType
+    };
+
     TransformDescription() { }
-    TransformDescription(QString _type, QString _category,
+    TransformDescription(Type _type, QString _category,
                          TransformId _identifier, QString _name,
                          QString _friendlyName, QString _description,
                          QString _longDescription,
@@ -57,7 +65,7 @@
         longDescription(_longDescription),
         maker(_maker), units(_units), configurable(_configurable) { }
 
-    QString type; // e.g. feature extraction plugin
+    Type type;
     QString category; // e.g. time > onsets
     TransformId identifier; // e.g. vamp:vamp-aubio:aubioonset
     QString name; // plugin's name if 1 output, else "name: output"
--- a/transform/TransformFactory.cpp	Thu Nov 20 14:58:52 2008 +0000
+++ b/transform/TransformFactory.cpp	Fri Nov 21 13:37:35 2008 +0000
@@ -212,19 +212,19 @@
 }
     
 
-std::vector<QString>
+std::vector<TransformDescription::Type>
 TransformFactory::getAllTransformTypes()
 {
     populateTransforms();
 
-    std::set<QString> types;
+    std::set<TransformDescription::Type> 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) {
+    std::vector<TransformDescription::Type> rv;
+    for (std::set<TransformDescription::Type>::iterator i = types.begin(); i != types.end(); ++i) {
         rv.push_back(*i);
     }
 
@@ -232,7 +232,7 @@
 }
 
 std::vector<QString>
-TransformFactory::getTransformCategories(QString transformType)
+TransformFactory::getTransformCategories(TransformDescription::Type transformType)
 {
     populateTransforms();
 
@@ -259,7 +259,7 @@
 }
 
 std::vector<QString>
-TransformFactory::getTransformMakers(QString transformType)
+TransformFactory::getTransformMakers(TransformDescription::Type transformType)
 {
     populateTransforms();
 
@@ -285,6 +285,18 @@
     return rv;
 }
 
+QString
+TransformFactory::getTransformTypeName(TransformDescription::Type type) const
+{
+    switch (type) {
+    case TransformDescription::Analysis: return tr("Analysis");
+    case TransformDescription::Effects: return tr("Effects");
+    case TransformDescription::EffectsData: return tr("Effects Data");
+    case TransformDescription::Generator: return tr("Generator");
+    case TransformDescription::UnknownType: return tr("Other");
+    }
+}
+
 void
 TransformFactory::populateTransforms()
 {
@@ -436,7 +448,7 @@
 //            cerr << "Feature extraction plugin transform: " << transformId.toStdString() << " friendly name: " << friendlyName.toStdString() << endl;
 
 	    transforms[transformId] = 
-                TransformDescription(tr("Analysis"),
+                TransformDescription(TransformDescription::Analysis,
                                      category,
                                      transformId,
                                      userName,
@@ -539,7 +551,7 @@
                 }
 
                 transforms[transformId] = 
-                    TransformDescription(tr("Effects Data"),
+                    TransformDescription(TransformDescription::EffectsData,
                                          category,
                                          transformId,
                                          userName,
@@ -557,14 +569,14 @@
             if (descriptor->audioOutputPortCount > 0) {
 
                 QString transformId = QString("%1:A").arg(pluginId);
-                QString type = tr("Effects");
+                TransformDescription::Type type = TransformDescription::Effects;
 
                 QString description = tr("Transform audio signal with \"%1\" effect plugin (from %2)")
                     .arg(pluginName)
                     .arg(maker);
 
                 if (descriptor->audioInputPortCount == 0) {
-                    type = tr("Generators");
+                    type = TransformDescription::Generator;
                     QString description = tr("Generate audio signal using \"%1\" plugin (from %2)")
                         .arg(pluginName)
                         .arg(maker);
@@ -641,7 +653,7 @@
             if (oname == "") oname = *j;
             
             TransformDescription td;
-            td.type = tr("Analysis"); //!!! should be enum or something
+            td.type = TransformDescription::Analysis;
             td.category = "";
             td.identifier = tid;
 
@@ -1063,7 +1075,10 @@
 
         match.key = i->first;
         
-        matcher.test(match, keywords, i->second.type, tr("Plugin type"), 5);
+        matcher.test(match, keywords,
+                     getTransformTypeName(i->second.type),
+                     tr("Plugin type"), 5);
+
         matcher.test(match, keywords, i->second.category, tr("Category"), 20);
         matcher.test(match, keywords, i->second.identifier, tr("System Identifier"), 6);
         matcher.test(match, keywords, i->second.name, tr("Name"), 30);
@@ -1098,7 +1113,10 @@
 
         match.key = i->first;
         
-        matcher.test(match, keywords, i->second.type, tr("Plugin type"), 2);
+        matcher.test(match, keywords,
+                     getTransformTypeName(i->second.type),
+                     tr("Plugin type"), 2);
+
         matcher.test(match, keywords, i->second.category, tr("Category"), 10);
         matcher.test(match, keywords, i->second.identifier, tr("System Identifier"), 3);
         matcher.test(match, keywords, i->second.name, tr("Name"), 15);
--- a/transform/TransformFactory.h	Thu Nov 20 14:58:52 2008 +0000
+++ b/transform/TransformFactory.h	Fri Nov 21 13:37:35 2008 +0000
@@ -68,9 +68,10 @@
 
     TransformInstallStatus getTransformInstallStatus(TransformId id);
 
-    std::vector<QString> getAllTransformTypes();
-    std::vector<QString> getTransformCategories(QString transformType);
-    std::vector<QString> getTransformMakers(QString transformType);
+    std::vector<TransformDescription::Type> getAllTransformTypes();
+    std::vector<QString> getTransformCategories(TransformDescription::Type);
+    std::vector<QString> getTransformMakers(TransformDescription::Type);
+    QString getTransformTypeName(TransformDescription::Type) const;
 
     typedef std::map<TransformId, TextMatcher::Match> SearchResults;
     SearchResults search(QString keyword);