diff options
author | N.N. <krzyszcz@users.sourceforge.net> | 2004-04-25 10:37:27 +0000 |
---|---|---|
committer | N.N. <krzyszcz@users.sourceforge.net> | 2004-04-25 10:37:27 +0000 |
commit | 075b865652ce146fe8419494b149ceadcac48071 (patch) | |
tree | 7d640bf6700aa425b0391ad4256a9fe772caf47d /cyclone/hammer | |
parent | 356d0569f9eab63238e966bbb309746bcf81d490 (diff) |
*** empty log message ***
svn path=/trunk/externals/miXed/; revision=1639
Diffstat (limited to 'cyclone/hammer')
-rw-r--r-- | cyclone/hammer/Table.c | 97 | ||||
-rw-r--r-- | cyclone/hammer/coll.c | 117 | ||||
-rw-r--r-- | cyclone/hammer/funbuff.c | 2 |
3 files changed, 137 insertions, 79 deletions
diff --git a/cyclone/hammer/Table.c b/cyclone/hammer/Table.c index 9b08cbe..e366cbb 100644 --- a/cyclone/hammer/Table.c +++ b/cyclone/hammer/Table.c @@ -61,7 +61,7 @@ typedef struct _tablecommon typedef struct _table { t_object x_ob; - t_canvas *x_canvas; + t_canvas *x_glist; t_symbol *x_name; t_tablecommon *x_common; t_float x_value; @@ -92,8 +92,8 @@ static void tablecommon_modified(t_tablecommon *cc, int relocated) { t_table *x; for (x = cc->c_refs; x; x = x->x_next) - if (x->x_canvas && glist_isvisible(x->x_canvas)) - canvas_dirty(x->x_canvas, 1); + if (x->x_glist && glist_isvisible(x->x_glist)) + canvas_dirty(x->x_glist, 1); } } @@ -223,9 +223,37 @@ static int tablecommon_quantile(t_tablecommon *cc, float f) return (ndx); } +/* LATER binary files */ static void tablecommon_doread(t_tablecommon *cc, t_symbol *fn, t_canvas *cv) { /* FIXME */ + t_binbuf *bb = binbuf_new(); + int ac; + t_atom *av; + char buf[MAXPDSTRING]; + if (!fn) + return; /* CHECKME complaint */ + if (cv || (cv = cc->c_lastcanvas)) /* !cv: 'read' w/o arg */ + canvas_makefilename(cv, fn->s_name, buf, MAXPDSTRING); + else + { + strncpy(buf, fn->s_name, MAXPDSTRING); + buf[MAXPDSTRING-1] = 0; + } + binbuf_read(bb, buf, "", 0); + if ((ac = binbuf_getnatom(bb)) && + (av = binbuf_getvec(bb)) && + av->a_type == A_SYMBOL && + av->a_w.w_symbol == gensym("table")) + { + post("Table: %s read successful", fn->s_name); /* CHECKME */ + /* FIXME */ + } +#if 0 /* FIXME */ + else /* CHECKME complaint */ + loud_error((t_pd *)cc, "invalid file %s", fn->s_name); +#endif + binbuf_free(bb); } static void tablecommon_readhook(t_pd *z, t_symbol *fn, int ac, t_atom *av) @@ -235,7 +263,23 @@ static void tablecommon_readhook(t_pd *z, t_symbol *fn, int ac, t_atom *av) static void tablecommon_dowrite(t_tablecommon *cc, t_symbol *fn, t_canvas *cv) { - /* FIXME */ + t_binbuf *bb = binbuf_new(); + char buf[MAXPDSTRING]; + int ndx, *ptr; + if (!fn) + return; /* CHECKME complaint */ + if (cv || (cv = cc->c_lastcanvas)) /* !cv: 'write' w/o arg */ + canvas_makefilename(cv, fn->s_name, buf, MAXPDSTRING); + else + { + strncpy(buf, fn->s_name, MAXPDSTRING); + buf[MAXPDSTRING-1] = 0; + } + binbuf_addv(bb, "s", gensym("table")); + for (ndx = 0, ptr = cc->c_table; ndx < cc->c_length; ndx++, ptr++) + binbuf_addv(bb, "i", *ptr); + binbuf_write(bb, buf, "", 0); + binbuf_free(bb); } static void tablecommon_writehook(t_pd *z, t_symbol *fn, int ac, t_atom *av) @@ -365,7 +409,7 @@ static void table_bind(t_table *x, t_symbol *name) { pd_bind(&cc->c_pd, name); /* LATER rethink canvas unpredictability */ - tablecommon_doread(cc, name, x->x_canvas); + tablecommon_doread(cc, name, x->x_glist); } else { @@ -641,20 +685,35 @@ static void table_fquantile(t_table *x, t_floatarg f) (t_float)tablecommon_quantile(x->x_common, f)); } -/* FIXME arguments (from, to) */ -/* CHECKED no remote dumping, symbol args bashed to 0 */ static void table_dump(t_table *x, t_symbol *s, int ac, t_atom *av) { t_tablecommon *cc = x->x_common; + int thelength = cc->c_length; + int *thetable = cc->c_table; t_outlet *out = ((t_object *)x)->ob_outlet; - int ndx; - /* The usual way of traversing the table by incrementing a pointer is - not robust, because calling outlet_float() may invalidate the pointer. - The test below is simpler than generic selfmod detection ala coll, - but behaviour may be different. LATER revisit, consider asserting - invariance of cc->c_table and cc->c_length, instead. */ - for (ndx = 0; ndx < cc->c_length; ndx++) - outlet_float(out, (t_float)cc->c_table[ndx]); + int ndx, nmx, *ptr; + /* CHECKED optional arguments: from, to, Negative 'from' causes + invalid output, symbols are bashed to zero for both arguments, + inconsistent warnings, etc. -- no strict emulation attempted below. */ + if (ac && av->a_type == A_FLOAT) + ndx = tablecommon_getindex(cc, (int)av->a_w.w_float); + else + ndx = 0; + if (ac > 1 && av[1].a_type == A_FLOAT) + nmx = tablecommon_getindex(cc, (int)av[1].a_w.w_float); + else + nmx = thelength - 1; + for (ptr = thetable + ndx; ndx <= nmx; ndx++, ptr++) + { + /* Plain traversing by incrementing a pointer is not robust, + because calling outlet_float() may invalidate the pointer. + Continous storage does not require generic selfmod detection + (ala coll), so we can get away with the simpler test below. */ + if (cc->c_length != thelength || cc->c_table != thetable) + break; + /* CHECKED no remote dumping */ + outlet_float(out, (t_float)*ptr); + } } static void table_refer(t_table *x, t_symbol *s) @@ -669,7 +728,7 @@ static void table_read(t_table *x, t_symbol *s) { t_tablecommon *cc = x->x_common; if (s && s != &s_) - tablecommon_doread(cc, s, x->x_canvas); + tablecommon_doread(cc, s, x->x_glist); else hammerpanel_open(cc->c_filehandle, 0); } @@ -678,9 +737,8 @@ static void table_write(t_table *x, t_symbol *s) { t_tablecommon *cc = x->x_common; if (s && s != &s_) - tablecommon_dowrite(cc, s, x->x_canvas); + tablecommon_dowrite(cc, s, x->x_glist); else - /* CHECKED default name is plain `Untitled' */ hammerpanel_save(cc->c_filehandle, 0, 0); } @@ -709,6 +767,7 @@ static void table_open(t_table *x) int count = cc->c_length, col = 0; /* LATER prepend "table: " */ hammereditor_open(cc->c_filehandle, + /* CHECKED default name is plain `Untitled' */ x->x_name ? x->x_name->s_name : "Untitled"); while (count--) col = tablecommon_editorappend(cc, *bp++, buf, col); @@ -754,7 +813,7 @@ static void *table_new(t_symbol *s) loud_warning((t_pd *)x, 0, "Table is not ready yet"); warned = 1; } - x->x_canvas = canvas_getcurrent(); + x->x_glist = canvas_getcurrent(); x->x_valueset = 0; x->x_head = 0; x->x_intraversal = 0; /* CHECKED */ diff --git a/cyclone/hammer/coll.c b/cyclone/hammer/coll.c index a6d6476..850c2c7 100644 --- a/cyclone/hammer/coll.c +++ b/cyclone/hammer/coll.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2002-2003 krzYszcz and others. +/* Copyright (c) 2002-2004 krzYszcz and others. * For information on usage and redistribution, and for a DISCLAIMER OF ALL * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ @@ -16,6 +16,10 @@ #define COLL_DEBUG +enum { COLL_HEADRESET, + COLL_HEADNEXT, COLL_HEADPREV, /* distinction not used, currently */ + COLL_HEADDELETED }; + typedef struct _collelem { int e_hasnumkey; @@ -41,8 +45,8 @@ typedef struct _collcommon t_hammerfile *c_filehandle; t_collelem *c_first; t_collelem *c_last; - t_collelem *c_ahead; - t_collelem *c_back; + t_collelem *c_head; + int c_headstate; } t_collcommon; typedef struct _coll @@ -184,10 +188,12 @@ static void collcommon_takeout(t_collcommon *cc, t_collelem *ep) ep->e_next->e_prev = ep->e_prev; else cc->c_last = ep->e_prev; - if (cc->c_ahead == ep) - cc->c_ahead = ep->e_next; - if (cc->c_back == ep) - cc->c_back = ep->e_prev; + if (cc->c_head == ep) + { + cc->c_head = ep->e_next; /* asymmetric, LATER rethink */ + cc->c_headstate = COLL_HEADDELETED; + } + } static void collcommon_modified(t_collcommon *cc, int relinked) @@ -222,7 +228,8 @@ static void collcommon_clearall(t_collcommon *cc) } while (ep1 = ep2); cc->c_first = cc->c_last = 0; - cc->c_ahead = cc->c_back = 0; + cc->c_head = 0; + cc->c_headstate = COLL_HEADRESET; collcommon_modified(cc, 1); } } @@ -581,8 +588,6 @@ static int collcommon_frombinbuf(t_collcommon *cc, t_binbuf *bb) static void collcommon_doread(t_collcommon *cc, t_symbol *fn, t_canvas *cv) { t_binbuf *bb; - int ac; - t_atom *av; char buf[MAXPDSTRING]; if (!fn && !(fn = cc->c_filename)) /* !fn: 'readagain' */ return; @@ -761,7 +766,8 @@ static void *collcommon_new(void) t_collcommon *cc = (t_collcommon *)pd_new(collcommon_class); cc->c_embedflag = 0; cc->c_first = cc->c_last = 0; - cc->c_ahead = cc->c_back = 0; + cc->c_head = 0; + cc->c_headstate = COLL_HEADRESET; return (cc); } @@ -1203,70 +1209,59 @@ static void coll_swap(t_coll *x, t_symbol *s, int ac, t_atom *av) else loud_messarg((t_pd *)x, s); } +/* CHECKED traversal direction change is consistent with the general rule: + 'next' always outputs e_next of a previous output, and 'prev' always + outputs e_prev, whether preceded by 'prev', or by 'next'. This is + currently implemented by pre-updating of the head (which is inhibited + if there was no previous output, i.e. after 'goto', 'end', or collection + initialization). CHECKME again. */ + static void coll_next(t_coll *x) { t_collcommon *cc = x->x_common; - if (!cc->c_ahead && !(cc->c_ahead = cc->c_first)) - return; - coll_keyoutput(x, cc->c_ahead); - if (cc->c_selfmodified && !cc->c_ahead) - return; - coll_dooutput(x, cc->c_ahead->e_size, cc->c_ahead->e_data); - /* LATER think why c74 updates the heads prior to sendout - (it seems so clumsy...) */ - if (!cc->c_ahead && !(cc->c_ahead = cc->c_first)) - { - cc->c_back = 0; - return; - } - if (cc->c_ahead->e_next) - { - cc->c_ahead = cc->c_ahead->e_next; - if (!(cc->c_back = cc->c_ahead->e_prev)) /* LATER rethink */ - cc->c_back = cc->c_last; - } - else + if (cc->c_headstate != COLL_HEADRESET && + cc->c_headstate != COLL_HEADDELETED) /* asymmetric, LATER rethink */ { - /* CHECKED wraping */ - cc->c_back = cc->c_ahead; - cc->c_ahead = 0; + if (cc->c_head) + cc->c_head = cc->c_head->e_next; + if (!cc->c_head && !(cc->c_head = cc->c_first)) /* CHECKED wrapping */ + return; } + else if (!cc->c_head && !(cc->c_head = cc->c_first)) + return; + cc->c_headstate = COLL_HEADNEXT; + coll_keyoutput(x, cc->c_head); + if (cc->c_head) + coll_dooutput(x, cc->c_head->e_size, cc->c_head->e_data); + else if (!cc->c_selfmodified) + bug("coll_next"); /* LATER rethink */ } static void coll_prev(t_coll *x) { t_collcommon *cc = x->x_common; - if (!cc->c_back && !(cc->c_back = cc->c_last)) - return; - coll_keyoutput(x, cc->c_back); - if (cc->c_selfmodified && !cc->c_back) - return; - coll_dooutput(x, cc->c_back->e_size, cc->c_back->e_data); - /* LATER think why c74 updates the heads prior to sendout - (it seems so clumsy...) */ - if (!cc->c_back && !(cc->c_back = cc->c_last)) + if (cc->c_headstate != COLL_HEADRESET) { - cc->c_ahead = 0; - return; - } - if (cc->c_back->e_prev) - { - cc->c_back = cc->c_back->e_prev; - if (!(cc->c_ahead = cc->c_back->e_next)) /* LATER rethink */ - cc->c_ahead = cc->c_first; - } - else - { - /* CHECKED wraping */ - cc->c_ahead = cc->c_back; - cc->c_back = 0; + if (cc->c_head) + cc->c_head = cc->c_head->e_prev; + if (!cc->c_head && !(cc->c_head = cc->c_last)) /* CHECKED wrapping */ + return; } + else if (!cc->c_head && !(cc->c_head = cc->c_first)) + return; + cc->c_headstate = COLL_HEADPREV; + coll_keyoutput(x, cc->c_head); + if (cc->c_head) + coll_dooutput(x, cc->c_head->e_size, cc->c_head->e_data); + else if (!cc->c_selfmodified) + bug("coll_prev"); /* LATER rethink */ } static void coll_end(t_coll *x) { t_collcommon *cc = x->x_common; - cc->c_back = cc->c_ahead = cc->c_last; + cc->c_head = cc->c_last; + cc->c_headstate = COLL_HEADRESET; } static void coll_goto(t_coll *x, t_symbol *s, int ac, t_atom *av) @@ -1275,7 +1270,11 @@ static void coll_goto(t_coll *x, t_symbol *s, int ac, t_atom *av) { t_collelem *ep = coll_findkey(x, av, s); if (ep) - x->x_common->c_back = x->x_common->c_ahead = ep; + { + t_collcommon *cc = x->x_common; + cc->c_head = ep; + cc->c_headstate = COLL_HEADRESET; + } } else loud_messarg((t_pd *)x, s); } diff --git a/cyclone/hammer/funbuff.c b/cyclone/hammer/funbuff.c index 5791b1e..3ce6080 100644 --- a/cyclone/hammer/funbuff.c +++ b/cyclone/hammer/funbuff.c @@ -444,7 +444,7 @@ static void *funbuff_new(t_symbol *s) x->x_canvas = canvas_getcurrent(); x->x_valueset = 0; x->x_pointer = 0; - x->x_pointerset = 0; + x->x_pointerset = 0; /* CHECKME, rename to intraversal? */ x->x_lastdelta = 0; x->x_embedflag = 0; hammertree_init(&x->x_tree, 0); |