diff 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
line wrap: on
line diff
--- a/json/VampJson.h	Tue May 17 11:15:25 2016 +0100
+++ b/json/VampJson.h	Tue May 17 13:52:51 2016 +0100
@@ -149,7 +149,7 @@
         }
         return json11::Json(jo);
     }
-
+    
     static Vamp::Plugin::OutputDescriptor
     toOutputDescriptor(json11::Json j) {
 
@@ -658,7 +658,7 @@
                     { "pluginKey", json11::Json::STRING },
                     { "inputSampleRate", json11::Json::NUMBER },
                     { "adapterFlags", json11::Json::ARRAY } }, err)) {
-            throw VampJson::Failure("malformed load request: " + err);
+            throw Failure("malformed load request: " + err);
         }
     
         Vamp::HostExt::LoadRequest req;
@@ -690,7 +690,7 @@
                     { "pluginHandle", json11::Json::NUMBER },
                     { "staticData", json11::Json::OBJECT },
                     { "defaultConfiguration", json11::Json::OBJECT } }, err)) {
-            throw VampJson::Failure("malformed load response: " + err);
+            throw Failure("malformed load response: " + err);
         }
 
         Vamp::HostExt::LoadResponse resp;
@@ -699,6 +699,35 @@
         resp.defaultConfiguration = toPluginConfiguration(j["defaultConfiguration"]);
         return resp;
     }
+
+    static json11::Json
+    fromConfigurationResponse(const Vamp::HostExt::ConfigurationResponse &cr) {
+
+        json11::Json::object jout;
+        
+        json11::Json::array outs;
+        for (auto &d: cr.outputs) {
+            outs.push_back(fromOutputDescriptor(d));
+        }
+        jout["outputList"] = outs;
+        
+        return json11::Json(jout);
+    }
+
+    static Vamp::HostExt::ConfigurationResponse toConfigurationResponse(json11::Json j) {
+
+        Vamp::HostExt::ConfigurationResponse cr;
+
+        if (!j["outputList"].is_array()) {
+            throw Failure("array expected for output list");
+        }
+
+        for (const auto &o: j["outputList"].array_items()) {
+            cr.outputs.push_back(toOutputDescriptor(o));
+        }
+
+        return cr;
+    }
 };
 
 }