c@90: c@90: #ifndef PIPER_STUB_PLUGIN_H c@90: #define PIPER_STUB_PLUGIN_H c@90: c@90: #include c@90: #include c@90: #include c@90: #include c@90: c@90: #include c@90: c@90: #include "PiperClient.h" c@90: c@90: namespace piper { //!!! should be something else c@90: c@90: class PiperStubPlugin : public Vamp::Plugin c@90: { c@90: enum State { c@90: Loaded, Configured, Finished c@90: }; c@90: c@90: public: c@90: PiperStubPlugin(PiperStubPluginClientInterface *client, c@90: float inputSampleRate, c@90: Vamp::HostExt::PluginStaticData psd, c@90: Vamp::HostExt::PluginConfiguration defaultConfig) : c@90: Plugin(inputSampleRate), c@90: m_client(client), c@90: m_state(Loaded), c@90: m_psd(psd), c@90: m_defaultConfig(defaultConfig), c@90: m_config(defaultConfig) c@90: { } c@90: c@90: virtual ~PiperStubPlugin() { c@90: if (m_state != Finished) { c@90: (void)m_client->finish(this); c@90: } c@90: } c@90: c@90: virtual std::string getIdentifier() const { c@90: return m_psd.basic.identifier; c@90: } c@90: c@90: virtual std::string getName() const { c@90: return m_psd.basic.name; c@90: } c@90: c@90: virtual std::string getDescription() const { c@90: return m_psd.basic.description; c@90: } c@90: c@90: virtual std::string getMaker() const { c@90: return m_psd.maker; c@90: } c@90: c@90: virtual std::string getCopyright() const { c@90: return m_psd.copyright; c@90: } c@90: c@90: virtual int getPluginVersion() const { c@90: return m_psd.pluginVersion; c@90: } c@90: c@90: virtual ParameterList getParameterDescriptors() const { c@90: return m_psd.parameters; c@90: } c@90: c@90: virtual float getParameter(std::string name) const { c@90: if (m_config.parameterValues.find(name) != m_config.parameterValues.end()) { c@90: return m_config.parameterValues.at(name); c@90: } else { c@90: return 0.f; c@90: } c@90: } c@90: c@90: virtual void setParameter(std::string name, float value) { c@90: if (m_state != Loaded) { c@90: throw std::logic_error("Can't set parameter after plugin initialised"); c@90: } c@90: m_config.parameterValues[name] = value; c@90: } c@90: c@90: virtual ProgramList getPrograms() const { c@90: return m_psd.programs; c@90: } c@90: c@90: virtual std::string getCurrentProgram() const { c@90: return m_config.currentProgram; c@90: } c@90: c@90: virtual void selectProgram(std::string program) { c@90: if (m_state != Loaded) { c@90: throw std::logic_error("Can't select program after plugin initialised"); c@90: } c@90: m_config.currentProgram = program; c@90: } c@90: c@90: virtual bool initialise(size_t inputChannels, c@90: size_t stepSize, c@90: size_t blockSize) { c@90: c@90: if (m_state != Loaded) { c@90: throw std::logic_error("Plugin has already been initialised"); c@90: } c@90: c@90: m_config.channelCount = inputChannels; c@90: m_config.stepSize = stepSize; c@90: m_config.blockSize = blockSize; c@90: c@90: m_outputs = m_client->configure(this, m_config); c@90: c@90: if (!m_outputs.empty()) { c@90: m_state = Configured; c@90: return true; c@90: } else { c@90: return false; c@90: } c@90: } c@90: c@90: virtual void reset() { c@90: //!!! hm, how to deal with this? there is no reset() in Piper! c@90: throw "Please do not call this function again."; c@90: } c@90: c@90: virtual InputDomain getInputDomain() const { c@90: return m_psd.inputDomain; c@90: } c@90: c@90: virtual size_t getPreferredBlockSize() const { c@90: return m_defaultConfig.blockSize; c@90: } c@90: c@90: virtual size_t getPreferredStepSize() const { c@90: return m_defaultConfig.stepSize; c@90: } c@90: c@90: virtual size_t getMinChannelCount() const { c@90: return m_psd.minChannelCount; c@90: } c@90: c@90: virtual size_t getMaxChannelCount() const { c@90: return m_psd.maxChannelCount; c@90: } c@90: c@90: virtual OutputList getOutputDescriptors() const { c@90: if (m_state == Configured) { c@90: return m_outputs; c@90: } c@90: c@90: //!!! todo: figure out for which hosts (and adapters?) it may c@90: //!!! be a problem that the output descriptors are incomplete c@90: //!!! here. Any such hosts/adapters are broken, but I bet they c@90: //!!! exist c@90: c@90: OutputList staticOutputs; c@90: for (const auto &o: m_psd.basicOutputInfo) { c@90: OutputDescriptor od; c@90: od.identifier = o.identifier; c@90: od.name = o.name; c@90: od.description = o.description; c@90: staticOutputs.push_back(od); c@90: } c@90: return staticOutputs; c@90: } c@90: c@90: virtual FeatureSet process(const float *const *inputBuffers, c@90: Vamp::RealTime timestamp) { c@90: c@90: if (m_state == Loaded) { c@90: throw std::logic_error("Plugin has not been initialised"); c@90: } c@90: if (m_state == Finished) { c@90: throw std::logic_error("Plugin has already been disposed of"); c@90: } c@90: c@90: //!!! ew c@90: std::vector > vecbuf; c@90: for (int c = 0; c < m_config.channelCount; ++c) { c@90: vecbuf.push_back(std::vector c@90: (inputBuffers[c], c@90: inputBuffers[c] + m_config.blockSize)); c@90: } c@90: c@90: return m_client->process(this, vecbuf, timestamp); c@90: } c@90: c@90: virtual FeatureSet getRemainingFeatures() { c@90: c@90: if (m_state == Loaded) { c@90: throw std::logic_error("Plugin has not been configured"); c@90: } c@90: if (m_state == Finished) { c@90: throw std::logic_error("Plugin has already been disposed of"); c@90: } c@90: c@90: m_state = Finished; c@90: c@90: return m_client->finish(this); c@90: } c@90: c@90: private: c@90: PiperStubPluginClientInterface *m_client; c@90: State m_state; c@90: Vamp::HostExt::PluginStaticData m_psd; c@90: OutputList m_outputs; c@90: Vamp::HostExt::PluginConfiguration m_defaultConfig; c@90: Vamp::HostExt::PluginConfiguration m_config; c@90: }; c@90: c@90: } c@90: c@90: #endif