Access to attributes of another object from the C API
Is there a way, in the C API, given a t_object or a t_class, to list the attributes of the object and their metadata (range, etc) ?
Thanks!
Hi there,
yes, there is:void object_list_attributes_and_their_metadata(t_object *obj)
{
void *attr;
long attrcount = 0;
t_symbol **attrnames = NULL;
void *attr2;
long attrcount2 = 0;
t_symbol **attrnames2 = NULL;
long argc = 0;
t_atom *argv = NULL;
t_max_err err;
long i, j, k;
err = object_attr_getnames(obj, &attrcount, &attrnames);
if (!err && attrcount && attrnames) {
for (i = 0; i < attrcount; i++) {
post("-");
post("attrname: %s", attrnames[i]->s_name);
attr = object_attr_get(obj, attrnames[i]);
err = object_attr_getnames(attr, &attrcount2, &attrnames2); // attr metadata
if (!err && attrcount2 && attrnames2) {
for (j = 0; j < attrcount2; j++) {
post("metadata: %s", attrnames2[j]->s_name);
err = object_attr_getvalueof(attr, attrnames2[j], &argc, &argv); // metadata values
if (!err && argc && argv) {
for (k = 0; k < argc; k++) {
postatom(argv+k);
}
}
if (argv) {
sysmem_freeptr(argv);
}
}
}
if (attrnames2) {
sysmem_freeptr(attrnames2);
}
}
}
if (attrnames) {
sysmem_freeptr(attrnames);
}
}
I coded this function from the top of my head without testing it.
Please use it with care, however you get the idea...
Cheers
- Luigi
ah, thanks, it's object_attr_getnames that I could not find in the SDK API.