Update of /cvsroot/pure-data/externals/mrpeach/osc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30531
Modified Files: packOSC.c Log Message: added bufsize message and cleaned up code
Index: packOSC.c =================================================================== RCS file: /cvsroot/pure-data/externals/mrpeach/osc/packOSC.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** packOSC.c 28 May 2007 00:45:58 -0000 1.3 --- packOSC.c 4 Jun 2007 21:18:24 -0000 1.4 *************** *** 232,237 **** } typedArg;
- static char bufferForOSCbuf[SC_BUFFER_SIZE]; - static t_atom bufferForOSClist[SC_BUFFER_SIZE];
static t_class *packOSC_class; --- 232,235 ---- *************** *** 240,249 **** { t_object x_obj; ! t_int x_typetags; // typetag flag ! int x_bundle; // bundle open flag ! OSCbuf x_oscbuf[1]; // OSCbuffer ! t_atom *x_osclist; ! t_outlet *x_bdpthout; // bundle-depth floatoutlet ! t_outlet *x_listout; // OSC packet list ouput } t_packOSC;
--- 238,249 ---- { t_object x_obj; ! t_int x_typetags; /* typetag flag */ ! int x_bundle; /* bundle open flag */ ! OSCbuf x_oscbuf[1]; /* OSCbuffer */ ! t_outlet *x_bdpthout; /* bundle-depth floatoutlet */ ! t_outlet *x_listout; /* OSC packet list ouput */ ! size_t x_buflength; /* number of elements in x_bufferForOSCbuf and x_bufferForOSClist */ ! char *x_bufferForOSCbuf; /*[SC_BUFFER_SIZE];*/ ! t_atom *x_bufferForOSClist; /*[SC_BUFFER_SIZE];*/ } t_packOSC;
*************** *** 251,255 **** static void packOSC_openbundle(t_packOSC *x); static void packOSC_closebundle(t_packOSC *x); ! static void packOSC_settypetags(t_packOSC *x, t_float *f); static void packOSC_sendtyped(t_packOSC *x, t_symbol *s, int argc, t_atom *argv); static void packOSC_send_type_forced(t_packOSC *x, t_symbol *s, int argc, t_atom *argv); --- 251,256 ---- static void packOSC_openbundle(t_packOSC *x); static void packOSC_closebundle(t_packOSC *x); ! static void packOSC_settypetags(t_packOSC *x, t_floatarg f); ! static void packOSC_setbufsize(t_packOSC *x, t_floatarg f); static void packOSC_sendtyped(t_packOSC *x, t_symbol *s, int argc, t_atom *argv); static void packOSC_send_type_forced(t_packOSC *x, t_symbol *s, int argc, t_atom *argv); *************** *** 266,275 **** { t_packOSC *x = (t_packOSC *)pd_new(packOSC_class); ! // set typetags to 1 by default ! x->x_typetags = 1; ! // bundle is closed ! x->x_bundle = 0; ! OSC_initBuffer(x->x_oscbuf, SC_BUFFER_SIZE, bufferForOSCbuf); ! x->x_osclist = bufferForOSClist; x->x_listout = outlet_new(&x->x_obj, &s_list); x->x_bdpthout = outlet_new(&x->x_obj, &s_float); --- 267,281 ---- { t_packOSC *x = (t_packOSC *)pd_new(packOSC_class); ! x->x_typetags = 1; /* set typetags to 1 by default */ ! x->x_bundle = 0; /* bundle is closed */ ! x->x_buflength = SC_BUFFER_SIZE; ! x->x_bufferForOSCbuf = (char *)getbytes(sizeof(char)*x->x_buflength); ! if(x->x_bufferForOSCbuf == NULL) ! error("packOSC: unable to allocate %lu bytes for x_bufferForOSCbuf", sizeof(char)*x->x_buflength); ! x->x_bufferForOSClist = (t_atom *)getbytes(sizeof(t_atom)*x->x_buflength); ! if(x->x_bufferForOSClist == NULL) ! error("packOSC: unable to allocate %lu bytes for x_bufferForOSClist", sizeof(t_atom)*x->x_buflength); ! if (x->x_oscbuf != NULL) ! OSC_initBuffer(x->x_oscbuf, x->x_buflength, x->x_bufferForOSCbuf); x->x_listout = outlet_new(&x->x_obj, &s_list); x->x_bdpthout = outlet_new(&x->x_obj, &s_float); *************** *** 298,306 **** } outlet_float(x->x_bdpthout, (float)x->x_oscbuf->bundleDepth); ! // in bundle mode we send when bundle is closed? if(!OSC_isBufferEmpty(x->x_oscbuf) > 0 && OSC_isBufferDone(x->x_oscbuf)) { packOSC_sendbuffer(x); ! OSC_initBuffer(x->x_oscbuf, SC_BUFFER_SIZE, bufferForOSCbuf); x->x_bundle = 0; return; --- 304,312 ---- } outlet_float(x->x_bdpthout, (float)x->x_oscbuf->bundleDepth); ! /* in bundle mode we send when bundle is closed */ if(!OSC_isBufferEmpty(x->x_oscbuf) > 0 && OSC_isBufferDone(x->x_oscbuf)) { packOSC_sendbuffer(x); ! OSC_initBuffer(x->x_oscbuf, x->x_buflength, x->x_bufferForOSCbuf); x->x_bundle = 0; return; *************** *** 308,327 **** }
! static void packOSC_settypetags(t_packOSC *x, t_float *f) { x->x_typetags = (f != 0)?1:0; ! post("packOSC: setting typetags %d",x->x_typetags); }
! ////////////////////////////////////////////////////////////////////// ! // this is the real and only sending routine now, for both typed and ! // undtyped mode.
static void packOSC_sendtyped(t_packOSC *x, t_symbol *s, int argc, t_atom *argv) { char messageName[MAXPDSTRING]; ! unsigned int nTypeTags = 0, typeStrTotalSize; unsigned int argsSize = sizeof(typedArg)*argc; char* typeStr = NULL; /* might not be used */ --- 314,347 ---- }
! static void packOSC_settypetags(t_packOSC *x, t_floatarg f) { x->x_typetags = (f != 0)?1:0; ! post("packOSC: setting typetags %d", x->x_typetags); }
+ static void packOSC_setbufsize(t_packOSC *x, t_floatarg f) + { + if (x->x_bufferForOSCbuf != NULL) freebytes((void *)x->x_bufferForOSCbuf, sizeof(char)*x->x_buflength); + if (x->x_bufferForOSClist != NULL) freebytes((void *)x->x_bufferForOSClist, sizeof(t_atom)*x->x_buflength); + post("packOSC: bufsize arg is %f (%lu)", f, (long)f); + x->x_buflength = (long)f; + x->x_bufferForOSCbuf = (char *)getbytes(sizeof(char)*x->x_buflength); + if(x->x_bufferForOSCbuf == NULL) + error("packOSC unable to allocate %lu bytes for x_bufferForOSCbuf", sizeof(char)*x->x_buflength); + x->x_bufferForOSClist = (t_atom *)getbytes(sizeof(t_atom)*x->x_buflength); + if(x->x_bufferForOSClist == NULL) + error("packOSC unable to allocate %lu bytes for x_bufferForOSClist", sizeof(t_atom)*x->x_buflength); + OSC_initBuffer(x->x_oscbuf, x->x_buflength, x->x_bufferForOSCbuf); + post("packOSC: bufsize is now %d",x->x_buflength); + }
! /* this is the real and only sending routine now, for both typed and */ ! /* undtyped mode. */
static void packOSC_sendtyped(t_packOSC *x, t_symbol *s, int argc, t_atom *argv) { char messageName[MAXPDSTRING]; ! unsigned int nTypeTags = 0, typeStrTotalSize = 0; unsigned int argsSize = sizeof(typedArg)*argc; char* typeStr = NULL; /* might not be used */ *************** *** 336,340 **** return; } ! messageName[0] = '\0'; // empty
atom_string(&argv[0], messageName, MAXPDSTRING); /* the OSC address string */ --- 356,360 ---- return; } ! messageName[0] = '\0'; /* empty */
atom_string(&argv[0], messageName, MAXPDSTRING); /* the OSC address string */ *************** *** 419,423 **** { packOSC_sendbuffer(x); ! OSC_initBuffer(x->x_oscbuf, SC_BUFFER_SIZE, bufferForOSCbuf); }
--- 439,443 ---- { packOSC_sendbuffer(x); ! OSC_initBuffer(x->x_oscbuf, x->x_buflength, x->x_bufferForOSCbuf); }
*************** *** 446,449 **** --- 466,471 ---- static void packOSC_free(t_packOSC *x) { + if (x->x_bufferForOSCbuf != NULL) freebytes((void *)x->x_bufferForOSCbuf, sizeof(char)*x->x_buflength); + if (x->x_bufferForOSClist != NULL) freebytes((void *)x->x_bufferForOSClist, sizeof(t_atom)*x->x_buflength); }
*************** *** 454,458 **** sizeof(t_packOSC), 0, A_DEFFLOAT, 0); class_addmethod(packOSC_class, (t_method)packOSC_settypetags, ! gensym("typetags"), A_FLOAT, 0); class_addmethod(packOSC_class, (t_method)packOSC_send, gensym("send"), A_GIMME, 0); --- 476,482 ---- sizeof(t_packOSC), 0, A_DEFFLOAT, 0); class_addmethod(packOSC_class, (t_method)packOSC_settypetags, ! gensym("typetags"), A_DEFFLOAT, 0); ! class_addmethod(packOSC_class, (t_method)packOSC_setbufsize, ! gensym("bufsize"), A_DEFFLOAT, 0); class_addmethod(packOSC_class, (t_method)packOSC_send, gensym("send"), A_GIMME, 0); *************** *** 486,490 **** i = atom_getint(a); if (f == (t_float)i) ! { // assume that if the int and float are the same, it's an int returnVal.type = INT_osc; returnVal.datum.i = i; --- 510,514 ---- i = atom_getint(a); if (f == (t_float)i) ! { /* assume that if the int and float are the same, it's an int */ returnVal.type = INT_osc; returnVal.datum.i = i; *************** *** 602,606 **** }
! static int packOSC_writetypedmessage(t_packOSC *x, OSCbuf *buf, char *messageName, int numArgs, typedArg *args, char *typeStr) { int i, j, returnVal = OSC_writeAddressAndTypes(buf, messageName, typeStr); --- 626,631 ---- }
! static int packOSC_writetypedmessage ! (t_packOSC *x, OSCbuf *buf, char *messageName, int numArgs, typedArg *args, char *typeStr) { int i, j, returnVal = OSC_writeAddressAndTypes(buf, messageName, typeStr); *************** *** 709,713 **** break; default: ! break; // just skip bad types (which we won't get anyway unless this code is buggy) } } --- 734,738 ---- break; default: ! break; /* just skip bad types (which we won't get anyway unless this code is buggy) */ } } *************** *** 732,746 **** { post("packOSC_sendbuffer() called but buffer not ready!, not exiting"); ! return; //{{raf}} } length = OSC_packetSize(x->x_oscbuf); ! buf = OSC_getPacket(x->x_oscbuf); #ifdef DEBUG post ("packOSC_sendbuffer: length: %lu", length); #endif /* convert the bytes in the buffer to floats in a list */ ! for (i = 0; i < length; ++i) SETFLOAT(&x->x_osclist[i], buf[i]); /* send the list out the outlet */ ! outlet_list(x->x_listout, &s_list, length, x->x_osclist); }
--- 757,771 ---- { post("packOSC_sendbuffer() called but buffer not ready!, not exiting"); ! return; } length = OSC_packetSize(x->x_oscbuf); ! buf = (unsigned char *)OSC_getPacket(x->x_oscbuf); #ifdef DEBUG post ("packOSC_sendbuffer: length: %lu", length); #endif /* convert the bytes in the buffer to floats in a list */ ! for (i = 0; i < length; ++i) SETFLOAT(&x->x_bufferForOSClist[i], buf[i]); /* send the list out the outlet */ ! outlet_list(x->x_listout, &s_list, length, x->x_bufferForOSClist); }
*************** *** 982,985 **** --- 1007,1011 ---- int4byte paddedLength;
+ if (buf == NULL) return 10; if (CheckTypeTag(buf, '\0')) return 9;
*************** *** 1107,1111 **** { int len = OSC_strlen(string) + 1; /* We need space for the null char. */ ! /* Round up len to next multiple of STRING_ALIGN_PAD to account for alignment padding */ if ((len % STRING_ALIGN_PAD) != 0) --- 1133,1137 ---- { int len = OSC_strlen(string) + 1; /* We need space for the null char. */ ! /* Round up len to next multiple of STRING_ALIGN_PAD to account for alignment padding */ if ((len % STRING_ALIGN_PAD) != 0) *************** *** 1119,1125 **** { int i; ! for (i = 0; str[i] != '\0'; i++) dest[i] = str[i]; ! return OSC_WritePadding(dest, i); } --- 1145,1151 ---- { int i; ! for (i = 0; str[i] != '\0'; i++) dest[i] = str[i]; ! return OSC_WritePadding(dest, i); } *************** *** 1128,1132 **** { int i; ! dest[0] = ','; for (i = 0; str[i] != '\0'; i++) dest[i+1] = str[i]; --- 1154,1158 ---- { int i; ! dest[0] = ','; for (i = 0; str[i] != '\0'; i++) dest[i+1] = str[i];