aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--help/getdollarzero-abs0.pd16
-rw-r--r--help/getdollarzero-abs1.pd15
-rw-r--r--help/getdollarzero-help.pd27
-rw-r--r--src/getdollarzero.c69
4 files changed, 57 insertions, 70 deletions
diff --git a/help/getdollarzero-abs0.pd b/help/getdollarzero-abs0.pd
deleted file mode 100644
index 73b842e..0000000
--- a/help/getdollarzero-abs0.pd
+++ /dev/null
@@ -1,16 +0,0 @@
-#N canvas 186 97 466 316 10;
-#X obj 103 52 loadbang;
-#X obj 116 139 f \$0;
-#X obj 174 253 print;
-#X msg 122 178 abs0 dollarzero= \$1;
-#X obj 279 174 getdollarzero 1;
-#X obj 180 98 t b b;
-#X msg 275 204 parent dollarzero= \$1;
-#X obj 303 100 getdollarzero-abs1;
-#X connect 0 0 5 0;
-#X connect 1 0 3 0;
-#X connect 3 0 2 0;
-#X connect 4 0 6 0;
-#X connect 5 0 1 0;
-#X connect 5 1 4 0;
-#X connect 6 0 2 0;
diff --git a/help/getdollarzero-abs1.pd b/help/getdollarzero-abs1.pd
deleted file mode 100644
index ef5f5bd..0000000
--- a/help/getdollarzero-abs1.pd
+++ /dev/null
@@ -1,15 +0,0 @@
-#N canvas 0 0 470 320 10;
-#X obj 103 52 loadbang;
-#X obj 116 139 f \$0;
-#X obj 174 253 print;
-#X obj 180 98 t b b;
-#X msg 122 178 abs1 dollarzero= \$1;
-#X obj 280 174 getdollarzero 5;
-#X msg 275 204 abs1's parent's parent dollarzero= \$1;
-#X connect 0 0 3 0;
-#X connect 1 0 4 0;
-#X connect 3 0 1 0;
-#X connect 3 1 5 0;
-#X connect 4 0 2 0;
-#X connect 5 0 6 0;
-#X connect 6 0 2 0;
diff --git a/help/getdollarzero-help.pd b/help/getdollarzero-help.pd
index 1f9f127..04aebab 100644
--- a/help/getdollarzero-help.pd
+++ b/help/getdollarzero-help.pd
@@ -1,13 +1,20 @@
-#N canvas 372 409 472 395 10;
-#X msg 42 73 bang;
-#X obj 41 149 print;
-#X obj 42 111 getdollarzero;
-#X symbolatom 87 148 10 0 0 0 - - -;
-#X obj 209 112 getdollarzero-abs0;
-#X text 17 22 Get the dollar zero of a patch.;
-#X text 28 199 Argument: How much recursion you want (If set to 1 \,
-it will get the parent's dollar zero \, if set to 2 \, it will get
-the parent's parent's dollar zero \, etc);
+#N canvas 275 172 587 373 10;
+#X msg 42 193 bang;
+#X obj 41 269 print;
+#X obj 42 231 getdollarzero;
+#X symbolatom 87 268 10 0 0 0 - - -;
+#X obj -1 29 cnv 15 400 100 empty empty empty 20 12 0 14 -249661 -66577
+0;
+#X text 4 73 author: mrtoftrash@gmail.com;
+#X text 3 50 tags: initialization patch;
+#X text 4 94 version: 2009-09-23 (release 2: added "root" keyword)
+;
+#X text 204 162 ARGUMENT:;
+#X text 4 28 description: gets the \$0 of a patch.;
+#X text 203 181 float: How much recursion you want (If set to 1 \,
+it will get the parent patch's \$0. If set to 2 \, it will get the
+parent's parent's \$0 \, etc);
+#X text 200 234 root: Get the \$0 of the root patch;
#X connect 0 0 2 0;
#X connect 2 0 1 0;
#X connect 2 0 3 0;
diff --git a/src/getdollarzero.c b/src/getdollarzero.c
index 8a19486..8a7da38 100644
--- a/src/getdollarzero.c
+++ b/src/getdollarzero.c
@@ -1,30 +1,19 @@
-/* (C) 2005 Guenter Geiger */
+// Original object by (C) 2005 Guenter Geiger
+// New version by Thomas Ouellet Fredericks
+
#include "m_pd.h"
#include "g_canvas.h"
-
-/* HACK
-
-struct _glist
-{
- t_object gl_obj; // header in case we're a glist
- t_gobj *gl_list; // the actual data
- struct _gstub *gl_stub; // safe pointer handler
- int gl_valid; // incremented when pointers might be stale
- struct _glist *gl_owner; // parent glist, supercanvas, or 0 if none
-};
-
-END HACK
-
-*/
+#define IS_A_SYMBOL(atom,index) ((atom+index)->a_type == A_SYMBOL)
+#define IS_A_FLOAT(atom,index) ((atom+index)->a_type == A_FLOAT)
typedef struct getdollarzero
{
t_object x_ob;
t_canvas * x_canvas;
t_outlet* x_outlet;
- int x_level;
+ //int x_level;
} t_getdollarzero;
@@ -32,33 +21,55 @@ typedef struct getdollarzero
static void getdollarzero_bang(t_getdollarzero *x)
{
- int i = x->x_level;
- t_canvas* last = x->x_canvas;
-
- while (i>0) {
- i--;
- if (last->gl_owner) last = last->gl_owner;
- }
+
// x->s_parent_unique = canvas_realizedollar((t_canvas *)this_canvas->gl_owner, gensym("$0"));
//outlet_symbol(x->x_outlet,canvas_getdir(last));
- outlet_symbol(x->x_outlet,canvas_realizedollar(last, gensym("$0")));
+ outlet_symbol(x->x_outlet,canvas_realizedollar(x->x_canvas, gensym("$0")));
}
t_class *getdollarzero_class;
-static void *getdollarzero_new(t_floatarg level)
+static void *getdollarzero_new(t_symbol *s, int argc, t_atom *argv)
{
t_getdollarzero *x = (t_getdollarzero *)pd_new(getdollarzero_class);
- x->x_canvas = canvas_getcurrent();
+
+
+ t_canvas* last = canvas_getcurrent();
+
+ if ( argc > 0 && IS_A_FLOAT(argv,0) ) {
+ int i = atom_getfloat(argv);
+
+ while (i>0) {
+ i--;
+ if (last->gl_owner) {
+ last = last->gl_owner;
+ } else {
+ break;
+ }
+ }
+
+ } else if ( argc > 0 && IS_A_SYMBOL(argv,0) && atom_getsymbol(argv) == gensym("root") ) {
+
+ while ( last->gl_owner) {
+
+ last = last->gl_owner;
+ }
+ }
+
+ x->x_canvas = last;
+
+
+
x->x_outlet = outlet_new(&x->x_ob, &s_);
- x->x_level = level;
+
+
return (void *)x;
}
void getdollarzero_setup(void)
{
getdollarzero_class = class_new(gensym("getdollarzero"), (t_newmethod)getdollarzero_new, 0,
- sizeof(t_getdollarzero), 0, A_DEFFLOAT,0);
+ sizeof(t_getdollarzero), 0, A_GIMME,0);
class_addbang(getdollarzero_class, getdollarzero_bang);
}