static void prob_bang(t_prob *x) { if (x->x_state) /* CHECKED: no output after clear */ { int rnd = rand_int(&x->x_seed, x->x_state->tr_count); t_probtrans *trans = x->x_state->tr_nexttrans; if (trans) { for (trans = x->x_state->tr_nexttrans; trans; trans = trans->tr_nexttrans) if ((rnd -= trans->tr_count) < 0) break; if (trans) { t_probtrans *nextstate = trans->tr_suffix; if (nextstate) { outlet_float(((t_object *)x)->ob_outlet, nextstate->tr_value); x->x_state = nextstate; } else loudbug_bug("prob_bang: void suffix"); } else loudbug_bug("prob_bang: search overflow"); } else { outlet_bang(x->x_bangout); if (x->x_default) /* CHECKED: stays at dead-end if no default */ x->x_state = x->x_default; } } }
/* returns black-height or 0 if failed */ static int qnode_verify(t_qnode *np) { if (np) { int bhl, bhr; if (((bhl = qnode_verify(np->n_left)) == 0) || ((bhr = qnode_verify(np->n_right)) == 0)) return (0); if (bhl != bhr) { /* failure: two paths rooted in the same node contain different number of black nodes */ loudbug_bug("qnode_verify: not balanced"); return (0); } if (np->n_black) return (bhl + 1); else { if ((np->n_left && !np->n_left->n_black) || (np->n_right && !np->n_right->n_black)) { loudbug_bug("qnode_verify: adjacent red nodes"); return (0); } return (bhl); } } else return (1); }
/* Assert a standard stackless traversal producing the same sequence, as the auxiliary list. */ static int qtree_checktraversal(t_qtree *tree) { t_qnode *treewalk = tree->t_root; t_qnode *listwalk = tree->t_first; int count = 0; while (treewalk) { t_qnode *prev = treewalk->n_left; if (prev) { while (prev->n_right && prev->n_right != treewalk) prev = prev->n_right; if (prev->n_right) { prev->n_right = 0; count++; if (treewalk == listwalk) listwalk = listwalk->n_next; else { loudbug_bug("qtree_checktraversal 1"); qnode_post(tree, treewalk, 0, "treewalk"); if (listwalk) qnode_post(tree, listwalk, 0, "listwalk"); else loudbug_post("empty listwalk pointer"); listwalk = treewalk; } treewalk = treewalk->n_right; } else { prev->n_right = treewalk; treewalk = treewalk->n_left; } } else { count++; if (treewalk == listwalk) listwalk = listwalk->n_next; else { loudbug_bug("qtree_checktraversal 2"); qnode_post(tree, treewalk, 0, "treewalk"); if (listwalk) qnode_post(tree, listwalk, 0, "listwalk"); else loudbug_post("empty listwalk pointer"); listwalk = treewalk; } treewalk = treewalk->n_right; } } return (count); }
/* To be called for redirection only. Bobs created as orphans are a special case, and cannot be attached later on. Likewise, changing non-orphan bobs to orphans is illegal. */ void plusbob_attach(t_plusbob *bob, t_plusbob *newparent) { if (bob->bob_parent && newparent) { t_plustype *tp; plusbob_dodetach(bob); plusbob_doattach(bob, newparent); for (tp = bob->bob_type; tp; tp = tp->tp_base) if (tp->tp_attachfn) (*tp->tp_attachfn)(bob); } else if (newparent) loudbug_bug("plusbob_attach 1"); else loudbug_bug("plusbob_attach 2"); }
static void *cycle_new(t_symbol *s, int ac, t_atom *av) { t_cycle *x = (t_cycle *)pd_new(cycle_class); int i = (ac && av->a_type == A_FLOAT ? 1 : 0); int tabsize = CYCLE_TABSIZE; x->x_costable = sic_makecostable(&tabsize); if (tabsize != CYCLE_TABSIZE) { loudbug_bug("cycle_new"); pd_free((t_pd *)x); return (0); } if (ac && av->a_type == A_FLOAT) { sic_inlet((t_sic *)x, 0, 0, 0, ac, av); ac--, av++; } sic_newinlet((t_sic *)x, 0); outlet_new((t_object *)x, &s_signal); x->x_offset = 0; if (ac && av->a_type == A_SYMBOL) { x->x_name = av->a_w.w_symbol; ac--, av++; if (ac && av->a_type == A_FLOAT) if ((x->x_offset = (int)av->a_w.w_float) < 0) x->x_offset = 0; } else x->x_name = 0; x->x_table = 0; x->x_phase = 0.; x->x_conv = 0.; return (x); }
static void tosymbol_anything(t_tosymbol *x, t_symbol *s, int ac, t_atom *av) { if (!x->x_entered) { if (tosymbol_bufferlocked) { loudbug_bug("tosymbol_anything"); tosymbol_parse(s, ac, av, x->x_separator, x->x_bufsize, x->x_buffer); } else { int ntotal; tosymbol_bufferlocked = 1; ntotal = tosymbol_parse(s, ac, av, x->x_separator, TOSYMBOL_MAXSTRING, tosymbol_buffer); if (ntotal > x->x_bufsize) { int newtotal = ntotal; x->x_buffer = grow_nodata(&newtotal, &x->x_bufsize, x->x_buffer, TOSYMBOL_INISTRING, x->x_bufini, sizeof(*x->x_buffer)); if (newtotal < ntotal) { ntotal = newtotal - 1; x->x_buffer[ntotal] = 0; } } memcpy(x->x_buffer, tosymbol_buffer, ntotal); tosymbol_bufferlocked = 0; } tosymbol_flushbuffer(x); } }
/* LATER rethink the remote case */ void riddle_setsourceblock(t_riddle *rd, int siginno, int newblock) { int slotno = (siginno < 0 ? rd->rd_nsiginlets - siginno - 1 : siginno); #ifdef RIDDLE_DEBUG riddlebug_post(rd, "setsourceblock", "%d (%d) %d", siginno, slotno, newblock); #endif if (siginno >= rd->rd_nsiginlets || -siginno > rd->rd_nremoteslots) loudbug_bug("riddle_setsourceblock"); else if (newblock <= 0) loud_error((t_pd *)rd, "invalid source block on inlet %d: %d", siginno, newblock); else { t_rdsource *so = rd->rd_inslots + slotno; /* LATER if (so->so_newpattern) complain */ if (newblock == so->so_newblock) so->so_sourcecount++; else if (so->so_sourcecount > 0) loud_error((t_pd *)rd, "source block mismatch on inlet %d: %d != %d", siginno, newblock, so->so_newblock); else { so->so_newblock = newblock; so->so_sourcecount = 1; } } }
t_patchvalue *patchvalue_resolve(t_symbol *category, t_glist *glist, t_class *cls, t_symbol *name) { t_patchboard *pb; if (pb = patchboard_find(category)) { t_patchstorage *ps; t_patchvalue *pv; while (glist) { if ((ps = patchboard_findstorage(pb, glist)) && (pv = patchstorage_findvalue(ps, name))) { if (*(t_pd *)pv == cls) return (pv); else loudbug_bug("patchvalue_resolve"); } else if (canvas_isabstraction(glist)) break; else glist = glist->gl_owner; } } return (0); }
t_scriptlet *widgethandlers_takeany(t_widgethandlers *wh, t_symbol *selector) { t_scriptlet *sp; if (selector == widgetps_vis) sp = wh->wh_vis; else if (selector == widgetps_new) sp = wh->wh_new; else if (selector == widgetps_free) sp = wh->wh_free; else if (selector == widgetps_data) sp = wh->wh_data; else if (selector == &s_bang) sp = wh->wh_bang; else if (selector == &s_float) sp = wh->wh_float; else if (selector == &s_symbol) sp = wh->wh_symbol; else { t_widgetscript *ws; if (ws = widgethandlers_takeotherscript(wh, selector)) sp = ws->ws_script; else { loudbug_bug("widgethandlers_takeany"); sp = 0; } } return (sp); }
t_atom *props_getfirst(t_props *pp, int *npp) { if (pp->p_nextindex >= 0) loudbug_bug("props_getfirst"); pp->p_nextindex = 0; return (props_getnext(pp, npp)); }
static void riddle_mute(t_riddle *rd, t_signal **sp) { int i, j, nouts = obj_nsigoutlets((t_object *)rd); t_rdsink *si = rd->rd_outslots; #ifdef RIDDLE_DEBUG riddlebug_post(rd, "MUTE", 0); #endif if (rd->rd_nsigoutlets != nouts) { loudbug_bug("riddle_mute"); riddle_validatesinks(rd); if (rd->rd_nsigoutlets != nouts) return; } i = 0; j = obj_nsiginlets((t_object *)rd); while (nouts--) { si->si_pattern = 0; si->si_block = sp[j]->s_n; si->si_outbuf[1].a_w.w_symbol = rdps__; si->si_outbuf[2].a_w.w_float = (t_float)si->si_block; si->si_isready = 1; dsp_add_zero(sp[j]->s_vec, sp[j]->s_n); i++; j++; si++; } }
void widgethandlers_fill(t_widgethandlers *wh, t_props *pp) { int ac; t_atom *ap; if (ap = props_getfirst(pp, &ac)) { do { if (ac > 1 && ap->a_type == A_SYMBOL && ap->a_w.w_symbol->s_name[0] == '@' && ap->a_w.w_symbol->s_name[1] != 0) { t_symbol *sel = gensym(ap->a_w.w_symbol->s_name + 1); t_scriptlet *sp; if (sp = widgethandlers_takeany(wh, sel)) { scriptlet_reset(sp); scriptlet_add(sp, 0, 0, ac - 1, ap + 1); } } else loudbug_bug("widgethandlers_fill"); } while (ap = props_getnext(pp, &ac)); } }
static void plusbob_doattach(t_plusbob *bob, t_plusbob *parent) { if (bob->bob_parent = parent) { /* become the youngest child: */ bob->bob_prev = 0; if (bob->bob_next = parent->bob_children) { if (parent->bob_children->bob_prev) loudbug_bug("plusbob_doattach 1"); parent->bob_children->bob_prev = bob; } parent->bob_children = bob; } else loudbug_bug("plusbob_doattach 2"); }
static void mtrack_setmode(t_mtrack *tp, int newmode) { if (tp->tr_mode == MTR_PLAYMODE) { clock_unset(tp->tr_clock); tp->tr_ixnext = 0; } switch (tp->tr_mode = newmode) { case MTR_STEPMODE: break; case MTR_RECMODE: binbuf_clear(tp->tr_binbuf); tp->tr_prevtime = clock_getlogicaltime(); break; case MTR_PLAYMODE: tp->tr_atdelta = 0; tp->tr_ixnext = 0; tp->tr_prevtime = 0.; mtrack_donext(tp); break; default: loudbug_bug("mtrack_setmode"); } }
static void plusbob_dodetach(t_plusbob *bob) { if (bob->bob_parent) { if (bob->bob_prev) { if (bob == bob->bob_parent->bob_children) loudbug_bug("plusbob_dodetach 1"); bob->bob_prev->bob_next = bob->bob_next; } if (bob->bob_next) bob->bob_next->bob_prev = bob->bob_prev; if (bob == bob->bob_parent->bob_children) bob->bob_parent->bob_children = bob->bob_next; } else loudbug_bug("plusbob_dodetach 2"); }
t_symbol *plustag_rootname(t_symbol *tag, int validate, t_pd *caller) { if (!validate || tag->s_name == plustag_name) return (((t_plusstub *)tag)->sb_bob->bob_root->tp_name); else if (plustag_isvalid(tag, caller)) /* print the error there */ loudbug_bug("plustag_rootname"); return (0); }
char *props_firstvalue(t_props *pp, char **keyp) { if (pp->p_nextelem) loudbug_bug("props_firstvalue"); if (pp->p_resolver) pp->p_nextelem = pp->p_dict; return (props_nextvalue(pp, keyp)); }
static t_canvas *scope_getcanvas(t_scope *x, t_glist *glist) { if (glist != x->x_glist) { loudbug_bug("scope_getcanvas"); x->x_glist = glist; } return (x->x_canvas = glist_getcanvas(glist)); }
/* CHECKME if pointer is updated */ static void funbuff_dointerp(t_funbuff *x, t_floatarg f, int vsz, t_float *vec) { t_hammernode *np1; int trunc = (int)f; if (trunc > f) trunc--; /* CHECKME negative floats */ if (np1 = hammertree_closest(&x->x_tree, trunc, 0)) { float value = HAMMERNODE_GETFLOAT(np1); t_hammernode *np2 = np1->n_next; if (np2) { float delta = (float)(np2->n_key - np1->n_key); /* this is incompatible -- CHECKED float argument is silently truncated (which does not make much sense here), CHECKME again */ float frac = f - np1->n_key; if (frac < 0 || frac >= delta) { loudbug_bug("funbuff_dointerp"); return; } frac /= delta; if (vec) { /* CHECKME */ float vpos = (vsz - 1) * frac; int vndx = (int)vpos; float vfrac = vpos - vndx; if (vndx < 0 || vndx >= vsz - 1) { loudbug_bug("funbuff_dointerp redundant test..."); return; } vec += vndx; frac = *vec + (vec[1] - *vec) * vfrac; } value += (HAMMERNODE_GETFLOAT(np2) - HAMMERNODE_GETFLOAT(np1)) * frac; } funbuff_dooutput(x, value, x->x_lastdelta); /* CHECKME !np2 */ } else if (np1 = hammertree_closest(&x->x_tree, trunc, 1)) /* CHECKME */ funbuff_dooutput(x, HAMMERNODE_GETFLOAT(np1), x->x_lastdelta); }
static void comment__clickhook(t_comment *x, t_symbol *s, int ac, t_atom *av) { int xx, yy, ndx; if (ac == 8 && av->a_type == A_SYMBOL && av[1].a_type == A_FLOAT && av[2].a_type == A_FLOAT && av[3].a_type == A_FLOAT && av[4].a_type == A_FLOAT && av[5].a_type == A_FLOAT && av[6].a_type == A_FLOAT && av[7].a_type == A_FLOAT) { xx = (int)av[1].a_w.w_float; yy = (int)av[2].a_w.w_float; ndx = (int)av[3].a_w.w_float; comment__bboxhook(x, av->a_w.w_symbol, av[4].a_w.w_float, av[5].a_w.w_float, av[6].a_w.w_float, av[7].a_w.w_float); } else { loudbug_bug("comment__clickhook"); return; } if (x->x_glist->gl_edit) { if (x->x_active) { if (ndx >= 0 && ndx < x->x_textbufsize) { /* set selection, LATER shift-click and drag */ x->x_selstart = x->x_selend = ndx; comment_dograb(x); comment_update(x); } } else if (xx > x->x_x2 - COMMENT_HANDLEWIDTH) { /* start resizing */ char buf[COMMENT_OUTBUFSIZE], *outp = buf; unsigned long cvid = (unsigned long)x->x_canvas; sprintf(outp, ".x%lx.c bind %s <ButtonRelease> \ {pdsend {%s _release %s}}\n", cvid, x->x_texttag, x->x_bindsym->s_name, x->x_bindsym->s_name); outp += strlen(outp); sprintf(outp, ".x%lx.c bind %s <Motion> \ {pdsend {%s _motion %s %%x %%y}}\n", cvid, x->x_texttag, x->x_bindsym->s_name, x->x_bindsym->s_name); outp += strlen(outp); sprintf(outp, ".x%lx.c create rectangle %d %d %d %d -outline blue \ -tags {%s %s}\n", cvid, x->x_x1, x->x_y1, x->x_x2, x->x_y2, x->x_outlinetag, x->x_tag); sys_gui(buf); x->x_newx2 = x->x_x2; x->x_dragon = 1; } }
/* apart from normalization, this is used only as a sanity check; patterns are never interpreted, they just have to match (after normalization) */ static t_symbol *riddle_validatepattern(t_symbol *pattern) { char *p = pattern->s_name, lc, uc; switch (*p) { case 'a': case 'A': lc = 'b'; uc = 'A'; break; case 'b': lc = 'c'; uc = 'B'; break; default: lc = 0; } if (lc) { /* we require at least one vector for each size element */ int vused[RDLAYOUT_MAXNVECTORS], i; for (i = 0; i < RDLAYOUT_MAXNVECTORS; i++) vused[i] = 0; if (*p == 'A') vused[0] = 1; for (p++; *p; p++) { if (*p == lc) { if (lc - 'a' < RDLAYOUT_MAXNVECTORS) lc++, uc++; else break; } else if (*p >= 'A' && *p <= uc) vused[*p - 'A'] = 1; else break; } if (!*p) { for (i = 0; i < lc - 'a'; i++) if (!vused[i]) break; if (i == lc - 'a') { if (*pattern->s_name == 'a') /* normalization */ pattern = gensym(pattern->s_name + 1); return (pattern); } } } loudbug_bug("riddle_validatepattern"); return (0); }
static int qnode_checkmulti(t_qnode *np1, t_qnode *np2) { if (np1 && np2 && np1->n_key == np2->n_key) { if (np1 == np2) loudbug_bug("qnode_checkmulti"); else return (1); } return (0); }
static void import_addclassname(t_port *x, char *outname, t_atom *inatom) { t_atom at; if (outname) SETSYMBOL(&at, gensym(outname)); else { t_symbol *insym = 0; if (inatom->a_type == A_SYMBOL) { /* LATER bash inatom to lowercase (CHECKME first) */ insym = inatom->a_w.w_symbol; if (import_mapping && import_mapsize) { char **fromp = import_mapping, **top = import_mapping + 1; int cnt = import_mapsize; while (cnt--) { if (strcmp(*fromp, insym->s_name)) { fromp += 2; top += 2; } else { insym = gensym(*top); inatom = 0; break; } } } if (insym != &s_bang && insym != &s_float && insym != &s_symbol && insym != &s_list && (insym == portps_inlet || insym == portps_outlet || zgetfn(&pd_objectmaker, insym) == 0)) { x->x_withbogus = 1; SETSYMBOL(&at, portps_bogus); binbuf_add(x->x_outbb, 1, &at); } } if (inatom) import_copyatoms(&at, inatom, 1); else if (insym) SETSYMBOL(&at, insym); else { loudbug_bug("import_addclassname"); SETSYMBOL(&at, gensym("???")); } } binbuf_add(x->x_outbb, 1, &at); }
void arsic_redraw(t_arsic *x) { if (x->s_mononame) { t_garray *ap = (t_garray *)pd_findbyclass(x->s_mononame, garray_class); if (ap) garray_redraw(ap); else if (x->s_vectors[0]) loudbug_bug("arsic_redraw 1"); } else if (*x->s_stub) { int ch = x->s_nchannels; while (ch--) { t_garray *ap = (t_garray *)pd_findbyclass(x->s_channames[ch], garray_class); if (ap) garray_redraw(ap); else if (x->s_vectors[ch]) loudbug_bug("arsic_redraw 2"); } } }
static void append_free(t_append *x) { if (x->x_messbuf != x->x_messini) freebytes(x->x_messbuf, x->x_size * sizeof(*x->x_messbuf)); if (x->x_auxbuf) { loudbug_bug("append_free"); /* LATER rethink */ freebytes(x->x_auxbuf, x->x_auxsize * sizeof(*x->x_auxbuf)); } if (x->x_proxy) pd_free(x->x_proxy); }
static char *props_mixupinitial(t_props *pp, char c) { t_props *pp1 = pp->p_firstmixup; while (pp1) { if (pp1 != pp && pp1->p_thisescape == c) return (pp1->p_thisinitial); pp1 = pp1->p_next; } loudbug_bug("props_mixupinitial"); loudbug_post("(%c \"%s\")", c, pp->p_mixupescapes); return (0); }
t_rdfeedchain *riddle_getfeedchain(t_riddle *rd, int sigoutno) { if (sigoutno < 0 || sigoutno >= rd->rd_nsigoutlets) { loudbug_bug("riddle_getfeedchain 1"); return (0); } else { t_rdsink *si = rd->rd_outslots + sigoutno; if (si->si_outno >= 0) { /* LATER update ch_outno */ return (si->si_feedchain); } else { loudbug_bug("riddle_getfeedchain 2"); return (0); } } }
/* ensures that sinks match signal outlets -- this is needed in the constructor, but is called before each push, perhaps too defensively... LATER rethink */ static int riddle_validatesinks(t_riddle *rd) { t_object *x = (t_object *)rd; int sigoutno, outno, nouts = obj_noutlets(x); for (sigoutno = 0, outno = 0; outno < nouts; outno++) { if (obj_issignaloutlet(x, outno)) { if (sigoutno < rd->rd_nsigoutlets) { if (rd->rd_outslots[sigoutno].si_outno != outno) { if (rd->rd_outslots[sigoutno].si_outno < 0) rd->rd_outslots[sigoutno].si_outno = outno; else { loudbug_bug("riddle_validatesinks 1"); return (0); } } } else { loudbug_bug("riddle_validatesinks 2"); /* LATER grow */ return (0); } sigoutno++; } } if (sigoutno < rd->rd_nsigoutlets) { loudbug_bug("riddle_validatesinks 3"); /* LATER shrink */ return (0); } return (1); }
void riddle_setoutflags(t_riddle *rd, int sigoutno, int flags) { #ifdef RIDDLE_DEBUG riddlebug_post(rd, "setoutflags", "%d %d", sigoutno, flags); #endif if (sigoutno < 0 || sigoutno >= rd->rd_nsigoutlets) loudbug_bug("riddle_setoutflags"); else { t_rdsink *si = rd->rd_outslots + sigoutno; si->si_flags = flags; si->si_outbuf[3].a_w.w_float = (t_float)flags; } }
t_qnode *qtree_override(t_qtree *tree, t_qnode *oldnode, t_qnode *newnode) { if (tree->t_nodesize) { loudbug_bug("qtree_override 1"); return (0); } else { newnode->n_key = oldnode->n_key; newnode->n_black = oldnode->n_black; if (newnode->n_left = oldnode->n_left) newnode->n_left->n_parent = newnode; if (newnode->n_right = oldnode->n_right) newnode->n_right->n_parent = newnode; if (newnode->n_parent = oldnode->n_parent) { if (oldnode == newnode->n_parent->n_left) newnode->n_parent->n_left = newnode; else if (oldnode == newnode->n_parent->n_right) newnode->n_parent->n_right = newnode; else loudbug_bug("qtree_override 2"); } if (newnode->n_prev = oldnode->n_prev) newnode->n_prev->n_next = newnode; if (newnode->n_next = oldnode->n_next) newnode->n_next->n_prev = newnode; if (tree->t_root == oldnode) tree->t_root = newnode; if (tree->t_first == oldnode) tree->t_first = newnode; if (tree->t_last == oldnode) tree->t_last = newnode; return (newnode); } }