annotate src/PiperAdapter.h @ 133:2255741a934c

Add test target
author Chris Cannam <c.cannam@qmul.ac.uk>
date Fri, 11 Nov 2016 11:08:10 +0000
parents 523047216129
children c0256c2debf5
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 std::string getLibraryName() const override {
c@117 69 return m_soname;
c@117 70 }
c@117 71
c@117 72 virtual piper_vamp::PluginStaticData getStaticData() const override {
c@117 73 Vamp::Plugin *p = createPlugin(44100.f);
c@117 74 auto data = piper_vamp::PluginStaticData::fromPlugin
c@117 75 (m_soname + ":" + p->getIdentifier(),
c@117 76 {}, //!!! todo: category - tricky one that
c@117 77 p);
c@117 78 delete p;
c@117 79 return data;
c@117 80 }
c@117 81
c@117 82 virtual piper_vamp::LoadResponse loadPlugin(piper_vamp::LoadRequest r)
c@117 83 const override {
c@117 84
c@117 85 // We assume the caller has guaranteed that the request is for
c@117 86 // the correct plugin (so we don't have to check the plugin
c@117 87 // key field here)
c@117 88
c@117 89 Vamp::Plugin *p = createPlugin(r.inputSampleRate);
c@117 90
c@117 91 if (r.adapterFlags & adaptInputDomain) {
c@117 92 if (p->getInputDomain() == Vamp::Plugin::FrequencyDomain) {
c@117 93 p = new Vamp::HostExt::PluginInputDomainAdapter(p);
c@117 94 }
c@117 95 }
c@117 96
c@117 97 if (r.adapterFlags & adaptBufferSize) {
c@117 98 p = new Vamp::HostExt::PluginBufferingAdapter(p);
c@117 99 }
c@117 100
c@117 101 if (r.adapterFlags & adaptChannelCount) {
c@117 102 p = new Vamp::HostExt::PluginChannelAdapter(p);
c@117 103 }
c@117 104
c@117 105 piper_vamp::LoadResponse response;
c@117 106 response.plugin = p;
c@117 107
c@117 108 response.staticData = piper_vamp::PluginStaticData::fromPlugin
c@117 109 (m_soname + ":" + p->getIdentifier(),
c@117 110 {}, //!!! todo: category - tricky one that
c@117 111 p);
c@117 112
c@117 113 int defaultChannels = 0;
c@117 114 if (p->getMinChannelCount() == p->getMaxChannelCount()) {
c@117 115 defaultChannels = p->getMinChannelCount();
c@117 116 }
c@117 117
c@117 118 response.defaultConfiguration = piper_vamp::PluginConfiguration::fromPlugin
c@117 119 (p,
c@117 120 defaultChannels,
c@117 121 p->getPreferredStepSize(),
c@117 122 p->getPreferredBlockSize());
c@117 123
c@117 124 return response;
c@117 125 }
c@117 126
c@117 127 private:
c@117 128 std::string m_soname;
c@117 129 };
c@117 130
c@117 131 template <typename P>
c@117 132 class PiperAdapter : public PiperAdapterBase<P>
c@117 133 {
c@117 134 public:
c@117 135 PiperAdapter(std::string libname) : PiperAdapterBase<P>(libname) { }
c@117 136
c@117 137 virtual Vamp::Plugin *createPlugin(float inputSampleRate) const override {
c@117 138 return new P(inputSampleRate);
c@117 139 }
c@117 140 };
c@117 141
c@117 142 }
c@117 143
c@117 144 #endif
c@117 145