[gegl/meta-json: 9/18] meta-json: Can redirect properties



commit bf1bc22fbbaffd23fe20fdfb62b621c914fdba30
Author: Jon Nordby <jononor gmail com>
Date:   Sun Dec 28 20:01:31 2014 +0100

    meta-json: Can redirect properties

 operations/core/json.c           |   49 ++++++++++++++++++++++++++++++++++---
 operations/json/dropshadow2.fbp  |    2 +-
 operations/json/dropshadow2.json |    4 +++
 3 files changed, 50 insertions(+), 5 deletions(-)
---
diff --git a/operations/core/json.c b/operations/core/json.c
index 1dc0ca2..13e419c 100644
--- a/operations/core/json.c
+++ b/operations/core/json.c
@@ -168,8 +168,6 @@ attach (GeglOperation *operation)
 {
   JsonOp *self = (JsonOp *)operation;
   GeglNode  *gegl = operation->node;
-  GeglNode  *input = gegl_node_get_input_proxy (gegl, "input");
-  GeglNode  *output = gegl_node_get_output_proxy (gegl, "output");
 
   // Processes
   JsonObject *root = self->json_root;
@@ -223,8 +221,51 @@ attach (GeglOperation *operation)
       }
   }
 
-  // TODO: go over the exported ports and redirect them
-  // gegl_operation_meta_redirect (operation, "radius", blur, "std-dev-x");
+
+  // Exported ports
+  if (json_object_has_member(root, "inports")) {
+      JsonObject *inports = json_object_get_object_member(root, "inports");
+      GList *inport_names = json_object_get_members(inports);
+      for (int i=0; i<g_list_length(inport_names); i++) {
+          const gchar *name = g_list_nth_data(inport_names, i);
+          JsonObject *conn = json_object_get_object_member(inports, name);
+          const gchar *proc = json_object_get_string_member(conn, "process");
+          const gchar *port = json_object_get_string_member(conn, "port");
+          GeglNode *node = g_hash_table_lookup(self->nodes, proc);
+
+          g_print("redirecting input %s, to %s %s\n", name, port, proc);
+          g_assert(node);
+
+          if (g_strcmp0(name, "input") == 0) {
+              GeglNode *input = gegl_node_get_input_proxy (gegl, "input");
+              gegl_node_connect_to (input, "output", node, "input");
+          } else {
+            gegl_operation_meta_redirect (operation, name, node, port);
+          }
+      }
+  }
+
+  if (json_object_has_member(root, "outports")) {
+      JsonObject *outports = json_object_get_object_member(root, "outports");
+      GList *outport_names = json_object_get_members(outports);
+      for (int i=0; i<g_list_length(outport_names); i++) {
+          const gchar *name = g_list_nth_data(outport_names, i);
+          JsonObject *conn = json_object_get_object_member(outports, name);
+          const gchar *proc = json_object_get_string_member(conn, "process");
+          const gchar *port = json_object_get_string_member(conn, "port");
+          GeglNode *node = g_hash_table_lookup(self->nodes, proc);
+
+          g_print("redirecting output %s, to %s %s\n", name, port, proc);
+          g_assert(node);
+
+          if (g_strcmp0(name, "output") == 0) {
+            GeglNode *output = gegl_node_get_output_proxy (gegl, "output");
+            gegl_node_connect_to (node, "output", output, "input");
+          } else {
+            g_warning("Unsupported output '%s' exported in .json file", name);
+          }
+      }
+  }
 
 }
 
diff --git a/operations/json/dropshadow2.fbp b/operations/json/dropshadow2.fbp
index 0d8fb9e..5049184 100644
--- a/operations/json/dropshadow2.fbp
+++ b/operations/json/dropshadow2.fbp
@@ -1,5 +1,5 @@
 INPORT=translate.X:X
-INPORT=translate.Y:X
+INPORT=translate.Y:Y
 INPORT=color.VALUE:COLOR
 INPORT=blur.STD_DEV_X:RADIUS
 INPORT=opacity.VALUE:OPACITY
diff --git a/operations/json/dropshadow2.json b/operations/json/dropshadow2.json
index 9f4846a..b7ad9df 100644
--- a/operations/json/dropshadow2.json
+++ b/operations/json/dropshadow2.json
@@ -117,6 +117,10 @@
   "inports": {
     "x": {
       "process": "translate",
+      "port": "x"
+    },
+    "y": {
+      "process": "translate",
       "port": "y"
     },
     "color": {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]