[PD-cvs] pd/src desire.c,1.1.2.173,1.1.2.174

Mathieu Bouchard matju at users.sourceforge.net
Sat Sep 9 03:56:35 CEST 2006


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

Modified Files:
      Tag: devel_0_39
	desire.c 
Log Message:
.


Index: desire.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/Attic/desire.c,v
retrieving revision 1.1.2.173
retrieving revision 1.1.2.174
diff -C2 -d -r1.1.2.173 -r1.1.2.174
*** desire.c	9 Sep 2006 00:49:33 -0000	1.1.2.173
--- desire.c	9 Sep 2006 01:56:31 -0000	1.1.2.174
***************
*** 1864,1870 ****
  
  static int array_getfields(t_symbol *elemtemplatesym, t_canvas **elemtemplatecanvasp,
!     t_template **elemtemplatep, int *elemsizep,
!     t_fielddesc *xfielddesc, t_fielddesc *yfielddesc, t_fielddesc *wfielddesc,
!     int *xonsetp, int *yonsetp, int *wonsetp);
  
  /* try clicking on an element of the array as a scalar (if clicking
--- 1864,1870 ----
  
  static int array_getfields(t_symbol *elemtemplatesym, t_canvas **elemtemplatecanvasp,
! t_template **elemtemplatep, int *elemsizep,
! t_fielddesc *xfielddesc, t_fielddesc *yfielddesc, t_fielddesc *wfielddesc,
! int *xonsetp, int *yonsetp, int *wonsetp);
  
  /* try clicking on an element of the array as a scalar (if clicking
***************
*** 2622,2625 ****
--- 2622,2627 ----
  t_symbol *garray_getname(t_garray *x);
  
+ #define FONT "-*-courier-bold--normal--%d-*"
+ 
  /* don't remove this code yet: has to be rewritten in tcl */
  static void graph_vis(t_gobj *gr, int vis) {
***************
*** 2657,2662 ****
              int ymin = y1<y2 ? y1 : y2;
              t_symbol *s = garray_getname((t_garray *)g);
!             sys_vgui(".x%lx.c create text %d %d -text {%s} -anchor sw\
!              -font -*-courier-bold--normal--%d-* -tags %s\n",
                  (long)c,  x1, ymin, s->s_name, sys_hostfontsize(canvas_getfont(x)), tag);
          }
--- 2659,2663 ----
              int ymin = y1<y2 ? y1 : y2;
              t_symbol *s = garray_getname((t_garray *)g);
!             sys_vgui(".x%lx.c create text %d %d -text {%s} -anchor sw -font "FONT" -tags %s\n",
                  (long)c,  x1, ymin, s->s_name, sys_hostfontsize(canvas_getfont(x)), tag);
          }
***************
*** 2702,2711 ****
      /* draw x labels */
          for (i = 0; i < x->nxlabels; i++)
!             sys_vgui(".x%lx.c create text %d %d -text {%s} -font -*-courier-bold--normal--%d-* -tags %s\n",
                  (long)c, (int)canvas_xtopixels(x, atof(x->xlabel[i]->s_name)),
                  (int)canvas_ytopixels(x, x->xlabely), x->xlabel[i]->s_name, canvas_getfont(x), tag);
      /* draw y labels */
          for (i = 0; i < x->nylabels; i++)
!             sys_vgui(".x%lx.c create text %d %d -text {%s} -font -*-courier-bold--normal--%d-* -tags %s\n",
                  (long)c, (int)canvas_xtopixels(x, x->ylabelx),
                  (int)canvas_ytopixels(x, atof(x->ylabel[i]->s_name)), x->ylabel[i]->s_name,
--- 2703,2712 ----
      /* draw x labels */
          for (i = 0; i < x->nxlabels; i++)
!             sys_vgui(".x%lx.c create text %d %d -text {%s} -font "FONT" -tags %s\n",
                  (long)c, (int)canvas_xtopixels(x, atof(x->xlabel[i]->s_name)),
                  (int)canvas_ytopixels(x, x->xlabely), x->xlabel[i]->s_name, canvas_getfont(x), tag);
      /* draw y labels */
          for (i = 0; i < x->nylabels; i++)
!             sys_vgui(".x%lx.c create text %d %d -text {%s} -font "FONT" -tags %s\n",
                  (long)c, (int)canvas_xtopixels(x, x->ylabelx),
                  (int)canvas_ytopixels(x, atof(x->ylabel[i]->s_name)), x->ylabel[i]->s_name,
***************
*** 4145,4178 ****
  }
  
  static t_float template_getfloat(t_template *x, t_symbol *fieldname, t_word *wp, int loud) {
!     int onset, type; t_symbol *arraytype; float val = 0;
!     if (template_find_field(x, fieldname, &onset, &type, &arraytype)) {
!         if (type == DT_FLOAT) val = *(t_float *)(((char *)wp) + onset);
!         else if (loud) pd_error(x,"%s.%s: not a number", x->sym->s_name, fieldname->s_name);
!     } else if (loud) pd_error(x,"%s.%s: no such field", x->sym->s_name, fieldname->s_name);
!     return val;
  }
  static t_symbol *template_getsymbol(t_template *x, t_symbol *fieldname, t_word *wp, int loud) {
!     int onset, type; t_symbol *arraytype; t_symbol *val = &s_;
!     if (template_find_field(x, fieldname, &onset, &type, &arraytype)) {
!         if (type == DT_SYMBOL) val = *(t_symbol **)(((char *)wp) + onset);
!         else if (loud) pd_error(x,"%s.%s: not a symbol", x->sym->s_name, fieldname->s_name);
!     } else if (loud) pd_error(x,"%s.%s: no such field", x->sym->s_name, fieldname->s_name);
!     return val;
  }
  static void template_setfloat(t_template *x, t_symbol *fieldname, t_word *wp, t_float f, int loud) {
      int onset, type; t_symbol *arraytype;
!     if (template_find_field(x, fieldname, &onset, &type, &arraytype)) {
!         if (type == DT_FLOAT) *(t_float *)(((char *)wp) + onset) = f;
!         else if (loud) pd_error(x,"%s.%s: not a number", x->sym->s_name, fieldname->s_name);
!     } else if (loud) pd_error(x,"%s.%s: no such field", x->sym->s_name, fieldname->s_name);
  }
  static void template_setsymbol(t_template *x, t_symbol *fieldname, t_word *wp, t_symbol *s, int loud) {
      int onset, type; t_symbol *arraytype;
!     if (template_find_field(x, fieldname, &onset, &type, &arraytype)) {
!         if (type == DT_SYMBOL) *(t_symbol **)(((char *)wp) + onset) = s;
!         else if (loud) pd_error(x,"%s.%s: not a symbol", x->sym->s_name, fieldname->s_name);
!     } else if (loud) pd_error(x,"%s.%s: no such field", x->sym->s_name, fieldname->s_name);
  }
  
  /* stringent check to see if a "saved" template, x2, matches the current
--- 4146,4177 ----
  }
  
+ #define ERR(msg,ret) do {\
+ 	if (loud) pd_error(x,"%s.%s: "msg, x->sym->s_name, fieldname->s_name);\
+ 	return ret;} while(0);
  static t_float template_getfloat(t_template *x, t_symbol *fieldname, t_word *wp, int loud) {
!     int onset, type; t_symbol *arraytype;
!     if (!template_find_field(x, fieldname, &onset, &type, &arraytype)) ERR("no such field",0);
!     if (type != DT_FLOAT) ERR("not a number",0);
!     return *(t_float *)(((char *)wp) + onset);
  }
  static t_symbol *template_getsymbol(t_template *x, t_symbol *fieldname, t_word *wp, int loud) {
!     int onset, type; t_symbol *arraytype;
!     if (!template_find_field(x, fieldname, &onset, &type, &arraytype)) ERR("no such field",&s_);
!     if (type != DT_SYMBOL) ERR("not a symbol",&s_);
!     return *(t_symbol **)(((char *)wp) + onset);
  }
  static void template_setfloat(t_template *x, t_symbol *fieldname, t_word *wp, t_float f, int loud) {
      int onset, type; t_symbol *arraytype;
!     if (!template_find_field(x, fieldname, &onset, &type, &arraytype)) ERR("no such field",);
!     if (type != DT_FLOAT) ERR("not a number",);
!     *(t_float *)(((char *)wp) + onset) = f;
  }
  static void template_setsymbol(t_template *x, t_symbol *fieldname, t_word *wp, t_symbol *s, int loud) {
      int onset, type; t_symbol *arraytype;
!     if (!template_find_field(x, fieldname, &onset, &type, &arraytype)) ERR("no such field",);
!     if (type != DT_SYMBOL) ERR("not a symbol",);
!     *(t_symbol **)(((char *)wp) + onset) = s;
  }
+ #undef ERR
  
  /* stringent check to see if a "saved" template, x2, matches the current
***************
*** 4182,4194 ****
      int i;
      if (x1->n < x2->n) return 0;
!     for (i = x2->n; i < x1->n; i++) {
          if (x1->vec[i].type == DT_ARRAY ||
              x1->vec[i].type == DT_LIST)
                  return 0;
-     }
      if (x2->n > x1->n) post("add elements...");
!     for (i = 0; i < x2->n; i++)
!         if (!dataslot_matches(&x1->vec[i], &x2->vec[i], 1))
!             return 0;
      return 1;
  }
--- 4181,4190 ----
      int i;
      if (x1->n < x2->n) return 0;
!     for (i = x2->n; i < x1->n; i++)
          if (x1->vec[i].type == DT_ARRAY ||
              x1->vec[i].type == DT_LIST)
                  return 0;
      if (x2->n > x1->n) post("add elements...");
!     for (i = 0; i < x2->n; i++) if (!dataslot_matches(&x1->vec[i], &x2->vec[i], 1)) return 0;
      return 1;
  }
***************
*** 4225,4229 ****
      t_gpointer gp;
      t_template *scalartemplate;
-     /* post("conform scalar"); */
      /* possibly replace the scalar */
      if (scfrom->sc_template == tfrom->sym) {
--- 4221,4224 ----
***************
*** 4252,4256 ****
          nobug: ;
          }
-             /* burn the old one */
          pd_free(&scfrom->sc_gobj.g_pd);
          scalartemplate = tto;
--- 4247,4250 ----
***************
*** 4279,4283 ****
          /* the array elements must all be conformed */
          int oldelemsize = sizeof(t_word) * tfrom->n,
!             newelemsize = sizeof(t_word) * tto->n;
          char *newarray = (char *)getbytes(newelemsize * a->n);
          char *oldarray = a->vec;
--- 4273,4277 ----
          /* the array elements must all be conformed */
          int oldelemsize = sizeof(t_word) * tfrom->n,
!             newelemsize = sizeof(t_word) *   tto->n;
          char *newarray = (char *)getbytes(newelemsize * a->n);
          char *oldarray = a->vec;
***************
*** 4286,4291 ****
              t_word *wp = (t_word *)(newarray + newelemsize * i);
              word_init(wp, tto, &a->gp);
!             template_conformwords(tfrom, tto, conformaction,
!                 (t_word *)(oldarray + oldelemsize * i), wp);
              word_free((t_word *)(oldarray + oldelemsize * i), tfrom);
          }
--- 4280,4284 ----
              t_word *wp = (t_word *)(newarray + newelemsize * i);
              word_init(wp, tto, &a->gp);
!             template_conformwords(tfrom, tto, conformaction, (t_word *)(oldarray + oldelemsize * i), wp);
              word_free((t_word *)(oldarray + oldelemsize * i), tfrom);
          }
***************
*** 5003,5017 ****
      t_array *array;
  
!         /* find the data and verify it's an array */
      if (x->data.type != A_ARRAY || !x->data.var) {
!         error("plot: needs an array field");
          return -1;
      }
      if (!template_find_field(ownertemplate, x->data.u.varsym, &arrayonset, &type, &elemtemplatesym)) {
!         error("plot: %s: no such field", x->data.u.varsym->s_name);
          return -1;
      }
      if (type != DT_ARRAY) {
!         error("plot: %s: not an array", x->data.u.varsym->s_name);
          return -1;
      }
--- 4996,5010 ----
      t_array *array;
  
!     /* find the data and verify it's an array */
      if (x->data.type != A_ARRAY || !x->data.var) {
!         pd_error(x,"needs an array field");
          return -1;
      }
      if (!template_find_field(ownertemplate, x->data.u.varsym, &arrayonset, &type, &elemtemplatesym)) {
!         pd_error(x,"%s: no such field", x->data.u.varsym->s_name);
          return -1;
      }
      if (type != DT_ARRAY) {
!         pd_error(x,"%s: not an array", x->data.u.varsym->s_name);
          return -1;
      }
***************
*** 5038,5042 ****
  t_fielddesc *xfielddesc, t_fielddesc *yfielddesc, t_fielddesc *wfielddesc,
  int *xonsetp, int *yonsetp, int *wonsetp) {
!     int elemsize, yonset, wonset, xonset, type;
      t_template *elemtemplate;
      t_symbol *dummy, *varname;
--- 5031,5035 ----
  t_fielddesc *xfielddesc, t_fielddesc *yfielddesc, t_fielddesc *wfielddesc,
  int *xonsetp, int *yonsetp, int *wonsetp) {
!     int type;
      t_template *elemtemplate;
      t_symbol *dummy, *varname;
***************
*** 5046,5071 ****
         template_findbyname is hardwired to return a predefined template. */
      if (!(elemtemplate = template_findbyname(elemtemplatesym))) {
!         error("plot: %s: no such template", elemtemplatesym->s_name);
          return -1;
      }
      if (!(elemtemplatesym==&s_float || (elemtemplatecanvas = template_findcanvas(elemtemplate)))) {
!         error("plot: %s: no canvas for this template", elemtemplatesym->s_name);
          return -1;
      }
-     elemsize = elemtemplate->n * sizeof(t_word);
-     varname = yfielddesc && yfielddesc->var ? yfielddesc->u.varsym : gensym("y");
-     varname = xfielddesc && xfielddesc->var ? xfielddesc->u.varsym : gensym("x");
-     varname = wfielddesc && wfielddesc->var ? wfielddesc->u.varsym : gensym("w");
-     if (!template_find_field(elemtemplate,varname,&yonset,&type,&dummy) || type!=DT_FLOAT) yonset=-1;
-     if (!template_find_field(elemtemplate,varname,&xonset,&type,&dummy) || type!=DT_FLOAT) xonset=-1;
-     if (!template_find_field(elemtemplate,varname,&wonset,&type,&dummy) || type!=DT_FLOAT) wonset=-1;
- 
-     /* fill in slots for return values */
      *elemtemplatecanvasp = elemtemplatecanvas;
      *elemtemplatep = elemtemplate;
!     *elemsizep = elemsize;
!     *xonsetp = xonset;
!     *yonsetp = yonset;
!     *wonsetp = wonset;
      return 0;
  }
--- 5039,5060 ----
         template_findbyname is hardwired to return a predefined template. */
      if (!(elemtemplate = template_findbyname(elemtemplatesym))) {
!         error("%s: no such template", elemtemplatesym->s_name);
          return -1;
      }
      if (!(elemtemplatesym==&s_float || (elemtemplatecanvas = template_findcanvas(elemtemplate)))) {
!         error("%s: no canvas for this template", elemtemplatesym->s_name);
          return -1;
      }
      *elemtemplatecanvasp = elemtemplatecanvas;
      *elemtemplatep = elemtemplate;
!     *elemsizep = elemtemplate->n * sizeof(t_word);
! 
! #define FOO(f,name,onset) \
!   varname = f && f->var ? f->u.varsym : gensym(name); \
!   if (!template_find_field(elemtemplate,varname,&onset,&type,&dummy) || type!=DT_FLOAT) onset=-1;
!     FOO(yfielddesc,"y",*yonsetp)
!     FOO(xfielddesc,"x",*xonsetp)
!     FOO(wfielddesc,"w",*wonsetp)
! #undef FOO
      return 0;
  }
***************
*** 5190,5198 ****
              numbertocolor(fielddesc_getfloat(&x->outlinecolor, template, data, 1), outline);
              if (wonset >= 0) {
! 	    /* found "w" field which controls linewidth.  The trace is
! 	    a filled polygon with 2n points. */
                  sys_vgui(".x%lx.c create polygon \\\n", (long)canvas_getcanvas(canvas));
                  for (i = 0, xsum = xloc; i < nelem; i++) {
!                     if (xonset >= 0) usexloc = xloc + *(float *)((elem + elemsize * i) + xonset); else usexloc = xsum, xsum += xinc;
                      if (yonset >= 0) yval = *(float *)((elem + elemsize * i) + yonset); else yval = 0;
                      wval = *(float *)((elem + elemsize * i) + wonset);
--- 5179,5187 ----
              numbertocolor(fielddesc_getfloat(&x->outlinecolor, template, data, 1), outline);
              if (wonset >= 0) {
! 	        /* found "w" field which controls linewidth.  The trace is a filled polygon with 2n points. */
                  sys_vgui(".x%lx.c create polygon \\\n", (long)canvas_getcanvas(canvas));
                  for (i = 0, xsum = xloc; i < nelem; i++) {
!                     if (xonset >= 0) usexloc = xloc + *(float *)((elem + elemsize * i) + xonset);
! 		    else usexloc = xsum, xsum += xinc;
                      if (yonset >= 0) yval = *(float *)((elem + elemsize * i) + yonset); else yval = 0;
                      wval = *(float *)((elem + elemsize * i) + wonset);
***************
*** 5211,5215 ****
                  for (i = nelem-1; i >= 0; i--) {
                      float usexloc;
!                     if (xonset >= 0) usexloc = xloc + *(float *)((elem + elemsize * i) + xonset); else xsum -= xinc, usexloc = xsum;
                      if (yonset >= 0) yval = *(float *)((elem + elemsize * i) + yonset); else yval = 0;
                      wval = *(float *)((elem + elemsize * i) + wonset);
--- 5200,5205 ----
                  for (i = nelem-1; i >= 0; i--) {
                      float usexloc;
!                     if (xonset >= 0) usexloc = xloc + *(float *)((elem + elemsize * i) + xonset);
! 		    else xsum -= xinc, usexloc = xsum;
                      if (yonset >= 0) yval = *(float *)((elem + elemsize * i) + yonset); else yval = 0;
                      wval = *(float *)((elem + elemsize * i) + wonset);
***************
*** 5238,5244 ****
                  sys_vgui("-tags plot%lx\n", (long)data);
  	    } else if (linewidth > 0) {
! 		/* no "w" field.  If the linewidth is positive, draw a
! 		segmented line with the requested width; otherwise don't
! 		draw the trace at all. */
                  sys_vgui(".x%lx.c create line \\\n", (long)canvas_getcanvas(canvas));
                  for (xsum = xloc, i = 0; i < nelem; i++) {
--- 5228,5233 ----
                  sys_vgui("-tags plot%lx\n", (long)data);
  	    } else if (linewidth > 0) {
! 		/* no "w" field.  If the linewidth is positive, draw a segmented line with the
! 		   requested width; otherwise don't draw the trace at all. */
                  sys_vgui(".x%lx.c create line \\\n", (long)canvas_getcanvas(canvas));
                  for (xsum = xloc, i = 0; i < nelem; i++) {
***************
*** 5265,5271 ****
              }
          }
! 	/* We're done with the outline; now draw all the points.
! 	This code is inefficient since the template has to be
! 	searched for drawing instructions for every last point. */
          if (scalarvis != 0) {
  	    int xsum = xloc;
--- 5254,5259 ----
              }
          }
! 	/* We're done with the outline; now draw all the points. This code is inefficient since
! 	   the template has to be searched for drawing instructions for every last point. */
          if (scalarvis != 0) {
  	    int xsum = xloc;
***************
*** 5365,5371 ****
          if (argc) fielddesc_setsymbolarg(   &x->value,argc--,argv++);
  	else      fielddesc_setsymbol_const(&x->value,&s_);
!     } else {
!         FIELDSET(float,value, 0);
!     }
      FIELDSET(float,xloc,0);
      FIELDSET(float,yloc,0);
--- 5353,5357 ----
          if (argc) fielddesc_setsymbolarg(   &x->value,argc--,argv++);
  	else      fielddesc_setsymbol_const(&x->value,&s_);
!     } else FIELDSET(float,value, 0);
      FIELDSET(float,xloc,0);
      FIELDSET(float,yloc,0);
***************
*** 5443,5448 ****
          sys_vgui(".x%lx.c create text %d %d -anchor nw -fill %s -text {%s}",
                  (long)canvas_getcanvas(canvas), xloc, yloc, colorstring, buf);
!         sys_vgui(" -font -*-courier-bold--normal--%d-*",
!             sys_hostfontsize(canvas_getfont(canvas)));
          sys_vgui(" -tags drawnumber%lx\n", (long)data);
      } else sys_vgui(".x%lx.c delete drawnumber%lx\n", (long)canvas_getcanvas(canvas), (long)data);
--- 5429,5433 ----
          sys_vgui(".x%lx.c create text %d %d -anchor nw -fill %s -text {%s}",
                  (long)canvas_getcanvas(canvas), xloc, yloc, colorstring, buf);
!         sys_vgui(" -font "FONT, sys_hostfontsize(canvas_getfont(canvas)));
          sys_vgui(" -tags drawnumber%lx\n", (long)data);
      } else sys_vgui(".x%lx.c delete drawnumber%lx\n", (long)canvas_getcanvas(canvas), (long)data);
***************
*** 5584,5601 ****
  
  static void gpointer_setcanvas(t_gpointer *gp, t_canvas *canvas, t_scalar *x) {
!     t_gstub *gs = gp->gp_stub;
!     if (gs) gstub_dis(gs);
!     gp->gp_stub = gs = canvas->stub;
!     gp->gp_valid = canvas->valid;
!     gp->gp_un.gp_scalar = x;
!     gs->gs_refcount++;
  }
  static void gpointer_setarray(t_gpointer *gp, t_array *array, t_word *w) {
!     t_gstub *gs = gp->gp_stub;
!     if (gs) gstub_dis(gs);
!     gp->gp_stub = gs = array->stub;
!     gp->gp_valid = array->valid;
!     gp->gp_un.gp_w = w;
!     gs->gs_refcount++;
  }
  
--- 5569,5578 ----
  
  static void gpointer_setcanvas(t_gpointer *gp, t_canvas *canvas, t_scalar *x) {
!     t_gstub *gs = gp->gp_stub; if (gs) gstub_dis(gs);
!     gp->gp_stub=gs=canvas->stub; gp->gp_valid = canvas->valid; gp->gp_un.gp_scalar = x; gs->gs_refcount++;
  }
  static void gpointer_setarray(t_gpointer *gp, t_array *array, t_word *w) {
!     t_gstub *gs = gp->gp_stub; if (gs) gstub_dis(gs);
!     gp->gp_stub=gs=array->stub; gp->gp_valid  =  array->valid; gp->gp_un.gp_w = w;      gs->gs_refcount++;
  }
  
***************
*** 5644,5648 ****
      t_canvas *canvas = (t_canvas *)pd_findbyclass(s, canvas_class);
      if (canvas) gpointer_setcanvas(&x->gp, canvas, 0);
!     else pd_error(x, "pointer: list '%s' not found", s->s_name);
  }
  
--- 5621,5625 ----
      t_canvas *canvas = (t_canvas *)pd_findbyclass(s, canvas_class);
      if (canvas) gpointer_setcanvas(&x->gp, canvas, 0);
!     else pd_error(x, "list '%s' not found", s->s_name);
  }
  
***************
*** 5652,5656 ****
      t_gstub *gs = gp->gp_stub;
      t_canvas *canvas;
!     int wantselected = (f != 0);
  
      if (!gs) {pd_error(x, "next: no current pointer"); return;}
--- 5629,5633 ----
      t_gstub *gs = gp->gp_stub;
      t_canvas *canvas;
!     int wantselected = f!=0;
  
      if (!gs) {pd_error(x, "next: no current pointer"); return;}





More information about the Pd-cvs mailing list