annotate VamPipeAdapter.h @ 107:f272e46f5615

Fix dumb typo
author Chris Cannam <c.cannam@qmul.ac.uk>
date Fri, 30 Sep 2016 19:20:23 +0100
parents 6c4b43298968
children
rev   line source
c@69 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
c@69 2
c@69 3 /*
c@69 4 VamPipe
c@69 5
c@69 6 Centre for Digital Music, Queen Mary, University of London.
c@69 7 Copyright 2015-2016 QMUL.
c@69 8
c@69 9 Permission is hereby granted, free of charge, to any person
c@69 10 obtaining a copy of this software and associated documentation
c@69 11 files (the "Software"), to deal in the Software without
c@69 12 restriction, including without limitation the rights to use, copy,
c@69 13 modify, merge, publish, distribute, sublicense, and/or sell copies
c@69 14 of the Software, and to permit persons to whom the Software is
c@69 15 furnished to do so, subject to the following conditions:
c@69 16
c@69 17 The above copyright notice and this permission notice shall be
c@69 18 included in all copies or substantial portions of the Software.
c@69 19
c@69 20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
c@69 21 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
c@69 22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
c@69 23 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
c@69 24 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
c@69 25 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
c@69 26 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
c@69 27
c@69 28 Except as contained in this notice, the names of the Centre for
c@69 29 Digital Music; Queen Mary, University of London; and Chris Cannam
c@69 30 shall not be used in advertising or otherwise to promote the sale,
c@69 31 use or other dealings in this Software without prior written
c@69 32 authorization.
c@69 33 */
c@69 34
c@69 35 #ifndef VAMPIPE_ADAPTER_H
c@69 36 #define VAMPIPE_ADAPTER_H
c@69 37
c@69 38 #include <vamp-hostsdk/PluginStaticData.h>
c@69 39 #include <vamp-hostsdk/PluginConfiguration.h>
c@69 40 #include <vamp-hostsdk/RequestResponse.h>
c@69 41
c@69 42 #include <vamp-hostsdk/PluginInputDomainAdapter.h>
c@69 43 #include <vamp-hostsdk/PluginBufferingAdapter.h>
c@69 44 #include <vamp-hostsdk/PluginChannelAdapter.h>
c@69 45
c@69 46 namespace vampipe {
c@69 47
c@88 48 class VamPipeAdapterInterface
c@69 49 {
c@69 50 public:
c@69 51 virtual Vamp::HostExt::PluginStaticData getStaticData() const = 0;
c@69 52 virtual Vamp::HostExt::LoadResponse loadPlugin(Vamp::HostExt::LoadRequest r) const = 0;
c@88 53 virtual Vamp::Plugin *createPlugin(float inputSampleRate) const = 0;
c@69 54 };
c@69 55
c@69 56 template <typename P>
c@88 57 class VamPipeAdapterBase : public VamPipeAdapterInterface
c@69 58 {
c@69 59 const int adaptInputDomain = 0x01;
c@69 60 const int adaptChannelCount = 0x02;
c@69 61 const int adaptBufferSize = 0x04;
c@88 62
c@88 63 protected:
c@88 64 VamPipeAdapterBase(std::string libname) : m_soname(libname) { }
c@69 65
c@69 66 public:
c@88 67 virtual Vamp::Plugin *createPlugin(float inputSampleRate) const = 0;
c@69 68
c@69 69 virtual Vamp::HostExt::PluginStaticData getStaticData() const {
c@88 70 Vamp::Plugin *p = createPlugin(44100.f);
c@88 71 auto data = Vamp::HostExt::PluginStaticData::fromPlugin
c@88 72 (m_soname + ":" + p->getIdentifier(),
c@69 73 {}, //!!! todo: category - tricky one that
c@88 74 p);
c@88 75 delete p;
c@88 76 return data;
c@69 77 }
c@69 78
c@69 79 virtual Vamp::HostExt::LoadResponse loadPlugin(Vamp::HostExt::
c@69 80 LoadRequest r) const {
c@69 81
c@69 82 // We assume the caller has guaranteed that the request is for
c@69 83 // the correct plugin (so we don't have to check the plugin
c@69 84 // key field here)
c@69 85
c@88 86 Vamp::Plugin *p = createPlugin(r.inputSampleRate);
c@69 87
c@69 88 if (r.adapterFlags & adaptInputDomain) {
c@69 89 if (p->getInputDomain() == Vamp::Plugin::FrequencyDomain) {
c@69 90 p = new Vamp::HostExt::PluginInputDomainAdapter(p);
c@69 91 }
c@69 92 }
c@69 93
c@69 94 if (r.adapterFlags & adaptBufferSize) {
c@69 95 p = new Vamp::HostExt::PluginBufferingAdapter(p);
c@69 96 }
c@69 97
c@69 98 if (r.adapterFlags & adaptChannelCount) {
c@69 99 p = new Vamp::HostExt::PluginChannelAdapter(p);
c@69 100 }
c@69 101
c@69 102 Vamp::HostExt::LoadResponse response;
c@69 103 response.plugin = p;
c@69 104
c@69 105 response.staticData = Vamp::HostExt::PluginStaticData::fromPlugin
c@69 106 (m_soname + ":" + p->getIdentifier(),
c@69 107 {}, //!!! todo: category - tricky one that
c@69 108 p);
c@69 109
c@69 110 int defaultChannels = 0;
c@69 111 if (p->getMinChannelCount() == p->getMaxChannelCount()) {
c@69 112 defaultChannels = p->getMinChannelCount();
c@69 113 }
c@69 114
c@69 115 response.defaultConfiguration = Vamp::HostExt::PluginConfiguration::fromPlugin
c@69 116 (p,
c@69 117 defaultChannels,
c@69 118 p->getPreferredStepSize(),
c@69 119 p->getPreferredBlockSize());
c@69 120
c@69 121 return response;
c@69 122 }
c@69 123
c@69 124 private:
c@69 125 std::string m_soname;
c@69 126 };
c@69 127
c@88 128 template <typename P>
c@88 129 class VamPipeAdapter : public VamPipeAdapterBase<P>
c@88 130 {
c@88 131 public:
c@88 132 VamPipeAdapter(std::string libname) : VamPipeAdapterBase<P>(libname) { }
c@88 133
c@88 134 virtual Vamp::Plugin *createPlugin(float inputSampleRate) const {
c@88 135 return new P(inputSampleRate);
c@88 136 }
c@88 137 };
c@88 138
c@69 139 }
c@69 140
c@69 141 #endif
c@69 142