From 356d0569f9eab63238e966bbb309746bcf81d490 Mon Sep 17 00:00:00 2001 From: "N.N." Date: Fri, 23 Apr 2004 11:26:52 +0000 Subject: *** empty log message *** svn path=/trunk/externals/miXed/; revision=1629 --- cyclone/hammer/Table.c | 69 ++++++++++++++++++++++++++++++++------------ cyclone/hammer/prob.c | 55 ++++++++++++++++------------------- shared/common/port.c | 67 +++++++++++++++++++++++++++++++++++------- test/cyclone/Table-test.pd | 50 ++++++++++++++++++++++++++++++++ test/cyclone/cyclone-test.pd | 19 ++++++++---- 5 files changed, 195 insertions(+), 65 deletions(-) create mode 100644 test/cyclone/Table-test.pd diff --git a/cyclone/hammer/Table.c b/cyclone/hammer/Table.c index da19b9f..9b08cbe 100644 --- a/cyclone/hammer/Table.c +++ b/cyclone/hammer/Table.c @@ -67,6 +67,7 @@ typedef struct _table t_float x_value; int x_valueset; int x_head; + int x_intraversal; /* ``set-with-next/prev'' flag */ int x_loadflag; int x_loadndx; unsigned int x_seed; @@ -183,8 +184,9 @@ static void tablecommon_setlength(t_tablecommon *cc, int length) } cc->c_length = length; /* CHECKED values at common indices are preserved */ - /* CHECKED rewinding neither head, nor loadndx, but a separate - condition of eot is preserved only for the head. */ + /* CHECKED rewinding neither head, nor loadndx -- both are preserved, + although there is a bug in handling of 'prev' after the head + overflows due to shrinking. */ tablecommon_modified(cc, relocate); } @@ -427,8 +429,7 @@ static void table_float(t_table *x, t_float f) x->x_valueset = 0; } else table_dooutput(x, ndx); - /* CHECKME if head is updated */ - x->x_head = ndx; + /* CHECKED head is not updated */ } } @@ -500,13 +501,13 @@ static void table_cancel(t_table *x) static void table_clear(t_table *x) { tablecommon_setall(x->x_common, 0); - /* CHECKME head */ + /* CHECKED head preserved */ } static void table_const(t_table *x, t_floatarg f) { tablecommon_setall(x->x_common, (int)f); - /* CHECKME head */ + /* CHECKED head preserved */ } static void table_load(t_table *x) @@ -522,29 +523,59 @@ static void table_normal(t_table *x) static void table_next(t_table *x) { - table_dooutput(x, x->x_head++); - if (x->x_head >= x->x_common->c_length) + if (!x->x_intraversal) + x->x_intraversal = 1; + else if (++x->x_head >= x->x_common->c_length) x->x_head = 0; + table_dooutput(x, x->x_head); } static void table_prev(t_table *x) { - table_dooutput(x, x->x_head--); - if (x->x_head < 0) + if (!x->x_intraversal) + x->x_intraversal = 1; + else if (--x->x_head < 0) x->x_head = x->x_common->c_length - 1; + table_dooutput(x, x->x_head); } static void table_goto(t_table *x, t_floatarg f) { /* CHECKED floats are truncated */ x->x_head = tablecommon_getindex(x->x_common, (int)f); + /* CHECKED the head should be pre-updated during traversal, in order + to maintain the logical way of direction change. Therefore, we + need the flag below, which locks head in place that has just been + set by goto. The flag is then set by next or prev. */ + x->x_intraversal = 0; } -/* CHECKED 'send length' works, but not max, min, sum... */ -/* CHECKED 'send ' writes the value (a bug?) */ -static void table_send(t_table *x, t_symbol *s, t_floatarg f) +static void table_send(t_table *x, t_symbol *s, int ac, t_atom *av) { - /* FIXME */ + if (ac > 1 && av->a_type == A_SYMBOL) + { + t_symbol *target = av->a_w.w_symbol; + if (!target->s_thing) + return; /* CHECKED no complaint */ + ac--; av++; + if (av->a_type == A_FLOAT) + { + if (ac == 1) + { + int ndx = (int)av->a_w.w_float; + pd_float(target->s_thing, + (t_float)tablecommon_getvalue(x->x_common, ndx)); + } + /* CHECKED incompatible: 'send ' + stores at (a bug?) */ + } + else if (av->a_type == A_SYMBOL) + { + /* CHECKED 'send length' works, but not max, min, sum... */ + if (av->a_w.w_symbol == gensym("length")) + pd_float(target->s_thing, (t_float)x->x_common->c_length); + } + } } static void table_length(t_table *x) @@ -612,7 +643,7 @@ static void table_fquantile(t_table *x, t_floatarg f) /* FIXME arguments (from, to) */ /* CHECKED no remote dumping, symbol args bashed to 0 */ -static void table_dump(t_table *x) +static void table_dump(t_table *x, t_symbol *s, int ac, t_atom *av) { t_tablecommon *cc = x->x_common; t_outlet *out = ((t_object *)x)->ob_outlet; @@ -649,7 +680,8 @@ static void table_write(t_table *x, t_symbol *s) if (s && s != &s_) tablecommon_dowrite(cc, s, x->x_canvas); else - hammerpanel_save(cc->c_filehandle, 0, 0); /* CHECKME default name */ + /* CHECKED default name is plain `Untitled' */ + hammerpanel_save(cc->c_filehandle, 0, 0); } static int tablecommon_editorappend(t_tablecommon *cc, @@ -725,6 +757,7 @@ static void *table_new(t_symbol *s) x->x_canvas = canvas_getcurrent(); x->x_valueset = 0; x->x_head = 0; + x->x_intraversal = 0; /* CHECKED */ x->x_loadflag = 0; rand_seed(&x->x_seed, 0); inlet_new((t_object *)x, (t_pd *)x, &s_float, gensym("ft1")); @@ -773,7 +806,7 @@ void Table_setup(void) class_addmethod(table_class, (t_method)table_goto, gensym("goto"), A_FLOAT, 0); class_addmethod(table_class, (t_method)table_send, - gensym("send"), A_SYMBOL, A_FLOAT, 0); + gensym("send"), A_GIMME, 0); class_addmethod(table_class, (t_method)table_length, gensym("length"), 0); class_addmethod(table_class, (t_method)table_sum, @@ -793,7 +826,7 @@ void Table_setup(void) class_addmethod(table_class, (t_method)table_fquantile, gensym("fquantile"), A_FLOAT, 0); class_addmethod(table_class, (t_method)table_dump, - gensym("dump"), 0); + gensym("dump"), A_GIMME, 0); class_addmethod(table_class, (t_method)table_refer, gensym("refer"), A_SYMBOL, 0); class_addmethod(table_class, (t_method)table_read, diff --git a/cyclone/hammer/prob.c b/cyclone/hammer/prob.c index 5227870..e20e420 100644 --- a/cyclone/hammer/prob.c +++ b/cyclone/hammer/prob.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. */ @@ -8,8 +8,8 @@ #include "common/rand.h" #include "hammer/file.h" -/* CHECKED: no preallocation. Apparently, it looks like if the new - state-entries were added to the list's head, and the new transition-entries +/* CHECKED: no preallocation. It looks like if new state-entries + were added to the list's head, and new transition-entries were added to the sublist's head. No sorting of any kind. */ #define PROB_DEBUG 0 @@ -62,29 +62,26 @@ static void prob_reset(t_prob *x, t_floatarg f) } } -/* -CHECKED: embedmode off: -#N prob; -#P newobj ... prob; - -CHECKED: embedmode on, after clear: -#N prob; -#T embed 1; -#P newobj ... prob; +static void prob_embedhook(t_pd *z, t_binbuf *bb, t_symbol *bindsym) +{ + t_prob *x = (t_prob *)z; + if (x->x_embedmode) + { + t_probtrans *pfx, *sfx; + for (pfx = x->x_translist; pfx; pfx = pfx->tr_nextstate) + for (sfx = pfx->tr_nexttrans; sfx; sfx = sfx->tr_nexttrans) + binbuf_addv(bb, "siii;", bindsym, + pfx->tr_value, sfx->tr_value, sfx->tr_count); + binbuf_addv(bb, "ssi;", bindsym, gensym("embed"), 1); + if (x->x_default) + binbuf_addv(bb, "ssi;", bindsym, gensym("reset"), + x->x_default->tr_value); + } +} -CHECKED: embedmode on, filled: -#N prob; -#T -... -#T embed 1; -#T reset ; (if set) -#P newobj ... prob; -*/ static void prob_embed(t_prob *x, t_floatarg f) { x->x_embedmode = ((int)f != 0); - if (x->x_embedmode) - loud_incompatible(prob_class, "embedding not supported (yet)..."); } static void prob_clear(t_prob *x) @@ -235,11 +232,11 @@ static void prob_list(t_prob *x, t_symbol *s, int ac, t_atom *av) else loud_error((t_pd *)x, "bad list message format"); /* CHECKED */ } -static void prob_silent(t_prob *x) +static void prob__silent(t_prob *x) { if (!x->x_silent) { - loud_incompatible(prob_class, "no 'silent' message in max"); + loud_incompatible(prob_class, "no '_silent' message in max"); x->x_silent = 1; } } @@ -279,7 +276,7 @@ static void *prob_new(void) rand_seed(&x->x_seed, 0); outlet_new((t_object *)x, &s_float); x->x_bangout = outlet_new((t_object *)x, &s_bang); - x->x_filehandle = hammerfile_new((t_pd *)x, 0, 0, 0, 0); + x->x_filehandle = hammerfile_new((t_pd *)x, prob_embedhook, 0, 0, 0); return (x); } @@ -301,12 +298,10 @@ void prob_setup(void) class_addmethod(prob_class, (t_method)prob_dump, gensym("dump"), 0); /* CHECKED: doesn't understand "seed" */ - - /* below are the incompatible extensions... */ - class_addmethod(prob_class, (t_method)prob_silent, - gensym("silent"), 0); + class_addmethod(prob_class, (t_method)prob__silent, + gensym("_silent"), 0); class_addmethod(prob_class, (t_method)prob_click, gensym("click"), A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0); - hammerfile_setup(prob_class, 0); /* LATER embedding (, 1) */ + hammerfile_setup(prob_class, 1); } diff --git a/shared/common/port.c b/shared/common/port.c index 9c08802..87f770e 100644 --- a/shared/common/port.c +++ b/shared/common/port.c @@ -89,6 +89,7 @@ static t_symbol *portps_outlet; static t_symbol *portps_vtable; static t_symbol *portps_coll; static t_symbol *portps_funbuff; +static t_symbol *portps_prob; static t_symbol *portps_picture; static t_int port_getint(t_port *x, int ndx) @@ -509,6 +510,12 @@ static int imaction_N1_funbuff(t_port *x, char *arg) return (PORT_NEXT); } +static int imaction_N1_prob(t_port *x, char *arg) +{ + import_emstart(x, portps_prob, &s_, 0); + return (PORT_NEXT); +} + static int imaction_N1_picture(t_port *x, char *arg) { import_emstart(x, portps_picture, 0, 0); @@ -583,6 +590,16 @@ static int imaction_P6_funbuff(t_port *x, char *arg) return (PORT_NEXT); } +static int imaction_P6_prob(t_port *x, char *arg) +{ + binbuf_addv(x->x_outbb, "ssffs;", + gensym("#X"), gensym("obj"), + port_getx(x, 2), port_gety(x, 3), portps_prob); + import_emflush(x, portps_prob, &s_); + x->x_nobj++; + return (PORT_NEXT); +} + /* LATER use hammer replacements */ static int imaction_P6_pack(t_port *x, char *arg) { @@ -755,7 +772,12 @@ static int imaction_P1_connect(t_port *x, char *arg) static int imaction_T1_int(t_port *x, char *arg) { - import_emcopy(x, portps_coll); + if (x->x_emstate == portps_coll) + import_emcopy(x, portps_coll); + else if (x->x_emstate == portps_prob) + import_emcopy(x, portps_prob); + else + import_unexpected(x); return (PORT_NEXT); } @@ -767,16 +789,34 @@ static int imaction_T1_flags(t_port *x, char *arg) static int imaction_T1_set(t_port *x, char *arg) { - /* FIXME funbuff */ - if (import_emcopy(x, portps_vtable)) + if (x->x_emstate == portps_vtable) { - int count = port_getint(x, 2); - if (count != x->x_emcount) - loud_warning(0, "import", - "[%d] bad vtable chunk index %d (%d already taken)", - x->x_messcount, count, x->x_emcount); - x->x_emcount += x->x_inatoms - 3; + if (import_emcopy(x, portps_vtable)) + { + int count = port_getint(x, 2); + if (count != x->x_emcount) + loud_warning(0, "import", + "[%d] bad vtable chunk index %d (%d already taken)", + x->x_messcount, count, x->x_emcount); + x->x_emcount += x->x_inatoms - 3; + } } + else if (x->x_emstate == portps_funbuff) + import_emcopy(x, portps_funbuff); + else + import_unexpected(x); + return (PORT_NEXT); +} + +static int imaction_T1_reset(t_port *x, char *arg) +{ + import_emcopy(x, portps_prob); + return (PORT_NEXT); +} + +static int imaction_T1_embed(t_port *x, char *arg) +{ + import_emcopy(x, portps_prob); return (PORT_NEXT); } @@ -861,6 +901,7 @@ static t_portslot imslots__N[] = { "vtable", imaction_N1_vtable, 0, 0, 0 }, { "coll", imaction_N1_coll, 0, 0, 0 }, { "funbuff", imaction_N1_funbuff, 0, 0, 0 }, + { "prob", imaction_N1_prob, 0, 0, 0 }, { "picture", imaction_N1_picture, 0, 0, 0 } }; static t_portnode imnode__N = { imslots__N, PORT_NSLOTS(imslots__N), 1 }; @@ -871,7 +912,8 @@ static t_portslot imslots_newobj[] = { "p", imaction_P6_patcher, 0, 0, 0 }, { "table", imaction_P6_table, 0, 0, 0 }, { "coll", imaction_P6_coll, 0, 0, 0 }, - { "funbuff", imaction_P6_funbuff, 0, 0, 0 } + { "funbuff", imaction_P6_funbuff, 0, 0, 0 }, + { "prob", imaction_P6_prob, 0, 0, 0 } }; static t_portnode imnode_newobj = { imslots_newobj, PORT_NSLOTS(imslots_newobj), 6 }; @@ -963,7 +1005,9 @@ static t_portslot imslots__T[] = { { "int", imaction_T1_int, 0, 0, 0 }, { "flags", imaction_T1_flags, 0, 0, 0 }, - { "set", imaction_T1_set, 0, 0, 0 } + { "set", imaction_T1_set, 0, 0, 0 }, + { "reset", imaction_T1_reset, 0, 0, 0 }, + { "embed", imaction_T1_embed, 0, 0, 0 } }; static t_portnode imnode__T = { imslots__T, PORT_NSLOTS(imslots__T), 1 }; @@ -1292,6 +1336,7 @@ static void port_checksetup(void) portps_vtable = gensym("vtable"); portps_coll = gensym("coll"); portps_funbuff = gensym("funbuff"); + portps_prob = gensym("prob"); portps_picture = gensym("picture"); if (zgetfn(&pd_objectmaker, portps_bogus) == 0) diff --git a/test/cyclone/Table-test.pd b/test/cyclone/Table-test.pd new file mode 100644 index 0000000..a5f6eb4 --- /dev/null +++ b/test/cyclone/Table-test.pd @@ -0,0 +1,50 @@ +#N canvas 278 182 656 317 12; +#X msg 25 72 load; +#X obj 97 102 Uzi; +#X msg 97 72 100; +#X msg 29 222 size 100; +#X obj 119 256 print; +#X msg 157 102 next; +#X msg 159 137 prev; +#X msg 148 72 goto \$1; +#X floatatom 148 41 5 0 0 0 - - -; +#X msg 313 72 fquantile \$1; +#X floatatom 313 45 5 0 0 0 - - -; +#X msg 441 72 quantile \$1; +#X floatatom 441 45 5 0 0 0 - - -; +#X obj 508 222 r test; +#X obj 508 256 print test; +#X msg 295 223 send test \$1; +#X floatatom 295 196 5 0 0 0 - - -; +#X obj 119 222 Table t; +#C restore; +#X obj 295 253 Table t; +#C restore; +#X obj 313 137 print; +#X obj 313 107 Table t; +#C restore; +#X msg 261 72 bang; +#X msg 360 196 symbol length; +#X msg 25 102 normal; +#X floatatom 159 184 5 0 0 0 - - -; +#X connect 0 0 17 0; +#X connect 1 2 17 0; +#X connect 2 0 1 0; +#X connect 3 0 17 0; +#X connect 5 0 17 0; +#X connect 6 0 17 0; +#X connect 7 0 17 0; +#X connect 8 0 7 0; +#X connect 9 0 20 0; +#X connect 10 0 9 0; +#X connect 11 0 20 0; +#X connect 12 0 11 0; +#X connect 13 0 14 0; +#X connect 15 0 18 0; +#X connect 16 0 15 0; +#X connect 17 0 4 0; +#X connect 20 0 19 0; +#X connect 21 0 20 0; +#X connect 22 0 15 0; +#X connect 23 0 17 0; +#X connect 24 0 17 0; diff --git a/test/cyclone/cyclone-test.pd b/test/cyclone/cyclone-test.pd index a8702c3..c8d6333 100644 --- a/test/cyclone/cyclone-test.pd +++ b/test/cyclone/cyclone-test.pd @@ -1,11 +1,11 @@ -#N canvas 150 47 531 442 12; +#N canvas 150 47 650 442 12; #X obj 39 399 cyclone; #X msg 39 19 bang; #X msg 244 19 import; -#X obj 42 210 forward texthelp; -#X obj 63 278 r texthelp; -#X msg 56 245 send binhelp; -#X msg 182 245 send texthelp; +#X obj 43 220 forward texthelp; +#X obj 63 282 r texthelp; +#X msg 52 252 send binhelp; +#X msg 178 252 send texthelp; #X obj 90 309 r binhelp; #X obj 90 338 sprintf import ../../../ref/c74help/bin/%s.help; #X obj 63 369 sprintf import ../../../ref/c74help/text/%s.help; @@ -13,10 +13,14 @@ #X msg 170 19 reps; #X msg 125 181 buffir~; #X obj 244 56 cyclone; -#X msg 42 181 record~; +#X msg 43 177 record~; #X obj 39 94 cyclone ../../../ref; #X msg 211 181 fffb~; #X msg 286 181 pictctrl; +#X msg 43 148 universal; +#X msg 140 148 funbuff; +#X obj 244 94 cyclone ../../../rob; +#X msg 222 148 prob; #X connect 1 0 15 0; #X connect 2 0 13 0; #X connect 4 0 9 0; @@ -31,3 +35,6 @@ #X connect 14 0 3 0; #X connect 16 0 3 0; #X connect 17 0 3 0; +#X connect 18 0 3 0; +#X connect 19 0 3 0; +#X connect 21 0 3 0; -- cgit v1.2.1