[PD-cvs] externals/mrpeach/osc packOSC-help.pd, 1.6, 1.7 packOSC.c, 1.6, 1.7 unpackOSC.c, 1.3, 1.4 routeOSC-help.pd, 1.2, 1.3

Martin Peach mrpeach at users.sourceforge.net
Wed Jul 11 19:34:40 CEST 2007


Update of /cvsroot/pure-data/externals/mrpeach/osc
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5352

Modified Files:
	packOSC-help.pd packOSC.c unpackOSC.c routeOSC-help.pd 
Log Message:
unpackOSC now simply outputs (through the right outlet) a delay in milliseconds when it 
receives a timetag, as the timetag itself is not useable inside pd.
The delay is zero when the timetag is in the past.
Help patches have been updated to match.
Also corrected a mistake in packOSC.c timetag calculation.



Index: packOSC.c
===================================================================
RCS file: /cvsroot/pure-data/externals/mrpeach/osc/packOSC.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** packOSC.c	5 Jul 2007 19:08:53 -0000	1.6
--- packOSC.c	11 Jul 2007 17:34:38 -0000	1.7
***************
*** 1282,1286 ****
          (unsigned) offset/onemillion;
      /* Now get the fractional part. */
!     tt.fraction = ((unsigned) tv.tv_usec + (unsigned)(offset%onemillion)) * (unsigned) TWO_TO_THE_32_OVER_ONE_MILLION;
      if (tt.fraction > onemillion)
      {
--- 1282,1286 ----
          (unsigned) offset/onemillion;
      /* Now get the fractional part. */
!     tt.fraction = (unsigned) tv.tv_usec + (unsigned)(offset%onemillion); /* in usec */
      if (tt.fraction > onemillion)
      {
***************
*** 1288,1291 ****
--- 1288,1292 ----
          tt.seconds++;
      }
+     tt.fraction *= (unsigned) TWO_TO_THE_32_OVER_ONE_MILLION; /* convert usec to 32-bit fraction of 1 sec */
      return tt;
  }

Index: packOSC-help.pd
===================================================================
RCS file: /cvsroot/pure-data/externals/mrpeach/osc/packOSC-help.pd,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** packOSC-help.pd	5 Jul 2007 19:08:53 -0000	1.6
--- packOSC-help.pd	11 Jul 2007 17:34:38 -0000	1.7
***************
*** 1,6 ****
! #N canvas 0 366 1064 453 12;
  #X obj 72 393 udpsend;
! #X msg 373 359 disconnect;
! #X msg 161 359 connect 127.0.0.1 9997;
  #X obj 72 296 packOSC;
  #X obj 72 428 tgl 15 0 empty empty 1=connected 20 8 0 8 -262144 -1
--- 1,6 ----
! #N canvas 0 430 1064 453 12;
  #X obj 72 393 udpsend;
! #X msg 102 368 disconnect;
! #X msg 80 345 connect 127.0.0.1 9997;
  #X obj 72 296 packOSC;
  #X obj 72 428 tgl 15 0 empty empty 1=connected 20 8 0 8 -262144 -1
***************
*** 15,38 ****
  #X text 299 2 send a type-guessed message;
  #X text 596 201 send a type-forced message;
! #X obj 652 417 routeOSC;
! #X text 573 417 see also:;
! #X msg 121 264 typetags \$1;
! #X obj 121 247 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
  1;
! #X text 228 264 typetags are on by default;
! #X text 670 223 Useable types are:;
! #X text 670 241 i: 32 bit integer;
! #X text 670 259 f: 32-bit float;
! #X text 670 277 s: string;
  #X text 539 26 send a type-forced message;
  #X msg 164 27 sendtyped /test/one/two/three sis zz 88 T;
  #X msg 112 202 sendtyped /left/right TTiTIFNfisf 1.1 2.1 3.1 4.1 5.1
  ;
! #X text 670 295 T: true (no argument);
! #X text 670 313 F: false (no argument);
! #X text 670 331 I: infinitum (no argument);
! #X obj 72 323 list prepend send;
! #X obj 72 349 list trim;
! #X text 670 348 N: Nil (no argument);
  #X msg 115 225 bufsize 100;
  #X text 221 226 set buffer size (default is 64000 bytes);
--- 15,36 ----
  #X text 299 2 send a type-guessed message;
  #X text 596 201 send a type-forced message;
! #X obj 387 381 routeOSC;
! #X text 308 380 see also:;
! #X msg 242 264 typetags \$1;
! #X obj 242 247 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
  1;
! #X text 349 264 typetags are on by default;
! #X text 722 218 Useable types are:;
! #X text 722 236 i: 32 bit integer;
! #X text 722 254 f: 32-bit float;
! #X text 722 272 s: string;
  #X text 539 26 send a type-forced message;
  #X msg 164 27 sendtyped /test/one/two/three sis zz 88 T;
  #X msg 112 202 sendtyped /left/right TTiTIFNfisf 1.1 2.1 3.1 4.1 5.1
  ;
! #X text 722 290 T: true (no argument);
! #X text 722 308 F: false (no argument);
! #X text 722 326 I: infinitum (no argument);
! #X text 722 343 N: Nil (no argument);
  #X msg 115 225 bufsize 100;
  #X text 221 226 set buffer size (default is 64000 bytes);
***************
*** 44,48 ****
  #X msg -37 105 [;
  #X msg -95 129 ];
- #X text 270 421 2007/07/05 Martin Peach;
  #X text 8 104 open a bundle;
  #X text -55 128 close bundle;
--- 42,45 ----
***************
*** 50,63 ****
  #X msg 464 130 timetagoffset -1;
  #X text 602 110 send current time as timetag;
- #X msg 472 149 timetagoffset 1e+07;
  #X text 494 169 (timetags are sent in bundle messages only);
- #X text 680 148 current time plus 10 seconds;
  #X obj -95 71 t b a b;
  #X msg -95 48 /test 5 6 7;
  #X text 615 129 immediate time tag (default);
  #X connect 0 0 4 0;
  #X connect 1 0 0 0;
  #X connect 2 0 0 0;
! #X connect 3 0 28 0;
  #X connect 5 0 3 0;
  #X connect 6 0 3 0;
--- 47,68 ----
  #X msg 464 130 timetagoffset -1;
  #X text 602 110 send current time as timetag;
  #X text 494 169 (timetags are sent in bundle messages only);
  #X obj -95 71 t b a b;
  #X msg -95 48 /test 5 6 7;
  #X text 615 129 immediate time tag (default);
+ #X floatatom 130 323 5 0 0 0 - - -;
+ #X text 180 323 bundle depth;
+ #X obj 294 340 cnv 15 380 30 empty empty empty 20 12 0 14 -24198 -66577
+ 0;
+ #X text 270 421 2007/07/11 Martin Peach;
+ #X text 469 380 and http://opensoundcontrol.org/cnmat;
+ #X text 653 148 current time plus 1 second;
+ #X msg 472 149 timetagoffset 1e+06;
+ #X text 298 347 <- First open routeOSC-help \, then connect;
  #X connect 0 0 4 0;
  #X connect 1 0 0 0;
  #X connect 2 0 0 0;
! #X connect 3 0 0 0;
! #X connect 3 1 47 0;
  #X connect 5 0 3 0;
  #X connect 6 0 3 0;
***************
*** 69,85 ****
  #X connect 23 0 3 0;
  #X connect 24 0 3 0;
! #X connect 28 0 29 0;
! #X connect 29 0 0 0;
  #X connect 31 0 3 0;
  #X connect 33 0 3 0;
! #X connect 35 0 3 0;
  #X connect 36 0 3 0;
! #X connect 38 0 3 0;
! #X connect 39 0 3 0;
! #X connect 43 0 3 0;
! #X connect 44 0 3 0;
! #X connect 46 0 3 0;
! #X connect 49 0 39 0;
! #X connect 49 1 3 0;
! #X connect 49 2 38 0;
! #X connect 50 0 49 0;
--- 74,88 ----
  #X connect 23 0 3 0;
  #X connect 24 0 3 0;
! #X connect 29 0 3 0;
  #X connect 31 0 3 0;
  #X connect 33 0 3 0;
! #X connect 34 0 3 0;
  #X connect 36 0 3 0;
! #X connect 37 0 3 0;
! #X connect 40 0 3 0;
! #X connect 41 0 3 0;
! #X connect 44 0 37 0;
! #X connect 44 1 3 0;
! #X connect 44 2 36 0;
! #X connect 45 0 44 0;
! #X connect 53 0 3 0;

Index: routeOSC-help.pd
===================================================================
RCS file: /cvsroot/pure-data/externals/mrpeach/osc/routeOSC-help.pd,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** routeOSC-help.pd	5 Jul 2007 19:08:53 -0000	1.2
--- routeOSC-help.pd	11 Jul 2007 17:34:38 -0000	1.3
***************
*** 1,27 ****
! #N canvas 0 0 623 272 12;
! #X obj 58 69 udpreceive 9997;
! #X obj 188 97 unpack 0 0 0 0;
! #X floatatom 188 128 3 0 0 0 - - -;
! #X floatatom 228 128 3 0 0 0 - - -;
! #X floatatom 268 128 3 0 0 0 - - -;
! #X floatatom 309 128 3 0 0 0 - - -;
! #X text 148 127 from;
! #X obj 58 97 unpackOSC;
! #X obj 58 147 print;
! #X obj 70 206 routeOSC /test /west;
! #X obj 70 241 print a;
! #X obj 157 241 print b;
! #X obj 245 241 print c;
! #X msg 76 175 set /left;
! #X msg 193 175 set /left /right;
  #X text 10 7 routeOSC;
  #X text 10 25 accepts lists of floats that are interpreted as OSC packets
  ;
  #X text 10 43 set message reassigns outputs;
! #X text 258 205 arguments are OSC addresses to route;
! #X obj 134 147 print timetag;
! #X text 329 244 2007/07/05 Martin Peach;
! #X text 423 121 see also:;
! #X obj 502 121 packOSC;
  #X connect 0 0 7 0;
  #X connect 0 1 1 0;
--- 1,31 ----
! #N canvas 0 0 641 324 12;
! #X obj 25 64 udpreceive 9997;
! #X obj 155 116 unpack 0 0 0 0;
! #X floatatom 155 147 3 0 0 0 - - -;
! #X floatatom 195 147 3 0 0 0 - - -;
! #X floatatom 235 147 3 0 0 0 - - -;
! #X floatatom 276 147 3 0 0 0 - - -;
! #X text 115 146 from;
! #X obj 25 116 unpackOSC;
! #X obj 35 142 print;
! #X obj 25 262 routeOSC /test /west;
! #X obj 25 297 print a;
! #X obj 112 297 print b;
! #X obj 200 297 print c;
! #X msg 31 231 set /left;
! #X msg 148 231 set /left /right;
  #X text 10 7 routeOSC;
  #X text 10 25 accepts lists of floats that are interpreted as OSC packets
  ;
  #X text 10 43 set message reassigns outputs;
! #X text 213 261 arguments are OSC addresses to route;
! #X text 390 140 see also:;
! #X obj 469 140 packOSC;
! #X text 284 300 2007/07/11 Martin Peach;
! #X obj 43 185 delay 0;
! #X obj 43 206 bng 15 250 50 0 empty empty sync 17 7 0 10 -24198 -258699
! -1;
! #X obj 43 164 b;
! #X floatatom 118 185 10 0 0 1 ms_delay - -;
  #X connect 0 0 7 0;
  #X connect 0 1 1 0;
***************
*** 32,36 ****
  #X connect 7 0 8 0;
  #X connect 7 0 9 0;
! #X connect 7 1 19 0;
  #X connect 9 0 10 0;
  #X connect 9 1 11 0;
--- 36,42 ----
  #X connect 7 0 8 0;
  #X connect 7 0 9 0;
! #X connect 7 0 24 0;
! #X connect 7 1 22 1;
! #X connect 7 1 25 0;
  #X connect 9 0 10 0;
  #X connect 9 1 11 0;
***************
*** 38,39 ****
--- 44,47 ----
  #X connect 13 0 9 0;
  #X connect 14 0 9 0;
+ #X connect 22 0 23 0;
+ #X connect 24 0 22 0;

Index: unpackOSC.c
===================================================================
RCS file: /cvsroot/pure-data/externals/mrpeach/osc/unpackOSC.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** unpackOSC.c	5 Jul 2007 19:08:53 -0000	1.3
--- unpackOSC.c	11 Jul 2007 17:34:38 -0000	1.4
***************
*** 34,38 ****
  */
  
- 
  /*
  
--- 34,37 ----
***************
*** 76,88 ****
  #include "m_pd.h"
  
! #ifdef _WIN32
      #include <string.h>
      #include <stdlib.h>
      #include <winsock2.h>
-     #include <stdio.h>
  #else
-     #include <stdio.h>
-     #include <string.h>
-     #include <stdlib.h>
      #include <sys/types.h>
      #include <netinet/in.h>
--- 75,85 ----
  #include "m_pd.h"
  
!     #include <stdio.h>
      #include <string.h>
      #include <stdlib.h>
+     #include <sys/time.h>
+ #ifdef _WIN32
      #include <winsock2.h>
  #else
      #include <sys/types.h>
      #include <netinet/in.h>
***************
*** 97,105 ****
  #endif
  
! #define MAX_MESG 65536 // was 32768 MP: make same as MAX_UDP_PACKET
  
  /* ----------------------------- was dumpOSC ------------------------- */
  
! #define MAX_PATH_AT 50 // maximum nuber of elements in OSC path
  
  static t_class *unpackOSC_class;
--- 94,113 ----
  #endif
  
! #define MAX_MESG 65536
! /* MAX_MESG was 32768 MP: make same as MAX_UDP_PACKET */
  
  /* ----------------------------- was dumpOSC ------------------------- */
  
! #define MAX_PATH_AT 50
! /* MAX_PATH_AT = maximum number of elements in OSC path */
! 
! /* You may have to redefine this typedef if ints on your system
!   aren't 4 bytes. */
! typedef unsigned int uint4;
! typedef struct
! {
!     uint4 seconds;
!     uint4 fraction;
! } OSCTimeTag;
  
  static t_class *unpackOSC_class;
***************
*** 107,118 ****
  typedef struct _unpackOSC
  {
!     t_object x_obj;
!     t_outlet *x_data_out;
!     t_outlet *x_timetag_out;
!     t_atom   x_timetag[4];// timetag as four floats
!     t_atom   x_data_at[MAX_MESG];// symbols making up the path + payload
!     int      x_data_atc;// number of symbols to be output
!     char     x_raw[MAX_MESG];// bytes making up the entire OSC message
!     int      x_raw_c;// number of bytes in OSC message
  } t_unpackOSC;
  
--- 115,125 ----
  typedef struct _unpackOSC
  {
!     t_object    x_obj;
!     t_outlet    *x_data_out;
!     t_outlet    *x_delay_out;
!     t_atom      x_data_at[MAX_MESG];/* symbols making up the path + payload */
!     int         x_data_atc;/* number of symbols to be output */
!     char        x_raw[MAX_MESG];/* bytes making up the entire OSC message */
!     int         x_raw_c;/* number of bytes in OSC message */
  } t_unpackOSC;
  
***************
*** 120,124 ****
  static void *unpackOSC_new(void);
  static void unpackOSC_free(t_unpackOSC *x);
- void unpackOSC_setup(void);
  static void unpackOSC_list(t_unpackOSC *x, t_symbol *s, int argc, t_atom *argv);
  static int unpackOSC_path(t_unpackOSC *x, char *path);
--- 127,130 ----
***************
*** 128,131 ****
--- 134,138 ----
  static char *unpackOSC_DataAfterAlignedString(char *string, char *boundary);
  static int unpackOSC_IsNiceString(char *string, char *boundary);
+ static t_float unpackOSC_DeltaTime(OSCTimeTag tt);
  
  static void *unpackOSC_new(void)
***************
*** 135,139 ****
      x = (t_unpackOSC *)pd_new(unpackOSC_class);
      x->x_data_out = outlet_new(&x->x_obj, &s_list);
!     x->x_timetag_out = outlet_new(&x->x_obj, &s_list);
      x->x_raw_c = x->x_data_atc = 0;
      return (x);
--- 142,146 ----
      x = (t_unpackOSC *)pd_new(unpackOSC_class);
      x->x_data_out = outlet_new(&x->x_obj, &s_list);
!     x->x_delay_out = outlet_new(&x->x_obj, &s_float);
      x->x_raw_c = x->x_data_atc = 0;
      return (x);
***************
*** 155,163 ****
  static void unpackOSC_list(t_unpackOSC *x, t_symbol *s, int argc, t_atom *argv) 
  {
!     int size, messageLen, i, j;
!     char *messageName, *args, *buf;
!     unsigned long timetag_s;
!     unsigned long timetag_ms;
!     unsigned short timetag[4];
  
      if ((argc%4) != 0)
--- 162,168 ----
  static void unpackOSC_list(t_unpackOSC *x, t_symbol *s, int argc, t_atom *argv) 
  {
!     int             size, messageLen, i, j;
!     char            *messageName, *args, *buf;
!     OSCTimeTag      tt;
  
      if ((argc%4) != 0)
***************
*** 172,178 ****
          {
              j = (int)argv[i].a_w.w_float;
! //          if ((j == argv[i].a_w.w_float) && (j >= 0) && (j <= 255))
! // this can miss bytes between 128 and 255 because they are interpreted somewhere as negative
! // , so change to this:
              if ((j == argv[i].a_w.w_float) && (j >= -128) && (j <= 255))
              {
--- 177,183 ----
          {
              j = (int)argv[i].a_w.w_float;
! /*          if ((j == argv[i].a_w.w_float) && (j >= 0) && (j <= 255)) */
! /* this can miss bytes between 128 and 255 because they are interpreted somewhere as negative */
! /* , so change to this: */
              if ((j == argv[i].a_w.w_float) && (j >= -128) && (j <= 255))
              {
***************
*** 211,223 ****
              ntohl(*((unsigned long *)(buf+12))));
  #endif
! /* split the timetag into 4 16-bit fragments so we can output them as floats */
!         timetag_s = ntohl(*((unsigned long *)(buf+8)));
!         timetag_ms = ntohl(*((unsigned long *)(buf+12)));
!         timetag[0] = (short)(timetag_s>>8);
!         timetag[1] = (short)(timetag_s & 0xFFFF);
!         timetag[2] = (short)(timetag_ms>>8);
!         timetag[3] = (short)(timetag_ms & 0xFFFF);
!         for (i = 0; i < 4; ++i) SETFLOAT(&x->x_timetag[i], (float)timetag[i]);
!         outlet_list(x->x_timetag_out, &s_list, 4, x->x_timetag);
          /* Note: if we wanted to actually use the time tag as a little-endian
            64-bit int, we'd have to word-swap the two 32-bit halves of it */
--- 216,224 ----
              ntohl(*((unsigned long *)(buf+12))));
  #endif
! /* convert the timetag into a millisecond delay from now */
!         tt.seconds = ntohl(*((unsigned long *)(buf+8)));
!         tt.fraction = ntohl(*((unsigned long *)(buf+12)));
!         /* pd can use a delay in milliseconds */
!         outlet_float(x->x_delay_out, unpackOSC_DeltaTime(tt));
          /* Note: if we wanted to actually use the time tag as a little-endian
            64-bit int, we'd have to word-swap the two 32-bit halves of it */
***************
*** 491,495 ****
          else
          {
!             // unhandled .. ;)
  #ifdef DEBUG
              post("unpackOSC: indeterminate type: 0x%x xx", ints[i]);
--- 492,496 ----
          else
          {
!             /* unhandled .. ;) */
  #ifdef DEBUG
              post("unpackOSC: indeterminate type: 0x%x xx", ints[i]);
***************
*** 581,583 ****
--- 582,612 ----
  }
  
+ #define SECONDS_FROM_1900_to_1970 2208988800LL /* 17 leap years */
+ #define TWO_TO_THE_32_OVER_ONE_MILLION 4295LL
+ #define ONE_MILLION_OVER_TWO_TO_THE_32 0.00023283064365386963
+ 
+ /* return the time difference in milliseconds between an OSC timetag and now */
+ static t_float unpackOSC_DeltaTime(OSCTimeTag tt)
+ {
+     OSCTimeTag ttnow;
+     struct timeval tv;
+     struct timezone tz;
+     static double onemillion = 1000000.0f;
+     double  ttusec, nowusec, delta;
+ 
+     if (tt.fraction == 1 && tt.seconds == 0) return 0.0; /* immediate */
+     gettimeofday(&tv, &tz); /* find now */
+     /* First get the seconds right */
+     ttnow.seconds = (unsigned) SECONDS_FROM_1900_to_1970 +
+         (unsigned) tv.tv_sec -
+         (unsigned) 60 * tz.tz_minuteswest +
+         (unsigned) (tz.tz_dsttime ? 3600 : 0);
+     /* find usec in tt */
+     ttusec = tt.seconds*onemillion + ONE_MILLION_OVER_TWO_TO_THE_32*tt.fraction;
+     nowusec = ttnow.seconds*onemillion + tv.tv_usec;
+     /* subtract now from tt to get delta time */
+     if (ttusec < nowusec) return 0.0;
+     delta = ttusec - nowusec;
+     return (float)(delta*0.001f);
+ }
  /* end of unpackOSC.c */





More information about the Pd-cvs mailing list