Exemple #1
0
void osc_message_s_free(t_osc_msg_s *m)
{
	if(!m){
		return;
	}
	if(m->data_offset_cache){
		osc_mem_free(m->data_offset_cache);
	}
	if(m->data_size_cache){
		osc_mem_free(m->data_size_cache);
	}
	osc_mem_free(m);
}
Exemple #2
0
void osc_message_s_deepFree(t_osc_msg_s *m)
{
	if(!m){
		return;
	}
	if(m->size){
		osc_mem_free(m->size);
	}
	osc_message_s_free(m);
}
Exemple #3
0
void simplemax_anything(t_simplemax *x,t_symbol* s,int argc,t_atom* argv){
    
    // msg is a dispatch name (/foo), argc is # of elements, argv is element vector
    
    if (!s){object_error((t_object*)x, "NOOOOOO!!!!");}
    
    //object_post((t_object*)x, "%s",msg->s_name);
    t_osc_bundle_u *bundle = osc_bundle_u_alloc();//alloc creates memory for and initializes the bundle
    
    
    t_osc_message_u *msg = osc_message_u_alloc();
    osc_message_u_setAddress(msg, s->s_name);
    
    
    for(int i=0;i < argc;i++){ //going through all the arguments (arg vector) whos length is argc
        
        t_osc_atom_u* a = osc_atom_u_alloc();
        
        switch(atom_gettype(argv+i)){
            
            case A_LONG:
            osc_atom_u_setInt32(a, atom_getlong(argv+i));
            break;
            
            case A_FLOAT:
            osc_atom_u_setFloat(a, atom_getfloat(argv+i));
            break;
            
            case A_SYM:
            osc_atom_u_setString(a, atom_getsym(argv+i)->s_name);
            break;
        
        }
        
        osc_message_u_appendAtom(msg, a);
        //osc_message_u_appendFloat(msg, 15.0);
    }
    osc_bundle_u_addMsg(bundle, msg);
    long bytes = 0;//length of byte array
    char* pointer = NULL;
    
    osc_bundle_u_serialize(bundle, &bytes, &pointer);//& is adress of the variable
    //post("%ld %p", bytes,pointer);
    
    t_atom out[2];
    atom_setlong(out, bytes);
    atom_setlong(out+1, (long)pointer);
    outlet_anything(x->outlet, gensym("FullPacket"), 2, out);
    
    osc_bundle_u_free(bundle);//get rid of stuff in osc message
    osc_mem_free(pointer);//marks pointer address as being free (clear if you want to keep using same pointer)
    
    
}
Exemple #4
0
void osc_bundle_u_free(t_osc_bndl_u *bndl)
{
	if(!bndl){
		return;
	}
	t_osc_msg_u *m = bndl->msghead;
	while(m){
		t_osc_msg_u *next = m->next;
		osc_message_u_free(m);
		m = next;
	}
	osc_mem_free(bndl);
}
Exemple #5
0
void odisplay_clearBundles(t_odisplay *x)
{
	critical_enter(x->lock);
	if(x->bndl_u){
		osc_bundle_u_free(x->bndl_u);
		x->bndl_u = NULL;
	}
	if(x->bndl_s){
		osc_bundle_s_deepFree(x->bndl_s);
		x->bndl_s = NULL;
	}
#ifndef OMAX_PD_VERSION
	if(x->text){
		x->textlen = 0;
		osc_mem_free(x->text);
		x->text = NULL;
	}
#endif
	critical_exit(x->lock);
}
Exemple #6
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);
}
Exemple #7
0
//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;
}
Exemple #8
0
//input an expression and a bundle with data and have it evaluate the expression and compares the results to answer. 
int test_expression(char *expr, char *bundle_string, char *answer){
	t_osc_expr *f = NULL; //f = function = lambda
	int ret = osc_expr_parser_parseString(expr, &f); //parse expression string. returns valid or not
	if(ret){
		printf("parsing %s failed\n", expr);
		osc_expr_free(f);
		return 0;
	}	
	//text representation of the function tree
	char *functiongraph = NULL;
	long len = 0;
	osc_expr_formatFunctionGraph(f, &len, &functiongraph); //from osc_expr.c
	
	t_osc_bndl_u *bndl = NULL;
	t_osc_parser_subst *subs = NULL;
	long nsubs = 0;
	//printf("bundle: %s\n", bundle_string);
	osc_parser_parseString(strlen(bundle_string)+2, bundle_string, &bndl, &nsubs, &subs); //unserialized oscizer. throw valid bundles at this and see if it parses it.
	//^multiple bundles need to be /n delimited. 
	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 *ser_bundle = NULL;
	long sbndl_len = 0;
	osc_bundle_u_serialize(bndl, &sbndl_len, &ser_bundle); //serialize the bundle
	
	//char * ser_bundle = bundalize_osc_string(bundle_string);
	
	t_osc_atom_ar_u *out = NULL;
	ret = osc_expr_funcall(f, &sbndl_len, &ser_bundle, &out);//calls the function on the bundle
	osc_atom_array_u_free(out);
	
	char *buf = NULL;
	long buflen = 0;
	osc_bundle_s_format(sbndl_len, ser_bundle, &buflen, &buf);
	char bufcopy[strlen(buf)];
	strcpy(bufcopy, buf);
	char * formated_answer = validate_osc_string(answer);
	char answer_copy[strlen(formated_answer)];
	strcpy(answer_copy, formated_answer);
	//make sure that the answer provided is the same as the answer computed
	ret = compare_answer(buf, formated_answer);
	if (ret==0){
		printf("expecting: '%s', but instead got: '%s'\n", answer_copy, bufcopy);
	}
	//free all the memory
	osc_bundle_u_free(bndl);
	if(ser_bundle){
		osc_mem_free(ser_bundle);
	}
	if(buf){
		osc_mem_free(buf);
	}
	osc_expr_free(f);
	if(functiongraph){
		osc_mem_free(functiongraph);
	}
	return ret;
}