annotate src/PiperAdapter.h @ 117:2e8aacb7f883

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