comparison 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
comparison
equal deleted inserted replaced
219:db929669e7d3 220:02de5df3a884
2 2
3 /* 3 /*
4 Piper C++ 4 Piper C++
5 5
6 Centre for Digital Music, Queen Mary, University of London. 6 Centre for Digital Music, Queen Mary, University of London.
7 Copyright 2015-2016 QMUL. 7 Copyright 2015-2017 QMUL.
8 8
9 Permission is hereby granted, free of charge, to any person 9 Permission is hereby granted, free of charge, to any person
10 obtaining a copy of this software and associated documentation 10 obtaining a copy of this software and associated documentation
11 files (the "Software"), to deal in the Software without 11 files (the "Software"), to deal in the Software without
12 restriction, including without limitation the rights to use, copy, 12 restriction, including without limitation the rights to use, copy,
45 #include <base-n/include/basen.hpp> 45 #include <base-n/include/basen.hpp>
46 46
47 #include <vamp-hostsdk/Plugin.h> 47 #include <vamp-hostsdk/Plugin.h>
48 #include <vamp-hostsdk/PluginLoader.h> 48 #include <vamp-hostsdk/PluginLoader.h>
49 49
50 #include "vamp-support/StaticOutputDescriptor.h"
50 #include "vamp-support/PluginStaticData.h" 51 #include "vamp-support/PluginStaticData.h"
51 #include "vamp-support/PluginConfiguration.h" 52 #include "vamp-support/PluginConfiguration.h"
52 #include "vamp-support/RequestResponse.h" 53 #include "vamp-support/RequestResponse.h"
53 54
54 #include "vamp-support/PluginHandleMapper.h" 55 #include "vamp-support/PluginHandleMapper.h"
214 return Vamp::Plugin::OutputDescriptor::OneSamplePerStep; 215 return Vamp::Plugin::OutputDescriptor::OneSamplePerStep;
215 } 216 }
216 } 217 }
217 218
218 static json11::Json 219 static json11::Json
220 fromStaticOutputDescriptor(const StaticOutputDescriptor &sd) {
221 json11::Json::object jo;
222 if (sd.typeURI != "") {
223 jo["typeURI"] = sd.typeURI;
224 }
225 return json11::Json(jo);
226 }
227
228 static json11::Json
219 fromConfiguredOutputDescriptor(const Vamp::Plugin::OutputDescriptor &desc) { 229 fromConfiguredOutputDescriptor(const Vamp::Plugin::OutputDescriptor &desc) {
220 json11::Json::object jo { 230 json11::Json::object jo {
221 { "unit", desc.unit }, 231 { "unit", desc.unit },
222 { "sampleType", fromSampleType(desc.sampleType) }, 232 { "sampleType", fromSampleType(desc.sampleType) },
223 { "sampleRate", desc.sampleRate }, 233 { "sampleRate", desc.sampleRate },
236 } 246 }
237 return json11::Json(jo); 247 return json11::Json(jo);
238 } 248 }
239 249
240 static json11::Json 250 static json11::Json
241 fromOutputDescriptor(const Vamp::Plugin::OutputDescriptor &desc) { 251 fromOutputDescriptor(const Vamp::Plugin::OutputDescriptor &desc,
252 const StaticOutputDescriptor &sd) {
242 json11::Json::object jo { 253 json11::Json::object jo {
243 { "basic", fromBasicDescriptor(desc) }, 254 { "basic", fromBasicDescriptor(desc) },
255 { "static", fromStaticOutputDescriptor(sd) },
244 { "configured", fromConfiguredOutputDescriptor(desc) } 256 { "configured", fromConfiguredOutputDescriptor(desc) }
245 }; 257 };
246 return json11::Json(jo); 258 return json11::Json(jo);
259 }
260
261 static StaticOutputDescriptor
262 toStaticOutputDescriptor(json11::Json j, std::string &err) {
263
264 StaticOutputDescriptor sd;
265 if (!j.is_object()) {
266 err = "object expected for static output descriptor";
267 return {};
268 }
269
270 sd.typeURI = j["typeURI"].string_value();
271 return sd;
247 } 272 }
248 273
249 static Vamp::Plugin::OutputDescriptor 274 static Vamp::Plugin::OutputDescriptor
250 toConfiguredOutputDescriptor(json11::Json j, std::string &err) { 275 toConfiguredOutputDescriptor(json11::Json j, std::string &err) {
251 276
294 } 319 }
295 320
296 return od; 321 return od;
297 } 322 }
298 323
299 static Vamp::Plugin::OutputDescriptor 324 static std::pair<Vamp::Plugin::OutputDescriptor, StaticOutputDescriptor>
300 toOutputDescriptor(json11::Json j, std::string &err) { 325 toOutputDescriptor(json11::Json j, std::string &err) {
301 326
302 Vamp::Plugin::OutputDescriptor od; 327 Vamp::Plugin::OutputDescriptor od;
303 if (!j.is_object()) { 328 if (!j.is_object()) {
304 err = "object expected for output descriptor"; 329 err = "object expected for output descriptor";
309 if (failed(err)) return {}; 334 if (failed(err)) return {};
310 335
311 toBasicDescriptor(j["basic"], od, err); 336 toBasicDescriptor(j["basic"], od, err);
312 if (failed(err)) return {}; 337 if (failed(err)) return {};
313 338
314 return od; 339 StaticOutputDescriptor sd;
340 if (j["static"] != json11::Json()) {
341 sd = toStaticOutputDescriptor(j["static"], err);
342 if (failed(err)) return {};
343 }
344
345 return { od, sd };
315 } 346 }
316 347
317 static json11::Json 348 static json11::Json
318 fromParameterDescriptor(const Vamp::PluginBase::ParameterDescriptor &desc) { 349 fromParameterDescriptor(const Vamp::PluginBase::ParameterDescriptor &desc) {
319 350
567 598
568 json11::Json::array outinfo; 599 json11::Json::array outinfo;
569 auto vouts = d.basicOutputInfo; 600 auto vouts = d.basicOutputInfo;
570 for (auto &o: vouts) outinfo.push_back(fromBasicDescriptor(o)); 601 for (auto &o: vouts) outinfo.push_back(fromBasicDescriptor(o));
571 jo["basicOutputInfo"] = outinfo; 602 jo["basicOutputInfo"] = outinfo;
572 603
604 json11::Json::object statinfo;
605 auto souts = d.staticOutputInfo;
606 for (auto &s: souts) jo[s.first] = fromStaticOutputDescriptor(s.second);
607
573 return json11::Json(jo); 608 return json11::Json(jo);
574 } 609 }
575 610
576 static PluginStaticData 611 static PluginStaticData
577 toPluginStaticData(json11::Json j, std::string &err) { 612 toPluginStaticData(json11::Json j, std::string &err) {
966 1001
967 jo["handle"] = double(pmapper.pluginToHandle(cr.plugin)); 1002 jo["handle"] = double(pmapper.pluginToHandle(cr.plugin));
968 1003
969 json11::Json::array outs; 1004 json11::Json::array outs;
970 for (auto &d: cr.outputs) { 1005 for (auto &d: cr.outputs) {
971 outs.push_back(fromOutputDescriptor(d)); 1006 auto id = d.identifier;
1007 StaticOutputDescriptor sd;
1008 if (cr.staticOutputInfo.find(id) != cr.staticOutputInfo.end()) {
1009 sd = cr.staticOutputInfo.at(id);
1010 }
1011 outs.push_back(fromOutputDescriptor(d, sd));
972 } 1012 }
973 jo["outputList"] = outs; 1013 jo["outputList"] = outs;
974 1014
975 json11::Json::object framing; 1015 json11::Json::object framing;
976 framing["stepSize"] = cr.framing.stepSize; 1016 framing["stepSize"] = cr.framing.stepSize;
999 } 1039 }
1000 1040
1001 cr.plugin = pmapper.handleToPlugin(j["handle"].int_value()); 1041 cr.plugin = pmapper.handleToPlugin(j["handle"].int_value());
1002 1042
1003 for (const auto &o: j["outputList"].array_items()) { 1043 for (const auto &o: j["outputList"].array_items()) {
1004 cr.outputs.push_back(toOutputDescriptor(o, err)); 1044 auto odpair = toOutputDescriptor(o, err);
1005 if (failed(err)) return {}; 1045 if (failed(err)) return {};
1046 cr.outputs.push_back(odpair.first);
1047 cr.staticOutputInfo[odpair.first.identifier] = odpair.second;
1006 } 1048 }
1007 1049
1008 cr.framing.stepSize = int(round(j["framing"]["stepSize"].number_value())); 1050 cr.framing.stepSize = int(round(j["framing"]["stepSize"].number_value()));
1009 cr.framing.blockSize = int(round(j["framing"]["blockSize"].number_value())); 1051 cr.framing.blockSize = int(round(j["framing"]["blockSize"].number_value()));
1010 1052