Max API  8.2.0
Poly

If your object is instatiated as a voice of a poly~ object, it is possible both to determine this context and to determine information about the specific voice.

+ Collaboration diagram for Poly:

If your object is instatiated as a voice of a poly~ object, it is possible both to determine this context and to determine information about the specific voice.

This is done by querying the patcher in which your object exists for an associated object, and then calling methods on that object.

t_object *patcher = NULL;
t_object *assoc = NULL;
method m = NULL;
long voices = -1;
long index = -1;
err = object_obex_lookup(x, gensym("#P"), &patcher);
if (err == MAX_ERR_NONE) {
object_method(patcher, gensym("getassoc"), &assoc);
if (assoc) {
post("found %s", object_classname(assoc)->s_name);
voices = object_attr_getlong(assoc, gensym("voices"));
post("total amount of voices: %ld", voices);
if(m = zgetfn(assoc, gensym("getindex")))
index = (long)(*m)(assoc, patcher);
post("index: %ld", index);
}
}
t_atom_long object_attr_getlong(void *x, t_symbol *s)
Retrieves the value of an attribute, given its parent object and name.
method zgetfn(t_object *op, t_symbol *msg)
Use zgetfn() to send an untyped message to a Max object without error checking.
BEGIN_USING_C_LINKAGE void post(C74_CONST char *fmt,...)
Print text to the Max window.
BEGIN_USING_C_LINKAGE typedef void *(* method)(void *)
Function pointer type for generic methods.
Definition: ext_mess.h:25
t_atom_long t_max_err
an integer value suitable to be returned as an error code
Definition: max_types.h:78
@ MAX_ERR_NONE
No error.
Definition: max_types.h:118
t_max_err object_obex_lookup(void *x, t_symbol *key, t_object **val)
Retrieves the value of a data stored in the obex.
t_symbol * object_classname(void *x)
Retrieves an object instance's class name.
void * object_method(void *x, t_symbol *s,...)
Sends an untyped message to an object.
t_symbol * gensym(C74_CONST char *s)
Given a C-string, fetch the matching t_symbol pointer from the symbol table, generating the symbol if...
The structure for the head of any object which wants to have inlets or outlets, or support attributes...
Definition: ext_mess.h:191