comparison json/VampJson.h @ 64:85ec33975434

Support split OutputDescriptor, and plugins rather than pluginData in listResponse from SDK
author Chris Cannam <c.cannam@qmul.ac.uk>
date Fri, 23 Sep 2016 14:20:29 +0100
parents 77833938f0f8
children 2d866edd79d5
comparison
equal deleted inserted replaced
63:72c43bc69616 64:85ec33975434
188 throw Failure("invalid sample type string: " + text); 188 throw Failure("invalid sample type string: " + text);
189 } 189 }
190 } 190 }
191 191
192 static json11::Json 192 static json11::Json
193 fromOutputDescriptor(const Vamp::Plugin::OutputDescriptor &desc) { 193 fromConfiguredOutputDescriptor(const Vamp::Plugin::OutputDescriptor &desc) {
194 json11::Json::object jo { 194 json11::Json::object jo {
195 { "basic", fromBasicDescriptor(desc) },
196 { "unit", desc.unit }, 195 { "unit", desc.unit },
197 { "sampleType", fromSampleType(desc.sampleType) }, 196 { "sampleType", fromSampleType(desc.sampleType) },
198 { "sampleRate", desc.sampleRate }, 197 { "sampleRate", desc.sampleRate },
199 { "hasDuration", desc.hasDuration } 198 { "hasDuration", desc.hasDuration }
200 }; 199 };
210 jo["quantizeStep"] = desc.quantizeStep; 209 jo["quantizeStep"] = desc.quantizeStep;
211 } 210 }
212 return json11::Json(jo); 211 return json11::Json(jo);
213 } 212 }
214 213
214 static json11::Json
215 fromOutputDescriptor(const Vamp::Plugin::OutputDescriptor &desc) {
216 json11::Json::object jo {
217 { "basic", fromBasicDescriptor(desc) },
218 { "configured", fromConfiguredOutputDescriptor(desc) }
219 };
220 return json11::Json(jo);
221 }
222
215 static Vamp::Plugin::OutputDescriptor 223 static Vamp::Plugin::OutputDescriptor
216 toOutputDescriptor(json11::Json j) { 224 toConfiguredOutputDescriptor(json11::Json j) {
217 225
218 Vamp::Plugin::OutputDescriptor od; 226 Vamp::Plugin::OutputDescriptor od;
219 if (!j.is_object()) { 227 if (!j.is_object()) {
220 throw Failure("object expected for output descriptor"); 228 throw Failure("object expected for output descriptor");
221 } 229 }
222 230
223 toBasicDescriptor(j["basic"], od);
224
225 od.unit = j["unit"].string_value(); 231 od.unit = j["unit"].string_value();
226 232
227 od.sampleType = toSampleType(j["sampleType"].string_value()); 233 od.sampleType = toSampleType(j["sampleType"].string_value());
228 234
229 if (!j["sampleRate"].is_number()) { 235 if (!j["sampleRate"].is_number()) {
252 od.isQuantized = true; 258 od.isQuantized = true;
253 od.quantizeStep = j["quantizeStep"].number_value(); 259 od.quantizeStep = j["quantizeStep"].number_value();
254 } else { 260 } else {
255 od.isQuantized = false; 261 od.isQuantized = false;
256 } 262 }
263
264 return od;
265 }
266
267 static Vamp::Plugin::OutputDescriptor
268 toOutputDescriptor(json11::Json j) {
269
270 Vamp::Plugin::OutputDescriptor od;
271 if (!j.is_object()) {
272 throw Failure("object expected for output descriptor");
273 }
274
275 od = toConfiguredOutputDescriptor(j);
276
277 toBasicDescriptor(j["basic"], od);
257 278
258 return od; 279 return od;
259 } 280 }
260 281
261 static json11::Json 282 static json11::Json
931 json11::Json::object jo; 952 json11::Json::object jo;
932 jo["type"] = "list"; 953 jo["type"] = "list";
933 jo["success"] = true; 954 jo["success"] = true;
934 955
935 json11::Json::array arr; 956 json11::Json::array arr;
936 for (const auto &a: resp.pluginData) { 957 for (const auto &a: resp.plugins) {
937 arr.push_back(fromPluginStaticData(a)); 958 arr.push_back(fromPluginStaticData(a));
938 } 959 }
939 json11::Json::object po; 960 json11::Json::object po;
940 po["plugins"] = arr; 961 po["plugins"] = arr;
941 962
1121 toVampResponse_List(json11::Json j) { 1142 toVampResponse_List(json11::Json j) {
1122 1143
1123 Vamp::HostExt::ListResponse resp; 1144 Vamp::HostExt::ListResponse resp;
1124 if (successful(j)) { 1145 if (successful(j)) {
1125 for (const auto &a: j["content"]["plugins"].array_items()) { 1146 for (const auto &a: j["content"]["plugins"].array_items()) {
1126 resp.pluginData.push_back(toPluginStaticData(a)); 1147 resp.plugins.push_back(toPluginStaticData(a));
1127 } 1148 }
1128 } 1149 }
1129 return resp; 1150 return resp;
1130 } 1151 }
1131 1152