annotate vamp-client/PiperPluginStub.h @ 92:21f8af53eaf0

Reorganise some classes
author Chris Cannam <c.cannam@qmul.ac.uk>
date Thu, 13 Oct 2016 12:02:44 +0100
parents
children
rev   line source
c@92 1
c@92 2 #ifndef PIPER_STUB_PLUGIN_H
c@92 3 #define PIPER_STUB_PLUGIN_H
c@92 4
c@92 5 #include <vamp-hostsdk/Plugin.h>
c@92 6 #include <vamp-hostsdk/PluginLoader.h>
c@92 7 #include <vamp-hostsdk/PluginStaticData.h>
c@92 8 #include <vamp-hostsdk/PluginConfiguration.h>
c@92 9
c@92 10 #include <cstdint>
c@92 11
c@92 12 #include "PiperClient.h"
c@92 13
c@92 14 namespace piper { //!!! should be something else
c@92 15
c@92 16 class PiperPluginStub : public Vamp::Plugin
c@92 17 {
c@92 18 enum State {
c@92 19 Loaded, Configured, Finished
c@92 20 };
c@92 21
c@92 22 public:
c@92 23 PiperPluginStub(PiperPluginClientInterface *client,
c@92 24 std::string pluginKey,
c@92 25 float inputSampleRate,
c@92 26 int adapterFlags,
c@92 27 Vamp::HostExt::PluginStaticData psd,
c@92 28 Vamp::HostExt::PluginConfiguration defaultConfig) :
c@92 29 Plugin(inputSampleRate),
c@92 30 m_client(client),
c@92 31 m_key(pluginKey),
c@92 32 m_adapterFlags(adapterFlags),
c@92 33 m_state(Loaded),
c@92 34 m_psd(psd),
c@92 35 m_defaultConfig(defaultConfig),
c@92 36 m_config(defaultConfig)
c@92 37 { }
c@92 38
c@92 39 virtual ~PiperPluginStub() {
c@92 40 if (m_state != Finished) {
c@92 41 (void)m_client->finish(this);
c@92 42 }
c@92 43 }
c@92 44
c@92 45 virtual std::string getIdentifier() const {
c@92 46 return m_psd.basic.identifier;
c@92 47 }
c@92 48
c@92 49 virtual std::string getName() const {
c@92 50 return m_psd.basic.name;
c@92 51 }
c@92 52
c@92 53 virtual std::string getDescription() const {
c@92 54 return m_psd.basic.description;
c@92 55 }
c@92 56
c@92 57 virtual std::string getMaker() const {
c@92 58 return m_psd.maker;
c@92 59 }
c@92 60
c@92 61 virtual std::string getCopyright() const {
c@92 62 return m_psd.copyright;
c@92 63 }
c@92 64
c@92 65 virtual int getPluginVersion() const {
c@92 66 return m_psd.pluginVersion;
c@92 67 }
c@92 68
c@92 69 virtual ParameterList getParameterDescriptors() const {
c@92 70 return m_psd.parameters;
c@92 71 }
c@92 72
c@92 73 virtual float getParameter(std::string name) const {
c@92 74 if (m_config.parameterValues.find(name) != m_config.parameterValues.end()) {
c@92 75 return m_config.parameterValues.at(name);
c@92 76 } else {
c@92 77 return 0.f;
c@92 78 }
c@92 79 }
c@92 80
c@92 81 virtual void setParameter(std::string name, float value) {
c@92 82 if (m_state != Loaded) {
c@92 83 throw std::logic_error("Can't set parameter after plugin initialised");
c@92 84 }
c@92 85 m_config.parameterValues[name] = value;
c@92 86 }
c@92 87
c@92 88 virtual ProgramList getPrograms() const {
c@92 89 return m_psd.programs;
c@92 90 }
c@92 91
c@92 92 virtual std::string getCurrentProgram() const {
c@92 93 return m_config.currentProgram;
c@92 94 }
c@92 95
c@92 96 virtual void selectProgram(std::string program) {
c@92 97 if (m_state != Loaded) {
c@92 98 throw std::logic_error("Can't select program after plugin initialised");
c@92 99 }
c@92 100 m_config.currentProgram = program;
c@92 101 }
c@92 102
c@92 103 virtual bool initialise(size_t inputChannels,
c@92 104 size_t stepSize,
c@92 105 size_t blockSize) {
c@92 106
c@92 107 if (m_state != Loaded) {
c@92 108 throw std::logic_error("Plugin has already been initialised");
c@92 109 }
c@92 110
c@92 111 m_config.channelCount = inputChannels;
c@92 112 m_config.stepSize = stepSize;
c@92 113 m_config.blockSize = blockSize;
c@92 114
c@92 115 m_outputs = m_client->configure(this, m_config);
c@92 116
c@92 117 if (!m_outputs.empty()) {
c@92 118 m_state = Configured;
c@92 119 return true;
c@92 120 } else {
c@92 121 return false;
c@92 122 }
c@92 123 }
c@92 124
c@92 125 virtual void reset() {
c@92 126
c@92 127 if (m_state == Loaded) {
c@92 128 // reset is a no-op if the plugin hasn't been initialised yet
c@92 129 return;
c@92 130 }
c@92 131
c@92 132 m_client->reset(this, m_config);
c@92 133
c@92 134 m_state = Configured;
c@92 135 }
c@92 136
c@92 137 virtual InputDomain getInputDomain() const {
c@92 138 return m_psd.inputDomain;
c@92 139 }
c@92 140
c@92 141 virtual size_t getPreferredBlockSize() const {
c@92 142 return m_defaultConfig.blockSize;
c@92 143 }
c@92 144
c@92 145 virtual size_t getPreferredStepSize() const {
c@92 146 return m_defaultConfig.stepSize;
c@92 147 }
c@92 148
c@92 149 virtual size_t getMinChannelCount() const {
c@92 150 return m_psd.minChannelCount;
c@92 151 }
c@92 152
c@92 153 virtual size_t getMaxChannelCount() const {
c@92 154 return m_psd.maxChannelCount;
c@92 155 }
c@92 156
c@92 157 virtual OutputList getOutputDescriptors() const {
c@92 158 if (m_state == Configured) {
c@92 159 return m_outputs;
c@92 160 }
c@92 161
c@92 162 //!!! todo: figure out for which hosts (and adapters?) it may
c@92 163 //!!! be a problem that the output descriptors are incomplete
c@92 164 //!!! here. Any such hosts/adapters are broken, but I bet they
c@92 165 //!!! exist
c@92 166
c@92 167 OutputList staticOutputs;
c@92 168 for (const auto &o: m_psd.basicOutputInfo) {
c@92 169 OutputDescriptor od;
c@92 170 od.identifier = o.identifier;
c@92 171 od.name = o.name;
c@92 172 od.description = o.description;
c@92 173 staticOutputs.push_back(od);
c@92 174 }
c@92 175 return staticOutputs;
c@92 176 }
c@92 177
c@92 178 virtual FeatureSet process(const float *const *inputBuffers,
c@92 179 Vamp::RealTime timestamp) {
c@92 180
c@92 181 if (m_state == Loaded) {
c@92 182 throw std::logic_error("Plugin has not been initialised");
c@92 183 }
c@92 184 if (m_state == Finished) {
c@92 185 throw std::logic_error("Plugin has already been disposed of");
c@92 186 }
c@92 187
c@92 188 //!!! ew
c@92 189 std::vector<std::vector<float> > vecbuf;
c@92 190 for (int c = 0; c < m_config.channelCount; ++c) {
c@92 191 vecbuf.push_back(std::vector<float>
c@92 192 (inputBuffers[c],
c@92 193 inputBuffers[c] + m_config.blockSize));
c@92 194 }
c@92 195
c@92 196 return m_client->process(this, vecbuf, timestamp);
c@92 197 }
c@92 198
c@92 199 virtual FeatureSet getRemainingFeatures() {
c@92 200
c@92 201 if (m_state == Loaded) {
c@92 202 throw std::logic_error("Plugin has not been configured");
c@92 203 }
c@92 204 if (m_state == Finished) {
c@92 205 throw std::logic_error("Plugin has already been disposed of");
c@92 206 }
c@92 207
c@92 208 m_state = Finished;
c@92 209
c@92 210 return m_client->finish(this);
c@92 211 }
c@92 212
c@92 213 // Not Plugin methods, but needed by the PiperClient to support reloads:
c@92 214
c@92 215 virtual float getInputSampleRate() const {
c@92 216 return m_inputSampleRate;
c@92 217 }
c@92 218
c@92 219 virtual std::string getPluginKey() const {
c@92 220 return m_key;
c@92 221 }
c@92 222
c@92 223 virtual int getAdapterFlags() const {
c@92 224 return m_adapterFlags;
c@92 225 }
c@92 226
c@92 227 private:
c@92 228 PiperPluginClientInterface *m_client;
c@92 229 std::string m_key;
c@92 230 int m_adapterFlags;
c@92 231 State m_state;
c@92 232 Vamp::HostExt::PluginStaticData m_psd;
c@92 233 OutputList m_outputs;
c@92 234 Vamp::HostExt::PluginConfiguration m_defaultConfig;
c@92 235 Vamp::HostExt::PluginConfiguration m_config;
c@92 236 };
c@92 237
c@92 238 }
c@92 239
c@92 240 #endif