annotate src/PiperAdapter.h @ 176:eaf46e7647a0 tip master

Update for latest Emscripten - Pointer_stringify has apparently been deprecated for a while, and was removed in v1.38.27
author Chris Cannam <cannam@all-day-breakfast.com>
date Wed, 27 Feb 2019 11:29:53 +0000
parents c43d2e93153f
children
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"
cannam@152 41 #include "vamp-support/StaticOutputDescriptor.h"
c@117 42
c@117 43 #include <vamp-hostsdk/PluginInputDomainAdapter.h>
c@117 44 #include <vamp-hostsdk/PluginBufferingAdapter.h>
c@117 45 #include <vamp-hostsdk/PluginChannelAdapter.h>
c@117 46
c@117 47 namespace piper_vamp_js { //!!! not a good name for this namespace
c@117 48
c@117 49 class PiperAdapterInterface
c@117 50 {
c@117 51 public:
c@117 52 virtual std::string getLibraryName() const = 0;
c@117 53 virtual piper_vamp::PluginStaticData getStaticData() const = 0;
c@117 54 virtual piper_vamp::LoadResponse loadPlugin(piper_vamp::LoadRequest r) const = 0;
c@117 55 virtual Vamp::Plugin *createPlugin(float inputSampleRate) const = 0;
c@117 56 };
c@117 57
c@117 58 template <typename P>
c@117 59 class PiperAdapterBase : public PiperAdapterInterface
c@117 60 {
c@117 61 const int adaptInputDomain = 0x01;
c@117 62 const int adaptChannelCount = 0x02;
c@117 63 const int adaptBufferSize = 0x04;
c@117 64
c@117 65 protected:
cannam@152 66 PiperAdapterBase(std::string libname,
cannam@152 67 std::vector<std::string> category = {},
cannam@152 68 piper_vamp::StaticOutputInfo staticOutputInfo = {}) :
cannam@152 69 m_soname(libname),
cannam@152 70 m_category(category),
cannam@152 71 m_staticOutputInfo(staticOutputInfo) { }
c@117 72
c@117 73 public:
c@117 74 virtual std::string getLibraryName() const override {
c@117 75 return m_soname;
c@117 76 }
c@117 77
c@117 78 virtual piper_vamp::PluginStaticData getStaticData() const override {
c@117 79 Vamp::Plugin *p = createPlugin(44100.f);
c@117 80 auto data = piper_vamp::PluginStaticData::fromPlugin
c@117 81 (m_soname + ":" + p->getIdentifier(),
cannam@152 82 m_category,
c@117 83 p);
cannam@152 84 data.staticOutputInfo = m_staticOutputInfo;
c@117 85 delete p;
c@117 86 return data;
c@117 87 }
c@117 88
c@117 89 virtual piper_vamp::LoadResponse loadPlugin(piper_vamp::LoadRequest r)
c@117 90 const override {
c@117 91
c@117 92 // We assume the caller has guaranteed that the request is for
c@117 93 // the correct plugin (so we don't have to check the plugin
c@117 94 // key field here)
c@117 95
c@117 96 Vamp::Plugin *p = createPlugin(r.inputSampleRate);
c@117 97
c@117 98 if (r.adapterFlags & adaptInputDomain) {
c@117 99 if (p->getInputDomain() == Vamp::Plugin::FrequencyDomain) {
c@117 100 p = new Vamp::HostExt::PluginInputDomainAdapter(p);
c@117 101 }
c@117 102 }
c@117 103
c@117 104 if (r.adapterFlags & adaptBufferSize) {
c@117 105 p = new Vamp::HostExt::PluginBufferingAdapter(p);
c@117 106 }
c@117 107
c@117 108 if (r.adapterFlags & adaptChannelCount) {
c@117 109 p = new Vamp::HostExt::PluginChannelAdapter(p);
c@117 110 }
c@117 111
c@117 112 piper_vamp::LoadResponse response;
c@117 113 response.plugin = p;
c@117 114
c@117 115 response.staticData = piper_vamp::PluginStaticData::fromPlugin
c@117 116 (m_soname + ":" + p->getIdentifier(),
cannam@152 117 m_category,
c@117 118 p);
cannam@152 119 response.staticData.staticOutputInfo = m_staticOutputInfo;
c@117 120
c@117 121 int defaultChannels = 0;
c@117 122 if (p->getMinChannelCount() == p->getMaxChannelCount()) {
c@117 123 defaultChannels = p->getMinChannelCount();
c@117 124 }
c@134 125
c@134 126 int defaultBlockSize = p->getPreferredBlockSize();
c@134 127 int defaultStepSize = p->getPreferredStepSize();
c@134 128
c@134 129 if (defaultBlockSize == 0) {
c@134 130 defaultBlockSize = 1024;
c@134 131 }
c@134 132 if (defaultStepSize == 0) {
c@134 133 if (p->getInputDomain() == Vamp::Plugin::FrequencyDomain) {
c@134 134 defaultStepSize = defaultBlockSize / 2;
c@134 135 } else {
c@134 136 defaultStepSize = defaultBlockSize;
c@134 137 }
c@134 138 }
c@134 139
c@134 140 response.defaultConfiguration =
c@134 141 piper_vamp::PluginConfiguration::fromPlugin
c@117 142 (p,
c@117 143 defaultChannels,
c@134 144 defaultStepSize,
c@134 145 defaultBlockSize);
c@117 146
c@117 147 return response;
c@117 148 }
c@117 149
c@117 150 private:
c@117 151 std::string m_soname;
cannam@152 152 std::vector<std::string> m_category;
cannam@152 153 piper_vamp::StaticOutputInfo m_staticOutputInfo;
c@117 154 };
c@117 155
c@117 156 template <typename P>
c@117 157 class PiperAdapter : public PiperAdapterBase<P>
c@117 158 {
c@117 159 public:
cannam@152 160 PiperAdapter(std::string libname,
cannam@152 161 std::vector<std::string> category = {},
cannam@152 162 piper_vamp::StaticOutputInfo staticOutputInfo = {}) :
cannam@152 163 PiperAdapterBase<P>(libname, category, staticOutputInfo) { }
c@117 164
c@117 165 virtual Vamp::Plugin *createPlugin(float inputSampleRate) const override {
c@117 166 return new P(inputSampleRate);
c@117 167 }
c@117 168 };
c@117 169
c@117 170 }
c@117 171
c@117 172 #endif
c@117 173