Mercurial > hg > piper-cpp
diff vamp-json/VampJson.h @ 220:02de5df3a884
Add static output descriptor, pass through type URI
Note that the server doesn't actually populate any type URIs yet, so
this is only half-tested.
author | Chris Cannam <cannam@all-day-breakfast.com> |
---|---|
date | Thu, 08 Jun 2017 16:17:03 +0100 |
parents | 328ffacfc70e |
children | 9aca3267809c |
line wrap: on
line diff
--- a/vamp-json/VampJson.h Mon May 22 08:57:02 2017 +0100 +++ b/vamp-json/VampJson.h Thu Jun 08 16:17:03 2017 +0100 @@ -4,7 +4,7 @@ Piper C++ Centre for Digital Music, Queen Mary, University of London. - Copyright 2015-2016 QMUL. + Copyright 2015-2017 QMUL. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation @@ -47,6 +47,7 @@ #include <vamp-hostsdk/Plugin.h> #include <vamp-hostsdk/PluginLoader.h> +#include "vamp-support/StaticOutputDescriptor.h" #include "vamp-support/PluginStaticData.h" #include "vamp-support/PluginConfiguration.h" #include "vamp-support/RequestResponse.h" @@ -216,6 +217,15 @@ } static json11::Json + fromStaticOutputDescriptor(const StaticOutputDescriptor &sd) { + json11::Json::object jo; + if (sd.typeURI != "") { + jo["typeURI"] = sd.typeURI; + } + return json11::Json(jo); + } + + static json11::Json fromConfiguredOutputDescriptor(const Vamp::Plugin::OutputDescriptor &desc) { json11::Json::object jo { { "unit", desc.unit }, @@ -238,13 +248,28 @@ } static json11::Json - fromOutputDescriptor(const Vamp::Plugin::OutputDescriptor &desc) { + fromOutputDescriptor(const Vamp::Plugin::OutputDescriptor &desc, + const StaticOutputDescriptor &sd) { json11::Json::object jo { { "basic", fromBasicDescriptor(desc) }, + { "static", fromStaticOutputDescriptor(sd) }, { "configured", fromConfiguredOutputDescriptor(desc) } }; return json11::Json(jo); } + + static StaticOutputDescriptor + toStaticOutputDescriptor(json11::Json j, std::string &err) { + + StaticOutputDescriptor sd; + if (!j.is_object()) { + err = "object expected for static output descriptor"; + return {}; + } + + sd.typeURI = j["typeURI"].string_value(); + return sd; + } static Vamp::Plugin::OutputDescriptor toConfiguredOutputDescriptor(json11::Json j, std::string &err) { @@ -296,7 +321,7 @@ return od; } - static Vamp::Plugin::OutputDescriptor + static std::pair<Vamp::Plugin::OutputDescriptor, StaticOutputDescriptor> toOutputDescriptor(json11::Json j, std::string &err) { Vamp::Plugin::OutputDescriptor od; @@ -311,7 +336,13 @@ toBasicDescriptor(j["basic"], od, err); if (failed(err)) return {}; - return od; + StaticOutputDescriptor sd; + if (j["static"] != json11::Json()) { + sd = toStaticOutputDescriptor(j["static"], err); + if (failed(err)) return {}; + } + + return { od, sd }; } static json11::Json @@ -569,7 +600,11 @@ auto vouts = d.basicOutputInfo; for (auto &o: vouts) outinfo.push_back(fromBasicDescriptor(o)); jo["basicOutputInfo"] = outinfo; - + + json11::Json::object statinfo; + auto souts = d.staticOutputInfo; + for (auto &s: souts) jo[s.first] = fromStaticOutputDescriptor(s.second); + return json11::Json(jo); } @@ -968,7 +1003,12 @@ json11::Json::array outs; for (auto &d: cr.outputs) { - outs.push_back(fromOutputDescriptor(d)); + auto id = d.identifier; + StaticOutputDescriptor sd; + if (cr.staticOutputInfo.find(id) != cr.staticOutputInfo.end()) { + sd = cr.staticOutputInfo.at(id); + } + outs.push_back(fromOutputDescriptor(d, sd)); } jo["outputList"] = outs; @@ -1001,8 +1041,10 @@ cr.plugin = pmapper.handleToPlugin(j["handle"].int_value()); for (const auto &o: j["outputList"].array_items()) { - cr.outputs.push_back(toOutputDescriptor(o, err)); + auto odpair = toOutputDescriptor(o, err); if (failed(err)) return {}; + cr.outputs.push_back(odpair.first); + cr.staticOutputInfo[odpair.first.identifier] = odpair.second; } cr.framing.stepSize = int(round(j["framing"]["stepSize"].number_value()));