From 508f39dabbcc4901ae0d44402a0d85fa69476263 Mon Sep 17 00:00:00 2001 From: Ivica Ico Bukvic <ico@vt.edu> Date: Sun, 31 Aug 2014 00:00:21 -0400 Subject: [PATCH] *drawsymbol clean-up (still need to fix a few things) *m_pd.c debugging info *improved dealing with scalar properties editor (making it persistent and alleviating errors of things being multiply defined) --- pd/src/g_readwrite.c | 54 ++++++++++++++++++++++++++++++-------------- pd/src/g_template.c | 12 ++++++---- pd/src/m_pd.c | 4 ++++ 3 files changed, 48 insertions(+), 22 deletions(-) diff --git a/pd/src/g_readwrite.c b/pd/src/g_readwrite.c index fd817d6b3..f485fbf27 100644 --- a/pd/src/g_readwrite.c +++ b/pd/src/g_readwrite.c @@ -163,8 +163,10 @@ int glist_readscalar(t_glist *x, int natoms, t_atom *vec, void glist_readfrombinbuf(t_glist *x, t_binbuf *b, char *filename, int selectem) { - int natoms, nline, message, nextmsg = 0; + t_canvas *canvas = glist_getcanvas(x); + int cr = 0, natoms, nline, message, nextmsg = 0, i, j, nitems; t_atom *vec; + t_gobj *gobj; natoms = binbuf_getnatom(b); vec = binbuf_getvec(b); @@ -216,15 +218,15 @@ void glist_readfrombinbuf(t_glist *x, t_binbuf *b, char *filename, int selectem) templateargs[ntemplateargs + 2] = vec[message + 2]; ntemplateargs = newnargs; } - newtemplate = template_new(templatesym, ntemplateargs, templateargs); - t_freebytes(templateargs, sizeof (*templateargs) * ntemplateargs); if (!(existtemplate = template_findbyname(templatesym))) { error("%s: template not found in current patch", templatesym->s_name); - template_free(newtemplate); + t_freebytes(templateargs, sizeof (*templateargs) * ntemplateargs); return; } + newtemplate = template_new(templatesym, ntemplateargs, templateargs); + t_freebytes(templateargs, sizeof (*templateargs) * ntemplateargs); if (!template_match(existtemplate, newtemplate)) { error("%s: template doesn't match current one", @@ -286,6 +288,7 @@ void canvas_dataproperties(t_canvas *x, t_scalar *sc, t_binbuf *b) { int ntotal, nnew, scindex; t_gobj *y, *y2 = 0, *newone, *oldone = 0; + t_template *template; for (y = x->gl_list, ntotal = 0, scindex = -1; y; y = y->g_next) { if (y == &sc->sc_gobj) @@ -294,31 +297,48 @@ void canvas_dataproperties(t_canvas *x, t_scalar *sc, t_binbuf *b) } if (scindex == -1) - bug("data_properties: scalar disappeared"); + { + error("data_properties: scalar disappeared"); + return; + } glist_readfrombinbuf(x, b, "properties dialog", 0); newone = 0; - if (scindex >= 0) - { /* take the new object off the list */ - if (ntotal) + if (ntotal) + { + for (y = x->gl_list, nnew = 1; y2 = y->g_next; + y = y2, nnew++) + if (nnew == ntotal) { - for (y = x->gl_list, nnew = 1; y2 = y->g_next; - y = y2, nnew++) - if (nnew == ntotal) - { - newone = y2; - y->g_next = y2->g_next; - break; - } + newone = y2; + gobj_vis(newone, x, 0); + y->g_next = y2->g_next; + break; } - else newone = x->gl_list, x->gl_list = newone->g_next; } + else gobj_vis((newone = x->gl_list), x, 0), x->gl_list = newone->g_next; if (!newone) error("couldn't update properties (perhaps a format problem?)"); else if (!oldone) bug("data_properties: couldn't find old element"); + else if (newone->g_pd == scalar_class && oldone->g_pd == scalar_class + && ((t_scalar *)newone)->sc_template == + ((t_scalar *)oldone)->sc_template + && (template = template_findbyname(((t_scalar *)newone)->sc_template))) + { + /* copy new one to old one and delete new one */ + memcpy(&((t_scalar *)oldone)->sc_vec, &((t_scalar *)newone)->sc_vec, + template->t_n * sizeof(t_word)); + pd_free(&newone->g_pd); + if (glist_isvisible(x)) + { + gobj_vis(oldone, x, 0); + gobj_vis(oldone, x, 1); + } + } else { + /* delete old one; put new one where the old one was on glist */ glist_delete(x, oldone); if (scindex > 0) { diff --git a/pd/src/g_template.c b/pd/src/g_template.c index bcb287ade..f206371a6 100644 --- a/pd/src/g_template.c +++ b/pd/src/g_template.c @@ -66,6 +66,7 @@ static int dataslot_matches(t_dataslot *ds1, t_dataslot *ds2, t_template *template_new(t_symbol *templatesym, int argc, t_atom *argv) { t_template *x = (t_template *)pd_new(template_class); + //fprintf(stderr,"template_new %lx\n", x); x->t_n = 0; x->t_transformable = 0; x->t_vec = (t_dataslot *)t_getbytes(0); @@ -6645,11 +6646,12 @@ void drawsymbol_float(t_drawsymbol *x, t_floatarg f) #define DRAWSYMBOL_BUFSIZE 80 static void drawsymbol_sprintf(t_drawsymbol *x, char *buf, t_atom *ap) { - //int nchars; - //strncpy(buf, x->x_label->s_name, DRAWSYMBOL_BUFSIZE); - //buf[DRAWSYMBOL_BUFSIZE - 1] = 0; - //nchars = strlen(buf); - atom_string(ap, buf, DRAWSYMBOL_BUFSIZE); + int nchars; + strncpy(buf, x->x_label->s_name, DRAWSYMBOL_BUFSIZE); + buf[DRAWSYMBOL_BUFSIZE - 1] = 0; + nchars = strlen(buf); + atom_string(ap, buf + nchars, DRAWSYMBOL_BUFSIZE - nchars); + //fprintf(stderr,"drawsymbol_sprintf %s\n", buf); } static void drawsymbol_getrect(t_gobj *z, t_glist *glist, diff --git a/pd/src/m_pd.c b/pd/src/m_pd.c index 359f6f0a0..d45d88fb2 100644 --- a/pd/src/m_pd.c +++ b/pd/src/m_pd.c @@ -315,6 +315,7 @@ t_pd *pd_findbyclass(t_symbol *s, t_class *c) { t_pd *x = 0; + //fprintf(stderr,"pd_findbyclass\n"); if (!s->s_thing) return (0); if (*s->s_thing == c) return (s->s_thing); if (*s->s_thing == bindlist_class) @@ -325,8 +326,10 @@ t_pd *pd_findbyclass(t_symbol *s, t_class *c) for (e = b->b_list; e; e = e->e_next) { //if (e->e_who != NULL && *e->e_who == c) + //fprintf(stderr, "(e_who == c)?%d || e->e_delayed_free=%d\n", (*e->e_who == c ? 1 : 0), e->e_delayed_free); if (e->e_delayed_free != 1 && *e->e_who == c) { + //fprintf(stderr,"...found %lx", e); if (x && !warned) { zz(); @@ -337,6 +340,7 @@ t_pd *pd_findbyclass(t_symbol *s, t_class *c) } } } + //fprintf(stderr,"====\n"); return x; } -- GitLab