changeset 152:c43d2e93153f

Provide category and output static info
author Chris Cannam <cannam@all-day-breakfast.com>
date Tue, 13 Jun 2017 17:25:47 +0100
parents 9a0947545d37
children 38675dcea44f
files src/PiperAdapter.h src/PiperPluginLibrary.cpp src/PiperPluginLibrary.h
diffstat 3 files changed, 49 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/src/PiperAdapter.h	Tue Mar 14 16:07:46 2017 +0000
+++ b/src/PiperAdapter.h	Tue Jun 13 17:25:47 2017 +0100
@@ -38,6 +38,7 @@
 #include "vamp-support/PluginStaticData.h"
 #include "vamp-support/PluginConfiguration.h"
 #include "vamp-support/RequestResponse.h"
+#include "vamp-support/StaticOutputDescriptor.h"
 
 #include <vamp-hostsdk/PluginInputDomainAdapter.h>
 #include <vamp-hostsdk/PluginBufferingAdapter.h>
@@ -62,7 +63,12 @@
     const int adaptBufferSize = 0x04;
 
 protected:
-    PiperAdapterBase(std::string libname) : m_soname(libname) { }
+    PiperAdapterBase(std::string libname,
+                     std::vector<std::string> category = {},
+                     piper_vamp::StaticOutputInfo staticOutputInfo = {}) :
+        m_soname(libname),
+        m_category(category),
+        m_staticOutputInfo(staticOutputInfo) { }
     
 public:
     virtual std::string getLibraryName() const override {
@@ -73,8 +79,9 @@
         Vamp::Plugin *p = createPlugin(44100.f);
 	auto data = piper_vamp::PluginStaticData::fromPlugin
 	    (m_soname + ":" + p->getIdentifier(),
-	     {}, //!!! todo: category - tricky one that
+             m_category,
 	     p);
+        data.staticOutputInfo = m_staticOutputInfo;
         delete p;
         return data;
     }
@@ -107,8 +114,9 @@
 
 	response.staticData = piper_vamp::PluginStaticData::fromPlugin
 	    (m_soname + ":" + p->getIdentifier(),
-	     {}, //!!! todo: category - tricky one that
+             m_category,
 	     p);
+        response.staticData.staticOutputInfo = m_staticOutputInfo;
 
 	int defaultChannels = 0;
 	if (p->getMinChannelCount() == p->getMaxChannelCount()) {
@@ -141,13 +149,18 @@
     
 private:
     std::string m_soname;
+    std::vector<std::string> m_category;
+    piper_vamp::StaticOutputInfo m_staticOutputInfo;
 };
 
 template <typename P>
 class PiperAdapter : public PiperAdapterBase<P>
 {
 public:
-    PiperAdapter(std::string libname) : PiperAdapterBase<P>(libname) { }
+    PiperAdapter(std::string libname,
+                 std::vector<std::string> category = {},
+                 piper_vamp::StaticOutputInfo staticOutputInfo = {}) :
+        PiperAdapterBase<P>(libname, category, staticOutputInfo) { }
     
     virtual Vamp::Plugin *createPlugin(float inputSampleRate) const override {
         return new P(inputSampleRate);
--- a/src/PiperPluginLibrary.cpp	Tue Mar 14 16:07:46 2017 +0000
+++ b/src/PiperPluginLibrary.cpp	Tue Jun 13 17:25:47 2017 +0100
@@ -114,6 +114,7 @@
 
 ConfigurationResponse
 PiperPluginLibrary::configurePlugin(ConfigurationRequest req,
+                                    const PluginStaticData &psd,
                                     string &err) const
 {
     for (PluginConfiguration::ParameterMap::const_iterator i =
@@ -127,13 +128,12 @@
     }
 
     ConfigurationResponse response;
-
     response.plugin = req.plugin;
+    response.staticOutputInfo = psd.staticOutputInfo;
 
     Framing pluginPreferredFraming;
     pluginPreferredFraming.stepSize = req.plugin->getPreferredStepSize();
     pluginPreferredFraming.blockSize = req.plugin->getPreferredBlockSize();
-        
     
     if (req.plugin->initialise(req.configuration.channelCount,
                                req.configuration.framing.stepSize,
@@ -171,7 +171,7 @@
             err = "configuration failed (wrong channel count, step size, block size?)";
         }
     }
-
+    
     return response;
 }
 
@@ -258,6 +258,8 @@
                 rj = VampJson::fromError(err, type, id);
             } else {
                 m_mapper.addPlugin(resp.plugin);
+                m_pluginStaticData[m_mapper.pluginToHandle(resp.plugin)] =
+                    resp.staticData;
                 rj = VampJson::fromRpcResponse_Load(resp, m_mapper, id);
             }
         }
@@ -272,11 +274,14 @@
         } else {
             auto h = m_mapper.pluginToHandle(req.plugin);
             if (h == m_mapper.INVALID_HANDLE) {
-                rj = VampJson::fromError("unknown or invalid plugin handle", type, id);
+                rj = VampJson::fromError
+                    ("unknown or invalid plugin handle", type, id);
             } else if (m_mapper.isConfigured(h)) {
-                rj = VampJson::fromError("plugin has already been configured", type, id);
+                rj = VampJson::fromError
+                    ("plugin has already been configured", type, id);
             } else {
-                auto resp = configurePlugin(req, err);
+                PluginStaticData psd(m_pluginStaticData[h]);
+                auto resp = configurePlugin(req, psd, err);
                 if (err != "") {
                     rj = VampJson::fromError(err, type, id);
                 } else {
@@ -302,11 +307,14 @@
             auto h = m_mapper.pluginToHandle(req.plugin);
             int channels = int(req.inputBuffers.size());
             if (h == m_mapper.INVALID_HANDLE) {
-                rj = VampJson::fromError("unknown or invalid plugin handle", type, id);
+                rj = VampJson::fromError
+                    ("unknown or invalid plugin handle", type, id);
             } else if (!m_mapper.isConfigured(h)) {
-                rj = VampJson::fromError("plugin has not been configured", type, id);
+                rj = VampJson::fromError
+                    ("plugin has not been configured", type, id);
             } else if (channels != m_mapper.getChannelCount(h)) {
-                rj = VampJson::fromError("wrong number of channels supplied", type, id);
+                rj = VampJson::fromError
+                    ("wrong number of channels supplied", type, id);
             } else {
 
                 if (serialisation == VampJson::BufferSerialisation::Base64) {
@@ -320,7 +328,8 @@
                     if (req.inputBuffers[i].size() != blockSize) {
                         delete[] fbuffers;
                         fbuffers = 0;
-                        rj = VampJson::fromError("wrong block size supplied", type, id);
+                        rj = VampJson::fromError
+                            ("wrong block size supplied", type, id);
                         break;
                     }
                     fbuffers[i] = req.inputBuffers[i].data();
@@ -347,7 +356,8 @@
         } else {
             auto h = m_mapper.pluginToHandle(req.plugin);
             if (h == m_mapper.INVALID_HANDLE) {
-                rj = VampJson::fromError("unknown or invalid plugin handle", type, id);
+                rj = VampJson::fromError
+                    ("unknown or invalid plugin handle", type, id);
             } else {
 
                 FinishResponse resp;
@@ -363,7 +373,8 @@
 
                 rj = VampJson::fromRpcResponse_Finish
                     (resp, m_mapper, serialisation, id);
-	
+
+                m_pluginStaticData.erase(h);
                 m_mapper.removePlugin(h);
                 delete req.plugin;
             }
--- a/src/PiperPluginLibrary.h	Tue Mar 14 16:07:46 2017 +0000
+++ b/src/PiperPluginLibrary.h	Tue Jun 13 17:25:47 2017 +0100
@@ -72,12 +72,19 @@
     piper_vamp::ListResponse listPluginData(piper_vamp::ListRequest r) const;
     piper_vamp::LoadResponse loadPlugin(piper_vamp::LoadRequest r,
                                         std::string &err) const;
-    piper_vamp::ConfigurationResponse configurePlugin(piper_vamp::ConfigurationRequest r,
-                                                      std::string &err)
+    piper_vamp::ConfigurationResponse
+    configurePlugin(piper_vamp::ConfigurationRequest r,
+                    const piper_vamp::PluginStaticData &psd,
+                    std::string &err)
         const;
 
     // map from pluginKey -> adapter
     std::map<std::string, PiperAdapterInterface *> m_adapters;
+
+    // map from plugin handle -> plugin static data
+    std::map<piper_vamp::PluginHandleMapper::Handle,
+             piper_vamp::PluginStaticData> m_pluginStaticData;
+        
     piper_vamp::CountingPluginHandleMapper m_mapper;
     bool m_useBase64;
 };