changeset 52:4bd0cd3c60f3

Fix erroneous timestamp printing in verbose feature output (it was printing (none) if there was a timestamp instead of if there wasn't); print only diffs; update SDK subrepo
author Chris Cannam
date Fri, 12 Sep 2014 18:05:52 +0100
parents 13db8d010367
children 86d8a699dfbe
files .hgsubstate Test.cpp Test.h TestDefaults.cpp TestMultipleRuns.cpp
diffstat 5 files changed, 150 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/.hgsubstate	Thu Sep 04 09:58:18 2014 +0100
+++ b/.hgsubstate	Fri Sep 12 18:05:52 2014 +0100
@@ -1,1 +1,1 @@
-e43186ff8854485f4985eddf55b77b589a563857 vamp-plugin-sdk
+654a7e9839f648b6eeb81533f8a696560c895501 vamp-plugin-sdk
--- a/Test.cpp	Thu Sep 04 09:58:18 2014 +0100
+++ b/Test.cpp	Fri Sep 12 18:05:52 2014 +0100
@@ -54,8 +54,13 @@
 Test::Test() { }
 Test::~Test() { }
 
+using std::cerr;
+using std::cout;
+using std::endl;
+using std::string;
+
 Plugin *
-Test::load(std::string key, float rate)
+Test::load(string key, float rate)
 {
     Plugin *p = PluginLoader::getInstance()->loadPlugin
         (key, rate, PluginLoader::ADAPT_ALL);
@@ -171,41 +176,126 @@
 }
 
 void
-Test::dump(const Plugin::FeatureSet &fs)
+Test::dumpFeature(const Plugin::Feature &f, bool showValues)
+{
+    cout << "    Timestamp: " << (!f.hasTimestamp ? "(none)" : f.timestamp.toText()) << endl;
+    cout << "    Duration: " << (!f.hasDuration ? "(none)" : f.duration.toText()) << endl;
+    cout << "    Label: " << (f.label == "" ? "(none)" : f.label) << endl;
+    if (showValues) {
+        cout << "    Values (" << f.values.size() << "): " << (f.values.empty() ? "(none)" : "");
+        for (int j = 0; j < (int)f.values.size(); ++j) {
+            cout << f.values[j] << " ";
+        }
+        cout << endl;
+    } else {
+        cout << "    Values (" << f.values.size() << "): (elided)" << endl;
+    }
+}    
+
+void
+Test::dump(const Plugin::FeatureSet &fs, bool showValues)
 {
     for (Plugin::FeatureSet::const_iterator fsi = fs.begin();
          fsi != fs.end(); ++fsi) {
         int output = fsi->first;
-        std::cout << "Output " << output << ":" << std::endl;
+        cout << "Output " << output << ":" << endl;
         const Plugin::FeatureList &fl = fsi->second;
         for (int i = 0; i < (int)fl.size(); ++i) {
-            std::cout << "  Feature " << i << ":" << std::endl;
+            cout << "  Feature " << i << ":" << endl;
             const Plugin::Feature &f = fl[i];
-            std::cout << "    Timestamp: " << (f.hasTimestamp ? "(none)" : f.timestamp.toText()) << std::endl;
-            std::cout << "    Duration: " << (f.hasDuration ? "(none)" : f.duration.toText()) << std::endl;
-            std::cout << "    Label: " << (f.label == "" ? "(none)" : f.label) << std::endl;
-            std::cout << "    Value: " << (f.values.empty() ? "(none)" : "");
-            for (int j = 0; j < (int)f.values.size(); ++j) {
-                std::cout << f.values[j] << " ";
-            }
-            std::cout << std::endl;
+            dumpFeature(f, showValues);
         }
     }
 }
 
 void
-Test::dump(const Result &r,
-           const Plugin::FeatureSet &a,
-           const Plugin::FeatureSet &b)
+Test::dumpTwo(const Result &r,
+              const Plugin::FeatureSet &a,
+              const Plugin::FeatureSet &b)
 {
     std::cout << r.message() << std::endl;
     std::cout << "\nFirst result set:" << std::endl;
-    dump(a);
+    dump(a, false);
     std::cout << "\nSecond result set:" << std::endl;
-    dump(b);
+    dump(b, false);
     std::cout << std::endl;
 }
 
+void
+Test::dumpDiff(const Result &r,
+               const Plugin::FeatureSet &a,
+               const Plugin::FeatureSet &b)
+{
+    cout << r.message() << endl;
+    cout << "\nDifferences follow:" << endl;
+    if (a.size() != b.size()) {
+        cout << "*** First result set has features on " << a.size() 
+                  << " output(s), second has features on " << b.size()
+                  << endl;
+        return;
+    }
+    Plugin::FeatureSet::const_iterator ai = a.begin();
+    Plugin::FeatureSet::const_iterator bi = b.begin();
+    while (ai != a.end()) {
+        if (ai->first != bi->first) {
+            cout << "\n*** Output number mismatch: first result set says "
+                      << ai->first << " where second says " << bi->first
+                      << endl;
+        } else {
+            cout << "\nOutput " << ai->first << ":" << endl;
+            if (ai->second.size() != bi->second.size()) {
+                cout << "*** First result set has " << ai->second.size()
+                          << " feature(s) on this output, second has "
+                          << bi->second.size() << endl;
+            } else {
+                int fno = 0;
+                int diffcount = 0;
+                Plugin::FeatureList::const_iterator afi = ai->second.begin();
+                Plugin::FeatureList::const_iterator bfi = bi->second.begin();
+                while (afi != ai->second.end()) {
+                    if (!(*afi == *bfi)) {
+                        if (diffcount == 0) {
+                            bool differInValues = (afi->values != bfi->values);
+                            if (afi->hasTimestamp != bfi->hasTimestamp) {
+                                cout << "*** Feature " << fno << " differs in presence of timestamp (" << afi->hasTimestamp << " vs " << bfi->hasTimestamp << ")" << endl;
+                            }
+                            if (afi->hasTimestamp && (afi->timestamp != bfi->timestamp)) {
+                                cout << "*** Feature " << fno << " differs in timestamp (" << afi->timestamp << " vs " << bfi->timestamp << " )" << endl;
+                            }
+                            if (afi->hasDuration != bfi->hasDuration) {
+                                cout << "*** Feature " << fno << " differs in presence of duration (" << afi->hasDuration << " vs " << bfi->hasDuration << ")" << endl;
+                            }
+                            if (afi->hasDuration && (afi->duration != bfi->duration)) {
+                                cout << "*** Feature " << fno << " differs in duration (" << afi->duration << " vs " << bfi->duration << " )" << endl;
+                            }
+                            if (afi->label != bfi->label) {
+                                cout << "*** Feature " << fno << " differs in label" << endl;
+                            }
+                            if (differInValues) {
+                                cout << "*** Feature " << fno << " differs in values" << endl;
+                            }
+                            cout << "  First output:" << endl;
+                            dumpFeature(*afi, differInValues);
+                            cout << "  Second output:" << endl;
+                            dumpFeature(*bfi, differInValues);
+                        }
+                        ++diffcount;
+                    }
+                    ++fno;
+                    ++afi;
+                    ++bfi;
+                }
+                if (diffcount > 1) {
+                    cout << diffcount-1 << " subsequent differing feature(s) elided" << endl;
+                }
+            }
+        }                
+        ++ai;
+        ++bi;
+    }
+    cout << endl;
+}
+
 bool
 operator==(const Plugin::FeatureSet &a, const Plugin::FeatureSet &b)
 {
--- a/Test.h	Thu Sep 04 09:58:18 2014 +0100
+++ b/Test.h	Fri Sep 12 18:05:52 2014 +0100
@@ -110,10 +110,14 @@
 
     bool allFeaturesValid(const Vamp::Plugin::FeatureSet &); // i.e. no NaN/inf
 
-    void dump(const Vamp::Plugin::FeatureSet &);
-    void dump(const Result &r,
-              const Vamp::Plugin::FeatureSet &,
-              const Vamp::Plugin::FeatureSet &);
+    void dumpFeature(const Vamp::Plugin::Feature &, bool showValues);
+    void dump(const Vamp::Plugin::FeatureSet &, bool showValues = true);
+    void dumpTwo(const Result &r,
+                 const Vamp::Plugin::FeatureSet &,
+                 const Vamp::Plugin::FeatureSet &);
+    void dumpDiff(const Result &r,
+                  const Vamp::Plugin::FeatureSet &,
+                  const Vamp::Plugin::FeatureSet &);
 };
 
 extern bool operator==(const Vamp::Plugin::FeatureSet &a,
--- a/TestDefaults.cpp	Thu Sep 04 09:58:18 2014 +0100
+++ b/TestDefaults.cpp	Fri Sep 12 18:05:52 2014 +0100
@@ -103,7 +103,7 @@
         Result res;
         if (options & NonDeterministic) res = note(message);
         else res = error(message);
-        if (options & Verbose) dump(res, f[0], f[1]);
+        if (options & Verbose) dumpDiff(res, f[0], f[1]);
         r.push_back(res);
     } else {
         r.push_back(success());
@@ -163,7 +163,7 @@
         Result res;
         if (options & NonDeterministic) res = note(message);
         else res = error(message);
-        if (options & Verbose) dump(res, f[0], f[1]);
+        if (options & Verbose) dumpDiff(res, f[0], f[1]);
         r.push_back(res);
     } else {
         r.push_back(success());
@@ -224,7 +224,30 @@
             p->setParameter(pl[i].identifier, value);
         }
 
-        if (!initAdapted(p.get(), channels, _step, _step, r)) return r;
+        if (!initAdapted(p.get(), channels, _step, _step, r)) {
+
+            // OK, plugin didn't like that. Let's try a different tack
+            // -- set everything to min except those parameters whose
+            // default is min, and set those to half way instead
+            
+            for (int i = 0; i < (int)pl.size(); ++i) {
+                float value = pl[i].minValue;
+                if (value == pl[i].defaultValue) {
+                    value = (pl[i].maxValue + pl[i].minValue) / 2;
+                    value = ceil(value / pl[i].quantizeStep) * pl[i].quantizeStep;
+                    if (value > pl[i].maxValue) {
+                        value = pl[i].maxValue;
+                    }
+                }
+                p->setParameter(pl[i].identifier, value);
+            }
+
+            r = Results();
+            if (!initAdapted(p.get(), channels, _step, _step, r)) {
+                // Still didn't work, give up
+                return r;
+            }
+        }
 
         //  First run: construct, set params, init, process
         // Second run: construct, set params, init, reset, process
@@ -254,7 +277,7 @@
         Result res;
         if (options & NonDeterministic) res = note(message);
         else res = error(message);
-        if (options & Verbose) dump(res, f[0], f[1]);
+        if (options & Verbose) dumpDiff(res, f[0], f[1]);
         r.push_back(res);
     } else {
         r.push_back(success());
--- a/TestMultipleRuns.cpp	Thu Sep 04 09:58:18 2014 +0100
+++ b/TestMultipleRuns.cpp	Fri Sep 12 18:05:52 2014 +0100
@@ -101,7 +101,7 @@
         string message = "Consecutive runs with separate instances produce different results";
         if (options & NonDeterministic) res = note(message);
         else res = error(message);
-        if (options & Verbose) dump(res, f[0], f[1]);
+        if (options & Verbose) dumpDiff(res, f[0], f[1]);
         r.push_back(res);
     } else {
         r.push_back(success());
@@ -148,7 +148,7 @@
         Result res;
         if (options & NonDeterministic) res = note(message);
         else res = error(message);
-        if (options & Verbose) dump(res, f[0], f[1]);
+        if (options & Verbose) dumpDiff(res, f[0], f[1]);
         r.push_back(res);
     } else {
         r.push_back(success());
@@ -204,7 +204,7 @@
         Result res;
         if (options & NonDeterministic) res = note(message);
         else res = error(message);
-        if (options & Verbose) dump(res, f[0], f[1]);
+        if (options & Verbose) dumpDiff(res, f[0], f[1]);
         r.push_back(res);
     } else {
         r.push_back(success());
@@ -250,7 +250,10 @@
         Result res;
         if (options & NonDeterministic) res = note(message);
         else res = warning(message);
-        if (options & Verbose) dump(res, f[0], f[1]);
+        if (options & Verbose) {
+            cout << message << endl;
+            dump(f[0], false);
+        }
         r.push_back(res);
     } else {
         r.push_back(success());