Exemplo n.º 1
0
t_osc_err osc_bundle_u_copy(t_osc_bndl_u **dest, t_osc_bndl_u *src)
{
	t_osc_bndl_s *bs = osc_bundle_u_serialize(src);
	*dest = osc_bundle_s_deserialize(osc_bundle_s_getLen(bs), osc_bundle_s_getPtr(bs));
	osc_bundle_s_deepFree(bs);
	return OSC_ERR_NONE;
}
Exemplo n.º 2
0
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);
	}
}
Exemplo n.º 3
0
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);
	*/
}
Exemplo n.º 4
0
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);
}
Exemplo n.º 5
0
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);
}
Exemplo n.º 6
0
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);
}
Exemplo n.º 7
0
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);
}
Exemplo n.º 8
0
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;
    }
}
Exemplo n.º 9
0
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);
}
Exemplo n.º 10
0
void odisplay_bundle2text(t_odisplay *x)
{
    critical_enter(x->lock);
	if(x->newbndl && x->bndl_s){
		long len = osc_bundle_s_getLen(x->bndl_s);
		char ptr[len];
		memcpy(ptr, osc_bundle_s_getPtr(x->bndl_s), len);
		critical_exit(x->lock);
		long bufpos = osc_bundle_s_nformat(NULL, 0, len, (char *)ptr, 0);
		char *buf = osc_mem_alloc(bufpos + 1);
        osc_bundle_s_nformat(buf, bufpos + 1, len, (char *)ptr, 0);
        if (bufpos != 0) {
		/*
            if(buf[bufpos - 2] == '\n'){
                buf[bufpos - 2] = '\0';
            }
		*/
        } else {
            *buf = '\0';
        }
		
#ifndef OMAX_PD_VERSION
		critical_enter(x->lock);
		if(x->text){
			osc_mem_free(x->text);
		}
		x->textlen = bufpos;
        x->text = buf;
		critical_exit(x->lock);
        object_method(jbox_get_textfield((t_object *)x), gensym("settext"), buf);
#else
        opd_textbox_resetText(x->textbox, buf);

#endif
		if(buf){
			//osc_mem_free(buf);
		}
		x->newbndl = 0;
	}
	critical_exit(x->lock);
}
Exemplo n.º 11
0
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);
	}
}
Exemplo n.º 12
0
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);
}
Exemplo n.º 13
0
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);
	}

}
Exemplo n.º 14
0
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);
}
Exemplo n.º 15
0
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);
	}
}
Exemplo n.º 16
0
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);
    }
}
Exemplo n.º 17
0
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);
	}
}
Exemplo n.º 18
0
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);
 	}
}
Exemplo n.º 19
0
//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);
}