[PD-cvs] externals/mrpeach/osc packOSC.c,1.4,1.5

Martin Peach mrpeach at users.sourceforge.net
Wed Jun 20 22:28:07 CEST 2007


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

Modified Files:
	packOSC.c 
Log Message:
Implemented IOhannes' prefix and anything methods.


Index: packOSC.c
===================================================================
RCS file: /cvsroot/pure-data/externals/mrpeach/osc/packOSC.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** packOSC.c	4 Jun 2007 21:18:24 -0000	1.4
--- packOSC.c	20 Jun 2007 20:28:05 -0000	1.5
***************
*** 3,6 ****
--- 3,7 ----
  /* Started by Martin Peach 20060403 */
  /* 20060425 version independent of libOSC */
+ /* 20070620 added packOSC_path and packOSC_anything methods by zmoelnig */
  /* packOSC.c makes extensive use of code from OSC-client.c and sendOSC.c */
  /* as well as some from OSC-timetag.c. These files have the following header: */
***************
*** 246,252 ****
--- 247,255 ----
      char        *x_bufferForOSCbuf; /*[SC_BUFFER_SIZE];*/
      t_atom      *x_bufferForOSClist; /*[SC_BUFFER_SIZE];*/
+     char        *x_prefix;
  } t_packOSC;
  
  static void *packOSC_new(t_floatarg udpflag);
+ static void packOSC_path(t_packOSC *x, t_symbol*s);
  static void packOSC_openbundle(t_packOSC *x);
  static void packOSC_closebundle(t_packOSC *x);
***************
*** 256,259 ****
--- 259,263 ----
  static void packOSC_send_type_forced(t_packOSC *x, t_symbol *s, int argc, t_atom *argv);
  static void packOSC_send(t_packOSC *x, t_symbol *s, int argc, t_atom *argv);
+ static void packOSC_anything(t_packOSC *x, t_symbol *s, int argc, t_atom *argv);
  static void packOSC_free(t_packOSC *x);
  void packOSC_setup(void);
***************
*** 283,286 ****
--- 287,305 ----
  }
  
+ static void packOSC_path(t_packOSC *x, t_symbol*s)
+ {
+ /* Set a default prefix to the OSC path */
+     if(s == gensym(""))
+     {
+         x->x_prefix = 0;
+         return;
+     }
+     if ((*s->s_name) != '/')
+     {
+         pd_error(x, "packOSC: bad path: '%s'", s->s_name);
+         return;
+     }
+     x->x_prefix = s->s_name;
+ }
  
  static void packOSC_openbundle(t_packOSC *x)
***************
*** 357,362 ****
      }
      messageName[0] = '\0'; /* empty */
  
-     atom_string(&argv[0], messageName, MAXPDSTRING); /* the OSC address string */
      if (x->x_typetags & 2)
      { /* second arg is typestring */
--- 376,391 ----
      }
      messageName[0] = '\0'; /* empty */
+     if(x->x_prefix) /* if there is a prefix, prefix it to the path */
+     {
+         size_t len = strlen(x->x_prefix);
+         if(len >= MAXPDSTRING)
+         len = MAXPDSTRING-1;
+ 
+         strncpy(messageName, x->x_prefix, MAXPDSTRING);
+         atom_string(&argv[0], messageName+len, MAXPDSTRING-len);
+     }
+     else
+         atom_string(&argv[0], messageName, MAXPDSTRING); /* the OSC address string */
  
      if (x->x_typetags & 2)
      { /* second arg is typestring */
***************
*** 464,467 ****
--- 493,517 ----
  }
  
+ static void packOSC_anything(t_packOSC *x, t_symbol *s, int argc, t_atom *argv)
+ {
+ /* If the message starts with '/', assume it's an OSC path and send it */
+     t_atom*ap = 0;
+ 
+     if ((*s->s_name)!='/')
+     {
+         pd_error(x, "packOSC: bad path: '%s'", s->s_name);
+         return;
+     }
+ 
+     ap = (t_atom*)getbytes((argc+1)*sizeof(t_atom));
+     SETSYMBOL(ap, s);
+     memcpy(ap+1, argv, argc * sizeof(t_atom));
+ 
+     packOSC_send(x, gensym("send"), argc+1, ap);
+ 
+     freebytes(ap, (argc+1)*sizeof(t_atom));
+ 
+ }
+ 
  static void packOSC_free(t_packOSC *x)
  {
***************
*** 475,478 ****
--- 525,530 ----
          (t_method)packOSC_free,
          sizeof(t_packOSC), 0, A_DEFFLOAT, 0);
+     class_addmethod(packOSC_class, (t_method)packOSC_path,
+         gensym("prefix"), A_DEFSYM, 0);
      class_addmethod(packOSC_class, (t_method)packOSC_settypetags,
          gensym("typetags"), A_DEFFLOAT, 0);
***************
*** 489,492 ****
--- 541,545 ----
      class_addmethod(packOSC_class, (t_method)packOSC_closebundle,
          gensym("]"), 0, 0);
+     class_addanything(packOSC_class, (t_method)packOSC_anything);
  }
  





More information about the Pd-cvs mailing list