void otimetag_doFullPacket(t_otimetag *x, long len, char *ptr) { t_osc_timetag t = osc_timetag_now(); if(x->address){ t_osc_bndl_u *copy = osc_bundle_s_deserialize(len, ptr); t_osc_msg_u *m = osc_message_u_allocWithTimetag(x->address->s_name, t); osc_bundle_u_addMsgWithoutDups(copy, m); t_osc_bndl_s *bs = osc_bundle_u_serialize(copy); if(bs){ omax_util_outletOSC(x->outlet, osc_bundle_s_getLen(bs), osc_bundle_s_getPtr(bs)); osc_bundle_s_deepFree(bs); } osc_bundle_u_free(copy); }else{ char copy[len]; memcpy(copy, ptr, len); osc_bundle_s_setTimetag(len, copy, t); omax_util_outletOSC(x->outlet, len, copy); OSC_MEM_INVALIDATE(copy); } }
static void udpreceive_read(t_oudpreceive *x, int sockfd) { int i, read = 0; struct sockaddr_in from; socklen_t fromlen = sizeof(from); t_atom output_atom; long addr; unsigned short port; read = recvfrom(sockfd, x->x_msginbuf, MAX_UDP_RECEIVE, 0, (struct sockaddr *)&from, &fromlen); #ifdef DEBUG post("udpreceive_read: read %lu x->x_connectsocket = %d", read, x->x_connectsocket); #endif /* get the sender's ip */ addr = ntohl(from.sin_addr.s_addr); port = ntohs(from.sin_port); x->x_addrbytes[0].a_w.w_float = (addr & 0xFF000000)>>24; x->x_addrbytes[1].a_w.w_float = (addr & 0x0FF0000)>>16; x->x_addrbytes[2].a_w.w_float = (addr & 0x0FF00)>>8; x->x_addrbytes[3].a_w.w_float = (addr & 0x0FF); x->x_addrbytes[4].a_w.w_float = port; outlet_anything(x->x_addrout, gensym("from"), 5L, x->x_addrbytes); if (read < 0) { udpreceive_sock_err(x, "udpreceive_read"); sys_closesocket(x->x_connectsocket); return; } if((read % 4) == 0){ char buf[read]; memcpy(buf, x->x_msginbuf, read); critical_exit(x->lock); omax_util_outletOSC(x->outlet, read, buf); OSC_MEM_INVALIDATE(buf); //oudp_sendData(x, t, x->slipibuf); }else{ critical_exit(x->lock); //object_error((t_object *)x, "bad packet: not a multiple of 4 length"); } /* if (read > 0) { for (i = 0; i < read; ++i) { oudp_decode(x, (unsigned char)x->x_msginbuf[i]); } oudp_decode(x, END); x->x_total_received += read; SETFLOAT(&output_atom, read); outlet_anything(x->x_addrout, gensym("received"), 1, &output_atom); }*/ }
void ouniform_doFullPacket(t_ouniform *x, long len, char *ptr) { int seed_is_bound = 0; osc_bundle_s_addressIsBound(len, ptr, "/uniform/set/seed", 1, &seed_is_bound); if (seed_is_bound) { long change_to = ouniform_getNumber(len, ptr, "/uniform/set/seed"); if (change_to > 0) { if (x->seed != change_to) { x->seed = change_to; srand(x->seed); x->state = 0; } } osc_bundle_s_removeMessage("/uniform/set/seed", &len, ptr, 1); } int state_is_bound = 0; osc_bundle_s_addressIsBound(len, ptr, "/uniform/set/state", 1, &state_is_bound); if (state_is_bound) { long change_to = ouniform_getNumber(len, ptr, "/uniform/set/state"); if (change_to >= 0) { x->state = 0; srand(x->seed); for (int i = 0; i < change_to; ++i) { rand(); ++x->state; } } osc_bundle_s_removeMessage("/uniform/set/state", &len, ptr, 1); } t_osc_bndl_u *copy = osc_bundle_s_deserialize(len, ptr); t_osc_message_u *result = NULL; if(x->address) { result = osc_message_u_allocWithFloat(x->address->s_name, (1.0f * rand() / RAND_MAX)); }else{ result = osc_message_u_allocWithFloat("/uniform/random", (1.0f * rand() / RAND_MAX)); } t_osc_message_u *seed = osc_message_u_allocWithAddress("/uniform/seed"); osc_message_u_appendInt32(seed, x->seed); t_osc_message_u *state = osc_message_u_allocWithAddress("/uniform/state"); osc_message_u_appendInt32(state, x->state); osc_bundle_u_addMsgWithoutDups(copy, result); osc_bundle_u_addMsgWithoutDups(copy, seed); osc_bundle_u_addMsgWithoutDups(copy, state); ++x->state; t_osc_bndl_s *bs = osc_bundle_u_serialize(copy); if(bs){ omax_util_outletOSC(x->outlet, osc_bundle_s_getLen(bs), osc_bundle_s_getPtr(bs)); osc_bundle_s_deepFree(bs); } osc_bundle_u_free(copy); }
//void omiterate_fullPacket(t_omiterate *x, long len, long ptr) void omiterate_fullPacket(t_omiterate *x, t_symbol *msg, int argc, t_atom *argv) { OMAX_UTIL_GET_LEN_AND_PTR; t_osc_bndl_it_s *it = osc_bndl_it_s_get(len, ptr); while(osc_bndl_it_s_hasNext(it)){ t_osc_msg_s *m = osc_bndl_it_s_next(it); long l = osc_message_s_getSize(m); char *p = osc_message_s_getAddress(m); omax_util_outletOSC(x->outlet, l, p); } osc_bndl_it_s_destroy(it); }
void oflatten_fullPacket(t_oflatten *x, t_symbol *msg, int argc, t_atom *argv) { OMAX_UTIL_GET_LEN_AND_PTR char srcc[osc_bundle_s_getStructSize()]; t_osc_bndl_s *src = (t_osc_bndl_s *)srcc; osc_bundle_s_setLen(src, len); osc_bundle_s_setPtr(src, ptr); t_osc_bndl_s *dest = NULL; osc_bundle_s_flatten(&dest, src, x->level, x->sep->s_name, x->remove_enclosing_address_if_empty); omax_util_outletOSC(x->outlet, osc_bundle_s_getLen(dest), osc_bundle_s_getPtr(dest)); osc_bundle_s_deepFree(dest); }
void ocoll_bang(t_ocoll *x){ critical_enter(x->lock); int len = x->buffer_pos; char outbuf[len]; memcpy(outbuf, x->buffer, len); memset(x->buffer + OSC_HEADER_SIZE, '\0', len - OSC_HEADER_SIZE); x->buffer_pos = OSC_HEADER_SIZE; critical_exit(x->lock); omax_util_outletOSC(x->outlet, len, outbuf); // invalidate outbuf: OSC_MEM_INVALIDATE(outbuf); }
void odisplay_output_bundle(t_odisplay *x) { // the use of critical sections is a little weird here, but correct. critical_enter(x->lock); if(x->bndl_s){ t_osc_bndl_s *b = x->bndl_s; long len = osc_bundle_s_getLen(b); char *ptr = osc_bundle_s_getPtr(b); char buf[len]; memcpy(buf, ptr, len); critical_exit(x->lock); omax_util_outletOSC(x->outlet, len, buf); OSC_MEM_INVALIDATE(buf); return; } critical_exit(x->lock); char buf[OSC_HEADER_SIZE]; memset(buf, '\0', OSC_HEADER_SIZE); osc_bundle_s_setBundleID(buf); omax_util_outletOSC(x->outlet, OSC_HEADER_SIZE, buf); OSC_MEM_INVALIDATE(buf); }
void oedge_callback(t_oedge *x, t_symbol *msg, int argc, t_atom *argv) { double lastx = x->lastx; //t_osc_bndl_u *b = osc_bundle_u_alloc(); double sr = atom_getfloat(argv); double blockcount = atom_getlong(argv + 1); t_osc_timetag dspstarttime = x->dspstarttime; t_osc_timetag now = (t_osc_timetag){atom_getlong(argv + 2), atom_getlong(argv + 3)};//(((uint64_t)atom_getlong(argv + 2)) << 32) | ((uint64_t)atom_getlong(argv + 3)); int shouldoutput = 0; for(int i = 0; i < argc - 4; i++){ double xx = atom_getfloat(argv + i + 4); if(lastx == 0 && xx != 0){ shouldoutput = 1; t_osc_timetag t = oedge_computeTime(now, dspstarttime, sr, argc - 4, blockcount, i); osc_message_u_appendTimetag(x->time_onset, t); osc_message_u_appendUInt32(x->block_sample_onset, (i)); osc_message_u_appendDouble(x->global_sample_onset, ((argc - 4) * blockcount) + (i)); osc_message_u_appendDouble(x->value_onset, xx); //oedge_addMessageToBundle(b, "/zerotononzero", i, blockcount, argc, t); }else if(lastx != 0 && xx == 0){ shouldoutput = 1; t_osc_timetag t = oedge_computeTime(now, dspstarttime, sr, argc - 4, blockcount, (i)); osc_message_u_appendTimetag(x->time_zero, t); osc_message_u_appendUInt32(x->block_sample_zero, (i)); osc_message_u_appendDouble(x->global_sample_zero, ((argc - 4) * blockcount) + (i)); //oedge_addMessageToBundle(b, "/nonzerotozero", i, blockcount, argc, t); } lastx = xx; } x->lastx = lastx; if(shouldoutput){ t_osc_bndl_s *bs = osc_bundle_u_serialize(x->bundle); if(bs){ omax_util_outletOSC(x->outlet, osc_bundle_s_getLen(bs), osc_bundle_s_getPtr(bs)); osc_bundle_s_deepFree(bs); } } osc_message_u_clearArgs(x->time_onset); osc_message_u_clearArgs(x->block_sample_onset); osc_message_u_clearArgs(x->global_sample_onset); osc_message_u_clearArgs(x->value_onset); osc_message_u_clearArgs(x->time_zero); osc_message_u_clearArgs(x->block_sample_zero); osc_message_u_clearArgs(x->global_sample_zero); }
//void opbytes_fullPacket(t_opbytes *x, long len, long ptr) void opbytes_fullPacket(t_opbytes *x, t_symbol *msg, int argc, t_atom *argv) { OMAX_UTIL_GET_LEN_AND_PTR unsigned char *buf = (unsigned char *)ptr; int i; post("%-12s%-12s%-12s%s", "Byte #", "ASCII", "Decimal", "Hex\n"); for(i = 0; i < len; i++){ if(buf[i] == '\0'){ post("%05d %-14s%-14d0x%x\n", i, "'\\0'", buf[i], buf[i]); }else if(buf[i] < 32 || buf[i] > 126){ post("%05d %-14s%-14d0x%x\n", i, "''", buf[i], buf[i]); }else{ char b[32]; sprintf(b, "'%c'", buf[i]); post("%05d %-14s%-14d0x%x\n", i, b, buf[i], buf[i]); } } omax_util_outletOSC(x->outlet, len, (char *)ptr); }
void ocontext_doFullPacket(t_ocontext *x, long len, char *ptr) { t_canvas *patcher = NULL; patcher = x->canvas; t_osc_bndl_u *mypatcher_bndl = ocontext_processCanvas(patcher); t_osc_msg_u *context_msg = osc_message_u_allocWithAddress("/context"); osc_message_u_appendBndl_u(context_msg, mypatcher_bndl); t_osc_bndl_u *bu = osc_bundle_s_deserialize(len, ptr); if(bu){ osc_bundle_u_addMsgWithoutDups(bu, context_msg); t_osc_bndl_s *bs = osc_bundle_u_serialize(bu); if(bs){ omax_util_outletOSC(x->outlet, osc_bundle_s_getLen(bs), osc_bundle_s_getPtr(bs)); osc_bundle_s_deepFree(bs); } } osc_bundle_u_free(mypatcher_bndl); }
void olistenumerate_noMatchesOrData(t_olistenumerate *x) { // left outlet: t_osc_message_u* address = osc_message_u_allocWithString("/address", x->address->s_name); t_osc_message_u* length = osc_message_u_allocWithAddress("/length"); osc_message_u_appendInt32(length, 0); t_osc_bundle_u* unserialized_result = osc_bundle_u_alloc(); osc_bundle_u_addMsg(unserialized_result, address); osc_bundle_u_addMsg(unserialized_result, length); t_osc_bndl_s *bs = osc_bundle_u_serialize(unserialized_result); osc_bundle_u_free(unserialized_result); unserialized_result = NULL; if (bs) { omax_util_outletOSC(x->outlets[1], osc_bundle_s_getLen(bs), osc_bundle_s_getPtr(bs)); osc_bundle_s_deepFree(bs); bs = NULL; } }
void ocontext_doFullPacket(t_ocontext *x, long len, char *ptr) { t_object *parent = NULL, *patcher = NULL; object_obex_lookup(x, gensym("#P"), &patcher); //t_jbox *box = NULL; //object_obex_lookup(x, gensym("#B"), &box); t_osc_bndl_u *mypatcher_bndl = ocontext_processPatcher(patcher); t_osc_msg_u *context_msg = osc_message_u_allocWithAddress("/context"); osc_message_u_appendBndl_u(context_msg, mypatcher_bndl); t_osc_bndl_u *bu = osc_bundle_s_deserialize(len, ptr); if(bu){ osc_bundle_u_addMsgWithoutDups(bu, context_msg); t_osc_bndl_s *bs = osc_bundle_u_serialize(bu); if(bs){ omax_util_outletOSC(x->outlet, osc_bundle_s_getLen(bs), osc_bundle_s_getPtr(bs)); osc_bundle_s_deepFree(bs); } osc_bundle_u_free(bu); } }
void ovalidate_fullPacket(t_ovalidate *x, t_symbol *msg, int argc, t_atom *argv) { OMAX_UTIL_GET_LEN_AND_PTR; /* t_osc_err e = osc_error_bundleSanityCheck(len, ptr); if(e){ t_osc_bndl_u *b = osc_bundle_u_alloc(); t_osc_msg_u *merr = osc_message_u_alloc(); osc_message_u_setAddress(merr, "/error/str"); osc_message_u_appendString(merr, osc_error_string(e)); osc_bundle_u_addMsg(b, merr); long l = 0; char *buf = NULL; osc_bundle_u_serialize(b, &l, &buf); if(buf){ omax_util_outletOSC(x->outletErr, l, buf); omax_util_outletOSC(x->outletInval, len, ptr); osc_mem_free(buf); } return; } */ if(*ptr != '#' && *ptr != '/'){ char errstr[128]; snprintf(errstr, 128, "invalid packet: packet does not begin with a # or a /"); t_osc_bndl_u *b = osc_bundle_u_alloc(); t_osc_msg_u *merr = osc_message_u_alloc(); osc_message_u_setAddress(merr, "/error/str"); osc_message_u_appendString(merr, errstr); osc_bundle_u_addMsg(b, merr); t_osc_bndl_s *bs = osc_bundle_u_serialize(b); if(bs){ omax_util_outletOSC(x->outletErr, osc_bundle_s_getLen(bs), osc_bundle_s_getPtr(bs)); omax_util_outletOSC(x->outletInval, len, ptr); osc_bundle_s_deepFree(bs); } return; } if(len % 4){ char errstr[128]; snprintf(errstr, 128, "%ld is not a multiple of 4 bytes", len); t_osc_bndl_u *b = osc_bundle_u_alloc(); t_osc_msg_u *merr = osc_message_u_alloc(); osc_message_u_setAddress(merr, "/error/str"); osc_message_u_appendString(merr, errstr); osc_bundle_u_addMsg(b, merr); t_osc_bndl_s *bs = osc_bundle_u_serialize(b); if(bs){ omax_util_outletOSC(x->outletErr, osc_bundle_s_getLen(bs), osc_bundle_s_getPtr(bs)); omax_util_outletOSC(x->outletInval, len, ptr); osc_bundle_s_deepFree(bs); } return; } if(*ptr == '#'){ char *p = ptr; p += OSC_HEADER_SIZE; while((p - ptr) < (len - 4)){ int i = ntoh32(*((int32_t *)p)); if(i < 0){ break; } p += i + 4; } if((p - ptr) != len){ char errstr[128]; snprintf(errstr, 128, "expected %ld bytes, but found %d", len, p - ptr); t_osc_bndl_u *b = osc_bundle_u_alloc(); t_osc_msg_u *merr = osc_message_u_alloc(); osc_message_u_setAddress(merr, "/error/str"); osc_message_u_appendString(merr, errstr); osc_bundle_u_addMsg(b, merr); t_osc_bndl_s *bs = osc_bundle_u_serialize(b); if(bs){ omax_util_outletOSC(x->outletErr, osc_bundle_s_getLen(bs), osc_bundle_s_getPtr(bs)); omax_util_outletOSC(x->outletInval, len, ptr); osc_bundle_s_deepFree(bs); } return; } } uint64_t state = OSC_SERIAL_INIT; for(int i = 0; i < len; i++){ state = osc_serial_processByte(ptr[i], state); if(osc_serial_errorp(state)){ char *errstr = osc_serial_errstr(state); t_osc_bndl_u *b = osc_bundle_u_alloc(); t_osc_msg_u *merr = osc_message_u_alloc(); osc_message_u_setAddress(merr, "/error/str"); osc_message_u_appendString(merr, errstr); osc_bundle_u_addMsg(b, merr); t_osc_msg_u *mbytenum = osc_message_u_alloc(); osc_message_u_setAddress(mbytenum, "/error/byte/num"); osc_message_u_appendInt32(mbytenum, i); osc_bundle_u_addMsg(b, mbytenum); if(mbytenum < len){ t_osc_msg_u *mbyteval = osc_message_u_alloc(); osc_message_u_setAddress(mbyteval, "/error/byte/val"); osc_message_u_appendInt32(mbyteval, ptr[i]); osc_bundle_u_addMsg(b, mbyteval); } t_osc_bndl_s *bs = osc_bundle_u_serialize(b); if(bs){ omax_util_outletOSC(x->outletErr, osc_bundle_s_getLen(bs), osc_bundle_s_getPtr(bs)); omax_util_outletOSC(x->outletInval, len, ptr); osc_bundle_s_deepFree(bs); } return; } } omax_util_outletOSC(x->outletVal, len, ptr); }
void olistenumerate_doFullPacket(t_olistenumerate *x, long len, char *ptr) { if (!x->address) { return; } critical_enter(x->lock); char* address_name = x->address->s_name; critical_exit(x->lock); t_osc_msg_ar_s *matches = osc_bundle_s_lookupAddress(len, ptr, address_name, 1); char delegate[len]; long dlen = len; memcpy(delegate, ptr, len); if (matches) { // right outlet: osc_bundle_s_removeMessage(address_name, &dlen, delegate, 1); int message_count = 0; osc_bundle_s_getMsgCount(dlen, delegate, &message_count); if (message_count > 0) { omax_util_outletOSC(x->outlets[0], dlen, delegate); OSC_MEM_INVALIDATE(delegate); } // left outlet: for (int i = 0; i < osc_array_getLen(matches); ++i) { t_osc_message_s* message_match = (t_osc_message_s*)osc_array_get(matches, i); t_osc_message_u* unserialized_msg = osc_message_s_deserialize(message_match); int array_length = osc_message_u_getArgCount(unserialized_msg); if (array_length > 0) { for (int j = 0; j < array_length; ++j) { t_osc_atom_u* iter_atom = osc_message_u_getArg(unserialized_msg, j); t_osc_atom_u* atom_copy = osc_atom_u_copy(iter_atom); if (atom_copy) { t_osc_bundle_u* unserialized_result = NULL; //char type = osc_atom_u_getTypetag(atom_copy); unserialized_result = osc_bundle_u_alloc(); t_osc_message_u* value = osc_message_u_allocWithAddress("/value"); osc_message_u_appendAtom(value, atom_copy); osc_bundle_u_addMsg(unserialized_result, value); t_osc_message_u* address = osc_message_u_allocWithString("/address", address_name); t_osc_message_u* index = osc_message_u_allocWithAddress("/index"); osc_message_u_appendInt32(index, j); t_osc_message_u* length = osc_message_u_allocWithAddress("/length"); osc_message_u_appendInt32(length, array_length); osc_bundle_u_addMsg(unserialized_result, address); osc_bundle_u_addMsg(unserialized_result, index); osc_bundle_u_addMsg(unserialized_result, length); t_osc_bndl_s *bs = osc_bundle_u_serialize(unserialized_result); osc_bundle_u_free(unserialized_result); // frees value, count, length and atom_copy unserialized_result = NULL; atom_copy = NULL; if (bs) { omax_util_outletOSC(x->outlets[1], osc_bundle_s_getLen(bs), osc_bundle_s_getPtr(bs)); osc_bundle_s_deepFree(bs); bs = NULL; } } } if (unserialized_msg) { osc_message_u_free(unserialized_msg); unserialized_msg = NULL; } } else { olistenumerate_noMatchesOrData(x); } } } else { // no matches // right outlet: omax_util_outletOSC(x->outlets[0], dlen, delegate); } if (matches) { osc_array_free(matches); } }
//void odowncast_fullPacket(t_odowncast *x, long len, long ptr) void odowncast_fullPacket(t_odowncast *x, t_symbol *msg, int argc, t_atom *argv) { OMAX_UTIL_GET_LEN_AND_PTR; t_osc_bndl_u *b = osc_bundle_s_deserialize(len, ptr); if(!b){ object_error((t_object *)x, "invalid OSC packet"); return; } /* if(x->flatten_nested_bundles){ t_osc_bndl_u *bf = NULL; e = osc_bundle_u_flatten(&bf, b } */ t_osc_bndl_u **nestedbundles = NULL; int nnestedbundles = 0, nestedbundles_buflen = 0; t_osc_bndl_it_u *bit = osc_bndl_it_u_get(b); t_osc_timetag timetag = OSC_TIMETAG_NULL; while(osc_bndl_it_u_hasNext(bit)){ t_osc_msg_u *m = osc_bndl_it_u_next(bit); t_osc_msg_it_u *mit = osc_msg_it_u_get(m); while(osc_msg_it_u_hasNext(mit)){ t_osc_atom_u *a = osc_msg_it_u_next(mit); int i = 0; switch(osc_atom_u_getTypetag(a)){ case 'c': case 'C': case 'I': case 'h': case 'H': case 'u': case 'U': case 'N': case 'T': case 'F': if(x->ints){ osc_atom_u_setInt32(a, osc_atom_u_getInt32(a)); } break; case 'd': if(x->doubles){ osc_atom_u_setFloat(a, osc_atom_u_getFloat(a)); } break; case OSC_BUNDLE_TYPETAG: if(x->bundles){ if(!nestedbundles || nnestedbundles == nestedbundles_buflen){ nestedbundles = (t_osc_bndl_u **)osc_mem_resize(nestedbundles, (nestedbundles_buflen + 16) * sizeof(char *)); } nestedbundles[nnestedbundles++] = osc_atom_u_getBndl(a); osc_message_u_removeAtom(m, a); } break; case OSC_TIMETAG_TYPETAG: #if OSC_TIMETAG_FORMAT == OSC_TIMETAG_NTP if(x->timetags){ t_osc_timetag tt = osc_atom_u_getTimetag(a); if(x->timetag_address){ char *address = osc_message_u_getAddress(m); if(!strcmp(address, x->timetag_address->s_name)){ timetag = tt; } } t_osc_atom_u *aa = osc_atom_u_alloc(); int32_t tt1, tt2; //tt1 = (tt & 0xffffffff00000000) >> 32; //tt2 = tt & 0xffffffff; tt1 = osc_timetag_ntp_getSeconds(tt); tt2 = osc_timetag_ntp_getFraction(tt); osc_atom_u_setInt32(aa, ntoh32(tt1)); osc_atom_u_setInt32(a, ntoh32(tt2)); osc_message_u_insertAtom(m, aa, ++i); } #else object_error((t_object *)x, "o.downcast only supports NTP timetags"); #endif break; } i++; } osc_msg_it_u_destroy(mit); } osc_bndl_it_u_destroy(bit); t_osc_bndl_s *bs1 = osc_bundle_u_serialize(b); if(bs1){ long l = osc_bundle_s_getLen(bs1); char *p = osc_bundle_s_getPtr(bs1); memcpy(p + OSC_ID_SIZE, &timetag, sizeof(t_osc_timetag)); for(int i = 0; i < nnestedbundles; i++){ t_osc_bndl_s *bs2 = osc_bundle_u_serialize(nestedbundles[i]); if(bs2){ long ll = osc_bundle_s_getLen(bs2); char *pp = osc_bundle_s_getPtr(bs2); p = osc_mem_resize(p, l + ll); memcpy(p + l, pp, ll); l += ll; osc_bundle_s_deepFree(bs2); } } //if(x->bundle){ omax_util_outletOSC(x->outlet, l, p); /* }else{ t_osc_bndl_it_s *bit = osc_bndl_it_s_get(l, p); while(osc_bndl_it_s_hasNext(bit)){ t_osc_msg_s *m = osc_bndl_it_s_next(bit); long ml = osc_message_s_getSize(m); char *mp = osc_message_s_getAddress(m); omax_util_outletOSC(x->outlet, ml, mp); } osc_bndl_it_s_destroy(bit); } */ osc_bundle_s_deepFree(bs1); } osc_bundle_u_free(b); }
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_doc_outletDoc(void *outlet, char *name, char *short_desc, char *long_desc, int ninlets, char **inlets_desc, int noutlets, char **outlets_desc, int num_see_also_refs, char **see_also) { t_osc_bndl_u *bndl = osc_bundle_u_alloc(); t_osc_msg_u *msg_name = osc_message_u_alloc(); osc_message_u_setAddress(msg_name, "/doc/name"); osc_message_u_appendString(msg_name, name); osc_bundle_u_addMsg(bndl, msg_name); t_osc_msg_u *msg_short_desc = osc_message_u_alloc(); osc_message_u_setAddress(msg_short_desc, "/doc/desc/short"); osc_message_u_appendString(msg_short_desc, short_desc); osc_bundle_u_addMsg(bndl, msg_short_desc); t_osc_msg_u *msg_long_desc = osc_message_u_alloc(); osc_message_u_setAddress(msg_long_desc, "/doc/desc/long"); osc_message_u_appendString(msg_long_desc, long_desc); osc_bundle_u_addMsg(bndl, msg_long_desc); t_osc_msg_u *msg_ninlets = osc_message_u_alloc(); osc_message_u_setAddress(msg_ninlets, "/doc/ninlets"); osc_message_u_appendInt32(msg_ninlets, ninlets); osc_bundle_u_addMsg(bndl, msg_ninlets); t_osc_msg_u *msg_noutlets = osc_message_u_alloc(); osc_message_u_setAddress(msg_noutlets, "/doc/noutlets"); osc_message_u_appendInt32(msg_noutlets, noutlets); osc_bundle_u_addMsg(bndl, msg_noutlets); int i; for(i = 0; i < ninlets; i++){ if(inlets_desc[i]){ t_osc_msg_u *m = osc_message_u_alloc(); char buf[64]; sprintf(buf, "/doc/desc/inlet/%d", i + 1); osc_message_u_setAddress(m, buf); osc_message_u_appendString(m, inlets_desc[i]); osc_bundle_u_addMsg(bndl, m); } } for(i = 0; i < noutlets; i++){ if(outlets_desc[i]){ t_osc_msg_u *m = osc_message_u_alloc(); char buf[64]; sprintf(buf, "/doc/desc/outlet/%d", i + 1); osc_message_u_setAddress(m, buf); osc_message_u_appendString(m, outlets_desc[i]); osc_bundle_u_addMsg(bndl, m); } } t_osc_msg_u *msg_seealso = osc_message_u_alloc(); osc_message_u_setAddress(msg_seealso, "/doc/seealso"); for(i = 0; i < num_see_also_refs; i++){ osc_message_u_appendString(msg_seealso, see_also[i]); } osc_bundle_u_addMsg(bndl, msg_seealso); //long len = 0; //char *bndl_s = NULL; t_osc_bndl_s *bs = osc_bundle_u_serialize(bndl); if(bs){ omax_util_outletOSC(outlet, osc_bundle_s_getLen(bs), osc_bundle_s_getPtr(bs)); osc_bundle_s_deepFree(bs); } if(bndl){ osc_bundle_u_free(bndl); } }
//void oO_fullPacket(t_oO *x, long len, long ptr) void oO_fullPacket(t_oO *x, t_symbol *msg, int argc, t_atom *argv) { char bracket[] = {'[', ']', '{', '}'}; char wild[] = {'*', '?'}; char alphanum[62]; for(int i = 0; i < 10; i++){ alphanum[i] = i + 48; } for(int i = 0; i < 26; i++){ alphanum[i + 10] = i + 65; } for(int i = 0; i < 26; i++){ alphanum[i + 36] = i + 97; } OMAX_UTIL_GET_LEN_AND_PTR; char copy[len]; memcpy(copy, ptr, len); int n = 0; osc_bundle_s_getMsgCount(len, copy, &n); long r = floor(((double)random() / 2147483647.) * n); t_osc_bndl_it_s *it = osc_bndl_it_s_get(len, copy); int i = 0; t_osc_msg_s *m = NULL; while(i <= r && osc_bndl_it_s_hasNext(it)){ i++; m = osc_bndl_it_s_next(it); } osc_bndl_it_s_destroy(it); if(m){ char *p = osc_message_s_getAddress(m); if(p){ int n = osc_message_s_getSize(m); long r = floor(((double)random() / 2147483647.) * n); if(r <= strlen(p)){ // inside address section---can add a random NULL byte or f**k with wildcard chars switch(random() & 0x1){ case 0: object_post((t_object *)x, "replaced '%c' at position %d with NULL\n", p[r], r); p[r] = '\0'; break; case 1: { int isbracket = 0; for(int i = 0; i < sizeof(bracket); i++){ if(bracket[i] == p[r]){ isbracket = 1; break; } } if(isbracket){ // we have a bracket, replace it with an alphanum char or NULL switch(random() & 0x1){ case 0: { long rrr = (long)floor(((double)random() / 2147483647.) * sizeof(alphanum)); object_post((t_object *)x, "replaced '%c' at position %d with '%c'\n", p[r], r, alphanum[rrr]); p[r] = alphanum[rrr]; } break; case 1: object_post((t_object *)x, "replaced '%c' at position %d with NULL\n", p[r], r); p[r] = NULL; break; } }else{ // not a bracket, replace it with one or NULL switch(random() & 0x1){ case 0: { long rrr = (long)floor(((double)random() / 2147483647.) * sizeof(bracket)); object_post((t_object *)x, "replaced '%c' at position %d with '%c'\n", p[r], r, bracket[rrr]); p[r] = bracket[rrr]; } break; case 1: object_post((t_object *)x, "replaced '%c' at position %d with NULL\n", p[r], r); p[r] = NULL; break; } } } break; } }else if(r < (osc_message_s_getData(m) - p)){ // typetag section---add a NULL or char if(p[r] == NULL){ long rrr = (long)floor(((double)random() / 2147483647.) * sizeof(alphanum)); object_post((t_object *)x, "replaced NULL at position %d with '%c'\n", r, alphanum[rrr]); p[r] = alphanum[rrr]; }else{ object_post((t_object *)x, "replaced '%c' at position %d with NULL\n", p[r], r); p[r] = NULL; } }else{ // not much we can do here unles we know it's a string or something else with NULL padding, // so just try again oO_fullPacket(x, msg, argc, argv); return; } } } omax_util_outletOSC(x->outlet, len, copy); }
int oudp_decode(t_oudpreceive *x, unsigned char c) { post("%s %x %c", __func__, c, c); critical_enter(x->lock); int t; switch(x->istate) { case 0: // waiting for packet to start x->istate = 1; if(c==END){ break; } case 1: // packet has started switch(c){ case END: if((x->icount > 0)){ // it was the END byte #ifdef untestedDEBUGOUTPUT // full packet process char stringbuf[4096]; int j=0; int i; for(p=0;i<x->icount && i<4095;++i) { char c = x->slipibuf[i]; if(c=='/' || c=='#' || (c>='a' && c<='z') || (c>='A' && c<='Z') || (c<='9' && c>='0') ) stringbuf[j++] = c; else stringbuf[j++] = '*'; } stringbuf[j++] = '\0'; object_post((t_object *)x, "o.udp.receive: packet %d %s", x->icount, stringbuf); #endif // ParseOSCPacket(x, x->slipibuf, x->icount, true); t = x->icount; x->icount = 0; x->istate = 0; if((t % 4) == 0){ char buf[t]; memcpy(buf, x->slipibuf, t); critical_exit(x->lock); omax_util_outletOSC(x->outlet, t, buf); OSC_MEM_INVALIDATE(buf); //oudp_sendData(x, t, x->slipibuf); return 0; }else{ critical_exit(x->lock); //object_error((t_object *)x, "bad packet: not a multiple of 4 length"); return 0; } } x->istate = 0; break; case ESC: x->istate = 2; break; // otherwise, just stick it in the packet buffer default: if(x->icount < MAXSLIPBUF){ x->slipibuf[(x->icount)++] = c; }else{ x->istate = 3; } break; } break; case 2: // process escapes switch(c){ case ESC_END: if(x->icount<MAXSLIPBUF){ x->slipibuf[(x->icount)++] = END; x->istate = 1; } else x->istate = 3; break; case ESC_ESC: if(x->icount<MAXSLIPBUF){ x->slipibuf[(x->icount)++] = ESC; x->istate = 1; } else x->istate = 3; break; default: object_post((t_object *)x, "o.udp.receive: ESC not followed by ESC_END or ESC_ESC."); x->istate = 3; } break; case 3: // error state: hunt for END character (this should probably be a hunt for a non escaped END character.. if(c == END){ x->icount = 0; x->istate = 0; } break; } critical_exit(x->lock); return 1; }