comparison vamp-json/VampJson.h @ 185:3eb00e5c76c4

Pull step & block size out into framing struct, return in config Update the C++ code to separate out the framing parameters (step and block size) from the configuration structure into their own structure, as in the latest schema, and to return the accepted framing params in the configuration response. This also implies that the plugin stub (which adapts Piper API back to Vamp) makes a note of the returned values, making them available via its own getPreferredStep/BlockSize so that the host can retry the initialise call in the case where it failed for having the wrong values first time.
author Chris Cannam <cannam@all-day-breakfast.com>
date Fri, 03 Feb 2017 16:23:21 +0000
parents 03b067abd91d
children d2a32436bf09
comparison
equal deleted inserted replaced
184:150cfa0c71e1 185:3eb00e5c76c4
692 if (c.currentProgram != "") { 692 if (c.currentProgram != "") {
693 jo["currentProgram"] = c.currentProgram; 693 jo["currentProgram"] = c.currentProgram;
694 } 694 }
695 695
696 jo["channelCount"] = c.channelCount; 696 jo["channelCount"] = c.channelCount;
697 jo["stepSize"] = c.stepSize; 697
698 jo["blockSize"] = c.blockSize; 698 json11::Json::object framing;
699 framing["stepSize"] = c.framing.stepSize;
700 framing["blockSize"] = c.framing.blockSize;
701 jo["framing"] = framing;
699 702
700 return json11::Json(jo); 703 return json11::Json(jo);
701 } 704 }
702 705
703 static PluginConfiguration 706 static PluginConfiguration
704 toPluginConfiguration(json11::Json j, std::string &err) { 707 toPluginConfiguration(json11::Json j, std::string &err) {
705 708
706 if (!j.has_shape({ 709 if (!j.has_shape({
707 { "channelCount", json11::Json::NUMBER }, 710 { "channelCount", json11::Json::NUMBER } }, err)) {
711 err = "malformed plugin configuration: " + err;
712 return {};
713 }
714
715 if (!j["framing"].has_shape({
708 { "stepSize", json11::Json::NUMBER }, 716 { "stepSize", json11::Json::NUMBER },
709 { "blockSize", json11::Json::NUMBER } }, err)) { 717 { "blockSize", json11::Json::NUMBER } }, err)) {
710 err = "malformed plugin configuration: " + err; 718 err = "malformed framing: " + err;
711 return {}; 719 return {};
712 } 720 }
713 721
714 if (!j["parameterValues"].is_null() && 722 if (!j["parameterValues"].is_null() &&
715 !j["parameterValues"].is_object()) { 723 !j["parameterValues"].is_object()) {
716 err = "object expected for parameter values"; 724 err = "object expected for parameter values";
717 return {}; 725 return {};
718 } 726 }
731 } 739 }
732 740
733 PluginConfiguration config; 741 PluginConfiguration config;
734 742
735 config.channelCount = int(round(j["channelCount"].number_value())); 743 config.channelCount = int(round(j["channelCount"].number_value()));
736 config.stepSize = int(round(j["stepSize"].number_value())); 744 config.framing.stepSize = int(round(j["framing"]["stepSize"].number_value()));
737 config.blockSize = int(round(j["blockSize"].number_value())); 745 config.framing.blockSize = int(round(j["framing"]["blockSize"].number_value()));
738 746
739 for (auto &pv : j["parameterValues"].object_items()) { 747 for (auto &pv : j["parameterValues"].object_items()) {
740 config.parameterValues[pv.first] = float(pv.second.number_value()); 748 config.parameterValues[pv.first] = float(pv.second.number_value());
741 } 749 }
742 750
961 json11::Json::array outs; 969 json11::Json::array outs;
962 for (auto &d: cr.outputs) { 970 for (auto &d: cr.outputs) {
963 outs.push_back(fromOutputDescriptor(d)); 971 outs.push_back(fromOutputDescriptor(d));
964 } 972 }
965 jo["outputList"] = outs; 973 jo["outputList"] = outs;
974
975 json11::Json::object framing;
976 framing["stepSize"] = cr.framing.stepSize;
977 framing["blockSize"] = cr.framing.blockSize;
978 jo["framing"] = framing;
966 979
967 return json11::Json(jo); 980 return json11::Json(jo);
968 } 981 }
969 982
970 static ConfigurationResponse 983 static ConfigurationResponse
971 toConfigurationResponse(json11::Json j, 984 toConfigurationResponse(json11::Json j,
972 const PluginHandleMapper &pmapper, std::string &err) { 985 const PluginHandleMapper &pmapper, std::string &err) {
973 986
974 ConfigurationResponse cr; 987 ConfigurationResponse cr;
975 988
976 cr.plugin = pmapper.handleToPlugin(j["handle"].int_value()); 989 if (!j["framing"].has_shape({
990 { "stepSize", json11::Json::NUMBER },
991 { "blockSize", json11::Json::NUMBER } }, err)) {
992 err = "malformed framing: " + err;
993 return {};
994 }
977 995
978 if (!j["outputList"].is_array()) { 996 if (!j["outputList"].is_array()) {
979 err = "array expected for output list"; 997 err = "array expected for output list";
980 return {}; 998 return {};
981 } 999 }
1000
1001 cr.plugin = pmapper.handleToPlugin(j["handle"].int_value());
982 1002
983 for (const auto &o: j["outputList"].array_items()) { 1003 for (const auto &o: j["outputList"].array_items()) {
984 cr.outputs.push_back(toOutputDescriptor(o, err)); 1004 cr.outputs.push_back(toOutputDescriptor(o, err));
985 if (failed(err)) return {}; 1005 if (failed(err)) return {};
986 } 1006 }
987 1007
1008 cr.framing.stepSize = int(round(j["framing"]["stepSize"].number_value()));
1009 cr.framing.blockSize = int(round(j["framing"]["blockSize"].number_value()));
1010
988 return cr; 1011 return cr;
989 } 1012 }
990 1013
991 static json11::Json 1014 static json11::Json
992 fromProcessRequest(const ProcessRequest &r, 1015 fromProcessRequest(const ProcessRequest &r,