void cmmjl_osc_makeDefaultAddress(void *x, long instance, char *buf){ char buf2[256], tmp[64]; t_patcher *p, *pp; t_box *b; t_symbol *name; char *ptr; int index; object_obex_lookup(x, gensym("#P"), (t_object **)&p); if(!p){ return; } name = jpatcher_get_name(p); if(name){ if(strcmp(name->s_name, "")){ // if this is a filename, get rid of the extension if(ptr = strrchr(name->s_name, '.')){ memset(tmp, '\0', 64); index = name->s_name - ptr; if(index < 0) index = -index; memcpy(tmp, name->s_name, index); sprintf(buf2, "/%s", tmp); }else{ sprintf(buf2, "/%s", name->s_name); } } }else{ // maybe we didn't wait long enough... } b = jpatcher_get_box(p); if(b){ while(p){ pp = jpatcher_get_parentpatcher(p); if(pp){ name = jpatcher_get_name(pp); if(name){ if(strcmp(name->s_name, "")){ if(ptr = strrchr(name->s_name, '.')){ memset(tmp, '\0', 64); index = name->s_name - ptr; if(index < 0) index = -index; memcpy(tmp, name->s_name, index); sprintf(buf, "/%s%s", tmp, buf2); }else{ sprintf(buf, "/%s%s", name->s_name, buf2); } } } } p = pp; strcpy(buf2, buf); } } }
t_osc_bndl_u *ocontext_processPatcher(t_object *patcher) { t_osc_bndl_u *patcher_bndl = osc_bundle_u_alloc(); if(patcher == NULL){ // return empty bundle---this is intentional return patcher_bndl; } long nattrs = 0; t_symbol **attrs = NULL; object_attr_getnames(patcher, &nattrs, &attrs); for(int i = 0; i < nattrs; i++){ t_atom *av = NULL; long ac = 0; object_attr_getvalueof(patcher, attrs[i], &ac, &av); if(av && ac){ long addresslen = strlen(attrs[i]->s_name) + 2; char address[addresslen]; snprintf(address, addresslen, "/%s", attrs[i]->s_name); t_osc_msg_u *msg = NULL; if(ac == 1 && atom_gettype(av) == A_OBJ){ //printf("%s has object: %p %p\n", address, patcher, atom_getobj(av)); continue; t_osc_bndl_u *b = ocontext_processPatcher(atom_getobj(av)); if(b){ msg = osc_message_u_allocWithAddress(address); osc_message_u_appendBndl_u(msg, b); osc_bundle_u_addMsg(patcher_bndl, msg); } }else{ omax_util_maxAtomsToOSCMsg_u(&msg, gensym(address), ac, av); if(msg){ osc_bundle_u_addMsg(patcher_bndl, msg); } } } } sysmem_freeptr(attrs); t_symbol *maxclass = object_attr_getsym(patcher, gensym("maxclass")); if(maxclass && maxclass == gensym("jpatcher")){ patcher = jpatcher_get_parentpatcher(patcher); t_osc_bndl_u *parent_bndl = ocontext_processPatcher(patcher); t_osc_msg_u *msg = osc_message_u_allocWithAddress("/parent"); osc_message_u_appendBndl_u(msg, parent_bndl); osc_bundle_u_addMsg(patcher_bndl, msg); } return patcher_bndl; }