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); } }
static void line_list(t_line *x, t_symbol *s, int ac, t_atom *av) { int natoms, nsegs, odd; t_atom *ap; t_lineseg *segp; for (natoms = 0, ap = av; natoms < ac; natoms++, ap++) { if (ap->a_type != A_FLOAT) { loud_messarg((t_pd *)x, &s_list); /* CHECKED */ return; /* CHECKED */ } } if (!natoms) return; /* CHECKED */ odd = natoms % 2; nsegs = natoms / 2; if (odd) nsegs++; if (nsegs > LINE_MAXSIZE) nsegs = LINE_MAXSIZE; { int ns = nsegs; x->x_segs = grow_nodata(&ns, &x->x_size, x->x_segs, LINE_MAXSIZE, x->x_segini, sizeof(*x->x_segs)); if (ns < nsegs) { natoms = ns * 2; nsegs = ns; odd = 0; } } x->x_nsegs = nsegs; /* #ifdef LINE_DEBUG loudbug_post("%d segments:", x->x_nsegs); #endif */ segp = x->x_segs; if (odd) nsegs--; while (nsegs--) { segp->s_target = av++->a_w.w_float; segp->s_delta = av++->a_w.w_float; /* #ifdef LINE_DEBUG loudbug_post("%g %g", segp->s_target, segp->s_delta); #endif */ segp++; } if (odd) { segp->s_target = av->a_w.w_float; segp->s_delta = 0; /* #ifdef LINE_DEBUG loudbug_post("%g %g", segp->s_target, segp->s_delta); #endif */ } x->x_deltaset = 0; x->x_target = x->x_segs->s_target; x->x_curseg = x->x_segs; x->x_retarget = 1; x->x_pause = 0; }
static void curve_list(t_curve *x, t_symbol *s, int ac, t_atom *av) { int natoms, nsegs, odd; t_atom *ap; t_curveseg *segp; for (natoms = 0, ap = av; natoms < ac; natoms++, ap++) { if (ap->a_type != A_FLOAT) { loud_messarg((t_pd *)x, &s_list); /* CHECKED */ return; /* CHECKED */ } } if (!natoms) return; /* CHECKED */ odd = natoms % 3; nsegs = natoms / 3; if (odd) nsegs++; if (nsegs > x->x_size) { int ns = nsegs; x->x_segs = grow_nodata(&ns, &x->x_size, x->x_segs, CURVE_INISIZE, x->x_segini, sizeof(*x->x_segs)); if (ns < nsegs) { natoms = ns * 3; nsegs = ns; odd = 0; } } x->x_nsegs = nsegs; #ifdef CURVE_DEBUG loudbug_post("%d segments:", x->x_nsegs); #endif segp = x->x_segs; if (odd) nsegs--; while (nsegs--) { segp->s_target = av++->a_w.w_float; segp->s_delta = av++->a_w.w_float; curve_cc(x, segp, av++->a_w.w_float); segp++; } if (odd) { segp->s_target = av->a_w.w_float; if (odd > 1) segp->s_delta = av[1].a_w.w_float; else segp->s_delta = 0; curve_cc(x, segp, 0.); } x->x_deltaset = 0; x->x_target = x->x_segs->s_target; x->x_curseg = x->x_segs; x->x_retarget = 1; }
static void iter_anything(t_iter *x, t_symbol *s, int ac, t_atom *av) { iter_dobang(x, s, ac, av); x->x_selector = s; if (ac > x->x_size) x->x_message = grow_nodata(&ac, &x->x_size, x->x_message, ITER_INISIZE, x->x_messini, sizeof(*x->x_message)); x->x_natoms = ac; memcpy(x->x_message, av, ac * sizeof(*x->x_message)); }
static void frameaccum_dsp(t_frameaccum *x, t_signal **sp) { int nblock = sp[0]->s_n; if (nblock > x->x_size) x->x_frame = grow_nodata(&nblock, &x->x_size, x->x_frame, FRAMEACCUM_INISIZE, x->x_frameini, sizeof(*x->x_frame)); memset(x->x_frame, 0, nblock * sizeof(*x->x_frame)); /* CHECKED */ dsp_add(frameaccum_perform, 4, nblock, x, sp[0]->s_vec, sp[1]->s_vec); }
static void buddy_proxy_domessage(t_buddy_proxy *x, int ac, t_atom *av) { if (ac > x->p_size) { /* LATER consider using BUDDY_MAXSIZE (and warning if exceeded) */ x->p_message = grow_nodata(&ac, &x->p_size, x->p_message, BUDDY_INISIZE, x->p_messini, sizeof(*x->p_message)); } x->p_natoms = ac; memcpy(x->p_message, av, ac * sizeof(*x->p_message)); buddy_check(x->p_master); }
static void prepend_set(t_prepend *x, t_symbol *s, int ac, t_atom *av) { if (ac) { int newsize; if (av->a_type == A_FLOAT) { if (ac > 1) x->x_selector = &s_list; else x->x_selector = &s_float; } else if (av->a_type == A_SYMBOL) { x->x_selector = av->a_w.w_symbol; ac--; av++; } else return; /* LATER rethink */ newsize = ac * 2; if (x->x_entered) { if (x->x_auxbuf) { freebytes(x->x_auxbuf, x->x_auxsize * sizeof(*x->x_auxbuf)); x->x_auxsize = 0; } if (x->x_auxbuf = getbytes(newsize * sizeof(*x->x_auxbuf))) { memcpy(x->x_auxbuf, av, ac * sizeof(*x->x_auxbuf)); x->x_auxsize = newsize; } } else { t_atom *ap; if (newsize > x->x_size) { int sz = newsize; x->x_message = grow_nodata(&sz, &x->x_size, x->x_message, PREPEND_INISIZE, x->x_messini, sizeof(*x->x_message)); if (sz != newsize) ac = sz / 2; /* LATER rethink */ } x->x_natoms = ac; ap = x->x_message; while (ac--) *ap++ = *av++; } } }
static void bondo_proxy_domultiatom(t_bondo_proxy *x, int ac, t_atom *av, int doit) { if (ac > x->p_size) { /* LATER consider using BONDO_MAXSIZE (and warning if exceeded) */ x->p_message = grow_nodata(&ac, &x->p_size, x->p_message, BONDO_INISIZE, x->p_messini, sizeof(*x->p_message)); } x->p_natoms = ac; memcpy(x->p_message, av, ac * sizeof(*x->p_message)); if (doit) bondo_arm(x->p_master); }
static void *frameaccum_new(t_symbol *s, int ac, t_atom *av) { t_frameaccum *x = (t_frameaccum *)pd_new(frameaccum_class); int size; t_float wrapFlag = FRAMEACCUM_NOWRAP; x->x_size = FRAMEACCUM_INISIZE; x->x_frame = x->x_frameini; if ((size = sys_getblksize()) > FRAMEACCUM_INISIZE) x->x_frame = grow_nodata(&size, &x->x_size, x->x_frame, FRAMEACCUM_INISIZE, x->x_frameini, sizeof(*x->x_frame)); loud_floatarg(*(t_pd *)x, 0, ac, av, &wrapFlag, 0.f, 1.f, LOUD_CLIP | LOUD_WARN | LOUD_ARGUNDER, LOUD_CLIP | LOUD_WARN | LOUD_ARGOVER, "wrapFlag"); x->x_wrapFlag = (wrapFlag) ? 1 : 0; outlet_new((t_object *)x, &s_signal); return (x); }
static void clip_list(t_clip *x, t_symbol *s, int ac, t_atom *av) { if (ac) { int docopy = 0; int i; t_atom *ap; t_float f1 = x->x_f1; t_float f2 = x->x_f2; for (i = 0, ap = av; i < ac; i++, ap++) { t_float f; if (ap->a_type == A_FLOAT) f = ap->a_w.w_float; else { docopy = 1; /* CHECKED: symbols inside lists are converted to zeros */ f = 0; } if (f < f1 || f > f2) docopy = 1; } if (docopy) { t_atom *buf; t_atom *bp; int reentered = x->x_entered; int prealloc = !reentered; x->x_entered = 1; if (prealloc && ac > x->x_size) { if (ac > CLIP_MAXSIZE) prealloc = 0; else x->x_message = grow_nodata(&ac, &x->x_size, x->x_message, CLIP_INISIZE, x->x_messini, sizeof(*x->x_message)); } if (prealloc) buf = x->x_message; else /* LATER consider using the stack if ntotal <= MAXSTACK */ buf = getbytes(ac * sizeof(*buf)); if (buf) { for (i = 0, ap = av, bp = buf; i < ac; i++, ap++, bp++) { t_float f = (ap->a_type == A_FLOAT ? ap->a_w.w_float : 0); if (f < f1) f = f1; else if (f > f2) f = f2; SETFLOAT(bp, f); } outlet_list(((t_object *)x)->ob_outlet, &s_list, ac, buf); if (buf != x->x_message) freebytes(buf, ac * sizeof(*buf)); } if (!reentered) { x->x_entered = 0; } } else outlet_list(((t_object *)x)->ob_outlet, &s_list, ac, av); } }
static void substitute_anything(t_substitute *x, t_symbol *s, int ac, t_atom *av) { int matchndx = substitute_check(x, s, ac, av); if (matchndx < -1) //if replace type is null or no match found substitute_dooutput(x, s, ac, av, 1); else { int replaceonce = x->x_replaceonce; int replaced = 0; //if we've replaced something, useful for replaceonce int reentered = x->x_entered; int prealloc = !reentered; int ntotal = ac; t_atom *buf; t_substitute_proxy *proxy = (t_substitute_proxy *)x->x_proxy; x->x_entered = 1; //while method is working, point to aux versions so if they change, won't effect //currently undergoing replacement scheme proxy->p_match = &x->x_auxmatch; proxy->p_repl = &x->x_auxrepl; if (s == &s_) s = 0; if (matchndx == -1) { //if match type is a symbol AND is the selector if (x->x_repl.a_type == A_FLOAT) { //since we're replacing the selector and it can't be a float, //need to add it to the list ntotal++; //if there's a rest to it, the selector needs to be a list selector if (ac) s = &s_list; //else there's no "rest of it", can be a float selector else s = &s_float; replaced = 1; } else if (x->x_repl.a_type == A_SYMBOL) { //just replace the selector if the replace type is the symbol //set matchndx to 0 to avoid the if in the message contructor clause below s = x->x_repl.a_w.w_symbol; matchndx = 0; replaced = 1; } } else if (matchndx == 0 && (!s || s == &s_list || s == &s_float) && av->a_type == A_FLOAT && x->x_repl.a_type == A_SYMBOL) { //match index is at the beginning of a list (or singleton) //incoming list[0] is a float, being replaced by a symbol //just make the selector the replacement s = x->x_repl.a_w.w_symbol; ac--; av++; ntotal = ac; } if (prealloc && ac > x->x_size) { //if bigger that maximum size, don't bother allocating to x_message if (ntotal > SUBSTITUTE_MAXSIZE) prealloc = 0; else x->x_message = grow_nodata(&ntotal, &x->x_size, x->x_message, SUBSTITUTE_INISIZE, x->x_messini, sizeof(*x->x_message)); } //if allocated, just point stack pointer to struct's x_message //else just point stack pointer to new allocated memory if (prealloc) buf = x->x_message; else /* LATER consider using the stack if ntotal <= MAXSTACK */ buf = getbytes(ntotal * sizeof(*buf)); if (buf) { int ncopy = ntotal; t_atom *bp = buf; if (matchndx == -1) { //only hit if x_repl is a float because of the earlier clause SETFLOAT(bp++, x->x_repl.a_w.w_float); ncopy--; } //copy over incoming list to allocated buf (or x message), do the substitution if (ncopy) memcpy(bp, av, ncopy * sizeof(*buf)); substitute_doit(x, s, ntotal, buf, matchndx, replaceonce, replaced); //free newly allocated memory if using it if (buf != x->x_message) freebytes(buf, ntotal * sizeof(*buf)); } if (!reentered) { x->x_entered = 0; if (x->x_auxmatch.a_type != A_NULL) { x->x_match = x->x_auxmatch; x->x_auxmatch.a_type = A_NULL; } if (x->x_auxrepl.a_type != A_NULL) { x->x_repl = x->x_auxrepl; x->x_auxrepl.a_type = A_NULL; } proxy->p_match = &x->x_match; proxy->p_repl = &x->x_repl; } } }
static void append_doset(t_append *x, t_symbol *s, int ac, t_atom *av) { int newsize = ac * 2; if (s) newsize += 2; if (newsize > 0) { if (x->x_entered) { if (x->x_auxbuf) { loud_warning((t_pd *)x, 0, "\'set\' message overridden"); freebytes(x->x_auxbuf, x->x_auxsize * sizeof(*x->x_auxbuf)); x->x_auxsize = 0; } if (x->x_auxbuf = getbytes(newsize * sizeof(*x->x_auxbuf))) { t_atom *ap = x->x_auxbuf + ac; if (s) { ap++; SETSYMBOL(ap, s); ap++; } if (ac) memcpy(ap, av, ac * sizeof(*x->x_auxbuf)); x->x_auxsize = newsize; } } else { t_atom *ap; if (newsize > x->x_size) { int sz = newsize; x->x_messbuf = grow_nodata(&sz, &x->x_size, x->x_messbuf, APPEND_INISIZE, x->x_messini, sizeof(*x->x_messbuf)); if (sz != newsize) { ac = sz / 2; /* LATER rethink */ if (s) ac--; } } if (s) { append_setnatoms(x, ac + 1); ap = x->x_message; SETSYMBOL(ap, s); ap++; } else { append_setnatoms(x, ac); ap = x->x_message; } while (ac--) *ap++ = *av++; } } }
static void substitute_anything(t_substitute *x, t_symbol *s, int ac, t_atom *av) { int matchndx = substitute_check(x, s, ac, av); if (matchndx < -1) substitute_dooutput(x, s, ac, av, 1); else { int reentered = x->x_entered; int prealloc = !reentered; int ntotal = ac; t_atom *buf; t_substitute_proxy *proxy = (t_substitute_proxy *)x->x_proxy; x->x_entered = 1; proxy->p_match = &x->x_auxmatch; proxy->p_repl = &x->x_auxrepl; if (s == &s_) s = 0; if (matchndx == -1) { if (x->x_repl.a_type == A_FLOAT) { ntotal++; if (ac) s = &s_list; else s = &s_float; } else if (x->x_repl.a_type == A_SYMBOL) { s = x->x_repl.a_w.w_symbol; matchndx = 0; } } else if (matchndx == 0 && (!s || s == &s_list || s == &s_float) && av->a_type == A_FLOAT && x->x_repl.a_type == A_SYMBOL) { s = x->x_repl.a_w.w_symbol; ac--; av++; ntotal = ac; } if (prealloc && ac > x->x_size) { if (ntotal > SUBSTITUTE_MAXSIZE) prealloc = 0; else x->x_message = grow_nodata(&ntotal, &x->x_size, x->x_message, SUBSTITUTE_INISIZE, x->x_messini, sizeof(*x->x_message)); } if (prealloc) buf = x->x_message; else /* LATER consider using the stack if ntotal <= MAXSTACK */ buf = getbytes(ntotal * sizeof(*buf)); if (buf) { int ncopy = ntotal; t_atom *bp = buf; if (matchndx == -1) { SETFLOAT(bp++, x->x_repl.a_w.w_float); ncopy--; } if (ncopy) memcpy(bp, av, ncopy * sizeof(*buf)); substitute_doit(x, s, ntotal, buf, matchndx); if (buf != x->x_message) freebytes(buf, ntotal * sizeof(*buf)); } if (!reentered) { x->x_entered = 0; if (x->x_auxmatch.a_type != A_NULL) { x->x_match = x->x_auxmatch; x->x_auxmatch.a_type = A_NULL; } if (x->x_auxrepl.a_type != A_NULL) { x->x_repl = x->x_auxrepl; x->x_auxrepl.a_type = A_NULL; } proxy->p_match = &x->x_match; proxy->p_repl = &x->x_repl; } } }