comparison VamPipeAdapter.h @ 69:967b0619b090

Start on plugin-library-to-json-request-response-handler adapter
author Chris Cannam <c.cannam@qmul.ac.uk>
date Mon, 22 Aug 2016 17:17:28 +0100
parents
children 0e1909abe921
comparison
equal deleted inserted replaced
-1:000000000000 69:967b0619b090
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3 /*
4 VamPipe
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 VAMPIPE_ADAPTER_H
36 #define VAMPIPE_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 vampipe {
47
48 class VamPipeAdapterBase
49 {
50 public:
51 virtual Vamp::HostExt::PluginStaticData getStaticData() const = 0;
52 virtual Vamp::HostExt::LoadResponse loadPlugin(Vamp::HostExt::LoadRequest r) const = 0;
53 };
54
55 template <typename P>
56 class VamPipeAdapter : public VamPipeAdapterBase
57 {
58 const int adaptInputDomain = 0x01;
59 const int adaptChannelCount = 0x02;
60 const int adaptBufferSize = 0x04;
61
62 public:
63 VamPipeAdapter(std::string libname) :
64 m_soname(libname) { }
65
66 virtual Vamp::HostExt::PluginStaticData getStaticData() const {
67 P p(44100.f);
68 return Vamp::HostExt::PluginStaticData::fromPlugin
69 (m_soname + ":" + p.getIdentifier(),
70 {}, //!!! todo: category - tricky one that
71 &p);
72 }
73
74 virtual Vamp::HostExt::LoadResponse loadPlugin(Vamp::HostExt::
75 LoadRequest r) const {
76
77 // We assume the caller has guaranteed that the request is for
78 // the correct plugin (so we don't have to check the plugin
79 // key field here)
80
81 Vamp::Plugin *p = new P(r.inputSampleRate);
82
83 if (r.adapterFlags & adaptInputDomain) {
84 if (p->getInputDomain() == Vamp::Plugin::FrequencyDomain) {
85 p = new Vamp::HostExt::PluginInputDomainAdapter(p);
86 }
87 }
88
89 if (r.adapterFlags & adaptBufferSize) {
90 p = new Vamp::HostExt::PluginBufferingAdapter(p);
91 }
92
93 if (r.adapterFlags & adaptChannelCount) {
94 p = new Vamp::HostExt::PluginChannelAdapter(p);
95 }
96
97 Vamp::HostExt::LoadResponse response;
98 response.plugin = p;
99
100 response.staticData = Vamp::HostExt::PluginStaticData::fromPlugin
101 (m_soname + ":" + p->getIdentifier(),
102 {}, //!!! todo: category - tricky one that
103 p);
104
105 int defaultChannels = 0;
106 if (p->getMinChannelCount() == p->getMaxChannelCount()) {
107 defaultChannels = p->getMinChannelCount();
108 }
109
110 response.defaultConfiguration = Vamp::HostExt::PluginConfiguration::fromPlugin
111 (p,
112 defaultChannels,
113 p->getPreferredStepSize(),
114 p->getPreferredBlockSize());
115
116 return response;
117 }
118
119 private:
120 std::string m_soname;
121 };
122
123 }
124
125 #endif
126