[PD-cvs] pd/src desire.c,1.1.2.188,1.1.2.189

Mathieu Bouchard matju at users.sourceforge.net
Fri Nov 17 04:26:16 CET 2006


Update of /cvsroot/pure-data/pd/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10456

Modified Files:
      Tag: devel_0_39
	desire.c 
Log Message:
some C++ compatibility


Index: desire.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/Attic/desire.c,v
retrieving revision 1.1.2.188
retrieving revision 1.1.2.189
diff -C2 -d -r1.1.2.188 -r1.1.2.189
*** desire.c	31 Oct 2006 11:30:26 -0000	1.1.2.188
--- desire.c	17 Nov 2006 03:26:12 -0000	1.1.2.189
***************
*** 63,66 ****
--- 63,77 ----
  	for (linetraverser_start(&TRAV,CANVAS); (WIRE=linetraverser_next(&TRAV)); )
  
+ #define CLAMP(_var,_min,_max) do { if (_var<_min) _var=_min; else if (_var>_max) _var=_max; } while(0)
+ #ifdef _cplusplus
+ template <typename T> T MIN(T a, T b) {return a<b?a:b;}
+ template <typename T> T MAX(T a, T b) {return a>b?a:b;}
+ #else
+ #define MIN(a,b) ((a)<(b)?(a):(b))
+ #define MAX(a,b) ((a)>(b)?(a):(b))
+ #endif
+ #define IS_A_FLOAT(atom,index)   ((atom+index)->a_type == A_FLOAT)
+ #define IS_A_SYMBOL(atom,index)  ((atom+index)->a_type == A_SYMBOL)
+ 
  static void postatom2(const char *s, int argc, t_atom *argv);
  int imin(int a, int b) {return a<b?a:b;}
***************
*** 583,588 ****
      }
      x->name = sym;
!     x->x1 = x1; x->y1 = y1; x->gl_obj.te_xpix = px1; x->pixwidth  = px2-px1;
!     x->x2 = x2; x->y2 = y2; x->gl_obj.te_ypix = py1; x->pixheight = py2-py1;
      x->font =  (canvas_getcurrent() ? canvas_getcurrent()->font : sys_defaultfont);
      x->screenx1 = x->screeny1 = 0; x->screenx2 = 450; x->screeny2 = 300;
--- 594,599 ----
      }
      x->name = sym;
!     x->x1 = x1; x->y1 = y1; x->gl_obj.te_xpix = (short)px1; x->pixwidth  = (int)(px2-px1);
!     x->x2 = x2; x->y2 = y2; x->gl_obj.te_ypix = (short)py1; x->pixheight = (int)(py2-py1);
      x->font =  (canvas_getcurrent() ? canvas_getcurrent()->font : sys_defaultfont);
      x->screenx1 = x->screeny1 = 0; x->screenx2 = 450; x->screeny2 = 300;
***************
*** 666,670 ****
  	gobj_unsubscribe((t_gobj *)x,(t_gobj *)manager);
      }
!     x->mapped = f;
  }
  
--- 677,681 ----
  	gobj_unsubscribe((t_gobj *)x,(t_gobj *)manager);
      }
!     x->mapped = (unsigned)f;
  }
  
***************
*** 679,683 ****
      if (f && !x->havewindow) canvas_map(x,1);
      if (!f && x->havewindow) {sys_mgui(x,"delete",""); canvas_map(x,0);}
!     x->havewindow = f;
  }
  
--- 690,694 ----
      if (f && !x->havewindow) canvas_map(x,1);
      if (!f && x->havewindow) {sys_mgui(x,"delete",""); canvas_map(x,0);}
!     x->havewindow = (unsigned)f;
  }
  
***************
*** 1128,1141 ****
  /* just a raw insert, no other business */
  /* doesn't work (why?) */
! static void canvas_insert_nth(t_canvas *x, int n, t_gobj *new) {
      t_gobj **y;
      t_gobj *z;
      canvas_each2(y,x) if (!n) {
  	z = *y;
! 	*y = new;
! 	new->g_next = z;
  	return;
      } else n--;
!     *y = new;
  }
  
--- 1139,1152 ----
  /* just a raw insert, no other business */
  /* doesn't work (why?) */
! static void canvas_insert_nth(t_canvas *x, int n, t_gobj *nu) {
      t_gobj **y;
      t_gobj *z;
      canvas_each2(y,x) if (!n) {
  	z = *y;
! 	*y = nu;
! 	nu->g_next = z;
  	return;
      } else n--;
!     *y = nu;
  }
  
***************
*** 1226,1231 ****
      pd_scanargs(argc,argv,"ffbffffffff",&xperpix,&yperpix,&graphme,
  	&x1,&y1,&x2,&y2,&xpix,&ypix,&xmargin,&ymargin);
!     x->pixwidth = xpix;    x->pixheight = ypix;
!     x->xmargin  = xmargin; x->ymargin   = ymargin;
      yperpix = -yperpix;
      if (xperpix == 0) xperpix = 1;
--- 1237,1242 ----
      pd_scanargs(argc,argv,"ffbffffffff",&xperpix,&yperpix,&graphme,
  	&x1,&y1,&x2,&y2,&xpix,&ypix,&xmargin,&ymargin);
!     x->pixwidth = (int)xpix;    x->pixheight = (int)ypix;
!     x->xmargin  = (int)xmargin; x->ymargin   = (int)ymargin;
      yperpix = -yperpix;
      if (xperpix == 0) xperpix = 1;
***************
*** 1394,1398 ****
  
  void canvas_connect(t_canvas *x, t_floatarg fwhoout, t_floatarg foutlet, t_floatarg fwhoin,t_floatarg finlet) {
!     int i, ifrom=fwhoout, outlet=foutlet, ito=fwhoin, inlet=finlet;
      t_gobj *gfrom=0, *gto=0;
      t_object *from, *to;
--- 1405,1409 ----
  
  void canvas_connect(t_canvas *x, t_floatarg fwhoout, t_floatarg foutlet, t_floatarg fwhoin,t_floatarg finlet) {
!     int i, ifrom=(int)fwhoout, outlet=(int)foutlet, ito=(int)fwhoin, inlet=(int)finlet;
      t_gobj *gfrom=0, *gto=0;
      t_object *from, *to;
***************
*** 1614,1618 ****
  t_garray *graph_array(t_canvas *gl, t_symbol *s, t_symbol *templateargsym,
  t_floatarg fsize, t_floatarg fflags) {
!     int n = fsize, zonset, ztype, saveit;
      t_symbol *zarraytype;
      t_garray *x;
--- 1625,1629 ----
  t_garray *graph_array(t_canvas *gl, t_symbol *s, t_symbol *templateargsym,
  t_floatarg fsize, t_floatarg fflags) {
!     int n = (int)fsize, zonset, ztype, saveit;
      t_symbol *zarraytype;
      t_garray *x;
***************
*** 1620,1624 ****
      t_template *template, *ztemplate;
      t_symbol *templatesym = gensym("pd-_float_array");
!     int flags = fflags;
      int filestyle = ((flags & 6) >> 1);
      int style = filestyle == 0 ? PLOTSTYLE_POLY : filestyle == 1 ? PLOTSTYLE_POINTS : filestyle;
--- 1631,1635 ----
      t_template *template, *ztemplate;
      t_symbol *templatesym = gensym("pd-_float_array");
!     int flags = (int)fflags;
      int filestyle = ((flags & 6) >> 1);
      int style = filestyle == 0 ? PLOTSTYLE_POLY : filestyle == 1 ? PLOTSTYLE_POINTS : filestyle;
***************
*** 1667,1671 ****
      t_canvas *gl;
      t_garray *a;
!     int flags = fflags;
      if (size < 1) size = 1;
      if (otherflag == 0 || !(gl = canvas_findgraph(parent)))
--- 1678,1682 ----
      t_canvas *gl;
      t_garray *a;
!     int flags = (int)fflags;
      if (size < 1) size = 1;
      if (otherflag == 0 || !(gl = canvas_findgraph(parent)))
***************
*** 1682,1686 ****
  void garray_arraydialog(t_garray *x, t_symbol *name, t_floatarg fsize,
  t_floatarg fflags, t_floatarg deleteit) {
!     int flags = fflags;
      int saveit = ((flags & 1) != 0);
      int style = ((flags & 6) >> 1);
--- 1693,1697 ----
  void garray_arraydialog(t_garray *x, t_symbol *name, t_floatarg fsize,
  t_floatarg fflags, t_floatarg deleteit) {
!     int flags = (int)fflags;
      int saveit = ((flags & 1) != 0);
      int style = ((flags & 6) >> 1);
***************
*** 1709,1713 ****
              else if (canvas_isvisible(x->canvas->owner)) gobj_changed(x,0);
          }
!         size = fsize;
          if (size < 1) size = 1;
          if (size != a->n) garray_resize(x, size);
--- 1720,1724 ----
              else if (canvas_isvisible(x->canvas->owner)) gobj_changed(x,0);
          }
!         size = (int)fsize;
          if (size < 1) size = 1;
          if (size != a->n) garray_resize(x, size);
***************
*** 1747,1751 ****
      }
      sys_vgui(".%sArrayWindow.lb delete 0 %d\n", x->realname->s_name, ARRAYPAGESIZE - 1);
!     for (i = page * ARRAYPAGESIZE; (i < (page+1)*ARRAYPAGESIZE && i < a->n); i++)    {
          yval = *(float *)(a->vec + elemsize*i + yonset);
          sys_vgui(".%sArrayWindow.lb insert %d {%d) %g}\n", x->realname->s_name, i%ARRAYPAGESIZE, i, yval);
--- 1758,1762 ----
      }
      sys_vgui(".%sArrayWindow.lb delete 0 %d\n", x->realname->s_name, ARRAYPAGESIZE - 1);
!     for (i = (int)page * ARRAYPAGESIZE; (i < (page+1)*ARRAYPAGESIZE && i < a->n); i++)    {
          yval = *(float *)(a->vec + elemsize*i + yonset);
          sys_vgui(".%sArrayWindow.lb insert %d {%d) %g}\n", x->realname->s_name, i%ARRAYPAGESIZE, i, yval);
***************
*** 1770,1775 ****
  }
  
! static float canvas_xtopixels(t_canvas *x, float xval);
! static float canvas_ytopixels(t_canvas *x, float yval);
  
      /* routine to get screen coordinates of a point in an array */
--- 1781,1786 ----
  }
  
! static int canvas_xtopixels(t_canvas *x, float xval);
! static int canvas_ytopixels(t_canvas *x, float yval);
  
      /* routine to get screen coordinates of a point in an array */
***************
*** 2011,2015 ****
          return;
      }
!     style = template_getfloat(scalartemplate, gensym("style"), x->scalar->sc_vec, 0);
      filestyle = (style == PLOTSTYLE_POINTS ? 1 : (style == PLOTSTYLE_POLY ? 0 : style));
      binbuf_addv(b, "sssisi;", gensym("#X"), gensym("array"),
--- 2022,2026 ----
          return;
      }
!     style = (int)template_getfloat(scalartemplate, gensym("style"), x->scalar->sc_vec, 0);
      filestyle = (style == PLOTSTYLE_POINTS ? 1 : (style == PLOTSTYLE_POLY ? 0 : style));
      binbuf_addv(b, "sssisi;", gensym("#X"), gensym("array"),
***************
*** 2090,2094 ****
          return;
      }
!     npoints = atom_getfloatarg(0,argc--,argv++);
      argv++, argc--;
      svec = (t_float *)getbytes(sizeof(t_float) * argc);
--- 2101,2105 ----
          return;
      }
!     npoints = atom_getintarg(0,argc--,argv++);
      argv++, argc--;
      svec = (t_float *)getbytes(sizeof(t_float) * argc);
***************
*** 2104,2108 ****
          return;
      }
!     npoints = atom_getfloatarg(0,argc--,argv++);
      svec = (t_float *)getbytes(sizeof(t_float) * argc);
      for (i = 0; i < argc; i++) svec[i] = atom_getfloatarg(i, argc, argv);
--- 2115,2119 ----
          return;
      }
!     npoints = atom_getintarg(0,argc--,argv++);
      svec = (t_float *)getbytes(sizeof(t_float) * argc);
      for (i = 0; i < argc; i++) svec[i] = atom_getfloatarg(i, argc, argv);
***************
*** 2137,2141 ****
      if (argc < 2) return;
      else {
!         int firstindex = atom_getfloatarg(0,argc--,argv++);
          if (firstindex < 0) { /* drop negative x values */
              argc += firstindex;
--- 2148,2152 ----
      if (argc < 2) return;
      else {
!         int firstindex = atom_getintarg(0,argc--,argv++);
          if (firstindex < 0) { /* drop negative x values */
              argc += firstindex;
***************
*** 2223,2228 ****
  void garray_resize(t_garray *x, t_floatarg f) {
      t_array *array = garray_getarray(x);
!     int n = f<1?1:f;
!     garray_fittograph(x, n, template_getfloat(
          template_findbyname(x->scalar->sc_template), gensym("style"), x->scalar->sc_vec, 1));
      array_resize_and_redraw(array, n);
--- 2234,2239 ----
  void garray_resize(t_garray *x, t_floatarg f) {
      t_array *array = garray_getarray(x);
!     int n = f<1?1:(int)f;
!     garray_fittograph(x, n, (int)template_getfloat(
          template_findbyname(x->scalar->sc_template), gensym("style"), x->scalar->sc_vec, 1));
      array_resize_and_redraw(array, n);
***************
*** 2502,2508 ****
  
  static void graph_xticks(t_canvas *x, t_floatarg point, t_floatarg inc, t_floatarg f)
! {t_tick *t = &x->xtick; t->point = point; t->inc = inc; t->lperb = f; canvas_redraw(x);}
  static void graph_yticks(t_canvas *x, t_floatarg point, t_floatarg inc, t_floatarg f)
! {t_tick *t = &x->ytick; t->point = point; t->inc = inc; t->lperb = f; canvas_redraw(x);}
  
  static void graph_xlabel(t_canvas *x, t_symbol *s, int argc, t_atom *argv) {
--- 2513,2519 ----
  
  static void graph_xticks(t_canvas *x, t_floatarg point, t_floatarg inc, t_floatarg f)
! {t_tick *t = &x->xtick; t->point = point; t->inc = inc; t->lperb = (int)f; canvas_redraw(x);}
  static void graph_yticks(t_canvas *x, t_floatarg point, t_floatarg inc, t_floatarg f)
! {t_tick *t = &x->ytick; t->point = point; t->inc = inc; t->lperb = (int)f; canvas_redraw(x);}
  
  static void graph_xlabel(t_canvas *x, t_symbol *s, int argc, t_atom *argv) {
***************
*** 2547,2563 ****
  
  /* convert an x coordinate value to an x pixel location in window */
! static float canvas_xtopixels(t_canvas *x, float xval) {
      int x1, y1, x2, y2; float width = x->x2-x->x1;
!     if (!x->isgraph) return (xval-x->x1) / width;
!     if (x->havewindow) return (x->screenx2-x->screenx1) * (xval-x->x1) / width;
      graph_graphrect((t_gobj *)x, x->owner, &x1, &y1, &x2, &y2);
!     return x1 + (x2-x1) * (xval-x->x1) / width;
  }
! static float canvas_ytopixels(t_canvas *x, float yval) {
      int x1, y1, x2, y2; float height = x->y2-x->y1;
!     if (!x->isgraph) return (yval-x->y1) / height;
!     if (x->havewindow) return (x->screeny2-x->screeny1) * (yval-x->y1) / height;
      graph_graphrect((t_gobj *)x, x->owner, &x1, &y1, &x2, &y2);
!     return y1 + (y2-y1) * (yval-x->y1) / height;
  }
  
--- 2558,2574 ----
  
  /* convert an x coordinate value to an x pixel location in window */
! static int canvas_xtopixels(t_canvas *x, float xval) {
      int x1, y1, x2, y2; float width = x->x2-x->x1;
!     if (!x->isgraph) return (int)((xval-x->x1)/width);
!     if (x->havewindow) return (int)((x->screenx2-x->screenx1) * (xval-x->x1) / width);
      graph_graphrect((t_gobj *)x, x->owner, &x1, &y1, &x2, &y2);
!     return (int)(x1 + (x2-x1) * (xval-x->x1) / width);
  }
! static int canvas_ytopixels(t_canvas *x, float yval) {
      int x1, y1, x2, y2; float height = x->y2-x->y1;
!     if (!x->isgraph) return (int)((yval-x->y1)/height);
!     if (x->havewindow) return (int)((x->screeny2-x->screeny1) * (yval-x->y1) / height);
      graph_graphrect((t_gobj *)x, x->owner, &x1, &y1, &x2, &y2);
!     return (int)(y1 + (y2-y1) * (yval-x->y1) / height);
  }
  
***************
*** 2633,2637 ****
              for (i=0,f=x->xtick.point; f<0.99*x->x2+0.01*x->x1; i++, f+=x->xtick.inc) {
                  int tickpix = i%x->xtick.lperb ? 2 : 4;
! 		int x0 = canvas_xtopixels(x, f);
                  sys_vgui(".x%lx.c create line %d %d %d %d -tags %s\n", (long)c, x0, (int)upix, x0, (int)(upix-tickpix), tag);
                  sys_vgui(".x%lx.c create line %d %d %d %d -tags %s\n", (long)c, x0, (int)lpix, x0, (int)(lpix+tickpix), tag);
--- 2644,2648 ----
              for (i=0,f=x->xtick.point; f<0.99*x->x2+0.01*x->x1; i++, f+=x->xtick.inc) {
                  int tickpix = i%x->xtick.lperb ? 2 : 4;
! 		int x0 = (int)canvas_xtopixels(x, f);
                  sys_vgui(".x%lx.c create line %d %d %d %d -tags %s\n", (long)c, x0, (int)upix, x0, (int)(upix-tickpix), tag);
                  sys_vgui(".x%lx.c create line %d %d %d %d -tags %s\n", (long)c, x0, (int)lpix, x0, (int)(lpix+tickpix), tag);
***************
*** 4495,4501 ****
  }
  
- float MIN(float a, float b) {return a<b?a:b;}
- float MAX(float a, float b) {return a>b?a:b;}
- 
  static void slot_setfloat_var(t_slot *fd, t_symbol *s) {
      char *s1, *s2, *s3, strbuf[MAXPDSTRING];
--- 4506,4509 ----
***************
*** 4506,4510 ****
          fd->min = fd->max = fd->scrmin = fd->scrmax = fd->quantum = 0;
      } else {
!         int cpy = MIN(s1-s->s_name,MAXPDSTRING-5), got;
          strncpy(strbuf, s->s_name, cpy);
          strbuf[cpy] = 0;
--- 4514,4518 ----
          fd->min = fd->max = fd->scrmin = fd->scrmax = fd->quantum = 0;
      } else {
!         int cpy = (int)MIN(s1-s->s_name,MAXPDSTRING-5), got;
          strncpy(strbuf, s->s_name, cpy);
          strbuf[cpy] = 0;
***************
*** 4699,4703 ****
  
  static void numbertocolor(int n, char *s) {
!     n = MAX(n,0);
      sprintf(s, "#%2.2x%2.2x%2.2x", rangecolor(n/100), rangecolor((n/10)%10), rangecolor(n%10));
  }
--- 4707,4711 ----
  
  static void numbertocolor(int n, char *s) {
!     n = (int)MAX(n,0);
      sprintf(s, "#%2.2x%2.2x%2.2x", rangecolor(n/100), rangecolor((n/10)%10), rangecolor(n%10));
  }
***************
*** 4722,4728 ****
                  pix[2*i+1] = canvas_ytopixels(canvas, basey + slot_getcoord(f+1, template, data, 1));
              }
!             numbertocolor(slot_getfloat(&x->outlinecolor, template, data, 1), outline);
              if (flags & CLOSED) {
!                 numbertocolor(slot_getfloat(&x->fillcolor, template, data, 1), fill);
                  //sys_vgui(".x%lx.c create polygon\\\n", (long)canvas_getcanvas(canvas));
              } else sys_vgui(".x%lx.c create line\\\n", (long)canvas_getcanvas(canvas));
--- 4730,4736 ----
                  pix[2*i+1] = canvas_ytopixels(canvas, basey + slot_getcoord(f+1, template, data, 1));
              }
!             numbertocolor((int)slot_getfloat(&x->outlinecolor, template, data, 1), outline);
              if (flags & CLOSED) {
!                 numbertocolor((int)slot_getfloat(&x->fillcolor, template, data, 1), fill);
                  //sys_vgui(".x%lx.c create polygon\\\n", (long)canvas_getcanvas(canvas));
              } else sys_vgui(".x%lx.c create line\\\n", (long)canvas_getcanvas(canvas));
***************
*** 4777,4782 ****
      if (!slot_getfloat(&x->vis, template, data, 0)) return 0;
      for (i = 0, f = x->vec; i < n; i++, f += 2) {
!         int xval = slot_getcoord(f  , template, data, 0), xloc = canvas_xtopixels(canvas, basex + xval);
!         int yval = slot_getcoord(f+1, template, data, 0), yloc = canvas_ytopixels(canvas, basey + yval);
          int xerr = iabs(xloc-xpix);
  	int yerr = iabs(yloc-ypix);
--- 4785,4790 ----
      if (!slot_getfloat(&x->vis, template, data, 0)) return 0;
      for (i = 0, f = x->vec; i < n; i++, f += 2) {
!         int xval = (int)slot_getcoord(f  , template, data, 0), xloc = canvas_xtopixels(canvas, basex + xval);
!         int yval = (int)slot_getcoord(f+1, template, data, 0), yloc = canvas_ytopixels(canvas, basey + yval);
          int xerr = iabs(xloc-xpix);
  	int yerr = iabs(yloc-ypix);
***************
*** 4961,4966 ****
  	array_getcoordinate(canvas, &array->vec[i*elemsize], xonset, yonset, wonset,
  		i, basex + xloc, basey + yloc, xinc, xslot, yslot, wslot, &xpix, &ypix, &wpix);
! 	x1=MIN(x1,xpix); y1=MIN(y1,ypix-wpix);
! 	x2=MAX(x2,xpix); y2=MAX(y2,ypix+wpix);
  	if (scalarvis != 0) {
  	    /* check also the drawing instructions for the scalar */ 
--- 4969,4974 ----
  	array_getcoordinate(canvas, &array->vec[i*elemsize], xonset, yonset, wonset,
  		i, basex + xloc, basey + yloc, xinc, xslot, yslot, wslot, &xpix, &ypix, &wpix);
! 	x1=(int)MIN(x1,xpix); y1=(int)MIN(y1,ypix-wpix);
! 	x2=(int)MAX(x2,xpix); y2=(int)MAX(y2,ypix+wpix);
  	if (scalarvis != 0) {
  	    /* check also the drawing instructions for the scalar */ 
***************
*** 6064,6073 ****
  }
  
- #define CLAMP(_var,_min,_max) do { if (_var<_min) _var=_min; else if (_var>_max) _var=_max; } while(0)
- #define MIN(a,b) ((a)<(b)?(a):(b))
- #define MAX(a,b) ((a)>(b)?(a):(b))
- #define IS_A_FLOAT(atom,index)   ((atom+index)->a_type == A_FLOAT)
- #define IS_A_SYMBOL(atom,index)  ((atom+index)->a_type == A_SYMBOL)
- 
  /*EXTERN*/ void canvas_savecontainerto(t_canvas *x, t_binbuf *b);
  
--- 6072,6075 ----





More information about the Pd-cvs mailing list