Mercurial > hg > piper-cpp
changeset 238:0664784566d8
Generate plausible metadata names; emit empty type URIs for outputs that
don't have any (to make the structure clearer)
author | Chris Cannam <cannam@all-day-breakfast.com> |
---|---|
date | Tue, 13 Jun 2017 12:09:35 +0100 |
parents | 5ba2749f2024 |
children | 335a5909d4a8 |
files | vamp-stubber/stubber.cpp |
diffstat | 1 files changed, 53 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/vamp-stubber/stubber.cpp Tue Jun 13 10:06:44 2017 +0100 +++ b/vamp-stubber/stubber.cpp Tue Jun 13 12:09:35 2017 +0100 @@ -74,12 +74,11 @@ { cerr << "\n" << myname << ": Emit stub version of main code\nfor a Piper Adapter implementation of a Vamp plugin library\n\n" - " Usage: " << myname << " [-d] <soname>\n" + " Usage: " << myname << " [-d] <libname>\n" " " << myname << " -v\n" " " << myname << " -h\n\n" " where\n" - " <soname>: the Vamp plugin library name to emit stub conversion code for\n" - " -d: also print debug information to stderr\n" + " <libname>: the Vamp plugin library name to emit stub conversion code for\n" " -v: print version number to stdout and exit\n" " -h: print this text to stderr and exit\n\n"; if (successful) exit(0); @@ -139,10 +138,10 @@ } ListResponse -makeRequest(string soname, bool debug) +makeRequest(string libname) { ListRequest req; - req.from.push_back(soname); + req.from.push_back(libname); return LoaderRequests().listPluginData(req); } @@ -155,14 +154,47 @@ PlausibleMetadata inventPlausibleMetadata(string key) { + string className, adapterName; + bool initial = true, interCap = false; + + int idIdx = 0; + for (int i = 0; i < int(key.size()); ++i) { + char c = key[i]; + if (c == ':') { + idIdx = i + 1; + break; + } + } + + for (int i = idIdx; i < int(key.size()); ++i) { + char c = key[i]; + if (isalpha(c)) { + if (initial || interCap) { + className += toupper(c); + } else { + className += c; + } + if (interCap) { + adapterName += toupper(c); + } else { + adapterName += c; + } + interCap = false; + } else { + interCap = true; + } + initial = false; + } + adapterName += "Adapter"; + PlausibleMetadata pm; - pm.className = "MyPlugin";//!!! - pm.adapterName = "myPluginAdapter";//!!! + pm.className = className; + pm.adapterName = adapterName; return pm; } void -emitFor(string soname, const ListResponse &resp, bool debug) +emitFor(string libname, const ListResponse &resp) { cout << "\n#include \"PiperExport.h\"\n" @@ -172,7 +204,7 @@ "using piper_vamp_js::PiperAdapter;\n" "using piper_vamp_js::PiperPluginLibrary;\n" "\n" - "static std::string soname(\"" << soname << "\");\n" + "static std::string libname(\"" << libname << "\");\n" "\n"; // The same plugin key may appear more than once in the available @@ -194,7 +226,7 @@ << pm.className << "> // replace with the actual Vamp plugin class name for \"" << plugin.basic.identifier << "\" plugin\n" << pm.adapterName - << "(\n soname,\n "; + << "(\n libname,\n "; string catString = "{ "; bool first = true; @@ -208,15 +240,18 @@ cout << "{\n "; first = true; - for (auto o: plugin.staticOutputInfo) { + for (auto o: plugin.basicOutputInfo) { if (!first) { cout << ",\n "; } cout << " "; - string outputId = o.first; - const StaticOutputDescriptor &desc = o.second; - cout << "{ \"" << outputId << "\",\n { \"" - << desc.typeURI << "\" }\n }"; + string outputId = o.identifier; + cout << "{ \"" << outputId << "\",\n { \""; + if (plugin.staticOutputInfo.find(outputId) != + plugin.staticOutputInfo.end()) { + cout << plugin.staticOutputInfo.at(outputId).typeURI; + } + cout << "\" }\n }"; first = false; } cout << "\n }\n"; @@ -250,8 +285,6 @@ usage(); } - bool debug = false; - string arg = argv[1]; if (arg == "-h") { if (argc == 2) { @@ -265,16 +298,9 @@ } else { usage(); } - } else if (arg == "-d") { - if (argc == 2) { - usage(); - } else { - debug = true; - arg = argv[2]; - } } - string soname = arg; + string libname = arg; try { initFds(false); @@ -285,11 +311,11 @@ suspendOutput(); - ListResponse resp = makeRequest(soname, debug); + ListResponse resp = makeRequest(libname); resumeOutput(); - emitFor(soname, resp, debug); + emitFor(libname, resp); exit(0); }