annotate vamp-client/PiperStubPlugin.h @ 91:c897c9a8daf1

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