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