changeset 98:f55631599988

Plugin that creates its own server
author Chris Cannam <c.cannam@qmul.ac.uk>
date Thu, 13 Oct 2016 19:11:24 +0100
parents 427c4c725085
children b2ec891c22b9
files vamp-client/AutoPlugin.h vamp-client/Makefile vamp-client/client.cpp vamp-client/client.pro
diffstat 4 files changed, 175 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vamp-client/AutoPlugin.h	Thu Oct 13 19:11:24 2016 +0100
@@ -0,0 +1,148 @@
+
+#ifndef PIPER_AUTO_PLUGIN_H
+#define PIPER_AUTO_PLUGIN_H
+
+#include "ProcessQtTransport.h"
+#include "CapnpRRClient.h"
+
+#include <cstdint>
+
+namespace piper_vamp {
+namespace client {
+
+class AutoPlugin : public Vamp::Plugin
+{
+public:
+    AutoPlugin(std::string pluginKey,
+	       float inputSampleRate,
+	       int adapterFlags) :
+	Vamp::Plugin(inputSampleRate),
+	m_transport("../bin/piper-vamp-server"), //!!!*£*$&"$*"
+	m_client(&m_transport)
+    {
+	LoadRequest req;
+	req.pluginKey = pluginKey;
+	req.inputSampleRate = inputSampleRate;
+	req.adapterFlags = adapterFlags;
+	LoadResponse resp = m_client.loadPlugin(req);
+	m_plugin = resp.plugin;
+    }
+
+    virtual ~AutoPlugin() {
+	delete m_plugin;
+    }
+
+    bool isOK() const {
+	return (m_plugin != nullptr);
+    }
+    
+    virtual std::string getIdentifier() const {
+	return getPlugin()->getIdentifier();
+    }
+
+    virtual std::string getName() const {
+	return getPlugin()->getName();
+    }
+
+    virtual std::string getDescription() const {
+	return getPlugin()->getDescription();
+    }
+
+    virtual std::string getMaker() const {
+	return getPlugin()->getMaker();
+    }
+
+    virtual std::string getCopyright() const {
+	return getPlugin()->getCopyright();
+    }
+
+    virtual int getPluginVersion() const {
+        return getPlugin()->getPluginVersion();
+    }
+
+    virtual ParameterList getParameterDescriptors() const {
+	return getPlugin()->getParameterDescriptors();
+    }
+
+    virtual float getParameter(std::string name) const {
+	return getPlugin()->getParameter(name);
+    }
+
+    virtual void setParameter(std::string name, float value) {
+	getPlugin()->setParameter(name, value);
+    }
+
+    virtual ProgramList getPrograms() const {
+        return getPlugin()->getPrograms();
+    }
+
+    virtual std::string getCurrentProgram() const {
+        return getPlugin()->getCurrentProgram();
+    }
+    
+    virtual void selectProgram(std::string program) {
+	getPlugin()->selectProgram(program);
+    }
+
+    virtual bool initialise(size_t inputChannels,
+                            size_t stepSize,
+                            size_t blockSize) {
+	return getPlugin()->initialise(inputChannels, stepSize, blockSize);
+    }
+
+    virtual void reset() {
+	getPlugin()->reset();
+    }
+
+    virtual InputDomain getInputDomain() const {
+	return getPlugin()->getInputDomain();
+    }
+
+    virtual size_t getPreferredBlockSize() const {
+	return getPlugin()->getPreferredBlockSize();
+    }
+
+    virtual size_t getPreferredStepSize() const {
+	return getPlugin()->getPreferredStepSize();
+    }
+
+    virtual size_t getMinChannelCount() const {
+	return getPlugin()->getMinChannelCount();
+    }
+
+    virtual size_t getMaxChannelCount() const {
+	return getPlugin()->getMaxChannelCount();
+    }
+
+    virtual OutputList getOutputDescriptors() const {
+	return getPlugin()->getOutputDescriptors();
+    }
+
+    virtual FeatureSet process(const float *const *inputBuffers,
+			       Vamp::RealTime timestamp) {
+	return getPlugin()->process(inputBuffers, timestamp);
+    }
+
+    virtual FeatureSet getRemainingFeatures() {
+	return getPlugin()->getRemainingFeatures();
+    }
+
+private:
+    ProcessQtTransport m_transport;
+    CapnpRRClient m_client;
+    Vamp::Plugin *m_plugin;
+    Vamp::Plugin *getPlugin() const {
+	if (!m_plugin) {
+	    throw std::logic_error
+		("Plugin load failed (should have called AutoPlugin::isOK)");
+	}
+	return m_plugin;
+    }
+};
+
+}
+}
+
+#endif
+
+    
--- a/vamp-client/Makefile	Thu Oct 13 18:05:35 2016 +0100
+++ b/vamp-client/Makefile	Thu Oct 13 19:11:24 2016 +0100
@@ -216,6 +216,7 @@
 		Loader.h \
 		PluginClient.h \
 		PluginStub.h \
+		AutoPlugin.h \
 		SynchronousTransport.h client.cpp \
 		../vamp-capnp/piper.capnp.c++
 QMAKE_TARGET  = client
@@ -566,7 +567,7 @@
 distdir: FORCE
 	@test -d $(DISTDIR) || mkdir -p $(DISTDIR)
 	$(COPY_FILE) --parents $(DIST) $(DISTDIR)/
-	$(COPY_FILE) --parents ProcessQtTransport.h CapnpRRClient.h Loader.h PluginClient.h PluginStub.h SynchronousTransport.h $(DISTDIR)/
+	$(COPY_FILE) --parents ProcessQtTransport.h CapnpRRClient.h Loader.h PluginClient.h PluginStub.h AutoPlugin.h SynchronousTransport.h $(DISTDIR)/
 	$(COPY_FILE) --parents client.cpp ../vamp-capnp/piper.capnp.c++ $(DISTDIR)/
 
 
@@ -612,7 +613,8 @@
 		CapnpRRClient.h \
 		Loader.h \
 		PluginClient.h \
-		PluginStub.h
+		PluginStub.h \
+		AutoPlugin.h
 	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o ../o/client.o client.cpp
 
 ../o/piper.capnp.o: ../vamp-capnp/piper.capnp.c++ ../vamp-capnp/piper.capnp.h
--- a/vamp-client/client.cpp	Thu Oct 13 18:05:35 2016 +0100
+++ b/vamp-client/client.cpp	Thu Oct 13 19:11:24 2016 +0100
@@ -1,6 +1,7 @@
 
 #include "ProcessQtTransport.h"
 #include "CapnpRRClient.h"
+#include "AutoPlugin.h"
 
 #include <stdexcept>
 
@@ -58,5 +59,26 @@
     (void)plugin->getRemainingFeatures();
 
     delete plugin;
+
+    // Let's try a crazy AutoPlugin
+
+    piper_vamp::client::AutoPlugin ap("vamp-example-plugins:zerocrossing", 16, 0);
+    if (!ap.isOK()) {
+	cerr << "AutoPlugin creation failed" << endl;
+    } else {
+	if (!ap.initialise(1, 4, 4)) {
+	    cerr << "initialisation failed" << endl;
+	} else {
+	    std::vector<float> buf = { 1.0, -1.0, 1.0, -1.0 };
+	    float *bd = buf.data();
+	    Vamp::Plugin::FeatureSet features = ap.process
+		(&bd, Vamp::RealTime::zeroTime);
+	    cerr << "results for output 0:" << endl;
+	    auto fl(features[0]);
+	    for (const auto &f: fl) {
+		cerr << f.values[0] << endl;
+	    }
+	}
+    }
 }
 
--- a/vamp-client/client.pro	Thu Oct 13 18:05:35 2016 +0100
+++ b/vamp-client/client.pro	Thu Oct 13 19:11:24 2016 +0100
@@ -34,6 +34,7 @@
         Loader.h \
         PluginClient.h \
         PluginStub.h \
+        AutoPlugin.h \
         SynchronousTransport.h