void otimetag_anything(t_otimetag *x, t_symbol *selector, short argc, t_atom *argv) { t_osc_msg_u *msg = NULL; t_osc_err e = omax_util_maxAtomsToOSCMsg_u(&msg, selector, argc, argv); if(e){ object_error((t_object *)x, "%s", osc_error_string(e)); return; } t_osc_bndl_u *bndl = osc_bundle_u_alloc(); osc_bundle_u_addMsg(bndl, msg); t_osc_bndl_s *bs = osc_bundle_u_serialize(bndl); if(bs){ otimetag_doFullPacket(x, osc_bundle_s_getLen(bs), osc_bundle_s_getPtr(bs)); osc_bundle_s_deepFree(bs); } osc_bundle_u_free(bndl); /* t_osc_msg_u *msg = NULL; t_symbol *address_sym = NULL; long osc_argc = argc; t_atom *osc_argv = argv; if(selector){ if(selector->s_name[0] == '/'){ address_sym = selector; } } if(!address_sym){ if(argc != 0){ if(atom_gettype(argv) != A_SYM){ object_error((t_object *)x, "first argument must be an OSC address"); return; } address_sym = atom_getsym(argv); if(address_sym->s_name[0] != '/'){ object_error((t_object *)x, "first argument must be an OSC address"); return; } osc_argc = argc - 1; osc_argv = argv + 1; }else{ object_error((t_object *)x, "first argument must be an OSC address"); return; } } omax_util_maxAtomsToOSCMsg_u(&msg, address_sym, osc_argc, osc_argv); t_osc_bndl_u *bndl = osc_bundle_u_alloc(); osc_bundle_u_addMsg(bndl, msg); long len = 0; char *buf = NULL; osc_bundle_u_serialize(bndl, &len, &buf); otimetag_doFullPacket(x, len, buf); if(buf){ osc_mem_free(buf); } osc_bundle_u_free(bndl); */ }
void olistenumerate_anything(t_olistenumerate *x, t_symbol *selector, short argc, t_atom *argv) { t_osc_msg_u *msg = NULL; t_osc_err e = omax_util_maxAtomsToOSCMsg_u(&msg, selector, argc, argv); if(e){ object_error((t_object *)x, "%s", osc_error_string(e)); return; } t_osc_bndl_u *bndl = osc_bundle_u_alloc(); osc_bundle_u_addMsg(bndl, msg); t_osc_bndl_s *bs = osc_bundle_u_serialize(bndl); if(bs){ olistenumerate_doFullPacket(x, osc_bundle_s_getLen(bs), osc_bundle_s_getPtr(bs)); osc_bundle_s_deepFree(bs); } osc_bundle_u_free(bndl); }
void omax_FullPacket(t_object *ob, long len, long ptr) { t_symbol *classname = object_classname(ob); if(!classname){ // if we can't get our classname, there's no way we can match anything return; } char buf[len]; sprintf(buf, "/%s", classname->s_name); t_context c; c.ob = ob; c.classname = classname; c.osc_classname = gensym(buf); memset(buf, '\0', len); c.buf = buf; osc_bundle_s_setBundleID(buf); c.bufpos = OSC_HEADER_SIZE; c.should_output_state = 0; t_osc_err e = osc_bundle_s_getMessagesWithCallback(len, (char *)ptr, omax_FullPacketCallback, (void *)(&c)); if(e){ object_error(ob, "%s (%d)", osc_error_string(e), e); return; } if(c.bufpos > OSC_HEADER_SIZE){ void *cout = omax_object_getContinuationOutlet(ob); if(cout){ t_atom out[2]; atom_setlong(out, c.bufpos); atom_setlong(out + 1, (long)(c.buf)); outlet_anything(cout, gensym("FullPacket"), 2, out); } } if(c.should_output_state > 0){ omax_outputState(ob); } }
void ocoll_anything(t_ocoll *x, t_symbol *msg, int argc, t_atom *argv) { t_osc_bndl_u *bndl_u = osc_bundle_u_alloc(); t_osc_msg_u *msg_u = NULL; t_osc_err e = omax_util_maxAtomsToOSCMsg_u(&msg_u, msg, argc, argv); if(e){ object_error((t_object *)x, "%s", osc_error_string(e)); if(bndl_u){ osc_bundle_u_free(bndl_u); } return; } osc_bundle_u_addMsg(bndl_u, msg_u); t_osc_bndl_s *bs = osc_bundle_u_serialize(bndl_u); if(bndl_u){ osc_bundle_u_free(bndl_u); } ocoll_fullPacket_impl(x, osc_bundle_s_getLen(bs), osc_bundle_s_getPtr(bs)); if(bs){ osc_bundle_s_deepFree(bs); } }
//takes a string, oscizes and then turns it back into a string char * validate_osc_string(char * bundle_string){ t_osc_bndl_u *bndl = NULL; t_osc_parser_subst *subs = NULL; long nsubs = 0; //printf("bundle: %s\n", bundle_string); t_osc_err err = osc_parser_parseString(strlen(bundle_string)+2, bundle_string, &bndl, &nsubs, &subs); if (err != 0){ printf("%s\n", osc_error_string(err)); } //^multiple bundles need to be /n delimited. //not using this for now while(subs){ //subs is linked list of $n substitutions that need to take place t_osc_parser_subst *next = subs->next; osc_mem_free(subs); subs = next; } char *sbndl = NULL; long sbndl_len = 0; osc_bundle_u_serialize(bndl, &sbndl_len, &sbndl); //serialize the bundle char *buf = NULL; long buflen = 0; osc_bundle_s_format(sbndl_len, sbndl, &buflen, &buf); return buf; }
t_osc_bndl_u *ocontext_processCanvas(t_canvas *canvas) { t_osc_bndl_u *canvas_bndl = osc_bundle_u_alloc(); if(canvas == NULL){ // return empty bundle---this is intentional return canvas_bndl; } t_osc_msg_u *msg = NULL; msg = osc_message_u_allocWithAddress("/name"); osc_message_u_appendString(msg, canvas->gl_name->s_name); osc_bundle_u_addMsg(canvas_bndl, msg); t_canvasenvironment *c_env = canvas_getenv(canvas); msg = osc_message_u_allocWithAddress("/path"); osc_message_u_appendString(msg, c_env->ce_dir->s_name); osc_bundle_u_addMsg(canvas_bndl, msg); msg = osc_message_u_allocWithAddress("/$0"); osc_message_u_appendInt32(msg, c_env->ce_dollarzero); osc_bundle_u_addMsg(canvas_bndl, msg); msg = osc_message_u_allocWithAddress("/isabstraction"); osc_message_u_appendBool(msg, !canvas_isabstraction(canvas)); osc_bundle_u_addMsg(canvas_bndl, msg); msg = osc_message_u_allocWithAddress("/editmode"); osc_message_u_appendBool(msg, canvas->gl_edit); osc_bundle_u_addMsg(canvas_bndl, msg); msg = osc_message_u_allocWithAddress("/font"); osc_message_u_appendString(msg, sys_font); osc_bundle_u_addMsg(canvas_bndl, msg); msg = osc_message_u_allocWithAddress("/fontsize"); osc_message_u_appendInt32(msg, canvas->gl_font); osc_bundle_u_addMsg(canvas_bndl, msg); msg = osc_message_u_allocWithAddress("/dirty"); osc_message_u_appendBool(msg, canvas->gl_dirty); osc_bundle_u_addMsg(canvas_bndl, msg); if(!canvas_isabstraction(canvas)) { msg = osc_message_u_allocWithAddress("/abstraction/position/x1"); osc_message_u_appendInt32(msg, canvas->gl_obj.te_xpix); osc_bundle_u_addMsg(canvas_bndl, msg); msg = osc_message_u_allocWithAddress("/abstraction/position/y1"); osc_message_u_appendInt32(msg, canvas->gl_obj.te_ypix); osc_bundle_u_addMsg(canvas_bndl, msg); } msg = osc_message_u_allocWithAddress("/pixwidth"); osc_message_u_appendInt32(msg, canvas->gl_pixwidth); osc_bundle_u_addMsg(canvas_bndl, msg); msg = osc_message_u_allocWithAddress("/pixheight"); osc_message_u_appendInt32(msg, canvas->gl_pixheight); osc_bundle_u_addMsg(canvas_bndl, msg); msg = osc_message_u_allocWithAddress("/screen/x1"); osc_message_u_appendInt32(msg, canvas->gl_screenx1); osc_bundle_u_addMsg(canvas_bndl, msg); msg = osc_message_u_allocWithAddress("/screen/y1"); osc_message_u_appendInt32(msg, canvas->gl_screeny1); osc_bundle_u_addMsg(canvas_bndl, msg); msg = osc_message_u_allocWithAddress("/screen/x2"); osc_message_u_appendInt32(msg, canvas->gl_screenx2); osc_bundle_u_addMsg(canvas_bndl, msg); msg = osc_message_u_allocWithAddress("/screen/y2"); osc_message_u_appendInt32(msg, canvas->gl_screeny2); osc_bundle_u_addMsg(canvas_bndl, msg); msg = osc_message_u_allocWithAddress("/xmargin"); osc_message_u_appendInt32(msg, canvas->gl_xmargin); osc_bundle_u_addMsg(canvas_bndl, msg); msg = osc_message_u_allocWithAddress("/ymargin"); osc_message_u_appendInt32(msg, canvas->gl_ymargin); osc_bundle_u_addMsg(canvas_bndl, msg); if(canvas->gl_goprect && canvas->gl_owner) { int x1,y1,x2,y2; gobj_getrect(&canvas->gl_obj.te_g, canvas->gl_owner, &x1, &y1, &x2, &y2); msg = osc_message_u_allocWithAddress("/graphrect"); osc_message_u_appendInt32(msg, x1); osc_message_u_appendInt32(msg, y1); osc_message_u_appendInt32(msg, x2); osc_message_u_appendInt32(msg, y2); osc_bundle_u_addMsg(canvas_bndl, msg); } t_binbuf *b = NULL; b = canvas->gl_obj.te_binbuf; if(b) { int argc = binbuf_getnatom(b); t_atom *argv = binbuf_getvec(b); if(argc) { t_osc_msg_u *msg_u = NULL; int abstr = !canvas_isabstraction(canvas); t_osc_err e = omax_util_maxAtomsToOSCMsg_u(&msg_u, gensym("/arguments"), argc-1-abstr, argv+1+abstr); if(e) { if(e){ object_error((t_object *)x, "%s", osc_error_string(e)); goto exit; } } osc_bundle_u_addMsg(canvas_bndl, msg_u); } else { msg = osc_message_u_allocWithAddress("/arguments"); osc_message_u_appendString(msg, ""); osc_bundle_u_addMsg(canvas_bndl, msg); } } else { msg = osc_message_u_allocWithAddress("/arguments"); osc_message_u_appendString(msg, ""); osc_bundle_u_addMsg(canvas_bndl, msg); } exit: if(canvas->gl_owner) { t_osc_bndl_u *parent_bndl = ocontext_processCanvas(canvas->gl_owner); t_osc_msg_u *pmsg = osc_message_u_allocWithAddress("/parent"); osc_message_u_appendBndl_u(pmsg, parent_bndl); osc_bundle_u_addMsg(canvas_bndl, pmsg); } return canvas_bndl; }
void omax_outputState(t_object *x) { t_symbol *classname = object_classname(x); if(!classname){ return; } t_hashtab *ht = omax_class_getHashtab(classname->s_name); if(!ht){ return; } long nkeys = 0; t_symbol **keys = NULL; hashtab_getkeys(ht, &nkeys, &keys); t_osc_bndl_u *bndl_u = osc_bundle_u_alloc(); int i; for(i = 0; i < nkeys; i++){ if(osc_error_validateAddress(keys[i]->s_name)){ continue; } t_omax_method *m = NULL; hashtab_lookup(ht, keys[i], (t_object **)(&m)); if(!m){ continue; } if(m->type == OMAX_PARAMETER){ t_object *attr = object_attr_get(x, m->sym); long argc = 0; t_atom *argv = NULL; //m->m.m_fun(ob, attr, &argc, &argv); char getter[128]; sprintf(getter, "get%s", m->sym->s_name); long get; method f = object_attr_method(x, gensym(getter), (void **)(&attr), &get); if(f){ f(x, attr, &argc, &argv); if(argv){ char address[128]; sprintf(address, "/%s", m->sym->s_name); t_symbol *addresssym = gensym(address); t_osc_msg_u *msg_u = NULL; t_osc_err e = omax_util_maxAtomsToOSCMsg_u(&msg_u, addresssym, argc, argv); if(e){ object_error((t_object *)x, "%s", osc_error_string(e)); if(bndl_u){ osc_bundle_u_free(bndl_u); } return; } osc_bundle_u_addMsg(bndl_u, msg_u); if(argv){ sysmem_freeptr(argv); } } } } } //long len = 0; //char *buf = NULL; t_osc_bndl_s *bs = osc_bundle_u_serialize(bndl_u); void *outlet = omax_object_getInfoOutlet(x); if(outlet && bs){ omax_util_outletOSC(outlet, osc_bundle_s_getLen(bs), osc_bundle_s_getPtr(bs)); osc_bundle_s_deepFree(bs); } if(bndl_u){ osc_bundle_u_free(bndl_u); } }
void omax_object_createIOReport(t_object *x, t_symbol *msg, int argc, t_atom *argv, long *buflen, char **buf) { t_symbol *classname = object_classname(x); if(!classname){ return; } t_hashtab *ht = omax_class_getHashtab(classname->s_name); if(!ht){ return; } long nkeys = 0; t_symbol **keys = NULL; hashtab_getkeys(ht, &nkeys, &keys); t_osc_bndl_u *bndl_u = osc_bundle_u_alloc(); int i; for(i = 0; i < nkeys; i++){ if(!osc_error_validateAddress(keys[i]->s_name)){ int j; for(j = 0; j < argc; j++){ t_atom *a = argv + j; if(atom_gettype(a) == A_SYM){ int ret = 0; int ao, po; if(atom_getsym(a) == gensym("/*")){ ret = OSC_MATCH_ADDRESS_COMPLETE; }else{ ret = osc_match(atom_getsym(a)->s_name, keys[i]->s_name, &po, &ao); } if(ret && OSC_MATCH_ADDRESS_COMPLETE){ t_omax_method *m = NULL; hashtab_lookup(ht, keys[i], (t_object **)(&m)); if(!m){ continue; } if(m->type == OMAX_PARAMETER){ t_object *attr = object_attr_get(x, m->sym); long argc = 0; t_atom *argv = NULL; //m->m.m_fun(ob, attr, &argc, &argv); char getter[128]; sprintf(getter, "get%s", m->sym->s_name); long get; method f = object_attr_method(x, gensym(getter), (void **)(&attr), &get); if(f){ f(x, attr, &argc, &argv); if(argv){ char address[128]; sprintf(address, "/%s", m->sym->s_name); t_atom a[argc + 1]; atom_setsym(a, gensym(address)); memcpy(a + 1, argv, argc * sizeof(t_atom)); t_osc_msg_u *msg_u = NULL; t_osc_err e = omax_util_maxAtomsToOSCMsg_u(&msg_u, ps_oscioreport, argc + 1, a); if(e){ object_error((t_object *)x, "%s", osc_error_string(e)); if(bndl_u){ osc_bundle_u_free(bndl_u); } return; } osc_bundle_u_addMsg(bndl_u, msg_u); sysmem_freeptr(argv); } } } } } } } } //*buflen = pos; t_osc_bndl_s *bs = osc_bundle_u_serialize(bndl_u); if(bs){ *buflen = osc_bundle_s_getLen(bs); *buf = osc_bundle_s_getPtr(bs); osc_bundle_s_free(bs); } if(bndl_u){ osc_bundle_u_free(bndl_u); } }