comparison host/vamp-simple-host.cpp @ 99:fe31e6aed666

* Add --list-by-category to vamp-simple-host * Some comment updates
author cannam
date Mon, 14 Jan 2008 11:00:41 +0000
parents cd4425ab7b98
children 9830daccee4b
comparison
equal deleted inserted replaced
98:896a97349ac5 99:fe31e6aed666
41 #include "vamp-sdk/hostext/PluginLoader.h" 41 #include "vamp-sdk/hostext/PluginLoader.h"
42 #include "vamp/vamp.h" 42 #include "vamp/vamp.h"
43 43
44 #include <iostream> 44 #include <iostream>
45 #include <fstream> 45 #include <fstream>
46 #include <set>
46 #include <sndfile.h> 47 #include <sndfile.h>
47 48
48 #include "system.h" 49 #include "system.h"
49 50
50 #include <cmath> 51 #include <cmath>
51 52
52 using std::cout; 53 using namespace std;
53 using std::cerr; 54
54 using std::endl; 55 using Vamp::Plugin;
55 using std::string; 56 using Vamp::PluginHostAdapter;
56 using std::vector; 57 using Vamp::RealTime;
57 using std::ofstream;
58 using std::ios;
59
60 using Vamp::HostExt::PluginLoader; 58 using Vamp::HostExt::PluginLoader;
61 59
62 #define HOST_VERSION "1.1" 60 #define HOST_VERSION "1.1"
63 61
64 enum Verbosity { 62 enum Verbosity {
65 PluginIds, 63 PluginIds,
66 PluginOutputIds, 64 PluginOutputIds,
67 PluginInformation 65 PluginInformation
68 }; 66 };
69 67
70 void printFeatures(int, int, int, Vamp::Plugin::FeatureSet, ofstream *); 68 void printFeatures(int, int, int, Plugin::FeatureSet, ofstream *);
71 void transformInput(float *, size_t); 69 void transformInput(float *, size_t);
72 void fft(unsigned int, bool, double *, double *, double *, double *); 70 void fft(unsigned int, bool, double *, double *, double *, double *);
73 void printPluginPath(bool verbose); 71 void printPluginPath(bool verbose);
72 void printPluginCategoryList();
74 void enumeratePlugins(Verbosity); 73 void enumeratePlugins(Verbosity);
75 void listPluginsInLibrary(string soname); 74 void listPluginsInLibrary(string soname);
76 int runPlugin(string myname, string soname, string id, string output, 75 int runPlugin(string myname, string soname, string id, string output,
77 int outputNo, string inputFile, string outfilename); 76 int outputNo, string inputFile, string outfilename);
78 77
100 " -- List the plugins in the search path in a terse machine-readable format,\n" 99 " -- List the plugins in the search path in a terse machine-readable format,\n"
101 " in the form vamp:soname:identifier.\n\n" 100 " in the form vamp:soname:identifier.\n\n"
102 " " << name << " --list-outputs\n\n" 101 " " << name << " --list-outputs\n\n"
103 " -- List the outputs for plugins in the search path in a machine-readable\n" 102 " -- List the outputs for plugins in the search path in a machine-readable\n"
104 " format, in the form vamp:soname:identifier:output.\n\n" 103 " format, in the form vamp:soname:identifier:output.\n\n"
104 " " << name << " --list-by-category\n\n"
105 " -- List the plugins as a plugin index by category, in a machine-readable\n"
106 " format. The format may change in future releases.\n\n"
105 " " << name << " -p\n\n" 107 " " << name << " -p\n\n"
106 " -- Print out the Vamp library search path.\n\n" 108 " -- Print out the Vamp library search path.\n\n"
107 " " << name << " -v\n\n" 109 " " << name << " -v\n\n"
108 " -- Display version information only.\n" 110 " -- Display version information only.\n"
109 << endl; 111 << endl;
148 return 0; 150 return 0;
149 151
150 } else if (!strcmp(argv[1], "--list-outputs")) { 152 } else if (!strcmp(argv[1], "--list-outputs")) {
151 153
152 enumeratePlugins(PluginOutputIds); 154 enumeratePlugins(PluginOutputIds);
155 return 0;
156
157 } else if (!strcmp(argv[1], "--list-by-category")) {
158
159 printPluginCategoryList();
153 return 0; 160 return 0;
154 161
155 } else usage(name); 162 } else usage(name);
156 } 163 }
157 164
248 delete out; 255 delete out;
249 return 1; 256 return 1;
250 } 257 }
251 } 258 }
252 259
253 Vamp::Plugin *plugin = loader->loadPlugin 260 Plugin *plugin = loader->loadPlugin
254 (key, sfinfo.samplerate, PluginLoader::ADAPT_ALL_SAFE); 261 (key, sfinfo.samplerate, PluginLoader::ADAPT_ALL_SAFE);
255 if (!plugin) { 262 if (!plugin) {
256 cerr << myname << ": ERROR: Failed to load plugin \"" << id 263 cerr << myname << ": ERROR: Failed to load plugin \"" << id
257 << "\" from library \"" << soname << "\"" << endl; 264 << "\" from library \"" << soname << "\"" << endl;
258 sf_close(sndfile); 265 sf_close(sndfile);
270 277
271 if (blockSize == 0) { 278 if (blockSize == 0) {
272 blockSize = 1024; 279 blockSize = 1024;
273 } 280 }
274 if (stepSize == 0) { 281 if (stepSize == 0) {
275 if (plugin->getInputDomain() == Vamp::Plugin::FrequencyDomain) { 282 if (plugin->getInputDomain() == Plugin::FrequencyDomain) {
276 stepSize = blockSize/2; 283 stepSize = blockSize/2;
277 } else { 284 } else {
278 stepSize = blockSize; 285 stepSize = blockSize;
279 } 286 }
280 } else if (stepSize > blockSize) { 287 } else if (stepSize > blockSize) {
281 cerr << "WARNING: stepSize " << stepSize << " > blockSize " << blockSize << ", resetting blockSize to "; 288 cerr << "WARNING: stepSize " << stepSize << " > blockSize " << blockSize << ", resetting blockSize to ";
282 if (plugin->getInputDomain() == Vamp::Plugin::FrequencyDomain) { 289 if (plugin->getInputDomain() == Plugin::FrequencyDomain) {
283 blockSize = stepSize * 2; 290 blockSize = stepSize * 2;
284 } else { 291 } else {
285 blockSize = stepSize; 292 blockSize = stepSize;
286 } 293 }
287 cerr << blockSize << endl; 294 cerr << blockSize << endl;
299 int minch = plugin->getMinChannelCount(); 306 int minch = plugin->getMinChannelCount();
300 int maxch = plugin->getMaxChannelCount(); 307 int maxch = plugin->getMaxChannelCount();
301 cerr << "Plugin accepts " << minch << " -> " << maxch << " channel(s)" << endl; 308 cerr << "Plugin accepts " << minch << " -> " << maxch << " channel(s)" << endl;
302 cerr << "Sound file has " << channels << " (will mix/augment if necessary)" << endl; 309 cerr << "Sound file has " << channels << " (will mix/augment if necessary)" << endl;
303 310
304 Vamp::Plugin::OutputList outputs = plugin->getOutputDescriptors(); 311 Plugin::OutputList outputs = plugin->getOutputDescriptors();
305 Vamp::Plugin::OutputDescriptor od; 312 Plugin::OutputDescriptor od;
306 313
307 int returnValue = 1; 314 int returnValue = 1;
308 int progress = 0; 315 int progress = 0;
309 316
310 if (outputs.empty()) { 317 if (outputs.empty()) {
370 } 377 }
371 } 378 }
372 379
373 printFeatures 380 printFeatures
374 (i, sfinfo.samplerate, outputNo, plugin->process 381 (i, sfinfo.samplerate, outputNo, plugin->process
375 (plugbuf, Vamp::RealTime::frame2RealTime(i, sfinfo.samplerate)), 382 (plugbuf, RealTime::frame2RealTime(i, sfinfo.samplerate)),
376 out); 383 out);
377 384
378 int pp = progress; 385 int pp = progress;
379 progress = lrintf((float(i) / sfinfo.frames) * 100.f); 386 progress = lrintf((float(i) / sfinfo.frames) * 100.f);
380 if (progress != pp && out) { 387 if (progress != pp && out) {
397 sf_close(sndfile); 404 sf_close(sndfile);
398 return returnValue; 405 return returnValue;
399 } 406 }
400 407
401 void 408 void
409 printFeatures(int frame, int sr, int output,
410 Plugin::FeatureSet features, ofstream *out)
411 {
412 for (unsigned int i = 0; i < features[output].size(); ++i) {
413
414 RealTime rt = RealTime::frame2RealTime(frame, sr);
415
416 if (features[output][i].hasTimestamp) {
417 rt = features[output][i].timestamp;
418 }
419
420 (out ? *out : cout) << rt.toString() << ":";
421
422 for (unsigned int j = 0; j < features[output][i].values.size(); ++j) {
423 (out ? *out : cout) << " " << features[output][i].values[j];
424 }
425
426 (out ? *out : cout) << endl;
427 }
428 }
429
430 void
402 printPluginPath(bool verbose) 431 printPluginPath(bool verbose)
403 { 432 {
404 if (verbose) { 433 if (verbose) {
405 cout << "\nVamp plugin search path: "; 434 cout << "\nVamp plugin search path: ";
406 } 435 }
407 436
408 vector<string> path = Vamp::PluginHostAdapter::getPluginPath(); 437 vector<string> path = PluginHostAdapter::getPluginPath();
409 for (size_t i = 0; i < path.size(); ++i) { 438 for (size_t i = 0; i < path.size(); ++i) {
410 if (verbose) { 439 if (verbose) {
411 cout << "[" << path[i] << "]"; 440 cout << "[" << path[i] << "]";
412 } else { 441 } else {
413 cout << path[i] << endl; 442 cout << path[i] << endl;
424 453
425 if (verbosity == PluginInformation) { 454 if (verbosity == PluginInformation) {
426 cout << "\nVamp plugin libraries found in search path:" << endl; 455 cout << "\nVamp plugin libraries found in search path:" << endl;
427 } 456 }
428 457
429 std::vector<PluginLoader::PluginKey> plugins = loader->listPlugins(); 458 vector<PluginLoader::PluginKey> plugins = loader->listPlugins();
430 typedef std::multimap<std::string, PluginLoader::PluginKey> 459 typedef multimap<string, PluginLoader::PluginKey>
431 LibraryMap; 460 LibraryMap;
432 LibraryMap libraryMap; 461 LibraryMap libraryMap;
433 462
434 for (size_t i = 0; i < plugins.size(); ++i) { 463 for (size_t i = 0; i < plugins.size(); ++i) {
435 std::string path = loader->getLibraryPathForPlugin(plugins[i]); 464 string path = loader->getLibraryPathForPlugin(plugins[i]);
436 libraryMap.insert(LibraryMap::value_type(path, plugins[i])); 465 libraryMap.insert(LibraryMap::value_type(path, plugins[i]));
437 } 466 }
438 467
439 std::string prevPath = ""; 468 string prevPath = "";
440 int index = 0; 469 int index = 0;
441 470
442 for (LibraryMap::iterator i = libraryMap.begin(); 471 for (LibraryMap::iterator i = libraryMap.begin();
443 i != libraryMap.end(); ++i) { 472 i != libraryMap.end(); ++i) {
444 473
445 std::string path = i->first; 474 string path = i->first;
446 PluginLoader::PluginKey key = i->second; 475 PluginLoader::PluginKey key = i->second;
447 476
448 if (path != prevPath) { 477 if (path != prevPath) {
449 prevPath = path; 478 prevPath = path;
450 index = 0; 479 index = 0;
451 if (verbosity == PluginInformation) { 480 if (verbosity == PluginInformation) {
452 cout << "\n " << path << ":" << endl; 481 cout << "\n " << path << ":" << endl;
453 } 482 }
454 } 483 }
455 484
456 Vamp::Plugin *plugin = loader->loadPlugin(key, 48000); 485 Plugin *plugin = loader->loadPlugin(key, 48000);
457 if (plugin) { 486 if (plugin) {
458 487
459 char c = char('A' + index); 488 char c = char('A' + index);
460 if (c > 'Z') c = char('a' + (index - 26)); 489 if (c > 'Z') c = char('a' + (index - 26));
461 490
484 513
485 } else if (verbosity == PluginIds) { 514 } else if (verbosity == PluginIds) {
486 cout << "vamp:" << key << endl; 515 cout << "vamp:" << key << endl;
487 } 516 }
488 517
489 Vamp::Plugin::OutputList outputs = 518 Plugin::OutputList outputs =
490 plugin->getOutputDescriptors(); 519 plugin->getOutputDescriptors();
491 520
492 if (outputs.size() > 1 || verbosity == PluginOutputIds) { 521 if (outputs.size() > 1 || verbosity == PluginOutputIds) {
493 for (size_t j = 0; j < outputs.size(); ++j) { 522 for (size_t j = 0; j < outputs.size(); ++j) {
494 if (verbosity == PluginInformation) { 523 if (verbosity == PluginInformation) {
515 cout << endl; 544 cout << endl;
516 } 545 }
517 } 546 }
518 547
519 void 548 void
520 printFeatures(int frame, int sr, int output, 549 printPluginCategoryList()
521 Vamp::Plugin::FeatureSet features, ofstream *out) 550 {
522 { 551 PluginLoader *loader = PluginLoader::getInstance();
523 for (unsigned int i = 0; i < features[output].size(); ++i) { 552
524 553 vector<PluginLoader::PluginKey> plugins = loader->listPlugins();
525 Vamp::RealTime rt = Vamp::RealTime::frame2RealTime(frame, sr); 554
526 555 set<string> printedcats;
527 if (features[output][i].hasTimestamp) { 556
528 rt = features[output][i].timestamp; 557 for (size_t i = 0; i < plugins.size(); ++i) {
529 } 558
530 559 PluginLoader::PluginKey key = plugins[i];
531 (out ? *out : cout) << rt.toString() << ":";
532
533 for (unsigned int j = 0; j < features[output][i].values.size(); ++j) {
534 (out ? *out : cout) << " " << features[output][i].values[j];
535 }
536
537 (out ? *out : cout) << endl;
538 }
539 }
540
541
542 560
561 PluginLoader::PluginCategoryHierarchy category =
562 loader->getPluginCategory(key);
563
564 Plugin *plugin = loader->loadPlugin(key, 48000);
565 if (!plugin) continue;
566
567 string catstr = "";
568
569 if (category.empty()) catstr = '|';
570 else {
571 for (size_t j = 0; j < category.size(); ++j) {
572 catstr += category[j];
573 catstr += '|';
574 if (printedcats.find(catstr) == printedcats.end()) {
575 std::cout << catstr << std::endl;
576 printedcats.insert(catstr);
577 }
578 }
579 }
580
581 std::cout << catstr << key << ":::" << plugin->getName() << ":::" << plugin->getMaker() << ":::" << plugin->getDescription() << std::endl;
582 }
583 }
584