cannam@233
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
cannam@233
|
2
|
cannam@233
|
3 /*
|
cannam@233
|
4 Vamp
|
cannam@233
|
5
|
cannam@233
|
6 An API for audio analysis and feature extraction plugins.
|
cannam@233
|
7
|
cannam@233
|
8 Centre for Digital Music, Queen Mary, University of London.
|
Chris@423
|
9 Copyright 2006-2016 Chris Cannam and QMUL.
|
cannam@233
|
10
|
cannam@233
|
11 Permission is hereby granted, free of charge, to any person
|
cannam@233
|
12 obtaining a copy of this software and associated documentation
|
cannam@233
|
13 files (the "Software"), to deal in the Software without
|
cannam@233
|
14 restriction, including without limitation the rights to use, copy,
|
cannam@233
|
15 modify, merge, publish, distribute, sublicense, and/or sell copies
|
cannam@233
|
16 of the Software, and to permit persons to whom the Software is
|
cannam@233
|
17 furnished to do so, subject to the following conditions:
|
cannam@233
|
18
|
cannam@233
|
19 The above copyright notice and this permission notice shall be
|
cannam@233
|
20 included in all copies or substantial portions of the Software.
|
cannam@233
|
21
|
cannam@233
|
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
cannam@233
|
23 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
cannam@233
|
24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
cannam@233
|
25 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
|
cannam@233
|
26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
cannam@233
|
27 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
cannam@233
|
28 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
cannam@233
|
29
|
cannam@233
|
30 Except as contained in this notice, the names of the Centre for
|
cannam@233
|
31 Digital Music; Queen Mary, University of London; and Chris Cannam
|
cannam@233
|
32 shall not be used in advertising or otherwise to promote the sale,
|
cannam@233
|
33 use or other dealings in this Software without prior written
|
cannam@233
|
34 authorization.
|
cannam@233
|
35 */
|
cannam@233
|
36
|
cannam@233
|
37 #include <vamp-hostsdk/PluginLoader.h>
|
cannam@233
|
38 #include <vamp-hostsdk/PluginInputDomainAdapter.h>
|
cannam@233
|
39 #include <vamp-hostsdk/PluginChannelAdapter.h>
|
cannam@233
|
40 #include <vamp-hostsdk/PluginBufferingAdapter.h>
|
Chris@390
|
41 #include <vamp-hostsdk/PluginHostAdapter.h>
|
Chris@390
|
42
|
Chris@390
|
43 #include <vamp/vamp.h>
|
Chris@390
|
44
|
Chris@390
|
45 #include "Files.h"
|
cannam@233
|
46
|
cannam@233
|
47 #include <fstream>
|
cannam@233
|
48
|
cannam@233
|
49 using namespace std;
|
cannam@233
|
50
|
cannam@263
|
51 _VAMP_SDK_HOSTSPACE_BEGIN(PluginLoader.cpp)
|
cannam@263
|
52
|
cannam@233
|
53 namespace Vamp {
|
cannam@233
|
54
|
cannam@233
|
55 namespace HostExt {
|
cannam@233
|
56
|
cannam@233
|
57 class PluginLoader::Impl
|
cannam@233
|
58 {
|
cannam@233
|
59 public:
|
cannam@233
|
60 Impl();
|
cannam@233
|
61 virtual ~Impl();
|
cannam@233
|
62
|
cannam@233
|
63 PluginKeyList listPlugins();
|
Chris@456
|
64
|
Chris@456
|
65 ListResponse listPluginData();
|
cannam@233
|
66
|
cannam@233
|
67 Plugin *loadPlugin(PluginKey key,
|
cannam@233
|
68 float inputSampleRate,
|
cannam@233
|
69 int adapterFlags);
|
cannam@233
|
70
|
Chris@423
|
71 LoadResponse loadPlugin(LoadRequest req);
|
Chris@423
|
72
|
Chris@431
|
73 ConfigurationResponse configurePlugin(ConfigurationRequest req);
|
Chris@423
|
74
|
cannam@233
|
75 PluginKey composePluginKey(string libraryName, string identifier);
|
cannam@233
|
76
|
cannam@233
|
77 PluginCategoryHierarchy getPluginCategory(PluginKey key);
|
cannam@233
|
78
|
cannam@233
|
79 string getLibraryPathForPlugin(PluginKey key);
|
cannam@233
|
80
|
cannam@233
|
81 static void setInstanceToClean(PluginLoader *instance);
|
cannam@233
|
82
|
cannam@233
|
83 protected:
|
cannam@233
|
84 class PluginDeletionNotifyAdapter : public PluginWrapper {
|
cannam@233
|
85 public:
|
cannam@233
|
86 PluginDeletionNotifyAdapter(Plugin *plugin, Impl *loader);
|
cannam@233
|
87 virtual ~PluginDeletionNotifyAdapter();
|
cannam@233
|
88 protected:
|
cannam@233
|
89 Impl *m_loader;
|
cannam@233
|
90 };
|
cannam@233
|
91
|
cannam@233
|
92 class InstanceCleaner {
|
cannam@233
|
93 public:
|
cannam@233
|
94 InstanceCleaner() : m_instance(0) { }
|
cannam@233
|
95 ~InstanceCleaner() { delete m_instance; }
|
cannam@233
|
96 void setInstance(PluginLoader *instance) { m_instance = instance; }
|
cannam@233
|
97 protected:
|
cannam@233
|
98 PluginLoader *m_instance;
|
cannam@233
|
99 };
|
cannam@233
|
100
|
cannam@233
|
101 virtual void pluginDeleted(PluginDeletionNotifyAdapter *adapter);
|
cannam@233
|
102
|
cannam@233
|
103 map<PluginKey, string> m_pluginLibraryNameMap;
|
cannam@233
|
104 bool m_allPluginsEnumerated;
|
cannam@233
|
105 void enumeratePlugins(PluginKey forPlugin = "");
|
cannam@233
|
106
|
cannam@233
|
107 map<PluginKey, PluginCategoryHierarchy> m_taxonomy;
|
cannam@233
|
108 void generateTaxonomy();
|
cannam@233
|
109
|
cannam@233
|
110 map<Plugin *, void *> m_pluginLibraryHandleMap;
|
cannam@233
|
111
|
cannam@233
|
112 bool decomposePluginKey(PluginKey key,
|
cannam@233
|
113 string &libraryName, string &identifier);
|
cannam@233
|
114
|
cannam@233
|
115 static InstanceCleaner m_cleaner;
|
cannam@233
|
116 };
|
cannam@233
|
117
|
cannam@233
|
118 PluginLoader *
|
cannam@233
|
119 PluginLoader::m_instance = 0;
|
cannam@233
|
120
|
cannam@233
|
121 PluginLoader::Impl::InstanceCleaner
|
cannam@233
|
122 PluginLoader::Impl::m_cleaner;
|
cannam@233
|
123
|
cannam@233
|
124 PluginLoader::PluginLoader()
|
cannam@233
|
125 {
|
cannam@233
|
126 m_impl = new Impl();
|
cannam@233
|
127 }
|
cannam@233
|
128
|
cannam@233
|
129 PluginLoader::~PluginLoader()
|
cannam@233
|
130 {
|
cannam@233
|
131 delete m_impl;
|
cannam@233
|
132 }
|
cannam@233
|
133
|
cannam@233
|
134 PluginLoader *
|
cannam@233
|
135 PluginLoader::getInstance()
|
cannam@233
|
136 {
|
cannam@233
|
137 if (!m_instance) {
|
cannam@233
|
138 // The cleaner doesn't own the instance, because we leave the
|
cannam@233
|
139 // instance pointer in the base class for binary backwards
|
cannam@233
|
140 // compatibility reasons and to avoid waste
|
cannam@233
|
141 m_instance = new PluginLoader();
|
cannam@233
|
142 Impl::setInstanceToClean(m_instance);
|
cannam@233
|
143 }
|
cannam@233
|
144 return m_instance;
|
cannam@233
|
145 }
|
cannam@233
|
146
|
Chris@426
|
147 PluginLoader::PluginKeyList
|
cannam@233
|
148 PluginLoader::listPlugins()
|
cannam@233
|
149 {
|
cannam@233
|
150 return m_impl->listPlugins();
|
cannam@233
|
151 }
|
cannam@233
|
152
|
Chris@456
|
153 ListResponse
|
Chris@426
|
154 PluginLoader::listPluginData()
|
Chris@426
|
155 {
|
Chris@426
|
156 return m_impl->listPluginData();
|
Chris@426
|
157 }
|
Chris@426
|
158
|
cannam@233
|
159 Plugin *
|
cannam@233
|
160 PluginLoader::loadPlugin(PluginKey key,
|
cannam@233
|
161 float inputSampleRate,
|
cannam@233
|
162 int adapterFlags)
|
cannam@233
|
163 {
|
cannam@233
|
164 return m_impl->loadPlugin(key, inputSampleRate, adapterFlags);
|
cannam@233
|
165 }
|
cannam@233
|
166
|
Chris@423
|
167 LoadResponse
|
Chris@423
|
168 PluginLoader::loadPlugin(LoadRequest req)
|
Chris@423
|
169 {
|
Chris@423
|
170 return m_impl->loadPlugin(req);
|
Chris@423
|
171 }
|
Chris@423
|
172
|
Chris@431
|
173 ConfigurationResponse
|
Chris@431
|
174 PluginLoader::configurePlugin(ConfigurationRequest req)
|
Chris@423
|
175 {
|
Chris@431
|
176 return m_impl->configurePlugin(req);
|
Chris@423
|
177 }
|
Chris@423
|
178
|
cannam@233
|
179 PluginLoader::PluginKey
|
cannam@233
|
180 PluginLoader::composePluginKey(string libraryName, string identifier)
|
cannam@233
|
181 {
|
cannam@233
|
182 return m_impl->composePluginKey(libraryName, identifier);
|
cannam@233
|
183 }
|
cannam@233
|
184
|
cannam@233
|
185 PluginLoader::PluginCategoryHierarchy
|
cannam@233
|
186 PluginLoader::getPluginCategory(PluginKey key)
|
cannam@233
|
187 {
|
cannam@233
|
188 return m_impl->getPluginCategory(key);
|
cannam@233
|
189 }
|
cannam@233
|
190
|
cannam@233
|
191 string
|
cannam@233
|
192 PluginLoader::getLibraryPathForPlugin(PluginKey key)
|
cannam@233
|
193 {
|
cannam@233
|
194 return m_impl->getLibraryPathForPlugin(key);
|
cannam@233
|
195 }
|
cannam@233
|
196
|
cannam@233
|
197 PluginLoader::Impl::Impl() :
|
cannam@233
|
198 m_allPluginsEnumerated(false)
|
cannam@233
|
199 {
|
cannam@233
|
200 }
|
cannam@233
|
201
|
cannam@233
|
202 PluginLoader::Impl::~Impl()
|
cannam@233
|
203 {
|
cannam@233
|
204 }
|
cannam@233
|
205
|
cannam@233
|
206 void
|
cannam@233
|
207 PluginLoader::Impl::setInstanceToClean(PluginLoader *instance)
|
cannam@233
|
208 {
|
cannam@233
|
209 m_cleaner.setInstance(instance);
|
cannam@233
|
210 }
|
cannam@233
|
211
|
Chris@426
|
212 PluginLoader::PluginKeyList
|
cannam@233
|
213 PluginLoader::Impl::listPlugins()
|
cannam@233
|
214 {
|
cannam@233
|
215 if (!m_allPluginsEnumerated) enumeratePlugins();
|
cannam@233
|
216
|
cannam@233
|
217 vector<PluginKey> plugins;
|
cannam@233
|
218 for (map<PluginKey, string>::iterator mi = m_pluginLibraryNameMap.begin();
|
cannam@233
|
219 mi != m_pluginLibraryNameMap.end(); ++mi) {
|
cannam@233
|
220 plugins.push_back(mi->first);
|
cannam@233
|
221 }
|
cannam@233
|
222
|
cannam@233
|
223 return plugins;
|
cannam@233
|
224 }
|
cannam@233
|
225
|
Chris@456
|
226 ListResponse
|
Chris@426
|
227 PluginLoader::Impl::listPluginData()
|
Chris@426
|
228 {
|
Chris@426
|
229 PluginKeyList keys = listPlugins();
|
Chris@456
|
230 ListResponse response;
|
Chris@426
|
231
|
Chris@426
|
232 for (PluginKeyList::const_iterator ki = keys.begin(); ki != keys.end(); ++ki) {
|
Chris@426
|
233 string key = *ki;
|
Chris@426
|
234 Plugin *p = loadPlugin(key, 44100, 0);
|
Chris@426
|
235 if (p) {
|
Chris@426
|
236 PluginCategoryHierarchy category = getPluginCategory(key);
|
Chris@458
|
237 response.plugins.push_back
|
Chris@456
|
238 (PluginStaticData::fromPlugin(key, category, p));
|
Chris@426
|
239 }
|
Chris@426
|
240 delete p;
|
Chris@426
|
241 }
|
Chris@426
|
242
|
Chris@456
|
243 return response;
|
Chris@426
|
244 }
|
Chris@426
|
245
|
cannam@233
|
246 void
|
cannam@233
|
247 PluginLoader::Impl::enumeratePlugins(PluginKey forPlugin)
|
cannam@233
|
248 {
|
cannam@233
|
249 string libraryName, identifier;
|
Chris@390
|
250 vector<string> fullPaths;
|
Chris@390
|
251
|
cannam@233
|
252 if (forPlugin != "") {
|
cannam@233
|
253 if (!decomposePluginKey(forPlugin, libraryName, identifier)) {
|
cannam@233
|
254 std::cerr << "WARNING: Vamp::HostExt::PluginLoader: Invalid plugin key \""
|
cannam@233
|
255 << forPlugin << "\" in enumerate" << std::endl;
|
cannam@233
|
256 return;
|
cannam@233
|
257 }
|
Chris@390
|
258 fullPaths = Files::listLibraryFilesMatching(libraryName);
|
Chris@390
|
259 } else {
|
Chris@390
|
260 fullPaths = Files::listLibraryFiles();
|
cannam@233
|
261 }
|
cannam@233
|
262
|
Chris@390
|
263 for (size_t i = 0; i < fullPaths.size(); ++i) {
|
cannam@233
|
264
|
Chris@390
|
265 string fullPath = fullPaths[i];
|
Chris@390
|
266 void *handle = Files::loadLibrary(fullPath);
|
Chris@390
|
267 if (!handle) continue;
|
cannam@233
|
268
|
Chris@390
|
269 VampGetPluginDescriptorFunction fn =
|
Chris@390
|
270 (VampGetPluginDescriptorFunction)Files::lookupInLibrary
|
Chris@390
|
271 (handle, "vampGetPluginDescriptor");
|
cannam@233
|
272
|
Chris@390
|
273 if (!fn) {
|
Chris@390
|
274 if (forPlugin != "") {
|
Chris@390
|
275 cerr << "Vamp::HostExt::PluginLoader: No vampGetPluginDescriptor function found in library \""
|
cannam@295
|
276 << fullPath << "\"" << endl;
|
cannam@295
|
277 }
|
Chris@390
|
278 Files::unloadLibrary(handle);
|
Chris@390
|
279 continue;
|
Chris@390
|
280 }
|
cannam@233
|
281
|
Chris@390
|
282 int index = 0;
|
Chris@390
|
283 const VampPluginDescriptor *descriptor = 0;
|
Chris@390
|
284 bool found = false;
|
Chris@390
|
285
|
Chris@390
|
286 while ((descriptor = fn(VAMP_API_VERSION, index))) {
|
Chris@390
|
287 ++index;
|
Chris@390
|
288 if (identifier != "") {
|
Chris@390
|
289 if (descriptor->identifier != identifier) continue;
|
Chris@390
|
290 }
|
Chris@390
|
291 found = true;
|
Chris@390
|
292 PluginKey key = composePluginKey(fullPath, descriptor->identifier);
|
Chris@390
|
293 // std::cerr << "enumerate: " << key << " (path: " << fullPath << ")" << std::endl;
|
Chris@390
|
294 if (m_pluginLibraryNameMap.find(key) ==
|
Chris@390
|
295 m_pluginLibraryNameMap.end()) {
|
Chris@390
|
296 m_pluginLibraryNameMap[key] = fullPath;
|
Chris@390
|
297 }
|
cannam@233
|
298 }
|
Chris@390
|
299
|
Chris@390
|
300 if (!found && forPlugin != "") {
|
Chris@390
|
301 cerr << "Vamp::HostExt::PluginLoader: Plugin \""
|
Chris@390
|
302 << identifier << "\" not found in library \""
|
Chris@390
|
303 << fullPath << "\"" << endl;
|
Chris@390
|
304 }
|
Chris@390
|
305
|
Chris@390
|
306 Files::unloadLibrary(handle);
|
cannam@233
|
307 }
|
cannam@233
|
308
|
cannam@233
|
309 if (forPlugin == "") m_allPluginsEnumerated = true;
|
cannam@233
|
310 }
|
cannam@233
|
311
|
cannam@233
|
312 PluginLoader::PluginKey
|
cannam@233
|
313 PluginLoader::Impl::composePluginKey(string libraryName, string identifier)
|
cannam@233
|
314 {
|
Chris@390
|
315 string basename = Files::lcBasename(libraryName);
|
cannam@233
|
316 return basename + ":" + identifier;
|
cannam@233
|
317 }
|
cannam@233
|
318
|
cannam@233
|
319 bool
|
cannam@233
|
320 PluginLoader::Impl::decomposePluginKey(PluginKey key,
|
cannam@233
|
321 string &libraryName,
|
cannam@233
|
322 string &identifier)
|
cannam@233
|
323 {
|
cannam@233
|
324 string::size_type ki = key.find(':');
|
cannam@233
|
325 if (ki == string::npos) {
|
cannam@233
|
326 return false;
|
cannam@233
|
327 }
|
cannam@233
|
328
|
cannam@233
|
329 libraryName = key.substr(0, ki);
|
cannam@233
|
330 identifier = key.substr(ki + 1);
|
cannam@233
|
331 return true;
|
cannam@233
|
332 }
|
cannam@233
|
333
|
cannam@233
|
334 PluginLoader::PluginCategoryHierarchy
|
cannam@233
|
335 PluginLoader::Impl::getPluginCategory(PluginKey plugin)
|
cannam@233
|
336 {
|
cannam@233
|
337 if (m_taxonomy.empty()) generateTaxonomy();
|
cannam@233
|
338 if (m_taxonomy.find(plugin) == m_taxonomy.end()) {
|
cannam@233
|
339 return PluginCategoryHierarchy();
|
cannam@233
|
340 }
|
cannam@233
|
341 return m_taxonomy[plugin];
|
cannam@233
|
342 }
|
cannam@233
|
343
|
cannam@233
|
344 string
|
cannam@233
|
345 PluginLoader::Impl::getLibraryPathForPlugin(PluginKey plugin)
|
cannam@233
|
346 {
|
cannam@233
|
347 if (m_pluginLibraryNameMap.find(plugin) == m_pluginLibraryNameMap.end()) {
|
cannam@233
|
348 if (m_allPluginsEnumerated) return "";
|
cannam@233
|
349 enumeratePlugins(plugin);
|
cannam@233
|
350 }
|
cannam@233
|
351 if (m_pluginLibraryNameMap.find(plugin) == m_pluginLibraryNameMap.end()) {
|
cannam@233
|
352 return "";
|
cannam@233
|
353 }
|
cannam@233
|
354 return m_pluginLibraryNameMap[plugin];
|
cannam@233
|
355 }
|
cannam@233
|
356
|
cannam@233
|
357 Plugin *
|
cannam@233
|
358 PluginLoader::Impl::loadPlugin(PluginKey key,
|
cannam@233
|
359 float inputSampleRate, int adapterFlags)
|
cannam@233
|
360 {
|
cannam@233
|
361 string libname, identifier;
|
cannam@233
|
362 if (!decomposePluginKey(key, libname, identifier)) {
|
cannam@233
|
363 std::cerr << "Vamp::HostExt::PluginLoader: Invalid plugin key \""
|
cannam@233
|
364 << key << "\" in loadPlugin" << std::endl;
|
cannam@233
|
365 return 0;
|
cannam@233
|
366 }
|
cannam@233
|
367
|
cannam@233
|
368 string fullPath = getLibraryPathForPlugin(key);
|
cannam@293
|
369 if (fullPath == "") {
|
cannam@295
|
370 std::cerr << "Vamp::HostExt::PluginLoader: No library found in Vamp path for plugin \"" << key << "\"" << std::endl;
|
cannam@293
|
371 return 0;
|
cannam@293
|
372 }
|
cannam@233
|
373
|
Chris@390
|
374 void *handle = Files::loadLibrary(fullPath);
|
cannam@233
|
375 if (!handle) return 0;
|
cannam@233
|
376
|
cannam@233
|
377 VampGetPluginDescriptorFunction fn =
|
Chris@390
|
378 (VampGetPluginDescriptorFunction)Files::lookupInLibrary
|
cannam@233
|
379 (handle, "vampGetPluginDescriptor");
|
cannam@233
|
380
|
cannam@233
|
381 if (!fn) {
|
cannam@293
|
382 cerr << "Vamp::HostExt::PluginLoader: No vampGetPluginDescriptor function found in library \""
|
cannam@293
|
383 << fullPath << "\"" << endl;
|
Chris@390
|
384 Files::unloadLibrary(handle);
|
cannam@233
|
385 return 0;
|
cannam@233
|
386 }
|
cannam@233
|
387
|
cannam@233
|
388 int index = 0;
|
cannam@233
|
389 const VampPluginDescriptor *descriptor = 0;
|
cannam@233
|
390
|
cannam@233
|
391 while ((descriptor = fn(VAMP_API_VERSION, index))) {
|
cannam@233
|
392
|
cannam@233
|
393 if (string(descriptor->identifier) == identifier) {
|
cannam@233
|
394
|
cannam@233
|
395 Vamp::PluginHostAdapter *plugin =
|
cannam@233
|
396 new Vamp::PluginHostAdapter(descriptor, inputSampleRate);
|
cannam@233
|
397
|
cannam@233
|
398 Plugin *adapter = new PluginDeletionNotifyAdapter(plugin, this);
|
cannam@233
|
399
|
cannam@233
|
400 m_pluginLibraryHandleMap[adapter] = handle;
|
cannam@233
|
401
|
cannam@233
|
402 if (adapterFlags & ADAPT_INPUT_DOMAIN) {
|
cannam@233
|
403 if (adapter->getInputDomain() == Plugin::FrequencyDomain) {
|
cannam@233
|
404 adapter = new PluginInputDomainAdapter(adapter);
|
cannam@233
|
405 }
|
cannam@233
|
406 }
|
cannam@233
|
407
|
cannam@233
|
408 if (adapterFlags & ADAPT_BUFFER_SIZE) {
|
cannam@233
|
409 adapter = new PluginBufferingAdapter(adapter);
|
cannam@233
|
410 }
|
cannam@233
|
411
|
cannam@233
|
412 if (adapterFlags & ADAPT_CHANNEL_COUNT) {
|
cannam@233
|
413 adapter = new PluginChannelAdapter(adapter);
|
cannam@233
|
414 }
|
cannam@233
|
415
|
cannam@233
|
416 return adapter;
|
cannam@233
|
417 }
|
cannam@233
|
418
|
cannam@233
|
419 ++index;
|
cannam@233
|
420 }
|
cannam@233
|
421
|
cannam@233
|
422 cerr << "Vamp::HostExt::PluginLoader: Plugin \""
|
cannam@233
|
423 << identifier << "\" not found in library \""
|
cannam@233
|
424 << fullPath << "\"" << endl;
|
cannam@233
|
425
|
cannam@233
|
426 return 0;
|
cannam@233
|
427 }
|
cannam@233
|
428
|
Chris@423
|
429 LoadResponse
|
Chris@423
|
430 PluginLoader::Impl::loadPlugin(LoadRequest req)
|
Chris@423
|
431 {
|
Chris@423
|
432 Plugin *plugin = loadPlugin(req.pluginKey,
|
Chris@423
|
433 req.inputSampleRate,
|
Chris@423
|
434 req.adapterFlags);
|
Chris@423
|
435 LoadResponse response;
|
Chris@425
|
436 response.plugin = plugin;
|
Chris@423
|
437 if (!plugin) return response;
|
Chris@423
|
438
|
Chris@423
|
439 response.plugin = plugin;
|
Chris@423
|
440 response.staticData = PluginStaticData::fromPlugin
|
Chris@423
|
441 (req.pluginKey,
|
Chris@423
|
442 getPluginCategory(req.pluginKey),
|
Chris@423
|
443 plugin);
|
Chris@423
|
444
|
Chris@423
|
445 int defaultChannels = 0;
|
Chris@423
|
446 if (plugin->getMinChannelCount() == plugin->getMaxChannelCount()) {
|
Chris@423
|
447 defaultChannels = plugin->getMinChannelCount();
|
Chris@423
|
448 }
|
Chris@423
|
449
|
Chris@423
|
450 response.defaultConfiguration = PluginConfiguration::fromPlugin
|
Chris@423
|
451 (plugin,
|
Chris@423
|
452 defaultChannels,
|
Chris@423
|
453 plugin->getPreferredStepSize(),
|
Chris@423
|
454 plugin->getPreferredBlockSize());
|
Chris@423
|
455
|
Chris@423
|
456 return response;
|
Chris@423
|
457 }
|
Chris@423
|
458
|
Chris@431
|
459 ConfigurationResponse
|
Chris@431
|
460 PluginLoader::Impl::configurePlugin(ConfigurationRequest req)
|
Chris@423
|
461 {
|
Chris@423
|
462 for (PluginConfiguration::ParameterMap::const_iterator i =
|
Chris@431
|
463 req.configuration.parameterValues.begin();
|
Chris@431
|
464 i != req.configuration.parameterValues.end(); ++i) {
|
Chris@431
|
465 req.plugin->setParameter(i->first, i->second);
|
Chris@423
|
466 }
|
Chris@423
|
467
|
Chris@431
|
468 if (req.configuration.currentProgram != "") {
|
Chris@431
|
469 req.plugin->selectProgram(req.configuration.currentProgram);
|
Chris@423
|
470 }
|
Chris@423
|
471
|
Chris@431
|
472 ConfigurationResponse response;
|
Chris@431
|
473
|
Chris@455
|
474 response.plugin = req.plugin;
|
Chris@455
|
475
|
Chris@431
|
476 if (req.plugin->initialise(req.configuration.channelCount,
|
Chris@431
|
477 req.configuration.stepSize,
|
Chris@431
|
478 req.configuration.blockSize)) {
|
Chris@431
|
479 response.outputs = req.plugin->getOutputDescriptors();
|
Chris@423
|
480 }
|
Chris@431
|
481
|
Chris@431
|
482 return response;
|
Chris@423
|
483 }
|
Chris@423
|
484
|
cannam@233
|
485 void
|
cannam@233
|
486 PluginLoader::Impl::generateTaxonomy()
|
cannam@233
|
487 {
|
cannam@233
|
488 // cerr << "PluginLoader::Impl::generateTaxonomy" << endl;
|
cannam@233
|
489
|
cannam@233
|
490 vector<string> path = PluginHostAdapter::getPluginPath();
|
cannam@233
|
491 string libfragment = "/lib/";
|
cannam@233
|
492 vector<string> catpath;
|
cannam@233
|
493
|
cannam@233
|
494 string suffix = "cat";
|
cannam@233
|
495
|
cannam@233
|
496 for (vector<string>::iterator i = path.begin();
|
cannam@233
|
497 i != path.end(); ++i) {
|
cannam@233
|
498
|
cannam@233
|
499 // It doesn't matter that we're using literal forward-slash in
|
cannam@233
|
500 // this bit, as it's only relevant if the path contains
|
cannam@233
|
501 // "/lib/", which is only meaningful and only plausible on
|
cannam@233
|
502 // systems with forward-slash delimiters
|
cannam@233
|
503
|
cannam@233
|
504 string dir = *i;
|
cannam@233
|
505 string::size_type li = dir.find(libfragment);
|
cannam@233
|
506
|
cannam@233
|
507 if (li != string::npos) {
|
cannam@233
|
508 catpath.push_back
|
cannam@233
|
509 (dir.substr(0, li)
|
cannam@233
|
510 + "/share/"
|
cannam@233
|
511 + dir.substr(li + libfragment.length()));
|
cannam@233
|
512 }
|
cannam@233
|
513
|
cannam@233
|
514 catpath.push_back(dir);
|
cannam@233
|
515 }
|
cannam@233
|
516
|
cannam@233
|
517 char buffer[1024];
|
cannam@233
|
518
|
cannam@233
|
519 for (vector<string>::iterator i = catpath.begin();
|
cannam@233
|
520 i != catpath.end(); ++i) {
|
cannam@233
|
521
|
Chris@390
|
522 vector<string> files = Files::listFiles(*i, suffix);
|
cannam@233
|
523
|
cannam@233
|
524 for (vector<string>::iterator fi = files.begin();
|
cannam@233
|
525 fi != files.end(); ++fi) {
|
cannam@233
|
526
|
Chris@390
|
527 string filepath = Files::splicePath(*i, *fi);
|
cannam@233
|
528 ifstream is(filepath.c_str(), ifstream::in | ifstream::binary);
|
cannam@233
|
529
|
cannam@233
|
530 if (is.fail()) {
|
cannam@233
|
531 // cerr << "failed to open: " << filepath << endl;
|
cannam@233
|
532 continue;
|
cannam@233
|
533 }
|
cannam@233
|
534
|
cannam@233
|
535 // cerr << "opened: " << filepath << endl;
|
cannam@233
|
536
|
cannam@233
|
537 while (!!is.getline(buffer, 1024)) {
|
cannam@233
|
538
|
cannam@233
|
539 string line(buffer);
|
cannam@233
|
540
|
cannam@233
|
541 // cerr << "line = " << line << endl;
|
cannam@233
|
542
|
cannam@233
|
543 string::size_type di = line.find("::");
|
cannam@233
|
544 if (di == string::npos) continue;
|
cannam@233
|
545
|
cannam@233
|
546 string id = line.substr(0, di);
|
cannam@233
|
547 string encodedCat = line.substr(di + 2);
|
cannam@233
|
548
|
cannam@233
|
549 if (id.substr(0, 5) != "vamp:") continue;
|
cannam@233
|
550 id = id.substr(5);
|
cannam@233
|
551
|
cannam@233
|
552 while (encodedCat.length() >= 1 &&
|
cannam@233
|
553 encodedCat[encodedCat.length()-1] == '\r') {
|
cannam@233
|
554 encodedCat = encodedCat.substr(0, encodedCat.length()-1);
|
cannam@233
|
555 }
|
cannam@233
|
556
|
cannam@233
|
557 // cerr << "id = " << id << ", cat = " << encodedCat << endl;
|
cannam@233
|
558
|
cannam@233
|
559 PluginCategoryHierarchy category;
|
cannam@233
|
560 string::size_type ai;
|
cannam@233
|
561 while ((ai = encodedCat.find(" > ")) != string::npos) {
|
cannam@233
|
562 category.push_back(encodedCat.substr(0, ai));
|
cannam@233
|
563 encodedCat = encodedCat.substr(ai + 3);
|
cannam@233
|
564 }
|
cannam@233
|
565 if (encodedCat != "") category.push_back(encodedCat);
|
cannam@233
|
566
|
cannam@233
|
567 m_taxonomy[id] = category;
|
cannam@233
|
568 }
|
cannam@233
|
569 }
|
cannam@233
|
570 }
|
cannam@233
|
571 }
|
cannam@233
|
572
|
cannam@233
|
573 void
|
cannam@233
|
574 PluginLoader::Impl::pluginDeleted(PluginDeletionNotifyAdapter *adapter)
|
cannam@233
|
575 {
|
cannam@233
|
576 void *handle = m_pluginLibraryHandleMap[adapter];
|
Chris@390
|
577 if (handle) Files::unloadLibrary(handle);
|
cannam@233
|
578 m_pluginLibraryHandleMap.erase(adapter);
|
cannam@233
|
579 }
|
cannam@233
|
580
|
cannam@233
|
581 PluginLoader::Impl::PluginDeletionNotifyAdapter::PluginDeletionNotifyAdapter(Plugin *plugin,
|
cannam@233
|
582 Impl *loader) :
|
cannam@233
|
583 PluginWrapper(plugin),
|
cannam@233
|
584 m_loader(loader)
|
cannam@233
|
585 {
|
cannam@233
|
586 }
|
cannam@233
|
587
|
cannam@233
|
588 PluginLoader::Impl::PluginDeletionNotifyAdapter::~PluginDeletionNotifyAdapter()
|
cannam@233
|
589 {
|
cannam@233
|
590 // We need to delete the plugin before calling pluginDeleted, as
|
cannam@233
|
591 // the delete call may require calling through to the descriptor
|
cannam@233
|
592 // (for e.g. cleanup) but pluginDeleted may unload the required
|
cannam@233
|
593 // library for the call. To prevent a double deletion when our
|
cannam@233
|
594 // parent's destructor runs (after this one), be sure to set
|
cannam@233
|
595 // m_plugin to 0 after deletion.
|
cannam@233
|
596 delete m_plugin;
|
cannam@233
|
597 m_plugin = 0;
|
cannam@233
|
598
|
cannam@233
|
599 if (m_loader) m_loader->pluginDeleted(this);
|
cannam@233
|
600 }
|
cannam@233
|
601
|
cannam@233
|
602 }
|
cannam@233
|
603
|
cannam@233
|
604 }
|
cannam@263
|
605
|
cannam@263
|
606 _VAMP_SDK_HOSTSPACE_END(PluginLoader.cpp)
|
cannam@263
|
607
|