comparison json/VampJson.h @ 12:828930f9a65d

Configuration request/response structs
author Chris Cannam <c.cannam@qmul.ac.uk>
date Tue, 17 May 2016 13:52:51 +0100
parents c8451896c40e
children 1d13354ddc44
comparison
equal deleted inserted replaced
11:aa61cb5c5754 12:828930f9a65d
147 if (desc.isQuantized) { 147 if (desc.isQuantized) {
148 jo["quantizeStep"] = desc.quantizeStep; 148 jo["quantizeStep"] = desc.quantizeStep;
149 } 149 }
150 return json11::Json(jo); 150 return json11::Json(jo);
151 } 151 }
152 152
153 static Vamp::Plugin::OutputDescriptor 153 static Vamp::Plugin::OutputDescriptor
154 toOutputDescriptor(json11::Json j) { 154 toOutputDescriptor(json11::Json j) {
155 155
156 Vamp::Plugin::OutputDescriptor od; 156 Vamp::Plugin::OutputDescriptor od;
157 if (!j.is_object()) { 157 if (!j.is_object()) {
656 656
657 if (!j.has_shape({ 657 if (!j.has_shape({
658 { "pluginKey", json11::Json::STRING }, 658 { "pluginKey", json11::Json::STRING },
659 { "inputSampleRate", json11::Json::NUMBER }, 659 { "inputSampleRate", json11::Json::NUMBER },
660 { "adapterFlags", json11::Json::ARRAY } }, err)) { 660 { "adapterFlags", json11::Json::ARRAY } }, err)) {
661 throw VampJson::Failure("malformed load request: " + err); 661 throw Failure("malformed load request: " + err);
662 } 662 }
663 663
664 Vamp::HostExt::LoadRequest req; 664 Vamp::HostExt::LoadRequest req;
665 req.pluginKey = j["pluginKey"].string_value(); 665 req.pluginKey = j["pluginKey"].string_value();
666 req.inputSampleRate = j["inputSampleRate"].number_value(); 666 req.inputSampleRate = j["inputSampleRate"].number_value();
688 688
689 if (!j.has_shape({ 689 if (!j.has_shape({
690 { "pluginHandle", json11::Json::NUMBER }, 690 { "pluginHandle", json11::Json::NUMBER },
691 { "staticData", json11::Json::OBJECT }, 691 { "staticData", json11::Json::OBJECT },
692 { "defaultConfiguration", json11::Json::OBJECT } }, err)) { 692 { "defaultConfiguration", json11::Json::OBJECT } }, err)) {
693 throw VampJson::Failure("malformed load response: " + err); 693 throw Failure("malformed load response: " + err);
694 } 694 }
695 695
696 Vamp::HostExt::LoadResponse resp; 696 Vamp::HostExt::LoadResponse resp;
697 resp.plugin = mapper.handleToPlugin(j["pluginHandle"].int_value()); 697 resp.plugin = mapper.handleToPlugin(j["pluginHandle"].int_value());
698 resp.staticData = toPluginStaticData(j["staticData"]); 698 resp.staticData = toPluginStaticData(j["staticData"]);
699 resp.defaultConfiguration = toPluginConfiguration(j["defaultConfiguration"]); 699 resp.defaultConfiguration = toPluginConfiguration(j["defaultConfiguration"]);
700 return resp; 700 return resp;
701 } 701 }
702
703 static json11::Json
704 fromConfigurationResponse(const Vamp::HostExt::ConfigurationResponse &cr) {
705
706 json11::Json::object jout;
707
708 json11::Json::array outs;
709 for (auto &d: cr.outputs) {
710 outs.push_back(fromOutputDescriptor(d));
711 }
712 jout["outputList"] = outs;
713
714 return json11::Json(jout);
715 }
716
717 static Vamp::HostExt::ConfigurationResponse toConfigurationResponse(json11::Json j) {
718
719 Vamp::HostExt::ConfigurationResponse cr;
720
721 if (!j["outputList"].is_array()) {
722 throw Failure("array expected for output list");
723 }
724
725 for (const auto &o: j["outputList"].array_items()) {
726 cr.outputs.push_back(toOutputDescriptor(o));
727 }
728
729 return cr;
730 }
702 }; 731 };
703 732
704 } 733 }
705 734
706 #endif 735 #endif