annotate vamp-client/qt/PiperAutoPlugin.h @ 208:c67a0a945b6b

Rename PluginStub to PiperVampPlugin and AutoPlugin to PiperAutoPlugin
author Chris Cannam <cannam@all-day-breakfast.com>
date Thu, 09 Feb 2017 13:31:46 +0000
parents
children df65480a08de
rev   line source
cannam@208 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
cannam@208 2 /*
cannam@208 3 Piper C++
cannam@208 4
cannam@208 5 An API for audio analysis and feature extraction plugins.
cannam@208 6
cannam@208 7 Centre for Digital Music, Queen Mary, University of London.
cannam@208 8 Copyright 2006-2017 Chris Cannam and QMUL.
cannam@208 9
cannam@208 10 Permission is hereby granted, free of charge, to any person
cannam@208 11 obtaining a copy of this software and associated documentation
cannam@208 12 files (the "Software"), to deal in the Software without
cannam@208 13 restriction, including without limitation the rights to use, copy,
cannam@208 14 modify, merge, publish, distribute, sublicense, and/or sell copies
cannam@208 15 of the Software, and to permit persons to whom the Software is
cannam@208 16 furnished to do so, subject to the following conditions:
cannam@208 17
cannam@208 18 The above copyright notice and this permission notice shall be
cannam@208 19 included in all copies or substantial portions of the Software.
cannam@208 20
cannam@208 21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
cannam@208 22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
cannam@208 23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
cannam@208 24 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
cannam@208 25 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
cannam@208 26 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
cannam@208 27 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
cannam@208 28
cannam@208 29 Except as contained in this notice, the names of the Centre for
cannam@208 30 Digital Music; Queen Mary, University of London; and Chris Cannam
cannam@208 31 shall not be used in advertising or otherwise to promote the sale,
cannam@208 32 use or other dealings in this Software without prior written
cannam@208 33 authorization.
cannam@208 34 */
cannam@208 35
cannam@208 36 #ifndef PIPER_AUTO_PLUGIN_H
cannam@208 37 #define PIPER_AUTO_PLUGIN_H
cannam@208 38
cannam@208 39 #include "ProcessQtTransport.h"
cannam@208 40 #include "../CapnpRRClient.h"
cannam@208 41 #include "../Exceptions.h"
cannam@208 42
cannam@208 43 #include <cstdint>
cannam@208 44
cannam@208 45 namespace piper_vamp {
cannam@208 46 namespace client {
cannam@208 47
cannam@208 48 /**
cannam@208 49 * This "plugin" make the Piper client abstraction behave like a local
cannam@208 50 * Vamp plugin, with its own server that lasts only for the lifetime
cannam@208 51 * of this plugin and serves only it.
cannam@208 52 *
cannam@208 53 * Note that any method may throw ServerCrashed, RequestTimedOut or
cannam@208 54 * ProtocolError exceptions.
cannam@208 55 */
cannam@208 56 class PiperAutoPlugin : public Vamp::Plugin
cannam@208 57 {
cannam@208 58 public:
cannam@208 59 PiperAutoPlugin(std::string serverName,
cannam@208 60 std::string pluginKey,
cannam@208 61 float inputSampleRate,
cannam@208 62 int adapterFlags,
cannam@208 63 LogCallback *logger) : // logger may be nullptr for cerr
cannam@208 64 Vamp::Plugin(inputSampleRate),
cannam@208 65 m_logger(logger),
cannam@208 66 m_transport(serverName, "capnp", logger),
cannam@208 67 m_client(&m_transport, logger)
cannam@208 68 {
cannam@208 69 LoadRequest req;
cannam@208 70 req.pluginKey = pluginKey;
cannam@208 71 req.inputSampleRate = inputSampleRate;
cannam@208 72 req.adapterFlags = adapterFlags;
cannam@208 73 try {
cannam@208 74 LoadResponse resp = m_client.load(req);
cannam@208 75 m_plugin = resp.plugin;
cannam@208 76 } catch (ServerCrashed c) {
cannam@208 77 log(std::string("PiperAutoPlugin: Server crashed: ") + c.what());
cannam@208 78 m_plugin = 0;
cannam@208 79 }
cannam@208 80 }
cannam@208 81
cannam@208 82 virtual ~PiperAutoPlugin() {
cannam@208 83 delete m_plugin;
cannam@208 84 }
cannam@208 85
cannam@208 86 bool isOK() const {
cannam@208 87 return (m_plugin != nullptr);
cannam@208 88 }
cannam@208 89
cannam@208 90 virtual std::string getIdentifier() const {
cannam@208 91 return getPlugin()->getIdentifier();
cannam@208 92 }
cannam@208 93
cannam@208 94 virtual std::string getName() const {
cannam@208 95 return getPlugin()->getName();
cannam@208 96 }
cannam@208 97
cannam@208 98 virtual std::string getDescription() const {
cannam@208 99 return getPlugin()->getDescription();
cannam@208 100 }
cannam@208 101
cannam@208 102 virtual std::string getMaker() const {
cannam@208 103 return getPlugin()->getMaker();
cannam@208 104 }
cannam@208 105
cannam@208 106 virtual std::string getCopyright() const {
cannam@208 107 return getPlugin()->getCopyright();
cannam@208 108 }
cannam@208 109
cannam@208 110 virtual int getPluginVersion() const {
cannam@208 111 return getPlugin()->getPluginVersion();
cannam@208 112 }
cannam@208 113
cannam@208 114 virtual ParameterList getParameterDescriptors() const {
cannam@208 115 return getPlugin()->getParameterDescriptors();
cannam@208 116 }
cannam@208 117
cannam@208 118 virtual float getParameter(std::string name) const {
cannam@208 119 return getPlugin()->getParameter(name);
cannam@208 120 }
cannam@208 121
cannam@208 122 virtual void setParameter(std::string name, float value) {
cannam@208 123 getPlugin()->setParameter(name, value);
cannam@208 124 }
cannam@208 125
cannam@208 126 virtual ProgramList getPrograms() const {
cannam@208 127 return getPlugin()->getPrograms();
cannam@208 128 }
cannam@208 129
cannam@208 130 virtual std::string getCurrentProgram() const {
cannam@208 131 return getPlugin()->getCurrentProgram();
cannam@208 132 }
cannam@208 133
cannam@208 134 virtual void selectProgram(std::string program) {
cannam@208 135 getPlugin()->selectProgram(program);
cannam@208 136 }
cannam@208 137
cannam@208 138 virtual bool initialise(size_t inputChannels,
cannam@208 139 size_t stepSize,
cannam@208 140 size_t blockSize) {
cannam@208 141 return getPlugin()->initialise(inputChannels, stepSize, blockSize);
cannam@208 142 }
cannam@208 143
cannam@208 144 virtual void reset() {
cannam@208 145 getPlugin()->reset();
cannam@208 146 }
cannam@208 147
cannam@208 148 virtual InputDomain getInputDomain() const {
cannam@208 149 return getPlugin()->getInputDomain();
cannam@208 150 }
cannam@208 151
cannam@208 152 virtual size_t getPreferredBlockSize() const {
cannam@208 153 return getPlugin()->getPreferredBlockSize();
cannam@208 154 }
cannam@208 155
cannam@208 156 virtual size_t getPreferredStepSize() const {
cannam@208 157 return getPlugin()->getPreferredStepSize();
cannam@208 158 }
cannam@208 159
cannam@208 160 virtual size_t getMinChannelCount() const {
cannam@208 161 return getPlugin()->getMinChannelCount();
cannam@208 162 }
cannam@208 163
cannam@208 164 virtual size_t getMaxChannelCount() const {
cannam@208 165 return getPlugin()->getMaxChannelCount();
cannam@208 166 }
cannam@208 167
cannam@208 168 virtual OutputList getOutputDescriptors() const {
cannam@208 169 return getPlugin()->getOutputDescriptors();
cannam@208 170 }
cannam@208 171
cannam@208 172 virtual FeatureSet process(const float *const *inputBuffers,
cannam@208 173 Vamp::RealTime timestamp) {
cannam@208 174 return getPlugin()->process(inputBuffers, timestamp);
cannam@208 175 }
cannam@208 176
cannam@208 177 virtual FeatureSet getRemainingFeatures() {
cannam@208 178 return getPlugin()->getRemainingFeatures();
cannam@208 179 }
cannam@208 180
cannam@208 181 private:
cannam@208 182 LogCallback *m_logger;
cannam@208 183 ProcessQtTransport m_transport;
cannam@208 184 CapnpRRClient m_client;
cannam@208 185 Vamp::Plugin *m_plugin;
cannam@208 186 Vamp::Plugin *getPlugin() const {
cannam@208 187 if (!m_plugin) {
cannam@208 188 log("PiperAutoPlugin: getPlugin() failed (caller should have called PiperAutoPlugin::isOK)");
cannam@208 189 throw std::logic_error("Plugin load failed");
cannam@208 190 }
cannam@208 191 return m_plugin;
cannam@208 192 }
cannam@208 193
cannam@208 194 void log(std::string message) const {
cannam@208 195 if (m_logger) m_logger->log(message);
cannam@208 196 else std::cerr << message << std::endl;
cannam@208 197 }
cannam@208 198 };
cannam@208 199
cannam@208 200 }
cannam@208 201 }
cannam@208 202
cannam@208 203 #endif
cannam@208 204
cannam@208 205