Max 5: Am I in a poly~, get the instance number?

Jan 10, 2009 at 9:09am

Max 5: Am I in a poly~, get the instance number?

Given a patcher, I need to determine if that patcher is an instance in a poly~, and if so, get the instance number.

From the docs, I thought I’d do something like this, but I’m not getting anything returned for object_attr_getobj(patcher, gensym(“parentclass”)):

if(t_object *obj = object_attr_getobj(patcher, gensym(“parentclass”))) {
// but obj is always null
if(object_classname(obj) == gensym(“poly~”)) {
// and if I get this far, how do I get the instance number?
}
}

#41622
Jan 23, 2009 at 10:46am

Dear Cycling ’74,

We are currently working on a Max 5 version of the oo objects, we received several requests from the community for this.

As for the specific idea of finding the instance number that belongs to a patcher loaded in a poly~, I’d say that could typically be done with a special utility method like the others that are defined in jpatcher_api.h. Does this method already exist? If not, are you planning to add such a method in the future?

Until then, would it be possible to directly access struct members of jpatcher or jbox to do this?

Thanks,
Mattijs

#148312
Jan 30, 2009 at 11:33pm

Bump again – any chance of someone throwing us a bone on this one, then we can get the oo objects out for testing? The objects do need to work in a poly~

The patcher-delete query/notification in my other question is less crucial, we cleanup at quit anyway so we’ll just hold onto more memory than strictly necessary as the session continues and oo-patchers are deleted.

#148313
Jan 31, 2009 at 4:53pm

I think I got it, this code seems to do the job:

t_object *jp;
t_max_err err;
t_object *target;
method m;
long index = -1;

err = object_obex_lookup(x, gensym(“#P”), (t_object **)&jp);
if (err != MAX_ERR_NONE) return;

object_method(jp, gensym(“getassoc”), &target);
if (target) {
post(“found %s”, object_classname(target)->s_name);

long voices = object_attr_getlong(target, gensym(“voices”));
post(“total amount of voices: %ld”, voices);

if(m = zgetfn(target, gensym(“getindex”))) index = (long)(*m)(target, jp);
post(“index: %ld”, index);
}

Cycling, let us know if there is something very scary about this.. ;)

Best,
Mattijs

#148314

You must be logged in to reply to this topic.