comparison vamp-json/VampJson.h @ 289:26027c3a99a0

Further wiring for ProgramParameters - should now be supported throughout
author Chris Cannam <cannam@all-day-breakfast.com>
date Wed, 08 Apr 2020 15:02:24 +0100
parents 292ec9b50280
children
comparison
equal deleted inserted replaced
288:c9f63ca1914d 289:26027c3a99a0
872 872
873 return Vamp::HostExt::PluginLoader::AdapterFlags(flags); 873 return Vamp::HostExt::PluginLoader::AdapterFlags(flags);
874 } 874 }
875 875
876 static json11::Json 876 static json11::Json
877 fromProgramParameters(const PluginProgramParameters &programParameters) {
878
879 json11::Json::object jo;
880 for (const auto &pp: programParameters.programParameters) {
881 auto program = pp.first;
882 json11::Json::object po;
883 for (const auto &pv: pp.second) {
884 po[pv.first] = pv.second;
885 }
886 jo[program] = po;
887 }
888
889 return json11::Json(jo);
890 }
891
892 static PluginProgramParameters
893 toProgramParameters(json11::Json j, std::string &err) {
894
895 if (!j.is_object()) {
896 err = "object expected for program parameters";
897 return {};
898 }
899
900 PluginProgramParameters params;
901
902 auto pp = j.object_items();
903 for (auto program: pp) {
904 std::string name = program.first;
905 if (!program.second.is_object()) {
906 err = std::string("object expected for program parameter map ") +
907 "(in program \"" + name + "\")";
908 return {};
909 }
910 for (auto p: program.second.object_items()) {
911 if (!p.second.is_number()) {
912 err = std::string("number expected for program parameter value ") +
913 "(in program \"" + name + "\")";
914 return {};
915 }
916 params.programParameters[name][p.first] = p.second.number_value();
917 }
918 }
919
920 return params;
921 }
922
923 static json11::Json
877 fromListRequest(const ListRequest &req) { 924 fromListRequest(const ListRequest &req) {
878 json11::Json::object jo; 925 json11::Json::object jo;
879 json11::Json::array arr; 926 json11::Json::array arr;
880 for (const auto &f: req.from) { 927 for (const auto &f: req.from) {
881 arr.push_back(f); 928 arr.push_back(f);
964 json11::Json::object jo; 1011 json11::Json::object jo;
965 jo["handle"] = double(pmapper.pluginToHandle(resp.plugin)); 1012 jo["handle"] = double(pmapper.pluginToHandle(resp.plugin));
966 jo["staticData"] = fromPluginStaticData(resp.staticData); 1013 jo["staticData"] = fromPluginStaticData(resp.staticData);
967 jo["defaultConfiguration"] = 1014 jo["defaultConfiguration"] =
968 fromPluginConfiguration(resp.defaultConfiguration); 1015 fromPluginConfiguration(resp.defaultConfiguration);
1016 jo["programParameters"] =
1017 fromProgramParameters(resp.programParameters);
969 return json11::Json(jo); 1018 return json11::Json(jo);
970 } 1019 }
971 1020
972 static LoadResponse 1021 static LoadResponse
973 toLoadResponse(json11::Json j, 1022 toLoadResponse(json11::Json j,
984 LoadResponse resp; 1033 LoadResponse resp;
985 auto h = j["handle"].int_value(); 1034 auto h = j["handle"].int_value();
986 resp.plugin = pmapper.handleToPlugin(h); 1035 resp.plugin = pmapper.handleToPlugin(h);
987 resp.staticData = toPluginStaticData(j["staticData"], err); 1036 resp.staticData = toPluginStaticData(j["staticData"], err);
988 if (failed(err)) return {}; 1037 if (failed(err)) return {};
989 resp.defaultConfiguration = toPluginConfiguration(j["defaultConfiguration"], 1038 resp.defaultConfiguration =
990 err); 1039 toPluginConfiguration(j["defaultConfiguration"], err);
991 if (failed(err)) return {}; 1040 if (failed(err)) return {};
1041 if (j.object_items().find("programParameters") !=
1042 j.object_items().end()) {
1043 resp.programParameters =
1044 toProgramParameters(j["programParameters"], err);
1045 if (failed(err)) return {};
1046 }
992 return resp; 1047 return resp;
993 } 1048 }
994 1049
995 static json11::Json 1050 static json11::Json
996 fromConfigurationRequest(const ConfigurationRequest &cr, 1051 fromConfigurationRequest(const ConfigurationRequest &cr,