cannam@1
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
cannam@1
|
2
|
cannam@1
|
3 /*
|
cannam@1
|
4 Vamp
|
cannam@1
|
5
|
cannam@1
|
6 An API for audio analysis and feature extraction plugins.
|
cannam@1
|
7
|
cannam@1
|
8 Centre for Digital Music, Queen Mary, University of London.
|
cannam@1
|
9 Copyright 2006 Chris Cannam.
|
cannam@16
|
10 FFT code from Don Cross's public domain FFT implementation.
|
cannam@1
|
11
|
cannam@1
|
12 Permission is hereby granted, free of charge, to any person
|
cannam@1
|
13 obtaining a copy of this software and associated documentation
|
cannam@1
|
14 files (the "Software"), to deal in the Software without
|
cannam@1
|
15 restriction, including without limitation the rights to use, copy,
|
cannam@1
|
16 modify, merge, publish, distribute, sublicense, and/or sell copies
|
cannam@1
|
17 of the Software, and to permit persons to whom the Software is
|
cannam@1
|
18 furnished to do so, subject to the following conditions:
|
cannam@1
|
19
|
cannam@1
|
20 The above copyright notice and this permission notice shall be
|
cannam@1
|
21 included in all copies or substantial portions of the Software.
|
cannam@1
|
22
|
cannam@1
|
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
cannam@1
|
24 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
cannam@1
|
25 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
cannam@6
|
26 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
|
cannam@1
|
27 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
cannam@1
|
28 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
cannam@1
|
29 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
cannam@1
|
30
|
cannam@1
|
31 Except as contained in this notice, the names of the Centre for
|
cannam@1
|
32 Digital Music; Queen Mary, University of London; and Chris Cannam
|
cannam@1
|
33 shall not be used in advertising or otherwise to promote the sale,
|
cannam@1
|
34 use or other dealings in this Software without prior written
|
cannam@1
|
35 authorization.
|
cannam@1
|
36 */
|
cannam@1
|
37
|
cannam@64
|
38 #include "vamp-sdk/PluginHostAdapter.h"
|
cannam@64
|
39 #include "vamp-sdk/hostext/PluginChannelAdapter.h"
|
cannam@64
|
40 #include "vamp-sdk/hostext/PluginInputDomainAdapter.h"
|
cannam@64
|
41 #include "vamp-sdk/hostext/PluginLoader.h"
|
cannam@64
|
42 #include "vamp/vamp.h"
|
cannam@1
|
43
|
cannam@16
|
44 #include <iostream>
|
cannam@88
|
45 #include <fstream>
|
cannam@99
|
46 #include <set>
|
cannam@16
|
47 #include <sndfile.h>
|
cannam@1
|
48
|
cannam@1
|
49 #include "system.h"
|
cannam@1
|
50
|
cannam@19
|
51 #include <cmath>
|
cannam@19
|
52
|
cannam@99
|
53 using namespace std;
|
cannam@16
|
54
|
cannam@99
|
55 using Vamp::Plugin;
|
cannam@99
|
56 using Vamp::PluginHostAdapter;
|
cannam@99
|
57 using Vamp::RealTime;
|
cannam@64
|
58 using Vamp::HostExt::PluginLoader;
|
cannam@64
|
59
|
cannam@64
|
60 #define HOST_VERSION "1.1"
|
cannam@40
|
61
|
cannam@95
|
62 enum Verbosity {
|
cannam@95
|
63 PluginIds,
|
cannam@95
|
64 PluginOutputIds,
|
cannam@95
|
65 PluginInformation
|
cannam@95
|
66 };
|
cannam@95
|
67
|
cannam@109
|
68 void printFeatures(int, int, int, Plugin::FeatureSet, ofstream *, bool frames);
|
cannam@16
|
69 void transformInput(float *, size_t);
|
cannam@16
|
70 void fft(unsigned int, bool, double *, double *, double *, double *);
|
cannam@64
|
71 void printPluginPath(bool verbose);
|
cannam@99
|
72 void printPluginCategoryList();
|
cannam@95
|
73 void enumeratePlugins(Verbosity);
|
cannam@64
|
74 void listPluginsInLibrary(string soname);
|
cannam@64
|
75 int runPlugin(string myname, string soname, string id, string output,
|
cannam@109
|
76 int outputNo, string inputFile, string outfilename, bool frames);
|
cannam@40
|
77
|
cannam@64
|
78 void usage(const char *name)
|
cannam@64
|
79 {
|
cannam@64
|
80 cerr << "\n"
|
cannam@64
|
81 << name << ": A simple Vamp plugin host.\n\n"
|
cannam@64
|
82 "Centre for Digital Music, Queen Mary, University of London.\n"
|
cannam@64
|
83 "Copyright 2006-2007 Chris Cannam and QMUL.\n"
|
cannam@64
|
84 "Freely redistributable; published under a BSD-style license.\n\n"
|
cannam@64
|
85 "Usage:\n\n"
|
cannam@109
|
86 " " << name << " [-s] pluginlibrary[." << PLUGIN_SUFFIX << "]:plugin[:output] file.wav [-o out.txt]\n"
|
cannam@109
|
87 " " << name << " [-s] pluginlibrary[." << PLUGIN_SUFFIX << "]:plugin file.wav [outputno] [-o out.txt]\n\n"
|
cannam@64
|
88 " -- Load plugin id \"plugin\" from \"pluginlibrary\" and run it on the\n"
|
cannam@73
|
89 " audio data in \"file.wav\", retrieving the named \"output\", or output\n"
|
cannam@73
|
90 " number \"outputno\" (the first output by default) and dumping it to\n"
|
cannam@95
|
91 " standard output, or to \"out.txt\" if the -o option is given.\n\n"
|
cannam@73
|
92 " \"pluginlibrary\" should be a library name, not a file path; the\n"
|
cannam@73
|
93 " standard Vamp library search path will be used to locate it. If\n"
|
cannam@73
|
94 " a file path is supplied, the directory part(s) will be ignored.\n\n"
|
cannam@109
|
95 " If the -s option is given, results will be labelled with the audio\n"
|
cannam@109
|
96 " sample frame at which they occur. Otherwise, they will be labelled\n"
|
cannam@109
|
97 " with time in seconds.\n\n"
|
cannam@64
|
98 " " << name << " -l\n\n"
|
cannam@95
|
99 " -- List the plugin libraries and Vamp plugins in the library search path\n"
|
cannam@95
|
100 " in a verbose human-readable format.\n\n"
|
cannam@95
|
101 " " << name << " --list-ids\n\n"
|
cannam@95
|
102 " -- List the plugins in the search path in a terse machine-readable format,\n"
|
cannam@95
|
103 " in the form vamp:soname:identifier.\n\n"
|
cannam@95
|
104 " " << name << " --list-outputs\n\n"
|
cannam@95
|
105 " -- List the outputs for plugins in the search path in a machine-readable\n"
|
cannam@95
|
106 " format, in the form vamp:soname:identifier:output.\n\n"
|
cannam@99
|
107 " " << name << " --list-by-category\n\n"
|
cannam@99
|
108 " -- List the plugins as a plugin index by category, in a machine-readable\n"
|
cannam@99
|
109 " format. The format may change in future releases.\n\n"
|
cannam@64
|
110 " " << name << " -p\n\n"
|
cannam@73
|
111 " -- Print out the Vamp library search path.\n\n"
|
cannam@64
|
112 " " << name << " -v\n\n"
|
cannam@95
|
113 " -- Display version information only.\n"
|
cannam@64
|
114 << endl;
|
cannam@64
|
115 exit(2);
|
cannam@64
|
116 }
|
cannam@1
|
117
|
cannam@1
|
118 int main(int argc, char **argv)
|
cannam@1
|
119 {
|
cannam@64
|
120 char *scooter = argv[0];
|
cannam@64
|
121 char *name = 0;
|
cannam@64
|
122 while (scooter && *scooter) {
|
cannam@64
|
123 if (*scooter == '/' || *scooter == '\\') name = ++scooter;
|
cannam@64
|
124 else ++scooter;
|
cannam@1
|
125 }
|
cannam@64
|
126 if (!name || !*name) name = argv[0];
|
cannam@43
|
127
|
cannam@88
|
128 if (argc < 2) usage(name);
|
cannam@64
|
129
|
cannam@88
|
130 if (argc == 2) {
|
cannam@88
|
131
|
cannam@88
|
132 if (!strcmp(argv[1], "-v")) {
|
cannam@88
|
133
|
cannam@88
|
134 cout << "Simple Vamp plugin host version: " << HOST_VERSION << endl
|
cannam@88
|
135 << "Vamp API version: " << VAMP_API_VERSION << endl
|
cannam@88
|
136 << "Vamp SDK version: " << VAMP_SDK_VERSION << endl;
|
cannam@88
|
137 return 0;
|
cannam@88
|
138
|
cannam@88
|
139 } else if (!strcmp(argv[1], "-l")) {
|
cannam@88
|
140
|
cannam@88
|
141 printPluginPath(true);
|
cannam@95
|
142 enumeratePlugins(PluginInformation);
|
cannam@88
|
143 return 0;
|
cannam@88
|
144
|
cannam@88
|
145 } else if (!strcmp(argv[1], "-p")) {
|
cannam@88
|
146
|
cannam@88
|
147 printPluginPath(false);
|
cannam@88
|
148 return 0;
|
cannam@88
|
149
|
cannam@95
|
150 } else if (!strcmp(argv[1], "--list-ids")) {
|
cannam@95
|
151
|
cannam@95
|
152 enumeratePlugins(PluginIds);
|
cannam@95
|
153 return 0;
|
cannam@95
|
154
|
cannam@95
|
155 } else if (!strcmp(argv[1], "--list-outputs")) {
|
cannam@95
|
156
|
cannam@95
|
157 enumeratePlugins(PluginOutputIds);
|
cannam@95
|
158 return 0;
|
cannam@95
|
159
|
cannam@99
|
160 } else if (!strcmp(argv[1], "--list-by-category")) {
|
cannam@99
|
161
|
cannam@99
|
162 printPluginCategoryList();
|
cannam@99
|
163 return 0;
|
cannam@99
|
164
|
cannam@88
|
165 } else usage(name);
|
cannam@64
|
166 }
|
cannam@64
|
167
|
cannam@88
|
168 if (argc < 3) usage(name);
|
cannam@88
|
169
|
cannam@109
|
170 bool useFrames = false;
|
cannam@109
|
171
|
cannam@109
|
172 int base = 1;
|
cannam@109
|
173 if (!strcmp(argv[1], "-s")) {
|
cannam@109
|
174 useFrames = true;
|
cannam@109
|
175 base = 2;
|
cannam@109
|
176 }
|
cannam@109
|
177
|
cannam@109
|
178 string soname = argv[base];
|
cannam@109
|
179 string wavname = argv[base+1];
|
cannam@88
|
180 string plugid = "";
|
cannam@88
|
181 string output = "";
|
cannam@88
|
182 int outputNo = -1;
|
cannam@88
|
183 string outfilename;
|
cannam@88
|
184
|
cannam@109
|
185 if (argc >= base+3) {
|
cannam@88
|
186
|
cannam@109
|
187 int idx = base+2;
|
cannam@88
|
188
|
cannam@88
|
189 if (isdigit(*argv[idx])) {
|
cannam@88
|
190 outputNo = atoi(argv[idx++]);
|
cannam@88
|
191 }
|
cannam@88
|
192
|
cannam@88
|
193 if (argc == idx + 2) {
|
cannam@88
|
194 if (!strcmp(argv[idx], "-o")) {
|
cannam@88
|
195 outfilename = argv[idx+1];
|
cannam@88
|
196 } else usage(name);
|
cannam@88
|
197 } else if (argc != idx) {
|
cannam@88
|
198 (usage(name));
|
cannam@88
|
199 }
|
cannam@40
|
200 }
|
cannam@40
|
201
|
cannam@64
|
202 cerr << endl << name << ": Running..." << endl;
|
cannam@1
|
203
|
cannam@88
|
204 cerr << "Reading file: \"" << wavname << "\", writing to ";
|
cannam@88
|
205 if (outfilename == "") {
|
cannam@88
|
206 cerr << "standard output" << endl;
|
cannam@88
|
207 } else {
|
cannam@88
|
208 cerr << "\"" << outfilename << "\"" << endl;
|
cannam@88
|
209 }
|
cannam@16
|
210
|
cannam@64
|
211 string::size_type sep = soname.find(':');
|
cannam@64
|
212
|
cannam@64
|
213 if (sep != string::npos) {
|
cannam@49
|
214 plugid = soname.substr(sep + 1);
|
cannam@20
|
215 soname = soname.substr(0, sep);
|
cannam@1
|
216
|
cannam@64
|
217 sep = plugid.find(':');
|
cannam@64
|
218 if (sep != string::npos) {
|
cannam@64
|
219 output = plugid.substr(sep + 1);
|
cannam@64
|
220 plugid = plugid.substr(0, sep);
|
cannam@16
|
221 }
|
cannam@16
|
222 }
|
cannam@16
|
223
|
cannam@64
|
224 if (plugid == "") {
|
cannam@64
|
225 usage(name);
|
cannam@16
|
226 }
|
cannam@64
|
227
|
cannam@64
|
228 if (output != "" && outputNo != -1) {
|
cannam@64
|
229 usage(name);
|
cannam@64
|
230 }
|
cannam@64
|
231
|
cannam@84
|
232 if (output == "" && outputNo == -1) {
|
cannam@84
|
233 outputNo = 0;
|
cannam@84
|
234 }
|
cannam@84
|
235
|
cannam@88
|
236 return runPlugin(name, soname, plugid, output, outputNo,
|
cannam@109
|
237 wavname, outfilename, useFrames);
|
cannam@64
|
238 }
|
cannam@64
|
239
|
cannam@64
|
240
|
cannam@64
|
241 int runPlugin(string myname, string soname, string id,
|
cannam@88
|
242 string output, int outputNo, string wavname,
|
cannam@109
|
243 string outfilename, bool useFrames)
|
cannam@64
|
244 {
|
cannam@64
|
245 PluginLoader *loader = PluginLoader::getInstance();
|
cannam@64
|
246
|
cannam@64
|
247 PluginLoader::PluginKey key = loader->composePluginKey(soname, id);
|
cannam@16
|
248
|
cannam@16
|
249 SNDFILE *sndfile;
|
cannam@16
|
250 SF_INFO sfinfo;
|
cannam@16
|
251 memset(&sfinfo, 0, sizeof(SF_INFO));
|
cannam@16
|
252
|
cannam@16
|
253 sndfile = sf_open(wavname.c_str(), SFM_READ, &sfinfo);
|
cannam@16
|
254 if (!sndfile) {
|
cannam@64
|
255 cerr << myname << ": ERROR: Failed to open input file \""
|
cannam@64
|
256 << wavname << "\": " << sf_strerror(sndfile) << endl;
|
cannam@16
|
257 return 1;
|
cannam@16
|
258 }
|
cannam@16
|
259
|
cannam@88
|
260 ofstream *out = 0;
|
cannam@88
|
261 if (outfilename != "") {
|
cannam@88
|
262 out = new ofstream(outfilename.c_str(), ios::out);
|
cannam@88
|
263 if (!*out) {
|
cannam@88
|
264 cerr << myname << ": ERROR: Failed to open output file \""
|
cannam@88
|
265 << outfilename << "\" for writing" << endl;
|
cannam@88
|
266 delete out;
|
cannam@88
|
267 return 1;
|
cannam@88
|
268 }
|
cannam@88
|
269 }
|
cannam@88
|
270
|
cannam@99
|
271 Plugin *plugin = loader->loadPlugin
|
cannam@92
|
272 (key, sfinfo.samplerate, PluginLoader::ADAPT_ALL_SAFE);
|
cannam@64
|
273 if (!plugin) {
|
cannam@64
|
274 cerr << myname << ": ERROR: Failed to load plugin \"" << id
|
cannam@64
|
275 << "\" from library \"" << soname << "\"" << endl;
|
cannam@64
|
276 sf_close(sndfile);
|
cannam@88
|
277 if (out) {
|
cannam@88
|
278 out->close();
|
cannam@88
|
279 delete out;
|
cannam@88
|
280 }
|
cannam@64
|
281 return 1;
|
cannam@64
|
282 }
|
cannam@16
|
283
|
cannam@64
|
284 cerr << "Running plugin: \"" << plugin->getIdentifier() << "\"..." << endl;
|
cannam@16
|
285
|
cannam@16
|
286 int blockSize = plugin->getPreferredBlockSize();
|
cannam@16
|
287 int stepSize = plugin->getPreferredStepSize();
|
cannam@16
|
288
|
cannam@91
|
289 if (blockSize == 0) {
|
cannam@91
|
290 blockSize = 1024;
|
cannam@91
|
291 }
|
cannam@83
|
292 if (stepSize == 0) {
|
cannam@99
|
293 if (plugin->getInputDomain() == Plugin::FrequencyDomain) {
|
cannam@83
|
294 stepSize = blockSize/2;
|
cannam@83
|
295 } else {
|
cannam@83
|
296 stepSize = blockSize;
|
cannam@83
|
297 }
|
cannam@91
|
298 } else if (stepSize > blockSize) {
|
cannam@91
|
299 cerr << "WARNING: stepSize " << stepSize << " > blockSize " << blockSize << ", resetting blockSize to ";
|
cannam@99
|
300 if (plugin->getInputDomain() == Plugin::FrequencyDomain) {
|
cannam@91
|
301 blockSize = stepSize * 2;
|
cannam@91
|
302 } else {
|
cannam@91
|
303 blockSize = stepSize;
|
cannam@91
|
304 }
|
cannam@91
|
305 cerr << blockSize << endl;
|
cannam@83
|
306 }
|
cannam@83
|
307
|
cannam@16
|
308 int channels = sfinfo.channels;
|
cannam@16
|
309
|
cannam@16
|
310 float *filebuf = new float[blockSize * channels];
|
cannam@16
|
311 float **plugbuf = new float*[channels];
|
cannam@47
|
312 for (int c = 0; c < channels; ++c) plugbuf[c] = new float[blockSize + 2];
|
cannam@16
|
313
|
cannam@16
|
314 cerr << "Using block size = " << blockSize << ", step size = "
|
cannam@16
|
315 << stepSize << endl;
|
cannam@16
|
316
|
cannam@16
|
317 int minch = plugin->getMinChannelCount();
|
cannam@16
|
318 int maxch = plugin->getMaxChannelCount();
|
cannam@16
|
319 cerr << "Plugin accepts " << minch << " -> " << maxch << " channel(s)" << endl;
|
cannam@64
|
320 cerr << "Sound file has " << channels << " (will mix/augment if necessary)" << endl;
|
cannam@16
|
321
|
cannam@99
|
322 Plugin::OutputList outputs = plugin->getOutputDescriptors();
|
cannam@99
|
323 Plugin::OutputDescriptor od;
|
cannam@16
|
324
|
cannam@29
|
325 int returnValue = 1;
|
cannam@88
|
326 int progress = 0;
|
cannam@29
|
327
|
cannam@16
|
328 if (outputs.empty()) {
|
cannam@64
|
329 cerr << "ERROR: Plugin has no outputs!" << endl;
|
cannam@16
|
330 goto done;
|
cannam@16
|
331 }
|
cannam@16
|
332
|
cannam@64
|
333 if (outputNo < 0) {
|
cannam@16
|
334
|
cannam@64
|
335 for (size_t oi = 0; oi < outputs.size(); ++oi) {
|
cannam@64
|
336 if (outputs[oi].identifier == output) {
|
cannam@64
|
337 outputNo = oi;
|
cannam@64
|
338 break;
|
cannam@64
|
339 }
|
cannam@64
|
340 }
|
cannam@64
|
341
|
cannam@64
|
342 if (outputNo < 0) {
|
cannam@64
|
343 cerr << "ERROR: Non-existent output \"" << output << "\" requested" << endl;
|
cannam@64
|
344 goto done;
|
cannam@64
|
345 }
|
cannam@64
|
346
|
cannam@64
|
347 } else {
|
cannam@64
|
348
|
cannam@64
|
349 if (int(outputs.size()) <= outputNo) {
|
cannam@64
|
350 cerr << "ERROR: Output " << outputNo << " requested, but plugin has only " << outputs.size() << " output(s)" << endl;
|
cannam@64
|
351 goto done;
|
cannam@64
|
352 }
|
cannam@64
|
353 }
|
cannam@64
|
354
|
cannam@64
|
355 od = outputs[outputNo];
|
cannam@64
|
356 cerr << "Output is: \"" << od.identifier << "\"" << endl;
|
cannam@16
|
357
|
cannam@29
|
358 if (!plugin->initialise(channels, stepSize, blockSize)) {
|
cannam@29
|
359 cerr << "ERROR: Plugin initialise (channels = " << channels
|
cannam@29
|
360 << ", stepSize = " << stepSize << ", blockSize = "
|
cannam@29
|
361 << blockSize << ") failed." << endl;
|
cannam@29
|
362 goto done;
|
cannam@29
|
363 }
|
cannam@16
|
364
|
cannam@16
|
365 for (size_t i = 0; i < sfinfo.frames; i += stepSize) {
|
cannam@16
|
366
|
cannam@16
|
367 int count;
|
cannam@16
|
368
|
cannam@16
|
369 if (sf_seek(sndfile, i, SEEK_SET) < 0) {
|
cannam@16
|
370 cerr << "ERROR: sf_seek failed: " << sf_strerror(sndfile) << endl;
|
cannam@16
|
371 break;
|
cannam@16
|
372 }
|
cannam@16
|
373
|
cannam@16
|
374 if ((count = sf_readf_float(sndfile, filebuf, blockSize)) < 0) {
|
cannam@16
|
375 cerr << "ERROR: sf_readf_float failed: " << sf_strerror(sndfile) << endl;
|
cannam@16
|
376 break;
|
cannam@16
|
377 }
|
cannam@16
|
378
|
cannam@16
|
379 for (int c = 0; c < channels; ++c) {
|
cannam@64
|
380 int j = 0;
|
cannam@64
|
381 while (j < count) {
|
cannam@64
|
382 plugbuf[c][j] = filebuf[j * sfinfo.channels + c];
|
cannam@64
|
383 ++j;
|
cannam@64
|
384 }
|
cannam@64
|
385 while (j < blockSize) {
|
cannam@16
|
386 plugbuf[c][j] = 0.0f;
|
cannam@64
|
387 ++j;
|
cannam@16
|
388 }
|
cannam@16
|
389 }
|
cannam@16
|
390
|
cannam@16
|
391 printFeatures
|
cannam@64
|
392 (i, sfinfo.samplerate, outputNo, plugin->process
|
cannam@99
|
393 (plugbuf, RealTime::frame2RealTime(i, sfinfo.samplerate)),
|
cannam@109
|
394 out, useFrames);
|
cannam@88
|
395
|
cannam@88
|
396 int pp = progress;
|
cannam@88
|
397 progress = lrintf((float(i) / sfinfo.frames) * 100.f);
|
cannam@88
|
398 if (progress != pp && out) {
|
cannam@88
|
399 cerr << "\r" << progress << "%";
|
cannam@88
|
400 }
|
cannam@16
|
401 }
|
cannam@88
|
402 if (out) cerr << "\rDone" << endl;
|
cannam@16
|
403
|
cannam@64
|
404 printFeatures(sfinfo.frames, sfinfo.samplerate, outputNo,
|
cannam@109
|
405 plugin->getRemainingFeatures(), out, useFrames);
|
cannam@16
|
406
|
cannam@29
|
407 returnValue = 0;
|
cannam@29
|
408
|
cannam@16
|
409 done:
|
cannam@16
|
410 delete plugin;
|
cannam@88
|
411 if (out) {
|
cannam@88
|
412 out->close();
|
cannam@88
|
413 delete out;
|
cannam@88
|
414 }
|
cannam@16
|
415 sf_close(sndfile);
|
cannam@29
|
416 return returnValue;
|
cannam@1
|
417 }
|
cannam@1
|
418
|
cannam@16
|
419 void
|
cannam@99
|
420 printFeatures(int frame, int sr, int output,
|
cannam@109
|
421 Plugin::FeatureSet features, ofstream *out, bool useFrames)
|
cannam@99
|
422 {
|
cannam@99
|
423 for (unsigned int i = 0; i < features[output].size(); ++i) {
|
cannam@99
|
424
|
cannam@109
|
425 if (useFrames) {
|
cannam@99
|
426
|
cannam@109
|
427 int displayFrame = frame;
|
cannam@109
|
428
|
cannam@109
|
429 if (features[output][i].hasTimestamp) {
|
cannam@109
|
430 displayFrame = RealTime::realTime2Frame
|
cannam@109
|
431 (features[output][i].timestamp, sr);
|
cannam@109
|
432 }
|
cannam@109
|
433
|
cannam@109
|
434 (out ? *out : cout) << displayFrame << ":";
|
cannam@109
|
435
|
cannam@109
|
436 } else {
|
cannam@109
|
437
|
cannam@109
|
438 RealTime rt = RealTime::frame2RealTime(frame, sr);
|
cannam@109
|
439
|
cannam@109
|
440 if (features[output][i].hasTimestamp) {
|
cannam@109
|
441 rt = features[output][i].timestamp;
|
cannam@109
|
442 }
|
cannam@109
|
443
|
cannam@109
|
444 (out ? *out : cout) << rt.toString() << ":";
|
cannam@99
|
445 }
|
cannam@99
|
446
|
cannam@99
|
447 for (unsigned int j = 0; j < features[output][i].values.size(); ++j) {
|
cannam@99
|
448 (out ? *out : cout) << " " << features[output][i].values[j];
|
cannam@99
|
449 }
|
cannam@99
|
450
|
cannam@99
|
451 (out ? *out : cout) << endl;
|
cannam@99
|
452 }
|
cannam@99
|
453 }
|
cannam@99
|
454
|
cannam@99
|
455 void
|
cannam@64
|
456 printPluginPath(bool verbose)
|
cannam@40
|
457 {
|
cannam@64
|
458 if (verbose) {
|
cannam@64
|
459 cout << "\nVamp plugin search path: ";
|
cannam@64
|
460 }
|
cannam@64
|
461
|
cannam@99
|
462 vector<string> path = PluginHostAdapter::getPluginPath();
|
cannam@40
|
463 for (size_t i = 0; i < path.size(); ++i) {
|
cannam@64
|
464 if (verbose) {
|
cannam@64
|
465 cout << "[" << path[i] << "]";
|
cannam@64
|
466 } else {
|
cannam@64
|
467 cout << path[i] << endl;
|
cannam@64
|
468 }
|
cannam@40
|
469 }
|
cannam@64
|
470
|
cannam@64
|
471 if (verbose) cout << endl;
|
cannam@40
|
472 }
|
cannam@40
|
473
|
cannam@40
|
474 void
|
cannam@95
|
475 enumeratePlugins(Verbosity verbosity)
|
cannam@40
|
476 {
|
cannam@64
|
477 PluginLoader *loader = PluginLoader::getInstance();
|
cannam@64
|
478
|
cannam@95
|
479 if (verbosity == PluginInformation) {
|
cannam@95
|
480 cout << "\nVamp plugin libraries found in search path:" << endl;
|
cannam@95
|
481 }
|
cannam@64
|
482
|
cannam@99
|
483 vector<PluginLoader::PluginKey> plugins = loader->listPlugins();
|
cannam@99
|
484 typedef multimap<string, PluginLoader::PluginKey>
|
cannam@64
|
485 LibraryMap;
|
cannam@64
|
486 LibraryMap libraryMap;
|
cannam@64
|
487
|
cannam@64
|
488 for (size_t i = 0; i < plugins.size(); ++i) {
|
cannam@99
|
489 string path = loader->getLibraryPathForPlugin(plugins[i]);
|
cannam@64
|
490 libraryMap.insert(LibraryMap::value_type(path, plugins[i]));
|
cannam@64
|
491 }
|
cannam@64
|
492
|
cannam@99
|
493 string prevPath = "";
|
cannam@64
|
494 int index = 0;
|
cannam@64
|
495
|
cannam@64
|
496 for (LibraryMap::iterator i = libraryMap.begin();
|
cannam@64
|
497 i != libraryMap.end(); ++i) {
|
cannam@64
|
498
|
cannam@99
|
499 string path = i->first;
|
cannam@64
|
500 PluginLoader::PluginKey key = i->second;
|
cannam@64
|
501
|
cannam@64
|
502 if (path != prevPath) {
|
cannam@64
|
503 prevPath = path;
|
cannam@64
|
504 index = 0;
|
cannam@95
|
505 if (verbosity == PluginInformation) {
|
cannam@95
|
506 cout << "\n " << path << ":" << endl;
|
cannam@95
|
507 }
|
cannam@40
|
508 }
|
cannam@64
|
509
|
cannam@99
|
510 Plugin *plugin = loader->loadPlugin(key, 48000);
|
cannam@64
|
511 if (plugin) {
|
cannam@64
|
512
|
cannam@64
|
513 char c = char('A' + index);
|
cannam@64
|
514 if (c > 'Z') c = char('a' + (index - 26));
|
cannam@64
|
515
|
cannam@95
|
516 if (verbosity == PluginInformation) {
|
cannam@64
|
517
|
cannam@95
|
518 cout << " [" << c << "] [v"
|
cannam@95
|
519 << plugin->getVampApiVersion() << "] "
|
cannam@95
|
520 << plugin->getName() << ", \""
|
cannam@95
|
521 << plugin->getIdentifier() << "\"" << " ["
|
cannam@95
|
522 << plugin->getMaker() << "]" << endl;
|
cannam@95
|
523
|
cannam@95
|
524 PluginLoader::PluginCategoryHierarchy category =
|
cannam@95
|
525 loader->getPluginCategory(key);
|
cannam@95
|
526
|
cannam@95
|
527 if (!category.empty()) {
|
cannam@95
|
528 cout << " ";
|
cannam@95
|
529 for (size_t ci = 0; ci < category.size(); ++ci) {
|
cannam@95
|
530 cout << " > " << category[ci];
|
cannam@95
|
531 }
|
cannam@95
|
532 cout << endl;
|
cannam@64
|
533 }
|
cannam@95
|
534
|
cannam@95
|
535 if (plugin->getDescription() != "") {
|
cannam@95
|
536 cout << " - " << plugin->getDescription() << endl;
|
cannam@95
|
537 }
|
cannam@95
|
538
|
cannam@95
|
539 } else if (verbosity == PluginIds) {
|
cannam@95
|
540 cout << "vamp:" << key << endl;
|
cannam@47
|
541 }
|
cannam@95
|
542
|
cannam@99
|
543 Plugin::OutputList outputs =
|
cannam@64
|
544 plugin->getOutputDescriptors();
|
cannam@64
|
545
|
cannam@95
|
546 if (outputs.size() > 1 || verbosity == PluginOutputIds) {
|
cannam@64
|
547 for (size_t j = 0; j < outputs.size(); ++j) {
|
cannam@95
|
548 if (verbosity == PluginInformation) {
|
cannam@95
|
549 cout << " (" << j << ") "
|
cannam@95
|
550 << outputs[j].name << ", \""
|
cannam@95
|
551 << outputs[j].identifier << "\"" << endl;
|
cannam@95
|
552 if (outputs[j].description != "") {
|
cannam@95
|
553 cout << " - "
|
cannam@95
|
554 << outputs[j].description << endl;
|
cannam@95
|
555 }
|
cannam@95
|
556 } else if (verbosity == PluginOutputIds) {
|
cannam@95
|
557 cout << "vamp:" << key << ":" << outputs[j].identifier << endl;
|
cannam@40
|
558 }
|
cannam@40
|
559 }
|
cannam@64
|
560 }
|
cannam@64
|
561
|
cannam@64
|
562 ++index;
|
cannam@64
|
563
|
cannam@64
|
564 delete plugin;
|
cannam@40
|
565 }
|
cannam@40
|
566 }
|
cannam@64
|
567
|
cannam@95
|
568 if (verbosity == PluginInformation) {
|
cannam@95
|
569 cout << endl;
|
cannam@95
|
570 }
|
cannam@40
|
571 }
|
cannam@40
|
572
|
cannam@40
|
573 void
|
cannam@99
|
574 printPluginCategoryList()
|
cannam@16
|
575 {
|
cannam@99
|
576 PluginLoader *loader = PluginLoader::getInstance();
|
cannam@88
|
577
|
cannam@99
|
578 vector<PluginLoader::PluginKey> plugins = loader->listPlugins();
|
cannam@88
|
579
|
cannam@99
|
580 set<string> printedcats;
|
cannam@99
|
581
|
cannam@99
|
582 for (size_t i = 0; i < plugins.size(); ++i) {
|
cannam@99
|
583
|
cannam@99
|
584 PluginLoader::PluginKey key = plugins[i];
|
cannam@99
|
585
|
cannam@99
|
586 PluginLoader::PluginCategoryHierarchy category =
|
cannam@99
|
587 loader->getPluginCategory(key);
|
cannam@99
|
588
|
cannam@99
|
589 Plugin *plugin = loader->loadPlugin(key, 48000);
|
cannam@99
|
590 if (!plugin) continue;
|
cannam@99
|
591
|
cannam@99
|
592 string catstr = "";
|
cannam@99
|
593
|
cannam@99
|
594 if (category.empty()) catstr = '|';
|
cannam@99
|
595 else {
|
cannam@99
|
596 for (size_t j = 0; j < category.size(); ++j) {
|
cannam@99
|
597 catstr += category[j];
|
cannam@99
|
598 catstr += '|';
|
cannam@99
|
599 if (printedcats.find(catstr) == printedcats.end()) {
|
cannam@99
|
600 std::cout << catstr << std::endl;
|
cannam@99
|
601 printedcats.insert(catstr);
|
cannam@99
|
602 }
|
cannam@99
|
603 }
|
cannam@16
|
604 }
|
cannam@88
|
605
|
cannam@99
|
606 std::cout << catstr << key << ":::" << plugin->getName() << ":::" << plugin->getMaker() << ":::" << plugin->getDescription() << std::endl;
|
cannam@16
|
607 }
|
cannam@16
|
608 }
|
cannam@16
|
609
|