Traversing patcher heirarchy from within poly~ possible?

May 22, 2007 at 9:12pm

Traversing patcher heirarchy from within poly~ possible?

I want to get a reference to the closest instance of my external, traversing upward, from inside a poly~. The code I’ve been using to do so from subpatchers/abstractions doesn’t work:

In object_new():
p = (t_patcher *)((t_symbol *)gensym(“#P”))->s_thing; // get patcher

Then later, after patcherargs fires:
if((b = (t_box *)p->p_vnewobj) != NULL) // get patcher’s box
pp = b->b_patcher; // get box’s patcher

So either an instance of an abstraction in poly~ doesn’t have a patcher, or the patcher’s box doesn’t correspond to the poly~’s box.

How do I go about getting the poly~’s box/patcher? Is this possible?

A js object within that poly~ can successfully traverse the patcher heirarchy upward via this.patcher.parentpatcher, so I assume so, but I’d rather avoid attaching a js to my external’s outlet to do this (a js created behind the scenes with newinstance() doesn’t appear to have a patcher).

#32033
May 23, 2007 at 11:30am

John -

This code is guaranteed to break with Max 5, but works with Max 4.6:

t_patcher *p = my_current_patcher;
t_patcher *parentpatcher = NULL; // the parent
t_object *target; // the poly~ object containing the patcher
method m;

if (p->p_assoc || p->p_parent) {
target = (p->p_assoc) ? p->p_assoc : p->p_parent;
if (m = zgetfn(target, gensym(“parentpatcher”))) {
(*m)(target, &parentpatcher);
}
}

jb

Am 22.05.2007 um 23:12 schrieb John Pitcairn:

>
> I want to get a reference to the closest instance of my external,
> traversing upward, from inside a poly~. The code I’ve been using to
> do so from subpatchers/abstractions doesn’t work:
>
> In object_new():
> p = (t_patcher *)((t_symbol *)gensym(“#P”))->s_thing; // get patcher
>
> Then later, after patcherargs fires:
> if((b = (t_box *)p->p_vnewobj) != NULL) // get patcher’s box
> pp = b->b_patcher; // get box’s patcher
>
> So either an instance of an abstraction in poly~ doesn’t have a
> patcher, or the patcher’s box doesn’t correspond to the poly~’s box.
>
> How do I go about getting the poly~’s box/patcher? Is this possible?
>
> A js object within that poly~ can successfully traverse the patcher
> heirarchy upward via this.patcher.parentpatcher, so I assume so,
> but I’d rather avoid attaching a js to my external’s outlet to do
> this (a js created behind the scenes with newinstance() doesn’t
> appear to have a patcher).
>

#104756
May 23, 2007 at 8:28pm

Great, thanks. It’ll all live in one function, so I can hopefully add a simple test for Max 5 when it arrives and use whatever method is appropriate then.

#104757

You must be logged in to reply to this topic.