changeset 1249:d45a16c232bd piper

Align Sonic Annotator with the new Piper-ified subrepos (bearing in mind we want neither Piper nor the plugin load checker in Sonic Annotator itself)
author Chris Cannam
date Fri, 04 Nov 2016 14:16:01 +0000
parents 58dd6a6fe414
children c2d66e3c83d0
files plugin/FeatureExtractionPluginFactory.cpp plugin/NativeVampPluginFactory.cpp plugin/PiperVampPluginFactory.cpp plugin/PiperVampPluginFactory.h plugin/PluginScan.cpp plugin/PluginScan.h svcore.pro
diffstat 7 files changed, 111 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/plugin/FeatureExtractionPluginFactory.cpp	Thu Nov 03 15:38:17 2016 +0000
+++ b/plugin/FeatureExtractionPluginFactory.cpp	Fri Nov 04 14:16:01 2016 +0000
@@ -20,6 +20,7 @@
 #include <QMutexLocker>
 
 #include "base/Preferences.h"
+#include "base/Debug.h"
 
 FeatureExtractionPluginFactory *
 FeatureExtractionPluginFactory::instance()
@@ -31,13 +32,21 @@
     
     if (!instance) {
 
+#ifdef HAVE_PIPER
         if (Preferences::getInstance()->getRunPluginsInProcess()) {
-            cerr << "creating native instance" << endl;
+            SVDEBUG << "FeatureExtractionPluginFactory: creating native instance"
+                    << endl;
             instance = new NativeVampPluginFactory();
         } else {
-            cerr << "creating piper instance" << endl;
+            SVDEBUG << "FeatureExtractionPluginFactory: creating Piper instance"
+                    << endl;
             instance = new PiperVampPluginFactory();
         }
+#else
+        SVDEBUG << "FeatureExtractionPluginFactory: no Piper support enabled,"
+                << " creating native instance" << endl;
+        instance = new NativeVampPluginFactory();
+#endif
     }
 
     return instance;
--- a/plugin/NativeVampPluginFactory.cpp	Thu Nov 03 15:38:17 2016 +0000
+++ b/plugin/NativeVampPluginFactory.cpp	Fri Nov 04 14:16:01 2016 +0000
@@ -70,6 +70,40 @@
     return m_pluginPath;
 }
 
+static
+QList<PluginScan::Candidate>
+getCandidateLibraries()
+{
+#ifdef HAVE_PLUGIN_CHECKER_HELPER
+    return PluginScan::getInstance()->getCandidateLibrariesFor
+        (PluginScan::VampPlugin);
+#else
+    auto path = Vamp::PluginHostAdapter::getPluginPath();
+    QList<PluginScan::Candidate> candidates;
+    for (string dirname: path) {
+        SVDEBUG << "NativeVampPluginFactory: scanning directory myself: "
+                << dirname << endl;
+#if defined(_WIN32)
+#define PLUGIN_GLOB "*.dll"
+#elif defined(__APPLE__)
+#define PLUGIN_GLOB "*.dylib *.so"
+#else
+#define PLUGIN_GLOB "*.so"
+#endif
+        QDir dir(dirname.c_str(), PLUGIN_GLOB,
+                 QDir::Name | QDir::IgnoreCase,
+                 QDir::Files | QDir::Readable);
+
+        for (unsigned int i = 0; i < dir.count(); ++i) {
+            QString soname = dir.filePath(dir[i]);
+            candidates.push_back({ soname, "" });
+        }
+    }
+
+    return candidates;
+#endif
+}
+
 vector<QString>
 NativeVampPluginFactory::getPluginIdentifiers(QString &)
 {
@@ -80,14 +114,17 @@
     if (!m_identifiers.empty()) {
         return m_identifiers;
     }
+
+    auto candidates = getCandidateLibraries();
     
-    auto candidates = PluginScan::getInstance()->getCandidateLibrariesFor
-        (PluginScan::VampPlugin);
-    
+    SVDEBUG << "INFO: Have " << candidates.size() << " candidate Vamp plugin libraries" << endl;
+        
     for (auto candidate : candidates) {
 
         QString soname = candidate.libraryPath;
 
+        SVDEBUG << "INFO: Considering candidate Vamp plugin library " << soname << endl;
+        
         void *libraryHandle = DLOPEN(soname, RTLD_LAZY | RTLD_LOCAL);
             
         if (!libraryHandle) {
--- a/plugin/PiperVampPluginFactory.cpp	Thu Nov 03 15:38:17 2016 +0000
+++ b/plugin/PiperVampPluginFactory.cpp	Fri Nov 04 14:16:01 2016 +0000
@@ -13,6 +13,8 @@
     COPYING included with this distribution for more information.
 */
 
+#ifdef HAVE_PIPER
+
 #include "PiperVampPluginFactory.h"
 #include "PluginIdentifier.h"
 
@@ -167,6 +169,8 @@
     auto candidateLibraries =
         scan->getCandidateLibrariesFor(PluginScan::VampPlugin);
 
+    SVDEBUG << "INFO: Have " << candidates.size() << " candidate Vamp plugin libraries" << endl;
+        
     vector<string> from;
     for (const auto &c: candidateLibraries) {
         if (c.helperTag == tag) {
@@ -242,3 +246,4 @@
     }
 }
 
+#endif
--- a/plugin/PiperVampPluginFactory.h	Thu Nov 03 15:38:17 2016 +0000
+++ b/plugin/PiperVampPluginFactory.h	Fri Nov 04 14:16:01 2016 +0000
@@ -16,6 +16,8 @@
 #ifndef SV_PIPER_VAMP_PLUGIN_FACTORY_H
 #define SV_PIPER_VAMP_PLUGIN_FACTORY_H
 
+#ifdef HAVE_PIPER
+
 #include "FeatureExtractionPluginFactory.h"
 
 #include <QMutex>
@@ -60,3 +62,5 @@
 };
 
 #endif
+
+#endif
--- a/plugin/PluginScan.cpp	Thu Nov 03 15:38:17 2016 +0000
+++ b/plugin/PluginScan.cpp	Fri Nov 04 14:16:01 2016 +0000
@@ -18,14 +18,21 @@
 #include "base/Preferences.h"
 #include "base/HelperExecPath.h"
 
+#ifdef HAVE_PLUGIN_CHECKER_HELPER
 #include "checker/knownplugins.h"
+#else
+class KnownPlugins {};
+#endif
 
 #include <QMutex>
 #include <QCoreApplication>
 
 using std::string;
 
-class PluginScan::Logger : public PluginCandidates::LogCallback
+class PluginScan::Logger
+#ifdef HAVE_PLUGIN_CHECKER_HELPER
+    : public PluginCandidates::LogCallback
+#endif
 {
 protected:
     void log(std::string message) {
@@ -55,6 +62,8 @@
 void
 PluginScan::scan()
 {
+#ifdef HAVE_PLUGIN_CHECKER_HELPER
+
     QMutexLocker locker(&m_mutex);
 
     bool inProcess = Preferences::getInstance()->getRunPluginsInProcess();
@@ -96,6 +105,8 @@
                  << " (with helper path = " << p.executable << ")" << endl;
         }
     }
+
+#endif
 }
 
 bool
@@ -118,6 +129,8 @@
 QList<PluginScan::Candidate>
 PluginScan::getCandidateLibrariesFor(PluginType type) const
 {
+#ifdef HAVE_PLUGIN_CHECKER_HELPER
+    
     QMutexLocker locker(&m_mutex);
 
     KnownPlugins::PluginType kpt;
@@ -157,11 +170,17 @@
     }
 
     return candidates;
+    
+#else
+    return {};
+#endif
 }
 
 QString
 PluginScan::getStartupFailureReport() const
 {
+#ifdef HAVE_PLUGIN_CHECKER_HELPER
+    
     QMutexLocker locker(&m_mutex);
 
     if (!m_succeeded) {
@@ -191,5 +210,9 @@
         + QObject::tr("<p>These plugins may be incompatible with the system, "
                       "and will be ignored during this run of %1.</p>")
         .arg(QCoreApplication::applicationName());
+
+#else
+    return "";
+#endif
 }
 
--- a/plugin/PluginScan.h	Thu Nov 03 15:38:17 2016 +0000
+++ b/plugin/PluginScan.h	Fri Nov 04 14:16:01 2016 +0000
@@ -27,8 +27,21 @@
 public:
     static PluginScan *getInstance();
 
+    /**
+     * Carry out startup scan of available plugins. Do not call
+     * getCandidateLibrariesFor() unless this has been called and
+     * scanSucceeded() is returning true.
+     */
     void scan();
 
+    /**
+     * Return true if scan() completed successfully. If the scan
+     * failed, consider using the normal plugin path to load any
+     * available plugins (as if they had all been found to be
+     * loadable) rather than rejecting all of them -- i.e. consider
+     * falling back on the behaviour of code from before the scan
+     * logic was added.
+     */
     bool scanSucceeded() const;
     
     enum PluginType {
@@ -37,9 +50,19 @@
 	DSSIPlugin
     };
     struct Candidate {
-        QString libraryPath;
-        QString helperTag;
+        QString libraryPath;    // full path, not just soname
+        QString helperTag;      // identifies the helper that found it
+                                // (see HelperExecPath) 
     };
+
+    /**
+     * Return the candidate plugin libraries of the given type that
+     * were found by helpers during the startup scan.
+     *
+     * This could return an empty list for two reasons: the scan
+     * succeeded but no libraries were found; or the scan failed. Call
+     * scanSucceeded() to distinguish between them.
+     */
     QList<Candidate> getCandidateLibrariesFor(PluginType) const;
 
     QString getStartupFailureReport() const;
--- a/svcore.pro	Thu Nov 03 15:38:17 2016 +0000
+++ b/svcore.pro	Fri Nov 04 14:16:01 2016 +0000
@@ -29,6 +29,6 @@
 
 include(files.pri)
 
-HEADERS = $$(SVCORE_HEADERS)
-SOURCES = $$(SVCORE_SOURCES)
+HEADERS = $$SVCORE_HEADERS
+SOURCES = $$SVCORE_SOURCES