From ed932acb5860bf8b9296169676499562a55d139e Mon Sep 17 00:00:00 2001 From: Miller Puckette Date: Mon, 6 Sep 2004 20:20:36 +0000 Subject: checking in version 0.38test5. Oops, I realize I forgot some more nice files, will add them and re-commit. svn path=/trunk/; revision=2010 --- pd/src/d_array.c | 493 +++++++++++++++++++++++++------------------------------ 1 file changed, 228 insertions(+), 265 deletions(-) (limited to 'pd/src/d_array.c') diff --git a/pd/src/d_array.c b/pd/src/d_array.c index 9b68b758..55e866bd 100644 --- a/pd/src/d_array.c +++ b/pd/src/d_array.c @@ -20,7 +20,6 @@ typedef struct _tabwrite_tilde int x_nsampsintab; float *x_vec; t_symbol *x_arrayname; - t_clock *x_clock; float x_f; } t_tabwrite_tilde; @@ -29,13 +28,20 @@ static void tabwrite_tilde_tick(t_tabwrite_tilde *x); static void *tabwrite_tilde_new(t_symbol *s) { t_tabwrite_tilde *x = (t_tabwrite_tilde *)pd_new(tabwrite_tilde_class); - x->x_clock = clock_new(x, (t_method)tabwrite_tilde_tick); x->x_phase = 0x7fffffff; x->x_arrayname = s; x->x_f = 0; return (x); } +static void tabwrite_tilde_redraw(t_tabwrite_tilde *x) +{ + t_garray *a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class); + if (!a) + bug("tabwrite_tilde_redraw"); + else garray_redraw(a); +} + static t_int *tabwrite_tilde_perform(t_int *w) { t_tabwrite_tilde *x = (t_tabwrite_tilde *)(w[1]); @@ -45,24 +51,25 @@ static t_int *tabwrite_tilde_perform(t_int *w) if (endphase > phase) { - int nxfer = endphase - phase; - float *fp = x->x_vec + phase; - if (nxfer > n) nxfer = n; - phase += nxfer; - while (nxfer--) - { - float f = *in++; - if (PD_BADFLOAT(f)) - f = 0; - *fp++ = f; - } - if (phase >= endphase) - { - clock_delay(x->x_clock, 0); - phase = 0x7fffffff; - } - x->x_phase = phase; + int nxfer = endphase - phase; + float *fp = x->x_vec + phase; + if (nxfer > n) nxfer = n; + phase += nxfer; + while (nxfer--) + { + float f = *in++; + if (PD_BIGORSMALL(f)) + f = 0; + *fp++ = f; + } + if (phase >= endphase) + { + tabwrite_tilde_redraw(x); + phase = 0x7fffffff; + } + x->x_phase = phase; } + else x->x_phase = 0x7fffffff; bad: return (w+4); } @@ -74,14 +81,14 @@ void tabwrite_tilde_set(t_tabwrite_tilde *x, t_symbol *s) x->x_arrayname = s; if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) { - if (*s->s_name) pd_error(x, "tabwrite~: %s: no such array", - x->x_arrayname->s_name); - x->x_vec = 0; + if (*s->s_name) pd_error(x, "tabwrite~: %s: no such array", + x->x_arrayname->s_name); + x->x_vec = 0; } else if (!garray_getfloatarray(a, &x->x_nsampsintab, &x->x_vec)) { - pd_error(x, "%s: bad template for tabwrite~", x->x_arrayname->s_name); - x->x_vec = 0; + pd_error(x, "%s: bad template for tabwrite~", x->x_arrayname->s_name); + x->x_vec = 0; } else garray_usedindsp(a); } @@ -97,39 +104,34 @@ static void tabwrite_tilde_bang(t_tabwrite_tilde *x) x->x_phase = 0; } +static void tabwrite_tilde_start(t_tabwrite_tilde *x, t_floatarg f) +{ + x->x_phase = (f > 0 ? f : 0); +} + static void tabwrite_tilde_stop(t_tabwrite_tilde *x) { if (x->x_phase != 0x7fffffff) { - tabwrite_tilde_tick(x); - x->x_phase = 0x7fffffff; + tabwrite_tilde_redraw(x); + x->x_phase = 0x7fffffff; } } -static void tabwrite_tilde_tick(t_tabwrite_tilde *x) -{ - t_garray *a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class); - if (!a) bug("tabwrite_tilde_tick"); - else garray_redraw(a); -} - -static void tabwrite_tilde_free(t_tabwrite_tilde *x) -{ - clock_free(x->x_clock); -} - static void tabwrite_tilde_setup(void) { tabwrite_tilde_class = class_new(gensym("tabwrite~"), - (t_newmethod)tabwrite_tilde_new, (t_method)tabwrite_tilde_free, - sizeof(t_tabwrite_tilde), 0, A_DEFSYM, 0); + (t_newmethod)tabwrite_tilde_new, 0, + sizeof(t_tabwrite_tilde), 0, A_DEFSYM, 0); CLASS_MAINSIGNALIN(tabwrite_tilde_class, t_tabwrite_tilde, x_f); class_addmethod(tabwrite_tilde_class, (t_method)tabwrite_tilde_dsp, - gensym("dsp"), 0); + gensym("dsp"), 0); class_addmethod(tabwrite_tilde_class, (t_method)tabwrite_tilde_set, - gensym("set"), A_SYMBOL, 0); + gensym("set"), A_SYMBOL, 0); class_addmethod(tabwrite_tilde_class, (t_method)tabwrite_tilde_stop, - gensym("stop"), 0); + gensym("stop"), 0); + class_addmethod(tabwrite_tilde_class, (t_method)tabwrite_tilde_start, + gensym("start"), A_DEFFLOAT, 0); class_addbang(tabwrite_tilde_class, tabwrite_tilde_bang); } @@ -168,25 +170,25 @@ static t_int *tabplay_tilde_perform(t_int *w) t_tabplay_tilde *x = (t_tabplay_tilde *)(w[1]); t_float *out = (t_float *)(w[2]), *fp; int n = (int)(w[3]), phase = x->x_phase, - endphase = (x->x_nsampsintab < x->x_limit ? - x->x_nsampsintab : x->x_limit), nxfer, n3; + endphase = (x->x_nsampsintab < x->x_limit ? + x->x_nsampsintab : x->x_limit), nxfer, n3; if (!x->x_vec || phase >= endphase) - goto zero; + goto zero; nxfer = endphase - phase; fp = x->x_vec + phase; if (nxfer > n) - nxfer = n; + nxfer = n; n3 = n - nxfer; phase += nxfer; while (nxfer--) - *out++ = *fp++; + *out++ = *fp++; if (phase >= endphase) { - clock_delay(x->x_clock, 0); - x->x_phase = 0x7fffffff; - while (n3--) - *out++ = 0; + clock_delay(x->x_clock, 0); + x->x_phase = 0x7fffffff; + while (n3--) + *out++ = 0; } else x->x_phase = phase; @@ -203,14 +205,14 @@ void tabplay_tilde_set(t_tabplay_tilde *x, t_symbol *s) x->x_arrayname = s; if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) { - if (*s->s_name) pd_error(x, "tabplay~: %s: no such array", - x->x_arrayname->s_name); - x->x_vec = 0; + if (*s->s_name) pd_error(x, "tabplay~: %s: no such array", + x->x_arrayname->s_name); + x->x_vec = 0; } else if (!garray_getfloatarray(a, &x->x_nsampsintab, &x->x_vec)) { - pd_error(x, "%s: bad template for tabplay~", x->x_arrayname->s_name); - x->x_vec = 0; + pd_error(x, "%s: bad template for tabplay~", x->x_arrayname->s_name); + x->x_vec = 0; } else garray_usedindsp(a); } @@ -228,9 +230,9 @@ static void tabplay_tilde_list(t_tabplay_tilde *x, t_symbol *s, long length = atom_getfloatarg(1, argc, argv); if (start < 0) start = 0; if (length <= 0) - x->x_limit = 0x7fffffff; + x->x_limit = 0x7fffffff; else - x->x_limit = start + length; + x->x_limit = start + length; x->x_phase = start; } @@ -252,14 +254,14 @@ static void tabplay_tilde_free(t_tabplay_tilde *x) static void tabplay_tilde_setup(void) { tabplay_tilde_class = class_new(gensym("tabplay~"), - (t_newmethod)tabplay_tilde_new, (t_method)tabplay_tilde_free, - sizeof(t_tabplay_tilde), 0, A_DEFSYM, 0); + (t_newmethod)tabplay_tilde_new, (t_method)tabplay_tilde_free, + sizeof(t_tabplay_tilde), 0, A_DEFSYM, 0); class_addmethod(tabplay_tilde_class, (t_method)tabplay_tilde_dsp, - gensym("dsp"), 0); + gensym("dsp"), 0); class_addmethod(tabplay_tilde_class, (t_method)tabplay_tilde_stop, - gensym("stop"), 0); + gensym("stop"), 0); class_addmethod(tabplay_tilde_class, (t_method)tabplay_tilde_set, - gensym("set"), A_DEFSYM, 0); + gensym("set"), A_DEFSYM, 0); class_addlist(tabplay_tilde_class, tabplay_tilde_list); } @@ -301,12 +303,12 @@ static t_int *tabread_tilde_perform(t_int *w) for (i = 0; i < n; i++) { - int index = *in++; - if (index < 0) - index = 0; - else if (index > maxindex) - index = maxindex; - *out++ = buf[index]; + int index = *in++; + if (index < 0) + index = 0; + else if (index > maxindex) + index = maxindex; + *out++ = buf[index]; } return (w+5); zero: @@ -322,14 +324,14 @@ void tabread_tilde_set(t_tabread_tilde *x, t_symbol *s) x->x_arrayname = s; if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) { - if (*s->s_name) - pd_error(x, "tabread~: %s: no such array", x->x_arrayname->s_name); - x->x_vec = 0; + if (*s->s_name) + pd_error(x, "tabread~: %s: no such array", x->x_arrayname->s_name); + x->x_vec = 0; } else if (!garray_getfloatarray(a, &x->x_npoints, &x->x_vec)) { - pd_error(x, "%s: bad template for tabread~", x->x_arrayname->s_name); - x->x_vec = 0; + pd_error(x, "%s: bad template for tabread~", x->x_arrayname->s_name); + x->x_vec = 0; } else garray_usedindsp(a); } @@ -339,7 +341,7 @@ static void tabread_tilde_dsp(t_tabread_tilde *x, t_signal **sp) tabread_tilde_set(x, x->x_arrayname); dsp_add(tabread_tilde_perform, 4, x, - sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n); + sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n); } @@ -350,13 +352,13 @@ static void tabread_tilde_free(t_tabread_tilde *x) static void tabread_tilde_setup(void) { tabread_tilde_class = class_new(gensym("tabread~"), - (t_newmethod)tabread_tilde_new, (t_method)tabread_tilde_free, - sizeof(t_tabread_tilde), 0, A_DEFSYM, 0); + (t_newmethod)tabread_tilde_new, (t_method)tabread_tilde_free, + sizeof(t_tabread_tilde), 0, A_DEFSYM, 0); CLASS_MAINSIGNALIN(tabread_tilde_class, t_tabread_tilde, x_f); class_addmethod(tabread_tilde_class, (t_method)tabread_tilde_dsp, - gensym("dsp"), 0); + gensym("dsp"), 0); class_addmethod(tabread_tilde_class, (t_method)tabread_tilde_set, - gensym("set"), A_SYMBOL, 0); + gensym("set"), A_SYMBOL, 0); } /******************** tabread4~ ***********************/ @@ -396,46 +398,46 @@ static t_int *tabread4_tilde_perform(t_int *w) if (!buf) goto zero; -#if 0 /* test for spam -- I'm not ready to deal with this */ +#if 0 /* test for spam -- I'm not ready to deal with this */ for (i = 0, xmax = 0, xmin = maxindex, fp = in1; i < n; i++, fp++) { - float f = *in1; - if (f < xmin) xmin = f; - else if (f > xmax) xmax = f; + float f = *in1; + if (f < xmin) xmin = f; + else if (f > xmax) xmax = f; } if (xmax < xmin + x->c_maxextent) xmax = xmin + x->c_maxextent; for (i = 0, splitlo = xmin+ x->c_maxextent, splithi = xmax - x->c_maxextent, - fp = in1; i < n; i++, fp++) + fp = in1; i < n; i++, fp++) { - float f = *in1; - if (f > splitlo && f < splithi) goto zero; + float f = *in1; + if (f > splitlo && f < splithi) goto zero; } #endif for (i = 0; i < n; i++) { - float findex = *in++; - int index = findex; - float frac, a, b, c, d, cminusb; - static int count; - if (index < 1) - index = 1, frac = 0; - else if (index > maxindex) - index = maxindex, frac = 1; - else frac = findex - index; - fp = buf + index; - a = fp[-1]; - b = fp[0]; - c = fp[1]; - d = fp[2]; - /* if (!i && !(count++ & 1023)) - post("fp = %lx, shit = %lx, b = %f", fp, buf->b_shit, b); */ - cminusb = c-b; - *out++ = b + frac * ( - cminusb - 0.1666667f * (1.-frac) * ( - (d - a - 3.0f * cminusb) * frac + (d + 2.0f*a - 3.0f*b) - ) - ); + float findex = *in++; + int index = findex; + float frac, a, b, c, d, cminusb; + static int count; + if (index < 1) + index = 1, frac = 0; + else if (index > maxindex) + index = maxindex, frac = 1; + else frac = findex - index; + fp = buf + index; + a = fp[-1]; + b = fp[0]; + c = fp[1]; + d = fp[2]; + /* if (!i && !(count++ & 1023)) + post("fp = %lx, shit = %lx, b = %f", fp, buf->b_shit, b); */ + cminusb = c-b; + *out++ = b + frac * ( + cminusb - 0.1666667f * (1.-frac) * ( + (d - a - 3.0f * cminusb) * frac + (d + 2.0f*a - 3.0f*b) + ) + ); } return (w+5); zero: @@ -451,14 +453,14 @@ void tabread4_tilde_set(t_tabread4_tilde *x, t_symbol *s) x->x_arrayname = s; if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) { - if (*s->s_name) - pd_error(x, "tabread4~: %s: no such array", x->x_arrayname->s_name); - x->x_vec = 0; + if (*s->s_name) + pd_error(x, "tabread4~: %s: no such array", x->x_arrayname->s_name); + x->x_vec = 0; } else if (!garray_getfloatarray(a, &x->x_npoints, &x->x_vec)) { - pd_error(x, "%s: bad template for tabread4~", x->x_arrayname->s_name); - x->x_vec = 0; + pd_error(x, "%s: bad template for tabread4~", x->x_arrayname->s_name); + x->x_vec = 0; } else garray_usedindsp(a); } @@ -468,7 +470,7 @@ static void tabread4_tilde_dsp(t_tabread4_tilde *x, t_signal **sp) tabread4_tilde_set(x, x->x_arrayname); dsp_add(tabread4_tilde_perform, 4, x, - sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n); + sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n); } @@ -479,13 +481,13 @@ static void tabread4_tilde_free(t_tabread4_tilde *x) static void tabread4_tilde_setup(void) { tabread4_tilde_class = class_new(gensym("tabread4~"), - (t_newmethod)tabread4_tilde_new, (t_method)tabread4_tilde_free, - sizeof(t_tabread4_tilde), 0, A_DEFSYM, 0); + (t_newmethod)tabread4_tilde_new, (t_method)tabread4_tilde_free, + sizeof(t_tabread4_tilde), 0, A_DEFSYM, 0); CLASS_MAINSIGNALIN(tabread4_tilde_class, t_tabread4_tilde, x_f); class_addmethod(tabread4_tilde_class, (t_method)tabread4_tilde_dsp, - gensym("dsp"), 0); + gensym("dsp"), 0); class_addmethod(tabread4_tilde_class, (t_method)tabread4_tilde_set, - gensym("set"), A_SYMBOL, 0); + gensym("set"), A_SYMBOL, 0); } /******************** tabosc4~ ***********************/ @@ -604,22 +606,22 @@ static t_int *tabosc4_tilde_perform(t_int *w) #if 1 while (n--) { - float frac, a, b, c, d, cminusb; - tf.tf_d = dphase; - dphase += *in++ * conv; - addr = tab + (tf.tf_i[HIOFFSET] & mask); - tf.tf_i[HIOFFSET] = normhipart; - frac = tf.tf_d - UNITBIT32; - a = addr[0]; - b = addr[1]; - c = addr[2]; - d = addr[3]; - cminusb = c-b; - *out++ = b + frac * ( - cminusb - 0.1666667f * (1.-frac) * ( - (d - a - 3.0f * cminusb) * frac + (d + 2.0f*a - 3.0f*b) - ) - ); + float frac, a, b, c, d, cminusb; + tf.tf_d = dphase; + dphase += *in++ * conv; + addr = tab + (tf.tf_i[HIOFFSET] & mask); + tf.tf_i[HIOFFSET] = normhipart; + frac = tf.tf_d - UNITBIT32; + a = addr[0]; + b = addr[1]; + c = addr[2]; + d = addr[3]; + cminusb = c-b; + *out++ = b + frac * ( + cminusb - 0.1666667f * (1.-frac) * ( + (d - a - 3.0f * cminusb) * frac + (d + 2.0f*a - 3.0f*b) + ) + ); } #endif @@ -643,27 +645,27 @@ void tabosc4_tilde_set(t_tabosc4_tilde *x, t_symbol *s) x->x_arrayname = s; if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) { - if (*s->s_name) - pd_error(x, "tabosc4~: %s: no such array", x->x_arrayname->s_name); - x->x_vec = 0; + if (*s->s_name) + pd_error(x, "tabosc4~: %s: no such array", x->x_arrayname->s_name); + x->x_vec = 0; } else if (!garray_getfloatarray(a, &pointsinarray, &x->x_vec)) { - pd_error(x, "%s: bad template for tabosc4~", x->x_arrayname->s_name); - x->x_vec = 0; + pd_error(x, "%s: bad template for tabosc4~", x->x_arrayname->s_name); + x->x_vec = 0; } else if ((npoints = pointsinarray - 3) != (1 << ilog2(pointsinarray - 3))) { - pd_error(x, "%s: number of points (%d) not a power of 2 plus three", - x->x_arrayname->s_name, pointsinarray); - x->x_vec = 0; - garray_usedindsp(a); + pd_error(x, "%s: number of points (%d) not a power of 2 plus three", + x->x_arrayname->s_name, pointsinarray); + x->x_vec = 0; + garray_usedindsp(a); } else { - x->x_fnpoints = npoints; - x->x_finvnpoints = 1./npoints; - garray_usedindsp(a); + x->x_fnpoints = npoints; + x->x_finvnpoints = 1./npoints; + garray_usedindsp(a); } } @@ -678,21 +680,21 @@ static void tabosc4_tilde_dsp(t_tabosc4_tilde *x, t_signal **sp) tabosc4_tilde_set(x, x->x_arrayname); dsp_add(tabosc4_tilde_perform, 4, x, - sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n); + sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n); } static void tabosc4_tilde_setup(void) { tabosc4_tilde_class = class_new(gensym("tabosc4~"), - (t_newmethod)tabosc4_tilde_new, 0, - sizeof(t_tabosc4_tilde), 0, A_DEFSYM, 0); + (t_newmethod)tabosc4_tilde_new, 0, + sizeof(t_tabosc4_tilde), 0, A_DEFSYM, 0); CLASS_MAINSIGNALIN(tabosc4_tilde_class, t_tabosc4_tilde, x_f); class_addmethod(tabosc4_tilde_class, (t_method)tabosc4_tilde_dsp, - gensym("dsp"), 0); + gensym("dsp"), 0); class_addmethod(tabosc4_tilde_class, (t_method)tabosc4_tilde_set, - gensym("set"), A_SYMBOL, 0); + gensym("set"), A_SYMBOL, 0); class_addmethod(tabosc4_tilde_class, (t_method)tabosc4_tilde_ft1, - gensym("ft1"), A_FLOAT, 0); + gensym("ft1"), A_FLOAT, 0); } /* ------------------------ tabsend~ ------------------------- */ @@ -706,7 +708,6 @@ typedef struct _tabsend int x_graphperiod; int x_graphcount; t_symbol *x_arrayname; - t_clock *x_clock; float x_f; } t_tabsend; @@ -717,7 +718,6 @@ static void *tabsend_new(t_symbol *s) t_tabsend *x = (t_tabsend *)pd_new(tabsend_class); x->x_graphcount = 0; x->x_arrayname = s; - x->x_clock = clock_new(x, (t_method)tabsend_tick); x->x_f = 0; return (x); } @@ -732,16 +732,19 @@ static t_int *tabsend_perform(t_int *w) if (!x->x_vec) goto bad; while (n--) - { - float f = *in++; - if (PD_BADFLOAT(f)) - f = 0; - *dest++ = f; + { + float f = *in++; + if (PD_BIGORSMALL(f)) + f = 0; + *dest++ = f; } if (!i--) { - clock_delay(x->x_clock, 0); - i = x->x_graphperiod; + t_garray *a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class); + if (!a) + bug("tabsend_dsp"); + else garray_redraw(a); + i = x->x_graphperiod; } x->x_graphcount = i; bad: @@ -755,40 +758,28 @@ static void tabsend_dsp(t_tabsend *x, t_signal **sp) if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) { - if (*x->x_arrayname->s_name) - pd_error(x, "tabsend~: %s: no such array", x->x_arrayname->s_name); + if (*x->x_arrayname->s_name) + pd_error(x, "tabsend~: %s: no such array", x->x_arrayname->s_name); } else if (!garray_getfloatarray(a, &vecsize, &x->x_vec)) - pd_error(x, "%s: bad template for tabsend~", x->x_arrayname->s_name); + pd_error(x, "%s: bad template for tabsend~", x->x_arrayname->s_name); else { - int n = sp[0]->s_n; - int ticksper = sp[0]->s_sr/n; - if (ticksper < 1) ticksper = 1; - x->x_graphperiod = ticksper; - if (x->x_graphcount > ticksper) x->x_graphcount = ticksper; - if (n < vecsize) vecsize = n; - garray_usedindsp(a); - dsp_add(tabsend_perform, 3, x, sp[0]->s_vec, vecsize); + int n = sp[0]->s_n; + int ticksper = sp[0]->s_sr/n; + if (ticksper < 1) ticksper = 1; + x->x_graphperiod = ticksper; + if (x->x_graphcount > ticksper) x->x_graphcount = ticksper; + if (n < vecsize) vecsize = n; + garray_usedindsp(a); + dsp_add(tabsend_perform, 3, x, sp[0]->s_vec, vecsize); } } -static void tabsend_tick(t_tabsend *x) -{ - t_garray *a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class); - if (!a) bug("tabsend_tick"); - else garray_redraw(a); -} - -static void tabsend_free(t_tabsend *x) -{ - clock_free(x->x_clock); -} - static void tabsend_setup(void) { tabsend_class = class_new(gensym("tabsend~"), (t_newmethod)tabsend_new, - (t_method)tabsend_free, sizeof(t_tabsend), 0, A_DEFSYM, 0); + 0, sizeof(t_tabsend), 0, A_DEFSYM, 0); CLASS_MAINSIGNALIN(tabsend_class, t_tabsend, x_f); class_addmethod(tabsend_class, (t_method)tabsend_dsp, gensym("dsp"), 0); } @@ -822,17 +813,17 @@ static void tabreceive_dsp(t_tabreceive *x, t_signal **sp) if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) { - if (*x->x_arrayname->s_name) - pd_error(x, "tabsend~: %s: no such array", x->x_arrayname->s_name); + if (*x->x_arrayname->s_name) + pd_error(x, "tabsend~: %s: no such array", x->x_arrayname->s_name); } else if (!garray_getfloatarray(a, &vecsize, &x->x_vec)) - pd_error(x, "%s: bad template for tabreceive~", x->x_arrayname->s_name); + pd_error(x, "%s: bad template for tabreceive~", x->x_arrayname->s_name); else { - int n = sp[0]->s_n; - if (n < vecsize) vecsize = n; - garray_usedindsp(a); - dsp_add(tabreceive_perform, 3, x, sp[0]->s_vec, vecsize); + int n = sp[0]->s_n; + if (n < vecsize) vecsize = n; + garray_usedindsp(a); + dsp_add(tabreceive_perform, 3, x, sp[0]->s_vec, vecsize); } } @@ -847,10 +838,10 @@ static void *tabreceive_new(t_symbol *s) static void tabreceive_setup(void) { tabreceive_class = class_new(gensym("tabreceive~"), - (t_newmethod)tabreceive_new, 0, - sizeof(t_tabreceive), 0, A_DEFSYM, 0); + (t_newmethod)tabreceive_new, 0, + sizeof(t_tabreceive), 0, A_DEFSYM, 0); class_addmethod(tabreceive_class, (t_method)tabreceive_dsp, - gensym("dsp"), 0); + gensym("dsp"), 0); } /* ---------- tabread: control, non-interpolating ------------------------ */ @@ -870,15 +861,15 @@ static void tabread_float(t_tabread *x, t_float f) t_float *vec; if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) - pd_error(x, "%s: no such array", x->x_arrayname->s_name); + pd_error(x, "%s: no such array", x->x_arrayname->s_name); else if (!garray_getfloatarray(a, &npoints, &vec)) - pd_error(x, "%s: bad template for tabread", x->x_arrayname->s_name); + pd_error(x, "%s: bad template for tabread", x->x_arrayname->s_name); else { - int n = f; - if (n < 0) n = 0; - else if (n >= npoints) n = npoints - 1; - outlet_float(x->x_obj.ob_outlet, (npoints ? vec[n] : 0)); + int n = f; + if (n < 0) n = 0; + else if (n >= npoints) n = npoints - 1; + outlet_float(x->x_obj.ob_outlet, (npoints ? vec[n] : 0)); } } @@ -898,10 +889,10 @@ static void *tabread_new(t_symbol *s) static void tabread_setup(void) { tabread_class = class_new(gensym("tabread"), (t_newmethod)tabread_new, - 0, sizeof(t_tabread), 0, A_DEFSYM, 0); + 0, sizeof(t_tabread), 0, A_DEFSYM, 0); class_addfloat(tabread_class, (t_method)tabread_float); class_addmethod(tabread_class, (t_method)tabread_set, gensym("set"), - A_SYMBOL, 0); + A_SYMBOL, 0); } /* ---------- tabread4: control, non-interpolating ------------------------ */ @@ -921,31 +912,31 @@ static void tabread4_float(t_tabread4 *x, t_float f) t_float *vec; if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) - pd_error(x, "%s: no such array", x->x_arrayname->s_name); + pd_error(x, "%s: no such array", x->x_arrayname->s_name); else if (!garray_getfloatarray(a, &npoints, &vec)) - pd_error(x, "%s: bad template for tabread4", x->x_arrayname->s_name); + pd_error(x, "%s: bad template for tabread4", x->x_arrayname->s_name); else if (npoints < 4) - outlet_float(x->x_obj.ob_outlet, 0); + outlet_float(x->x_obj.ob_outlet, 0); else if (f <= 1) - outlet_float(x->x_obj.ob_outlet, vec[1]); + outlet_float(x->x_obj.ob_outlet, vec[1]); else if (f >= npoints - 2) - outlet_float(x->x_obj.ob_outlet, vec[npoints - 2]); + outlet_float(x->x_obj.ob_outlet, vec[npoints - 2]); else { - int n = f; - float a, b, c, d, cminusb, frac, *fp; - if (n >= npoints - 2) - n = npoints - 3; - fp = vec + n; - frac = f - n; - a = fp[-1]; - b = fp[0]; - c = fp[1]; - d = fp[2]; - cminusb = c-b; - outlet_float(x->x_obj.ob_outlet, b + frac * ( - cminusb - 0.1666667f * (1.-frac) * ( - (d - a - 3.0f * cminusb) * frac + (d + 2.0f*a - 3.0f*b)))); + int n = f; + float a, b, c, d, cminusb, frac, *fp; + if (n >= npoints - 2) + n = npoints - 3; + fp = vec + n; + frac = f - n; + a = fp[-1]; + b = fp[0]; + c = fp[1]; + d = fp[2]; + cminusb = c-b; + outlet_float(x->x_obj.ob_outlet, b + frac * ( + cminusb - 0.1666667f * (1.-frac) * ( + (d - a - 3.0f * cminusb) * frac + (d + 2.0f*a - 3.0f*b)))); } } @@ -965,10 +956,10 @@ static void *tabread4_new(t_symbol *s) static void tabread4_setup(void) { tabread4_class = class_new(gensym("tabread4"), (t_newmethod)tabread4_new, - 0, sizeof(t_tabread4), 0, A_DEFSYM, 0); + 0, sizeof(t_tabread4), 0, A_DEFSYM, 0); class_addfloat(tabread4_class, (t_method)tabread4_float); class_addmethod(tabread4_class, (t_method)tabread4_set, gensym("set"), - A_SYMBOL, 0); + A_SYMBOL, 0); } /* ------------------ tabwrite: control ------------------------ */ @@ -979,21 +970,9 @@ typedef struct _tabwrite { t_object x_obj; t_symbol *x_arrayname; - t_clock *x_clock; float x_ft1; - double x_updtime; - int x_set; } t_tabwrite; -static void tabwrite_tick(t_tabwrite *x) -{ - t_garray *a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class); - if (!a) bug("tabwrite_tick"); - else garray_redraw(a); - x->x_set = 0; - x->x_updtime = clock_getsystime(); -} - static void tabwrite_float(t_tabwrite *x, t_float f) { int i, vecsize; @@ -1001,28 +980,18 @@ static void tabwrite_float(t_tabwrite *x, t_float f) t_float *vec; if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) - pd_error(x, "%s: no such array", x->x_arrayname->s_name); + pd_error(x, "%s: no such array", x->x_arrayname->s_name); else if (!garray_getfloatarray(a, &vecsize, &vec)) - pd_error(x, "%s: bad template for tabwrite", x->x_arrayname->s_name); + pd_error(x, "%s: bad template for tabwrite", x->x_arrayname->s_name); else { - int n = x->x_ft1; - double timesince = clock_gettimesince(x->x_updtime); - if (n < 0) n = 0; - else if (n >= vecsize) n = vecsize-1; - vec[n] = f; - if (timesince > 1000) - { - tabwrite_tick(x); - } - else - { - if (x->x_set == 0) - { - clock_delay(x->x_clock, 1000 - timesince); - x->x_set = 1; - } - } + int n = x->x_ft1; + if (n < 0) + n = 0; + else if (n >= vecsize) + n = vecsize-1; + vec[n] = f; + garray_redraw(a); } } @@ -1031,18 +1000,11 @@ static void tabwrite_set(t_tabwrite *x, t_symbol *s) x->x_arrayname = s; } -static void tabwrite_free(t_tabwrite *x) -{ - clock_free(x->x_clock); -} - static void *tabwrite_new(t_symbol *s) { t_tabwrite *x = (t_tabwrite *)pd_new(tabwrite_class); x->x_ft1 = 0; x->x_arrayname = s; - x->x_updtime = clock_getsystime(); - x->x_clock = clock_new(x, (t_method)tabwrite_tick); floatinlet_new(&x->x_obj, &x->x_ft1); return (x); } @@ -1050,9 +1012,10 @@ static void *tabwrite_new(t_symbol *s) void tabwrite_setup(void) { tabwrite_class = class_new(gensym("tabwrite"), (t_newmethod)tabwrite_new, - (t_method)tabwrite_free, sizeof(t_tabwrite), 0, A_DEFSYM, 0); + 0, sizeof(t_tabwrite), 0, A_DEFSYM, 0); class_addfloat(tabwrite_class, (t_method)tabwrite_float); - class_addmethod(tabwrite_class, (t_method)tabwrite_set, gensym("set"), A_SYMBOL, 0); + class_addmethod(tabwrite_class, (t_method)tabwrite_set, gensym("set"), + A_SYMBOL, 0); } /* ------------------------ global setup routine ------------------------- */ -- cgit v1.2.1