c@117: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ c@117: c@117: /* c@117: Piper Vamp JSON Adapter c@117: c@117: Centre for Digital Music, Queen Mary, University of London. c@117: Copyright 2015-2016 QMUL. c@117: c@117: Permission is hereby granted, free of charge, to any person c@117: obtaining a copy of this software and associated documentation c@117: files (the "Software"), to deal in the Software without c@117: restriction, including without limitation the rights to use, copy, c@117: modify, merge, publish, distribute, sublicense, and/or sell copies c@117: of the Software, and to permit persons to whom the Software is c@117: furnished to do so, subject to the following conditions: c@117: c@117: The above copyright notice and this permission notice shall be c@117: included in all copies or substantial portions of the Software. c@117: c@117: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, c@117: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF c@117: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND c@117: NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR c@117: ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF c@117: CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION c@117: WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. c@117: c@117: Except as contained in this notice, the names of the Centre for c@117: Digital Music; Queen Mary, University of London; and Chris Cannam c@117: shall not be used in advertising or otherwise to promote the sale, c@117: use or other dealings in this Software without prior written c@117: authorization. c@117: */ c@117: c@117: #ifndef PIPER_ADAPTER_H c@117: #define PIPER_ADAPTER_H c@117: c@117: #include "vamp-support/PluginStaticData.h" c@117: #include "vamp-support/PluginConfiguration.h" c@117: #include "vamp-support/RequestResponse.h" cannam@152: #include "vamp-support/StaticOutputDescriptor.h" c@117: c@117: #include c@117: #include c@117: #include c@117: c@117: namespace piper_vamp_js { //!!! not a good name for this namespace c@117: c@117: class PiperAdapterInterface c@117: { c@117: public: c@117: virtual std::string getLibraryName() const = 0; c@117: virtual piper_vamp::PluginStaticData getStaticData() const = 0; c@117: virtual piper_vamp::LoadResponse loadPlugin(piper_vamp::LoadRequest r) const = 0; c@117: virtual Vamp::Plugin *createPlugin(float inputSampleRate) const = 0; c@117: }; c@117: c@117: template c@117: class PiperAdapterBase : public PiperAdapterInterface c@117: { c@117: const int adaptInputDomain = 0x01; c@117: const int adaptChannelCount = 0x02; c@117: const int adaptBufferSize = 0x04; c@117: c@117: protected: cannam@152: PiperAdapterBase(std::string libname, cannam@152: std::vector category = {}, cannam@152: piper_vamp::StaticOutputInfo staticOutputInfo = {}) : cannam@152: m_soname(libname), cannam@152: m_category(category), cannam@152: m_staticOutputInfo(staticOutputInfo) { } c@117: c@117: public: c@117: virtual std::string getLibraryName() const override { c@117: return m_soname; c@117: } c@117: c@117: virtual piper_vamp::PluginStaticData getStaticData() const override { c@117: Vamp::Plugin *p = createPlugin(44100.f); c@117: auto data = piper_vamp::PluginStaticData::fromPlugin c@117: (m_soname + ":" + p->getIdentifier(), cannam@152: m_category, c@117: p); cannam@152: data.staticOutputInfo = m_staticOutputInfo; c@117: delete p; c@117: return data; c@117: } c@117: c@117: virtual piper_vamp::LoadResponse loadPlugin(piper_vamp::LoadRequest r) c@117: const override { c@117: c@117: // We assume the caller has guaranteed that the request is for c@117: // the correct plugin (so we don't have to check the plugin c@117: // key field here) c@117: c@117: Vamp::Plugin *p = createPlugin(r.inputSampleRate); c@117: c@117: if (r.adapterFlags & adaptInputDomain) { c@117: if (p->getInputDomain() == Vamp::Plugin::FrequencyDomain) { c@117: p = new Vamp::HostExt::PluginInputDomainAdapter(p); c@117: } c@117: } c@117: c@117: if (r.adapterFlags & adaptBufferSize) { c@117: p = new Vamp::HostExt::PluginBufferingAdapter(p); c@117: } c@117: c@117: if (r.adapterFlags & adaptChannelCount) { c@117: p = new Vamp::HostExt::PluginChannelAdapter(p); c@117: } c@117: c@117: piper_vamp::LoadResponse response; c@117: response.plugin = p; c@117: c@117: response.staticData = piper_vamp::PluginStaticData::fromPlugin c@117: (m_soname + ":" + p->getIdentifier(), cannam@152: m_category, c@117: p); cannam@152: response.staticData.staticOutputInfo = m_staticOutputInfo; c@117: c@117: int defaultChannels = 0; c@117: if (p->getMinChannelCount() == p->getMaxChannelCount()) { c@117: defaultChannels = p->getMinChannelCount(); c@117: } c@134: c@134: int defaultBlockSize = p->getPreferredBlockSize(); c@134: int defaultStepSize = p->getPreferredStepSize(); c@134: c@134: if (defaultBlockSize == 0) { c@134: defaultBlockSize = 1024; c@134: } c@134: if (defaultStepSize == 0) { c@134: if (p->getInputDomain() == Vamp::Plugin::FrequencyDomain) { c@134: defaultStepSize = defaultBlockSize / 2; c@134: } else { c@134: defaultStepSize = defaultBlockSize; c@134: } c@134: } c@134: c@134: response.defaultConfiguration = c@134: piper_vamp::PluginConfiguration::fromPlugin c@117: (p, c@117: defaultChannels, c@134: defaultStepSize, c@134: defaultBlockSize); c@117: c@117: return response; c@117: } c@117: c@117: private: c@117: std::string m_soname; cannam@152: std::vector m_category; cannam@152: piper_vamp::StaticOutputInfo m_staticOutputInfo; c@117: }; c@117: c@117: template c@117: class PiperAdapter : public PiperAdapterBase

c@117: { c@117: public: cannam@152: PiperAdapter(std::string libname, cannam@152: std::vector category = {}, cannam@152: piper_vamp::StaticOutputInfo staticOutputInfo = {}) : cannam@152: PiperAdapterBase

(libname, category, staticOutputInfo) { } c@117: c@117: virtual Vamp::Plugin *createPlugin(float inputSampleRate) const override { c@117: return new P(inputSampleRate); c@117: } c@117: }; c@117: c@117: } c@117: c@117: #endif c@117: