Mercurial > hg > piper-cpp
comparison vamp-support/LoaderRequests.h @ 97:427c4c725085
Bring in the Request/Response classes that were in the Vamp SDK, adding them to vamp-support in here instead
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Thu, 13 Oct 2016 18:05:35 +0100 |
parents | |
children | 247d8d533a9c |
comparison
equal
deleted
inserted
replaced
96:215c9fb6b7a4 | 97:427c4c725085 |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 Piper C++ | |
5 | |
6 An API for audio analysis and feature extraction plugins. | |
7 | |
8 Centre for Digital Music, Queen Mary, University of London. | |
9 Copyright 2006-2016 Chris Cannam and QMUL. | |
10 | |
11 Permission is hereby granted, free of charge, to any person | |
12 obtaining a copy of this software and associated documentation | |
13 files (the "Software"), to deal in the Software without | |
14 restriction, including without limitation the rights to use, copy, | |
15 modify, merge, publish, distribute, sublicense, and/or sell copies | |
16 of the Software, and to permit persons to whom the Software is | |
17 furnished to do so, subject to the following conditions: | |
18 | |
19 The above copyright notice and this permission notice shall be | |
20 included in all copies or substantial portions of the Software. | |
21 | |
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
23 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
25 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR | |
26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | |
27 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
28 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
29 | |
30 Except as contained in this notice, the names of the Centre for | |
31 Digital Music; Queen Mary, University of London; and Chris Cannam | |
32 shall not be used in advertising or otherwise to promote the sale, | |
33 use or other dealings in this Software without prior written | |
34 authorization. | |
35 */ | |
36 | |
37 #ifndef PIPER_LOADER_REQUESTS_H | |
38 #define PIPER_LOADER_REQUESTS_H | |
39 | |
40 #include "PluginStaticData.h" | |
41 #include "PluginConfiguration.h" | |
42 | |
43 #include <vamp-hostsdk/PluginLoader.h> | |
44 | |
45 #include <map> | |
46 #include <string> | |
47 | |
48 namespace piper_vamp { | |
49 | |
50 class LoaderRequests | |
51 { | |
52 public: | |
53 ListResponse | |
54 listPluginData() { | |
55 | |
56 auto loader = Vamp::HostExt::PluginLoader::getInstance(); | |
57 auto keys = loader->listPlugins(); | |
58 ListResponse response; | |
59 | |
60 for (std::string key: keys) { | |
61 Vamp::Plugin *p = loader->loadPlugin(key, 44100, 0); | |
62 if (!p) continue; | |
63 auto category = loader->getPluginCategory(key); | |
64 response.available.push_back | |
65 (PluginStaticData::fromPlugin(key, category, p)); | |
66 delete p; | |
67 } | |
68 | |
69 return response; | |
70 } | |
71 | |
72 LoadResponse | |
73 loadPlugin(LoadRequest req) { | |
74 | |
75 auto loader = Vamp::HostExt::PluginLoader::getInstance(); | |
76 | |
77 Vamp::Plugin *plugin = loader->loadPlugin(req.pluginKey, | |
78 req.inputSampleRate, | |
79 req.adapterFlags); | |
80 | |
81 LoadResponse response; | |
82 response.plugin = plugin; | |
83 if (!plugin) return response; | |
84 | |
85 response.plugin = plugin; | |
86 response.staticData = PluginStaticData::fromPlugin | |
87 (req.pluginKey, | |
88 loader->getPluginCategory(req.pluginKey), | |
89 plugin); | |
90 | |
91 int defaultChannels = 0; | |
92 if (plugin->getMinChannelCount() == plugin->getMaxChannelCount()) { | |
93 defaultChannels = plugin->getMinChannelCount(); | |
94 } | |
95 | |
96 response.defaultConfiguration = PluginConfiguration::fromPlugin | |
97 (plugin, | |
98 defaultChannels, | |
99 plugin->getPreferredStepSize(), | |
100 plugin->getPreferredBlockSize()); | |
101 | |
102 return response; | |
103 } | |
104 | |
105 ConfigurationResponse | |
106 configurePlugin(ConfigurationRequest req) { | |
107 | |
108 for (PluginConfiguration::ParameterMap::const_iterator i = | |
109 req.configuration.parameterValues.begin(); | |
110 i != req.configuration.parameterValues.end(); ++i) { | |
111 req.plugin->setParameter(i->first, i->second); | |
112 } | |
113 | |
114 if (req.configuration.currentProgram != "") { | |
115 req.plugin->selectProgram(req.configuration.currentProgram); | |
116 } | |
117 | |
118 ConfigurationResponse response; | |
119 | |
120 response.plugin = req.plugin; | |
121 | |
122 if (req.plugin->initialise(req.configuration.channelCount, | |
123 req.configuration.stepSize, | |
124 req.configuration.blockSize)) { | |
125 response.outputs = req.plugin->getOutputDescriptors(); | |
126 } | |
127 | |
128 return response; | |
129 } | |
130 }; | |
131 | |
132 } | |
133 | |
134 #endif |