changeset 508:1b8c748fd7ea

* Support recording the summary type in transform
author Chris Cannam
date Fri, 05 Dec 2008 16:18:04 +0000
parents 0944d13689b2
children 6066bde1c126
files rdf/PluginRDFDescription.cpp rdf/PluginRDFIndexer.cpp rdf/RDFFeatureWriter.cpp rdf/RDFImporter.cpp rdf/RDFTransformFactory.cpp transform/Transform.cpp transform/Transform.h transform/TransformFactory.cpp transform/TransformFactory.h
diffstat 9 files changed, 116 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/rdf/PluginRDFDescription.cpp	Fri Dec 05 14:19:04 2008 +0000
+++ b/rdf/PluginRDFDescription.cpp	Fri Dec 05 16:18:04 2008 +0000
@@ -375,10 +375,7 @@
             (m, queryTemplate.arg("feature"), "feature");
 
         if (v.type == SimpleSPARQLQuery::URIValue && v.value != "") {
-            cerr << "Feature attribute URI: \"" << v.value.toStdString() << "\"" << endl;
             m_outputFeatureAttributeURIMap[outputId] = v.value;
-        } else {
-            cerr << "No feature attribute URI: \"" << v.value.toStdString() << "\"" << endl;
         }           
 
         v = SimpleSPARQLQuery::singleResultQuery
--- a/rdf/PluginRDFIndexer.cpp	Fri Dec 05 14:19:04 2008 +0000
+++ b/rdf/PluginRDFIndexer.cpp	Fri Dec 05 16:18:04 2008 +0000
@@ -236,7 +236,7 @@
 {
     Profiler profiler("PluginRDFIndexer::indexURL");
 
-    std::cerr << "PluginRDFIndexer::indexURL(" << urlString.toStdString() << ")" << std::endl;
+//    std::cerr << "PluginRDFIndexer::indexURL(" << urlString.toStdString() << ")" << std::endl;
 
     QMutexLocker locker(&m_mutex);
 
--- a/rdf/RDFFeatureWriter.cpp	Fri Dec 05 14:19:04 2008 +0000
+++ b/rdf/RDFFeatureWriter.cpp	Fri Dec 05 16:18:04 2008 +0000
@@ -23,6 +23,7 @@
 
 #include <QTextStream>
 #include <QUrl>
+#include <QFileInfo>
 #include <QRegExp>
 
 using namespace std;
@@ -223,6 +224,7 @@
     if (local) {
         if (scheme == "") {
             url.setScheme("file");
+            url.setPath(QFileInfo(url.path()).absoluteFilePath());
         } else if (scheme.length() == 1) { // DOS drive letter!
             url.setScheme("file");
             url.setPath(scheme + ":" + url.path());
@@ -315,8 +317,6 @@
         // see note above -- need to generate an event type if no
         // feature type given, or if in plain mode
 
-        cerr << "Note: track level output" << endl;
-
         if (m_plain) {
         
             needEventType = true;
@@ -352,7 +352,8 @@
     }
 
     if (transform.getIdentifier() != "") {
-        stream << RDFTransformFactory::writeTransformToRDF(transform, transformUri)
+        stream << endl
+               << RDFTransformFactory::writeTransformToRDF(transform, transformUri)
                << endl;
     }
 
@@ -510,8 +511,8 @@
 
             if (feature.label == "") continue;
 
-            stream << signalURI << " " << featureUri << " \""
-                   << feature.label.c_str() << "\" .\n";
+            stream << signalURI << " " << featureUri << " \"\"\""
+                   << feature.label.c_str() << "\"\"\" .\n";
 
         } else {
 
--- a/rdf/RDFImporter.cpp	Fri Dec 05 14:19:04 2008 +0000
+++ b/rdf/RDFImporter.cpp	Fri Dec 05 16:18:04 2008 +0000
@@ -146,9 +146,13 @@
         return models;
     }
 
+    QString error;
+
+    if (!isOK()) error = m_errorString;
+    m_errorString = "";
+
     getDataModelsDense(models, reporter);
 
-    QString error;
     if (!isOK()) error = m_errorString;
     m_errorString = "";
 
@@ -195,9 +199,11 @@
                     m_sampleRate = newModel->getSampleRate();
                 }
             } else {
-                std::cerr << "Failed to create wave file model from source at \"" << source.toStdString() << "\"" << std::endl;
+                m_errorString = QString("Failed to create wave file model from source at \"%1\"").arg(source);
                 delete newModel;
             }
+        } else {
+            m_errorString = QString("Signal source \"%1\" is not available").arg(source);
         }
     }
 }
--- a/rdf/RDFTransformFactory.cpp	Fri Dec 05 14:19:04 2008 +0000
+++ b/rdf/RDFTransformFactory.cpp	Fri Dec 05 16:18:04 2008 +0000
@@ -220,6 +220,7 @@
         static const char *optionals[] = {
             "output",
             "program",
+            "summary_type",
             "step_size",
             "block_size",
             "window_type",
@@ -262,6 +263,9 @@
                 
                     if (optional == "program") {
                         transform.setProgram(v.value);
+                    } else if (optional == "summary_type") {
+                        transform.setSummaryType
+                            (transform.stringToSummaryType(v.value));
                     } else if (optional == "step_size") {
                         transform.setStepSize(v.value.toUInt());
                     } else if (optional == "block_size") {
@@ -430,11 +434,15 @@
     }
     
     QString program = transform.getProgram();
-
     if (program != "") {
         s << "    vamp:program \"\"\"" << program << "\"\"\" ;" << endl;
     }
 
+    QString summary = transform.summaryTypeToString(transform.getSummaryType());
+    if (summary != "") {
+        s << "    vamp:summary_type \"" << summary << "\" ;" << endl;
+    }
+
     Transform::ParameterMap parameters = transform.getParameters();
     for (Transform::ParameterMap::const_iterator i = parameters.begin();
          i != parameters.end(); ++i) {
--- a/transform/Transform.cpp	Fri Dec 05 14:19:04 2008 +0000
+++ b/transform/Transform.cpp	Fri Dec 05 16:18:04 2008 +0000
@@ -31,6 +31,7 @@
 #include <iostream>
 
 Transform::Transform() :
+    m_summaryType(NoSummary),
     m_stepSize(0),
     m_blockSize(0),
     m_windowType(HanningWindow),
@@ -39,6 +40,7 @@
 }
 
 Transform::Transform(QString xml) :
+    m_summaryType(NoSummary),
     m_stepSize(0),
     m_blockSize(0),
     m_windowType(HanningWindow),
@@ -114,6 +116,7 @@
         m_parameters == t.m_parameters &&
         m_configuration == t.m_configuration &&
         m_program == t.m_program &&
+        m_summaryType == t.m_summaryType &&
         m_stepSize == t.m_stepSize &&
         m_blockSize == t.m_blockSize &&
         m_windowType == t.m_windowType &&
@@ -137,6 +140,9 @@
     if (m_program != t.m_program) {
         return m_program < t.m_program;
     }
+    if (m_summaryType != t.m_summaryType) {
+        return int(m_summaryType) < int(t.m_summaryType);
+    }
     if (m_stepSize != t.m_stepSize) {
         return m_stepSize < t.m_stepSize;
     }
@@ -295,6 +301,17 @@
     m_program = program;
 }
 
+Transform::SummaryType
+Transform::getSummaryType() const
+{
+    return m_summaryType;
+}
+
+void
+Transform::setSummaryType(SummaryType type)
+{
+    m_summaryType = type;
+}
     
 size_t
 Transform::getStepSize() const
@@ -387,6 +404,10 @@
         .arg(encodeEntities(m_duration.toString().c_str()))
         .arg(m_sampleRate);
 
+    if (m_summaryType != NoSummary) {
+        out << QString("\n    summaryType=\"%1\"").arg(summaryTypeToString(m_summaryType));
+    }
+
     if (extraAttributes != "") {
         out << " " << extraAttributes;
     }
@@ -419,6 +440,47 @@
     }
 }
 
+Transform::SummaryType
+Transform::stringToSummaryType(QString str)
+{
+    str = str.toLower();
+    if (str == "minimum" || str == "min") return Minimum;
+    if (str == "maximum" || str == "max") return Maximum;
+    if (str == "mean") return Mean;
+    if (str == "median") return Median;
+    if (str == "mode") return Mode;
+    if (str == "sum") return Sum;
+    if (str == "variance") return Variance;
+    if (str == "standard-deviation" || str == "standardDeviation" ||
+        str == "standard deviation" || str == "sd") return StandardDeviation;
+    if (str == "count") return Count;
+    if (str == "") return NoSummary;
+    std::cerr << "Transform::stringToSummaryType: unknown summary type \""
+              << str.toStdString() << "\"" << std::endl;
+    return NoSummary;
+}
+
+QString
+Transform::summaryTypeToString(SummaryType type)
+{
+    switch (type) {
+    case Minimum: return "min";
+    case Maximum: return "max";
+    case Mean: return "mean";
+    case Median: return "median";
+    case Mode: return "mode";
+    case Sum: return "sum";
+    case Variance: return "variance";
+    case StandardDeviation: return "sd";
+    case Count: return "count";
+    case NoSummary: return "";
+    default:
+        std::cerr << "Transform::summaryTypeToString: unexpected summary type "
+                  << int(type) << std::endl;
+        return "";
+    }
+}
+
 void
 Transform::setFromXmlAttributes(const QXmlAttributes &attrs)
 {
@@ -458,5 +520,9 @@
     if (attrs.value("sampleRate") != "") {
         setSampleRate(attrs.value("sampleRate").toFloat());
     }
+
+    if (attrs.value("summaryType") != "") {
+        setSummaryType(stringToSummaryType(attrs.value("summaryType")));
+    }
 }
 
--- a/transform/Transform.h	Fri Dec 05 14:19:04 2008 +0000
+++ b/transform/Transform.h	Fri Dec 05 16:18:04 2008 +0000
@@ -93,6 +93,26 @@
     void setConfiguration(const ConfigurationMap &cm);
     void setConfigurationValue(QString name, QString value);
 
+    enum SummaryType {
+
+        // This is the same as Vamp::PluginSummarisingAdapter::SummaryType
+        // except with NoSummary instead of UnknownSummaryType
+
+        Minimum            = 0,
+        Maximum            = 1,
+        Mean               = 2,
+        Median             = 3,
+        Mode               = 4,
+        Sum                = 5,
+        Variance           = 6,
+        StandardDeviation  = 7,
+        Count              = 8,
+
+        NoSummary          = 999
+    };
+    SummaryType getSummaryType() const;
+    void setSummaryType(SummaryType type);
+
     QString getPluginVersion() const;
     void setPluginVersion(QString version);
 
@@ -135,6 +155,9 @@
      */
     void setFromXmlAttributes(const QXmlAttributes &);
 
+    static SummaryType stringToSummaryType(QString);
+    static QString summaryTypeToString(SummaryType);
+
 protected:
     TransformId m_id; // pluginid:output, that is type:soname:label:output
     
@@ -162,6 +185,7 @@
 
     ParameterMap m_parameters;
     ConfigurationMap m_configuration;
+    SummaryType m_summaryType;
     QString m_pluginVersion;
     QString m_program;
     size_t m_stepSize;
--- a/transform/TransformFactory.cpp	Fri Dec 05 14:19:04 2008 +0000
+++ b/transform/TransformFactory.cpp	Fri Dec 05 16:18:04 2008 +0000
@@ -725,9 +725,11 @@
 {
     Vamp::PluginBase *plugin = instantiateDefaultPluginFor
         (transform.getIdentifier(), transform.getSampleRate());
+
     if (plugin) {
         setPluginParameters(transform, plugin);
     }
+
     return plugin;
 }
 
--- a/transform/TransformFactory.h	Fri Dec 05 14:19:04 2008 +0000
+++ b/transform/TransformFactory.h	Fri Dec 05 16:18:04 2008 +0000
@@ -210,7 +210,6 @@
     void populateRealTimePlugins(TransformDescriptionMap &);
 
     Vamp::PluginBase *instantiateDefaultPluginFor(TransformId id, size_t rate);
-
     QMutex m_transformsMutex;
     QMutex m_uninstalledTransformsMutex;