void space_preset(t_space *x) { void* z; if(!(z = gensym("_preset")->s_thing)) return; for(int i = 0; i < x->f_number_of_microphones; i++) binbuf_vinsert(z, gensym("osslf")->s_name, x, object_classname(x), gensym("coeffs"), i, (float)x->f_microphonesValues[i]); }
long howbigisyourp_callback(t_howbigisyourp *x, t_object *obj) { long numberofinstances = 1; t_symbol *name = object_classname(obj); // if it's a newobj, get the "real" name (e.g. borax) if (name == gensym("newobj")) name = object_classname(jbox_get_object(obj)); if (name) { t_object *obj; // if the object was already in the hashtable, increment the number of instances if (hashtab_lookup(x->hash, name, &obj) == MAX_ERR_NONE) numberofinstances = (long)obj + 1; // write the number of instances in the hashtable hashtab_store(x->hash, name, (t_object *)numberofinstances); } return 0; }
int validConditionColor(t_object *obj) { t_object *jb, *o; t_symbol *obclass = object_classname(obj); if(obclass == gensym("hoa.encoder~") || obclass == gensym("hoa.rotate~") || obclass == gensym("hoa.recomposer~") || obclass == gensym("sfplay~") || obclass == gensym("hoa.optim~") || obclass == gensym("hoa.convolve~") || obclass == gensym("hoa.wider~") || obclass == gensym("hoa.map~") || obclass == gensym("hoa.freeverb~") || obclass == gensym("hoa.gigaverb~") ) return 1; else if(obclass == gensym("hoa.projector~") || obclass == gensym("hoa.space~")) return 2; else if (obclass == gensym("jpatcher")) { jb = jpatcher_get_firstobject(obj); while(jb) { o = jbox_get_object(jb); if(object_classname(o) == gensym("hoa.plug_script")) { return 1; } jb = jbox_get_nextobject(jb); } } return 0; }
method omax_object_getNotificationCallback(t_object *ob) { t_symbol *classname = object_classname(ob); if(!classname){ return NULL; } t_hashtab *ht = omax_class_getHashtab(classname->s_name); if(!ht){ return NULL; } method f = NULL; hashtab_lookup(ht, gensym("cnmat_internal_osc_notification_function"), (t_object **)(&f)); return f; }
t_symbol *jamoma_patcher_getcontext(t_object *patcher) { t_object *box = object_attr_getobj(patcher, jps_box); t_symbol *objclass = NULL; if(box) objclass = object_classname(box); if(objclass == gensym("bpatcher")) return objclass; else if(objclass == gensym("newobj")) return gensym("subpatcher"); else return gensym("toplevel"); }
void iterator_bang(t_iterator *x) { t_object *jp; t_object *jb; t_object *mybox; t_object *o; t_rect jr; t_symbol *scriptingname; t_max_err err; // get the object's parent patcher err = object_obex_lookup(x, gensym("#P"), (t_object **)&jp); if (err != MAX_ERR_NONE) return; // get the object's wrapping box err = object_obex_lookup(x, gensym("#B"), (t_object **)&mybox); if (err != MAX_ERR_NONE) return; jb = jpatcher_get_firstobject(jp); // get the first BOX in the object list while(jb) { jbox_get_patching_rect(jb, &jr); // x, y, width, height (double) object_post((t_object *)x, "found an object at %ld %ld, w %ld, h %ld", (long)jr.x, (long)jr.y, (long)jr.width, (long)jr.height); scriptingname = jbox_get_varname(jb); // scripting name if (scriptingname && scriptingname != gensym("")) object_post((t_object *)x, " it is named %s...", scriptingname->s_name); o = jbox_get_object(jb); // get the box's object (b_firstin in Max4) post(" it's a(n) %s object...", object_classname(o)->s_name); if (jpatcher_is_patcher(o)) { post(" which is some kind of a patcher. we could recurse here..."); } if (jb == mybox) post(" ...and it's me!"); jb = jbox_get_nextobject(jb); // iterate } // jbox_get_patcher(abox); // get a box's patcher // maybe upwards? jpatcher_get_parentpatcher(<#t_object * p#>) }
t_omax *omax_object_getOmaxObj(t_object *ob) { t_symbol *classname = object_classname(ob); if(!classname){ return NULL; } t_hashtab *ht = NULL; ht = omax_class_getHashtab(classname->s_name); if(!ht){ return NULL; } size_t offset; hashtab_lookup(ht, gensym("cnmat_internal_osc_ob_offset"), (t_object **)(&offset)); t_omax *osc = (t_omax *)(((char *)ob) + offset); return osc; }
void send_configuration(t_hoa_decoder *x) { t_object *patcher; t_object *decoder; t_object *object; t_object *line; t_max_err err; if(!x->f_send_config) return; err = object_obex_lookup(x, gensym("#P"), (t_object **)&patcher); if (err != MAX_ERR_NONE) return; err = object_obex_lookup(x, gensym("#B"), (t_object **)&decoder); if (err != MAX_ERR_NONE) return; t_atom nchannels; t_atom offset; t_atom *argv = new t_atom[x->f_decoder->getNumberOfChannels()]; atom_setlong(&nchannels, x->f_decoder->getNumberOfChannels()); atom_setfloat(&offset, x->f_decoder->getChannelsOffset() / HOA_2PI * 360.); for(int i = 0; i < x->f_decoder->getNumberOfChannels(); i++) atom_setfloat(argv+i, x->f_decoder->getChannelAzimuth(i) / HOA_2PI * 360.); for (line = jpatcher_get_firstline(patcher); line; line = jpatchline_get_nextline(line)) { if (jpatchline_get_box1(line) == decoder) { object = jpatchline_get_box2(line); t_symbol* classname = object_classname(jbox_get_object(object)); if(classname == gensym("hoa.2d.meter~") || classname == gensym("hoa.meter~") || classname == gensym("hoa.2d.vector~")) { object_method_typed(jbox_get_object(object), gensym("channels"), 1, &nchannels, NULL); object_method_typed(jbox_get_object(object), gensym("angles"), x->f_decoder->getNumberOfChannels(), argv, NULL); object_method_typed(jbox_get_object(object), gensym("offset"), 1, &offset, NULL); } else if(classname == gensym("hoa.gain~")) object_method_typed(jbox_get_object(object), gensym("channels"), 1, &nchannels, NULL); } } free(argv); }
int validName(t_object *box) { int i; t_object *jb, *o, *obj; char objName[] = "nop."; obj = jbox_get_object(box); if(object_classname(obj) == gensym("jpatcher")) { if(strlen(jpatcher_get_name(obj)->s_name) >= 4) { for(i = 0; i < 4; i++) { objName[i] = jpatcher_get_name(obj)->s_name[i]; } } else { jb = jpatcher_get_firstobject(obj); while(jb) { o = jbox_get_object(jb); if(object_classname(o) == gensym("hoa.plug_script")) { strcpy(objName, "hoa."); } jb = jbox_get_nextobject(jb); } } } else if (object_classname(obj) == gensym("dac~") || object_classname(obj) == gensym("sfrecord~") || object_classname(obj) == gensym("sfplay~")) { strcpy(objName, "hoa."); } else if (strlen(object_classname(obj)->s_name) >= 4) { for(i = 0; i < 4; i++) { objName[i] = object_classname(obj)->s_name[i]; } } if(strcmp(objName, "hoa.") == 0) return 1; else return 0; }
short is_obj_hoa_exotic(t_object *obj) { int i; t_object *jb, *o; char objName[] = "nop."; if(object_classname(obj) == hoa_sym_jpatcher) { if(strlen(jpatcher_get_name(obj)->s_name) >= 4) { for(i = 0; i < 4; i++) { objName[i] = jpatcher_get_name(obj)->s_name[i]; } } else { jb = jpatcher_get_firstobject(obj); while(jb) { o = jbox_get_object(jb); if(object_classname(o) == gensym("hoa.plug_script")) { strcpy(objName, "hoa."); } jb = jbox_get_nextobject(jb); } } } else if (object_classname(obj) == gensym("dac~") || object_classname(obj) == gensym("sfrecord~") || object_classname(obj) == gensym("sfplay~")) { strcpy(objName, "hoa."); } else if (strlen(object_classname(obj)->s_name) >= 4) { for(i = 0; i < 4; i++) { objName[i] = object_classname(obj)->s_name[i]; } } if(strcmp(objName, "hoa.") == 0) return 1; return 0; }
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 HoaDecode_send_angles(t_HoaDecode *x) { t_object *patcher; t_object *decoder; t_object *object; t_object *line; t_max_err err; err = object_obex_lookup(x, gensym("#P"), (t_object **)&patcher); if (err != MAX_ERR_NONE) return; err = object_obex_lookup(x, gensym("#B"), (t_object **)&decoder); if (err != MAX_ERR_NONE) return; for (line = jpatcher_get_firstline(patcher); line; line = jpatchline_get_nextline(line)) { if (jpatchline_get_box1(line) == decoder) { object = jpatchline_get_box2(line); t_symbol* classname = object_classname(jbox_get_object(object)); if(classname == gensym("hoa.meter~") || classname == gensym("hoa.gain~") || classname == gensym("hoa.vector~")) { long argc = x->f_AmbisonicsDecoder->getNumberOfOutputs(); t_atom *argv = new t_atom[argc]; for(int i = 0; i < argc; i++) atom_setfloat(argv+i, x->f_AmbisonicsDecoder->getLoudspeakerAngle(i)); object_method_typed(jbox_get_object(object), gensym("angles"), argc, argv, NULL); free(argv); } } } }
void color_patchline(t_connect *x) { t_object *line, *startobj; t_object *jb, *o; t_hoa_err err; t_jrgba* linecolor = NULL; int inletnum, sign; short startobj_type; t_hoa_boxinfos* startobj_infos = (t_hoa_boxinfos*) malloc( sizeof(t_hoa_boxinfos)); line = jpatcher_get_firstline(x->f_patcher); while (line) { startobj = jbox_get_object(jpatchline_get_box1(line)); if(object_is_hoa(startobj) || is_obj_hoa_exotic(startobj)) { startobj_type = object_is_hoa(startobj); hoa_boxinfos_init(startobj_infos); err = (t_hoa_err) object_method(startobj, hoa_sym_hoa_getinfos, startobj_infos, NULL); if (err == HOA_ERR_NONE) { // ambisonics colors (zero | neg | pos) (ex: hoa.encoder~ => hoa.optim~) if (startobj_infos->autoconnect_outputs_type == HOA_CONNECT_TYPE_AMBISONICS) { inletnum = jpatchline_get_inletnum(line); if (startobj_infos->object_type == HOA_OBJECT_2D) sign = x->f_ambi2D->getHarmonicArgument(inletnum); if (startobj_infos->object_type == HOA_OBJECT_3D) sign = x->f_ambi3D->getHarmonicArgument(inletnum); if (sign > 0) linecolor = &x->f_color_positiv; else if (sign < 0) linecolor = &x->f_color_negativ; else linecolor = &x->f_color_zero; jpatchline_set_color(line, linecolor); } // planewave color (ex: hoa.projector~ => hoa.recomposer~) else if (startobj_infos->autoconnect_outputs_type == HOA_CONNECT_TYPE_PLANEWAVES) { jpatchline_set_color(line, &x->f_color_plane); } } // hoa.plug~ retro compatibility else if (object_classname(startobj) == hoa_sym_jpatcher) { jb = jpatcher_get_firstobject(startobj); while(jb) { o = jbox_get_object(jb); if(object_classname(o) == gensym("hoa.plug_script")) { inletnum = jpatchline_get_inletnum(line); if (inletnum == 0) jpatchline_set_color(line, &x->f_color_zero); else if (inletnum % 2 == 1) jpatchline_set_color(line, &x->f_color_negativ); else jpatchline_set_color(line, &x->f_color_positiv); break; } jb = jbox_get_nextobject(jb); } } } line = jpatchline_get_nextline(line); } free(startobj_infos); }
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_schemaList(t_object *ob, t_symbol *msg, int argc, t_atom *argv) { t_symbol *classname = object_classname(ob); if(!classname){ return; } t_hashtab *ht = omax_class_getHashtab(classname->s_name); if(!ht){ return; } t_schemalist *sl = NULL; hashtab_lookup(ht, gensym("cnmat_internal_osc_schema_list"), (t_object **)&sl); if(!sl){ return; } int typetaglen = (sl->address_buf_pos + 2); while(typetaglen % 4){ typetaglen++; } char *address = "/osc/schema/list"; int addresslen = 20; char buf[sl->nbytes + OSC_HEADER_SIZE + 4 + typetaglen + addresslen]; // need to add space for timetag memset(buf, '\0', sl->nbytes + OSC_HEADER_SIZE + 4 + typetaglen); char *bufptr = buf + OSC_HEADER_SIZE; *((uint32_t *)bufptr) = hton32(sl->nbytes + typetaglen + addresslen); bufptr += 4; strncpy(bufptr, address, 16); bufptr += addresslen; *bufptr = ','; memset(bufptr + 1, 's', sl->address_buf_pos); bufptr += typetaglen; int i; for(i = 0; i < sl->address_buf_pos; i++){ memcpy(bufptr, sl->addresses[i].buf, sl->addresses[i].bufpos); bufptr += sl->addresses[i].bufpos; } osc_bundle_s_setBundleID(buf); // put timestamp in place... /* long nkeys = 0; t_symbol **keys = NULL; hashtab_getkeys(ht, &nkeys, &keys); int buflen = 128; char *buf = sysmem_newptr(buflen); memset(buf, '\0', buflen); int bufpos = 0; osc_bundle_setBundleID(buf); bufpos += OSC_HEADER_SIZE; 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(ob, 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(ob, gensym(getter), (void **)(&attr), &get); if(f){ f(ob, attr, &argc, &argv); if(argv){ char address[128]; sprintf(address, "/parameter/%s", m->sym->s_name); int msglen = omax_util_get_bundle_size_for_atoms(gensym(address), argc, argv); if(msglen + bufpos >= buflen){ buf = sysmem_resizeptr(buf, buflen + msglen); if(!buf){ object_error(ob, "out of memory!"); return; } } bufpos += omax_util_encode_atoms(buf + bufpos, gensym(address), argc, argv); sysmem_freeptr(argv); } } }else { int msglen = omax_util_get_bundle_size_for_atoms(keys[i], 0, NULL); if(msglen + bufpos >= buflen){ buf = sysmem_resizeptr(buf, buflen + msglen); if(!buf){ object_error(ob, "out of memory!"); return; } memset(buf + buflen, '\0', msglen); buflen += msglen; } char methodname[128]; sprintf(methodname, "/method/%s", m->sym->s_name); bufpos += omax_util_encode_atoms(buf + bufpos, gensym(methodname), 0, NULL); } } */ void *infoout = omax_object_getInfoOutlet(ob); if(infoout){ t_atom out[2]; atom_setlong(out, bufptr - buf); atom_setlong(out + 1, (long)buf); outlet_anything(infoout, gensym("FullPacket"), 2, out); } }
void hoa_gain_tometer(t_hoa_gain *x, t_symbol *s, long ac, t_atom *av) { if(ac && av) { t_object *patcher; t_object *gain; t_object *line; t_max_err err; t_atom rv; t_atom msg[4]; err = object_obex_lookup(x, hoa_sym_pound_P, (t_object **)&patcher); if (err != MAX_ERR_NONE) return; err = object_obex_lookup(x, hoa_sym_pound_B, (t_object **)&gain); if (err != MAX_ERR_NONE) return; vector<t_jbox *> boxes; for (line = jpatcher_get_firstline(patcher); line; line = jpatchline_get_nextline(line)) { if (jpatchline_get_box1(line) == gain) { t_jbox *box = (t_jbox*)jpatchline_get_box2(line); t_object *obj = jbox_get_object((t_object*)box); t_symbol* classname = object_classname(obj); if (find(boxes.begin(), boxes.end(), box) == boxes.end()) { if(classname == hoa_sym_hoa_2d_meter || classname == hoa_sym_hoa_2d_vector || classname == hoa_sym_hoa_gain) { object_method_typed(obj, s, ac, av, NULL); boxes.push_back(box); } else if(classname == hoa_sym_dac || (object_is_hoa(obj) && classname != hoa_sym_hoa_pi && classname != hoa_sym_hoa_pi_tilde)) { boxes.push_back(box); } } } } for(auto box : boxes) { // re-connect patchlines for(int i = 0; jbox_getinlet(box, i) != NULL && i < x->f_number_of_channels; i++) { atom_setobj(msg, gain); atom_setlong(msg + 1, i); atom_setobj(msg + 2, box); atom_setlong(msg + 3, i); object_method_typed(patcher , hoa_sym_connect, 4, msg, &rv); } } boxes.clear(); } }
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); } }