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