Mercurial > hg > vamp-plugin-sdk
comparison host/vamp-simple-host.cpp @ 95:cd4425ab7b98
* Add --list-ids and --list-outputs options
author | cannam |
---|---|
date | Fri, 16 Nov 2007 21:19:24 +0000 |
parents | c94c066a4897 |
children | fe31e6aed666 |
comparison
equal
deleted
inserted
replaced
94:70bcd0b62cba | 95:cd4425ab7b98 |
---|---|
59 | 59 |
60 using Vamp::HostExt::PluginLoader; | 60 using Vamp::HostExt::PluginLoader; |
61 | 61 |
62 #define HOST_VERSION "1.1" | 62 #define HOST_VERSION "1.1" |
63 | 63 |
64 enum Verbosity { | |
65 PluginIds, | |
66 PluginOutputIds, | |
67 PluginInformation | |
68 }; | |
69 | |
64 void printFeatures(int, int, int, Vamp::Plugin::FeatureSet, ofstream *); | 70 void printFeatures(int, int, int, Vamp::Plugin::FeatureSet, ofstream *); |
65 void transformInput(float *, size_t); | 71 void transformInput(float *, size_t); |
66 void fft(unsigned int, bool, double *, double *, double *, double *); | 72 void fft(unsigned int, bool, double *, double *, double *, double *); |
67 void printPluginPath(bool verbose); | 73 void printPluginPath(bool verbose); |
68 void enumeratePlugins(); | 74 void enumeratePlugins(Verbosity); |
69 void listPluginsInLibrary(string soname); | 75 void listPluginsInLibrary(string soname); |
70 int runPlugin(string myname, string soname, string id, string output, | 76 int runPlugin(string myname, string soname, string id, string output, |
71 int outputNo, string inputFile, string outfilename); | 77 int outputNo, string inputFile, string outfilename); |
72 | 78 |
73 void usage(const char *name) | 79 void usage(const char *name) |
76 << name << ": A simple Vamp plugin host.\n\n" | 82 << name << ": A simple Vamp plugin host.\n\n" |
77 "Centre for Digital Music, Queen Mary, University of London.\n" | 83 "Centre for Digital Music, Queen Mary, University of London.\n" |
78 "Copyright 2006-2007 Chris Cannam and QMUL.\n" | 84 "Copyright 2006-2007 Chris Cannam and QMUL.\n" |
79 "Freely redistributable; published under a BSD-style license.\n\n" | 85 "Freely redistributable; published under a BSD-style license.\n\n" |
80 "Usage:\n\n" | 86 "Usage:\n\n" |
81 " " << name << " pluginlibrary[." << PLUGIN_SUFFIX << "]:plugin[:output] file.wav [-o outfile.txt]\n" | 87 " " << name << " pluginlibrary[." << PLUGIN_SUFFIX << "]:plugin[:output] file.wav [-o out.txt]\n" |
82 " " << name << " pluginlibrary[." << PLUGIN_SUFFIX << "]:plugin file.wav [outputno] [-o outfile.txt]\n\n" | 88 " " << name << " pluginlibrary[." << PLUGIN_SUFFIX << "]:plugin file.wav [outputno] [-o out.txt]\n\n" |
83 " -- Load plugin id \"plugin\" from \"pluginlibrary\" and run it on the\n" | 89 " -- Load plugin id \"plugin\" from \"pluginlibrary\" and run it on the\n" |
84 " audio data in \"file.wav\", retrieving the named \"output\", or output\n" | 90 " audio data in \"file.wav\", retrieving the named \"output\", or output\n" |
85 " number \"outputno\" (the first output by default) and dumping it to\n" | 91 " number \"outputno\" (the first output by default) and dumping it to\n" |
86 " standard output, or to \"outfile.txt\" if the -o option is given.\n\n" | 92 " standard output, or to \"out.txt\" if the -o option is given.\n\n" |
87 " \"pluginlibrary\" should be a library name, not a file path; the\n" | 93 " \"pluginlibrary\" should be a library name, not a file path; the\n" |
88 " standard Vamp library search path will be used to locate it. If\n" | 94 " standard Vamp library search path will be used to locate it. If\n" |
89 " a file path is supplied, the directory part(s) will be ignored.\n\n" | 95 " a file path is supplied, the directory part(s) will be ignored.\n\n" |
90 " " << name << " -l\n\n" | 96 " " << name << " -l\n\n" |
91 " -- List the plugin libraries and Vamp plugins in the library search path.\n\n" | 97 " -- List the plugin libraries and Vamp plugins in the library search path\n" |
98 " in a verbose human-readable format.\n\n" | |
99 " " << name << " --list-ids\n\n" | |
100 " -- List the plugins in the search path in a terse machine-readable format,\n" | |
101 " in the form vamp:soname:identifier.\n\n" | |
102 " " << name << " --list-outputs\n\n" | |
103 " -- 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" | |
92 " " << name << " -p\n\n" | 105 " " << name << " -p\n\n" |
93 " -- Print out the Vamp library search path.\n\n" | 106 " -- Print out the Vamp library search path.\n\n" |
94 " " << name << " -v\n\n" | 107 " " << name << " -v\n\n" |
95 " -- Display version information only.\n\n" | 108 " -- Display version information only.\n" |
96 << endl; | 109 << endl; |
97 exit(2); | 110 exit(2); |
98 } | 111 } |
99 | 112 |
100 int main(int argc, char **argv) | 113 int main(int argc, char **argv) |
119 return 0; | 132 return 0; |
120 | 133 |
121 } else if (!strcmp(argv[1], "-l")) { | 134 } else if (!strcmp(argv[1], "-l")) { |
122 | 135 |
123 printPluginPath(true); | 136 printPluginPath(true); |
124 enumeratePlugins(); | 137 enumeratePlugins(PluginInformation); |
125 return 0; | 138 return 0; |
126 | 139 |
127 } else if (!strcmp(argv[1], "-p")) { | 140 } else if (!strcmp(argv[1], "-p")) { |
128 | 141 |
129 printPluginPath(false); | 142 printPluginPath(false); |
143 return 0; | |
144 | |
145 } else if (!strcmp(argv[1], "--list-ids")) { | |
146 | |
147 enumeratePlugins(PluginIds); | |
148 return 0; | |
149 | |
150 } else if (!strcmp(argv[1], "--list-outputs")) { | |
151 | |
152 enumeratePlugins(PluginOutputIds); | |
130 return 0; | 153 return 0; |
131 | 154 |
132 } else usage(name); | 155 } else usage(name); |
133 } | 156 } |
134 | 157 |
393 | 416 |
394 if (verbose) cout << endl; | 417 if (verbose) cout << endl; |
395 } | 418 } |
396 | 419 |
397 void | 420 void |
398 enumeratePlugins() | 421 enumeratePlugins(Verbosity verbosity) |
399 { | 422 { |
400 PluginLoader *loader = PluginLoader::getInstance(); | 423 PluginLoader *loader = PluginLoader::getInstance(); |
401 | 424 |
402 cout << "\nVamp plugin libraries found in search path:" << endl; | 425 if (verbosity == PluginInformation) { |
426 cout << "\nVamp plugin libraries found in search path:" << endl; | |
427 } | |
403 | 428 |
404 std::vector<PluginLoader::PluginKey> plugins = loader->listPlugins(); | 429 std::vector<PluginLoader::PluginKey> plugins = loader->listPlugins(); |
405 typedef std::multimap<std::string, PluginLoader::PluginKey> | 430 typedef std::multimap<std::string, PluginLoader::PluginKey> |
406 LibraryMap; | 431 LibraryMap; |
407 LibraryMap libraryMap; | 432 LibraryMap libraryMap; |
421 PluginLoader::PluginKey key = i->second; | 446 PluginLoader::PluginKey key = i->second; |
422 | 447 |
423 if (path != prevPath) { | 448 if (path != prevPath) { |
424 prevPath = path; | 449 prevPath = path; |
425 index = 0; | 450 index = 0; |
426 cout << "\n " << path << ":" << endl; | 451 if (verbosity == PluginInformation) { |
452 cout << "\n " << path << ":" << endl; | |
453 } | |
427 } | 454 } |
428 | 455 |
429 Vamp::Plugin *plugin = loader->loadPlugin(key, 48000); | 456 Vamp::Plugin *plugin = loader->loadPlugin(key, 48000); |
430 if (plugin) { | 457 if (plugin) { |
431 | 458 |
432 char c = char('A' + index); | 459 char c = char('A' + index); |
433 if (c > 'Z') c = char('a' + (index - 26)); | 460 if (c > 'Z') c = char('a' + (index - 26)); |
434 | 461 |
435 cout << " [" << c << "] [v" | 462 if (verbosity == PluginInformation) { |
436 << plugin->getVampApiVersion() << "] " | 463 |
437 << plugin->getName() << ", \"" | 464 cout << " [" << c << "] [v" |
438 << plugin->getIdentifier() << "\"" << " [" | 465 << plugin->getVampApiVersion() << "] " |
439 << plugin->getMaker() << "]" << endl; | 466 << plugin->getName() << ", \"" |
440 | 467 << plugin->getIdentifier() << "\"" << " [" |
441 PluginLoader::PluginCategoryHierarchy category = | 468 << plugin->getMaker() << "]" << endl; |
442 loader->getPluginCategory(key); | 469 |
443 if (!category.empty()) { | 470 PluginLoader::PluginCategoryHierarchy category = |
444 cout << " "; | 471 loader->getPluginCategory(key); |
445 for (size_t ci = 0; ci < category.size(); ++ci) { | 472 |
446 cout << " > " << category[ci]; | 473 if (!category.empty()) { |
474 cout << " "; | |
475 for (size_t ci = 0; ci < category.size(); ++ci) { | |
476 cout << " > " << category[ci]; | |
477 } | |
478 cout << endl; | |
447 } | 479 } |
448 cout << endl; | 480 |
481 if (plugin->getDescription() != "") { | |
482 cout << " - " << plugin->getDescription() << endl; | |
483 } | |
484 | |
485 } else if (verbosity == PluginIds) { | |
486 cout << "vamp:" << key << endl; | |
449 } | 487 } |
450 | 488 |
451 if (plugin->getDescription() != "") { | |
452 cout << " - " << plugin->getDescription() << endl; | |
453 } | |
454 | |
455 Vamp::Plugin::OutputList outputs = | 489 Vamp::Plugin::OutputList outputs = |
456 plugin->getOutputDescriptors(); | 490 plugin->getOutputDescriptors(); |
457 | 491 |
458 if (outputs.size() > 1) { | 492 if (outputs.size() > 1 || verbosity == PluginOutputIds) { |
459 for (size_t j = 0; j < outputs.size(); ++j) { | 493 for (size_t j = 0; j < outputs.size(); ++j) { |
460 cout << " (" << j << ") " | 494 if (verbosity == PluginInformation) { |
461 << outputs[j].name << ", \"" | 495 cout << " (" << j << ") " |
462 << outputs[j].identifier << "\"" << endl; | 496 << outputs[j].name << ", \"" |
463 if (outputs[j].description != "") { | 497 << outputs[j].identifier << "\"" << endl; |
464 cout << " - " | 498 if (outputs[j].description != "") { |
465 << outputs[j].description << endl; | 499 cout << " - " |
500 << outputs[j].description << endl; | |
501 } | |
502 } else if (verbosity == PluginOutputIds) { | |
503 cout << "vamp:" << key << ":" << outputs[j].identifier << endl; | |
466 } | 504 } |
467 } | 505 } |
468 } | 506 } |
469 | 507 |
470 ++index; | 508 ++index; |
471 | 509 |
472 delete plugin; | 510 delete plugin; |
473 } | 511 } |
474 } | 512 } |
475 | 513 |
476 cout << endl; | 514 if (verbosity == PluginInformation) { |
515 cout << endl; | |
516 } | |
477 } | 517 } |
478 | 518 |
479 void | 519 void |
480 printFeatures(int frame, int sr, int output, | 520 printFeatures(int frame, int sr, int output, |
481 Vamp::Plugin::FeatureSet features, ofstream *out) | 521 Vamp::Plugin::FeatureSet features, ofstream *out) |