Mercurial > hg > piper-cpp
comparison json/VampJson.h @ 10:c8451896c40e
Some conversions for plugin handles
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Tue, 17 May 2016 09:58:15 +0100 |
parents | d8358afe3f2c |
children | 828930f9a65d |
comparison
equal
deleted
inserted
replaced
9:197440dc8296 | 10:c8451896c40e |
---|---|
11 #include <json11/json11.hpp> | 11 #include <json11/json11.hpp> |
12 #include <base-n/include/basen.hpp> | 12 #include <base-n/include/basen.hpp> |
13 | 13 |
14 #include <vamp-hostsdk/Plugin.h> | 14 #include <vamp-hostsdk/Plugin.h> |
15 #include <vamp-hostsdk/PluginLoader.h> | 15 #include <vamp-hostsdk/PluginLoader.h> |
16 | |
17 #include "bits/PluginHandleMapper.h" | |
18 | |
19 namespace vampipe { | |
16 | 20 |
17 /** | 21 /** |
18 * Convert the structures laid out in the Vamp SDK classes into JSON | 22 * Convert the structures laid out in the Vamp SDK classes into JSON |
19 * (and back again) following the schema in the vamp-json-schema | 23 * (and back again) following the schema in the vamp-json-schema |
20 * project repo. | 24 * project repo. |
661 req.pluginKey = j["pluginKey"].string_value(); | 665 req.pluginKey = j["pluginKey"].string_value(); |
662 req.inputSampleRate = j["inputSampleRate"].number_value(); | 666 req.inputSampleRate = j["inputSampleRate"].number_value(); |
663 req.adapterFlags = toAdapterFlags(j["adapterFlags"]); | 667 req.adapterFlags = toAdapterFlags(j["adapterFlags"]); |
664 return req; | 668 return req; |
665 } | 669 } |
670 | |
671 static json11::Json | |
672 fromLoadResponse(Vamp::HostExt::LoadResponse resp, | |
673 PluginHandleMapper &mapper) { | |
674 | |
675 json11::Json::object jo; | |
676 jo["pluginHandle"] = double(mapper.pluginToHandle(resp.plugin)); | |
677 jo["staticData"] = fromPluginStaticData(resp.staticData); | |
678 jo["defaultConfiguration"] = | |
679 fromPluginConfiguration(resp.defaultConfiguration); | |
680 return json11::Json(jo); | |
681 } | |
682 | |
683 static Vamp::HostExt::LoadResponse | |
684 toLoadResponse(json11::Json j, | |
685 PluginHandleMapper &mapper) { | |
686 | |
687 std::string err; | |
688 | |
689 if (!j.has_shape({ | |
690 { "pluginHandle", json11::Json::NUMBER }, | |
691 { "staticData", json11::Json::OBJECT }, | |
692 { "defaultConfiguration", json11::Json::OBJECT } }, err)) { | |
693 throw VampJson::Failure("malformed load response: " + err); | |
694 } | |
695 | |
696 Vamp::HostExt::LoadResponse resp; | |
697 resp.plugin = mapper.handleToPlugin(j["pluginHandle"].int_value()); | |
698 resp.staticData = toPluginStaticData(j["staticData"]); | |
699 resp.defaultConfiguration = toPluginConfiguration(j["defaultConfiguration"]); | |
700 return resp; | |
701 } | |
666 }; | 702 }; |
667 | 703 |
704 } | |
668 | 705 |
669 #endif | 706 #endif |