annotate vamp-client/AutoPlugin.h @ 116:d15cb1151d76

Add JSON support directly to the server. Had hoped to avoid this (using Capnp as canonical in the server and then converting externally as necessary) but it's just too useful for debugging purposes when bundled with client app
author Chris Cannam <c.cannam@qmul.ac.uk>
date Thu, 27 Oct 2016 11:39:41 +0100
parents d74dfc11927c
children ff3fd8d1b2dc
rev   line source
cannam@111 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
c@98 2
c@98 3 #ifndef PIPER_AUTO_PLUGIN_H
c@98 4 #define PIPER_AUTO_PLUGIN_H
c@98 5
c@98 6 #include "ProcessQtTransport.h"
c@98 7 #include "CapnpRRClient.h"
c@98 8
c@98 9 #include <cstdint>
c@98 10
c@98 11 namespace piper_vamp {
c@98 12 namespace client {
c@98 13
c@98 14 class AutoPlugin : public Vamp::Plugin
c@98 15 {
c@98 16 public:
c@101 17 AutoPlugin(std::string serverName,
c@101 18 std::string pluginKey,
c@98 19 float inputSampleRate,
c@98 20 int adapterFlags) :
c@98 21 Vamp::Plugin(inputSampleRate),
c@101 22 m_transport(serverName),
c@98 23 m_client(&m_transport)
c@98 24 {
c@98 25 LoadRequest req;
c@98 26 req.pluginKey = pluginKey;
c@98 27 req.inputSampleRate = inputSampleRate;
c@98 28 req.adapterFlags = adapterFlags;
c@98 29 LoadResponse resp = m_client.loadPlugin(req);
c@98 30 m_plugin = resp.plugin;
c@98 31 }
c@98 32
c@98 33 virtual ~AutoPlugin() {
c@98 34 delete m_plugin;
c@98 35 }
c@98 36
c@98 37 bool isOK() const {
c@98 38 return (m_plugin != nullptr);
c@98 39 }
c@98 40
c@98 41 virtual std::string getIdentifier() const {
c@98 42 return getPlugin()->getIdentifier();
c@98 43 }
c@98 44
c@98 45 virtual std::string getName() const {
c@98 46 return getPlugin()->getName();
c@98 47 }
c@98 48
c@98 49 virtual std::string getDescription() const {
c@98 50 return getPlugin()->getDescription();
c@98 51 }
c@98 52
c@98 53 virtual std::string getMaker() const {
c@98 54 return getPlugin()->getMaker();
c@98 55 }
c@98 56
c@98 57 virtual std::string getCopyright() const {
c@98 58 return getPlugin()->getCopyright();
c@98 59 }
c@98 60
c@98 61 virtual int getPluginVersion() const {
c@98 62 return getPlugin()->getPluginVersion();
c@98 63 }
c@98 64
c@98 65 virtual ParameterList getParameterDescriptors() const {
c@98 66 return getPlugin()->getParameterDescriptors();
c@98 67 }
c@98 68
c@98 69 virtual float getParameter(std::string name) const {
c@98 70 return getPlugin()->getParameter(name);
c@98 71 }
c@98 72
c@98 73 virtual void setParameter(std::string name, float value) {
c@98 74 getPlugin()->setParameter(name, value);
c@98 75 }
c@98 76
c@98 77 virtual ProgramList getPrograms() const {
c@98 78 return getPlugin()->getPrograms();
c@98 79 }
c@98 80
c@98 81 virtual std::string getCurrentProgram() const {
c@98 82 return getPlugin()->getCurrentProgram();
c@98 83 }
c@98 84
c@98 85 virtual void selectProgram(std::string program) {
c@98 86 getPlugin()->selectProgram(program);
c@98 87 }
c@98 88
c@98 89 virtual bool initialise(size_t inputChannels,
c@98 90 size_t stepSize,
c@98 91 size_t blockSize) {
c@98 92 return getPlugin()->initialise(inputChannels, stepSize, blockSize);
c@98 93 }
c@98 94
c@98 95 virtual void reset() {
c@98 96 getPlugin()->reset();
c@98 97 }
c@98 98
c@98 99 virtual InputDomain getInputDomain() const {
c@98 100 return getPlugin()->getInputDomain();
c@98 101 }
c@98 102
c@98 103 virtual size_t getPreferredBlockSize() const {
c@98 104 return getPlugin()->getPreferredBlockSize();
c@98 105 }
c@98 106
c@98 107 virtual size_t getPreferredStepSize() const {
c@98 108 return getPlugin()->getPreferredStepSize();
c@98 109 }
c@98 110
c@98 111 virtual size_t getMinChannelCount() const {
c@98 112 return getPlugin()->getMinChannelCount();
c@98 113 }
c@98 114
c@98 115 virtual size_t getMaxChannelCount() const {
c@98 116 return getPlugin()->getMaxChannelCount();
c@98 117 }
c@98 118
c@98 119 virtual OutputList getOutputDescriptors() const {
c@98 120 return getPlugin()->getOutputDescriptors();
c@98 121 }
c@98 122
c@98 123 virtual FeatureSet process(const float *const *inputBuffers,
c@98 124 Vamp::RealTime timestamp) {
c@98 125 return getPlugin()->process(inputBuffers, timestamp);
c@98 126 }
c@98 127
c@98 128 virtual FeatureSet getRemainingFeatures() {
c@98 129 return getPlugin()->getRemainingFeatures();
c@98 130 }
c@98 131
c@98 132 private:
c@98 133 ProcessQtTransport m_transport;
c@98 134 CapnpRRClient m_client;
c@98 135 Vamp::Plugin *m_plugin;
c@98 136 Vamp::Plugin *getPlugin() const {
c@98 137 if (!m_plugin) {
c@98 138 throw std::logic_error
c@98 139 ("Plugin load failed (should have called AutoPlugin::isOK)");
c@98 140 }
c@98 141 return m_plugin;
c@98 142 }
c@98 143 };
c@98 144
c@98 145 }
c@98 146 }
c@98 147
c@98 148 #endif
c@98 149
c@98 150