From 9dad6f40caaa3de6b7d6366b21c024714f20631e Mon Sep 17 00:00:00 2001
From: Guillem <guillembartrina@gmail.com>
Date: Fri, 4 Sep 2020 14:25:18 +0200
Subject: [PATCH] add clone iterator, this will allow us to interact with the
 instances of the clone

---
 pd/src/g_canvas.h |  2 ++
 pd/src/g_clone.c  | 10 ++++++++++
 2 files changed, 12 insertions(+)

diff --git a/pd/src/g_canvas.h b/pd/src/g_canvas.h
index 964d8fab8..5c340e103 100644
--- a/pd/src/g_canvas.h
+++ b/pd/src/g_canvas.h
@@ -237,6 +237,8 @@ struct _glist
 #define gl_gobj gl_obj.te_g
 #define gl_pd gl_gobj.g_pd
 
+typedef void (*t_canvas_iterator)(t_canvas *x, void *data);
+
 /*-------------------universal preset stuff---------------------*/
 // for the universal preset_node ability (see g_editor.c doconnect/disconnect functions)
 // this is where all the classes capable of being controlled via preset should be defined
diff --git a/pd/src/g_clone.c b/pd/src/g_clone.c
index 2529161e6..c06f8dba7 100644
--- a/pd/src/g_clone.c
+++ b/pd/src/g_clone.c
@@ -65,6 +65,16 @@ typedef struct _clone
     int x_suppressvoice; /* suppress voice number as $1 arg */
 } t_clone;
 
+/* the given 'it' function is executed over each of the underlying canvases
+    (they are passed as first parameter). 'data' is passed as second argument */
+void clone_iterate(t_pd *z, t_canvas_iterator it, void* data)
+{
+    t_clone *x = (t_clone *)z;
+    int i;
+    for(i = 0; i < x->x_n; i++)
+        it(x->x_vec[i].c_gl, data);
+}
+
 int clone_match(t_pd *z, t_symbol *name, t_symbol *dir)
 {
     t_clone *x = (t_clone *)z;
-- 
GitLab