comparison json/VampJson.h @ 39:183be3bc9d7b

Consts
author Chris Cannam <c.cannam@qmul.ac.uk>
date Mon, 22 Aug 2016 17:16:23 +0100
parents 54676b4e224e
children 10ac36b7198a
comparison
equal deleted inserted replaced
38:eb004c1b9579 39:183be3bc9d7b
708 return req; 708 return req;
709 } 709 }
710 710
711 static json11::Json 711 static json11::Json
712 fromLoadResponse(const Vamp::HostExt::LoadResponse &resp, 712 fromLoadResponse(const Vamp::HostExt::LoadResponse &resp,
713 PluginHandleMapper &mapper) { 713 const PluginHandleMapper &mapper) {
714 714
715 json11::Json::object jo; 715 json11::Json::object jo;
716 jo["pluginHandle"] = double(mapper.pluginToHandle(resp.plugin)); 716 jo["pluginHandle"] = double(mapper.pluginToHandle(resp.plugin));
717 jo["staticData"] = fromPluginStaticData(resp.staticData); 717 jo["staticData"] = fromPluginStaticData(resp.staticData);
718 jo["defaultConfiguration"] = 718 jo["defaultConfiguration"] =
720 return json11::Json(jo); 720 return json11::Json(jo);
721 } 721 }
722 722
723 static Vamp::HostExt::LoadResponse 723 static Vamp::HostExt::LoadResponse
724 toLoadResponse(json11::Json j, 724 toLoadResponse(json11::Json j,
725 PluginHandleMapper &mapper) { 725 const PluginHandleMapper &mapper) {
726 726
727 std::string err; 727 std::string err;
728 728
729 if (!j.has_shape({ 729 if (!j.has_shape({
730 { "pluginHandle", json11::Json::NUMBER }, 730 { "pluginHandle", json11::Json::NUMBER },
740 return resp; 740 return resp;
741 } 741 }
742 742
743 static json11::Json 743 static json11::Json
744 fromConfigurationRequest(const Vamp::HostExt::ConfigurationRequest &cr, 744 fromConfigurationRequest(const Vamp::HostExt::ConfigurationRequest &cr,
745 PluginHandleMapper &mapper) { 745 const PluginHandleMapper &mapper) {
746 746
747 json11::Json::object jo; 747 json11::Json::object jo;
748 748
749 jo["pluginHandle"] = mapper.pluginToHandle(cr.plugin); 749 jo["pluginHandle"] = mapper.pluginToHandle(cr.plugin);
750 jo["configuration"] = fromPluginConfiguration(cr.configuration); 750 jo["configuration"] = fromPluginConfiguration(cr.configuration);
752 return json11::Json(jo); 752 return json11::Json(jo);
753 } 753 }
754 754
755 static Vamp::HostExt::ConfigurationRequest 755 static Vamp::HostExt::ConfigurationRequest
756 toConfigurationRequest(json11::Json j, 756 toConfigurationRequest(json11::Json j,
757 PluginHandleMapper &mapper) { 757 const PluginHandleMapper &mapper) {
758 758
759 std::string err; 759 std::string err;
760 760
761 if (!j.has_shape({ 761 if (!j.has_shape({
762 { "pluginHandle", json11::Json::NUMBER }, 762 { "pluginHandle", json11::Json::NUMBER },
800 return cr; 800 return cr;
801 } 801 }
802 802
803 static json11::Json 803 static json11::Json
804 fromProcessRequest(const Vamp::HostExt::ProcessRequest &r, 804 fromProcessRequest(const Vamp::HostExt::ProcessRequest &r,
805 PluginHandleMapper &mapper) { 805 const PluginHandleMapper &mapper) {
806 806
807 json11::Json::object jo; 807 json11::Json::object jo;
808 jo["pluginHandle"] = mapper.pluginToHandle(r.plugin); 808 jo["pluginHandle"] = mapper.pluginToHandle(r.plugin);
809 809
810 json11::Json::object io; 810 json11::Json::object io;
822 jo["processInput"] = io; 822 jo["processInput"] = io;
823 return json11::Json(jo); 823 return json11::Json(jo);
824 } 824 }
825 825
826 static Vamp::HostExt::ProcessRequest 826 static Vamp::HostExt::ProcessRequest
827 toProcessRequest(json11::Json j, PluginHandleMapper &mapper) { 827 toProcessRequest(json11::Json j, const PluginHandleMapper &mapper) {
828 828
829 std::string err; 829 std::string err;
830 830
831 if (!j.has_shape({ 831 if (!j.has_shape({
832 { "pluginHandle", json11::Json::NUMBER }, 832 { "pluginHandle", json11::Json::NUMBER },
902 return json11::Json(jo); 902 return json11::Json(jo);
903 } 903 }
904 904
905 static json11::Json 905 static json11::Json
906 fromVampResponse_Load(const Vamp::HostExt::LoadResponse &resp, 906 fromVampResponse_Load(const Vamp::HostExt::LoadResponse &resp,
907 PluginHandleMapper &mapper) { 907 const PluginHandleMapper &mapper) {
908 908
909 json11::Json::object jo; 909 json11::Json::object jo;
910 jo["type"] = "load"; 910 jo["type"] = "load";
911 jo["success"] = (resp.plugin != 0); 911 jo["success"] = (resp.plugin != 0);
912 jo["errorText"] = ""; 912 jo["errorText"] = "";
914 return json11::Json(jo); 914 return json11::Json(jo);
915 } 915 }
916 916
917 static json11::Json 917 static json11::Json
918 fromVampRequest_Configure(const Vamp::HostExt::ConfigurationRequest &req, 918 fromVampRequest_Configure(const Vamp::HostExt::ConfigurationRequest &req,
919 PluginHandleMapper &mapper) { 919 const PluginHandleMapper &mapper) {
920 920
921 json11::Json::object jo; 921 json11::Json::object jo;
922 jo["type"] = "configure"; 922 jo["type"] = "configure";
923 jo["content"] = fromConfigurationRequest(req, mapper); 923 jo["content"] = fromConfigurationRequest(req, mapper);
924 return json11::Json(jo); 924 return json11::Json(jo);
935 return json11::Json(jo); 935 return json11::Json(jo);
936 } 936 }
937 937
938 static json11::Json 938 static json11::Json
939 fromVampRequest_Process(const Vamp::HostExt::ProcessRequest &req, 939 fromVampRequest_Process(const Vamp::HostExt::ProcessRequest &req,
940 PluginHandleMapper &mapper) { 940 const PluginHandleMapper &mapper) {
941 941
942 json11::Json::object jo; 942 json11::Json::object jo;
943 jo["type"] = "process"; 943 jo["type"] = "process";
944 jo["content"] = fromProcessRequest(req, mapper); 944 jo["content"] = fromProcessRequest(req, mapper);
945 return json11::Json(jo); 945 return json11::Json(jo);
956 return json11::Json(jo); 956 return json11::Json(jo);
957 } 957 }
958 958
959 static json11::Json 959 static json11::Json
960 fromVampRequest_Finish(Vamp::Plugin *p, 960 fromVampRequest_Finish(Vamp::Plugin *p,
961 PluginHandleMapper &mapper) { 961 const PluginHandleMapper &mapper) {
962 962
963 json11::Json::object jo; 963 json11::Json::object jo;
964 jo["type"] = "finish"; 964 jo["type"] = "finish";
965 json11::Json::object fo; 965 json11::Json::object fo;
966 fo["pluginHandle"] = mapper.pluginToHandle(p); 966 fo["pluginHandle"] = mapper.pluginToHandle(p);
1044 checkTypeField(j, "load"); 1044 checkTypeField(j, "load");
1045 return toLoadRequest(j["content"]); 1045 return toLoadRequest(j["content"]);
1046 } 1046 }
1047 1047
1048 static Vamp::HostExt::LoadResponse 1048 static Vamp::HostExt::LoadResponse
1049 toVampResponse_Load(json11::Json j, PluginHandleMapper &mapper) { 1049 toVampResponse_Load(json11::Json j, const PluginHandleMapper &mapper) {
1050 1050
1051 Vamp::HostExt::LoadResponse resp; 1051 Vamp::HostExt::LoadResponse resp;
1052 if (successful(j)) { 1052 if (successful(j)) {
1053 resp = toLoadResponse(j["content"], mapper); 1053 resp = toLoadResponse(j["content"], mapper);
1054 } 1054 }
1055 return resp; 1055 return resp;
1056 } 1056 }
1057 1057
1058 static Vamp::HostExt::ConfigurationRequest 1058 static Vamp::HostExt::ConfigurationRequest
1059 toVampRequest_Configure(json11::Json j, PluginHandleMapper &mapper) { 1059 toVampRequest_Configure(json11::Json j, const PluginHandleMapper &mapper) {
1060 1060
1061 checkTypeField(j, "configure"); 1061 checkTypeField(j, "configure");
1062 return toConfigurationRequest(j["content"], mapper); 1062 return toConfigurationRequest(j["content"], mapper);
1063 } 1063 }
1064 1064
1071 } 1071 }
1072 return resp; 1072 return resp;
1073 } 1073 }
1074 1074
1075 static Vamp::HostExt::ProcessRequest 1075 static Vamp::HostExt::ProcessRequest
1076 toVampRequest_Process(json11::Json j, PluginHandleMapper &mapper) { 1076 toVampRequest_Process(json11::Json j, const PluginHandleMapper &mapper) {
1077 1077
1078 checkTypeField(j, "process"); 1078 checkTypeField(j, "process");
1079 return toProcessRequest(j["content"], mapper); 1079 return toProcessRequest(j["content"], mapper);
1080 } 1080 }
1081 1081
1088 } 1088 }
1089 return resp; 1089 return resp;
1090 } 1090 }
1091 1091
1092 static Vamp::Plugin * 1092 static Vamp::Plugin *
1093 toVampRequest_Finish(json11::Json j, PluginHandleMapper &mapper) { 1093 toVampRequest_Finish(json11::Json j, const PluginHandleMapper &mapper) {
1094 1094
1095 checkTypeField(j, "finish"); 1095 checkTypeField(j, "finish");
1096 return mapper.handleToPlugin(j["content"]["pluginHandle"].int_value()); 1096 return mapper.handleToPlugin(j["content"]["pluginHandle"].int_value());
1097 } 1097 }
1098 1098