aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIOhannes m zmölnig <zmoelnig@users.sourceforge.net>2009-03-26 10:14:17 +0000
committerIOhannes m zmölnig <zmoelnig@users.sourceforge.net>2009-03-26 10:14:17 +0000
commitdf3d37ef7a6ee16dd3ef3da609ba91f5617db9fe (patch)
tree44543e0480313cd1e100753c2a67ca641f72cdc7 /src
parent5853f9ae585dfe47974358e1d6b9a394284000bf (diff)
first implementation of querying objects on the canvas by their name OR their index;
LATER: add separate search for class (now it's combined with name-search) LATER: find a more flexible and easy to parse output scheme svn path=/trunk/externals/iem/iemguts/; revision=10903
Diffstat (limited to 'src')
-rw-r--r--src/canvasindex.c67
1 files changed, 66 insertions, 1 deletions
diff --git a/src/canvasindex.c b/src/canvasindex.c
index 2ebd6d8..6633c1b 100644
--- a/src/canvasindex.c
+++ b/src/canvasindex.c
@@ -28,6 +28,7 @@
*/
#include "m_pd.h"
+#include "m_imp.h"
#include "g_canvas.h"
int glist_getindex(t_glist *x, t_gobj *y);
@@ -40,10 +41,72 @@ typedef struct _canvasindex
{
t_object x_obj;
t_canvas *x_canvas;
-
t_outlet*xoutlet, *youtlet;
} t_canvasindex;
+typedef struct _intlist
+{
+ int value;
+ struct _intlist*next;
+} t_intlist;
+
+static void canvasindex_symbol(t_canvasindex *x, t_symbol*s)
+{
+ /* check whether an object of name <s> is in the canvas */
+ t_canvas*c=x->x_canvas;
+ t_gobj*y;
+ int index=0;
+
+ if(!c || !c->gl_owner) return;
+ c =c->gl_owner;
+
+ for (y = (t_gobj*)c->gl_list; y; y = y->g_next) /* traverse all objects in canvas */
+ {
+ t_object*obj=(t_object*)y;
+ t_class*obj_c=y->g_pd;
+ t_symbol*cname=obj_c->c_name;
+ t_binbuf*b=obj->te_binbuf;
+ t_atom*ap=binbuf_getvec(b);
+ int ac=binbuf_getnatom(b);
+ if(s!=cname && ac) {
+ cname=atom_getsymbol(ap);
+ }
+ if(s==cname){
+#warning LATER think about output format
+ outlet_float(x->xoutlet, (t_float)index);
+ }
+ index++;
+ }
+}
+
+
+static void canvasindex_float(t_canvasindex *x, t_floatarg f)
+{
+ /* get the objectname of object #<f> */
+ int index=f, cur=0;
+ t_canvas*c=x->x_canvas;
+ t_gobj*y;
+
+ if(index < 0 || !c || !c->gl_owner) return;
+ c =c->gl_owner;
+
+ for (y = (t_gobj*)c->gl_list; y && cur<index; y = y->g_next) /* traverse all objects in canvas */
+ {
+ cur++;
+ }
+ if(y) {
+ t_object*obj=(t_object*)y;
+ t_binbuf*b=obj->te_binbuf;
+ t_atom*ap=binbuf_getvec(b);
+ int ac=binbuf_getnatom(b);
+ t_atom classatom[1];
+ SETSYMBOL(classatom, y->g_pd->c_name);
+ /* LATER: shan't we output the index of the object as well? */
+ outlet_anything(x->youtlet, gensym("class"), 1, classatom);
+ outlet_anything(x->xoutlet, gensym("binbuf"), ac, ap);
+ }
+}
+
static void canvasindex_bang(t_canvasindex *x)
{
t_canvas*c=x->x_canvas;
@@ -92,4 +155,6 @@ void canvasindex_setup(void)
sizeof(t_canvasindex), 0,
A_DEFFLOAT, 0);
class_addbang(canvasindex_class, (t_method)canvasindex_bang);
+ class_addsymbol(canvasindex_class, (t_method)canvasindex_symbol);
+ class_addfloat(canvasindex_class, (t_method)canvasindex_float);
}