From 739a8290a8b05645a2d055aed8e5eb76ba2e24e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?IOhannes=20m=20zm=C3=B6lnig?= Date: Fri, 28 Aug 2015 17:55:26 +0000 Subject: one-true indentation svn path=/trunk/externals/zexy/; revision=17537 --- src/0x260x260x7e.c | 191 ++++++----- src/0x2e.c | 77 +++-- src/0x3c0x7e.c | 172 +++++----- src/0x3d0x3d0x7e.c | 170 +++++----- src/0x3e0x7e.c | 172 +++++----- src/0x7c0x7c0x7e.c | 178 +++++----- src/a2l.c | 35 +- src/absgn~.c | 78 +++-- src/abs~.c | 124 +++---- src/atof.c | 24 +- src/atoi.c | 37 +- src/avg~.c | 16 +- src/blockmirror~.c | 47 ++- src/blockshuffle~.c | 83 +++-- src/blockswap~.c | 48 ++- src/date.c | 34 +- src/demultiplex.c | 24 +- src/demultiplex~.c | 45 ++- src/dfreq~.c | 21 +- src/dirac~.c | 67 ++-- src/doublepole~.c | 163 ++++----- src/drip.c | 50 +-- src/envrms~.c | 103 +++--- src/fifop.c | 116 ++++--- src/freadln.c | 373 ++++++++++---------- src/fwriteln.c | 356 ++++++++++--------- src/glue.c | 33 +- src/index.c | 156 +++++---- src/length.c | 17 +- src/lifop.c | 112 +++--- src/limiter~.c | 581 ++++++++++++++++--------------- src/list2int.c | 41 ++- src/list2lists.c | 44 +-- src/list2symbol.c | 66 ++-- src/lister.c | 36 +- src/listfind.c | 74 ++-- src/liststorage.c | 141 +++++--- src/longload.c | 27 +- src/lpt.c | 107 +++--- src/makesymbol.c | 134 ++++---- src/matchbox.c | 320 ++++++++++------- src/mavg.c | 41 ++- src/minmax.c | 29 +- src/msgfile.c | 378 ++++++++++++++------- src/multiline~.c | 91 +++-- src/multiplex.c | 46 +-- src/multiplex~.c | 48 ++- src/multireceive.c | 100 +++--- src/niagara.c | 32 +- src/noish~.c | 136 ++++---- src/noisi~.c | 82 +++-- src/operating_system.c | 20 +- src/pack.c | 66 ++-- src/packel.c | 67 ++-- src/pack~.c | 15 +- src/pdf~.c | 59 ++-- src/prime.c | 19 +- src/quantize~.c | 42 ++- src/rawprint.c | 19 +- src/regex.c | 116 ++++--- src/relay.c | 69 ++-- src/repack.c | 45 ++- src/repeat.c | 38 ++- src/route~.c | 36 +- src/sfplay.c | 904 +++++++++++++++++++++++++------------------------ src/sfrecord.c | 739 +++++++++++++++++++++------------------- src/sgn~.c | 120 +++++-- src/sigzero~.c | 23 +- src/sleepgrain.c | 16 +- src/sort.c | 49 ++- src/step~.c | 44 +-- src/strcmp.c | 75 ++-- src/sum.c | 15 +- src/swap~.c | 28 +- src/symbol2list.c | 93 ++--- src/tabdump.c | 60 ++-- src/tabminmax.c | 105 +++--- src/tabread4~~.c | 97 +++--- src/tabset.c | 36 +- src/tavg~.c | 13 +- src/time.c | 36 +- src/unpack.c | 21 +- src/unpack~.c | 51 ++- src/urn.c | 59 ++-- src/winNT_portio.c | 136 ++++---- src/wrap.c | 31 +- src/z_zexy.c | 172 +++++----- src/zexy.c | 58 ++-- src/zexy.h | 23 +- src/zexySIMD.h | 48 ++- src/zexyconf.h | 6 +- src/z~.c | 41 ++- 92 files changed, 5224 insertions(+), 4162 deletions(-) (limited to 'src') diff --git a/src/0x260x260x7e.c b/src/0x260x260x7e.c index fe8f36c..bf755a5 100644 --- a/src/0x260x260x7e.c +++ b/src/0x260x260x7e.c @@ -1,4 +1,4 @@ -/* +/* * &&~: logical AND for signals * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -25,14 +25,12 @@ /* ----------------------------- andand_tilde ----------------------------- */ static t_class *andand_tilde_class, *scalarandand_tilde_class; -typedef struct _andand_tilde -{ +typedef struct _andand_tilde { t_object x_obj; t_float x_f; } t_andand_tilde; -typedef struct _scalarandand_tilde -{ +typedef struct _scalarandand_tilde { t_object x_obj; t_float x_f; t_float x_g; /* inlet value */ @@ -40,24 +38,24 @@ typedef struct _scalarandand_tilde static void *andand_tilde_new(t_symbol * UNUSED(s), int argc, t_atom *argv) { - if (argc > 1) post("&&~: extra arguments ignored"); - if (argc) - { - t_scalarandand_tilde *x = (t_scalarandand_tilde *)pd_new(scalarandand_tilde_class); - floatinlet_new(&x->x_obj, &x->x_g); - x->x_g = atom_getfloatarg(0, argc, argv); - outlet_new(&x->x_obj, gensym("signal")); - x->x_f = 0; - return (x); - } - else - { - t_andand_tilde *x = (t_andand_tilde *)pd_new(andand_tilde_class); - inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("signal"), gensym("signal")); - outlet_new(&x->x_obj, gensym("signal")); - x->x_f = 0; - return (x); - } + if (argc > 1) { + post("&&~: extra arguments ignored"); + } + if (argc) { + t_scalarandand_tilde *x = (t_scalarandand_tilde *)pd_new( + scalarandand_tilde_class); + floatinlet_new(&x->x_obj, &x->x_g); + x->x_g = atom_getfloatarg(0, argc, argv); + outlet_new(&x->x_obj, gensym("signal")); + x->x_f = 0; + return (x); + } else { + t_andand_tilde *x = (t_andand_tilde *)pd_new(andand_tilde_class); + inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("signal"), gensym("signal")); + outlet_new(&x->x_obj, gensym("signal")); + x->x_f = 0; + return (x); + } } static t_int *andand_tilde_perform(t_int *w) @@ -66,7 +64,7 @@ static t_int *andand_tilde_perform(t_int *w) t_sample *in2 = (t_sample *)(w[2]); t_sample *out = (t_sample *)(w[3]); int n = (int)(w[4]); - while (n--){ + while (n--) { int f=(int)*in1++; int g=(int)*in2++; *out++ = (f && g); @@ -80,17 +78,22 @@ static t_int *andand_tilde_perf8(t_int *w) t_sample *in2 = (t_sample *)(w[2]); t_sample *out = (t_sample *)(w[3]); int n = (int)(w[4]); - for (; n; n -= 8, in1 += 8, in2 += 8, out += 8) - { - int f0 = in1[0], f1 = in1[1], f2 = in1[2], f3 = in1[3]; - int f4 = in1[4], f5 = in1[5], f6 = in1[6], f7 = in1[7]; - - int g0 = in2[0], g1 = in2[1], g2 = in2[2], g3 = in2[3]; - int g4 = in2[4], g5 = in2[5], g6 = in2[6], g7 = in2[7]; - - out[0] = f0 && g0; out[1] = f1 && g1; out[2] = f2 && g2; out[3] = f3 && g3; - out[4] = f4 && g4; out[5] = f5 && g5; out[6] = f6 && g6; out[7] = f7 && g7; - } + for (; n; n -= 8, in1 += 8, in2 += 8, out += 8) { + int f0 = in1[0], f1 = in1[1], f2 = in1[2], f3 = in1[3]; + int f4 = in1[4], f5 = in1[5], f6 = in1[6], f7 = in1[7]; + + int g0 = in2[0], g1 = in2[1], g2 = in2[2], g3 = in2[3]; + int g4 = in2[4], g5 = in2[5], g6 = in2[6], g7 = in2[7]; + + out[0] = f0 && g0; + out[1] = f1 && g1; + out[2] = f2 && g2; + out[3] = f3 && g3; + out[4] = f4 && g4; + out[5] = f5 && g5; + out[6] = f6 && g6; + out[7] = f7 && g7; + } return (w+5); } @@ -100,7 +103,9 @@ static t_int *scalarandand_tilde_perform(t_int *w) int f = *(t_float *)(w[2]); t_sample *out = (t_sample *)(w[3]); int n = (int)(w[4]); - while (n--) *out++ = (int)*in++ && f; + while (n--) { + *out++ = (int)*in++ && f; + } return (w+5); } @@ -110,19 +115,24 @@ static t_int *scalarandand_tilde_perf8(t_int *w) int g = *(t_float *)(w[2]); t_sample *out = (t_sample *)(w[3]); int n = (int)(w[4]); - for (; n; n -= 8, in += 8, out += 8) - { - int f0 = in[0], f1 = in[1], f2 = in[2], f3 = in[3]; - int f4 = in[4], f5 = in[5], f6 = in[6], f7 = in[7]; - - out[0] = f0 && g; out[1] = f1 && g; out[2] = f2 && g; out[3] = f3 && g; - out[4] = f4 && g; out[5] = f5 && g; out[6] = f6 && g; out[7] = f7 && g; - } + for (; n; n -= 8, in += 8, out += 8) { + int f0 = in[0], f1 = in[1], f2 = in[2], f3 = in[3]; + int f4 = in[4], f5 = in[5], f6 = in[6], f7 = in[7]; + + out[0] = f0 && g; + out[1] = f1 && g; + out[2] = f2 && g; + out[3] = f3 && g; + out[4] = f4 && g; + out[5] = f5 && g; + out[6] = f6 && g; + out[7] = f7 && g; + } return (w+5); } #ifdef __SSE__ -static int l_bitmask[]={0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}; +static int l_bitmask[]= {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}; static t_int *andand_tilde_performSSE(t_int *w) { @@ -131,14 +141,16 @@ static t_int *andand_tilde_performSSE(t_int *w) __m128 *out = (__m128 *)(w[3]); int n = (int)(w[4])>>4; - const __m128 bitmask= _mm_loadu_ps((float*)l_bitmask); /* for getting the absolute value */ + const __m128 bitmask= _mm_loadu_ps((float*) + l_bitmask); /* for getting the absolute value */ const __m128 one = _mm_set1_ps(1.f); while (n--) { __m128 xmm0, xmm1, xmm2; xmm0 = _mm_and_ps (in1[0] , bitmask); /* =abs(f); */ xmm1 = _mm_and_ps (in2[0] , bitmask); - xmm0 = _mm_cmpge_ps(xmm0 , one); /* =(abs(f)>=1.0)=i (a weird cast to integer) */ + xmm0 = _mm_cmpge_ps(xmm0 , + one); /* =(abs(f)>=1.0)=i (a weird cast to integer) */ xmm1 = _mm_cmpge_ps(xmm1 , one); xmm2 = _mm_and_ps (xmm0 , xmm1); /* =(i0&&i1) */ out[0] = _mm_and_ps (xmm2 , one); /* 0xfffffff -> 1.0 */ @@ -167,7 +179,7 @@ static t_int *andand_tilde_performSSE(t_int *w) in1+=4; in2+=4; out+=4; - } + } return (w+5); } @@ -179,7 +191,8 @@ static t_int *scalarandand_tilde_performSSE(t_int *w) __m128 scalar = _mm_set1_ps(f); int n = (int)(w[4])>>4; - const __m128 bitmask= _mm_loadu_ps((float*)l_bitmask); /* for getting the absolute value */ + const __m128 bitmask= _mm_loadu_ps((float*) + l_bitmask); /* for getting the absolute value */ const __m128 one = _mm_set1_ps(1.f); scalar = _mm_and_ps (scalar, bitmask); @@ -189,7 +202,8 @@ static t_int *scalarandand_tilde_performSSE(t_int *w) while (n--) { __m128 xmm0, xmm1; xmm0 = _mm_and_ps (in[0], bitmask); /* =abs(f); */ - xmm0 = _mm_cmpge_ps(xmm0 , one); /* =(abs(f)>=1.0)=i (a weird cast to integer) */ + xmm0 = _mm_cmpge_ps(xmm0 , + one); /* =(abs(f)>=1.0)=i (a weird cast to integer) */ xmm0 = _mm_and_ps (xmm0 , scalar); /* =(i0&&i1) */ out[0] = _mm_and_ps (xmm0 , one); /* 0xfffffff -> 1.0 */ @@ -225,20 +239,20 @@ static void andand_tilde_dsp(t_andand_tilde *UNUSED(x), t_signal **sp) #ifdef __SSE__ if( - Z_SIMD_CHKBLOCKSIZE(n)&& - Z_SIMD_CHKALIGN(in1)&& - Z_SIMD_CHKALIGN(in2)&& - Z_SIMD_CHKALIGN(out)&& - ZEXY_TYPE_EQUAL(t_sample, float) - ) - { - dsp_add(andand_tilde_performSSE, 4, in1, in2, out, n); - } else + Z_SIMD_CHKBLOCKSIZE(n)&& + Z_SIMD_CHKALIGN(in1)&& + Z_SIMD_CHKALIGN(in2)&& + Z_SIMD_CHKALIGN(out)&& + ZEXY_TYPE_EQUAL(t_sample, float) + ) { + dsp_add(andand_tilde_performSSE, 4, in1, in2, out, n); + } else #endif - if (n&7) - dsp_add(andand_tilde_perform, 4, in1, in2, out, n); - else - dsp_add(andand_tilde_perf8, 4, in1, in2, out, n); + if (n&7) { + dsp_add(andand_tilde_perform, 4, in1, in2, out, n); + } else { + dsp_add(andand_tilde_perf8, 4, in1, in2, out, n); + } } static void scalarandand_tilde_dsp(t_scalarandand_tilde *x, t_signal **sp) @@ -249,19 +263,19 @@ static void scalarandand_tilde_dsp(t_scalarandand_tilde *x, t_signal **sp) #ifdef __SSE__ if( - Z_SIMD_CHKBLOCKSIZE(n)&& - Z_SIMD_CHKALIGN(in)&& - Z_SIMD_CHKALIGN(out)&& - ZEXY_TYPE_EQUAL(t_sample, float) - ) - { - dsp_add(scalarandand_tilde_performSSE, 4, in, &x->x_g, out, n); - } else + Z_SIMD_CHKBLOCKSIZE(n)&& + Z_SIMD_CHKALIGN(in)&& + Z_SIMD_CHKALIGN(out)&& + ZEXY_TYPE_EQUAL(t_sample, float) + ) { + dsp_add(scalarandand_tilde_performSSE, 4, in, &x->x_g, out, n); + } else #endif - if (n&7) - dsp_add(scalarandand_tilde_perform, 4, in, &x->x_g, out, n); - else - dsp_add(scalarandand_tilde_perf8, 4, in, &x->x_g, out, n); + if (n&7) { + dsp_add(scalarandand_tilde_perform, 4, in, &x->x_g, out, n); + } else { + dsp_add(scalarandand_tilde_perf8, 4, in, &x->x_g, out, n); + } } static void andand_tilde_help(t_object*x) @@ -271,20 +285,25 @@ static void andand_tilde_help(t_object*x) void setup_0x260x260x7e(void) { - andand_tilde_class = class_new(gensym("&&~"), (t_newmethod)andand_tilde_new, 0, - sizeof(t_andand_tilde), 0, A_GIMME, 0); - class_addmethod(andand_tilde_class, (t_method)andand_tilde_dsp, gensym("dsp"), 0); + andand_tilde_class = class_new(gensym("&&~"), + (t_newmethod)andand_tilde_new, 0, + sizeof(t_andand_tilde), 0, A_GIMME, 0); + class_addmethod(andand_tilde_class, (t_method)andand_tilde_dsp, + gensym("dsp"), 0); CLASS_MAINSIGNALIN(andand_tilde_class, t_andand_tilde, x_f); - class_addmethod (andand_tilde_class, (t_method)andand_tilde_help, gensym("help"), A_NULL); + class_addmethod (andand_tilde_class, (t_method)andand_tilde_help, + gensym("help"), A_NULL); class_sethelpsymbol(andand_tilde_class, gensym("zigbinops")); scalarandand_tilde_class = class_new(gensym("&&~"), 0, 0, - sizeof(t_scalarandand_tilde), 0, 0); + sizeof(t_scalarandand_tilde), 0, 0); CLASS_MAINSIGNALIN(scalarandand_tilde_class, t_scalarandand_tilde, x_f); - class_addmethod(scalarandand_tilde_class, (t_method)scalarandand_tilde_dsp, gensym("dsp"), - 0); - class_addmethod (scalarandand_tilde_class, (t_method)andand_tilde_help, gensym("help"), A_NULL); + class_addmethod(scalarandand_tilde_class, (t_method)scalarandand_tilde_dsp, + gensym("dsp"), + 0); + class_addmethod (scalarandand_tilde_class, (t_method)andand_tilde_help, + gensym("help"), A_NULL); class_sethelpsymbol(scalarandand_tilde_class, gensym("zigbinops")); zexy_register("&&~"); @@ -293,6 +312,6 @@ void setup_0x260x260x7e(void) #ifndef ZEXY_LIBRARY void setup(void) { - setup_0x260x260x7e(); + setup_0x260x260x7e(); } #endif diff --git a/src/0x2e.c b/src/0x2e.c index d138ed7..7dc06c9 100644 --- a/src/0x2e.c +++ b/src/0x2e.c @@ -1,4 +1,4 @@ -/* +/* * [.]: scala multiplication * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -23,8 +23,7 @@ static t_class *scalmul_class; static t_class *scalmul_scal_class; -typedef struct _scalmul -{ +typedef struct _scalmul { t_object x_obj; t_int n1, n2; @@ -35,7 +34,8 @@ typedef struct _scalmul } t_scalmul; -static void scalmul_lst2(t_scalmul *x, t_symbol *UNUSED(s), int argc, t_atom *argv) +static void scalmul_lst2(t_scalmul *x, t_symbol *UNUSED(s), int argc, + t_atom *argv) { t_float *fp; if (x->n2 != argc) { @@ -44,30 +44,35 @@ static void scalmul_lst2(t_scalmul *x, t_symbol *UNUSED(s), int argc, t_atom *ar x->buf2=(t_float *)getbytes(sizeof(t_float)*x->n2); }; fp = x->buf2; - while(argc--)*fp++=atom_getfloat(argv++); + while(argc--) { + *fp++=atom_getfloat(argv++); + } } -static void scalmul_lst(t_scalmul *x, t_symbol* UNUSED(s), int argc, t_atom *argv) +static void scalmul_lst(t_scalmul *x, t_symbol* UNUSED(s), int argc, + t_atom *argv) { t_float *fp; t_atom *ap; int n; - if (argc){ + if (argc) { if (x->n1 != argc) { freebytes(x->buf1, x->n1 * sizeof(t_float)); x->n1 = argc; x->buf1=(t_float *)getbytes(sizeof(t_float)*x->n1); }; fp = x->buf1; - while(argc--)*fp++=atom_getfloat(argv++); + while(argc--) { + *fp++=atom_getfloat(argv++); + } } - if (x->n1*x->n2==1){ + if (x->n1*x->n2==1) { outlet_float(x->x_obj.ob_outlet, *x->buf1**x->buf2); return; } - if (x->n1==1){ + if (x->n1==1) { t_atom *a; int i = x->n2; t_float f = *x->buf1; @@ -75,11 +80,11 @@ static void scalmul_lst(t_scalmul *x, t_symbol* UNUSED(s), int argc, t_atom *arg n = x->n2; ap = (t_atom *)getbytes(sizeof(t_atom)*n); a = ap; - while(i--){ + while(i--) { SETFLOAT(a, *fp++*f); a++; } - } else if (x->n2==1){ + } else if (x->n2==1) { t_float f = *x->buf2; t_atom *a; int i = x->n1; @@ -87,7 +92,7 @@ static void scalmul_lst(t_scalmul *x, t_symbol* UNUSED(s), int argc, t_atom *arg ap = (t_atom *)getbytes(sizeof(t_atom)*n); a = ap; fp = x->buf1; - while(i--){ + while(i--) { SETFLOAT(a, *fp++*f); a++; } @@ -97,14 +102,16 @@ static void scalmul_lst(t_scalmul *x, t_symbol* UNUSED(s), int argc, t_atom *arg t_float *fp2=x->buf2; fp = x->buf1; n = x->n1; - if (x->n1!=x->n2){ + if (x->n1!=x->n2) { post("scalar multiplication: truncating vectors to the same length"); - if (x->n2n1)n=x->n2; + if (x->n2n1) { + n=x->n2; + } } ap = (t_atom *)getbytes(sizeof(t_atom)*n); a = ap; i=n; - while(i--){ + while(i--) { SETFLOAT(a, *fp++**fp2++); a++; } @@ -121,10 +128,12 @@ static void scalmul_free(t_scalmul *x) static void *scalmul_new(t_symbol* UNUSED(s), int argc, t_atom *argv) { t_scalmul *x; - if (argc-1){ + if (argc-1) { x = (t_scalmul *)pd_new(scalmul_class); inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("list"), gensym("")); - } else x = (t_scalmul *)pd_new(scalmul_scal_class); + } else { + x = (t_scalmul *)pd_new(scalmul_scal_class); + } outlet_new(&x->x_obj, 0); @@ -132,14 +141,17 @@ static void *scalmul_new(t_symbol* UNUSED(s), int argc, t_atom *argv) x->buf1 =(t_float*)getbytes(sizeof(t_float)); *x->buf1=0; - if (argc)scalmul_lst2(x, gensym("list"), argc, argv); - else { + if (argc) { + scalmul_lst2(x, gensym("list"), argc, argv); + } else { x->n2 =1; x->buf2 =(t_float*)getbytes(sizeof(t_float)); *x->buf2=0; } - if (argc==1)floatinlet_new(&x->x_obj, x->buf2); + if (argc==1) { + floatinlet_new(&x->x_obj, x->buf2); + } return (x); } @@ -151,16 +163,19 @@ static void scalmul_help(t_scalmul*x) void setup_0x2e(void) { - scalmul_class = class_new(gensym("."), (t_newmethod)scalmul_new, - (t_method)scalmul_free, sizeof(t_scalmul), 0, A_GIMME, 0); + scalmul_class = class_new(gensym("."), (t_newmethod)scalmul_new, + (t_method)scalmul_free, sizeof(t_scalmul), 0, A_GIMME, 0); class_addlist(scalmul_class, scalmul_lst); - class_addmethod (scalmul_class, (t_method)scalmul_lst2, gensym(""), A_GIMME, 0); - class_addmethod(scalmul_class, (t_method)scalmul_help, gensym("help"), A_NULL); + class_addmethod (scalmul_class, (t_method)scalmul_lst2, gensym(""), + A_GIMME, 0); + class_addmethod(scalmul_class, (t_method)scalmul_help, gensym("help"), + A_NULL); - scalmul_scal_class = class_new(gensym("."), 0, (t_method)scalmul_free, - sizeof(t_scalmul), 0, 0); + scalmul_scal_class = class_new(gensym("."), 0, (t_method)scalmul_free, + sizeof(t_scalmul), 0, 0); class_addlist(scalmul_scal_class, scalmul_lst); - class_addmethod(scalmul_scal_class, (t_method)scalmul_help, gensym("help"), A_NULL); + class_addmethod(scalmul_scal_class, (t_method)scalmul_help, gensym("help"), + A_NULL); class_sethelpsymbol(scalmul_class, gensym("scalarmult")); class_sethelpsymbol(scalmul_scal_class, gensym("scalarmult")); @@ -170,6 +185,6 @@ void setup_0x2e(void) #ifndef ZEXY_LIBRARY void setup(void) { - setup_0x2e(); + setup_0x2e(); } #endif diff --git a/src/0x3c0x7e.c b/src/0x3c0x7e.c index 3a348bd..f3d5e83 100644 --- a/src/0x3c0x7e.c +++ b/src/0x3c0x7e.c @@ -1,4 +1,4 @@ -/* +/* * <~: signal comparision * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -25,14 +25,12 @@ /* ----------------------------- lt_tilde ----------------------------- */ static t_class *lt_tilde_class, *scalarlt_tilde_class; -typedef struct _lt_tilde -{ +typedef struct _lt_tilde { t_object x_obj; t_float x_f; } t_lt_tilde; -typedef struct _scalarlt_tilde -{ +typedef struct _scalarlt_tilde { t_object x_obj; t_float x_f; t_float x_g; /* inlet value */ @@ -40,24 +38,23 @@ typedef struct _scalarlt_tilde static void *lt_tilde_new(t_symbol *UNUSED(s), int argc, t_atom *argv) { - if (argc > 1) post("<~: extra arguments ignored"); - if (argc) - { - t_scalarlt_tilde *x = (t_scalarlt_tilde *)pd_new(scalarlt_tilde_class); - floatinlet_new(&x->x_obj, &x->x_g); - x->x_g = atom_getfloatarg(0, argc, argv); - outlet_new(&x->x_obj, gensym("signal")); - x->x_f = 0; - return (x); - } - else - { - t_lt_tilde *x = (t_lt_tilde *)pd_new(lt_tilde_class); - inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("signal"), gensym("signal")); - outlet_new(&x->x_obj, gensym("signal")); - x->x_f = 0; - return (x); - } + if (argc > 1) { + post("<~: extra arguments ignored"); + } + if (argc) { + t_scalarlt_tilde *x = (t_scalarlt_tilde *)pd_new(scalarlt_tilde_class); + floatinlet_new(&x->x_obj, &x->x_g); + x->x_g = atom_getfloatarg(0, argc, argv); + outlet_new(&x->x_obj, gensym("signal")); + x->x_f = 0; + return (x); + } else { + t_lt_tilde *x = (t_lt_tilde *)pd_new(lt_tilde_class); + inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("signal"), gensym("signal")); + outlet_new(&x->x_obj, gensym("signal")); + x->x_f = 0; + return (x); + } } static t_int *lt_tilde_perform(t_int *w) @@ -66,7 +63,9 @@ static t_int *lt_tilde_perform(t_int *w) t_sample *in2 = (t_sample *)(w[2]); t_sample *out = (t_sample *)(w[3]); int n = (int)(w[4]); - while (n--) *out++ = *in1++ < *in2++; + while (n--) { + *out++ = *in1++ < *in2++; + } return (w+5); } @@ -76,17 +75,22 @@ static t_int *lt_tilde_perf8(t_int *w) t_sample *in2 = (t_sample *)(w[2]); t_sample *out = (t_sample *)(w[3]); int n = (int)(w[4]); - for (; n; n -= 8, in1 += 8, in2 += 8, out += 8) - { - t_sample f0 = in1[0], f1 = in1[1], f2 = in1[2], f3 = in1[3]; - t_sample f4 = in1[4], f5 = in1[5], f6 = in1[6], f7 = in1[7]; - - t_sample g0 = in2[0], g1 = in2[1], g2 = in2[2], g3 = in2[3]; - t_sample g4 = in2[4], g5 = in2[5], g6 = in2[6], g7 = in2[7]; - - out[0] = f0 < g0; out[1] = f1 < g1; out[2] = f2 < g2; out[3] = f3 < g3; - out[4] = f4 < g4; out[5] = f5 < g5; out[6] = f6 < g6; out[7] = f7 < g7; - } + for (; n; n -= 8, in1 += 8, in2 += 8, out += 8) { + t_sample f0 = in1[0], f1 = in1[1], f2 = in1[2], f3 = in1[3]; + t_sample f4 = in1[4], f5 = in1[5], f6 = in1[6], f7 = in1[7]; + + t_sample g0 = in2[0], g1 = in2[1], g2 = in2[2], g3 = in2[3]; + t_sample g4 = in2[4], g5 = in2[5], g6 = in2[6], g7 = in2[7]; + + out[0] = f0 < g0; + out[1] = f1 < g1; + out[2] = f2 < g2; + out[3] = f3 < g3; + out[4] = f4 < g4; + out[5] = f5 < g5; + out[6] = f6 < g6; + out[7] = f7 < g7; + } return (w+5); } @@ -96,7 +100,9 @@ static t_int *scalarlt_tilde_perform(t_int *w) t_sample f = *(t_float *)(w[2]); t_sample *out = (t_sample *)(w[3]); int n = (int)(w[4]); - while (n--) *out++ = *in++ < f; + while (n--) { + *out++ = *in++ < f; + } return (w+5); } @@ -106,14 +112,19 @@ static t_int *scalarlt_tilde_perf8(t_int *w) t_sample g = *(t_float *)(w[2]); t_sample *out = (t_sample *)(w[3]); int n = (int)(w[4]); - for (; n; n -= 8, in += 8, out += 8) - { - t_sample f0 = in[0], f1 = in[1], f2 = in[2], f3 = in[3]; - t_sample f4 = in[4], f5 = in[5], f6 = in[6], f7 = in[7]; - - out[0] = f0 < g; out[1] = f1 < g; out[2] = f2 < g; out[3] = f3 < g; - out[4] = f4 < g; out[5] = f5 < g; out[6] = f6 < g; out[7] = f7 < g; - } + for (; n; n -= 8, in += 8, out += 8) { + t_sample f0 = in[0], f1 = in[1], f2 = in[2], f3 = in[3]; + t_sample f4 = in[4], f5 = in[5], f6 = in[6], f7 = in[7]; + + out[0] = f0 < g; + out[1] = f1 < g; + out[2] = f2 < g; + out[3] = f3 < g; + out[4] = f4 < g; + out[5] = f5 < g; + out[6] = f6 < g; + out[7] = f7 < g; + } return (w+5); } #ifdef __SSE__ @@ -142,7 +153,7 @@ static t_int *lt_tilde_performSSE(t_int *w) in1+=4; in2+=4; out+=4; - } + } return (w+5); } @@ -185,20 +196,20 @@ static void lt_tilde_dsp(t_lt_tilde* UNUSED(x), t_signal **sp) int n=sp[0]->s_n; #ifdef __SSE__ if( - Z_SIMD_CHKBLOCKSIZE(n)&& - Z_SIMD_CHKALIGN(in1)&& - Z_SIMD_CHKALIGN(in2)&& - Z_SIMD_CHKALIGN(out)&& - ZEXY_TYPE_EQUAL(t_sample, float) - ) - { - dsp_add(lt_tilde_performSSE, 4, in1, in2, out, n); - } else + Z_SIMD_CHKBLOCKSIZE(n)&& + Z_SIMD_CHKALIGN(in1)&& + Z_SIMD_CHKALIGN(in2)&& + Z_SIMD_CHKALIGN(out)&& + ZEXY_TYPE_EQUAL(t_sample, float) + ) { + dsp_add(lt_tilde_performSSE, 4, in1, in2, out, n); + } else #endif - if(n&7) - dsp_add(lt_tilde_perform, 4, in1, in2, out, n); - else - dsp_add(lt_tilde_perf8, 4, in1, in2, out, n); + if(n&7) { + dsp_add(lt_tilde_perform, 4, in1, in2, out, n); + } else { + dsp_add(lt_tilde_perf8, 4, in1, in2, out, n); + } } static void scalarlt_tilde_dsp(t_scalarlt_tilde *x, t_signal **sp) @@ -209,19 +220,19 @@ static void scalarlt_tilde_dsp(t_scalarlt_tilde *x, t_signal **sp) #ifdef __SSE__ if( - Z_SIMD_CHKBLOCKSIZE(n)&& - Z_SIMD_CHKALIGN(in)&& - Z_SIMD_CHKALIGN(out)&& - ZEXY_TYPE_EQUAL(t_sample, float) - ) - { - dsp_add(scalarlt_tilde_performSSE, 4, in, &x->x_g, out, n); - } else + Z_SIMD_CHKBLOCKSIZE(n)&& + Z_SIMD_CHKALIGN(in)&& + Z_SIMD_CHKALIGN(out)&& + ZEXY_TYPE_EQUAL(t_sample, float) + ) { + dsp_add(scalarlt_tilde_performSSE, 4, in, &x->x_g, out, n); + } else #endif - if (n&7) - dsp_add(scalarlt_tilde_perform, 4, in, &x->x_g, out, n); - else - dsp_add(scalarlt_tilde_perf8, 4, in, &x->x_g, out, n); + if (n&7) { + dsp_add(scalarlt_tilde_perform, 4, in, &x->x_g, out, n); + } else { + dsp_add(scalarlt_tilde_perf8, 4, in, &x->x_g, out, n); + } } static void lt_tilde_help(t_object*x) { @@ -231,18 +242,21 @@ static void lt_tilde_help(t_object*x) void setup_0x3c0x7e(void) { lt_tilde_class = class_new(gensym("<~"), (t_newmethod)lt_tilde_new, 0, - sizeof(t_lt_tilde), 0, A_GIMME, 0); + sizeof(t_lt_tilde), 0, A_GIMME, 0); class_addmethod(lt_tilde_class, (t_method)lt_tilde_dsp, gensym("dsp"), 0); CLASS_MAINSIGNALIN(lt_tilde_class, t_lt_tilde, x_f); - class_addmethod (lt_tilde_class, (t_method)lt_tilde_help, gensym("help"), A_NULL); + class_addmethod (lt_tilde_class, (t_method)lt_tilde_help, gensym("help"), + A_NULL); class_sethelpsymbol(lt_tilde_class, gensym("zigbinops")); scalarlt_tilde_class = class_new(gensym("<~"), 0, 0, - sizeof(t_scalarlt_tilde), 0, 0); + sizeof(t_scalarlt_tilde), 0, 0); CLASS_MAINSIGNALIN(scalarlt_tilde_class, t_scalarlt_tilde, x_f); - class_addmethod(scalarlt_tilde_class, (t_method)scalarlt_tilde_dsp, gensym("dsp"), - 0); - class_addmethod (scalarlt_tilde_class, (t_method)lt_tilde_help, gensym("help"), A_NULL); + class_addmethod(scalarlt_tilde_class, (t_method)scalarlt_tilde_dsp, + gensym("dsp"), + 0); + class_addmethod (scalarlt_tilde_class, (t_method)lt_tilde_help, + gensym("help"), A_NULL); class_sethelpsymbol(scalarlt_tilde_class, gensym("zigbinops")); zexy_register("<~"); } @@ -250,6 +264,6 @@ void setup_0x3c0x7e(void) #ifndef ZEXY_LIBRARY void setup(void) { - setup_0x3c0x7e(); + setup_0x3c0x7e(); } #endif diff --git a/src/0x3d0x3d0x7e.c b/src/0x3d0x3d0x7e.c index 94211dd..689ea12 100644 --- a/src/0x3d0x3d0x7e.c +++ b/src/0x3d0x3d0x7e.c @@ -1,4 +1,4 @@ -/* +/* * ==~: test signals for equality * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -22,14 +22,12 @@ /* ----------------------------- eq_tilde ----------------------------- */ static t_class *eq_tilde_class, *scalareq_tilde_class; -typedef struct _eq_tilde -{ +typedef struct _eq_tilde { t_object x_obj; t_float x_f; } t_eq_tilde; -typedef struct _scalareq_tilde -{ +typedef struct _scalareq_tilde { t_object x_obj; t_float x_f; t_float x_g; /* inlet value */ @@ -37,24 +35,23 @@ typedef struct _scalareq_tilde static void *eq_tilde_new(t_symbol* UNUSED(s), int argc, t_atom *argv) { - if (argc > 1) post("==~: extra arguments ignored"); - if (argc) - { - t_scalareq_tilde *x = (t_scalareq_tilde *)pd_new(scalareq_tilde_class); - floatinlet_new(&x->x_obj, &x->x_g); - x->x_g = atom_getfloatarg(0, argc, argv); - outlet_new(&x->x_obj, gensym("signal")); - x->x_f = 0; - return (x); - } - else - { - t_eq_tilde *x = (t_eq_tilde *)pd_new(eq_tilde_class); - inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("signal"), gensym("signal")); - outlet_new(&x->x_obj, gensym("signal")); - x->x_f = 0; - return (x); - } + if (argc > 1) { + post("==~: extra arguments ignored"); + } + if (argc) { + t_scalareq_tilde *x = (t_scalareq_tilde *)pd_new(scalareq_tilde_class); + floatinlet_new(&x->x_obj, &x->x_g); + x->x_g = atom_getfloatarg(0, argc, argv); + outlet_new(&x->x_obj, gensym("signal")); + x->x_f = 0; + return (x); + } else { + t_eq_tilde *x = (t_eq_tilde *)pd_new(eq_tilde_class); + inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("signal"), gensym("signal")); + outlet_new(&x->x_obj, gensym("signal")); + x->x_f = 0; + return (x); + } } static t_int *eq_tilde_perform(t_int *w) @@ -63,7 +60,9 @@ static t_int *eq_tilde_perform(t_int *w) t_sample *in2 = (t_sample *)(w[2]); t_sample *out = (t_sample *)(w[3]); int n = (int)(w[4]); - while (n--) *out++ = (*in1++ == *in2++); + while (n--) { + *out++ = (*in1++ == *in2++); + } return (w+5); } @@ -73,17 +72,22 @@ static t_int *eq_tilde_perf8(t_int *w) t_sample *in2 = (t_sample *)(w[2]); t_sample *out = (t_sample *)(w[3]); int n = (int)(w[4]); - for (; n; n -= 8, in1 += 8, in2 += 8, out += 8) - { - t_sample f0 = in1[0], f1 = in1[1], f2 = in1[2], f3 = in1[3]; - t_sample f4 = in1[4], f5 = in1[5], f6 = in1[6], f7 = in1[7]; - - t_sample g0 = in2[0], g1 = in2[1], g2 = in2[2], g3 = in2[3]; - t_sample g4 = in2[4], g5 = in2[5], g6 = in2[6], g7 = in2[7]; - - out[0] = f0 == g0; out[1] = f1 == g1; out[2] = f2 == g2; out[3] = f3 == g3; - out[4] = f4 == g4; out[5] = f5 == g5; out[6] = f6 == g6; out[7] = f7 == g7; - } + for (; n; n -= 8, in1 += 8, in2 += 8, out += 8) { + t_sample f0 = in1[0], f1 = in1[1], f2 = in1[2], f3 = in1[3]; + t_sample f4 = in1[4], f5 = in1[5], f6 = in1[6], f7 = in1[7]; + + t_sample g0 = in2[0], g1 = in2[1], g2 = in2[2], g3 = in2[3]; + t_sample g4 = in2[4], g5 = in2[5], g6 = in2[6], g7 = in2[7]; + + out[0] = f0 == g0; + out[1] = f1 == g1; + out[2] = f2 == g2; + out[3] = f3 == g3; + out[4] = f4 == g4; + out[5] = f5 == g5; + out[6] = f6 == g6; + out[7] = f7 == g7; + } return (w+5); } @@ -93,7 +97,9 @@ static t_int *scalareq_tilde_perform(t_int *w) t_sample f = *(t_float *)(w[2]); t_sample *out = (t_sample *)(w[3]); int n = (int)(w[4]); - while (n--) *out++ = (*in++ == f); + while (n--) { + *out++ = (*in++ == f); + } return (w+5); } @@ -103,14 +109,19 @@ static t_int *scalareq_tilde_perf8(t_int *w) t_sample g = *(t_float *)(w[2]); t_sample *out = (t_sample *)(w[3]); int n = (int)(w[4]); - for (; n; n -= 8, in += 8, out += 8) - { - t_sample f0 = in[0], f1 = in[1], f2 = in[2], f3 = in[3]; - t_sample f4 = in[4], f5 = in[5], f6 = in[6], f7 = in[7]; + for (; n; n -= 8, in += 8, out += 8) { + t_sample f0 = in[0], f1 = in[1], f2 = in[2], f3 = in[3]; + t_sample f4 = in[4], f5 = in[5], f6 = in[6], f7 = in[7]; - out[0] = (f0 == g); out[1] = (f1 == g); out[2] = (f2 == g); out[3] = (f3 == g); - out[4] = (f4 == g); out[5] = (f5 == g); out[6] = (f6 == g); out[7] = (f7 == g); - } + out[0] = (f0 == g); + out[1] = (f1 == g); + out[2] = (f2 == g); + out[3] = (f3 == g); + out[4] = (f4 == g); + out[5] = (f5 == g); + out[6] = (f6 == g); + out[7] = (f7 == g); + } return (w+5); } @@ -140,7 +151,7 @@ static t_int *eq_tilde_performSSE(t_int *w) in1+=4; in2+=4; out+=4; - } + } return (w+5); } @@ -184,20 +195,20 @@ static void eq_tilde_dsp(t_eq_tilde* UNUSED(x), t_signal **sp) #ifdef __SSE__ if( - Z_SIMD_CHKBLOCKSIZE(n)&& - Z_SIMD_CHKALIGN(in1)&& - Z_SIMD_CHKALIGN(in2)&& - Z_SIMD_CHKALIGN(out)&& - ZEXY_TYPE_EQUAL(t_sample, float) - ) - { - dsp_add(eq_tilde_performSSE, 4, in1, in2, out, n); - } else + Z_SIMD_CHKBLOCKSIZE(n)&& + Z_SIMD_CHKALIGN(in1)&& + Z_SIMD_CHKALIGN(in2)&& + Z_SIMD_CHKALIGN(out)&& + ZEXY_TYPE_EQUAL(t_sample, float) + ) { + dsp_add(eq_tilde_performSSE, 4, in1, in2, out, n); + } else #endif - if (n&7) - dsp_add(eq_tilde_perform, 4, in1, in2, out, n); - else - dsp_add(eq_tilde_perf8, 4, in1, in2, out, n); + if (n&7) { + dsp_add(eq_tilde_perform, 4, in1, in2, out, n); + } else { + dsp_add(eq_tilde_perf8, 4, in1, in2, out, n); + } } static void scalareq_tilde_dsp(t_scalareq_tilde *x, t_signal **sp) @@ -208,19 +219,19 @@ static void scalareq_tilde_dsp(t_scalareq_tilde *x, t_signal **sp) #ifdef __SSE__ if( - Z_SIMD_CHKBLOCKSIZE(n)&& - Z_SIMD_CHKALIGN(in)&& - Z_SIMD_CHKALIGN(out) && - ZEXY_TYPE_EQUAL(t_sample, float) - ) - { - dsp_add(scalareq_tilde_performSSE, 4, in, &x->x_g, out, n); - } else + Z_SIMD_CHKBLOCKSIZE(n)&& + Z_SIMD_CHKALIGN(in)&& + Z_SIMD_CHKALIGN(out) && + ZEXY_TYPE_EQUAL(t_sample, float) + ) { + dsp_add(scalareq_tilde_performSSE, 4, in, &x->x_g, out, n); + } else #endif - if (n&7) - dsp_add(scalareq_tilde_perform, 4, in, &x->x_g, out, n); - else - dsp_add(scalareq_tilde_perf8, 4, in, &x->x_g, out, n); + if (n&7) { + dsp_add(scalareq_tilde_perform, 4, in, &x->x_g, out, n); + } else { + dsp_add(scalareq_tilde_perf8, 4, in, &x->x_g, out, n); + } } static void eq_tilde_help(t_object*x) @@ -230,18 +241,21 @@ static void eq_tilde_help(t_object*x) void setup_0x3d0x3d0x7e(void) { eq_tilde_class = class_new(gensym("==~"), (t_newmethod)eq_tilde_new, 0, - sizeof(t_eq_tilde), 0, A_GIMME, 0); + sizeof(t_eq_tilde), 0, A_GIMME, 0); class_addmethod(eq_tilde_class, (t_method)eq_tilde_dsp, gensym("dsp"), 0); CLASS_MAINSIGNALIN(eq_tilde_class, t_eq_tilde, x_f); - class_addmethod (eq_tilde_class, (t_method)eq_tilde_help, gensym("help"), A_NULL); + class_addmethod (eq_tilde_class, (t_method)eq_tilde_help, gensym("help"), + A_NULL); class_sethelpsymbol(eq_tilde_class, gensym("zigbinops")); scalareq_tilde_class = class_new(gensym("==~"), 0, 0, - sizeof(t_scalareq_tilde), 0, 0); + sizeof(t_scalareq_tilde), 0, 0); CLASS_MAINSIGNALIN(scalareq_tilde_class, t_scalareq_tilde, x_f); - class_addmethod(scalareq_tilde_class, (t_method)scalareq_tilde_dsp, gensym("dsp"), - 0); - class_addmethod (scalareq_tilde_class, (t_method)eq_tilde_help, gensym("help"), A_NULL); + class_addmethod(scalareq_tilde_class, (t_method)scalareq_tilde_dsp, + gensym("dsp"), + 0); + class_addmethod (scalareq_tilde_class, (t_method)eq_tilde_help, + gensym("help"), A_NULL); class_sethelpsymbol(scalareq_tilde_class, gensym("zigbinops")); zexy_register("==~"); @@ -250,6 +264,6 @@ void setup_0x3d0x3d0x7e(void) #ifndef ZEXY_LIBRARY void setup(void) { - setup_0x3d0x3d0x7e(); + setup_0x3d0x3d0x7e(); } #endif diff --git a/src/0x3e0x7e.c b/src/0x3e0x7e.c index 766778d..eef7592 100644 --- a/src/0x3e0x7e.c +++ b/src/0x3e0x7e.c @@ -1,4 +1,4 @@ -/* +/* * >~: signal comparision * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -25,14 +25,12 @@ /* ----------------------------- gt_tilde ----------------------------- */ static t_class *gt_tilde_class, *scalargt_tilde_class; -typedef struct _gt_tilde -{ +typedef struct _gt_tilde { t_object x_obj; t_float x_f; } t_gt_tilde; -typedef struct _scalargt_tilde -{ +typedef struct _scalargt_tilde { t_object x_obj; t_float x_f; t_float x_g; /* inlet value */ @@ -40,24 +38,23 @@ typedef struct _scalargt_tilde static void *gt_tilde_new(t_symbol* UNUSED(s), int argc, t_atom *argv) { - if (argc > 1) post(">~: extra arguments ignored"); - if (argc) - { - t_scalargt_tilde *x = (t_scalargt_tilde *)pd_new(scalargt_tilde_class); - floatinlet_new(&x->x_obj, &x->x_g); - x->x_g = atom_getfloatarg(0, argc, argv); - outlet_new(&x->x_obj, gensym("signal")); - x->x_f = 0; - return (x); - } - else - { - t_gt_tilde *x = (t_gt_tilde *)pd_new(gt_tilde_class); - inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("signal"), gensym("signal")); - outlet_new(&x->x_obj, gensym("signal")); - x->x_f = 0; - return (x); - } + if (argc > 1) { + post(">~: extra arguments ignored"); + } + if (argc) { + t_scalargt_tilde *x = (t_scalargt_tilde *)pd_new(scalargt_tilde_class); + floatinlet_new(&x->x_obj, &x->x_g); + x->x_g = atom_getfloatarg(0, argc, argv); + outlet_new(&x->x_obj, gensym("signal")); + x->x_f = 0; + return (x); + } else { + t_gt_tilde *x = (t_gt_tilde *)pd_new(gt_tilde_class); + inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("signal"), gensym("signal")); + outlet_new(&x->x_obj, gensym("signal")); + x->x_f = 0; + return (x); + } } static t_int *gt_tilde_perform(t_int *w) @@ -66,7 +63,9 @@ static t_int *gt_tilde_perform(t_int *w) t_sample *in2 = (t_sample *)(w[2]); t_sample *out = (t_sample *)(w[3]); int n = (int)(w[4]); - while (n--) *out++ = *in1++ > *in2++; + while (n--) { + *out++ = *in1++ > *in2++; + } return (w+5); } @@ -76,17 +75,22 @@ static t_int *gt_tilde_perf8(t_int *w) t_sample *in2 = (t_sample *)(w[2]); t_sample *out = (t_sample *)(w[3]); int n = (int)(w[4]); - for (; n; n -= 8, in1 += 8, in2 += 8, out += 8) - { - t_sample f0 = in1[0], f1 = in1[1], f2 = in1[2], f3 = in1[3]; - t_sample f4 = in1[4], f5 = in1[5], f6 = in1[6], f7 = in1[7]; - - t_sample g0 = in2[0], g1 = in2[1], g2 = in2[2], g3 = in2[3]; - t_sample g4 = in2[4], g5 = in2[5], g6 = in2[6], g7 = in2[7]; - - out[0] = f0 > g0; out[1] = f1 > g1; out[2] = f2 > g2; out[3] = f3 > g3; - out[4] = f4 > g4; out[5] = f5 > g5; out[6] = f6 > g6; out[7] = f7 > g7; - } + for (; n; n -= 8, in1 += 8, in2 += 8, out += 8) { + t_sample f0 = in1[0], f1 = in1[1], f2 = in1[2], f3 = in1[3]; + t_sample f4 = in1[4], f5 = in1[5], f6 = in1[6], f7 = in1[7]; + + t_sample g0 = in2[0], g1 = in2[1], g2 = in2[2], g3 = in2[3]; + t_sample g4 = in2[4], g5 = in2[5], g6 = in2[6], g7 = in2[7]; + + out[0] = f0 > g0; + out[1] = f1 > g1; + out[2] = f2 > g2; + out[3] = f3 > g3; + out[4] = f4 > g4; + out[5] = f5 > g5; + out[6] = f6 > g6; + out[7] = f7 > g7; + } return (w+5); } @@ -96,7 +100,9 @@ static t_int *scalargt_tilde_perform(t_int *w) t_sample f = *(t_float *)(w[2]); t_sample *out = (t_sample *)(w[3]); int n = (int)(w[4]); - while (n--) *out++ = *in++ > f; + while (n--) { + *out++ = *in++ > f; + } return (w+5); } @@ -106,14 +112,19 @@ static t_int *scalargt_tilde_perf8(t_int *w) t_sample g = *(t_float *)(w[2]); t_sample *out = (t_sample *)(w[3]); int n = (int)(w[4]); - for (; n; n -= 8, in += 8, out += 8) - { - t_sample f0 = in[0], f1 = in[1], f2 = in[2], f3 = in[3]; - t_sample f4 = in[4], f5 = in[5], f6 = in[6], f7 = in[7]; - - out[0] = f0 > g; out[1] = f1 > g; out[2] = f2 > g; out[3] = f3 > g; - out[4] = f4 > g; out[5] = f5 > g; out[6] = f6 > g; out[7] = f7 > g; - } + for (; n; n -= 8, in += 8, out += 8) { + t_sample f0 = in[0], f1 = in[1], f2 = in[2], f3 = in[3]; + t_sample f4 = in[4], f5 = in[5], f6 = in[6], f7 = in[7]; + + out[0] = f0 > g; + out[1] = f1 > g; + out[2] = f2 > g; + out[3] = f3 > g; + out[4] = f4 > g; + out[5] = f5 > g; + out[6] = f6 > g; + out[7] = f7 > g; + } return (w+5); } #ifdef __SSE__ @@ -142,7 +153,7 @@ static t_int *gt_tilde_performSSE(t_int *w) in1+=4; in2+=4; out+=4; - } + } return (w+5); } @@ -187,20 +198,20 @@ static void gt_tilde_dsp(t_gt_tilde* UNUSED(x), t_signal **sp) #ifdef __SSE__ if( - Z_SIMD_CHKBLOCKSIZE(n)&& - Z_SIMD_CHKALIGN(in1)&& - Z_SIMD_CHKALIGN(in2)&& - Z_SIMD_CHKALIGN(out)&& - ZEXY_TYPE_EQUAL(t_sample, float) - ) - { - dsp_add(gt_tilde_performSSE, 4, in1, in2, out, n); - } else + Z_SIMD_CHKBLOCKSIZE(n)&& + Z_SIMD_CHKALIGN(in1)&& + Z_SIMD_CHKALIGN(in2)&& + Z_SIMD_CHKALIGN(out)&& + ZEXY_TYPE_EQUAL(t_sample, float) + ) { + dsp_add(gt_tilde_performSSE, 4, in1, in2, out, n); + } else #endif - if (n&7) - dsp_add(gt_tilde_perform, 4, in1, in2, out, n); - else - dsp_add(gt_tilde_perf8, 4, in1, in2, out, n); + if (n&7) { + dsp_add(gt_tilde_perform, 4, in1, in2, out, n); + } else { + dsp_add(gt_tilde_perf8, 4, in1, in2, out, n); + } } static void scalargt_tilde_dsp(t_scalargt_tilde *x, t_signal **sp) @@ -211,19 +222,19 @@ static void scalargt_tilde_dsp(t_scalargt_tilde *x, t_signal **sp) #ifdef __SSE__ if( - Z_SIMD_CHKBLOCKSIZE(n)&& - Z_SIMD_CHKALIGN(in)&& - Z_SIMD_CHKALIGN(out)&& - ZEXY_TYPE_EQUAL(t_sample, float) - ) - { - dsp_add(scalargt_tilde_performSSE, 4, in, &x->x_g, out, n); - } else + Z_SIMD_CHKBLOCKSIZE(n)&& + Z_SIMD_CHKALIGN(in)&& + Z_SIMD_CHKALIGN(out)&& + ZEXY_TYPE_EQUAL(t_sample, float) + ) { + dsp_add(scalargt_tilde_performSSE, 4, in, &x->x_g, out, n); + } else #endif - if (n&7) - dsp_add(scalargt_tilde_perform, 4, in, &x->x_g, out, n); - else - dsp_add(scalargt_tilde_perf8, 4, in, &x->x_g, out, n); + if (n&7) { + dsp_add(scalargt_tilde_perform, 4, in, &x->x_g, out, n); + } else { + dsp_add(scalargt_tilde_perf8, 4, in, &x->x_g, out, n); + } } static void gt_tilde_help(t_object*x) @@ -234,18 +245,21 @@ static void gt_tilde_help(t_object*x) void setup_0x3e0x7e(void) { gt_tilde_class = class_new(gensym(">~"), (t_newmethod)gt_tilde_new, 0, - sizeof(t_gt_tilde), 0, A_GIMME, 0); + sizeof(t_gt_tilde), 0, A_GIMME, 0); class_addmethod(gt_tilde_class, (t_method)gt_tilde_dsp, gensym("dsp"), 0); CLASS_MAINSIGNALIN(gt_tilde_class, t_gt_tilde, x_f); - class_addmethod (gt_tilde_class, (t_method)gt_tilde_help, gensym("help"), A_NULL); + class_addmethod (gt_tilde_class, (t_method)gt_tilde_help, gensym("help"), + A_NULL); class_sethelpsymbol(gt_tilde_class, gensym("zigbinops")); scalargt_tilde_class = class_new(gensym(">~"), 0, 0, - sizeof(t_scalargt_tilde), 0, 0); + sizeof(t_scalargt_tilde), 0, 0); CLASS_MAINSIGNALIN(scalargt_tilde_class, t_scalargt_tilde, x_f); - class_addmethod(scalargt_tilde_class, (t_method)scalargt_tilde_dsp, gensym("dsp"), - 0); - class_addmethod (scalargt_tilde_class, (t_method)gt_tilde_help, gensym("help"), A_NULL); + class_addmethod(scalargt_tilde_class, (t_method)scalargt_tilde_dsp, + gensym("dsp"), + 0); + class_addmethod (scalargt_tilde_class, (t_method)gt_tilde_help, + gensym("help"), A_NULL); class_sethelpsymbol(scalargt_tilde_class, gensym("zigbinops")); zexy_register(">~"); @@ -254,6 +268,6 @@ void setup_0x3e0x7e(void) #ifndef ZEXY_LIBRARY void setup(void) { - setup_0x3e0x7e(); + setup_0x3e0x7e(); } #endif diff --git a/src/0x7c0x7c0x7e.c b/src/0x7c0x7c0x7e.c index e0cc4dd..f31fba0 100644 --- a/src/0x7c0x7c0x7e.c +++ b/src/0x7c0x7c0x7e.c @@ -1,4 +1,4 @@ -/* +/* * ||~: logical OR for signals * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -22,14 +22,12 @@ /* ----------------------------- oror_tilde ----------------------------- */ static t_class *oror_tilde_class, *scalaroror_tilde_class; -typedef struct _oror_tilde -{ +typedef struct _oror_tilde { t_object x_obj; t_float x_f; } t_oror_tilde; -typedef struct _scalaroror_tilde -{ +typedef struct _scalaroror_tilde { t_object x_obj; t_float x_f; t_float x_g; /* inlet value */ @@ -37,24 +35,24 @@ typedef struct _scalaroror_tilde static void *oror_tilde_new(t_symbol* UNUSED(s), int argc, t_atom *argv) { - if (argc > 1) post("||~: extra arguments ignored"); - if (argc) - { - t_scalaroror_tilde *x = (t_scalaroror_tilde *)pd_new(scalaroror_tilde_class); - floatinlet_new(&x->x_obj, &x->x_g); - x->x_g = atom_getfloatarg(0, argc, argv); - outlet_new(&x->x_obj, gensym("signal")); - x->x_f = 0; - return (x); - } - else - { - t_oror_tilde *x = (t_oror_tilde *)pd_new(oror_tilde_class); - inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("signal"), gensym("signal")); - outlet_new(&x->x_obj, gensym("signal")); - x->x_f = 0; - return (x); - } + if (argc > 1) { + post("||~: extra arguments ignored"); + } + if (argc) { + t_scalaroror_tilde *x = (t_scalaroror_tilde *)pd_new( + scalaroror_tilde_class); + floatinlet_new(&x->x_obj, &x->x_g); + x->x_g = atom_getfloatarg(0, argc, argv); + outlet_new(&x->x_obj, gensym("signal")); + x->x_f = 0; + return (x); + } else { + t_oror_tilde *x = (t_oror_tilde *)pd_new(oror_tilde_class); + inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("signal"), gensym("signal")); + outlet_new(&x->x_obj, gensym("signal")); + x->x_f = 0; + return (x); + } } static t_int *oror_tilde_perform(t_int *w) @@ -63,7 +61,9 @@ static t_int *oror_tilde_perform(t_int *w) t_float *in2 = (t_float *)(w[2]); t_float *out = (t_float *)(w[3]); int n = (int)(w[4]); - while (n--) *out++ = (int)*in1++ || (int)*in2++; + while (n--) { + *out++ = (int)*in1++ || (int)*in2++; + } return (w+5); } @@ -73,17 +73,22 @@ static t_int *oror_tilde_perf8(t_int *w) t_float *in2 = (t_float *)(w[2]); t_float *out = (t_float *)(w[3]); int n = (int)(w[4]); - for (; n; n -= 8, in1 += 8, in2 += 8, out += 8) - { - int f0 = in1[0], f1 = in1[1], f2 = in1[2], f3 = in1[3]; - int f4 = in1[4], f5 = in1[5], f6 = in1[6], f7 = in1[7]; - - int g0 = in2[0], g1 = in2[1], g2 = in2[2], g3 = in2[3]; - int g4 = in2[4], g5 = in2[5], g6 = in2[6], g7 = in2[7]; - - out[0] = f0 || g0; out[1] = f1 || g1; out[2] = f2 || g2; out[3] = f3 || g3; - out[4] = f4 || g4; out[5] = f5 || g5; out[6] = f6 || g6; out[7] = f7 || g7; - } + for (; n; n -= 8, in1 += 8, in2 += 8, out += 8) { + int f0 = in1[0], f1 = in1[1], f2 = in1[2], f3 = in1[3]; + int f4 = in1[4], f5 = in1[5], f6 = in1[6], f7 = in1[7]; + + int g0 = in2[0], g1 = in2[1], g2 = in2[2], g3 = in2[3]; + int g4 = in2[4], g5 = in2[5], g6 = in2[6], g7 = in2[7]; + + out[0] = f0 || g0; + out[1] = f1 || g1; + out[2] = f2 || g2; + out[3] = f3 || g3; + out[4] = f4 || g4; + out[5] = f5 || g5; + out[6] = f6 || g6; + out[7] = f7 || g7; + } return (w+5); } @@ -93,7 +98,9 @@ static t_int *scalaroror_tilde_perform(t_int *w) int f = *(t_float *)(w[2]); t_float *out = (t_float *)(w[3]); int n = (int)(w[4]); - while (n--) *out++ = (int)*in++ || f; + while (n--) { + *out++ = (int)*in++ || f; + } return (w+5); } @@ -103,14 +110,19 @@ static t_int *scalaroror_tilde_perf8(t_int *w) int g = *(t_float *)(w[2]); t_float *out = (t_float *)(w[3]); int n = (int)(w[4]); - for (; n; n -= 8, in += 8, out += 8) - { - int f0 = in[0], f1 = in[1], f2 = in[2], f3 = in[3]; - int f4 = in[4], f5 = in[5], f6 = in[6], f7 = in[7]; - - out[0] = f0 || g; out[1] = f1 || g; out[2] = f2 || g; out[3] = f3 || g; - out[4] = f4 || g; out[5] = f5 || g; out[6] = f6 || g; out[7] = f7 || g; - } + for (; n; n -= 8, in += 8, out += 8) { + int f0 = in[0], f1 = in[1], f2 = in[2], f3 = in[3]; + int f4 = in[4], f5 = in[5], f6 = in[6], f7 = in[7]; + + out[0] = f0 || g; + out[1] = f1 || g; + out[2] = f2 || g; + out[3] = f3 || g; + out[4] = f4 || g; + out[5] = f5 || g; + out[6] = f6 || g; + out[7] = f7 || g; + } return (w+5); } @@ -149,7 +161,7 @@ static t_int *oror_tilde_performSSE(t_int *w) in1+=4; in2+=4; out+=4; - } + } return (w+5); } @@ -200,21 +212,21 @@ static void oror_tilde_dsp(t_oror_tilde* UNUSED(x), t_signal **sp) #ifdef __SSE__ if( - 0 && /* disabled for now since SSE2 code not compatible with [||] */ - Z_SIMD_CHKBLOCKSIZE(n)&& - Z_SIMD_CHKALIGN(in1)&& - Z_SIMD_CHKALIGN(in2)&& - Z_SIMD_CHKALIGN(out)&& - ZEXY_TYPE_EQUAL(t_sample, float) - ) - { - dsp_add(oror_tilde_performSSE, 4, in1, in2, out, n); - } else + 0 && /* disabled for now since SSE2 code not compatible with [||] */ + Z_SIMD_CHKBLOCKSIZE(n)&& + Z_SIMD_CHKALIGN(in1)&& + Z_SIMD_CHKALIGN(in2)&& + Z_SIMD_CHKALIGN(out)&& + ZEXY_TYPE_EQUAL(t_sample, float) + ) { + dsp_add(oror_tilde_performSSE, 4, in1, in2, out, n); + } else #endif - if(n&7) - dsp_add(oror_tilde_perform, 4, in1, in2, out, n); - else - dsp_add(oror_tilde_perf8, 4, in1, in2, out, n); + if(n&7) { + dsp_add(oror_tilde_perform, 4, in1, in2, out, n); + } else { + dsp_add(oror_tilde_perf8, 4, in1, in2, out, n); + } } static void scalaroror_tilde_dsp(t_scalaroror_tilde *x, t_signal **sp) @@ -225,19 +237,19 @@ static void scalaroror_tilde_dsp(t_scalaroror_tilde *x, t_signal **sp) #ifdef __SSE__ if( - Z_SIMD_CHKBLOCKSIZE(n)&& - Z_SIMD_CHKALIGN(in)&& - Z_SIMD_CHKALIGN(out)&& - ZEXY_TYPE_EQUAL(t_sample, float) - ) - { - dsp_add(scalaroror_tilde_performSSE, 4, in, &x->x_g, out, n); - } else + Z_SIMD_CHKBLOCKSIZE(n)&& + Z_SIMD_CHKALIGN(in)&& + Z_SIMD_CHKALIGN(out)&& + ZEXY_TYPE_EQUAL(t_sample, float) + ) { + dsp_add(scalaroror_tilde_performSSE, 4, in, &x->x_g, out, n); + } else #endif - if (n&7) - dsp_add(scalaroror_tilde_perform, 4, in, &x->x_g, out, n); - else - dsp_add(scalaroror_tilde_perf8, 4, in, &x->x_g, out, n); + if (n&7) { + dsp_add(scalaroror_tilde_perform, 4, in, &x->x_g, out, n); + } else { + dsp_add(scalaroror_tilde_perf8, 4, in, &x->x_g, out, n); + } } static void oror_tilde_help(t_object*x) @@ -248,18 +260,22 @@ static void oror_tilde_help(t_object*x) void setup_0x7c0x7c0x7e(void) { oror_tilde_class = class_new(gensym("||~"), (t_newmethod)oror_tilde_new, 0, - sizeof(t_oror_tilde), 0, A_GIMME, 0); - class_addmethod(oror_tilde_class, (t_method)oror_tilde_dsp, gensym("dsp"), 0); + sizeof(t_oror_tilde), 0, A_GIMME, 0); + class_addmethod(oror_tilde_class, (t_method)oror_tilde_dsp, gensym("dsp"), + 0); CLASS_MAINSIGNALIN(oror_tilde_class, t_oror_tilde, x_f); - class_addmethod (oror_tilde_class, (t_method)oror_tilde_help, gensym("help"), A_NULL); + class_addmethod (oror_tilde_class, (t_method)oror_tilde_help, + gensym("help"), A_NULL); class_sethelpsymbol(oror_tilde_class, gensym("zigbinops")); scalaroror_tilde_class = class_new(gensym("||~"), 0, 0, - sizeof(t_scalaroror_tilde), 0, 0); + sizeof(t_scalaroror_tilde), 0, 0); CLASS_MAINSIGNALIN(scalaroror_tilde_class, t_scalaroror_tilde, x_f); - class_addmethod(scalaroror_tilde_class, (t_method)scalaroror_tilde_dsp, gensym("dsp"), - 0); - class_addmethod (scalaroror_tilde_class, (t_method)oror_tilde_help, gensym("help"), A_NULL); + class_addmethod(scalaroror_tilde_class, (t_method)scalaroror_tilde_dsp, + gensym("dsp"), + 0); + class_addmethod (scalaroror_tilde_class, (t_method)oror_tilde_help, + gensym("help"), A_NULL); class_sethelpsymbol(scalaroror_tilde_class, gensym("zigbinops")); zexy_register("||~"); @@ -268,6 +284,6 @@ void setup_0x7c0x7c0x7e(void) #ifndef ZEXY_LIBRARY void setup(void) { - setup_0x7c0x7c0x7e(); + setup_0x7c0x7c0x7e(); } #endif diff --git a/src/a2l.c b/src/a2l.c index 2621b73..0f9b904 100644 --- a/src/a2l.c +++ b/src/a2l.c @@ -1,4 +1,4 @@ -/* +/* * a2l: convert anythings to lists (use [list] instead) * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -22,8 +22,7 @@ static t_class *a2l_class; -typedef struct _a2l -{ +typedef struct _a2l { t_object x_obj; } t_a2l; @@ -45,19 +44,29 @@ static void a2l_anything(t_a2l *x, t_symbol *s, int argc, t_atom *argv) } static void a2l_list(t_a2l *x, t_symbol *s, int argc, t_atom *argv) -{ outlet_list(x->x_obj.ob_outlet, s, argc, argv);} +{ + outlet_list(x->x_obj.ob_outlet, s, argc, argv); +} static void a2l_float(t_a2l *x, t_floatarg f) -{ outlet_float(x->x_obj.ob_outlet, f);} +{ + outlet_float(x->x_obj.ob_outlet, f); +} static void a2l_symbol(t_a2l *x, t_symbol *s) -{ outlet_symbol(x->x_obj.ob_outlet, s);} +{ + outlet_symbol(x->x_obj.ob_outlet, s); +} static void a2l_pointer(t_a2l *x, t_gpointer *gp) -{ outlet_pointer(x->x_obj.ob_outlet, gp);} +{ + outlet_pointer(x->x_obj.ob_outlet, gp); +} static void a2l_bang(t_a2l *x) -{ outlet_bang(x->x_obj.ob_outlet);} +{ + outlet_bang(x->x_obj.ob_outlet); +} static void *a2l_new(void) { @@ -68,9 +77,9 @@ static void *a2l_new(void) void a2l_setup(void) { - - a2l_class = class_new(gensym("a2l"), (t_newmethod)a2l_new, - 0, sizeof(t_a2l), 0, 0); + + a2l_class = class_new(gensym("a2l"), (t_newmethod)a2l_new, + 0, sizeof(t_a2l), 0, 0); class_addcreator((t_newmethod)a2l_new, gensym("any2list"), 0); diff --git a/src/absgn~.c b/src/absgn~.c index a134aa5..65bff49 100644 --- a/src/absgn~.c +++ b/src/absgn~.c @@ -1,4 +1,4 @@ -/* +/* * absgn~: combined absolute value and sign of a signal * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,20 +7,19 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ #include "zexySIMD.h" -typedef struct _absgn -{ +typedef struct _absgn { t_object x_obj; t_float x_f; } t_absgn; @@ -36,38 +35,41 @@ static t_int *sigABSGN_perform(t_int *w) t_sample *out = (t_sample *)(w[2]); t_sample *out2 = (t_sample *)(w[3]); int n = (int)(w[4]); - - while (n--) - { - t_sample val = *in++; - *out++ = fabsf(val); - - if (val>0.) *out2++=1.; - else if (val<0.) *out2++=-1.; - else *out2++=0.; + + while (n--) { + t_sample val = *in++; + *out++ = fabsf(val); + + if (val>0.) { + *out2++=1.; + } else if (val<0.) { + *out2++=-1.; + } else { + *out2++=0.; } + } + - return (w+5); } #ifdef __SSE__ -static int l_bitmask[] ={0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}; -static int l_sgnbitmask[]={0x80000000, 0x80000000, 0x80000000, 0x80000000}; +static int l_bitmask[] = {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}; +static int l_sgnbitmask[]= {0x80000000, 0x80000000, 0x80000000, 0x80000000}; static t_int *sigABSGN_performSSE(t_int *w) { __m128 *in = (__m128 *)(w[1]); __m128 *out1 = (__m128 *)(w[2]); __m128 *out2 = (__m128 *)(w[3]); int n = (int)(w[4])>>3; - + const __m128 bitmask= _mm_loadu_ps((float*)l_bitmask); const __m128 sgnmask= _mm_loadu_ps((float*)l_sgnbitmask); const __m128 zero = _mm_setzero_ps(); const __m128 one = _mm_set1_ps(1.f); - + do { - __m128 val, val2, xmm0, xmm1, xmm2, xmm3; + __m128 val, val2, xmm0, xmm1, xmm2, xmm3; val=in[0]; xmm0 = _mm_cmpneq_ps(val, zero); /* mask for non-zeros */ xmm1 = _mm_and_ps (val, sgnmask);/* sign (without value) */ @@ -85,8 +87,7 @@ static t_int *sigABSGN_performSSE(t_int *w) in +=2; out1+=2; out2+=2; - } - while (--n); + } while (--n); return (w+5); } @@ -96,20 +97,22 @@ static void sigABSGN_dsp(t_absgn* UNUSED(x), t_signal **sp) { #ifdef __SSE__ if( - ZEXY_TYPE_EQUAL(t_sample, float) && /* currently SSE2 code is only for float (not for double) */ - Z_SIMD_CHKBLOCKSIZE(sp[0]->s_n) && - Z_SIMD_CHKALIGN(sp[0]->s_vec) && - Z_SIMD_CHKALIGN(sp[1]->s_vec) && - Z_SIMD_CHKALIGN(sp[2]->s_vec) && - zexy_testSSE(sigABSGN_perform, sigABSGN_performSSE, 1, 2) - ) - { - dsp_add(sigABSGN_performSSE, 4, sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[0]->s_n); - } else + ZEXY_TYPE_EQUAL(t_sample, float) + && /* currently SSE2 code is only for float (not for double) */ + Z_SIMD_CHKBLOCKSIZE(sp[0]->s_n) && + Z_SIMD_CHKALIGN(sp[0]->s_vec) && + Z_SIMD_CHKALIGN(sp[1]->s_vec) && + Z_SIMD_CHKALIGN(sp[2]->s_vec) && + zexy_testSSE(sigABSGN_perform, sigABSGN_performSSE, 1, 2) + ) { + dsp_add(sigABSGN_performSSE, 4, sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, + sp[0]->s_n); + } else #endif - { - dsp_add(sigABSGN_perform, 4, sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[0]->s_n); - } + { + dsp_add(sigABSGN_perform, 4, sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, + sp[0]->s_n); + } } static void sigABSGN_helper(void) @@ -135,8 +138,9 @@ void absgn_tilde_setup(void) sizeof(t_absgn), 0, A_DEFFLOAT, 0); CLASS_MAINSIGNALIN(sigABSGN_class, t_absgn, x_f); class_addmethod(sigABSGN_class, (t_method)sigABSGN_dsp, gensym("dsp"), 0); - - class_addmethod(sigABSGN_class, (t_method)sigABSGN_helper, gensym("help"), 0); + + class_addmethod(sigABSGN_class, (t_method)sigABSGN_helper, gensym("help"), + 0); class_sethelpsymbol(sigABSGN_class, gensym("zigbinops")); zexy_register("absgn~"); diff --git a/src/abs~.c b/src/abs~.c index d021f8e..0bbdf08 100644 --- a/src/abs~.c +++ b/src/abs~.c @@ -1,4 +1,4 @@ -/* +/* * abs~: absolute value for signals * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -20,8 +20,7 @@ #include "zexySIMD.h" -typedef struct _abs -{ +typedef struct _abs { t_object x_obj; t_float x_f; } t_abs; @@ -36,14 +35,16 @@ static t_int *sigABS_perform(t_int *w) t_sample *in = (t_sample *)(w[1]); t_sample *out = (t_sample *)(w[2]); int n = (int)(w[3]); - - while (n--) *out++ = fabsf(*in++); - + + while (n--) { + *out++ = fabsf(*in++); + } + return (w+4); } #ifdef __SSE__ -static int l_bitmask[]={0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}; +static int l_bitmask[]= {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}; static t_int *sigABS_performSSE(t_int *w) { __m128 *in = (__m128 *)(w[1]); @@ -72,43 +73,43 @@ static t_int *sigABS_performSSE(t_int *w) * assembler */ asm( - ".section .rodata \n" - ".align 16 \n" - "2: \n" - ".long 2147483647 \n" /* bitmask */ - ".long 2147483647 \n" /* 0x7fffffff */ - ".long 2147483647 \n" - ".long 2147483647 \n" - - ".text \n" - - "movaps (2b), %%xmm0 \n" /* xmm0 = bitmask */ - "shrl $4, %2 \n" - - /* loop: *dest = abs(*src) */ - "1: \n" - "movaps (%0,%3), %%xmm1 \n" - "andps %%xmm0, %%xmm1 \n" - "movaps %%xmm1, (%1,%3) \n" - - "movaps 16(%0,%3), %%xmm2 \n" - "andps %%xmm0, %%xmm2 \n" - "movaps %%xmm2, 16(%1,%3) \n" - - "movaps 32(%0,%3), %%xmm3 \n" - "andps %%xmm0, %%xmm3 \n" - "movaps %%xmm3, 32(%1,%3) \n" - - "movaps 48(%0,%3), %%xmm4 \n" - "andps %%xmm0, %%xmm4 \n" - "movaps %%xmm4, 48(%1,%3) \n" - - "addl $64, %3 \n" - "loop 1b \n" - : - :"r"(in), "r"(out), "c"(n), "r"(0) - :"%xmm0", "%xmm1", "%xmm2", "%xmm3", "%xmm4" - ); + ".section .rodata \n" + ".align 16 \n" + "2: \n" + ".long 2147483647 \n" /* bitmask */ + ".long 2147483647 \n" /* 0x7fffffff */ + ".long 2147483647 \n" + ".long 2147483647 \n" + + ".text \n" + + "movaps (2b), %%xmm0 \n" /* xmm0 = bitmask */ + "shrl $4, %2 \n" + + /* loop: *dest = abs(*src) */ + "1: \n" + "movaps (%0,%3), %%xmm1 \n" + "andps %%xmm0, %%xmm1 \n" + "movaps %%xmm1, (%1,%3) \n" + + "movaps 16(%0,%3), %%xmm2 \n" + "andps %%xmm0, %%xmm2 \n" + "movaps %%xmm2, 16(%1,%3) \n" + + "movaps 32(%0,%3), %%xmm3 \n" + "andps %%xmm0, %%xmm3 \n" + "movaps %%xmm3, 32(%1,%3) \n" + + "movaps 48(%0,%3), %%xmm4 \n" + "andps %%xmm0, %%xmm4 \n" + "movaps %%xmm4, 48(%1,%3) \n" + + "addl $64, %3 \n" + "loop 1b \n" + : + :"r"(in), "r"(out), "c"(n), "r"(0) + :"%xmm0", "%xmm1", "%xmm2", "%xmm3", "%xmm4" + ); #endif /*0*/ return (w+4); @@ -119,21 +120,20 @@ static void sigABS_dsp(t_abs *x, t_signal **sp) { #ifdef __SSE__ if( - Z_SIMD_CHKBLOCKSIZE(sp[0]->s_n) && - Z_SIMD_CHKALIGN(sp[0]->s_vec) && - Z_SIMD_CHKALIGN(sp[1]->s_vec) && - ZEXY_TYPE_EQUAL(t_sample, float) && - zexy_testSSE(sigABS_perform, - sigABS_performSSE, - 1, 1) - ) - { - dsp_add(sigABS_performSSE, 3, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n); - } else + Z_SIMD_CHKBLOCKSIZE(sp[0]->s_n) && + Z_SIMD_CHKALIGN(sp[0]->s_vec) && + Z_SIMD_CHKALIGN(sp[1]->s_vec) && + ZEXY_TYPE_EQUAL(t_sample, float) && + zexy_testSSE(sigABS_perform, + sigABS_performSSE, + 1, 1) + ) { + dsp_add(sigABS_performSSE, 3, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n); + } else #endif - { - dsp_add(sigABS_perform, 3, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n); - } + { + dsp_add(sigABS_perform, 3, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n); + } } static void sigABS_helper(void) @@ -153,10 +153,10 @@ static void *sigABS_new(void) void abs_tilde_setup(void) { sigABS_class = class_new(gensym("abs~"), (t_newmethod)sigABS_new, 0, - sizeof(t_abs), 0, A_DEFFLOAT, 0); + sizeof(t_abs), 0, A_DEFFLOAT, 0); CLASS_MAINSIGNALIN(sigABS_class, t_abs, x_f); class_addmethod(sigABS_class, (t_method)sigABS_dsp, gensym("dsp"), 0); - + class_addmethod(sigABS_class, (t_method)sigABS_helper, gensym("help"), 0); class_sethelpsymbol(sigABS_class, gensym("zigbinops")); diff --git a/src/atof.c b/src/atof.c index 1f95c35..8311d83 100644 --- a/src/atof.c +++ b/src/atof.c @@ -1,4 +1,4 @@ -/* +/* * atof: ascii to A_FLOAT converter * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -23,8 +23,7 @@ static t_class *atof_class; -typedef struct _atof -{ +typedef struct _atof { t_object x_obj; t_float x_f; t_outlet*x_reject; @@ -50,20 +49,22 @@ static void atof_symbol(t_atof *x, t_symbol *sym) outlet_symbol(x->x_reject, sym); } } -static void atof_list(t_atof *x, t_symbol* UNUSED(s), int argc, t_atom *argv) +static void atof_list(t_atof *x, t_symbol* UNUSED(s), int argc, + t_atom *argv) { - if(!argc){ + if(!argc) { atof_bang(x); return; } - if (argv->a_type==A_FLOAT){ + if (argv->a_type==A_FLOAT) { atof_float(x, atom_getfloat(argv)); return; } atof_symbol(x, atom_getsymbol(argv)); } -static void atof_free(t_atof*x) { +static void atof_free(t_atof*x) +{ outlet_free(x->x_reject); x->x_reject=NULL; } @@ -78,8 +79,9 @@ static void *atof_new(void) void atof_setup(void) { - atof_class = class_new(gensym("atof"), (t_newmethod)atof_new, (t_method)atof_free, - sizeof(t_atof), 0, A_DEFFLOAT, 0); + atof_class = class_new(gensym("atof"), (t_newmethod)atof_new, + (t_method)atof_free, + sizeof(t_atof), 0, A_DEFFLOAT, 0); class_addbang(atof_class, (t_method)atof_bang); class_addfloat(atof_class, (t_method)atof_float); diff --git a/src/atoi.c b/src/atoi.c index 153b303..17e6b99 100644 --- a/src/atoi.c +++ b/src/atoi.c @@ -1,4 +1,4 @@ -/* +/* * atoi: ascii to integer converter * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -23,8 +23,7 @@ static t_class *atoi_class; -typedef struct _atoi -{ +typedef struct _atoi { t_object x_obj; int x_i; t_outlet*x_reject; @@ -39,36 +38,40 @@ static void atoi_float(t_atoi *x, t_float f) x->x_i = f; atoi_bang(x); } -static void atoi_atoi(t_atoi *x, t_symbol*s, int base) { +static void atoi_atoi(t_atoi *x, t_symbol*s, int base) +{ char*endptr=NULL; const char*str=s->s_name; long l=strtol(str, &endptr, base); size_t len=strlen(str); - if(str+len == endptr) + if(str+len == endptr) { atoi_float(x, l); - else + } else { outlet_symbol(x->x_reject, s); + } } static void atoi_symbol(t_atoi *x, t_symbol *sym) { int base=10; const char* s = sym->s_name; - if(s[0]=='0'){ + if(s[0]=='0') { base=8; - if (s[1]=='x')base=16; + if (s[1]=='x') { + base=16; + } } atoi_atoi(x, sym, base); } static void atoi_list(t_atoi *x, t_symbol* s, int argc, t_atom *argv) { int base=10; - if (argv->a_type==A_FLOAT){ + if (argv->a_type==A_FLOAT) { atoi_float(x, atom_getfloat(argv)); return; } - - if (argc>1){ + + if (argc>1) { base=atom_getfloat(argv+1); if (base<2) { error("atoi: setting base to 10"); @@ -78,7 +81,8 @@ static void atoi_list(t_atoi *x, t_symbol* s, int argc, t_atom *argv) atoi_atoi(x, s, base); } -static void atoi_free(t_atoi *x){ +static void atoi_free(t_atoi *x) +{ outlet_free(x->x_reject); x->x_reject=NULL; } @@ -93,8 +97,9 @@ static void *atoi_new(void) void atoi_setup(void) { - atoi_class = class_new(gensym("atoi"), (t_newmethod)atoi_new, (t_method)atoi_free, - sizeof(t_atoi), 0, A_DEFFLOAT, 0); + atoi_class = class_new(gensym("atoi"), (t_newmethod)atoi_new, + (t_method)atoi_free, + sizeof(t_atoi), 0, A_DEFFLOAT, 0); class_addbang(atoi_class, (t_method)atoi_bang); class_addfloat(atoi_class, (t_method)atoi_float); diff --git a/src/avg~.c b/src/avg~.c index 6254520..3e68c4c 100644 --- a/src/avg~.c +++ b/src/avg~.c @@ -1,4 +1,4 @@ -/* +/* * avg~: calculate the average of a signal block * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -25,8 +25,7 @@ static t_class *avg_class; -typedef struct _avg -{ +typedef struct _avg { t_object x_obj; t_float n_inv; @@ -45,10 +44,9 @@ static t_int *avg_perform(t_int *w) t_sample buf = 0.; - while (n--) - { - buf += *in++; - } + while (n--) { + buf += *in++; + } outlet_float(x->x_obj.ob_outlet, buf*x->n_inv); return (w+4); diff --git a/src/blockmirror~.c b/src/blockmirror~.c index c796d7b..63a0c12 100644 --- a/src/blockmirror~.c +++ b/src/blockmirror~.c @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -28,8 +28,7 @@ static t_class *blockmirror_class; -typedef struct _blockmirror -{ +typedef struct _blockmirror { t_object x_obj; int doit; int blocksize; @@ -48,24 +47,34 @@ static t_int *blockmirror_perform(t_int *w) t_sample *out = (t_sample *)(w[3]); int n = (int)(w[4]); if (x->doit) { - if (in==out){ + if (in==out) { int N=n; t_sample *dummy=x->blockbuffer; - while(n--)*dummy++=*in++; + while(n--) { + *dummy++=*in++; + } dummy--; - while(N--)*out++=*dummy--; + while(N--) { + *out++=*dummy--; + } } else { in+=n-1; - while(n--)*out++=*in--; + while(n--) { + *out++=*in--; + } + } + } else while (n--) { + *out++ = *in++; } - } else while (n--) *out++ = *in++; return (w+5); } static void blockmirror_dsp(t_blockmirror *x, t_signal **sp) { - if (x->blocksizes_n){ - if(x->blockbuffer)freebytes(x->blockbuffer, sizeof(*x->blockbuffer)*x->blocksize); + if (x->blocksizes_n) { + if(x->blockbuffer) { + freebytes(x->blockbuffer, sizeof(*x->blockbuffer)*x->blocksize); + } x->blocksize = sp[0]->s_n; x->blockbuffer = getbytes(sizeof(*x->blockbuffer)*x->blocksize); } @@ -81,8 +90,9 @@ static void blockmirror_helper(t_blockmirror*x) } static void blockmirror_free(t_blockmirror*x) { - if(x->blockbuffer) + if(x->blockbuffer) { freebytes(x->blockbuffer, sizeof(*x->blockbuffer)*x->blocksize); + } x->blockbuffer=0; } static void *blockmirror_new(void) @@ -96,14 +106,17 @@ static void *blockmirror_new(void) void blockmirror_tilde_setup(void) { - blockmirror_class = class_new(gensym("blockmirror~"), (t_newmethod)blockmirror_new, + blockmirror_class = class_new(gensym("blockmirror~"), + (t_newmethod)blockmirror_new, (t_method)blockmirror_free, sizeof(t_blockmirror), 0, A_NULL); class_addmethod(blockmirror_class, nullfn, gensym("signal"), 0); - class_addmethod(blockmirror_class, (t_method)blockmirror_dsp, gensym("dsp"), 0); - + class_addmethod(blockmirror_class, (t_method)blockmirror_dsp, + gensym("dsp"), 0); + class_addfloat(blockmirror_class, blockmirror_float); - - class_addmethod(blockmirror_class, (t_method)blockmirror_helper, gensym("help"), 0); + + class_addmethod(blockmirror_class, (t_method)blockmirror_helper, + gensym("help"), 0); zexy_register("blockmirror~"); } diff --git a/src/blockshuffle~.c b/src/blockshuffle~.c index db2a0d6..81a433e 100644 --- a/src/blockshuffle~.c +++ b/src/blockshuffle~.c @@ -1,4 +1,4 @@ -/* +/* * blockshuffle~: shuffle a signal block * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -28,8 +28,8 @@ static t_class *blockshuffle_class; -typedef struct _blockshuffle -{ t_object x_obj; +typedef struct _blockshuffle { + t_object x_obj; t_sample*blockbuf; t_int* indices; @@ -39,37 +39,47 @@ typedef struct _blockshuffle int shufflesize; } t_blockshuffle; -static void blockshuffle_buildindex(t_blockshuffle *x, int blocksize){ +static void blockshuffle_buildindex(t_blockshuffle *x, int blocksize) +{ int i=0; - if(blocksize!=x->size){ - if(x->indices)freebytes(x->indices, x->size); - if(x->blockbuf)freebytes(x->blockbuf, x->size); + if(blocksize!=x->size) { + if(x->indices) { + freebytes(x->indices, x->size); + } + if(x->blockbuf) { + freebytes(x->blockbuf, x->size); + } x->indices=getbytes (sizeof(t_int)*blocksize); x->blockbuf=getbytes(sizeof(t_sample)*blocksize); x->size=blocksize; } - for(i=0;ishufflesize&&ishufflesize&&ishuffle[i]; - if(idx>=blocksize)idx=blocksize-1; - if(idx<0)idx=0; + if(idx>=blocksize) { + idx=blocksize-1; + } + if(idx<0) { + idx=0; + } x->indices[i]=idx; } - for(;iindices[i]=i; } } -static void blockshuffle_list(t_blockshuffle *x, t_symbol*s, int argc, t_atom*argv) +static void blockshuffle_list(t_blockshuffle *x, t_symbol*s, int argc, + t_atom*argv) { int i; - if(x->shuffle){ + if(x->shuffle) { freebytes(x->shuffle, x->shufflesize); x->shuffle=0; } x->shufflesize=argc; x->shuffle=getbytes(sizeof(*x->shuffle)*argc); - for(i=0; ishuffle[i]=atom_getfloat(argv++); } blockshuffle_buildindex(x, x->size); @@ -85,16 +95,18 @@ static t_int *blockshuffle_perform(t_int *w) t_sample *temp=x->blockbuf; t_int *idx =x->indices; - if(idx){ - for(i=0; iblockbuf; - for(i=0; is_n); - dsp_add(blockshuffle_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n); + dsp_add(blockshuffle_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, + sp[0]->s_n); } static void blockshuffle_helper(void) @@ -113,10 +126,17 @@ static void blockshuffle_helper(void) "signal~"); post("outlet : signal~"); } -static void blockshuffle_free(t_blockshuffle *x){ - if(x->indices) freebytes(x->indices, sizeof(*x->indices) *x->size); - if(x->blockbuf)freebytes(x->blockbuf, sizeof(*x->blockbuf)*x->size); - if(x->shuffle) freebytes(x->shuffle, sizeof(*x->shuffle) *x->shufflesize); +static void blockshuffle_free(t_blockshuffle *x) +{ + if(x->indices) { + freebytes(x->indices, sizeof(*x->indices) *x->size); + } + if(x->blockbuf) { + freebytes(x->blockbuf, sizeof(*x->blockbuf)*x->size); + } + if(x->shuffle) { + freebytes(x->shuffle, sizeof(*x->shuffle) *x->shufflesize); + } } static void *blockshuffle_new(void) @@ -133,14 +153,17 @@ static void *blockshuffle_new(void) void blockshuffle_tilde_setup(void) { - blockshuffle_class = class_new(gensym("blockshuffle~"), (t_newmethod)blockshuffle_new, + blockshuffle_class = class_new(gensym("blockshuffle~"), + (t_newmethod)blockshuffle_new, (t_method)blockshuffle_free, sizeof(t_blockshuffle), 0, A_NULL); class_addmethod(blockshuffle_class, nullfn, gensym("signal"), 0); - class_addmethod(blockshuffle_class, (t_method)blockshuffle_dsp, gensym("dsp"), 0); - + class_addmethod(blockshuffle_class, (t_method)blockshuffle_dsp, + gensym("dsp"), 0); + class_addlist(blockshuffle_class, blockshuffle_list); - - class_addmethod(blockshuffle_class, (t_method)blockshuffle_helper, gensym("help"), 0); + + class_addmethod(blockshuffle_class, (t_method)blockshuffle_helper, + gensym("help"), 0); zexy_register("blockshuffle~"); } diff --git a/src/blockswap~.c b/src/blockswap~.c index deb9ce2..d59f312 100644 --- a/src/blockswap~.c +++ b/src/blockswap~.c @@ -1,4 +1,4 @@ -/* +/* * blockswap~: swaps a signalblock around it's center * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -27,8 +27,7 @@ static t_class *blockswap_class; -typedef struct _blockswap -{ +typedef struct _blockswap { t_object x_obj; int doit; int blocksize; @@ -50,20 +49,30 @@ static t_int *blockswap_perform(t_int *w) if (x->doit) { int n=N2; t_sample *dummy=x->blockbuffer; - while(n--)*dummy++=*in++; + while(n--) { + *dummy++=*in++; + } n=N-N2; - while(n--)*out++=*in++; + while(n--) { + *out++=*in++; + } dummy=x->blockbuffer; - n=N2; - while(n--)*out++=*dummy++; - } else while (N--) *out++=*in++; + n=N2; + while(n--) { + *out++=*dummy++; + } + } else while (N--) { + *out++=*in++; + } return (w+5); } static void blockswap_dsp(t_blockswap *x, t_signal **sp) { - if (x->blocksize*2s_n){ - if(x->blockbuffer)freebytes(x->blockbuffer, sizeof(*x->blockbuffer)*x->blocksize); + if (x->blocksize*2s_n) { + if(x->blockbuffer) { + freebytes(x->blockbuffer, sizeof(*x->blockbuffer)*x->blocksize); + } x->blocksize = sp[0]->s_n/2; x->blockbuffer = getbytes(sizeof(*x->blockbuffer)*x->blocksize); } @@ -80,7 +89,7 @@ static void blockswap_helper(t_blockswap *x) static void blockswap_free(t_blockswap *x) { - if(x->blockbuffer){ + if(x->blockbuffer) { freebytes(x->blockbuffer, sizeof(*x->blockbuffer)*x->blocksize); } x->blockbuffer=0; @@ -97,13 +106,16 @@ static void *blockswap_new(void) void blockswap_tilde_setup(void) { - blockswap_class = class_new(gensym("blockswap~"), (t_newmethod)blockswap_new, (t_method)blockswap_free, + blockswap_class = class_new(gensym("blockswap~"), + (t_newmethod)blockswap_new, (t_method)blockswap_free, sizeof(t_blockswap), 0, A_NULL); class_addmethod(blockswap_class, nullfn, gensym("signal"), 0); - class_addmethod(blockswap_class, (t_method)blockswap_dsp, gensym("dsp"), 0); - + class_addmethod(blockswap_class, (t_method)blockswap_dsp, gensym("dsp"), + 0); + class_addfloat(blockswap_class, blockswap_float); - - class_addmethod(blockswap_class, (t_method)blockswap_helper, gensym("help"), 0); + + class_addmethod(blockswap_class, (t_method)blockswap_helper, + gensym("help"), 0); zexy_register("blockswap~"); } diff --git a/src/date.c b/src/date.c index 3e2a5f5..0e92a7e 100644 --- a/src/date.c +++ b/src/date.c @@ -1,4 +1,4 @@ -/* +/* * date: gets the current date from the system * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -33,9 +33,9 @@ * ******************************************************/ -/* +/* (c) 1202:forum::für::umläute:2000 - 1506:forum::für::umläute:2003: use timeb only if needed (like on windoze) + 1506:forum::für::umläute:2003: use timeb only if needed (like on windoze) */ #include "zexy.h" @@ -63,12 +63,11 @@ static t_class *date_class; -typedef struct _date -{ +typedef struct _date { t_object x_obj; - + int GMT; - + t_outlet *x_outlet1; t_outlet *x_outlet2; t_outlet *x_outlet3; @@ -81,21 +80,22 @@ static void *date_new(t_symbol* UNUSED(s), int argc, t_atom *argv) { t_date *x = (t_date *)pd_new(date_class); char buf[5]; - + x->GMT=0; if (argc) { atom_string(argv, buf, 5); - if (buf[0]=='G' && buf[1]=='M' && buf[2]=='T') + if (buf[0]=='G' && buf[1]=='M' && buf[2]=='T') { x->GMT = 1; + } } - + x->x_outlet1 = outlet_new(&x->x_obj, gensym("float")); x->x_outlet2 = outlet_new(&x->x_obj, gensym("float")); x->x_outlet3 = outlet_new(&x->x_obj, gensym("float")); x->x_outlet4 = outlet_new(&x->x_obj, gensym("float")); x->x_outlet5 = outlet_new(&x->x_obj, gensym("float")); x->x_outlet6 = outlet_new(&x->x_obj, gensym("float")); - + return (x); } @@ -129,11 +129,11 @@ static void help_date(t_date* UNUSED(x)) void date_setup(void) { date_class = class_new(gensym("date"), - (t_newmethod)date_new, 0, - sizeof(t_date), 0, A_GIMME, 0); - + (t_newmethod)date_new, 0, + sizeof(t_date), 0, A_GIMME, 0); + class_addbang(date_class, date_bang); - + class_addmethod(date_class, (t_method)help_date, gensym("help"), 0); zexy_register("date"); } diff --git a/src/demultiplex.c b/src/demultiplex.c index 20886f5..ea6cd4a 100644 --- a/src/demultiplex.c +++ b/src/demultiplex.c @@ -1,5 +1,5 @@ -/* - * demux : demultiplex the input to a specified output +/* + * demux : demultiplex the input to a specified output * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) * @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -28,8 +28,7 @@ static t_class *demux_class; -typedef struct _demux -{ +typedef struct _demux { t_object x_obj; int n_out; @@ -59,8 +58,8 @@ static void demux_list(t_demux *x, t_symbol *s, int argc, t_atom *argv) outlet_symbol(x->selected, atom_getsymbol(argv)); break; case A_POINTER: - outlet_pointer(x->selected, argv->a_w.w_gpointer); - break; + outlet_pointer(x->selected, argv->a_w.w_gpointer); + break; default: outlet_list(x->selected, s, argc, argv); } @@ -80,7 +79,7 @@ static void *demux_new(t_symbol* UNUSED(s), int argc, t_atom* UNUSED(argv)) int n = (argc < 2)?2:argc; x->n_out = n - 1; - + inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("select")); x->out = (t_outlet **)getbytes(n * sizeof(t_outlet *)); @@ -96,13 +95,14 @@ static void *demux_new(t_symbol* UNUSED(s), int argc, t_atom* UNUSED(argv)) void demultiplex_setup(void) { demux_class = class_new(gensym("demultiplex"), (t_newmethod)demux_new, - 0, sizeof(t_demux), 0, A_GIMME, 0); + 0, sizeof(t_demux), 0, A_GIMME, 0); class_addcreator((t_newmethod)demux_new, gensym("demux"), A_GIMME, 0); - + class_addanything (demux_class, demux_any); class_addlist (demux_class, demux_list); - class_addmethod (demux_class, (t_method)demux_select, gensym("select"), A_DEFFLOAT, 0); + class_addmethod (demux_class, (t_method)demux_select, gensym("select"), + A_DEFFLOAT, 0); zexy_register("demultiplex"); } diff --git a/src/demultiplex~.c b/src/demultiplex~.c index 7d5f0b3..111e123 100644 --- a/src/demultiplex~.c +++ b/src/demultiplex~.c @@ -1,4 +1,4 @@ -/* +/* * demux~ : demultiplex a signal to a specified output * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -33,10 +33,12 @@ typedef struct _demux { static void demux_output(t_demux *x, t_floatarg f) { - if ((f>=0)&&(fn_out)){ + if ((f>=0)&&(fn_out)) { x->output=f; - } else - error("demultiplex: %d is channel out of range (0..%d)", (int)f, x->n_out); + } else { + error("demultiplex: %d is channel out of range (0..%d)", (int)f, + x->n_out); + } } @@ -49,13 +51,17 @@ static t_int *demux_perform(t_int *w) int channel=x->n_out; - while(channel--){ + while(channel--) { t_sample*out=x->out[channel]; n=N; - if(x->output==channel){ - while(n--)*out++=*in++; + if(x->output==channel) { + while(n--) { + *out++=*in++; + } } else - while(n--)*out++=0.f; + while(n--) { + *out++=0.f; + } } return (w+4); } @@ -64,7 +70,9 @@ static void demux_dsp(t_demux *x, t_signal **sp) { int n = x->n_out; t_sample **dummy=x->out; - while(n--)*dummy++=sp[x->n_out-n]->s_vec; + while(n--) { + *dummy++=sp[x->n_out-n]->s_vec; + } dsp_add(demux_perform, 3, x, sp[0]->s_vec, sp[0]->s_n); } @@ -87,22 +95,29 @@ static void *demux_new(t_symbol* UNUSED(s), int argc, t_atom* UNUSED(argv)) t_demux *x = (t_demux *)pd_new(demux_class); int i; - if (!argc)argc=2; + if (!argc) { + argc=2; + } x->n_out=argc; x->output=0; - while(argc--)outlet_new(&x->x_obj, gensym("signal")); + while(argc--) { + outlet_new(&x->x_obj, gensym("signal")); + } x->out = (t_sample **)getbytes(x->n_out * sizeof(t_sample *)); i=x->n_out; - while(i--)x->out[i]=0; + while(i--) { + x->out[i]=0; + } return (x); } void demultiplex_tilde_setup(void) { - demux_class = class_new(gensym("demultiplex~"), (t_newmethod)demux_new, (t_method)demux_free, sizeof(t_demux), 0, A_GIMME, 0); + demux_class = class_new(gensym("demultiplex~"), (t_newmethod)demux_new, + (t_method)demux_free, sizeof(t_demux), 0, A_GIMME, 0); class_addcreator((t_newmethod)demux_new, gensym("demux~"), A_GIMME, 0); class_addfloat(demux_class, demux_output); diff --git a/src/dfreq~.c b/src/dfreq~.c index 3e87567..151e851 100644 --- a/src/dfreq~.c +++ b/src/dfreq~.c @@ -1,4 +1,4 @@ -/* +/* * dfreq~: cound zero-crossings as a simple fequency estimation * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -28,8 +28,7 @@ static t_class *dfreq_class; -typedef struct _dfreq -{ +typedef struct _dfreq { t_object x_obj; t_sample freq; /*frequenz variable */ @@ -55,14 +54,15 @@ static t_int *dfreq_perform(t_int *w) while (n--) { - if( (a * *in) < 0 && (a < *in)){ + if( (a **in) < 0 && (a < *in)) { /* interpolate for real zerocross */ delta_inv = 1./(*in-a); - if(c > 0.0) + if(c > 0.0) { freq = sr / ((t_sample) c + a*delta_inv); - else + } else { freq = sr; + } c = *in*delta_inv; /*rest of time */ }; @@ -73,7 +73,7 @@ static t_int *dfreq_perform(t_int *w) *out++ = freq; } - x->alt = a; + x->alt = a; x->sampcount = c; x->freq=freq; @@ -112,6 +112,7 @@ void dfreq_tilde_setup(void) class_addmethod(dfreq_class, nullfn, gensym("signal"), 0); class_addmethod(dfreq_class, (t_method)dfreq_dsp, gensym("dsp"), 0); - class_addmethod(dfreq_class, (t_method)dfreq_tilde_helper, gensym("help"), 0); + class_addmethod(dfreq_class, (t_method)dfreq_tilde_helper, gensym("help"), + 0); zexy_register("dfreq~"); } diff --git a/src/dirac~.c b/src/dirac~.c index 3213c82..9c8745a 100644 --- a/src/dirac~.c +++ b/src/dirac~.c @@ -1,21 +1,21 @@ -/* +/* * dirac~: unity sample * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) * * optimizations: - * (c) 2005 tim blechmann + * (c) 2005 tim blechmann * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -34,13 +34,12 @@ #include "zexy.h" -/* ------------------------ dirac~ ----------------------------- */ +/* ------------------------ dirac~ ----------------------------- */ static t_class *dirac_class; -typedef struct _dirac -{ +typedef struct _dirac { t_object x_obj; t_int position; t_int do_it; @@ -61,29 +60,28 @@ static t_int *dirac_perform(t_int *w) t_dirac *x = (t_dirac *)(w[1]); t_sample *out = (t_sample *)(w[2]); int n = (int)(w[3]); - + t_int do_it = x->do_it; zero_perform(w+1); - if (do_it >= n) + if (do_it >= n) { x->do_it -= n; - else if(do_it >= 0) - { - out[do_it] = 1.f; - x->do_it = -1; - } + } else if(do_it >= 0) { + out[do_it] = 1.f; + x->do_it = -1; + } return (w+4); } #ifndef __WIN32__ - /* LATER: investigate the occurence of zero_perf8() */ - /* it seems, like pd has the symbol zero_perf8(), - * but it is not exported by m_pd.h: - * so linux can use it, but w32 not - * have to tell miller about that - */ +/* LATER: investigate the occurence of zero_perf8() */ +/* it seems, like pd has the symbol zero_perf8(), + * but it is not exported by m_pd.h: + * so linux can use it, but w32 not + * have to tell miller about that + */ t_int *zero_perf8(t_int *w); #else /* on w32 we have no access to this hidden function anyhow... */ @@ -95,27 +93,27 @@ static t_int *dirac_perf8(t_int *w) t_dirac *x = (t_dirac *)(w[1]); t_sample *out = (t_sample *)(w[2]); int n = (int)(w[3]); - + t_int do_it = x->do_it; zero_perf8(w+1); - if (do_it >= n) + if (do_it >= n) { x->do_it -= n; - else if(do_it >= 0) - { - out[do_it] = 1.f; - x->do_it = -1; - } + } else if(do_it >= 0) { + out[do_it] = 1.f; + x->do_it = -1; + } return (w+4); } static void dirac_dsp(t_dirac *x, t_signal **sp) { - if (sp[0]->s_n & 7) + if (sp[0]->s_n & 7) { dsp_add(dirac_perform, 3, x, sp[0]->s_vec, sp[0]->s_n); - else + } else { dsp_add(dirac_perf8, 3, x, sp[0]->s_vec, sp[0]->s_n); + } } static void dirac_helper(void) @@ -139,19 +137,20 @@ static void *dirac_new(t_floatarg where) // x->do_it = where; x->do_it = -1; - if (where > 0) + if (where > 0) { x->position = where; - else + } else { x->position = -where; + } return (x); } - + void dirac_tilde_setup(void) { dirac_class = class_new(gensym("dirac~"), (t_newmethod)dirac_new, 0, sizeof(t_dirac), 0, A_DEFFLOAT, 0); - class_addfloat(dirac_class, dirac_float); - class_addbang(dirac_class, dirac_bang); + class_addfloat(dirac_class, dirac_float); + class_addbang(dirac_class, dirac_bang); class_addmethod(dirac_class, (t_method)dirac_dsp, gensym("dsp"), 0); class_addmethod(dirac_class, (t_method)dirac_helper, gensym("help"), 0); diff --git a/src/doublepole~.c b/src/doublepole~.c index 93a2a74..a06e861 100644 --- a/src/doublepole~.c +++ b/src/doublepole~.c @@ -2,121 +2,126 @@ * For information on usage and redistribution, and for a DISCLAIMER OF ALL * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ -/* "filters", both linear and nonlinear. +/* "filters", both linear and nonlinear. */ #include "m_pd.h" #include //* ---------------- doublepole~ - raw doublepole filter ----------------- */ -typedef struct doublepolectl -{ - t_sample c_x1; - t_sample c_x2; - t_sample c_fb1; - t_sample c_fb2; +typedef struct doublepolectl { + t_sample c_x1; + t_sample c_x2; + t_sample c_fb1; + t_sample c_fb2; } t_doublepolectl; -typedef struct sigdoublepole -{ - t_object x_obj; - t_float x_f; - t_doublepolectl x_cspace; - t_doublepolectl *x_ctl; +typedef struct sigdoublepole { + t_object x_obj; + t_float x_f; + t_doublepolectl x_cspace; + t_doublepolectl *x_ctl; } t_sigdoublepole; static t_class *sigdoublepole_class = NULL; -static void sigdoublepole_list(t_sigdoublepole *x, t_symbol *s, int argc, t_atom *argv); +static void sigdoublepole_list(t_sigdoublepole *x, t_symbol *s, int argc, + t_atom *argv); static void *sigdoublepole_new(t_symbol *s, int argc, t_atom *argv) { - t_sigdoublepole *x = (t_sigdoublepole *)pd_new(sigdoublepole_class); - outlet_new(&x->x_obj, &s_signal); - x->x_ctl = &x->x_cspace; - x->x_cspace.c_x1 = x->x_cspace.c_x2 = 0; - sigdoublepole_list(x, s, argc, argv); - x->x_f = 0; - return (x); + t_sigdoublepole *x = (t_sigdoublepole *)pd_new(sigdoublepole_class); + outlet_new(&x->x_obj, &s_signal); + x->x_ctl = &x->x_cspace; + x->x_cspace.c_x1 = x->x_cspace.c_x2 = 0; + sigdoublepole_list(x, s, argc, argv); + x->x_f = 0; + return (x); } static t_int *sigdoublepole_perform(t_int *w) { - t_sample *in = (t_sample *)(w[1]); - t_sample *out = (t_sample *)(w[2]); - t_doublepolectl *c = (t_doublepolectl *)(w[3]); - int n = (t_int)(w[4]); - int i; - t_sample last = c->c_x1; - t_sample prev = c->c_x2; - t_sample fb1 = c->c_fb1; - t_sample fb2 = c->c_fb2; - for (i = 0; i < n; i++) - { - t_sample output = *in++ + fb1 * last + fb2 * prev; - if (PD_BIGORSMALL(output)) - output = 0; - *out++ = output; - prev = last; - last = output; + t_sample *in = (t_sample *)(w[1]); + t_sample *out = (t_sample *)(w[2]); + t_doublepolectl *c = (t_doublepolectl *)(w[3]); + int n = (t_int)(w[4]); + int i; + t_sample last = c->c_x1; + t_sample prev = c->c_x2; + t_sample fb1 = c->c_fb1; + t_sample fb2 = c->c_fb2; + for (i = 0; i < n; i++) { + t_sample output = *in++ + fb1 * last + fb2 * prev; + if (PD_BIGORSMALL(output)) { + output = 0; } - c->c_x1 = last; - c->c_x2 = prev; - return (w+5); + *out++ = output; + prev = last; + last = output; + } + c->c_x1 = last; + c->c_x2 = prev; + return (w+5); } -static void sigdoublepole_list(t_sigdoublepole *x, t_symbol *s, int argc, t_atom *argv) +static void sigdoublepole_list(t_sigdoublepole *x, t_symbol *s, int argc, + t_atom *argv) { - t_float fb1 = atom_getfloatarg(0, argc, argv); - t_float fb2 = atom_getfloatarg(1, argc, argv); - t_float discriminant = fb1 * fb1 + 4 * fb2; - t_doublepolectl *c = x->x_ctl; - if (discriminant < 0) /* imaginary roots -- resonant filter */ - { - /* they're conjugates so we just check that the product - is less than one */ - if (fb2 >= -1.0f) goto stable; + t_float fb1 = atom_getfloatarg(0, argc, argv); + t_float fb2 = atom_getfloatarg(1, argc, argv); + t_float discriminant = fb1 * fb1 + 4 * fb2; + t_doublepolectl *c = x->x_ctl; + if (discriminant < 0) { /* imaginary roots -- resonant filter */ + /* they're conjugates so we just check that the product + is less than one */ + if (fb2 >= -1.0f) { + goto stable; } - else /* real roots */ - { - /* check that the parabola 1 - fb1 x - fb2 x^2 has a - vertex between -1 and 1, and that it's nonnegative - at both ends, which implies both roots are in [1-,1]. */ - if (fb1 <= 2.0f && fb1 >= -2.0f && - 1.0f - fb1 -fb2 >= 0 && 1.0f + fb1 - fb2 >= 0) - goto stable; + } else { /* real roots */ + /* check that the parabola 1 - fb1 x - fb2 x^2 has a + vertex between -1 and 1, and that it's nonnegative + at both ends, which implies both roots are in [1-,1]. */ + if (fb1 <= 2.0f && fb1 >= -2.0f && + 1.0f - fb1 -fb2 >= 0 && 1.0f + fb1 - fb2 >= 0) { + goto stable; } - /* if unstable, just bash to zero */ - fb1 = fb2 = 0; + } + /* if unstable, just bash to zero */ + fb1 = fb2 = 0; stable: - c->c_fb1 = fb1; - c->c_fb2 = fb2; + c->c_fb1 = fb1; + c->c_fb2 = fb2; } -static void sigdoublepole_set(t_sigdoublepole *x, t_symbol *s, int argc, t_atom *argv) +static void sigdoublepole_set(t_sigdoublepole *x, t_symbol *s, int argc, + t_atom *argv) { - t_doublepolectl *c = x->x_ctl; - c->c_x1 = atom_getfloatarg(0, argc, argv); - c->c_x2 = atom_getfloatarg(1, argc, argv); + t_doublepolectl *c = x->x_ctl; + c->c_x1 = atom_getfloatarg(0, argc, argv); + c->c_x2 = atom_getfloatarg(1, argc, argv); } static void sigdoublepole_dsp(t_sigdoublepole *x, t_signal **sp) { - dsp_add(sigdoublepole_perform, 4, - sp[0]->s_vec, sp[1]->s_vec, - x->x_ctl, sp[0]->s_n); + dsp_add(sigdoublepole_perform, 4, + sp[0]->s_vec, sp[1]->s_vec, + x->x_ctl, sp[0]->s_n); } void doublepole_tilde_setup(void) { - sigdoublepole_class = class_new(gensym("doublepole~"), (t_newmethod)sigdoublepole_new, - 0, sizeof(t_sigdoublepole), 0, A_GIMME, 0); - CLASS_MAINSIGNALIN(sigdoublepole_class, t_sigdoublepole, x_f); - class_addmethod(sigdoublepole_class, (t_method)sigdoublepole_dsp, gensym("dsp"), 0); - class_addlist(sigdoublepole_class, sigdoublepole_list); - class_addmethod(sigdoublepole_class, (t_method)sigdoublepole_set, gensym("set"), - A_GIMME, 0); - class_addmethod(sigdoublepole_class, (t_method)sigdoublepole_set, gensym("clear"), - A_GIMME, 0); + sigdoublepole_class = class_new(gensym("doublepole~"), + (t_newmethod)sigdoublepole_new, + 0, sizeof(t_sigdoublepole), 0, A_GIMME, 0); + CLASS_MAINSIGNALIN(sigdoublepole_class, t_sigdoublepole, x_f); + class_addmethod(sigdoublepole_class, (t_method)sigdoublepole_dsp, + gensym("dsp"), 0); + class_addlist(sigdoublepole_class, sigdoublepole_list); + class_addmethod(sigdoublepole_class, (t_method)sigdoublepole_set, + gensym("set"), + A_GIMME, 0); + class_addmethod(sigdoublepole_class, (t_method)sigdoublepole_set, + gensym("clear"), + A_GIMME, 0); } diff --git a/src/drip.c b/src/drip.c index 855f9d8..59e504c 100644 --- a/src/drip.c +++ b/src/drip.c @@ -1,4 +1,4 @@ -/* +/* * drip: unfold a parallel data-structure (*pack*age) into a sequence * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -30,8 +30,7 @@ you can adjust the drop-speed in [ms] static t_class *drip_class; -typedef struct _drip -{ +typedef struct _drip { t_object x_obj; t_atom *buffer, *current; @@ -58,7 +57,9 @@ static void drip_makebuffer(t_drip *x, int n, t_atom *list) } static void drip_bang(t_drip *x) -{ outlet_bang(x->x_obj.ob_outlet);} +{ + outlet_bang(x->x_obj.ob_outlet); +} static void drip_all(t_drip *x, int argc, t_atom *argv) @@ -66,16 +67,16 @@ static void drip_all(t_drip *x, int argc, t_atom *argv) while (argc--) { switch (argv->a_type) { case A_FLOAT: - outlet_float(x->x_obj.ob_outlet, atom_getfloat(argv)); + outlet_float(x->x_obj.ob_outlet, atom_getfloat(argv)); break; case A_SYMBOL: - outlet_symbol(x->x_obj.ob_outlet, atom_getsymbol(argv)); + outlet_symbol(x->x_obj.ob_outlet, atom_getsymbol(argv)); break; case A_POINTER: - outlet_pointer(x->x_obj.ob_outlet, argv->a_w.w_gpointer); + outlet_pointer(x->x_obj.ob_outlet, argv->a_w.w_gpointer); break; default: - outlet_bang(x->x_obj.ob_outlet); + outlet_bang(x->x_obj.ob_outlet); } argv++; } @@ -98,7 +99,7 @@ static void drip_tick(t_drip *x) default: break; } - + if (x->current + 1 >= x->buffer + x->bufsize) { /* ok, we're done */ clock_unset(x->x_clock); x->current = 0; @@ -108,7 +109,8 @@ static void drip_tick(t_drip *x) } } -static void drip_list(t_drip *x, t_symbol* UNUSED(s), int argc, t_atom *argv) +static void drip_list(t_drip *x, t_symbol* UNUSED(s), int argc, + t_atom *argv) { if (x->flush && x->current) { /* do we want to flush */ drip_all(x, x->bufsize - (x->current - x->buffer), x->current); @@ -173,12 +175,20 @@ static void *drip_new(t_symbol* UNUSED(s), int argc, t_atom *argv) { t_drip *x = (t_drip *)pd_new(drip_class); - if (argc>1) x->flush = 1; - else x->flush = 0; + if (argc>1) { + x->flush = 1; + } else { + x->flush = 0; + } - if (argc) x->deltime = atom_getfloat(argv); - else x->deltime = -1.f; - if (x->deltime < 0.f) x->deltime = -1.0; + if (argc) { + x->deltime = atom_getfloat(argv); + } else { + x->deltime = -1.f; + } + if (x->deltime < 0.f) { + x->deltime = -1.0; + } x->x_clock = clock_new(x, (t_method)drip_tick); floatinlet_new(&x->x_obj, &x->deltime); @@ -189,12 +199,12 @@ static void *drip_new(t_symbol* UNUSED(s), int argc, t_atom *argv) void drip_setup(void) { - drip_class = class_new(gensym("drip"), (t_newmethod)drip_new, - (t_method)drip_free, sizeof(t_drip), 0 ,A_GIMME, 0); + drip_class = class_new(gensym("drip"), (t_newmethod)drip_new, + (t_method)drip_free, sizeof(t_drip), 0 ,A_GIMME, 0); class_addcreator((t_newmethod)drip_new, gensym("unfold"), A_GIMME, 0); /* for historical reasons */ - + class_addbang (drip_class, drip_bang); class_addlist (drip_class, drip_list); class_addanything(drip_class, drip_anything); diff --git a/src/envrms~.c b/src/envrms~.c index 263c2a9..1c1db80 100644 --- a/src/envrms~.c +++ b/src/envrms~.c @@ -1,4 +1,4 @@ -/* +/* * envrms~: simple envelope follower * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -28,8 +28,7 @@ t_class *sigenvrms_class; -typedef struct sigenvrms -{ +typedef struct sigenvrms { t_object x_obj; /* header */ void *x_outlet; /* a "float" outlet */ void *x_clock; /* a "clock" object */ @@ -52,24 +51,33 @@ static void *sigenvrms_new(t_floatarg fnpoints, t_floatarg fperiod) t_sample *buf; int i; - if (npoints < 1) npoints = 1024; - if (period < 1) period = npoints/2; - if (period < npoints / MAXOVERLAP + 1) + if (npoints < 1) { + npoints = 1024; + } + if (period < 1) { + period = npoints/2; + } + if (period < npoints / MAXOVERLAP + 1) { period = npoints / MAXOVERLAP + 1; - if (!(buf = getbytes(sizeof(*buf) * (npoints + MAXVSTAKEN)))) - { - error("env: couldn't allocate buffer"); - return (0); - } + } + if (!(buf = getbytes(sizeof(*buf) * (npoints + MAXVSTAKEN)))) { + error("env: couldn't allocate buffer"); + return (0); + } x = (t_sigenvrms *)pd_new(sigenvrms_class); x->x_buf = buf; x->x_npoints = npoints; x->x_phase = 0; x->x_period = period; - for (i = 0; i < MAXOVERLAP; i++) x->x_sumbuf[i] = 0; - for (i = 0; i < npoints; i++) + for (i = 0; i < MAXOVERLAP; i++) { + x->x_sumbuf[i] = 0; + } + for (i = 0; i < npoints; i++) { buf[i] = (1. - cos((2 * 3.141592654 * i) / npoints))/npoints; - for (; i < npoints+MAXVSTAKEN; i++) buf[i] = 0; + } + for (; i < npoints+MAXVSTAKEN; i++) { + buf[i] = 0; + } x->x_clock = clock_new(x, (t_method)sigenvrms_tick); x->x_outlet = outlet_new(&x->x_obj, gensym("float")); return (x); @@ -81,48 +89,51 @@ static t_int *sigenvrms_perform(t_int *w) t_sample *in = (t_sample *)(w[2]); int n = (int)(w[3]); int count; - t_sample *sump; + t_sample *sump; in += n; for (count = x->x_phase, sump = x->x_sumbuf; - count < x->x_npoints; count += x->x_realperiod, sump++) - { - t_sample *hp = x->x_buf + count; - t_sample *fp = in; - t_sample sum = *sump; - int i; - - for (i = 0; i < n; i++) - { - fp--; - sum += *hp++ * (*fp * *fp); - } - *sump = sum; + count < x->x_npoints; count += x->x_realperiod, sump++) { + t_sample *hp = x->x_buf + count; + t_sample *fp = in; + t_sample sum = *sump; + int i; + + for (i = 0; i < n; i++) { + fp--; + sum += *hp++ * (*fp **fp); } + *sump = sum; + } sump[0] = 0; x->x_phase -= n; - if (x->x_phase < 0) - { - x->x_result = x->x_sumbuf[0]; - for (count = x->x_realperiod, sump = x->x_sumbuf; - count < x->x_npoints; count += x->x_realperiod, sump++) - sump[0] = sump[1]; - sump[0] = 0; - x->x_phase = x->x_realperiod - n; - clock_delay(x->x_clock, 0L); + if (x->x_phase < 0) { + x->x_result = x->x_sumbuf[0]; + for (count = x->x_realperiod, sump = x->x_sumbuf; + count < x->x_npoints; count += x->x_realperiod, sump++) { + sump[0] = sump[1]; } + sump[0] = 0; + x->x_phase = x->x_realperiod - n; + clock_delay(x->x_clock, 0L); + } return (w+4); } static void sigenvrms_dsp(t_sigenvrms *x, t_signal **sp) { if (x->x_period % sp[0]->s_n) x->x_realperiod = - x->x_period + sp[0]->s_n - (x->x_period % sp[0]->s_n); - else x->x_realperiod = x->x_period; + x->x_period + sp[0]->s_n - (x->x_period % sp[0]->s_n); + else { + x->x_realperiod = x->x_period; + } dsp_add(sigenvrms_perform, 3, x, sp[0]->s_vec, sp[0]->s_n); - if (sp[0]->s_n > MAXVSTAKEN) bug("sigenvrms_dsp"); + if (sp[0]->s_n > MAXVSTAKEN) { + bug("sigenvrms_dsp"); + } } -static void sigenvrms_tick(t_sigenvrms *x) /* callback function for the clock */ +static void sigenvrms_tick(t_sigenvrms + *x) /* callback function for the clock */ { outlet_float(x->x_outlet, sqrtf(x->x_result)); } @@ -144,8 +155,10 @@ void envrms_tilde_setup(void) sigenvrms_class = class_new(gensym("envrms~"), (t_newmethod)sigenvrms_new, (t_method)sigenvrms_ff, sizeof(t_sigenvrms), 0, A_DEFFLOAT, A_DEFFLOAT, 0); class_addmethod(sigenvrms_class, nullfn, gensym("signal"), 0); - class_addmethod(sigenvrms_class, (t_method)sigenvrms_dsp, gensym("dsp"), 0); + class_addmethod(sigenvrms_class, (t_method)sigenvrms_dsp, gensym("dsp"), + 0); - class_addmethod(sigenvrms_class, (t_method)sigenvrms_help, gensym("help"), 0); + class_addmethod(sigenvrms_class, (t_method)sigenvrms_help, gensym("help"), + 0); zexy_register("envrms~"); } diff --git a/src/fifop.c b/src/fifop.c index fe94ffd..a5ffe3d 100644 --- a/src/fifop.c +++ b/src/fifop.c @@ -1,4 +1,4 @@ -/* +/* * fifop: a FIFO (first-in first-out) with priorities * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -46,8 +46,7 @@ typedef struct _fifop_prioritylist { struct _fifop_prioritylist *next; } t_fifop_prioritylist; -typedef struct _fifop -{ +typedef struct _fifop { t_object x_obj; t_fifop_prioritylist *fifo_list; t_float priority; /* current priority */ @@ -55,27 +54,31 @@ typedef struct _fifop t_outlet *x_out, *x_infout; } t_fifop; -static t_fifop_prioritylist*fifop_genprioritylist(t_fifop*x, t_float priority) +static t_fifop_prioritylist*fifop_genprioritylist(t_fifop*x, + t_float priority) { t_fifop_prioritylist*result=0, *dummy=0; - if(x->fifo_list!=0) - { - /* - * do we already have this priority ? - * if so, just return a pointer to that fifo - * else set the dummy-pointer to the fifo BEFORE the new one - */ - dummy=x->fifo_list; - while(dummy!=0){ - t_float prio=dummy->priority; - if(prio==priority)return dummy; - if(prio>priority)break; - result=dummy; - dummy=dummy->next; + if(x->fifo_list!=0) { + /* + * do we already have this priority ? + * if so, just return a pointer to that fifo + * else set the dummy-pointer to the fifo BEFORE the new one + */ + dummy=x->fifo_list; + while(dummy!=0) { + t_float prio=dummy->priority; + if(prio==priority) { + return dummy; + } + if(prio>priority) { + break; } - dummy=result; /* dummy points to the FIFO-before the one we want to insert */ + result=dummy; + dummy=dummy->next; } + dummy=result; /* dummy points to the FIFO-before the one we want to insert */ + } /* create a new priority list */ result = (t_fifop_prioritylist*)getbytes(sizeof( t_fifop_prioritylist)); result->priority=priority; @@ -84,7 +87,7 @@ static t_fifop_prioritylist*fifop_genprioritylist(t_fifop*x, t_float priority) result->next=0; /* insert it into the list of priority lists */ - if(dummy==0){ + if(dummy==0) { /* insert at the beginning */ result->next=x->fifo_list; x->fifo_list=result; @@ -103,18 +106,17 @@ static int add2fifo(t_fifop_prioritylist*fifoprio, int argc, t_atom *argv) t_fifop_list*fifo=0; t_fifop_list*entry=0; - if(fifoprio==0){ - error("pfifo: no fifos available"); + if(fifoprio==0) { + error("pfifo: no fifos available"); return -1; } /* create an entry for the fifo */ - if(!(entry = (t_fifop_list*)getbytes(sizeof(t_fifop_list)))) - { - error("pfifo: couldn't add entry to end of fifo"); - return -1; - } - if(!(entry->argv=(t_atom*)getbytes(argc*sizeof(t_atom)))){ + if(!(entry = (t_fifop_list*)getbytes(sizeof(t_fifop_list)))) { + error("pfifo: couldn't add entry to end of fifo"); + return -1; + } + if(!(entry->argv=(t_atom*)getbytes(argc*sizeof(t_atom)))) { error("pfifo: couldn't add list to fifo!"); return -1; } @@ -123,13 +125,13 @@ static int add2fifo(t_fifop_prioritylist*fifoprio, int argc, t_atom *argv) entry->next=0; /* insert entry into fifo */ - if(fifoprio->fifo_end){ + if(fifoprio->fifo_end) { /* append to the end of the fifo */ fifo=fifoprio->fifo_end; /* add new entry to end of fifo */ fifo->next=entry; - fifoprio->fifo_end=entry; + fifoprio->fifo_end=entry; } else { /* the new entry is the 1st entry of the fifo */ fifoprio->fifo_start=entry; @@ -140,23 +142,27 @@ static int add2fifo(t_fifop_prioritylist*fifoprio, int argc, t_atom *argv) } static t_fifop_prioritylist*getFifo(t_fifop_prioritylist*pfifo) { - if(pfifo==0)return 0; + if(pfifo==0) { + return 0; + } /* get the highest non-empty fifo */ - while(pfifo->fifo_start==0 && pfifo->next!=0)pfifo=pfifo->next; + while(pfifo->fifo_start==0 && pfifo->next!=0) { + pfifo=pfifo->next; + } return pfifo; } -static void fifop_list(t_fifop *x, t_symbol* UNUSED(s), int argc, t_atom *argv) +static void fifop_list(t_fifop *x, t_symbol* UNUSED(s), int argc, + t_atom *argv) { t_fifop_prioritylist*pfifo=0; if(!(pfifo=fifop_genprioritylist(x, x->priority))) { error("[fifop]: couldn't get priority fifo"); return; } - if(!add2fifo(pfifo, argc, argv)) - { - x->counter++; - } + if(!add2fifo(pfifo, argc, argv)) { + x->counter++; + } } static void fifop_bang(t_fifop *x) { @@ -165,11 +171,11 @@ static void fifop_bang(t_fifop *x) t_atom*argv=0; int argc=0; - if(!(pfifo=getFifo(x->fifo_list))){ + if(!(pfifo=getFifo(x->fifo_list))) { outlet_bang(x->x_infout); return; } - if(!(fifo=pfifo->fifo_start)){ + if(!(fifo=pfifo->fifo_start)) { outlet_bang(x->x_infout); return; } @@ -177,7 +183,7 @@ static void fifop_bang(t_fifop *x) x->counter--; pfifo->fifo_start=fifo->next; - if(0==pfifo->fifo_start){ + if(0==pfifo->fifo_start) { pfifo->fifo_end=0; } /* get the list from the entry */ @@ -200,24 +206,26 @@ static void fifop_bang(t_fifop *x) static void fifop_query(t_fifop*x) { z_verbose(1, "%d elements in fifo", (int)x->counter); - + outlet_float(x->x_infout, (t_float)x->counter); } static void fifop_clear(t_fifop*x) { t_fifop_prioritylist *fifo_list=x->fifo_list; - while(fifo_list){ + while(fifo_list) { t_fifop_prioritylist *fifo_list2=fifo_list; t_fifop_list*fifo=fifo_list2->fifo_start; fifo_list=fifo_list->next; - while(fifo){ + while(fifo) { t_fifop_list*fifo2=fifo; fifo=fifo->next; - if(fifo2->argv)freebytes(fifo2->argv, fifo2->argc*sizeof(t_atom)); + if(fifo2->argv) { + freebytes(fifo2->argv, fifo2->argc*sizeof(t_atom)); + } fifo2->argv=0; fifo2->argc=0; fifo2->next=0; @@ -234,7 +242,7 @@ static void fifop_clear(t_fifop*x) } /* this is NOT re-entrant! */ static void fifop_dump(t_fifop*x) -{ +{ t_fifop_prioritylist*pfifo=getFifo(x->fifo_list); if(!pfifo||!pfifo->fifo_start) { @@ -288,16 +296,20 @@ static void *fifop_new(void) void fifop_setup(void) { fifop_class = class_new(gensym("fifop"), (t_newmethod)fifop_new, - (t_method)fifop_free, sizeof(t_fifop), 0, A_NULL); + (t_method)fifop_free, sizeof(t_fifop), 0, A_NULL); class_addbang (fifop_class, fifop_bang); class_addlist (fifop_class, fifop_list); - class_addmethod (fifop_class, (t_method)fifop_clear, gensym("clear"), A_NULL); - class_addmethod (fifop_class, (t_method)fifop_dump, gensym("dump"), A_NULL); + class_addmethod (fifop_class, (t_method)fifop_clear, gensym("clear"), + A_NULL); + class_addmethod (fifop_class, (t_method)fifop_dump, gensym("dump"), + A_NULL); - class_addmethod (fifop_class, (t_method)fifop_query, gensym("info"), A_NULL); - class_addmethod (fifop_class, (t_method)fifop_help, gensym("help"), A_NULL); + class_addmethod (fifop_class, (t_method)fifop_query, gensym("info"), + A_NULL); + class_addmethod (fifop_class, (t_method)fifop_help, gensym("help"), + A_NULL); zexy_register("fifop"); } diff --git a/src/freadln.c b/src/freadln.c index e8e09bb..42ca868 100644 --- a/src/freadln.c +++ b/src/freadln.c @@ -1,4 +1,4 @@ -/* +/* * freadln: reads messages continuously from the lines of a file * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -37,125 +37,133 @@ #define MIN_FREADLN_LENGTH 10 -/* freadln: reads messages continuously from the lines of - * a file that doesn't necessarily need to fit +/* freadln: reads messages continuously from the lines of + * a file that doesn't necessarily need to fit * into the RAM of your system */ static t_class *freadln_class; -typedef struct freadln -{ - t_object x_ob; - FILE *x_file; - char *x_filename; - char *x_textbuf; - int x_textbuf_length; - t_outlet *x_message_outlet; - t_outlet *x_readybang_outlet; +typedef struct freadln { + t_object x_ob; + FILE *x_file; + char *x_filename; + char *x_textbuf; + int x_textbuf_length; + t_outlet *x_message_outlet; + t_outlet *x_readybang_outlet; - char linebreak_chr[3]; + char linebreak_chr[3]; - t_canvas *x_canvas; + t_canvas *x_canvas; } t_freadln; static void freadln_close (t_freadln *x) { - if(x->x_file) - fclose(x->x_file); - x->x_file=0; - if(x->x_filename) - freebytes(x->x_filename, sizeof(char)*MAXPDSTRING); - x->x_filename=0; - if(x->x_textbuf) - freebytes(x->x_textbuf, sizeof(char)*x->x_textbuf_length); - x->x_textbuf=0; - x->x_textbuf_length=0; + if(x->x_file) { + fclose(x->x_file); + } + x->x_file=0; + if(x->x_filename) { + freebytes(x->x_filename, sizeof(char)*MAXPDSTRING); + } + x->x_filename=0; + if(x->x_textbuf) { + freebytes(x->x_textbuf, sizeof(char)*x->x_textbuf_length); + } + x->x_textbuf=0; + x->x_textbuf_length=0; } static void freadln_open (t_freadln *x, t_symbol *s, t_symbol*type) { - char filenamebuf[MAXPDSTRING], *filenamebufptr; - char*dirname=canvas_getdir(x->x_canvas)->s_name; - int fd, len; - post("open: %s", s->s_name); + char filenamebuf[MAXPDSTRING], *filenamebufptr; + char*dirname=canvas_getdir(x->x_canvas)->s_name; + int fd, len; + post("open: %s", s->s_name); - freadln_close(x); + freadln_close(x); -/* - if(type!=gensym("cr")) { - pd_error(x, "currently only 'cr' type files are implemented!"); - return; - } -*/ - if (type==gensym("cr")) - strcpy(x->linebreak_chr,"\n"); - else - strcpy(x->linebreak_chr,";\n"); - + /* + if(type!=gensym("cr")) { + pd_error(x, "currently only 'cr' type files are implemented!"); + return; + } + */ + if (type==gensym("cr")) { + strcpy(x->linebreak_chr,"\n"); + } else { + strcpy(x->linebreak_chr,";\n"); + } - /* directory, filename, extension, dirresult, nameresult, unsigned int size, int bin */ - if ((fd=open_via_path( - dirname, - s->s_name, "", - filenamebuf, - &filenamebufptr, - MAXPDSTRING, - 0)) < 0 ) { - pd_error(x, "%s: failed to open %s", s->s_name, filenamebuf); - return; - } - z_close(fd); - len=strlen(filenamebuf); - if (!(x->x_filename=(char*)getbytes(sizeof(char)*(len+strlen(s->s_name)+2)))) { - pd_error(x, "out of memory"); - freadln_close(x); - return; - } - strcpy(x->x_filename,filenamebuf); - strcpy(x->x_filename+len,"/"); - strcpy(x->x_filename+len+1,filenamebufptr); - if (!(x->x_file=fopen(x->x_filename, "r"))) { - pd_error(x, "freadln: failed to fopen %s",x->x_filename); - return; - } - if (!(x->x_textbuf = (char *) getbytes (MIN_FREADLN_LENGTH * sizeof(char)))) { - pd_error(x, "out of memory!"); - freadln_close(x); - return; - } - x->x_textbuf_length=MIN_FREADLN_LENGTH; + + /* directory, filename, extension, dirresult, nameresult, unsigned int size, int bin */ + if ((fd=open_via_path( + dirname, + s->s_name, "", + filenamebuf, + &filenamebufptr, + MAXPDSTRING, + 0)) < 0 ) { + pd_error(x, "%s: failed to open %s", s->s_name, filenamebuf); + return; + } + z_close(fd); + len=strlen(filenamebuf); + if (!(x->x_filename=(char*)getbytes(sizeof(char)*(len+strlen( + s->s_name)+2)))) { + pd_error(x, "out of memory"); + freadln_close(x); + return; + } + strcpy(x->x_filename,filenamebuf); + strcpy(x->x_filename+len,"/"); + strcpy(x->x_filename+len+1,filenamebufptr); + if (!(x->x_file=fopen(x->x_filename, "r"))) { + pd_error(x, "freadln: failed to fopen %s",x->x_filename); + return; + } + if (!(x->x_textbuf = (char *) getbytes (MIN_FREADLN_LENGTH * sizeof( + char)))) { + pd_error(x, "out of memory!"); + freadln_close(x); + return; + } + x->x_textbuf_length=MIN_FREADLN_LENGTH; } -static int enlarge_cstr_if_required(const char **c_str, int *len, const int desired_min_length) +static int enlarge_cstr_if_required(const char **c_str, int *len, + const int desired_min_length) { - if ((!(*c_str))||*len==0) { - *c_str = (char*) calloc (1,sizeof(char)); - return 1; - } - if (len[0]x_textbuf_length < 1)?1:x->x_textbuf_length; - int linebreak_pos=0; - int items_read; - t_binbuf *bbuf; - t_atom *abuf; - int abuf_length; - int rewind_after; + int min_length=(x->x_textbuf_length < 1)?1:x->x_textbuf_length; + int linebreak_pos=0; + int items_read; + t_binbuf *bbuf; + t_atom *abuf; + int abuf_length; + int rewind_after; - if (!x->x_file) { - pd_error(x, "no file opened for reading"); - freadln_done(x); - return; - } - - do { - if (linebreak_pos==-1) { - min_length<<=1; - fseek(x->x_file,-(long)(x->x_textbuf_length),SEEK_CUR); - } - if (!enlarge_cstr_if_required((const char**) &x->x_textbuf, &x->x_textbuf_length, min_length)) { - pd_error(x, "out of memory"); - x->x_textbuf_length=0; - freadln_close(x); - freadln_done(x); - return; - } - if (!(items_read=fread(x->x_textbuf,sizeof(char),x->x_textbuf_length,x->x_file))) { - freadln_close(x); - freadln_done(x); - return; - } - x->x_textbuf[x->x_textbuf_length-1]=0; - } while (((linebreak_pos=cstr_char_pos(x->x_textbuf,x->linebreak_chr[0]))==-1) && - !(items_read < x->x_textbuf_length)); - - if (linebreak_pos-1 < items_read - strlen(x->linebreak_chr)) { - rewind_after=items_read-linebreak_pos; - fseek(x->x_file,-(long)(rewind_after),SEEK_CUR); - } - if (linebreak_pos==-1) - linebreak_pos=items_read; - x->x_textbuf[linebreak_pos-1]='\0'; - if (!(bbuf=binbuf_new())) { - pd_error(x, "out of memory"); - freadln_close(x); - freadln_done(x); - return; - } - binbuf_text(bbuf, x->x_textbuf, linebreak_pos-1); - abuf = binbuf_getvec(bbuf); - abuf_length = binbuf_getnatom(bbuf); - if (abuf_length>0) { - if (abuf->a_type==A_SYMBOL) { - outlet_anything(x->x_message_outlet, atom_getsymbol(abuf), abuf_length-1, abuf+1); - } - else { - outlet_list(x->x_message_outlet, gensym("list"), abuf_length, abuf); - } - } - else { - outlet_list(x->x_message_outlet, atom_getsymbol(abuf), 0, abuf); - } - /* NOTE: the following line might be a problem in recursions - * and could be performed before to outlet_* as well, - * but(!) atom buffer abuf must be copied if doing so. - */ - binbuf_free(bbuf); + if (!x->x_file) { + pd_error(x, "no file opened for reading"); + freadln_done(x); + return; + } + + do { + if (linebreak_pos==-1) { + min_length<<=1; + fseek(x->x_file,-(long)(x->x_textbuf_length),SEEK_CUR); + } + if (!enlarge_cstr_if_required((const char**) &x->x_textbuf, + &x->x_textbuf_length, min_length)) { + pd_error(x, "out of memory"); + x->x_textbuf_length=0; + freadln_close(x); + freadln_done(x); + return; + } + if (!(items_read=fread(x->x_textbuf,sizeof(char),x->x_textbuf_length, + x->x_file))) { + freadln_close(x); + freadln_done(x); + return; + } + x->x_textbuf[x->x_textbuf_length-1]=0; + } while (((linebreak_pos=cstr_char_pos(x->x_textbuf, + x->linebreak_chr[0]))==-1) && + !(items_read < x->x_textbuf_length)); + + if (linebreak_pos-1 < items_read - strlen(x->linebreak_chr)) { + rewind_after=items_read-linebreak_pos; + fseek(x->x_file,-(long)(rewind_after),SEEK_CUR); + } + if (linebreak_pos==-1) { + linebreak_pos=items_read; + } + x->x_textbuf[linebreak_pos-1]='\0'; + if (!(bbuf=binbuf_new())) { + pd_error(x, "out of memory"); + freadln_close(x); + freadln_done(x); + return; + } + binbuf_text(bbuf, x->x_textbuf, linebreak_pos-1); + abuf = binbuf_getvec(bbuf); + abuf_length = binbuf_getnatom(bbuf); + if (abuf_length>0) { + if (abuf->a_type==A_SYMBOL) { + outlet_anything(x->x_message_outlet, atom_getsymbol(abuf), abuf_length-1, + abuf+1); + } else { + outlet_list(x->x_message_outlet, gensym("list"), abuf_length, abuf); + } + } else { + outlet_list(x->x_message_outlet, atom_getsymbol(abuf), 0, abuf); + } + /* NOTE: the following line might be a problem in recursions + * and could be performed before to outlet_* as well, + * but(!) atom buffer abuf must be copied if doing so. + */ + binbuf_free(bbuf); } static void freadln_free (t_freadln *x) { - freadln_close(x); - outlet_free (x->x_message_outlet); - outlet_free (x->x_readybang_outlet); + freadln_close(x); + outlet_free (x->x_message_outlet); + outlet_free (x->x_readybang_outlet); } static void *freadln_new(void) { - t_freadln *x = (t_freadln *)pd_new(freadln_class); - x->x_message_outlet = outlet_new(&x->x_ob, gensym("list")); - x->x_readybang_outlet = outlet_new(&x->x_ob, gensym("bang")); - x->x_filename=0; - x->x_file=0; - x->x_textbuf=0; - x->x_canvas = canvas_getcurrent(); - return (void *)x; + t_freadln *x = (t_freadln *)pd_new(freadln_class); + x->x_message_outlet = outlet_new(&x->x_ob, gensym("list")); + x->x_readybang_outlet = outlet_new(&x->x_ob, gensym("bang")); + x->x_filename=0; + x->x_file=0; + x->x_textbuf=0; + x->x_canvas = canvas_getcurrent(); + return (void *)x; } void freadln_setup(void) { - freadln_class = class_new(gensym("freadln"), (t_newmethod)freadln_new, - (t_method) freadln_free, sizeof(t_freadln), 0, 0); - class_addmethod(freadln_class, (t_method)freadln_open, gensym("open"), A_SYMBOL, A_DEFSYM, 0); - class_addmethod(freadln_class, (t_method)freadln_close, gensym("close"), A_NULL, 0); - class_addbang(freadln_class, (t_method)freadln_readline); + freadln_class = class_new(gensym("freadln"), (t_newmethod)freadln_new, + (t_method) freadln_free, sizeof(t_freadln), 0, 0); + class_addmethod(freadln_class, (t_method)freadln_open, gensym("open"), + A_SYMBOL, A_DEFSYM, 0); + class_addmethod(freadln_class, (t_method)freadln_close, gensym("close"), + A_NULL, 0); + class_addbang(freadln_class, (t_method)freadln_readline); - zexy_register("freadln"); + zexy_register("freadln"); } diff --git a/src/fwriteln.c b/src/fwriteln.c index a53360f..1822631 100644 --- a/src/fwriteln.c +++ b/src/fwriteln.c @@ -1,4 +1,4 @@ -/* +/* * fwriteln: writes messages continuously into a file * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -34,227 +34,223 @@ * Franz Zotter zotter@iem.at, 2007 * Institute of Electronic Music and Acoustics * - * parts of this externals were copied from Iohannes zmoelnig's + * parts of this externals were copied from Iohannes zmoelnig's * iemmatrix */ static t_class *fwriteln_class; -typedef struct fwriteln -{ - t_object x_ob; - FILE *x_file; - char *x_filename; - char *x_textbuf; - char linebreak_chr[3]; - char format_string_afloats[10]; +typedef struct fwriteln { + t_object x_ob; + FILE *x_file; + char *x_filename; + char *x_textbuf; + char linebreak_chr[3]; + char format_string_afloats[10]; } t_fwriteln; static void fwriteln_close (t_fwriteln *x) { - if(x->x_file) - fclose(x->x_file); - x->x_file=0; - if(x->x_filename) - free(x->x_filename); - x->x_filename=0; - if(x->x_textbuf) - freebytes(x->x_textbuf, MAXPDSTRING + 1); - x->x_textbuf=0; + if(x->x_file) { + fclose(x->x_file); + } + x->x_file=0; + if(x->x_filename) { + free(x->x_filename); + } + x->x_filename=0; + if(x->x_textbuf) { + freebytes(x->x_textbuf, MAXPDSTRING + 1); + } + x->x_textbuf=0; } static void string_copy(const char* const from, char** to) { if ((*to = malloc(strlen(from) + 1))) { - strcpy(*to, from); - } + strcpy(*to, from); + } } static void fwriteln_open (t_fwriteln *x, t_symbol *s, t_symbol*type) { - char* filename; + char* filename; - string_copy(s->s_name, &filename); + string_copy(s->s_name, &filename); - sys_bashfilename (filename, filename); + sys_bashfilename (filename, filename); - fwriteln_close (x); + fwriteln_close (x); -/* if(0==type || type!=gensym("cr")) { - pd_error(x, "unknown type '%s'", (type)?type->s_name:""); - return; - }*/ + /* if(0==type || type!=gensym("cr")) { + pd_error(x, "unknown type '%s'", (type)?type->s_name:""); + return; + }*/ - if (type==gensym("cr")) - strcpy(x->linebreak_chr,"\n"); - else - strcpy(x->linebreak_chr,";\n"); + if (type==gensym("cr")) { + strcpy(x->linebreak_chr,"\n"); + } else { + strcpy(x->linebreak_chr,";\n"); + } - if (!(x->x_file=fopen(filename, "w"))) { - pd_error(x, "failed to open %128s",filename); - free(filename); - return; - } - string_copy(filename, &x->x_filename); - free(filename); - x->x_textbuf = (char *) getbytes (MAXPDSTRING + 1); + if (!(x->x_file=fopen(filename, "w"))) { + pd_error(x, "failed to open %128s",filename); + free(filename); + return; + } + string_copy(filename, &x->x_filename); + free(filename); + x->x_textbuf = (char *) getbytes (MAXPDSTRING + 1); } -static void fwriteln_write (t_fwriteln *x, t_symbol *s, int argc, t_atom *argv) +static void fwriteln_write (t_fwriteln *x, t_symbol *s, int argc, + t_atom *argv) { - int length=0; - char *text=x->x_textbuf; - if (x->x_file) { - if ((s!=gensym("list"))||(argv->a_type==A_SYMBOL)) { - snprintf(text,MAXPDSTRING,"%s ", s->s_name); - text[MAXPDSTRING-1]=0; - length=strlen(text); - if (fwrite(text, length*sizeof(char),1,x->x_file) < 1) { - pd_error(x, "failed to write %128s",x->x_filename); - freebytes (text, MAXPDSTRING * sizeof(char)); - fwriteln_close(x); - return; - } - } - while (argc--) - { - switch (argv->a_type) { - case A_FLOAT: - snprintf(text,MAXPDSTRING,x->format_string_afloats, - atom_getfloat(argv)); - text[MAXPDSTRING-1]=0; - length=strlen(text); - if (fwrite(text, length*sizeof(char),1,x->x_file) < 1) { - pd_error(x, "failed to write %128s",x->x_filename); - freebytes (text, MAXPDSTRING * sizeof(char)); - fwriteln_close(x); - return; - } - break; - case A_SYMBOL: - snprintf(text,MAXPDSTRING,"%s ", atom_getsymbol(argv)->s_name); - text[MAXPDSTRING-1]=0; - length=strlen(text); - if (fwrite(text, length*sizeof(char),1,x->x_file) < 1) { - pd_error(x, "failed to write %128s",x->x_filename); - freebytes (text, MAXPDSTRING * sizeof(char)); - fwriteln_close(x); - return; - } - break; - case A_COMMA: - snprintf(text,MAXPDSTRING,", "); - length=strlen(text); - if (fwrite(text, length*sizeof(char),1,x->x_file) < 1) { - pd_error(x, "failed to write %128s",x->x_filename); - freebytes (text, MAXPDSTRING * sizeof(char)); - fwriteln_close(x); - return; - } - break; - case A_SEMI: - snprintf(text,MAXPDSTRING,"; "); - length=strlen(text); - if (fwrite(text, length*sizeof(char),1,x->x_file) < 1) { - pd_error(x, "failed to write %128s",x->x_filename); - freebytes (text, MAXPDSTRING * sizeof(char)); - fwriteln_close(x); - return; - } - break; - default: - break; - } - argv++; - } - - snprintf(text,MAXPDSTRING,"%s", x->linebreak_chr); + int length=0; + char *text=x->x_textbuf; + if (x->x_file) { + if ((s!=gensym("list"))||(argv->a_type==A_SYMBOL)) { + snprintf(text,MAXPDSTRING,"%s ", s->s_name); + text[MAXPDSTRING-1]=0; length=strlen(text); if (fwrite(text, length*sizeof(char),1,x->x_file) < 1) { - pd_error(x, "failed to write %128s",x->x_filename); - freebytes (text, MAXPDSTRING * sizeof(char)); - fwriteln_close(x); - return; + pd_error(x, "failed to write %128s",x->x_filename); + freebytes (text, MAXPDSTRING * sizeof(char)); + fwriteln_close(x); + return; + } + } + while (argc--) { + switch (argv->a_type) { + case A_FLOAT: + snprintf(text,MAXPDSTRING,x->format_string_afloats, + atom_getfloat(argv)); + text[MAXPDSTRING-1]=0; + length=strlen(text); + if (fwrite(text, length*sizeof(char),1,x->x_file) < 1) { + pd_error(x, "failed to write %128s",x->x_filename); + freebytes (text, MAXPDSTRING * sizeof(char)); + fwriteln_close(x); + return; + } + break; + case A_SYMBOL: + snprintf(text,MAXPDSTRING,"%s ", atom_getsymbol(argv)->s_name); + text[MAXPDSTRING-1]=0; + length=strlen(text); + if (fwrite(text, length*sizeof(char),1,x->x_file) < 1) { + pd_error(x, "failed to write %128s",x->x_filename); + freebytes (text, MAXPDSTRING * sizeof(char)); + fwriteln_close(x); + return; + } + break; + case A_COMMA: + snprintf(text,MAXPDSTRING,", "); + length=strlen(text); + if (fwrite(text, length*sizeof(char),1,x->x_file) < 1) { + pd_error(x, "failed to write %128s",x->x_filename); + freebytes (text, MAXPDSTRING * sizeof(char)); + fwriteln_close(x); + return; + } + break; + case A_SEMI: + snprintf(text,MAXPDSTRING,"; "); + length=strlen(text); + if (fwrite(text, length*sizeof(char),1,x->x_file) < 1) { + pd_error(x, "failed to write %128s",x->x_filename); + freebytes (text, MAXPDSTRING * sizeof(char)); + fwriteln_close(x); + return; + } + break; + default: + break; } - } - else { - pd_error(x, "no file opened for writing"); - } + argv++; + } + + snprintf(text,MAXPDSTRING,"%s", x->linebreak_chr); + length=strlen(text); + if (fwrite(text, length*sizeof(char),1,x->x_file) < 1) { + pd_error(x, "failed to write %128s",x->x_filename); + freebytes (text, MAXPDSTRING * sizeof(char)); + fwriteln_close(x); + return; + } + } else { + pd_error(x, "no file opened for writing"); + } } static void fwriteln_free (t_fwriteln *x) { - fwriteln_close(x); + fwriteln_close(x); } static void *fwriteln_new(t_symbol *s, int argc, t_atom *argv) { - int k; - int width; - int precision; - char float_format[3]="g "; - char width_str[3]=""; - char precision_str[4]=""; - char prefix[3]="%"; - t_fwriteln *x = (t_fwriteln *)pd_new(fwriteln_class); - x->x_filename=0; - x->x_file=0; - x->x_textbuf=0; - for (k=0; k=argc)||(argv[k+1].a_type!=A_FLOAT)) { - post("fwriteln: no value given for precision!"); - } - else { - precision=atom_getint(&argv[++k]); - precision=(precision<0)?0:precision; - precision=(precision>30)?30:precision; - snprintf(precision_str,4,".%d",precision); - } - } - else if (atom_getsymbol(&argv[k])==gensym("w")) { - if ((k+1>=argc)||(argv[k+1].a_type!=A_FLOAT)) { - post("fwriteln: no value given for width!"); - } - else { - width=atom_getint(&argv[++k]); - width=(width<1)?1:width; - width=(width>40)?40:width; - snprintf(width_str,3,"%d",width); - } - } - else if (atom_getsymbol(&argv[k])==gensym("g")) { - float_format[0]='g'; - } - else if (atom_getsymbol(&argv[k])==gensym("f")) { - float_format[0]='f'; - } - else if (atom_getsymbol(&argv[k])==gensym("e")) { - float_format[0]='e'; - } - else if (atom_getsymbol(&argv[k])==gensym("-")) { - strcpy(prefix,"%-"); + int k; + int width; + int precision; + char float_format[3]="g "; + char width_str[3]=""; + char precision_str[4]=""; + char prefix[3]="%"; + t_fwriteln *x = (t_fwriteln *)pd_new(fwriteln_class); + x->x_filename=0; + x->x_file=0; + x->x_textbuf=0; + for (k=0; k=argc)||(argv[k+1].a_type!=A_FLOAT)) { + post("fwriteln: no value given for precision!"); + } else { + precision=atom_getint(&argv[++k]); + precision=(precision<0)?0:precision; + precision=(precision>30)?30:precision; + snprintf(precision_str,4,".%d",precision); } - else if (atom_getsymbol(&argv[k])==gensym("+")) { - strcpy(prefix,"%+"); + } else if (atom_getsymbol(&argv[k])==gensym("w")) { + if ((k+1>=argc)||(argv[k+1].a_type!=A_FLOAT)) { + post("fwriteln: no value given for width!"); + } else { + width=atom_getint(&argv[++k]); + width=(width<1)?1:width; + width=(width>40)?40:width; + snprintf(width_str,3,"%d",width); } - } - x->format_string_afloats[0]='\0'; - strncat(x->format_string_afloats,prefix,2); - strncat(x->format_string_afloats,width_str,2); - strncat(x->format_string_afloats,precision_str,3); - strncat(x->format_string_afloats,float_format,2); - return (void *)x; + } else if (atom_getsymbol(&argv[k])==gensym("g")) { + float_format[0]='g'; + } else if (atom_getsymbol(&argv[k])==gensym("f")) { + float_format[0]='f'; + } else if (atom_getsymbol(&argv[k])==gensym("e")) { + float_format[0]='e'; + } else if (atom_getsymbol(&argv[k])==gensym("-")) { + strcpy(prefix,"%-"); + } else if (atom_getsymbol(&argv[k])==gensym("+")) { + strcpy(prefix,"%+"); + } + } + x->format_string_afloats[0]='\0'; + strncat(x->format_string_afloats,prefix,2); + strncat(x->format_string_afloats,width_str,2); + strncat(x->format_string_afloats,precision_str,3); + strncat(x->format_string_afloats,float_format,2); + return (void *)x; } void fwriteln_setup(void) { - fwriteln_class = class_new(gensym("fwriteln"), (t_newmethod)fwriteln_new, - (t_method) fwriteln_free, sizeof(t_fwriteln), CLASS_DEFAULT, A_GIMME, 0); - class_addmethod(fwriteln_class, (t_method)fwriteln_open, gensym("open"), A_SYMBOL, A_DEFSYM, 0); - class_addmethod(fwriteln_class, (t_method)fwriteln_close, gensym("close"), A_NULL, 0); - class_addanything(fwriteln_class, (t_method)fwriteln_write); + fwriteln_class = class_new(gensym("fwriteln"), (t_newmethod)fwriteln_new, + (t_method) fwriteln_free, sizeof(t_fwriteln), CLASS_DEFAULT, A_GIMME, 0); + class_addmethod(fwriteln_class, (t_method)fwriteln_open, gensym("open"), + A_SYMBOL, A_DEFSYM, 0); + class_addmethod(fwriteln_class, (t_method)fwriteln_close, gensym("close"), + A_NULL, 0); + class_addanything(fwriteln_class, (t_method)fwriteln_write); - zexy_register("fwriteln"); + zexy_register("fwriteln"); } diff --git a/src/glue.c b/src/glue.c index 6821d3e..70b0bf5 100644 --- a/src/glue.c +++ b/src/glue.c @@ -1,4 +1,4 @@ -/* +/* * glue: glue two lists together (use [list append] instead) * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -22,8 +22,7 @@ static t_class *glue_class; -typedef struct _zglue -{ +typedef struct _zglue { t_object x_obj; t_atom *ap2, *ap; @@ -32,17 +31,21 @@ typedef struct _zglue t_int changed; } t_glue; -static void glue_lst2(t_glue *x, t_symbol* UNUSED(s), int argc, t_atom *argv) +static void glue_lst2(t_glue *x, t_symbol* UNUSED(s), int argc, + t_atom *argv) { x->changed = 1; if (x->n2 != argc) { freebytes(x->ap2, x->n2 * sizeof(t_atom)); x->n2 = argc; x->ap2 = copybytes(argv, argc * sizeof(t_atom)); - } else memcpy(x->ap2, argv, argc * sizeof(t_atom)); + } else { + memcpy(x->ap2, argv, argc * sizeof(t_atom)); + } } -static void glue_lst(t_glue *x, t_symbol* UNUSED(s), int argc, t_atom *argv) +static void glue_lst(t_glue *x, t_symbol* UNUSED(s), int argc, + t_atom *argv) { if (x->n != x->n2+argc) { freebytes(x->ap, x->n * sizeof(t_atom)); @@ -50,7 +53,9 @@ static void glue_lst(t_glue *x, t_symbol* UNUSED(s), int argc, t_atom *argv) x->n = x->n1+x->n2; x->ap = (t_atom *)getbytes(sizeof(t_atom)*x->n); memcpy(x->ap+argc, x->ap2, x->n2*sizeof(t_atom)); - } else if ((x->n1 != argc)||x->changed)memcpy(x->ap+argc, x->ap2, x->n2*sizeof(t_atom)); + } else if ((x->n1 != argc)||x->changed) { + memcpy(x->ap+argc, x->ap2, x->n2*sizeof(t_atom)); + } x->n1 = argc; memcpy(x->ap, argv, x->n1*sizeof(t_atom)); @@ -63,7 +68,7 @@ static void glue_lst(t_glue *x, t_symbol* UNUSED(s), int argc, t_atom *argv) static void glue_bang(t_glue *x) { if (x->changed) { - if (x->n1+x->n2 != x->n){ + if (x->n1+x->n2 != x->n) { t_atom *ap = (t_atom*)getbytes(sizeof(t_atom)*(x->n1+x->n2)); memcpy(ap, x->ap, x->n1*sizeof(t_atom)); freebytes(x->ap, sizeof(t_atom)*x->n); @@ -93,7 +98,9 @@ static void *glue_new(t_symbol* UNUSED(s), int argc, t_atom *argv) x->ap=x->ap2 = 0; x->changed = 0; - if (argc)glue_lst2(x, gensym("list"), argc, argv); + if (argc) { + glue_lst2(x, gensym("list"), argc, argv); + } return (x); } @@ -105,8 +112,8 @@ static void glue_help(t_glue*x) void glue_setup(void) { - glue_class = class_new(gensym("glue"), (t_newmethod)glue_new, - (t_method)glue_free, sizeof(t_glue), 0, A_GIMME, 0); + glue_class = class_new(gensym("glue"), (t_newmethod)glue_new, + (t_method)glue_free, sizeof(t_glue), 0, A_GIMME, 0); class_addlist(glue_class, glue_lst); class_addmethod (glue_class, (t_method)glue_lst2, gensym(""), A_GIMME, 0); class_addbang(glue_class, glue_bang); diff --git a/src/index.c b/src/index.c index 405bc19..403a3b2 100644 --- a/src/index.c +++ b/src/index.c @@ -1,4 +1,4 @@ -/* +/* * index: associative dictionary * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,18 +7,18 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ -/* +/* (c) 2005:forum::für::umläute:2000 "index" simulates an associative index :: that is : convert a symbol to an index @@ -32,7 +32,7 @@ TODO: "add" at a specific position (like "add 10 hallo" of "add hallo 10") (??) FIXED TODO: "delete" from a specific position (like "delete 4" deletes the 4th element) FIXED TODO: get the number of stored entries ("bang") FIXED - + TODO: resize the array if it gets to small */ @@ -44,8 +44,7 @@ static t_class *index_class; -typedef struct _index -{ +typedef struct _index { t_object x_obj; int entries, maxentries; @@ -64,34 +63,42 @@ typedef struct _index * LATER: shouldn't this return "-1" on failure ? */ static int find_last(t_symbol **names, int maxentries) -{ /* returns the index of the last entry (0..(maxentries-1)) */ - while (maxentries--) if (names[maxentries]) return maxentries; +{ + /* returns the index of the last entry (0..(maxentries-1)) */ + while (maxentries--) if (names[maxentries]) { + return maxentries; + } return 0; } -/* search the array for "key" - * if it is not there, return "-1" +/* search the array for "key" + * if it is not there, return "-1" */ static int find_item(const t_symbol *key, t_symbol **names, int maxentries) -{ /* returns index (0..[maxentries-1?]) on success; -1 if the item could not be found */ +{ + /* returns index (0..[maxentries-1?]) on success; -1 if the item could not be found */ int i=-1; int max = find_last(names, maxentries); - + while (++i<=max) - if (names[i] && key==names[i]) return i; - + if (names[i] && key==names[i]) { + return i; + } + return -1; } /* find the first NULL entry in the array - * return "-1" if none can be found + * return "-1" if none can be found */ static int find_free(t_symbol **names, int maxentries) { int i=0; while (inames, x->maxentries)+1) ) + if ( (element = find_item(s, x->names, x->maxentries)+1) ) { outlet_float(x->x_obj.ob_outlet, (t_float)element); - else if (x->auto_mode) /* not yet stored: add automatically */ + } else if (x->auto_mode) { /* not yet stored: add automatically */ index_add(x, s, 0); - else outlet_float(x->x_obj.ob_outlet, 0.f); /* not yet stored but do not add */ + } else { + outlet_float(x->x_obj.ob_outlet, 0.f); /* not yet stored but do not add */ + } } /* output the entry at a given index */ static void index_float(t_index *x, t_float findex) { int iindex = (int)findex; - if ((iindex > 0) && (iindex <= x->maxentries) && (x->names[iindex-1])) - { - /* TB: output symbol to outlet */ - outlet_symbol (x->x_obj.ob_outlet,x->names[iindex-1]); + if ((iindex > 0) && (iindex <= x->maxentries) && (x->names[iindex-1])) { + /* TB: output symbol to outlet */ + outlet_symbol (x->x_obj.ob_outlet,x->names[iindex-1]); } } @@ -131,14 +139,17 @@ static void index_add(t_index *x, t_symbol *s, t_float f) int newentry=(int)f; if (! (find_item(s, x->names, x->maxentries)+1) ) { - if (x->auto_resize && (x->entries==x->maxentries || newentry>=x->maxentries)){ + if (x->auto_resize && (x->entries==x->maxentries + || newentry>=x->maxentries)) { /* do some resizing */ int maxentries=(newentry>x->maxentries)?newentry:(x->maxentries*2); int i; t_symbol**buf=(t_symbol **)getbytes(sizeof(t_symbol *) * maxentries); - if(buf!=0){ + if(buf!=0) { memcpy(buf, x->names, sizeof(t_symbol *) * x->maxentries); - for(i=x->maxentries; imaxentries; inames, sizeof(t_symbol *) * x->maxentries); @@ -148,10 +159,12 @@ static void index_add(t_index *x, t_symbol *s, t_float f) } if ( x->entries < x->maxentries ) { - if(newentry>0){ + if(newentry>0) { newentry--; - if(x->names[newentry]){ /* it is already taken! */ - z_verbose(1, "index :: couldn't add element '%s' at position %d (already taken)", s->s_name, newentry+1); + if(x->names[newentry]) { /* it is already taken! */ + z_verbose(1, + "index :: couldn't add element '%s' at position %d (already taken)", + s->s_name, newentry+1); outlet_float(x->x_obj.ob_outlet, -1.f); return; } @@ -159,32 +172,39 @@ static void index_add(t_index *x, t_symbol *s, t_float f) newentry=find_free(x->names, x->maxentries); } if (newentry + 1) { - x->entries++; - x->names[newentry]=s; - outlet_float(x->x_obj.ob_outlet, (t_float)newentry+1); + x->entries++; + x->names[newentry]=s; + outlet_float(x->x_obj.ob_outlet, (t_float)newentry+1); return; - } else error("index :: couldn't find any place for new entry"); - } else error("index :: max number of elements (%d) reached !", x->maxentries); - } else z_verbose(1, "index :: element '%s' already exists", s->s_name); + } else { + error("index :: couldn't find any place for new entry"); + } + } else { + error("index :: max number of elements (%d) reached !", x->maxentries); + } + } else { + z_verbose(1, "index :: element '%s' already exists", s->s_name); + } /* couldn't add the symbol to our index table */ outlet_float(x->x_obj.ob_outlet, -1.f); } /* delete a symbol from the map (if it is in there) */ -static void index_delete(t_index *x, t_symbol* UNUSED(s), int argc, t_atom*argv) +static void index_delete(t_index *x, t_symbol* UNUSED(s), int argc, + t_atom*argv) { int idx=-1; - if(argc!=1){ + if(argc!=1) { error("index :: delete what ?"); return; } else { - if(argv->a_type==A_FLOAT){ + if(argv->a_type==A_FLOAT) { idx=atom_getint(argv)-1; - } else if (argv->a_type==A_SYMBOL){ + } else if (argv->a_type==A_SYMBOL) { idx=find_item(atom_getsymbol(argv),x->names, x->maxentries); } else { error("index :: delete what ?"); - return; + return; } } @@ -223,8 +243,8 @@ static void index_dump(t_index *x) { t_atom ap[2]; int i=0; - for(i=0; imaxentries; i++){ - if(x->names[i]){ + for(i=0; imaxentries; i++) { + if(x->names[i]) { SETSYMBOL(ap, x->names[i]); SETFLOAT(ap+1, i+1); outlet_list(x->x_obj.ob_outlet, 0, 2, ap); @@ -233,12 +253,13 @@ static void index_dump(t_index *x) } /* compact all entries, removing all holes in the map */ -static void index_compact(t_index *x){ +static void index_compact(t_index *x) +{ int i,j; - for(i=0; ientries; i++){ - if(!x->names[i]){ - for(j=i+1; jmaxentries; j++){ - if(x->names[j]){ + for(i=0; ientries; i++) { + if(!x->names[i]) { + for(j=i+1; jmaxentries; j++) { + if(x->names[j]) { x->names[i]=x->names[j]; x->names[j]=0; break; @@ -248,14 +269,16 @@ static void index_compact(t_index *x){ } } /* sort the map alphabetically */ -static void index_sort(t_index *x){ +static void index_sort(t_index *x) +{ int entries=x->entries; int step=entries; int loops=1, n; t_symbol**buf=x->names; - index_compact(x); /* couldn't we do it more "in-place", e.g. don't touch empty slots ? */ + index_compact( + x); /* couldn't we do it more "in-place", e.g. don't touch empty slots ? */ - while(step>1){ + while(step>1) { int i = loops; step+=step%2; step>>=1; @@ -296,10 +319,14 @@ static void *index_new(t_symbol* UNUSED(s), int argc, t_atom *argv) if (argc--) { maxentries = (int)atom_getfloat(argv++); - if (argc) automod = (int)atom_getfloat(argv++); + if (argc) { + automod = (int)atom_getfloat(argv++); + } } - if (maxentries<1) maxentries=128; + if (maxentries<1) { + maxentries=128; + } buf = (t_symbol **)getbytes(sizeof(t_symbol *) * maxentries); @@ -310,7 +337,9 @@ static void *index_new(t_symbol* UNUSED(s), int argc, t_atom *argv) x->auto_mode = !(!automod); x->auto_resize = 1; - while (maxentries--) buf[maxentries]=0; + while (maxentries--) { + buf[maxentries]=0; + } outlet_new(&x->x_obj, gensym("float")); @@ -351,23 +380,28 @@ static void index_helper(t_index *x) void index_setup(void) { index_class = class_new(gensym("index"), - (t_newmethod)index_new, (t_method)index_free, - sizeof(t_index), 0, A_GIMME, 0); + (t_newmethod)index_new, (t_method)index_free, + sizeof(t_index), 0, A_GIMME, 0); class_addsymbol(index_class, index_symbol); class_addmethod(index_class, (t_method)index_reset, gensym("reset"), 0); - class_addmethod(index_class, (t_method)index_delete, gensym("delete"), A_GIMME, 0); + class_addmethod(index_class, (t_method)index_delete, gensym("delete"), + A_GIMME, 0); /* class_addmethod(index_class, (t_method)index_add, gensym("add"), A_SYMBOL, 0); */ - class_addmethod(index_class, (t_method)index_add, gensym("add"), A_SYMBOL, A_DEFFLOAT, 0); + class_addmethod(index_class, (t_method)index_add, gensym("add"), A_SYMBOL, + A_DEFFLOAT, 0); - class_addmethod(index_class, (t_method)index_auto, gensym("auto"), A_FLOAT, 0); - class_addmethod(index_class, (t_method)index_resize, gensym("resize"), A_FLOAT, 0); + class_addmethod(index_class, (t_method)index_auto, gensym("auto"), + A_FLOAT, 0); + class_addmethod(index_class, (t_method)index_resize, gensym("resize"), + A_FLOAT, 0); class_addfloat(index_class, (t_method)index_float); class_addbang(index_class, (t_method)index_bang); class_addmethod(index_class, (t_method)index_sort, gensym("sort"), 0); - class_addmethod(index_class, (t_method)index_compact, gensym("compact"), 0); + class_addmethod(index_class, (t_method)index_compact, gensym("compact"), + 0); class_addmethod(index_class, (t_method)index_dump, gensym("dump"), 0); class_addmethod(index_class, (t_method)index_helper, gensym("help"), 0); diff --git a/src/length.c b/src/length.c index 6863cff..3a745d5 100644 --- a/src/length.c +++ b/src/length.c @@ -1,4 +1,4 @@ -/* +/* * length :: get the length of a list (use [list length] instead) * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -20,16 +20,17 @@ #include "zexy.h" static t_class *length_class; -typedef struct _length -{ +typedef struct _length { t_object x_obj; } t_length; -static void length_list(t_length *x, t_symbol* UNUSED(s), int argc, t_atom* UNUSED(argv)) +static void length_list(t_length *x, t_symbol* UNUSED(s), int argc, + t_atom* UNUSED(argv)) { outlet_float(x->x_obj.ob_outlet, (t_float)argc); } -static void length_any(t_length *x, t_symbol* UNUSED(s), int argc, t_atom* UNUSED(argv)) +static void length_any(t_length *x, t_symbol* UNUSED(s), int argc, + t_atom* UNUSED(argv)) { outlet_float(x->x_obj.ob_outlet, (t_float)argc+1); } @@ -44,7 +45,7 @@ static void *length_new(void) void length_setup(void) { length_class = class_new(gensym("length"), (t_newmethod)length_new, 0, - sizeof(t_length), 0, A_DEFFLOAT, 0); + sizeof(t_length), 0, A_DEFFLOAT, 0); class_addlist(length_class, (t_method)length_list); class_addanything(length_class, (t_method)length_any); diff --git a/src/lifop.c b/src/lifop.c index 69e6c5b..2037c6e 100644 --- a/src/lifop.c +++ b/src/lifop.c @@ -1,4 +1,4 @@ -/* +/* * lifop: a LIFO (last-in first-out) with priorities * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -45,8 +45,7 @@ typedef struct _lifop_prioritylist { t_lifop_list *lifo_start; struct _lifop_prioritylist *next; } t_lifop_prioritylist; -typedef struct _lifop -{ +typedef struct _lifop { t_object x_obj; t_lifop_prioritylist *lifo_list; unsigned long counter; @@ -54,37 +53,41 @@ typedef struct _lifop t_outlet *x_out, *x_infout; } t_lifop; -static t_lifop_prioritylist*lifop_genprioritylist(t_lifop*x, t_float priority) +static t_lifop_prioritylist*lifop_genprioritylist(t_lifop*x, + t_float priority) { t_lifop_prioritylist*result=0, *dummy=0; - if(x->lifo_list!=0) - { - /* - * do we already have this priority ? - * if so, just return a pointer to that lifo - * else set the dummy-pointer to the lifo BEFORE the new one - */ - dummy=x->lifo_list; - while(dummy!=0){ - t_float prio=dummy->priority; - if(prio==priority)return dummy; - if(prio>priority)break; - result=dummy; - dummy=dummy->next; + if(x->lifo_list!=0) { + /* + * do we already have this priority ? + * if so, just return a pointer to that lifo + * else set the dummy-pointer to the lifo BEFORE the new one + */ + dummy=x->lifo_list; + while(dummy!=0) { + t_float prio=dummy->priority; + if(prio==priority) { + return dummy; + } + if(prio>priority) { + break; } - dummy=result; + result=dummy; + dummy=dummy->next; } + dummy=result; + } /* create a new priority list */ result = (t_lifop_prioritylist*)getbytes(sizeof( t_lifop_prioritylist)); result->priority=priority; result->lifo_start=0; /* insert it into the list of priority lists */ - if(dummy==0){ + if(dummy==0) { /* insert at the beginning */ result->next=x->lifo_list; - x->lifo_list=result; + x->lifo_list=result; } else { /* post insert into the list of LIFOs */ result->next=dummy->next; @@ -99,18 +102,17 @@ static int add2lifo(t_lifop_prioritylist*lifoprio, int argc, t_atom *argv) { t_lifop_list*entry=0; - if(lifoprio==0){ + if(lifoprio==0) { error("plifo: no lifos available"); return -1; } /* create an entry for the lifo */ - if(!(entry = (t_lifop_list*)getbytes(sizeof(t_lifop_list)))) - { - error("plifo: couldn't add entry to end of lifo"); - return -1; - } - if(!(entry->argv=(t_atom*)getbytes(argc*sizeof(t_atom)))){ + if(!(entry = (t_lifop_list*)getbytes(sizeof(t_lifop_list)))) { + error("plifo: couldn't add entry to end of lifo"); + return -1; + } + if(!(entry->argv=(t_atom*)getbytes(argc*sizeof(t_atom)))) { error("plifo: couldn't add list to lifo!"); return -1; } @@ -125,23 +127,27 @@ static int add2lifo(t_lifop_prioritylist*lifoprio, int argc, t_atom *argv) } static t_lifop_prioritylist*getLifo(t_lifop_prioritylist*plifo) { - if(plifo==0)return 0; + if(plifo==0) { + return 0; + } /* get the highest non-empty lifo */ - while(plifo->lifo_start==0 && plifo->next!=0)plifo=plifo->next; + while(plifo->lifo_start==0 && plifo->next!=0) { + plifo=plifo->next; + } return plifo; } -static void lifop_list(t_lifop *x, t_symbol* UNUSED(s), int argc, t_atom *argv) +static void lifop_list(t_lifop *x, t_symbol* UNUSED(s), int argc, + t_atom *argv) { t_lifop_prioritylist*plifo=0; if(!(plifo=lifop_genprioritylist(x, x->priority))) { error("[lifop]: couldn't get priority lifo"); return; } - if(!add2lifo(plifo, argc, argv)) - { - x->counter++; - } + if(!add2lifo(plifo, argc, argv)) { + x->counter++; + } } static void lifop_bang(t_lifop *x) @@ -151,11 +157,11 @@ static void lifop_bang(t_lifop *x) t_atom*argv=0; int argc=0; - if(!(plifo=getLifo(x->lifo_list))){ + if(!(plifo=getLifo(x->lifo_list))) { outlet_bang(x->x_infout); return; } - if(!(lifo=plifo->lifo_start)){ + if(!(lifo=plifo->lifo_start)) { outlet_bang(x->x_infout); return; } @@ -182,25 +188,27 @@ static void lifop_bang(t_lifop *x) freebytes(argv, argc*sizeof(t_atom)); } static void lifop_query(t_lifop*x) -{ +{ z_verbose(1, "%d elements in lifo", (int)x->counter); - + outlet_float(x->x_infout, (t_float)x->counter); } static void lifop_clear(t_lifop *x) { t_lifop_prioritylist *lifo_list=x->lifo_list; - while(lifo_list){ + while(lifo_list) { t_lifop_prioritylist *lifo_list2=lifo_list; t_lifop_list*lifo=lifo_list2->lifo_start; lifo_list=lifo_list->next; - while(lifo){ + while(lifo) { t_lifop_list*lifo2=lifo; lifo=lifo->next; - if(lifo2->argv)freebytes(lifo2->argv, lifo2->argc*sizeof(t_atom)); + if(lifo2->argv) { + freebytes(lifo2->argv, lifo2->argc*sizeof(t_atom)); + } lifo2->argv=0; lifo2->argc=0; lifo2->next=0; @@ -217,7 +225,7 @@ static void lifop_clear(t_lifop *x) /* this is NOT re-entrant! */ static void lifop_dump(t_lifop*x) -{ +{ t_lifop_prioritylist*plifo=getLifo(x->lifo_list); if(!plifo||!plifo->lifo_start) { @@ -269,16 +277,20 @@ static void lifop_help(t_lifop*x) void lifop_setup(void) { lifop_class = class_new(gensym("lifop"), (t_newmethod)lifop_new, - (t_method)lifop_free, sizeof(t_lifop), 0, A_NULL); + (t_method)lifop_free, sizeof(t_lifop), 0, A_NULL); class_addbang (lifop_class, lifop_bang); class_addlist (lifop_class, lifop_list); - class_addmethod (lifop_class, (t_method)lifop_clear, gensym("clear"), A_NULL); - class_addmethod (lifop_class, (t_method)lifop_dump, gensym("dump"), A_NULL); + class_addmethod (lifop_class, (t_method)lifop_clear, gensym("clear"), + A_NULL); + class_addmethod (lifop_class, (t_method)lifop_dump, gensym("dump"), + A_NULL); - class_addmethod (lifop_class, (t_method)lifop_query, gensym("info"), A_NULL); - class_addmethod (lifop_class, (t_method)lifop_help, gensym("help"), A_NULL); + class_addmethod (lifop_class, (t_method)lifop_query, gensym("info"), + A_NULL); + class_addmethod (lifop_class, (t_method)lifop_help, gensym("help"), + A_NULL); zexy_register("lifop"); } diff --git a/src/limiter~.c b/src/limiter~.c index 8c930f9..a3ff59f 100644 --- a/src/limiter~.c +++ b/src/limiter~.c @@ -1,4 +1,4 @@ -/* +/* * limiter~: limit/compress signals * * (c) 1999-2011 IOhannes m zmölnig, forum::fÃŒr::umlÀute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -21,16 +21,16 @@ /* --------------------------------- limiter/compressor --------------------------------- - + for details on how it works watch out for "http://iem.kug.ac.at/~zmoelnig/pd" ...and search for "limiter" mail2me4more!n4m8ion : zmoelnig@iem.kug.ac.at */ -/* - this is a limiter/compressor-object - the limiter is based on Falkner's thesis +/* + this is a limiter/compressor-object + the limiter is based on Falkner's thesis "Entwicklung eines digitalen Stereo-limiters mit Hilfe des Signalprozessors DSP56001" pp.14 2108:forum::fÃŒr::umlÀute:1999 all rights reserved and no warranties... @@ -75,7 +75,8 @@ static t_sample SINC[9]; #define PI 3.1415926535897932384626433832795029L /* pi */ -static void init_sinc(void) { +static void init_sinc(void) +{ /* calculate the sinc (windowed with a cosine) */ int i=0; for(i=0; i<9; i++) { @@ -90,32 +91,30 @@ static void init_sinc(void) { static t_class *limiter_class; -typedef struct _limctl -{ +typedef struct _limctl { /* variables changed by user */ t_float limit; t_float hold_samples; t_float change_of_amplification; } t_limctl; -typedef struct _cmpctl -{ - t_float treshold, ratio; /* uclimit is the very same is the limiter1-limit (decalculated relative to our treshold) */ - t_float uclimit, climit_inverse; /* climit == compressed limit (uclimit == uncompressed limit) */ +typedef struct _cmpctl { + t_float treshold, + ratio; /* uclimit is the very same is the limiter1-limit (decalculated relative to our treshold) */ + t_float uclimit, + climit_inverse; /* climit == compressed limit (uclimit == uncompressed limit) */ t_float limiter_limit; /* start limiting (stop compressing); == tresh/limit; */ t_float treshdB, oneminusratio; } t_cmpctl; -typedef struct _inbuf -{ +typedef struct _inbuf { t_sample* ringbuf; int buf_position; } t_inbuf; -typedef struct _limiter -{ +typedef struct _limiter { t_object x_obj; int number_of_inlets, s_n; @@ -146,10 +145,11 @@ typedef struct _limiter /* calcs */ static t_float calc_holdsamples(t_float htime, int buf) -{ +{ /* hold_time must be greater than buffer_time to make sure that any peak_sample is amplified with its own factor */ t_float min_hold = buf / sys_getsr(); - return (0.001 * sys_getsr() * ((htime > min_hold)?htime:((min_hold > 50)?min_hold:50))); + return (0.001 * sys_getsr() * ((htime > min_hold)?htime:(( + min_hold > 50)?min_hold:50))); } static t_float calc_coa(t_float hlife) @@ -160,7 +160,8 @@ static t_float calc_coa(t_float hlife) static void set_uclimit(t_limiter *x) { t_cmpctl *c = x->cmp; - t_float limit = x->val1->limit, limitdB = rmstodb(limit), ratio = c->ratio, tresh = c->treshold, treshdB = rmstodb(tresh); + t_float limit = x->val1->limit, limitdB = rmstodb(limit), ratio = c->ratio, + tresh = c->treshold, treshdB = rmstodb(tresh); c->climit_inverse = limit / tresh; c->uclimit = tresh / dbtorms(treshdB+(limitdB - treshdB)/ratio); @@ -175,7 +176,9 @@ static void set_treshold(t_limiter *x, t_float treshold) { t_cmpctl *c = x->cmp; t_float tresh = dbtorms (treshold); - if (tresh > x->val1->limit) tresh = x->val1->limit; + if (tresh > x->val1->limit) { + tresh = x->val1->limit; + } c->treshold = tresh; @@ -184,7 +187,9 @@ static void set_treshold(t_limiter *x, t_float treshold) static void set_ratio(t_limiter *x, t_float ratio) { - if (ratio < 0) ratio = 1; + if (ratio < 0) { + ratio = 1; + } x->cmp->ratio = ratio; set_uclimit(x); @@ -226,18 +231,24 @@ static void set_COMPRESS(t_limiter *x) } static void set_bufsize(t_limiter *x, int size) -{ +{ /* this is really unneeded...and for historical reasons only */ - if (size < BUFSIZE) size = BUFSIZE; + if (size < BUFSIZE) { + size = BUFSIZE; + } x->buf_size = size + XTRASAMPS; } static void set_limit(t_limiter *x, t_floatarg limit) { - if (limit < 0.00001) limit = 100; + if (limit < 0.00001) { + limit = 100; + } x->val1->limit = dbtorms(limit); - if (x->val1->limit < x->cmp->treshold) x->cmp->treshold = x->val1->limit; + if (x->val1->limit < x->cmp->treshold) { + x->cmp->treshold = x->val1->limit; + } set_uclimit(x); } @@ -245,25 +256,29 @@ static void set_limits(t_limiter *x, t_floatarg limit1, t_floatarg limit2) { t_float lim1, lim2; - if (limit1 < 0.00001) limit1 = 100; + if (limit1 < 0.00001) { + limit1 = 100; + } lim1 = dbtorms(limit1); lim2 = dbtorms(limit2); - if (lim2 < lim1) - { - lim2 = 2*lim1; /* this is to prevent lim2 (which should trigger the FAST regulation) */ - x->mode = 0; /* to underrun the SLOW regulation; this would cause distortion */ - } + if (lim2 < lim1) { + lim2 = 2*lim1; /* this is to prevent lim2 (which should trigger the FAST regulation) */ + x->mode = 0; /* to underrun the SLOW regulation; this would cause distortion */ + } x->val1->limit = lim1; x->val2->limit = lim1/lim2; - if (lim1 < x->cmp->treshold) x->cmp->treshold = lim1; + if (lim1 < x->cmp->treshold) { + x->cmp->treshold = lim1; + } set_uclimit(x); } -static void set1(t_limiter *x, t_floatarg limit, t_floatarg hold, t_floatarg release) +static void set1(t_limiter *x, t_floatarg limit, t_floatarg hold, + t_floatarg release) { t_float lim = dbtorms(limit); @@ -271,12 +286,15 @@ static void set1(t_limiter *x, t_floatarg limit, t_floatarg hold, t_floatarg rel x->val1->hold_samples = calc_holdsamples(hold, x->buf_size); x->val1->change_of_amplification = calc_coa(release); - if (lim < x->cmp->treshold) x->cmp->treshold = lim; + if (lim < x->cmp->treshold) { + x->cmp->treshold = lim; + } set_uclimit(x); } -static void set2(t_limiter *x, t_floatarg limit, t_floatarg hold, t_floatarg release) +static void set2(t_limiter *x, t_floatarg limit, t_floatarg hold, + t_floatarg release) { t_float lim = dbtorms(limit); x->val2->limit = (lim > x->val1->limit)?(x->val1->limit/lim):.5; @@ -286,16 +304,24 @@ static void set2(t_limiter *x, t_floatarg limit, t_floatarg hold, t_floatarg rel -static void set_compressor(t_limiter *x, t_floatarg limit, t_floatarg treshold, t_floatarg ratio) +static void set_compressor(t_limiter *x, t_floatarg limit, + t_floatarg treshold, t_floatarg ratio) { t_cmpctl *c = x->cmp; t_float lim = dbtorms(limit); t_float tresh = dbtorms(treshold); - if ((limit == 0) && (treshold == 0) && (ratio == 0)) {set_mode(x, COMPRESS); return;} + if ((limit == 0) && (treshold == 0) && (ratio == 0)) { + set_mode(x, COMPRESS); + return; + } - if (tresh > lim) tresh = lim; - if (ratio < 0.) ratio = 1.; + if (tresh > lim) { + tresh = lim; + } + if (ratio < 0.) { + ratio = 1.; + } c->ratio = ratio; x->val1->limit = lim; @@ -322,36 +348,41 @@ static void status(t_limiter *x) switch (x->mode) { case LIMIT1: post("%d-channel crack-limiter @ %fkHz\n" - "\noutput-limit\t= %fdB\nhold1\t\t= %fms\nrelease1\t= %fms\ncrack-limit\t= %fdB\nhold2\t\t= %fms\nrelease2\t= %fms\n" - "\namplify\t\t= %fdB\n", - x->number_of_inlets, sr, - rmstodb(v1->limit), (v1->hold_samples) / sr, LN2 / (log(v1->change_of_amplification) * sr), - rmstodb(v1->limit / v2->limit), (v2->hold_samples) / sr, LN2 / (log(v2->change_of_amplification) * sr), - x->amplification); + "\noutput-limit\t= %fdB\nhold1\t\t= %fms\nrelease1\t= %fms\ncrack-limit\t= %fdB\nhold2\t\t= %fms\nrelease2\t= %fms\n" + "\namplify\t\t= %fdB\n", + x->number_of_inlets, sr, + rmstodb(v1->limit), (v1->hold_samples) / sr, + LN2 / (log(v1->change_of_amplification) * sr), + rmstodb(v1->limit / v2->limit), (v2->hold_samples) / sr, + LN2 / (log(v2->change_of_amplification) * sr), + x->amplification); break; case LIMIT0: post("%d-channel limiter @ %fkHz\n" - "\noutput-limit\t= %fdB\nhold\t\t= %fms\nrelease\t\t= %fms\n" - "\namplify\t\t= %fdB\n", - x->number_of_inlets, sr, - rmstodb(v1->limit), (v1->hold_samples) / sr, LN2 / (log(v1->change_of_amplification) * sr), - rmstodb(x->amplification)); + "\noutput-limit\t= %fdB\nhold\t\t= %fms\nrelease\t\t= %fms\n" + "\namplify\t\t= %fdB\n", + x->number_of_inlets, sr, + rmstodb(v1->limit), (v1->hold_samples) / sr, + LN2 / (log(v1->change_of_amplification) * sr), + rmstodb(x->amplification)); break; case COMPRESS: post("%d-channel compressor @ %fkHz\n" - "\noutput-limit\t= %fdB\ntreshold\t= %fdB\ninput-limit\t= %f\nratio\t\t= 1:%f\n" - "\nhold\t\t= %fms\nrelease\t\t= %fms\n" - "\namplify\t\t= %fdB\n", - x->number_of_inlets, sr, - rmstodb(c->treshold * c->climit_inverse), rmstodb(c->treshold), rmstodb(c->treshold / c->uclimit), 1./c->ratio, - (v1->hold_samples) / sr, LN2 / (log(v1->change_of_amplification) * sr), - rmstodb(x->amplification)); + "\noutput-limit\t= %fdB\ntreshold\t= %fdB\ninput-limit\t= %f\nratio\t\t= 1:%f\n" + "\nhold\t\t= %fms\nrelease\t\t= %fms\n" + "\namplify\t\t= %fdB\n", + x->number_of_inlets, sr, + rmstodb(c->treshold * c->climit_inverse), rmstodb(c->treshold), + rmstodb(c->treshold / c->uclimit), 1./c->ratio, + (v1->hold_samples) / sr, LN2 / (log(v1->change_of_amplification) * sr), + rmstodb(x->amplification)); } } static void limiter_tilde_helper(t_limiter *x) { - post("\n\n"HEARTSYMBOL" %d-channel limiter-object: mode %d", x->number_of_inlets, x->mode); + post("\n\n"HEARTSYMBOL" %d-channel limiter-object: mode %d", + x->number_of_inlets, x->mode); poststring("\n'mode '\t\t\t: (0_limiter, 1_crack-limiter, 2_compressor)"); poststring("\n'LIMIT'\t\t\t\t: set to LIMITer"); poststring("\n'CRACK'\t\t\t\t: set to CRACK-limiter"); @@ -360,26 +391,26 @@ static void limiter_tilde_helper(t_limiter *x) switch (x->mode) { case LIMIT0: poststring("\n'limit '\t\t\t: set limit (in dB)" - "\n'set '\t: set limiter"); + "\n'set '\t: set limiter"); break; case LIMIT1: poststring("\n'limits '\t: set limits (in dB)" - "\n'set '\t: set limiter 1" - "\n'set2 '\t: set crack-limiter"); + "\n'set '\t: set limiter 1" + "\n'set2 '\t: set crack-limiter"); break; case COMPRESS: poststring("\n'ratio '\t\t: set compressratio (Åœ0.5Åœ instead of Åœ1:2Åœ)" - "\n'treshold '\t\t: set treshold of the compressor" - "\n'compress '\t: set compressor" - "\n..........note that is the same for COMPRESSOR and LIMITER.........."); + "\n'treshold '\t\t: set treshold of the compressor" + "\n'compress '\t: set compressor" + "\n..........note that is the same for COMPRESSOR and LIMITER.........."); break; default: break; } - poststring("\n'print'\t\t\t\t: view actual settings" - "\n'help'\t\t\t\t: view this\n"); + poststring("\n'print'\t\t\t\t: view actual settings" + "\n'help'\t\t\t\t: view this\n"); poststring("\ncreating arguments are :\n" - "\"limiter~ [ [ [ [...]]]]\": may be anything\n"); + "\"limiter~ [ [ [ [...]]]]\": may be anything\n"); endpost(); } @@ -404,88 +435,87 @@ static t_int *oversampling_maxima(t_int *w) i += n; - while (n--) - { - t_sample os1, os2, max; - t_sample last4, last3, last2, last1, sinccurrent, current, next1, next2, next3, next4; - - if (bp == ep) - { - vp[0] = bp[-9]; - vp[1] = bp[-8]; - vp[2] = bp[-7]; - vp[3] = bp[-6]; - vp[4] = bp[-5]; - vp[5] = bp[-4]; - vp[6] = bp[-3]; - vp[7] = bp[-2]; - vp[8] = bp[-1]; - - bp = vp + XTRASAMPS; - i -= bufsize - XTRASAMPS; - } + while (n--) { + t_sample os1, os2, max; + t_sample last4, last3, last2, last1, sinccurrent, current, next1, next2, + next3, next4; + + if (bp == ep) { + vp[0] = bp[-9]; + vp[1] = bp[-8]; + vp[2] = bp[-7]; + vp[3] = bp[-6]; + vp[4] = bp[-5]; + vp[5] = bp[-4]; + vp[6] = bp[-3]; + vp[7] = bp[-2]; + vp[8] = bp[-1]; + + bp = vp + XTRASAMPS; + i -= bufsize - XTRASAMPS; + } - last4 = bp[-8]; - last3 = bp[-7]; - last2 = bp[-6]; - last1 = bp[-5]; - current = bp[-4]; - next1 = bp[-3]; - next2 = bp[-2]; - next3 = bp[-1]; - next4 = bp[0]; - - sinccurrent = SINC[4] * current; - - os1= fabsf(SINC[0] * last4 + - SINC[1] * last3 + - SINC[2] * last2 + - SINC[3] * last1 + - sinccurrent + - SINC[5] * next1 + - SINC[6] * next2 + - SINC[7] * next3 + - SINC[8] * next4); - - os2= fabsf(SINC[0] * next4 + - SINC[1] * next3 + - SINC[2] * next2 + - SINC[3] * next1 + - sinccurrent + - SINC[5] * last1 + - SINC[6] * last2 + - SINC[7] * last3 + - SINC[8] * last4); - - max = fabsf(current); + last4 = bp[-8]; + last3 = bp[-7]; + last2 = bp[-6]; + last1 = bp[-5]; + current = bp[-4]; + next1 = bp[-3]; + next2 = bp[-2]; + next3 = bp[-1]; + next4 = bp[0]; + + sinccurrent = SINC[4] * current; + + os1= fabsf(SINC[0] * last4 + + SINC[1] * last3 + + SINC[2] * last2 + + SINC[3] * last1 + + sinccurrent + + SINC[5] * next1 + + SINC[6] * next2 + + SINC[7] * next3 + + SINC[8] * next4); + + os2= fabsf(SINC[0] * next4 + + SINC[1] * next3 + + SINC[2] * next2 + + SINC[3] * next1 + + sinccurrent + + SINC[5] * last1 + + SINC[6] * last2 + + SINC[7] * last3 + + SINC[8] * last4); + + max = fabsf(current); #if 0 - if(max>1. || os1>1. || os2>1.) - post("%f %f %f\t%f %f %f %f %f %f %f %f %f", max, os1, os2, - last4, - last3, - last2, - last1, - current, - next1, - next2, - next3, - next4 - ); + if(max>1. || os1>1. || os2>1.) + post("%f %f %f\t%f %f %f %f %f %f %f %f %f", max, os1, os2, + last4, + last3, + last2, + last1, + current, + next1, + next2, + next3, + next4 + ); #endif - if (max < os1) - { - max = os1; - } - if (max < os2) - { - max = os2; - } - - *bp++ = *in++; - if (*out++ < max) *(out-1) = max; + if (max < os1) { + max = os1; + } + if (max < os2) { + max = os2; } + + *bp++ = *in++; + if (*out++ < max) { + *(out-1) = max; + } + } buf->buf_position = i; return (w+5); @@ -528,97 +558,97 @@ static t_int *limiter_perform(t_int *w) /* an intern variable... */ t_float max_val; - + switch (x->mode) { case LIMIT0: - while (n--) - { - max_val = *in; - - /* the MAIN routine for the 1-treshold-limiter */ - - if ((max_val * amp) > limit) - { - amp = limit / max_val; - samplesleft = holdlong; - } else - { - if (samplesleft > 0) - { - samplesleft--; - } else - { - if ((amp *= coa_long) > 1) amp = 1; - } + while (n--) { + max_val = *in; + + /* the MAIN routine for the 1-treshold-limiter */ + + if ((max_val * amp) > limit) { + amp = limit / max_val; + samplesleft = holdlong; + } else { + if (samplesleft > 0) { + samplesleft--; + } else { + if ((amp *= coa_long) > 1) { + amp = 1; } - - *out++ = amp; - *in++ = 0; + } } + + *out++ = amp; + *in++ = 0; + } break; case LIMIT1: - while (n--) - { - max_val = *in; - /* the main routine 2 */ - - if ((max_val * amp) > limit) - { - samplesleft = ((amp = (limit / max_val)) < alimit)?holdshort:holdlong; - stillleft = holdlong; - } else - { - if (samplesleft > 0) - { - samplesleft--; - stillleft--; - } else - { - if (amp < alimit) - { - if ((amp *= coa_short) > 1) amp = 1; - } else - { - if (stillleft > 0) - { - samplesleft = stillleft; - } else - { - if ((amp *= coa_long) > 1) amp = 1; - } - } + while (n--) { + max_val = *in; + /* the main routine 2 */ + + if ((max_val * amp) > limit) { + samplesleft = ((amp = (limit / max_val)) < alimit)?holdshort:holdlong; + stillleft = holdlong; + } else { + if (samplesleft > 0) { + samplesleft--; + stillleft--; + } else { + if (amp < alimit) { + if ((amp *= coa_short) > 1) { + amp = 1; + } + } else { + if (stillleft > 0) { + samplesleft = stillleft; + } else { + if ((amp *= coa_long) > 1) { + amp = 1; } + } } - *out++ = amp; - *in++ = 0; + } } + *out++ = amp; + *in++ = 0; + } x->still_left = stillleft; break; case COMPRESS: - while (n--) - { - max_val = *in; - - /* the MAIN routine for the compressor (very similar to the 1-treshold-limiter) */ - - if (max_val * amp > tresh) { - amp = tresh / max_val; - samplesleft = holdlong; - } else - if (samplesleft > 0) samplesleft--; - else if ((amp *= coa_long) > 1) amp = 1; - - if (amp < 1.) - if (amp > uclimit) /* amp is still UnCompressed uclimit==limitIN/tresh; */ - *out++ = pow(amp, oneminusratio); - else *out++ = amp * climit_inv; /* amp must fit for limiting : amp(new) = limit/maxval; = amp(old)*limitOUT/tresh; */ - else *out++ = 1.; - - *in++ = 0.; + while (n--) { + max_val = *in; + + /* the MAIN routine for the compressor (very similar to the 1-treshold-limiter) */ + + if (max_val * amp > tresh) { + amp = tresh / max_val; + samplesleft = holdlong; + } else if (samplesleft > 0) { + samplesleft--; + } else if ((amp *= coa_long) > 1) { + amp = 1; } + + if (amp < 1.) + if (amp > uclimit) { /* amp is still UnCompressed uclimit==limitIN/tresh; */ + *out++ = pow(amp, oneminusratio); + } else { + *out++ = amp * + climit_inv; /* amp must fit for limiting : amp(new) = limit/maxval; = amp(old)*limitOUT/tresh; */ + } + else { + *out++ = 1.; + } + + *in++ = 0.; + } break; default: - while (n--) *out++ = *in++ = 0.; + while (n--) { + *out++ = *in++ = 0.; + } break; } @@ -637,15 +667,18 @@ static void limiter_dsp(t_limiter *x, t_signal **sp) x->s_n = sp[0]->s_n; - if (x->amplification == 0) x->amplification = 0.0000001; + if (x->amplification == 0) { + x->amplification = 0.0000001; + } - if (x->val2->limit >= 1) x->mode = 0; + if (x->val2->limit >= 1) { + x->mode = 0; + } - while (i < x->number_of_inlets) - { - dsp_add(oversampling_maxima, 4, x, &(x->in[i]), sp[i]->s_vec, sig_buf); - i++; - } + while (i < x->number_of_inlets) { + dsp_add(oversampling_maxima, 4, x, &(x->in[i]), sp[i]->s_vec, sig_buf); + i++; + } dsp_add(limiter_perform, 3, x, sig_buf, sp[i]->s_vec); } @@ -660,35 +693,39 @@ static void *limiter_new(t_symbol *s, int argc, t_atom *argv) t_limiter *x = (t_limiter *)pd_new(limiter_class); int i = 0; - if (argc) set_bufsize(x, atom_getfloat(argv)); - else - { - argc = 1; - set_bufsize(x, 0); - } + if (argc) { + set_bufsize(x, atom_getfloat(argv)); + } else { + argc = 1; + set_bufsize(x, 0); + } - if (argc > 64) argc=64; - if (argc == 0) argc=1; + if (argc > 64) { + argc=64; + } + if (argc == 0) { + argc=1; + } x->number_of_inlets = argc--; - while (argc--) - { - inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("signal"), gensym("signal")); - } + while (argc--) { + inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("signal"), gensym("signal")); + } outlet_new(&x->x_obj, gensym("signal")); x->in = (t_inbuf*)getbytes(sizeof(t_inbuf) * x->number_of_inlets); - while (i < x->number_of_inlets) - { - int n; - t_sample* buf = (t_sample *)getbytes(sizeof(*buf) * x->buf_size); - x->in[i].ringbuf = buf; - x->in[i].buf_position = 0; - for (n = 0; n < x->buf_size; n++) x->in[i].ringbuf[n] = 0.; - i++; + while (i < x->number_of_inlets) { + int n; + t_sample* buf = (t_sample *)getbytes(sizeof(*buf) * x->buf_size); + x->in[i].ringbuf = buf; + x->in[i].buf_position = 0; + for (n = 0; n < x->buf_size; n++) { + x->in[i].ringbuf[n] = 0.; } + i++; + } x->val1 = (t_limctl *)getbytes(sizeof(t_limctl)); x->val2 = (t_limctl *)getbytes(sizeof(t_limctl)); @@ -714,7 +751,9 @@ static void limiter_free(t_limiter *x) freebytes(x->val2, sizeof(t_limctl)); freebytes(x->cmp , sizeof(t_cmpctl)); - while (i < x->number_of_inlets) freebytes(x->in[i++].ringbuf, x->buf_size * sizeof(t_sample)); + while (i < x->number_of_inlets) { + freebytes(x->in[i++].ringbuf, x->buf_size * sizeof(t_sample)); + } freebytes(x->in, x->number_of_inlets * sizeof(t_inbuf)); } @@ -730,30 +769,42 @@ void limiter_tilde_setup(void) { init_sinc(); - limiter_class = class_new(gensym("limiter~"), (t_newmethod)limiter_new, (t_method)limiter_free, - sizeof(t_limiter), 0, A_GIMME, 0); + limiter_class = class_new(gensym("limiter~"), (t_newmethod)limiter_new, + (t_method)limiter_free, + sizeof(t_limiter), 0, A_GIMME, 0); class_addmethod(limiter_class, nullfn, gensym("signal"), 0); class_addmethod(limiter_class, (t_method)limiter_dsp, gensym("dsp"), 0); - class_addmethod(limiter_class, (t_method)limiter_tilde_helper, gensym("help"), 0); + class_addmethod(limiter_class, (t_method)limiter_tilde_helper, + gensym("help"), 0); class_addmethod(limiter_class, (t_method)status, gensym("print"), 0); - class_addmethod(limiter_class, (t_method)set_mode, gensym("mode"), A_FLOAT, 0); + class_addmethod(limiter_class, (t_method)set_mode, gensym("mode"), A_FLOAT, + 0); class_addmethod(limiter_class, (t_method)set_LIMIT, gensym("LIMIT"), 0); class_addmethod(limiter_class, (t_method)set_CRACK, gensym("CRACK"), 0); - class_addmethod(limiter_class, (t_method)set_COMPRESS, gensym("COMPRESS"), 0); - - - class_addmethod(limiter_class, (t_method)set_treshold, gensym("tresh"), A_FLOAT, 0); - class_addmethod(limiter_class, (t_method)set_treshold, gensym("treshold"), A_FLOAT, 0); - class_addmethod(limiter_class, (t_method)set_ratio, gensym("ratio"), A_FLOAT, 0); - class_addmethod(limiter_class, (t_method)set1, gensym("set"), A_FLOAT, A_FLOAT, A_FLOAT, 0); - class_addmethod(limiter_class, (t_method)set2, gensym("set2"), A_FLOAT, A_FLOAT, A_FLOAT, 0); - class_addmethod(limiter_class, (t_method)set_compressor,gensym("compress"), A_FLOAT, A_FLOAT, A_FLOAT, 0); - - class_addmethod(limiter_class, (t_method)set_limits, gensym("limits"), A_FLOAT, A_FLOAT, 0); - class_addmethod(limiter_class, (t_method)set_limit, gensym("limit"), A_FLOAT, 0); + class_addmethod(limiter_class, (t_method)set_COMPRESS, gensym("COMPRESS"), + 0); + + + class_addmethod(limiter_class, (t_method)set_treshold, gensym("tresh"), + A_FLOAT, 0); + class_addmethod(limiter_class, (t_method)set_treshold, gensym("treshold"), + A_FLOAT, 0); + class_addmethod(limiter_class, (t_method)set_ratio, gensym("ratio"), + A_FLOAT, 0); + class_addmethod(limiter_class, (t_method)set1, gensym("set"), A_FLOAT, + A_FLOAT, A_FLOAT, 0); + class_addmethod(limiter_class, (t_method)set2, gensym("set2"), A_FLOAT, + A_FLOAT, A_FLOAT, 0); + class_addmethod(limiter_class, (t_method)set_compressor,gensym("compress"), + A_FLOAT, A_FLOAT, A_FLOAT, 0); + + class_addmethod(limiter_class, (t_method)set_limits, gensym("limits"), + A_FLOAT, A_FLOAT, 0); + class_addmethod(limiter_class, (t_method)set_limit, gensym("limit"), + A_FLOAT, 0); class_addfloat (limiter_class, set_limit); class_addmethod(limiter_class, (t_method)reset, gensym("reset"), 0); diff --git a/src/list2int.c b/src/list2int.c index 7f91db2..82e2df7 100644 --- a/src/list2int.c +++ b/src/list2int.c @@ -1,4 +1,4 @@ -/* +/* * list2int: cast each float of a list (or anything) to integer * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -22,29 +22,42 @@ static t_class *list2int_class; -static void list2int_any(t_mypdlist *x, t_symbol *s, int argc, t_atom *argv) +static void list2int_any(t_mypdlist *x, t_symbol *s, int argc, + t_atom *argv) { t_atom *ap; if (x->x_n != argc) { freebytes(x->x_list, x->x_n * sizeof(t_atom)); x->x_n = argc; x->x_list = copybytes(argv, argc * sizeof(t_atom)); - } else memcpy(x->x_list, argv, argc * sizeof(t_atom)); + } else { + memcpy(x->x_list, argv, argc * sizeof(t_atom)); + } ap = x->x_list; - while(argc--){ - if(ap->a_type == A_FLOAT)ap->a_w.w_float=(int)ap->a_w.w_float; + while(argc--) { + if(ap->a_type == A_FLOAT) { + ap->a_w.w_float=(int)ap->a_w.w_float; + } ap++; } outlet_anything(x->x_obj.ob_outlet, s, x->x_n, x->x_list); } static void list2int_bang(t_mypdlist *x) -{ outlet_bang(x->x_obj.ob_outlet);} +{ + outlet_bang(x->x_obj.ob_outlet); +} static void list2int_float(t_mypdlist *x, t_float f) -{ outlet_float(x->x_obj.ob_outlet, (int)f);} +{ + outlet_float(x->x_obj.ob_outlet, (int)f); +} static void list2int_symbol(t_mypdlist *x, t_symbol *s) -{ outlet_symbol(x->x_obj.ob_outlet, s);} +{ + outlet_symbol(x->x_obj.ob_outlet, s); +} static void list2int_pointer(t_mypdlist *x, t_gpointer *p) -{ outlet_pointer(x->x_obj.ob_outlet, p);} +{ + outlet_pointer(x->x_obj.ob_outlet, p); +} static void *list2int_new(t_symbol *s, int argc, t_atom *argv) { @@ -60,13 +73,13 @@ static void *list2int_new(t_symbol *s, int argc, t_atom *argv) static void mypdlist_free(t_mypdlist *x) { - freebytes(x->x_list, x->x_n * sizeof(t_atom)); + freebytes(x->x_list, x->x_n * sizeof(t_atom)); } void list2int_setup(void) { - list2int_class = class_new(gensym("list2int"), (t_newmethod)list2int_new, - (t_method)mypdlist_free, sizeof(t_mypdlist), 0, A_GIMME, 0); + list2int_class = class_new(gensym("list2int"), (t_newmethod)list2int_new, + (t_method)mypdlist_free, sizeof(t_mypdlist), 0, A_GIMME, 0); class_addcreator((t_newmethod)list2int_new, gensym("l2i"), A_GIMME, 0); class_addanything(list2int_class, list2int_any); class_addlist(list2int_class, list2int_any); diff --git a/src/list2lists.c b/src/list2lists.c index 14d553e..8467d57 100644 --- a/src/list2lists.c +++ b/src/list2lists.c @@ -1,4 +1,4 @@ -/* +/* * list2lists: split a list into several sublists given by their lenghts * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -31,8 +31,7 @@ static t_class *list2lists_class; -typedef struct _list2lists -{ +typedef struct _list2lists { t_object x_obj; t_outlet *x_outlet; @@ -45,7 +44,8 @@ typedef struct _list2lists -static void list2lists_list2(t_list2lists*x,t_symbol*s, int argc, t_atom*argv) +static void list2lists_list2(t_list2lists*x,t_symbol*s, int argc, + t_atom*argv) { if(x->x_length!=0) { freebytes(x->x_length, sizeof(t_atom)*x->x_lcount); @@ -62,8 +62,8 @@ static void list2lists_list2(t_list2lists*x,t_symbol*s, int argc, t_atom*argv) for(i=0; ix_length[i]=index; } @@ -72,19 +72,21 @@ static void list2lists_list2(t_list2lists*x,t_symbol*s, int argc, t_atom*argv) DEBUGFUN(post("list2: %d %x", x->x_lcount, x->x_length)); } -static void list2lists_output(t_list2lists*x, int argc, t_atom*argv) +static void list2lists_output(t_list2lists*x, int argc, t_atom*argv) { t_outlet*out=x->x_obj.ob_outlet; - if(argc<=0) + if(argc<=0) { outlet_bang(out); - else + } else { outlet_list(out, gensym("list"), argc, argv); + } } -static void list2lists_list(t_list2lists *x, t_symbol *s, int argc, t_atom *argv) +static void list2lists_list(t_list2lists *x, t_symbol *s, int argc, + t_atom *argv) { int i; - + if(x->x_lcount<1) { outlet_anything(x->x_obj.ob_outlet, s, argc, argv); return; @@ -103,7 +105,7 @@ static void list2lists_list(t_list2lists *x, t_symbol *s, int argc, t_atom *argv } static void list2lists_free(t_list2lists *x) -{ +{ if(x->x_length) { freebytes(x->x_length, x->x_lcount*sizeof(int)); x->x_length=0; @@ -118,7 +120,8 @@ static void *list2lists_new(t_symbol* UNUSED(s), int argc, t_atom *argv) t_list2lists *x = (t_list2lists *)pd_new(list2lists_class); outlet_new(&x->x_obj, 0); - x->x_lengin=inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("list"), gensym("lst2")); + x->x_lengin=inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("list"), + gensym("lst2")); x->x_lcount=0; x->x_length=0; @@ -136,11 +139,14 @@ static void list2lists_help(t_list2lists*x) void list2lists_setup(void) { - list2lists_class = class_new(gensym("list2lists"), (t_newmethod)list2lists_new, - (t_method)list2lists_free, sizeof(t_list2lists), 0, A_GIMME, 0); + list2lists_class = class_new(gensym("list2lists"), + (t_newmethod)list2lists_new, + (t_method)list2lists_free, sizeof(t_list2lists), 0, A_GIMME, 0); class_addlist (list2lists_class, list2lists_list); - class_addmethod (list2lists_class, (t_method)list2lists_list2, gensym("lst2"), A_GIMME, 0); + class_addmethod (list2lists_class, (t_method)list2lists_list2, + gensym("lst2"), A_GIMME, 0); - class_addmethod(list2lists_class, (t_method)list2lists_help, gensym("help"), A_NULL); + class_addmethod(list2lists_class, (t_method)list2lists_help, + gensym("help"), A_NULL); zexy_register("list2lists"); } diff --git a/src/list2symbol.c b/src/list2symbol.c index df6c7a5..03d0ac2 100644 --- a/src/list2symbol.c +++ b/src/list2symbol.c @@ -1,4 +1,4 @@ -/* +/* * list2symbol: convert a list into a single symbol * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -25,8 +25,7 @@ static t_class *list2symbol_class; -typedef struct _list2symbol -{ +typedef struct _list2symbol { t_object x_obj; int ac; t_atom *ap; @@ -35,7 +34,8 @@ typedef struct _list2symbol t_outlet*x_outlet; } t_list2symbol; -static void list2symbol_connector(t_list2symbol *x, t_symbol *s){ +static void list2symbol_connector(t_list2symbol *x, t_symbol *s) +{ x->connector = s; } @@ -49,20 +49,23 @@ static void list2symbol_bang(t_list2symbol *x) char *connector=0; char connlen=0; char*buffer = (char*)getbytes(MAXPDSTRING*sizeof(char)); - if(x->connector){ + if(x->connector) { connector=x->connector->s_name; connlen=strlen(connector); } - + /* 1st get the length of the symbol */ - if(x->s)length+=strlen(x->s->s_name); - else length-=connlen; + if(x->s) { + length+=strlen(x->s->s_name); + } else { + length-=connlen; + } length+=i*connlen; - while(i--){ + while(i--) { int len2=0; - if(A_SYMBOL==argv->a_type){ + if(A_SYMBOL==argv->a_type) { len2=strlen(argv->a_w.w_symbol->s_name); } else { atom_string(argv, buffer, MAXPDSTRING); @@ -72,7 +75,7 @@ static void list2symbol_bang(t_list2symbol *x) argv++; } - if (length<=0){ + if (length<=0) { outlet_symbol(x->x_obj.ob_outlet, gensym("")); return; } @@ -80,20 +83,20 @@ static void list2symbol_bang(t_list2symbol *x) result = (char*)getbytes((length+1)*sizeof(char)); /* 2nd create the symbol */ - if (x->s){ + if (x->s) { char *buf = x->s->s_name; int buflen=strlen(buf); strncpy(result+len, buf, length-len); len+=buflen; - if(i && connector){ + if(i && connector) { strncpy(result+len, connector, length-len); len += connlen; } } i=argc; argv=x->ap; - while(i--){ - if(A_SYMBOL==argv->a_type){ + while(i--) { + if(A_SYMBOL==argv->a_type) { strncpy(result+len, argv->a_w.w_symbol->s_name, length-len); len+= strlen(argv->a_w.w_symbol->s_name); } else { @@ -102,7 +105,7 @@ static void list2symbol_bang(t_list2symbol *x) len += strlen(buffer); } argv++; - if(i && connector){ + if(i && connector) { strncpy(result+len, connector, length-len); len += connlen; } @@ -114,9 +117,10 @@ static void list2symbol_bang(t_list2symbol *x) freebytes(result, (length+1)*sizeof(char)); } -static void list2symbol_anything(t_list2symbol *x, t_symbol *s, int argc, t_atom *argv) +static void list2symbol_anything(t_list2symbol *x, t_symbol *s, int argc, + t_atom *argv) { - if(x->ap){ + if(x->ap) { freebytes(x->ap, x->ac*sizeof(t_atom)); x->ap=0; } @@ -124,19 +128,20 @@ static void list2symbol_anything(t_list2symbol *x, t_symbol *s, int argc, t_atom x->s =s; x->ac=argc; - if(x->ac){ + if(x->ac) { x->ap=(t_atom*)getbytes(x->ac*sizeof(t_atom)); } - if(x->ap){ + if(x->ap) { t_atom*ap=x->ap; - while(argc--){ + while(argc--) { *ap++=*argv++; } } list2symbol_bang(x); } -static void list2symbol_list(t_list2symbol *x, t_symbol *s, int argc, t_atom *argv) +static void list2symbol_list(t_list2symbol *x, t_symbol *s, int argc, + t_atom *argv) { list2symbol_anything(x, 0, argc, argv); } @@ -145,7 +150,8 @@ static void *list2symbol_new(t_symbol *s, int argc, t_atom *argv) t_list2symbol *x = (t_list2symbol *)pd_new(list2symbol_class); x->x_outlet=outlet_new(&x->x_obj, 0); - x->x_inlet2=inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("symbol"), gensym("")); + x->x_inlet2=inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("symbol"), + gensym("")); #if 0 /* old behaviour: the argument list is used as the list-to-be-converted */ @@ -155,14 +161,14 @@ static void *list2symbol_new(t_symbol *s, int argc, t_atom *argv) /* new behaviour: set the delimiter with the argument */ list2symbol_connector(x, (argc)?atom_getsymbol(argv):gensym(" ")); #endif - + return (x); } static void list2symbol_free(t_list2symbol *x) { - if(x->ap){ + if(x->ap) { freebytes(x->ap, x->ac*sizeof(t_atom)); x->ap=0; } @@ -173,7 +179,8 @@ static void list2symbol_free(t_list2symbol *x) void list2symbol_setup(void) { - list2symbol_class = class_new(gensym("list2symbol"), (t_newmethod)list2symbol_new, + list2symbol_class = class_new(gensym("list2symbol"), + (t_newmethod)list2symbol_new, (t_method)list2symbol_free, sizeof(t_list2symbol), 0, A_GIMME, 0); @@ -181,7 +188,8 @@ void list2symbol_setup(void) class_addbang (list2symbol_class, list2symbol_bang); class_addlist (list2symbol_class, list2symbol_list); class_addanything(list2symbol_class, list2symbol_anything); - class_addmethod (list2symbol_class, (t_method)list2symbol_connector, gensym(""), A_SYMBOL, 0); + class_addmethod (list2symbol_class, (t_method)list2symbol_connector, + gensym(""), A_SYMBOL, 0); zexy_register("list2symbol"); } diff --git a/src/lister.c b/src/lister.c index 14096ab..72d9c46 100644 --- a/src/lister.c +++ b/src/lister.c @@ -1,4 +1,4 @@ -/* +/* * lister: this is for lists, what "float" is for floats (use [list] instead) * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -41,26 +41,30 @@ static t_class *mypdlist_class; static void atoms_copy(int argc, t_atom *from, t_atom *to) { int i; - for (i = 0; i < argc; i++) + for (i = 0; i < argc; i++) { to[i] = from[i]; + } } static void mypdlist_storelist(t_mypdlist *x, int argc, t_atom *argv) { - if(x->x_list)freebytes(x->x_list, x->x_n*sizeof(t_atom)); + if(x->x_list) { + freebytes(x->x_list, x->x_n*sizeof(t_atom)); + } x->x_n=argc; x->x_list=(t_atom*)getbytes(x->x_n*sizeof(t_atom)); atoms_copy(argc, argv, x->x_list); } -static void mypdlist_secondlist(t_mypdlist *x, t_symbol *s, int argc, t_atom *argv) +static void mypdlist_secondlist(t_mypdlist *x, t_symbol *s, int argc, + t_atom *argv) { mypdlist_storelist(x, argc, argv); } static void mypdlist_bang(t_mypdlist *x) -{ +{ int outc=x->x_n; t_atom*outv; ATOMS_ALLOCA(outv, outc); @@ -70,7 +74,8 @@ static void mypdlist_bang(t_mypdlist *x) } -static void mypdlist_list(t_mypdlist *x, t_symbol *s, int argc, t_atom *argv) +static void mypdlist_list(t_mypdlist *x, t_symbol *s, int argc, + t_atom *argv) { mypdlist_secondlist(x, s, argc, argv); mypdlist_bang(x); @@ -78,7 +83,9 @@ static void mypdlist_list(t_mypdlist *x, t_symbol *s, int argc, t_atom *argv) static void mypdlist_free(t_mypdlist *x) -{ freebytes(x->x_list, x->x_n * sizeof(t_atom)); } +{ + freebytes(x->x_list, x->x_n * sizeof(t_atom)); +} static void *mypdlist_new(t_symbol *s, int argc, t_atom *argv) { @@ -90,8 +97,9 @@ static void *mypdlist_new(t_symbol *s, int argc, t_atom *argv) x->x_n = 0; x->x_list = 0; - if(argc) + if(argc) { mypdlist_secondlist(x, gensym("list"), argc, argv); + } return (x); } @@ -104,7 +112,7 @@ static void mypdlist_help(t_mypdlist*x) void lister_setup(void) { - mypdlist_class = class_new(gensym("lister"), (t_newmethod)mypdlist_new, + mypdlist_class = class_new(gensym("lister"), (t_newmethod)mypdlist_new, (t_method)mypdlist_free, sizeof(t_mypdlist), 0, A_GIMME, 0); /* i don't know how to get this work with name=="list" !!! */ @@ -112,9 +120,11 @@ void lister_setup(void) class_addbang (mypdlist_class, mypdlist_bang); class_addlist (mypdlist_class, mypdlist_list); - class_addmethod (mypdlist_class, (t_method)mypdlist_secondlist, gensym("lst2"), A_GIMME, 0); + class_addmethod (mypdlist_class, (t_method)mypdlist_secondlist, + gensym("lst2"), A_GIMME, 0); - class_addmethod(mypdlist_class, (t_method)mypdlist_help, gensym("help"), A_NULL); + class_addmethod(mypdlist_class, (t_method)mypdlist_help, gensym("help"), + A_NULL); zexy_register("lister"); } void l_setup(void) diff --git a/src/listfind.c b/src/listfind.c index 22c7af1..e987f81 100644 --- a/src/listfind.c +++ b/src/listfind.c @@ -1,4 +1,4 @@ -/* +/* * listfind: find a sublist in a list and return the index of the occurence (or indices if there are more) * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -32,8 +32,7 @@ static t_class *listfind_class; -typedef struct _listfind -{ +typedef struct _listfind { t_object x_obj; t_outlet *x_outlet; @@ -68,13 +67,17 @@ static void listfind_list2(t_listfind*x,t_symbol*s, int argc, t_atom*argv) DEBUGFUN(post("list2: %d %x", x->x_argc, x->x_argv)); } -static int atom_equals(t_atom*a1, t_atom*a2) { - if(a1->a_type!=a2->a_type) return 0; +static int atom_equals(t_atom*a1, t_atom*a2) +{ + if(a1->a_type!=a2->a_type) { + return 0; + } - return(a1->a_w.w_symbol==a2->a_w.w_symbol); + return(a1->a_w.w_symbol==a2->a_w.w_symbol); } -static int list_equals(int count, t_atom*a1, t_atom*a2) { +static int list_equals(int count, t_atom*a1, t_atom*a2) +{ int i=0; DEBUGFUN(post("list(%d) equals?", count)); DEBUGFUN(postatom(count, a1)); @@ -90,14 +93,13 @@ static int list_equals(int count, t_atom*a1, t_atom*a2) { } if(A_FLOAT==a1->a_type) { if(atom_getfloat(a1)!=atom_getfloat(a2)) { - return 0; + return 0; } - } else - if(a1->a_w.w_symbol!=a2->a_w.w_symbol) { /* is it that simple? */ - DEBUGFUN(post("atom values do not match: %x != %x", - a1->a_w.w_symbol, - a2->a_w.w_symbol - )); + } else if(a1->a_w.w_symbol!=a2->a_w.w_symbol) { /* is it that simple? */ + DEBUGFUN(post("atom values do not match: %x != %x", + a1->a_w.w_symbol, + a2->a_w.w_symbol + )); return 0; } } @@ -105,7 +107,8 @@ static int list_equals(int count, t_atom*a1, t_atom*a2) { return 1; } -static int listfind_find(int argc, t_atom*argv, int matchc, t_atom*matchv) { +static int listfind_find(int argc, t_atom*argv, int matchc, t_atom*matchv) +{ int i=0; DEBUGFUN(post("match: %d vs %d elements", argc, matchc)); @@ -113,29 +116,33 @@ static int listfind_find(int argc, t_atom*argv, int matchc, t_atom*matchv) { if(matchc>argc) { DEBUGFUN(post("list find -1")); - return -1; + return -1; } if(matchc==0) { - DEBUGFUN(post("list find 0")); + DEBUGFUN(post("list find 0")); return 0; } for(i=0; i<=(argc-matchc); i++, argv++) { DEBUGFUN(post("checking at %d", i)); - if(list_equals(matchc, argv, matchv)) + if(list_equals(matchc, argv, matchv)) { return i; + } } return -1; } -static void listfind_doit(t_outlet*out, int longcount, t_atom*longlist, int patterncount, t_atom*patternlist) { +static void listfind_doit(t_outlet*out, int longcount, t_atom*longlist, + int patterncount, t_atom*patternlist) +{ int count=0; int index; int offset=0; t_atom*ap=0; - int length=1+((patterncount>0)?(longcount/patterncount):longcount); /* we shan't have more hits than this! */ + int length=1+((patterncount>0)?(longcount/patterncount): + longcount); /* we shan't have more hits than this! */ if(length<1) { outlet_bang(out); } @@ -143,7 +150,8 @@ static void listfind_doit(t_outlet*out, int longcount, t_atom*longlist, int patt DEBUGFUN(post("expecting no more than %d results", length)); - while((index=listfind_find(longcount-offset, longlist+offset, patterncount, patternlist))>=0) { + while((index=listfind_find(longcount-offset, longlist+offset, patterncount, + patternlist))>=0) { offset+=index; SETFLOAT(ap+count, offset); @@ -159,11 +167,12 @@ static void listfind_doit(t_outlet*out, int longcount, t_atom*longlist, int patt freebytes(ap, length*sizeof(t_atom)); } -static void listfind_list(t_listfind *x, t_symbol *s, int argc, t_atom *argv) +static void listfind_list(t_listfind *x, t_symbol *s, int argc, + t_atom *argv) { #if 0 - /* entire list hot: - * this is more intuitive when searching a pattern in many lists + /* entire list hot: + * this is more intuitive when searching a pattern in many lists */ listfind_doit(x->x_obj.ob_outlet, argc, argv, x->x_argc, x->x_argv); @@ -181,7 +190,7 @@ static void listfind_list(t_listfind *x, t_symbol *s, int argc, t_atom *argv) } static void listfind_free(t_listfind *x) -{ +{ if(x->x_argv) { freebytes(x->x_argv, x->x_argc*sizeof(int)); x->x_argv=0; @@ -196,7 +205,8 @@ static void *listfind_new(t_symbol* UNUSED(s), int argc, t_atom *argv) t_listfind *x = (t_listfind *)pd_new(listfind_class); outlet_new(&x->x_obj, 0); - x->x_listin=inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("list"), gensym("lst2")); + x->x_listin=inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("list"), + gensym("lst2")); x->x_argc=0; x->x_argv=0; @@ -214,11 +224,13 @@ static void listfind_help(t_listfind*x) void listfind_setup(void) { - listfind_class = class_new(gensym("listfind"), (t_newmethod)listfind_new, + listfind_class = class_new(gensym("listfind"), (t_newmethod)listfind_new, (t_method)listfind_free, sizeof(t_listfind), 0, A_GIMME, 0); class_addlist (listfind_class, listfind_list); - class_addmethod (listfind_class, (t_method)listfind_list2, gensym("lst2"), A_GIMME, 0); + class_addmethod (listfind_class, (t_method)listfind_list2, gensym("lst2"), + A_GIMME, 0); - class_addmethod(listfind_class, (t_method)listfind_help, gensym("help"), A_NULL); + class_addmethod(listfind_class, (t_method)listfind_help, gensym("help"), + A_NULL); zexy_register("listfind"); } diff --git a/src/liststorage.c b/src/liststorage.c index bec5b1f..7139cee 100644 --- a/src/liststorage.c +++ b/src/liststorage.c @@ -1,4 +1,4 @@ -/* +/* * liststorage: stores a number of lists * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,17 +7,17 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ -/* +/* this is heavily based on code from [textfile], which is part of pd and written by Miller S. Puckette pd (and thus [textfile]) come with their own license @@ -48,8 +48,7 @@ typedef struct _msglist { struct _msglist *next; } t_msglist; -typedef struct _liststorage -{ +typedef struct _liststorage { t_object x_obj; /* everything */ t_outlet*x_dataout; /* where the data appears */ @@ -69,13 +68,18 @@ static t_class *liststorage_class; /* ************************************************************************ */ /* helper functions */ -static t_msglist*_liststorage_getslot(t_liststorage*x, int slot) { +static t_msglist*_liststorage_getslot(t_liststorage*x, int slot) +{ // post("getting slot %d of %d|%d", slot, 0, x->x_numslots); - if(slot<0 || slot>=x->x_numslots) { pd_error(x, "[liststorage]: attempting to access invalid slot %d", slot); return NULL; } + if(slot<0 || slot>=x->x_numslots) { + pd_error(x, "[liststorage]: attempting to access invalid slot %d", slot); + return NULL; + } return x->x_slots[slot]; } -static void _liststorage_deletemsglist(t_msglist*list) { +static void _liststorage_deletemsglist(t_msglist*list) +{ t_msglist*x=list; while(x) { t_msglist*y=x; @@ -89,7 +93,8 @@ static void _liststorage_deletemsglist(t_msglist*list) { } } -static void _liststorage_deleteslot(t_liststorage*x, int slot) { +static void _liststorage_deleteslot(t_liststorage*x, int slot) +{ t_msglist*list=_liststorage_getslot(x, slot); if(list) { _liststorage_deletemsglist(list); @@ -97,7 +102,8 @@ static void _liststorage_deleteslot(t_liststorage*x, int slot) { } } -static t_msglist*_liststorage_newslot(int argc, t_atom*argv) { +static t_msglist*_liststorage_newslot(int argc, t_atom*argv) +{ t_msglist*slot=getbytes(sizeof(t_msglist)); int i=0; @@ -113,7 +119,9 @@ static t_msglist*_liststorage_newslot(int argc, t_atom*argv) { } -static t_msglist*_liststorage_add2slot(t_msglist*slot, int argc, t_atom*argv) { +static t_msglist*_liststorage_add2slot(t_msglist*slot, int argc, + t_atom*argv) +{ t_msglist*dummy=slot; t_msglist*newlist=_liststorage_newslot(argc, argv); if(NULL==slot) { @@ -130,12 +138,14 @@ static t_msglist*_liststorage_add2slot(t_msglist*slot, int argc, t_atom*argv) { } -static int _liststorage_resize(t_liststorage*x, int size) { +static int _liststorage_resize(t_liststorage*x, int size) +{ t_msglist**newarray=NULL; int i=0; if(size<0) { - pd_error(x, "[liststorage]: refusing to resize for negative amount of slots"); + pd_error(x, + "[liststorage]: refusing to resize for negative amount of slots"); return 0; } @@ -170,13 +180,17 @@ static int _liststorage_resize(t_liststorage*x, int size) { return size; } -static int _liststorage_checkslot(t_liststorage*x, const char*string, const int resize) { +static int _liststorage_checkslot(t_liststorage*x, const char*string, + const int resize) +{ int slot=x->x_currentslot; t_atom atom; SETFLOAT(&atom, (t_float)slot); - if(slot<0) { - if(NULL!=string)pd_error(x, "[liststorage]: %s %d", string, slot); + if(slot<0) { + if(NULL!=string) { + pd_error(x, "[liststorage]: %s %d", string, slot); + } outlet_anything(x->x_infoout, gensym("invalidslot"), 1, &atom); return -1; } @@ -184,7 +198,9 @@ static int _liststorage_checkslot(t_liststorage*x, const char*string, const int if(resize) { _liststorage_resize(x, slot+1); } else { - if(NULL!=string)pd_error(x, "[liststorage]: %s %d", string, slot); + if(NULL!=string) { + pd_error(x, "[liststorage]: %s %d", string, slot); + } outlet_anything(x->x_infoout, gensym("invalidslot"), 1, &atom); return -1; } @@ -194,14 +210,17 @@ static int _liststorage_checkslot(t_liststorage*x, const char*string, const int /* ************************************************************************ */ /* object methods */ - /* recall all lists from the current slot */ +/* recall all lists from the current slot */ static void liststorage_bang(t_liststorage *x) -{ +{ t_atom atom; t_msglist*list=NULL; - int slot=_liststorage_checkslot(x, "attempting to read data from invalid slot", 0); - if(slot<0)return; + int slot=_liststorage_checkslot(x, + "attempting to read data from invalid slot", 0); + if(slot<0) { + return; + } list=_liststorage_getslot(x, slot); while(list) { @@ -214,26 +233,32 @@ static void liststorage_bang(t_liststorage *x) // outlet_anything(x->x_infoout, gensym("done"), 1, &atom); } - /* add a new list to the current slot */ -static void liststorage_add(t_liststorage *x, t_symbol *s, int ac, t_atom *av) +/* add a new list to the current slot */ +static void liststorage_add(t_liststorage *x, t_symbol *s, int ac, + t_atom *av) { t_msglist*list=NULL; - int slot=_liststorage_checkslot(x, "attempting to add data to invalid slot", 1); - if(slot<0)return; + int slot=_liststorage_checkslot(x, + "attempting to add data to invalid slot", 1); + if(slot<0) { + return; + } list=_liststorage_getslot(x, slot); x->x_slots[slot]=_liststorage_add2slot(x->x_slots[slot], ac, av); } - /* clear the current slot */ +/* clear the current slot */ static void liststorage_clear(t_liststorage *x) { int slot=_liststorage_checkslot(x, "attempting to clear invalid slot", 0); - if(slot<0)return; + if(slot<0) { + return; + } _liststorage_deleteslot(x, slot); } - /* clear all slots */ +/* clear all slots */ static void liststorage_clearall(t_liststorage *x) { int i=0; @@ -242,7 +267,7 @@ static void liststorage_clearall(t_liststorage *x) } } - /* insert an empty slot at (before) given position */ +/* insert an empty slot at (before) given position */ static void liststorage_insert(t_liststorage *x, t_floatarg f) { int current=x->x_currentslot; @@ -253,17 +278,19 @@ static void liststorage_insert(t_liststorage *x, t_floatarg f) slot=_liststorage_checkslot(x, "attempting to insert invalid slot", 1); x->x_currentslot=current; - if(slot<0)return; + if(slot<0) { + return; + } - _liststorage_resize(x, x->x_numslots+1); + _liststorage_resize(x, x->x_numslots+1); for(i=x->x_numslots-1; i>slot; i--) { x->x_slots[i]=x->x_slots[i-1]; } - x->x_slots[slot]=NULL; + x->x_slots[slot]=NULL; } - /* get the number of slots */ +/* get the number of slots */ static void liststorage_info(t_liststorage *x) { t_atom ap; @@ -272,7 +299,7 @@ static void liststorage_info(t_liststorage *x) } - /* get the number of slots */ +/* get the number of slots */ static void liststorage_slot(t_liststorage *x, t_floatarg f) { int slot=f; @@ -281,7 +308,7 @@ static void liststorage_slot(t_liststorage *x, t_floatarg f) } - /* remove empty slots */ +/* remove empty slots */ static void liststorage_compress(t_liststorage *x) { t_msglist**newarray=NULL; @@ -289,7 +316,7 @@ static void liststorage_compress(t_liststorage *x) int size=0; for(i=0; ix_numslots; i++) { if(NULL!=x->x_slots[i]) { - + size++; } } @@ -299,8 +326,9 @@ static void liststorage_compress(t_liststorage *x) return; } - if(sizex_defaultnumslots) + if(sizex_defaultnumslots) { size=x->x_defaultnumslots; + } /* create a new array */ newarray=getbytes(sizeof(t_msglist*)*size); @@ -344,18 +372,21 @@ static void *liststorage_new(t_floatarg f) t_liststorage *x = (t_liststorage *)pd_new(liststorage_class); int slots=f; - x->x_slotin=inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("slot")); + x->x_slotin=inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), + gensym("slot")); x->x_dataout=outlet_new(&x->x_obj, gensym("list")); x->x_infoout=outlet_new(&x->x_obj, 0); - if(slots<=0)slots=20; + if(slots<=0) { + slots=20; + } x->x_defaultnumslots=slots; x->x_numslots=0; x->x_currentslot=0; x->x_slots=NULL; - + _liststorage_resize(x, x->x_defaultnumslots); @@ -365,33 +396,41 @@ static void *liststorage_new(t_floatarg f) void liststorage_setup(void) { - liststorage_class = class_new(gensym("liststorage"), (t_newmethod)liststorage_new, - (t_method)liststorage_free, sizeof(t_liststorage), 0, A_DEFFLOAT, 0); + liststorage_class = class_new(gensym("liststorage"), + (t_newmethod)liststorage_new, + (t_method)liststorage_free, sizeof(t_liststorage), 0, A_DEFFLOAT, 0); /* recall all lists from the current slot */ class_addbang(liststorage_class, (t_method)liststorage_bang); /* add a new list to the current slot */ - class_addmethod(liststorage_class, (t_method)liststorage_add, gensym("add"), A_GIMME, 0); + class_addmethod(liststorage_class, (t_method)liststorage_add, + gensym("add"), A_GIMME, 0); /* clear the current slot */ - class_addmethod(liststorage_class, (t_method)liststorage_clear, gensym("clear"), 0); + class_addmethod(liststorage_class, (t_method)liststorage_clear, + gensym("clear"), 0); /* clear all slots */ - class_addmethod(liststorage_class, (t_method)liststorage_clearall, gensym("clearall"), 0); + class_addmethod(liststorage_class, (t_method)liststorage_clearall, + gensym("clearall"), 0); /* add a new list to the current slot */ - class_addmethod(liststorage_class, (t_method)liststorage_slot, gensym("slot"), A_FLOAT, 0); + class_addmethod(liststorage_class, (t_method)liststorage_slot, + gensym("slot"), A_FLOAT, 0); /* insert an empty slot at (before) given position */ - class_addmethod(liststorage_class, (t_method)liststorage_insert, gensym("insert"), A_DEFFLOAT, 0); + class_addmethod(liststorage_class, (t_method)liststorage_insert, + gensym("insert"), A_DEFFLOAT, 0); - /* remove empty slots */ - class_addmethod(liststorage_class, (t_method)liststorage_compress, gensym("compress"), 0); + /* remove empty slots */ + class_addmethod(liststorage_class, (t_method)liststorage_compress, + gensym("compress"), 0); /* get the number of slots */ - class_addmethod(liststorage_class, (t_method)liststorage_info, gensym("info"), 0); + class_addmethod(liststorage_class, (t_method)liststorage_info, + gensym("info"), 0); zexy_register("liststorage"); } diff --git a/src/longload.c b/src/longload.c index fcdef25..0e914e7 100644 --- a/src/longload.c +++ b/src/longload.c @@ -1,4 +1,4 @@ -/* +/* * longload: takes a long time to load * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -30,12 +30,12 @@ static t_class *longload_class; -typedef struct _longload -{ +typedef struct _longload { t_object x_obj; } t_longload; -int millisleep(unsigned int milli) { +int millisleep(unsigned int milli) +{ #ifdef _WIN32 Sleep(milli); #else @@ -47,20 +47,21 @@ int millisleep(unsigned int milli) { static void *longload_new(t_float f) { t_longload *x = (t_longload *)pd_new(longload_class); - if(f>0.f) + if(f>0.f) { millisleep(f); - else + } else { millisleep(1000); + } return (x); } void longload_setup(void) { - longload_class = class_new(gensym("longload"), - (t_newmethod)longload_new, - 0, - sizeof(t_longload), - CLASS_NOINLET, + longload_class = class_new(gensym("longload"), + (t_newmethod)longload_new, + 0, + sizeof(t_longload), + CLASS_NOINLET, A_DEFFLOAT, 0); zexy_register("longload"); } diff --git a/src/lpt.c b/src/lpt.c index 270aead..26f4468 100644 --- a/src/lpt.c +++ b/src/lpt.c @@ -1,4 +1,4 @@ -/* +/* * lpt: read/write the parallel port * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,18 +7,18 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ -/* +/* (c) 2000:forum::für::umläute:2005 write to the parallel port @@ -68,7 +68,9 @@ extern int open_port(int port); static int ioperm(int port, int a, int b) { - if(open_port(port) == -1)return(1); + if(open_port(port) == -1) { + return(1); + } return(0); } @@ -104,8 +106,7 @@ static int sys_inb(int port) static int count_iopl = 0; static t_class *lpt_class; -typedef struct _lpt -{ +typedef struct _lpt { t_object x_obj; unsigned long port; @@ -119,13 +120,13 @@ static void lpt_float(t_lpt *x, t_floatarg f) #ifdef Z_WANT_LPT unsigned char b = f; # ifdef HAVE_LINUX_PPDEV_H - if (x->device>0){ + if (x->device>0) { ioctl (x->device, PPWDATA, &b); } else # endif - if (x->port) { - sys_outb(b, x->port+0); - } + if (x->port) { + sys_outb(b, x->port+0); + } #endif /* Z_WANT_LPT */ } @@ -134,13 +135,13 @@ static void lpt_control(t_lpt *x, t_floatarg f) #ifdef Z_WANT_LPT unsigned char b = f; # ifdef HAVE_LINUX_PPDEV_H - if (x->device>0){ + if (x->device>0) { ioctl (x->device, PPWCONTROL, &b); } else # endif - if (x->port) { - sys_outb(b, x->port+2); - } + if (x->port) { + sys_outb(b, x->port+2); + } #endif /* Z_WANT_LPT */ } @@ -148,15 +149,15 @@ static void lpt_bang(t_lpt *x) { #ifdef Z_WANT_LPT # ifdef HAVE_LINUX_PPDEV_H - if (x->device>0){ + if (x->device>0) { unsigned char b=0; ioctl (x->device, PPRCONTROL, &b); - outlet_float(x->x_obj.ob_outlet, (t_float)b); + outlet_float(x->x_obj.ob_outlet, (t_float)b); } else # endif - if (x->port) { - outlet_float(x->x_obj.ob_outlet, (t_float)sys_inb(x->port+1)); - } + if (x->port) { + outlet_float(x->x_obj.ob_outlet, (t_float)sys_inb(x->port+1)); + } #endif /* Z_WANT_LPT */ } @@ -165,8 +166,9 @@ static void *lpt_new(t_symbol *s, int argc, t_atom *argv) { t_lpt *x = (t_lpt *)pd_new(lpt_class); char*devname=atom_getsymbol(argv)->s_name; - if(s==gensym("lp")) + if(s==gensym("lp")) { error("lpt: the use of 'lp' has been deprecated; use 'lpt' instead"); + } inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("control")); @@ -184,7 +186,7 @@ static void *lpt_new(t_symbol *s, int argc, t_atom *argv) break; case 1: x->port = BASE1; - break; + break; case 2: x->port = BASE2; break; @@ -193,17 +195,17 @@ static void *lpt_new(t_symbol *s, int argc, t_atom *argv) x->port = 0; return (x); } - } else { + } else { /* SYMBOL might be a file or a hex port-number; we ignore the file (device) case by now; LATER think about this */ x->device=-1; x->port=strtol(devname, 0, 16); - if(0==x->port){ + if(0==x->port) { #ifdef HAVE_LINUX_PPDEV_H x->device = open(devname, O_RDWR); - if(x->device<=0){ + if(x->device<=0) { error("lpt: bad device %s", devname); return(x); } else { @@ -217,12 +219,12 @@ static void *lpt_new(t_symbol *s, int argc, t_atom *argv) } } - if ((x->device<0) && (!x->port || x->port>65535)){ + if ((x->device<0) && (!x->port || x->port>65535)) { error("lpt : bad port %x", x->port); x->port = 0; return (x); } - if (x->device<0){ + if (x->device<0) { /* this is ugly: when using a named device, * we are currently assuming that we have read/write-access * of course, this is not necessary true @@ -231,29 +233,37 @@ static void *lpt_new(t_symbol *s, int argc, t_atom *argv) * withOUT write permissions * (just reading the parport) */ - if (x->port && x->port < 0x400){ + if (x->port && x->port < 0x400) { if (ioperm(x->port, 8, 1)) { x->mode=MODE_NONE; - } else x->mode = MODE_IOPERM; + } else { + x->mode = MODE_IOPERM; + } } - if(x->mode==MODE_NONE){ - if (iopl(3)){ + if(x->mode==MODE_NONE) { + if (iopl(3)) { x->mode=MODE_NONE; - } else x->mode=MODE_IOPL; + } else { + x->mode=MODE_IOPL; + } count_iopl++; } - - if(x->mode==MODE_NONE){ + + if(x->mode==MODE_NONE) { error("lpt : couldn't get write permissions"); x->port = 0; return (x); } } - if(x->device>0) + if(x->device>0) { post("lpt: connected to device %s", devname); - else - post("lpt: connected to port %x in mode '%s'", x->port, (x->mode==MODE_IOPL)?"iopl":"ioperm"); - if (x->mode==MODE_IOPL)post("lpt-warning: this might seriously damage your pc..."); + } else { + post("lpt: connected to port %x in mode '%s'", x->port, + (x->mode==MODE_IOPL)?"iopl":"ioperm"); + } + if (x->mode==MODE_IOPL) { + post("lpt-warning: this might seriously damage your pc..."); + } #else error("zexy has been compiled without [lpt]!"); count_iopl=0; @@ -268,17 +278,19 @@ static void lpt_free(t_lpt *x) { #ifdef Z_WANT_LPT # ifdef HAVE_LINUX_PPDEV_H - if (x->device>0){ + if (x->device>0) { ioctl (x->device, PPRELEASE); close(x->device); x->device=0; } else # endif - if (x->port) { - if (x->mode==MODE_IOPERM && ioperm(x->port, 8, 0)) error("lpt: couldn't clean up device"); - else if (x->mode==MODE_IOPL && (!--count_iopl) && iopl(0)) - error("lpt: couldn't clean up device"); - } + if (x->port) { + if (x->mode==MODE_IOPERM && ioperm(x->port, 8, 0)) { + error("lpt: couldn't clean up device"); + } else if (x->mode==MODE_IOPL && (!--count_iopl) && iopl(0)) { + error("lpt: couldn't clean up device"); + } + } #endif /* Z_WANT_LPT */ } @@ -294,12 +306,13 @@ static void lpt_helper(t_lpt*UNUSED(x)) void lpt_setup(void) { lpt_class = class_new(gensym("lpt"), - (t_newmethod)lpt_new, (t_method)lpt_free, - sizeof(t_lpt), 0, A_GIMME, 0); + (t_newmethod)lpt_new, (t_method)lpt_free, + sizeof(t_lpt), 0, A_GIMME, 0); class_addcreator((t_newmethod)lpt_new, gensym("lp"), A_GIMME, 0); class_addfloat(lpt_class, (t_method)lpt_float); - class_addmethod(lpt_class, (t_method)lpt_control, gensym("control"), A_FLOAT, 0); + class_addmethod(lpt_class, (t_method)lpt_control, gensym("control"), + A_FLOAT, 0); class_addbang(lpt_class, (t_method)lpt_bang); class_addmethod(lpt_class, (t_method)lpt_helper, gensym("help"), 0); diff --git a/src/makesymbol.c b/src/makesymbol.c index f0342d8..bc24749 100644 --- a/src/makesymbol.c +++ b/src/makesymbol.c @@ -1,4 +1,4 @@ -/* +/* * makesymbol: yet another (formatted) symbol creation mechanism * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,29 +7,29 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ -/* +/* (l) 1210:forum::für::umläute:1999 -"makesymbol" is something between "symbol" and "makefilename", +"makesymbol" is something between "symbol" and "makefilename", thus storing and creating (formatted) symbols... TODO: - the use of only "%s" is really not very satisfying - LATER: - split the entire format string into subformats with only + the use of only "%s" is really not very satisfying + LATER: + split the entire format string into subformats with only one format-placeholder ("%[^%]*[diufFgGxXoscpn]") . split the entire format string into subformats with only one format-placeholder, store the types @@ -49,24 +49,23 @@ static t_class *makesymbol_class; -typedef struct _makesymbol -{ - t_object x_obj; - t_symbol *x_sym; +typedef struct _makesymbol { + t_object x_obj; + t_symbol *x_sym; - char* mask; - char* buf; + char* mask; + char* buf; } t_makesymbol; static void reset_mask(t_makesymbol *x, t_symbol *s) { - if (*s->s_name) { - x->mask = s->s_name; - x->x_sym = s; - } else { - x->mask = "%s%s%s%s%s%s%s%s%s%s"; - x->x_sym = gensym(""); - } + if (*s->s_name) { + x->mask = s->s_name; + x->x_sym = s; + } else { + x->mask = "%s%s%s%s%s%s%s%s%s%s"; + x->x_sym = gensym(""); + } } typedef char cstring[MAXSTRINGLENG]; @@ -74,85 +73,92 @@ typedef char cstring[MAXSTRINGLENG]; static t_symbol* list2symbol(char *masque, int argc, t_atom *argv) { cstring*buf=(cstring*)getbytes(MAXSTRINGARGS*sizeof(cstring)); - cstring buffer; - int i; + cstring buffer; + int i; - for(i=0; ix_sym = list2symbol(x->mask, argc, argv); - outlet_symbol(x->x_obj.ob_outlet, x->x_sym); + x->x_sym = list2symbol(x->mask, argc, argv); + outlet_symbol(x->x_obj.ob_outlet, x->x_sym); } static void makesymbol_bang(t_makesymbol *x) { - outlet_symbol(x->x_obj.ob_outlet, x->x_sym); + outlet_symbol(x->x_obj.ob_outlet, x->x_sym); } static void *makesymbol_new(t_symbol* UNUSED(s), int argc, t_atom *argv) { - t_makesymbol *x = (t_makesymbol *)pd_new(makesymbol_class); + t_makesymbol *x = (t_makesymbol *)pd_new(makesymbol_class); - x->buf = (char *)getbytes(MAXSTRINGLENG * sizeof(char)); + x->buf = (char *)getbytes(MAXSTRINGLENG * sizeof(char)); - x->mask = x->buf; + x->mask = x->buf; - if (argc) { - atom_string(argv, x->buf, MAXSTRINGLENG); - x->x_sym = gensym(x->buf); - } else { - x->mask = "%s%s%s%s%s%s%s%s%s%s"; - x->x_sym = gensym(""); - } + if (argc) { + atom_string(argv, x->buf, MAXSTRINGLENG); + x->x_sym = gensym(x->buf); + } else { + x->mask = "%s%s%s%s%s%s%s%s%s%s"; + x->x_sym = gensym(""); + } - outlet_new(&x->x_obj, gensym("symbol")); - inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("symbol"), gensym("sym1")); + outlet_new(&x->x_obj, gensym("symbol")); + inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("symbol"), gensym("sym1")); - return (x); + return (x); } static void makesymbol_free(t_makesymbol *x) { - freebytes(x->buf, MAXSTRINGLENG*sizeof(char)); + freebytes(x->buf, MAXSTRINGLENG*sizeof(char)); } static void makesymbol_helper(t_makesymbol* UNUSED(x)) { - post("\n"HEARTSYMBOL" makesymbol :: create a formatted symbol"); - post("\t: glue up to 10 list-elements to 1 formatted symbol\n" - "'bang'\t\t\t: re-output\n" - "'help'\t\t\t: view this" - "\ninlet2 : : new format-string (symbol !)" - "\noutlet : \t: formatted concatenation"); - post("\ncreation:\"makesymbol []\": C-style format-string (%s only)", "%s"); + post("\n"HEARTSYMBOL" makesymbol :: create a formatted symbol"); + post("\t: glue up to 10 list-elements to 1 formatted symbol\n" + "'bang'\t\t\t: re-output\n" + "'help'\t\t\t: view this" + "\ninlet2 : : new format-string (symbol !)" + "\noutlet : \t: formatted concatenation"); + post("\ncreation:\"makesymbol []\": C-style format-string (%s only)", + "%s"); } void makesymbol_setup(void) { - makesymbol_class = class_new(gensym("makesymbol"), - (t_newmethod)makesymbol_new, (t_method)makesymbol_free, - sizeof(t_makesymbol), 0, A_GIMME, 0); + makesymbol_class = class_new(gensym("makesymbol"), + (t_newmethod)makesymbol_new, (t_method)makesymbol_free, + sizeof(t_makesymbol), 0, A_GIMME, 0); - class_addlist(makesymbol_class, makesymbol_list); - class_addbang(makesymbol_class, makesymbol_bang); + class_addlist(makesymbol_class, makesymbol_list); + class_addbang(makesymbol_class, makesymbol_bang); - class_addmethod(makesymbol_class, (t_method)reset_mask, gensym("sym1"), A_SYMBOL, 0); + class_addmethod(makesymbol_class, (t_method)reset_mask, gensym("sym1"), + A_SYMBOL, 0); - class_addmethod(makesymbol_class, (t_method)makesymbol_helper, gensym("help"), 0); + class_addmethod(makesymbol_class, (t_method)makesymbol_helper, + gensym("help"), 0); zexy_register("makesymbol"); } diff --git a/src/matchbox.c b/src/matchbox.c index f1d8183..770d269 100644 --- a/src/matchbox.c +++ b/src/matchbox.c @@ -1,4 +1,4 @@ -/* +/* * matchbox: see whether a regular expression matches a symbol in the box * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -57,8 +57,7 @@ typedef struct _listlist { } t_listlist; -typedef struct _matchbox -{ +typedef struct _matchbox { t_object x_obj; t_listlist*x_lists; @@ -74,34 +73,42 @@ typedef struct _matchbox /* ----------- here comes some infrastructure stuff -------------- */ -static t_listlist* addlistlist(t_listlist*list, int argc, t_atom*argv) { +static t_listlist* addlistlist(t_listlist*list, int argc, t_atom*argv) +{ t_listlist*ll=(t_listlist*)getbytes(sizeof(t_listlist)); t_listlist*lp=0; ll->next=0; ll->argc=argc; ll->argv=(t_atom*)getbytes(argc*sizeof(t_atom)); - memcpy(ll->argv, argv, argc*sizeof(t_atom)); + memcpy(ll->argv, argv, argc*sizeof(t_atom)); if(0==list) { return ll; } - + lp=list; - while(0!=lp->next)lp=lp->next; + while(0!=lp->next) { + lp=lp->next; + } lp->next=ll; return list; } /* delete the _next_ element from the list */ -static t_listlist* deletelistnext(t_listlist*list) { +static t_listlist* deletelistnext(t_listlist*list) +{ t_listlist*ll=0; - if(!list || !list->next)return list; /* nothing to delete */ + if(!list || !list->next) { + return list; /* nothing to delete */ + } ll=list->next; list->next=ll->next; - if(ll->argv)freebytes(ll->argv, ll->argc*sizeof(t_atom)); + if(ll->argv) { + freebytes(ll->argv, ll->argc*sizeof(t_atom)); + } ll->argv=0; ll->argc=0; @@ -111,9 +118,12 @@ static t_listlist* deletelistnext(t_listlist*list) { } /* delete the entire list of lists */ -static void clearlistlist(t_listlist*list) { - if(!list)return; /* nothing to delete */ - while(list->next){ +static void clearlistlist(t_listlist*list) +{ + if(!list) { + return; /* nothing to delete */ + } + while(list->next) { list=deletelistnext(list); } } @@ -121,7 +131,8 @@ static void clearlistlist(t_listlist*list) { /* -------------- here comes the matching algorithms ----------- */ -static int atommatch_exact(t_atom*pattern, t_atom*atom) { +static int atommatch_exact(t_atom*pattern, t_atom*atom) +{ if(pattern->a_type==atom->a_type) { switch(pattern->a_type) { case A_FLOAT: @@ -142,10 +153,10 @@ static int atommatch_exact(t_atom*pattern, t_atom*atom) { #ifdef MATCHBOX_OSC /* OSC */ /* -OSC pattern matching code was written by Matt Wright, +OSC pattern matching code was written by Matt Wright, The Center for New Music and Audio Technologies, University of California, Berkeley. Copyright (c) 1998,99,2000,01,02,03,04 -The Regents of the University of California (Regents). +The Regents of the University of California (Regents). Permission to use, copy, modify, distribute, and distribute modified versions of this software and its documentation without fee and without a signed @@ -168,25 +179,32 @@ The OSC webpage is http://cnmat.cnmat.berkeley.edu/OpenSoundControl */ #define OSCWarning post -static int OSC_MatchBrackets (const char *pattern, const char *test, const char*theWholePattern); -static int OSC_MatchList (const char *pattern, const char *test, const char*theWholePattern); +static int OSC_MatchBrackets (const char *pattern, const char *test, + const char*theWholePattern); +static int OSC_MatchList (const char *pattern, const char *test, + const char*theWholePattern); -static int OSC_PatternMatch (const char * pattern, const char * test, const char*theWholePattern) { +static int OSC_PatternMatch (const char * pattern, const char * test, + const char*theWholePattern) +{ if (pattern == 0 || pattern[0] == 0) { return test[0] == 0; - } - + } + if (test[0] == 0) { - if (pattern[0] == '*') + if (pattern[0] == '*') { return OSC_PatternMatch (pattern+1,test, theWholePattern); - else + } else { return FALSE; + } } switch (pattern[0]) { - case 0 : return test[0] == 0; - case '?' : return OSC_PatternMatch (pattern + 1, test + 1, theWholePattern); - case '*' : + case 0 : + return test[0] == 0; + case '?' : + return OSC_PatternMatch (pattern + 1, test + 1, theWholePattern); + case '*' : if (OSC_PatternMatch (pattern+1, test, theWholePattern)) { return TRUE; } else { @@ -194,13 +212,14 @@ static int OSC_PatternMatch (const char * pattern, const char * test, const cha } case ']' : case '}' : - z_verbose(1, "[matchbox]: spurious %c in OSC-pattern \".../%s/...\"",pattern[0], theWholePattern); + z_verbose(1, "[matchbox]: spurious %c in OSC-pattern \".../%s/...\"", + pattern[0], theWholePattern); return FALSE; case '[' : return OSC_MatchBrackets (pattern,test, theWholePattern); case '{' : return OSC_MatchList (pattern,test, theWholePattern); - case '\\' : + case '\\' : if (pattern[1] == 0) { return test[0] == 0; } else if (pattern[1] == test[0]) { @@ -219,13 +238,16 @@ static int OSC_PatternMatch (const char * pattern, const char * test, const cha /* we know that pattern[0] == '[' and test[0] != 0 */ -static int OSC_MatchBrackets (const char *pattern, const char *test, const char*theWholePattern) { +static int OSC_MatchBrackets (const char *pattern, const char *test, + const char*theWholePattern) +{ int result; int negated = FALSE; const char *p = pattern; if (pattern[1] == 0) { - z_verbose(1, "[matchbox]: unterminated [ in OSC-pattern \".../%s/...\"", theWholePattern); + z_verbose(1, "[matchbox]: unterminated [ in OSC-pattern \".../%s/...\"", + theWholePattern); return FALSE; } @@ -236,13 +258,14 @@ static int OSC_MatchBrackets (const char *pattern, const char *test, const char* while (*p != ']') { if (*p == 0) { - z_verbose(1, "[matchbox]: unterminated [ in OSC-pattern \".../%s/...\"", theWholePattern); + z_verbose(1, "[matchbox]: unterminated [ in OSC-pattern \".../%s/...\"", + theWholePattern); return FALSE; } if (p[1] == '-' && p[2] != 0) { if (test[0] >= p[0] && test[0] <= p[2]) { - result = !negated; - goto advance; + result = !negated; + goto advance; } } if (p[0] == test[0]) { @@ -254,14 +277,16 @@ static int OSC_MatchBrackets (const char *pattern, const char *test, const char* result = negated; - advance: +advance: - if (!result) + if (!result) { return FALSE; + } while (*p != ']') { if (*p == 0) { - z_verbose(1, "[matchbox]: unterminated [ in OSC-pattern \".../%s/...\"", theWholePattern); + z_verbose(1, "[matchbox]: unterminated [ in OSC-pattern \".../%s/...\"", + theWholePattern); return FALSE; } p++; @@ -270,13 +295,16 @@ static int OSC_MatchBrackets (const char *pattern, const char *test, const char* return OSC_PatternMatch (p+1,test+1, theWholePattern); } -static int OSC_MatchList (const char *pattern, const char *test, const char* theWholePattern) { +static int OSC_MatchList (const char *pattern, const char *test, + const char* theWholePattern) +{ const char *restOfPattern, *tp = test; for(restOfPattern = pattern; *restOfPattern != '}'; restOfPattern++) { if (*restOfPattern == 0) { - z_verbose(1, "[matchbox]: unterminated { in OSC-pattern \".../%s/...\"", theWholePattern); + z_verbose(1, "[matchbox]: unterminated { in OSC-pattern \".../%s/...\"", + theWholePattern); return FALSE; } } @@ -287,7 +315,7 @@ static int OSC_MatchList (const char *pattern, const char *test, const char* the pattern++; /* skip open curly brace */ while (1) { - + if (*pattern == ',') { if (OSC_PatternMatch (restOfPattern, tp, theWholePattern)) { return TRUE; @@ -312,7 +340,8 @@ static int OSC_MatchList (const char *pattern, const char *test, const char* the } } -static int atommatch_osc(t_atom*pattern, t_atom*test) { +static int atommatch_osc(t_atom*pattern, t_atom*test) +{ char*s_pattern=0; char*s_test=0; int pattern_size=0, test_size=0; @@ -339,11 +368,13 @@ static int atommatch_osc(t_atom*pattern, t_atom*test) { if(pattern_size>0) { freebytes(s_pattern, pattern_size); - s_pattern=0; pattern_size=0; + s_pattern=0; + pattern_size=0; } if(test_size>0) { freebytes(s_test, test_size); - s_test=0; test_size=0; + s_test=0; + test_size=0; } @@ -353,13 +384,18 @@ static int atommatch_osc(t_atom*pattern, t_atom*test) { #ifdef MATCHBOX_REGEX -static int atommatch_regex(regex_t*pattern, t_atom*test) { +static int atommatch_regex(regex_t*pattern, t_atom*test) +{ int result=FALSE; char*s_test=0; int test_size=0; - if(0==pattern)return FALSE; - if(0==test) return FALSE; + if(0==pattern) { + return FALSE; + } + if(0==test) { + return FALSE; + } if(test->a_type==A_SYMBOL) { s_test=test->a_w.w_symbol->s_name; @@ -373,17 +409,21 @@ static int atommatch_regex(regex_t*pattern, t_atom*test) { if(test_size>0) { freebytes(s_test, test_size); - s_test=0; test_size=0; - } - + s_test=0; + test_size=0; + } + return result; } -static int listmatch_regex(int p_argc, regex_t**pattern, int t_argc, t_atom*test) { +static int listmatch_regex(int p_argc, regex_t**pattern, int t_argc, + t_atom*test) +{ /* match the patterns to the test */ int argc=p_argc; - if(p_argc!=t_argc) + if(p_argc!=t_argc) { return FALSE; + } while(argc--) { if(FALSE==atommatch_regex(*pattern++, test++)) { @@ -394,7 +434,10 @@ static int listmatch_regex(int p_argc, regex_t**pattern, int t_argc, t_atom*test return TRUE; } -static t_listlist*matchlistlist_regex(unsigned int*numresults, t_listlist*searchlist, int p_argc, t_atom*p_argv, int flags, int delete_results) { +static t_listlist*matchlistlist_regex(unsigned int*numresults, + t_listlist*searchlist, int p_argc, t_atom*p_argv, int flags, + int delete_results) +{ regex_t**regexpressions=0; t_listlist*matchinglist=0, *sl; int i=0; @@ -418,15 +461,18 @@ static t_listlist*matchlistlist_regex(unsigned int*numresults, t_listlist*search regexpressions[i]=(regex_t*)getbytes(sizeof(regex_t)); if(regcomp(regexpressions[i], s_pattern, flags)) { z_verbose(1, "[matchbox]: invalid regular expression: %s", s_pattern); - if(regexpressions[i])freebytes(regexpressions[i], sizeof(regex_t)); - regexpressions[i]=0; + if(regexpressions[i]) { + freebytes(regexpressions[i], sizeof(regex_t)); + } + regexpressions[i]=0; } if(pattern_size>0) { freebytes(s_pattern, pattern_size); - s_pattern=0; pattern_size=0; + s_pattern=0; + pattern_size=0; } } - + /* match the patterns to the tests */ if(FALSE==delete_results) { for(sl=searchlist; 0!=sl; sl=sl->next) { @@ -443,7 +489,7 @@ static t_listlist*matchlistlist_regex(unsigned int*numresults, t_listlist*search matchinglist=addlistlist(matchinglist, sl->argc, sl->argv); num++; - sl=deletelistnext(lastgood); + sl=deletelistnext(lastgood); } else { lastgood=sl; } @@ -452,16 +498,17 @@ static t_listlist*matchlistlist_regex(unsigned int*numresults, t_listlist*search /* clear the patterns */ for(i=0; inext; 0!=sl; sl=sl->next) { - if(matchlist(p_argc, p_argv, sl->argc, sl->argv, mode)) { - matchinglist=addlistlist(matchinglist, sl->argc, sl->argv); - num++; + /* normal matching */ + if(FALSE==delete_results) { + for(sl=searchlist->next; 0!=sl; sl=sl->next) { + if(matchlist(p_argc, p_argv, sl->argc, sl->argv, mode)) { + matchinglist=addlistlist(matchinglist, sl->argc, sl->argv); + num++; + } } - } - } else if (TRUE==delete_results) { - /* yummy: delete matching lists! */ - t_listlist*lastgood=searchlist; - for(sl=searchlist->next; 0!=sl; sl=sl->next) { - if(matchlist(p_argc, p_argv, sl->argc, sl->argv, mode)) { - matchinglist=addlistlist(matchinglist, sl->argc, sl->argv); - num++; - - sl=deletelistnext(lastgood); - } else { - lastgood=sl; + } else if (TRUE==delete_results) { + /* yummy: delete matching lists! */ + t_listlist*lastgood=searchlist; + for(sl=searchlist->next; 0!=sl; sl=sl->next) { + if(matchlist(p_argc, p_argv, sl->argc, sl->argv, mode)) { + matchinglist=addlistlist(matchinglist, sl->argc, sl->argv); + num++; + + sl=deletelistnext(lastgood); + } else { + lastgood=sl; + } } } - } - if(numresults!=0) + if(numresults!=0) { *numresults=num; + } return matchinglist; } -static void matchbox_list(t_matchbox*x, t_symbol*s, int argc, t_atom*argv) { +static void matchbox_list(t_matchbox*x, t_symbol*s, int argc, t_atom*argv) +{ unsigned int results=0; int mode=x->x_mode; - t_listlist*resultlist=matchlistlist(&results, x->x_lists, argc, argv, mode, FALSE); + t_listlist*resultlist=matchlistlist(&results, x->x_lists, argc, argv, mode, + FALSE); t_listlist*dummylist; outlet_float(x->x_outNumResults, (t_float)results); - - for(dummylist=resultlist; 0!=dummylist; dummylist=dummylist->next) - outlet_list(x->x_outResult, gensym("list"), dummylist->argc, dummylist->argv); + + for(dummylist=resultlist; 0!=dummylist; dummylist=dummylist->next) { + outlet_list(x->x_outResult, gensym("list"), dummylist->argc, + dummylist->argv); + } } -static void matchbox_add(t_matchbox*x, t_symbol*s, int argc, t_atom*argv) { +static void matchbox_add(t_matchbox*x, t_symbol*s, int argc, t_atom*argv) +{ /* 1st match, whether we already have this entry */ if(matchlistlist(0, x->x_lists, argc, argv, MATCHBOX_EXACT, FALSE)) { /* already there, skip the rest */ - z_verbose(1, "[matchbox]: refusing to add already existing list to buffer..."); + z_verbose(1, + "[matchbox]: refusing to add already existing list to buffer..."); return; } @@ -560,58 +624,66 @@ static void matchbox_add(t_matchbox*x, t_symbol*s, int argc, t_atom*argv) { x->x_numlists++; } -static void matchbox_delete(t_matchbox*x, t_symbol*s, int argc, t_atom*argv) { +static void matchbox_delete(t_matchbox*x, t_symbol*s, int argc, + t_atom*argv) +{ unsigned int results=0; int mode=x->x_mode; - t_listlist*resultlist=matchlistlist(&results, x->x_lists, argc, argv, mode, TRUE); + t_listlist*resultlist=matchlistlist(&results, x->x_lists, argc, argv, mode, + TRUE); t_listlist*dummylist; t_symbol*delsym=gensym("deleted"); x->x_numlists-=results; outlet_float(x->x_outNumResults, (t_float)results); - - for(dummylist=resultlist; 0!=dummylist; dummylist=dummylist->next) + + for(dummylist=resultlist; 0!=dummylist; dummylist=dummylist->next) { outlet_anything(x->x_outResult, delsym, dummylist->argc, dummylist->argv); + } } -static void matchbox_dump(t_matchbox*x) { +static void matchbox_dump(t_matchbox*x) +{ t_listlist*lp=0; - if(0==x->x_lists || 0==x->x_lists->next){ + if(0==x->x_lists || 0==x->x_lists->next) { outlet_float(x->x_outNumResults, 0); return; } outlet_float(x->x_outNumResults, x->x_numlists); - for(lp=x->x_lists->next; 0!=lp; lp=lp->next) - { + for(lp=x->x_lists->next; 0!=lp; lp=lp->next) { outlet_list(x->x_outResult, gensym("list"), lp->argc, lp->argv); } } -static void matchbox_clear(t_matchbox*x) { +static void matchbox_clear(t_matchbox*x) +{ clearlistlist(x->x_lists); x->x_numlists=0; } -static void matchbox_mode(t_matchbox*x, t_symbol*s) { - if(gensym("==")==s) +static void matchbox_mode(t_matchbox*x, t_symbol*s) +{ + if(gensym("==")==s) { x->x_mode=MATCHBOX_EXACT; - else if (gensym("OSC")==s) { + } else if (gensym("OSC")==s) { #ifdef MATCHBOX_OSC x->x_mode=MATCHBOX_OSC; #else - pd_error(x, "[matchbox] has been compiled without 'OSC' support; ignoring your request"); + pd_error(x, + "[matchbox] has been compiled without 'OSC' support; ignoring your request"); #endif /* MATCHBOX_OSC */ } else if(gensym("regex")==s) { #ifdef MATCHBOX_REGEX x->x_mode=MATCHBOX_REGEX; #else - pd_error(x, "[matchbox] has been compiled without 'regex' support; ignoring your request"); + pd_error(x, + "[matchbox] has been compiled without 'regex' support; ignoring your request"); #endif /* MATCHBOX_REGEX */ } else { pd_error(x, "mode '%s' is unknown, switching to 'exact' mode", s->s_name); @@ -648,7 +720,7 @@ static void *matchbox_new(t_symbol *s, int argc, t_atom*argv) static void matchbox_free(t_matchbox *x) { matchbox_clear(x); - freebytes(x->x_lists, sizeof(t_listlist)); + freebytes(x->x_lists, sizeof(t_listlist)); x->x_lists=0; } @@ -664,18 +736,24 @@ void matchbox_setup(void) #endif /* MATCHBOX_OSC */ - matchbox_class = class_new(gensym("matchbox"), (t_newmethod)matchbox_new, - (t_method)matchbox_free, sizeof(t_matchbox), 0, A_GIMME, 0); + matchbox_class = class_new(gensym("matchbox"), (t_newmethod)matchbox_new, + (t_method)matchbox_free, sizeof(t_matchbox), 0, A_GIMME, 0); class_addlist (matchbox_class, matchbox_list); - class_addmethod(matchbox_class, (t_method)matchbox_add, gensym("add"), A_GIMME, 0); - class_addmethod(matchbox_class, (t_method)matchbox_delete, gensym("delete"), A_GIMME, 0); - class_addmethod(matchbox_class, (t_method)matchbox_clear, gensym("clear"), A_NULL, 0); - class_addmethod(matchbox_class, (t_method)matchbox_dump, gensym("dump"), A_NULL); + class_addmethod(matchbox_class, (t_method)matchbox_add, gensym("add"), + A_GIMME, 0); + class_addmethod(matchbox_class, (t_method)matchbox_delete, + gensym("delete"), A_GIMME, 0); + class_addmethod(matchbox_class, (t_method)matchbox_clear, gensym("clear"), + A_NULL, 0); + class_addmethod(matchbox_class, (t_method)matchbox_dump, gensym("dump"), + A_NULL); - class_addmethod(matchbox_class, (t_method)matchbox_mode, gensym("mode"), A_SYMBOL, 0); + class_addmethod(matchbox_class, (t_method)matchbox_mode, gensym("mode"), + A_SYMBOL, 0); - class_addmethod(matchbox_class, (t_method)matchbox_help, gensym("help"), A_NULL); + class_addmethod(matchbox_class, (t_method)matchbox_help, gensym("help"), + A_NULL); zexy_register("matchbox"); } diff --git a/src/mavg.c b/src/mavg.c index 75b425b..943dbb6 100644 --- a/src/mavg.c +++ b/src/mavg.c @@ -1,4 +1,4 @@ -/* +/* * mavg :: moving average filter * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -21,8 +21,7 @@ static t_class *mavg_class; -typedef struct _mavg -{ +typedef struct _mavg { t_object x_obj; t_float n_inv; @@ -37,7 +36,9 @@ static void mavg_resize(t_mavg *x, t_float f) t_float *dumbuf; f = (int)f; - if ((f<1) || (f == x->size)) return; + if ((f<1) || (f == x->size)) { + return; + } freebytes(x->buf, sizeof(t_float)*x->size); x->n_inv = 1.0/f; @@ -46,16 +47,21 @@ static void mavg_resize(t_mavg *x, t_float f) dumbuf = x->wp = x->buf; i = x->size; - while(i--) *dumbuf++ = x->avg; + while(i--) { + *dumbuf++ = x->avg; + } } -static void mavg_set(t_mavg *x, t_symbol* UNUSED(s), int argc, t_atom *argv) +static void mavg_set(t_mavg *x, t_symbol* UNUSED(s), int argc, + t_atom *argv) { int i = x->size; t_float *dummy = x->buf; t_float f=(argc)?atom_getfloat(argv):x->avg; - while (i--) *dummy++=f; + while (i--) { + *dummy++=f; + } x->wp = x->buf; } @@ -67,9 +73,13 @@ static void mavg_float(t_mavg *x, t_float f) t_float *dumb = x->buf; *x->wp++ = f; - if (x->wp == x->buf + x->size) x->wp = x->buf; + if (x->wp == x->buf + x->size) { + x->wp = x->buf; + } - while (i--) dummy += *dumb++; + while (i--) { + dummy += *dumb++; + } x->avg = dummy*x->n_inv; @@ -90,7 +100,9 @@ static void *mavg_new(t_floatarg f) x->n_inv = 1.0f/(t_float)i; dumbuf = x->buf; - while (i--) *dumbuf++=0; + while (i--) { + *dumbuf++=0; + } return (x); } @@ -103,13 +115,14 @@ static void mavg_help(void) void mavg_setup(void) { mavg_class = class_new(gensym("mavg"), (t_newmethod)mavg_new, 0, - sizeof(t_mavg), 0, A_DEFFLOAT, 0); + sizeof(t_mavg), 0, A_DEFFLOAT, 0); class_addfloat(mavg_class, (t_method)mavg_float); class_addmethod(mavg_class, (t_method)mavg_help, gensym("help"), 0); class_addmethod(mavg_class, (t_method)mavg_set, gensym("set"), A_GIMME, 0); - class_addmethod(mavg_class, (t_method)mavg_resize, gensym(""), A_DEFFLOAT, 0); + class_addmethod(mavg_class, (t_method)mavg_resize, gensym(""), A_DEFFLOAT, + 0); zexy_register("mavg"); } diff --git a/src/minmax.c b/src/minmax.c index 8bb003a..4dfb6f9 100644 --- a/src/minmax.c +++ b/src/minmax.c @@ -1,4 +1,4 @@ -/* +/* * minmax :: get minimum and maximum of a list * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -22,8 +22,7 @@ static t_class *minmax_class; -typedef struct _minmax -{ +typedef struct _minmax { t_object x_obj; t_float min; t_float max; @@ -37,19 +36,23 @@ static void minmax_bang(t_minmax *x) outlet_float(x->mino,x->min); } -static void minmax_list(t_minmax *x, t_symbol* UNUSED(s), int argc, t_atom *argv) +static void minmax_list(t_minmax *x, t_symbol* UNUSED(s), int argc, + t_atom *argv) { - if(argc){ + if(argc) { t_float min = atom_getfloat(argv++); t_float max=min; argc--; - - while(argc--){ + + while(argc--) { t_float f = atom_getfloat(argv++); - if (fmax)max=f; + if (fmax) { + max=f; + } } - + x->min=min; x->max=max; } @@ -76,7 +79,7 @@ static void minmax_help(void) void minmax_setup(void) { minmax_class = class_new(gensym("minmax"), (t_newmethod)minmax_new, 0, - sizeof(t_minmax), 0, A_DEFFLOAT, 0); + sizeof(t_minmax), 0, A_DEFFLOAT, 0); class_addlist(minmax_class, (t_method)minmax_list); class_addbang(minmax_class, (t_method)minmax_bang); diff --git a/src/msgfile.c b/src/msgfile.c index ac004c4..c702a6f 100644 --- a/src/msgfile.c +++ b/src/msgfile.c @@ -1,4 +1,4 @@ -/* +/* * msgfile: an improved version of [textfile] * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,18 +7,18 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ -/* +/* this is heavily based on code from [textfile], which is part of pd and written by Miller S. Puckette pd (and thus [textfile]) come with their own license @@ -60,11 +60,10 @@ typedef struct _msglist { t_atom *thislist; void *next; - void *previous; + void *previous; } t_msglist; -typedef struct _msgfile -{ +typedef struct _msgfile { t_object x_obj; /* everything */ t_outlet *x_secondout; /* "done" */ @@ -107,25 +106,27 @@ static int node_wherearewe(t_msgfile *x) cur = cur->next; } - if(cur&&cur->thislist) + if(cur&&cur->thislist) { return counter; + } return -1; } static void write_currentnode(t_msgfile *x, int ac, t_atom *av) { /* append list to the current node list */ - + t_msglist *cur=x->current; t_atom *ap=NULL; - int newsize = 0; + int newsize = 0; - if(!cur || (ac && av && A_SYMBOL==av->a_type && gensym("")==atom_getsymbol(av))){ + if(!cur || (ac && av && A_SYMBOL==av->a_type + && gensym("")==atom_getsymbol(av))) { /* ignoring empty symbols! */ return; } - newsize = cur->n + ac; + newsize = cur->n + ac; ap = (t_atom *)getbytes(newsize * sizeof(t_atom)); memcpy(ap, cur->thislist, cur->n * sizeof(t_atom)); @@ -137,12 +138,12 @@ static void write_currentnode(t_msgfile *x, int ac, t_atom *av) static void delete_currentnode(t_msgfile *x) { - if (x&&x->current){ + if (x&&x->current) { t_msglist *dummy = x->current; t_msglist *nxt=0; t_msglist *prv=0; - if(dummy){ + if(dummy) { nxt=dummy->next; prv=dummy->previous; @@ -161,14 +162,19 @@ static void delete_currentnode(t_msgfile *x) dummy=0; } - if (nxt) nxt->previous = prv; - if (prv) prv->next = nxt; - + if (nxt) { + nxt->previous = prv; + } + if (prv) { + prv->next = nxt; + } + x->current = (nxt)?nxt:prv; - if(x->current) + if(x->current) { x->previous=x->current->previous; - else + } else { x->previous=prv; + } } } @@ -177,11 +183,14 @@ static void delete_emptynodes(t_msgfile *x) { x->current=x->start; x->previous=0; - if (!x->current) return; + if (!x->current) { + return; + } while (x->current && x->current->next) { - if (!x->current->thislist) delete_currentnode(x); - else { + if (!x->current->thislist) { + delete_currentnode(x); + } else { x->previous=x->current; x->current = x->current->next; } @@ -189,7 +198,7 @@ static void delete_emptynodes(t_msgfile *x) } static void add_currentnode(t_msgfile *x) -{ +{ /* add (after the current node) a node at the current position (do not write the listbuf !!!) */ t_msglist *newnode = (t_msglist *)getbytes(sizeof(t_msglist)); t_msglist *prv, *nxt, *cur=x->current; @@ -203,17 +212,23 @@ static void add_currentnode(t_msgfile *x) newnode->next = nxt; newnode->previous = prv; - if (prv) prv->next = newnode; - if (nxt) nxt->previous = newnode; + if (prv) { + prv->next = newnode; + } + if (nxt) { + nxt->previous = newnode; + } x->current = newnode; x->previous=prv; - if(!x->start) /* it's the first line in the buffer */ + if(!x->start) { /* it's the first line in the buffer */ x->start=x->current; + } } static void insert_currentnode(t_msgfile *x) -{ /* insert (add before the current node) a node (do not write a the listbuf !!!) */ +{ + /* insert (add before the current node) a node (do not write a the listbuf !!!) */ t_msglist *newnode; t_msglist *prv, *nxt, *cur = x->current; @@ -231,8 +246,12 @@ static void insert_currentnode(t_msgfile *x) newnode->next = nxt; newnode->previous = prv; - if (prv) prv->next = newnode; - if (nxt) nxt->previous = newnode; + if (prv) { + prv->next = newnode; + } + if (nxt) { + nxt->previous = newnode; + } x->previous=prv; x->current = newnode; @@ -261,25 +280,39 @@ static void delete_region(t_msgfile *x, int start, int stop) dummy = dummy->next; } - if ((stop > counter) || (stop == -1)) stop = counter; - if ((stop+1) && (start > stop)) return; - if (stop == 0) return; + if ((stop > counter) || (stop == -1)) { + stop = counter; + } + if ((stop+1) && (start > stop)) { + return; + } + if (stop == 0) { + return; + } - newwhere = (oldwhere < start)?oldwhere:( (oldwhere < stop)?start:start+(oldwhere-stop)); + newwhere = (oldwhere < start)?oldwhere:( (oldwhere < stop)?start:start+ + (oldwhere-stop)); n = stop - start; msgfile_goto(x, start); - while (n--) delete_currentnode(x); + while (n--) { + delete_currentnode(x); + } - if (newwhere+1) msgfile_goto(x, newwhere); - else msgfile_end(x); + if (newwhere+1) { + msgfile_goto(x, newwhere); + } else { + msgfile_end(x); + } } static int atomcmp(t_atom *this, t_atom *that) { - if (this->a_type != that->a_type) return 1; + if (this->a_type != that->a_type) { + return 1; + } switch (this->a_type) { case A_FLOAT: @@ -325,25 +358,31 @@ static void msgfile_binbuf2listbuf(t_msgfile *x, t_binbuf *bbuf) static void msgfile_rewind(t_msgfile *x) { - // while (x->current && x->current->previous) x->current = x->current->previous; + // while (x->current && x->current->previous) x->current = x->current->previous; x->current = x->start; x->previous=0; } static void msgfile_end(t_msgfile *x) { - if (!x->current) return; + if (!x->current) { + return; + } while (x->current->next) { x->previous= x->current; x->current = x->current->next; } - + } static void msgfile_goto(t_msgfile *x, t_float f) { int i = f; - if (i<0) return; - if (!x->current) return; + if (i<0) { + return; + } + if (!x->current) { + return; + } msgfile_rewind(x); while (i-- && x->current->next) { @@ -358,8 +397,12 @@ static void msgfile_skip(t_msgfile *x, t_float f) t_msglist *dummy = x->start; - if (!f) return; - if (!x->current) return; + if (!f) { + return; + } + if (!x->current) { + return; + } while (dummy->next && dummy!=x->current) { counter++; @@ -367,7 +410,9 @@ static void msgfile_skip(t_msgfile *x, t_float f) } i = counter + f; - if (i<0) i=0; + if (i<0) { + i=0; + } msgfile_goto(x, i); } @@ -388,8 +433,12 @@ static void msgfile_delete(t_msgfile *x, t_symbol *s, int ac, t_atom *av) int pos = atom_getfloat(av); int oldwhere = node_wherearewe(x); - if (pos<0) return; - if (oldwhere > pos) oldwhere--; + if (pos<0) { + return; + } + if (oldwhere > pos) { + oldwhere--; + } msgfile_goto(x, pos); delete_currentnode(x); msgfile_goto(x, oldwhere); @@ -398,13 +447,18 @@ static void msgfile_delete(t_msgfile *x, t_symbol *s, int ac, t_atom *av) int pos2 = atom_getfloat(av); if ((pos1 < pos2) || (pos2 == -1)) { - if (pos2+1) delete_region(x, pos1, pos2+1); - else delete_region(x, pos1, -1); + if (pos2+1) { + delete_region(x, pos1, pos2+1); + } else { + delete_region(x, pos1, -1); + } } else { delete_region(x, pos1+1, -1); delete_region(x, 0, pos2); } - } else delete_currentnode(x); + } else { + delete_currentnode(x); + } } static void msgfile_add(t_msgfile *x, t_symbol *s, int ac, t_atom *av) @@ -417,7 +471,9 @@ static void msgfile_add2(t_msgfile *x, t_symbol *s, int ac, t_atom *av) { msgfile_end(x); if (x->current) { - if(x->current->previous) x->current = x->current->previous; + if(x->current->previous) { + x->current = x->current->previous; + } } else { add_currentnode(x); } @@ -434,11 +490,15 @@ static void msgfile_append(t_msgfile *x, t_symbol *s, int ac, t_atom *av) } static void msgfile_append2(t_msgfile *x, t_symbol *s, int ac, t_atom *av) { - if(!x->current) + if(!x->current) { add_currentnode(x); + } - if (x->current->thislist) write_currentnode(x, ac, av); - else msgfile_append(x, s, ac, av); + if (x->current->thislist) { + write_currentnode(x, ac, av); + } else { + msgfile_append(x, s, ac, av); + } } static void msgfile_insert(t_msgfile *x, t_symbol *s, int ac, t_atom *av) { @@ -450,7 +510,9 @@ static void msgfile_insert(t_msgfile *x, t_symbol *s, int ac, t_atom *av) static void msgfile_insert2(t_msgfile *x, t_symbol *s, int ac, t_atom *av) { t_msglist *cur = x->current; - if ((x->current) && (x->current->previous)) x->current = x->current->previous; + if ((x->current) && (x->current->previous)) { + x->current = x->current->previous; + } write_currentnode(x, ac, av); x->current = cur; } @@ -486,7 +548,8 @@ static void msgfile_flush(t_msgfile *x) static void msgfile_this(t_msgfile *x) { if ((x->current) && (x->current->thislist)) { - outlet_list(x->x_obj.ob_outlet, gensym("list"), x->current->n, x->current->thislist); + outlet_list(x->x_obj.ob_outlet, gensym("list"), x->current->n, + x->current->thislist); } else { outlet_bang(x->x_secondout); } @@ -495,10 +558,14 @@ static void msgfile_next(t_msgfile *x) { if ((x->current) && (x->current->next)) { t_msglist *next = x->current->next; - if (next->thislist) + if (next->thislist) { outlet_list(x->x_obj.ob_outlet, gensym("list"), next->n, next->thislist); - else outlet_bang(x->x_secondout); - } else outlet_bang(x->x_secondout); + } else { + outlet_bang(x->x_secondout); + } + } else { + outlet_bang(x->x_secondout); + } } static void msgfile_prev(t_msgfile *x) { @@ -510,15 +577,19 @@ static void msgfile_prev(t_msgfile *x) prev = x->previous; } if(prev) { - if (prev->thislist) + if (prev->thislist) { outlet_list(x->x_obj.ob_outlet, gensym("list"), prev->n, prev->thislist); - else outlet_bang(x->x_secondout); + } else { + outlet_bang(x->x_secondout); + } - } else outlet_bang(x->x_secondout); + } else { + outlet_bang(x->x_secondout); + } } static void msgfile_bang(t_msgfile *x) -{ +{ if ((x->current) && (x->current->thislist)) { t_msglist*cur=x->current; x->current=cur->next; @@ -540,12 +611,14 @@ static void msgfile_find(t_msgfile *x, t_symbol *s, int ac, t_atom *av) t_atom *that = av; t_atom *this = cur->thislist; - if(0==this){ + if(0==this) { cur=cur->next; continue; } - - if (ac < n) n = ac; + + if (ac < n) { + n = ac; + } while (n-->0) { if ( (strcmp("*", atom_getsymbol(that)->s_name) && atomcmp(that, this)) ) { @@ -564,12 +637,14 @@ static void msgfile_find(t_msgfile *x, t_symbol *s, int ac, t_atom *av) cur=cur->next; } - if(found){ + if(found) { x->current = found; x->previous= found->previous; outlet_float(x->x_secondout, node_wherearewe(x)); - if(found->n && found->thislist) - outlet_list(x->x_obj.ob_outlet, gensym("list"), found->n, found->thislist); + if(found->n && found->thislist) { + outlet_list(x->x_obj.ob_outlet, gensym("list"), found->n, + found->thislist); + } } else { outlet_bang(x->x_secondout); } @@ -577,14 +652,19 @@ static void msgfile_find(t_msgfile *x, t_symbol *s, int ac, t_atom *av) static void msgfile_where(t_msgfile *x) { - if (x->current && x->current->thislist) outlet_float(x->x_secondout, node_wherearewe(x)); - else outlet_bang(x->x_secondout); + if (x->current && x->current->thislist) { + outlet_float(x->x_secondout, node_wherearewe(x)); + } else { + outlet_bang(x->x_secondout); + } } -static void msgfile_sort(t_msgfile *x, t_symbol *s0, t_symbol*s1, t_symbol*r) +static void msgfile_sort(t_msgfile *x, t_symbol *s0, t_symbol*s1, + t_symbol*r) { - post("sorting not implemented yet: '%s', '%s' -> '%s'", s0->s_name, s1->s_name, r->s_name); + post("sorting not implemented yet: '%s', '%s' -> '%s'", s0->s_name, + s1->s_name, r->s_name); #if 0 @@ -626,7 +706,8 @@ static void msgfile_sort(t_msgfile *x, t_symbol *s0, t_symbol*s1, t_symbol*r) /* ********************************** */ /* file I/O */ -static void msgfile_read2(t_msgfile *x, t_symbol *filename, t_symbol *format) +static void msgfile_read2(t_msgfile *x, t_symbol *filename, + t_symbol *format) { int rmode = 0; @@ -649,8 +730,8 @@ static void msgfile_read2(t_msgfile *x, t_symbol *filename, t_symbol *format) #endif fd = open_via_path(dirname, - filename->s_name, "", buf, &bufptr, MAXPDSTRING, 0); - + filename->s_name, "", buf, &bufptr, MAXPDSTRING, 0); + if (fd < 0) { /* open via path failed, fall back */ fd=open(filename->s_name, rmode); @@ -676,7 +757,8 @@ static void msgfile_read2(t_msgfile *x, t_symbol *filename, t_symbol *format) fseek(fil, 0, SEEK_SET); if (!(readbuf = t_getbytes(length))) { - pd_error(x, "msgfile_read: could not reserve %ld bytes to read into", length); + pd_error(x, "msgfile_read: could not reserve %ld bytes to read into", + length); fclose(fil); return; } @@ -687,8 +769,9 @@ static void msgfile_read2(t_msgfile *x, t_symbol *filename, t_symbol *format) mode = CSV_MODE; } else if (gensym("pd")==format) { mode = PD_MODE; - } else if (*format->s_name) + } else if (*format->s_name) { pd_error(x, "msgfile_read: unknown flag: %s", format->s_name); + } switch (mode) { case CR_MODE: @@ -707,7 +790,8 @@ static void msgfile_read2(t_msgfile *x, t_symbol *filename, t_symbol *format) /* read */ if ((readlength = fread(readbuf, sizeof(char), length, fil)) < length) { - pd_error(x, "msgfile_read: unable to read %s: %ld of %ld", filnam, readlength, length); + pd_error(x, "msgfile_read: unable to read %s: %ld of %ld", filnam, + readlength, length); fclose(fil); t_freebytes(readbuf, length); return; @@ -723,22 +807,26 @@ static void msgfile_read2(t_msgfile *x, t_symbol *filename, t_symbol *format) charbinbuflength=2*length+MSGFILE_HEADROOM; charbinbuf=(char*)getbytes(charbinbuflength); - + cbb=charbinbuf; - for(pos=0; pos=charbinbuflength){ - pd_error(x, "msgfile: read error (headroom %d too small!)", MSGFILE_HEADROOM); + if(pos>=charbinbuflength) { + pd_error(x, "msgfile: read error (headroom %d too small!)", + MSGFILE_HEADROOM); goto read_error; break; } if (*bufptr == separator) { *cbb = ' '; } else if (*bufptr==eol) { - *cbb++=';';pos++; + *cbb++=';'; + pos++; *cbb='\n'; } else { *cbb=*bufptr; @@ -753,18 +841,20 @@ static void msgfile_read2(t_msgfile *x, t_symbol *filename, t_symbol *format) binbuf_text(bbuf, charbinbuf, charbinbuflength); msgfile_binbuf2listbuf(x, bbuf); - read_error: +read_error: binbuf_free(bbuf); t_freebytes(readbuf, length); t_freebytes(charbinbuf, charbinbuflength); } -static void msgfile_read(t_msgfile *x, t_symbol *filename, t_symbol *format) +static void msgfile_read(t_msgfile *x, t_symbol *filename, + t_symbol *format) { msgfile_clear(x); msgfile_read2(x, filename, format); } -static void msgfile_write(t_msgfile *x, t_symbol *filename, t_symbol *format) +static void msgfile_write(t_msgfile *x, t_symbol *filename, + t_symbol *format) { char buf[MAXPDSTRING]; t_binbuf *bbuf = binbuf_new(); @@ -784,7 +874,7 @@ static void msgfile_write(t_msgfile *x, t_symbol *filename, t_symbol *format) binbuf_addsemi(bbuf); cur = cur->next; } - + canvas_makefilename(x->x_canvas, filename->s_name, buf, MAXPDSTRING); @@ -799,7 +889,7 @@ static void msgfile_write(t_msgfile *x, t_symbol *filename, t_symbol *format) pd_error(x, "msgfile_write: ignoring unknown flag: %s", format->s_name); } } - + switch (mode) { case CR_MODE: separator = ' '; @@ -814,19 +904,20 @@ static void msgfile_write(t_msgfile *x, t_symbol *filename, t_symbol *format) eol = ';'; break; } - + binbuf_gettext(bbuf, &mytext, &textlen); dumtext = mytext; i = textlen; while(i--) { - if (*dumtext==' ') + if (*dumtext==' ') { *dumtext=separator; - else if ((*dumtext==';') && (dumtext[1]=='\n')) + } else if ((*dumtext==';') && (dumtext[1]=='\n')) { *dumtext = eol; + } dumtext++; } - + /* open */ sys_bashfilename(filename->s_name, filnam); if (!(f = fopen(filnam, "w"))) { @@ -838,7 +929,9 @@ static void msgfile_write(t_msgfile *x, t_symbol *filename, t_symbol *format) } } /* close */ - if (f) fclose(f); + if (f) { + fclose(f); + } binbuf_free(bbuf); } @@ -916,10 +1009,13 @@ static void *msgfile_new(t_symbol *s, int argc, t_atom *argv) if ((argc==1) && (argv->a_type == A_SYMBOL)) { t_symbol*mode=atom_getsymbol(argv); - if (gensym("cr") == mode) x->mode = CR_MODE; - else if (gensym("csv")== mode) x->mode = CSV_MODE; - else if (gensym("pd") == mode) x->mode = PD_MODE; - else { + if (gensym("cr") == mode) { + x->mode = CR_MODE; + } else if (gensym("csv")== mode) { + x->mode = CSV_MODE; + } else if (gensym("pd") == mode) { + x->mode = PD_MODE; + } else { pd_error(x, "msgfile: unknown argument %s", argv->a_w.w_symbol->s_name); } } @@ -938,44 +1034,68 @@ void msgfile_setup(void) { msgfile_class = class_new(gensym("msgfile"), (t_newmethod)msgfile_new, (t_method)msgfile_free, sizeof(t_msgfile), 0, A_GIMME, 0); - class_addmethod(msgfile_class, (t_method)msgfile_goto, gensym("goto"), A_DEFFLOAT, 0); - class_addmethod(msgfile_class, (t_method)msgfile_rewind, gensym("rewind"), 0); - class_addmethod(msgfile_class, (t_method)msgfile_rewind, gensym("begin"), 0); + class_addmethod(msgfile_class, (t_method)msgfile_goto, gensym("goto"), + A_DEFFLOAT, 0); + class_addmethod(msgfile_class, (t_method)msgfile_rewind, gensym("rewind"), + 0); + class_addmethod(msgfile_class, (t_method)msgfile_rewind, gensym("begin"), + 0); class_addmethod(msgfile_class, (t_method)msgfile_end, gensym("end"), 0); - class_addmethod(msgfile_class, (t_method)msgfile_next, gensym("next"), A_DEFFLOAT, 0); - class_addmethod(msgfile_class, (t_method)msgfile_prev, gensym("prev"), A_DEFFLOAT, 0); - - class_addmethod(msgfile_class, (t_method)msgfile_skip, gensym("skip"), A_DEFFLOAT, 0); - - class_addmethod(msgfile_class, (t_method)msgfile_set, gensym("set"), A_GIMME, 0); - - class_addmethod(msgfile_class, (t_method)msgfile_clear, gensym("clear"), 0); - class_addmethod(msgfile_class, (t_method)msgfile_delete, gensym("delete"), A_GIMME, 0); - - class_addmethod(msgfile_class, (t_method)msgfile_add, gensym("add"), A_GIMME, 0); - class_addmethod(msgfile_class, (t_method)msgfile_add2, gensym("add2"), A_GIMME, 0); - class_addmethod(msgfile_class, (t_method)msgfile_append, gensym("append"), A_GIMME, 0); - class_addmethod(msgfile_class, (t_method)msgfile_append2, gensym("append2"), A_GIMME, 0); - class_addmethod(msgfile_class, (t_method)msgfile_insert, gensym("insert"), A_GIMME, 0); - class_addmethod(msgfile_class, (t_method)msgfile_insert2, gensym("insert2"), A_GIMME, 0); - - class_addmethod(msgfile_class, (t_method)msgfile_replace, gensym("replace"), A_GIMME, 0); - - class_addmethod(msgfile_class, (t_method)msgfile_find, gensym("find"), A_GIMME, 0); - - class_addmethod(msgfile_class, (t_method)msgfile_read, gensym("read"), A_SYMBOL, A_DEFSYM, 0); - class_addmethod(msgfile_class, (t_method)msgfile_read2, gensym("read2"), A_SYMBOL, A_DEFSYM, 0); - class_addmethod(msgfile_class, (t_method)msgfile_write, gensym("write"), A_SYMBOL, A_DEFSYM, 0); - class_addmethod(msgfile_class, (t_method)msgfile_print, gensym("print"), 0); - class_addmethod(msgfile_class, (t_method)msgfile_flush, gensym("flush"), 0); + class_addmethod(msgfile_class, (t_method)msgfile_next, gensym("next"), + A_DEFFLOAT, 0); + class_addmethod(msgfile_class, (t_method)msgfile_prev, gensym("prev"), + A_DEFFLOAT, 0); + + class_addmethod(msgfile_class, (t_method)msgfile_skip, gensym("skip"), + A_DEFFLOAT, 0); + + class_addmethod(msgfile_class, (t_method)msgfile_set, gensym("set"), + A_GIMME, 0); + + class_addmethod(msgfile_class, (t_method)msgfile_clear, gensym("clear"), + 0); + class_addmethod(msgfile_class, (t_method)msgfile_delete, gensym("delete"), + A_GIMME, 0); + + class_addmethod(msgfile_class, (t_method)msgfile_add, gensym("add"), + A_GIMME, 0); + class_addmethod(msgfile_class, (t_method)msgfile_add2, gensym("add2"), + A_GIMME, 0); + class_addmethod(msgfile_class, (t_method)msgfile_append, gensym("append"), + A_GIMME, 0); + class_addmethod(msgfile_class, (t_method)msgfile_append2, + gensym("append2"), A_GIMME, 0); + class_addmethod(msgfile_class, (t_method)msgfile_insert, gensym("insert"), + A_GIMME, 0); + class_addmethod(msgfile_class, (t_method)msgfile_insert2, + gensym("insert2"), A_GIMME, 0); + + class_addmethod(msgfile_class, (t_method)msgfile_replace, + gensym("replace"), A_GIMME, 0); + + class_addmethod(msgfile_class, (t_method)msgfile_find, gensym("find"), + A_GIMME, 0); + + class_addmethod(msgfile_class, (t_method)msgfile_read, gensym("read"), + A_SYMBOL, A_DEFSYM, 0); + class_addmethod(msgfile_class, (t_method)msgfile_read2, gensym("read2"), + A_SYMBOL, A_DEFSYM, 0); + class_addmethod(msgfile_class, (t_method)msgfile_write, gensym("write"), + A_SYMBOL, A_DEFSYM, 0); + class_addmethod(msgfile_class, (t_method)msgfile_print, gensym("print"), + 0); + class_addmethod(msgfile_class, (t_method)msgfile_flush, gensym("flush"), + 0); class_addbang(msgfile_class, msgfile_bang); class_addmethod(msgfile_class, (t_method)msgfile_this, gensym("this"), 0); - class_addmethod(msgfile_class, (t_method)msgfile_where, gensym("where"), 0); + class_addmethod(msgfile_class, (t_method)msgfile_where, gensym("where"), + 0); - class_addmethod(msgfile_class, (t_method)msgfile_sort, gensym("sort"), A_SYMBOL, A_SYMBOL, A_SYMBOL, 0); + class_addmethod(msgfile_class, (t_method)msgfile_sort, gensym("sort"), + A_SYMBOL, A_SYMBOL, A_SYMBOL, 0); class_addmethod(msgfile_class, (t_method)msgfile_help, gensym("help"), 0); diff --git a/src/multiline~.c b/src/multiline~.c index 6dc7f0d..5d53694 100644 --- a/src/multiline~.c +++ b/src/multiline~.c @@ -1,4 +1,4 @@ -/* +/* * multiline~: interpolating signal multiplier * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -63,30 +63,41 @@ typedef struct _mline { /* the message thing */ -static void mline_list(t_mline *x, t_symbol* UNUSED(s), int argc, t_atom *argv) +static void mline_list(t_mline *x, t_symbol* UNUSED(s), int argc, + t_atom *argv) { - if (argc>x->sigNUM)x->time=atom_getfloat(argv+argc-1); + if (argc>x->sigNUM) { + x->time=atom_getfloat(argv+argc-1); + } if (x->time <= 0) { if (argc==1) { t_float f = atom_getfloat(argv); int i=x->sigNUM; - while(i--)x->target[i]=x->value[i]=f; + while(i--) { + x->target[i]=x->value[i]=f; + } } else { int offset = (argcsigNUM)?x->sigNUM-argc:0; int i=offset?argc:x->sigNUM; - while(i--)x->target[i+offset]=x->value[i+offset]=atom_getfloat(argv++); + while(i--) { + x->target[i+offset]=x->value[i+offset]=atom_getfloat(argv++); + } } x->ticksleft=x->retarget=x->time=0; } else { if (argc==1) { int i = x->sigNUM; t_float f = atom_getfloat(argv); - for(i=0;isigNUM;i++)x->target[i]=f; + for(i=0; isigNUM; i++) { + x->target[i]=f; + } } else { int offset = (argcsigNUM)?x->sigNUM-argc:0; int i=offset?argc:x->sigNUM; - while(i--)x->target[i+offset]=atom_getfloat(argv++); + while(i--) { + x->target[i+offset]=atom_getfloat(argv++); + } } x->retarget = 1; } @@ -95,7 +106,9 @@ static void mline_list(t_mline *x, t_symbol* UNUSED(s), int argc, t_atom *argv) static void mline_stop(t_mline *x) { int i = x->sigNUM; - while (i--) x->target[i] = x->value[i]; + while (i--) { + x->target[i] = x->value[i]; + } x->ticksleft = x->retarget = 0; } @@ -118,7 +131,9 @@ static t_int *mline_perform(t_int *w) if (x->retarget) { int nticks = x->time * x->msec2tick; - if (!nticks) nticks = 1; + if (!nticks) { + nticks = 1; + } x->ticksleft = nticks; x->retarget = 0; @@ -129,8 +144,10 @@ static t_int *mline_perform(t_int *w) t_sample oneovernos = 1./(x->ticksleft*n); int i=sigNUM; - while(i--)*inc++=(*tgt++-*val++)*oneovernos; - + while(i--) { + *inc++=(*tgt++-*val++)*oneovernos; + } + n=-1; while (n++ticksleft) { val = value; tgt = target; i = sigNUM; - while(i--)*val++=*tgt++; + while(i--) { + *val++=*tgt++; + } } - + } else { /* no ticks left */ int i = sigNUM; while (n--) { i = sigNUM; val = value; buf = sigBUF; - while (i--)*buf++=in[i][n]**val++; + while (i--) { + *buf++=in[i][n]**val++; + } i = sigNUM; buf = sigBUF; - while (i--)out[i][n]=*buf++; + while (i--) { + out[i][n]=*buf++; + } } } @@ -173,11 +200,15 @@ static void mline_dsp(t_mline *x, t_signal **sp) { int i = x->sigNUM, n = 0; t_sample **dummy = x->sigIN; - while(i--)*dummy++=sp[n++]->s_vec; + while(i--) { + *dummy++=sp[n++]->s_vec; + } i = x->sigNUM; dummy =x->sigOUT; - while(i--)*dummy++=sp[n++]->s_vec; + while(i--) { + *dummy++=sp[n++]->s_vec; + } x->msec2tick = sp[0]->s_sr / (1000.f * sp[0]->s_n); dsp_add(mline_perform, 2, x, sp[0]->s_n); @@ -208,10 +239,14 @@ static void *mline_new(t_symbol* UNUSED(s), int argc, t_atom *argv) x->time = 0; } else { x->time = atom_getfloat(argv+argc-1); - if (x->time < 0) x->time = 0; + if (x->time < 0) { + x->time = 0; + } argc--; - if (!argc) argc = 1; + if (!argc) { + argc = 1; + } } x->sigNUM = argc; @@ -227,7 +262,7 @@ static void *mline_new(t_symbol* UNUSED(s), int argc, t_atom *argv) inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("")); floatinlet_new(&x->x_obj, &x->time); - + x->sigIN = (t_sample **)getbytes(x->sigNUM * sizeof(t_sample **)); x->sigOUT = (t_sample **)getbytes(x->sigNUM * sizeof(t_sample **)); x->sigBUF = (t_sample *)getbytes(x->sigNUM * sizeof(t_sample *)); @@ -257,8 +292,9 @@ static void mline_help(t_mline*x) void multiline_tilde_setup(void) { - mline_class = class_new(gensym("multiline~"), (t_newmethod)mline_new, (t_method)mline_free, - sizeof(t_mline), 0, A_GIMME, 0); + mline_class = class_new(gensym("multiline~"), (t_newmethod)mline_new, + (t_method)mline_free, + sizeof(t_mline), 0, A_GIMME, 0); class_addmethod(mline_class, (t_method)mline_dsp, gensym("dsp"), 0); class_addmethod(mline_class, nullfn, gensym("signal"), 0); @@ -266,6 +302,7 @@ void multiline_tilde_setup(void) class_addmethod(mline_class, (t_method)mline_list, gensym(""), A_GIMME, 0); class_addmethod(mline_class, (t_method)mline_stop, gensym("stop"), 0); - class_addmethod (mline_class, (t_method)mline_help, gensym("help"), A_NULL); + class_addmethod (mline_class, (t_method)mline_help, gensym("help"), + A_NULL); zexy_register("multiline_tilde"); } diff --git a/src/multiplex.c b/src/multiplex.c index 2b05d21..24faeea 100644 --- a/src/multiplex.c +++ b/src/multiplex.c @@ -1,4 +1,4 @@ -/* +/* * mulitplex : multiplex a specified input to the output * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -46,8 +46,7 @@ static t_class *mux_class; static t_class *muxproxy_class; -typedef struct _mux -{ +typedef struct _mux { t_object x_obj; struct _muxproxy **x_proxy; @@ -57,8 +56,7 @@ typedef struct _mux } t_mux; -typedef struct _muxproxy -{ +typedef struct _muxproxy { t_pd p_pd; t_mux *p_master; int id; @@ -69,11 +67,13 @@ static void mux_select(t_mux *x, t_float f) x->i_selected=f; } -static void mux_anything(t_muxproxy *y, t_symbol *s, int argc, t_atom *argv) +static void mux_anything(t_muxproxy *y, t_symbol *s, int argc, + t_atom *argv) { t_mux*x=y->p_master; - if(y->id==x->i_selected) + if(y->id==x->i_selected) { outlet_anything(x->x_obj.ob_outlet, s, argc, argv); + } } static void *mux_new(t_symbol *s, int argc, t_atom *argv) @@ -99,42 +99,44 @@ static void *mux_new(t_symbol *s, int argc, t_atom *argv) return (x); } -static void mux_free(t_mux*x){ +static void mux_free(t_mux*x) +{ const int count = x->i_count; - if(x->in && x->x_proxy){ + if(x->in && x->x_proxy) { int n=0; - for(n=0; nin[n]){ + for(n=0; nin[n]) { inlet_free(x->in[n]); } x->in[n]=0; - if(x->x_proxy[n]){ + if(x->x_proxy[n]) { t_muxproxy *y=x->x_proxy[n]; y->p_master=0; y->id=0; - pd_free(&y->p_pd); + pd_free(&y->p_pd); } - x->x_proxy[n]=0; + x->x_proxy[n]=0; } freebytes(x->in, x->i_count * sizeof(t_inlet *)); freebytes(x->x_proxy, x->i_count * sizeof(t_muxproxy*)); } - + /* pd_free(&y->p_pd); */ } void multiplex_setup(void) { mux_class = class_new(gensym("multiplex"), (t_newmethod)mux_new, - (t_method)mux_free, sizeof(t_mux), CLASS_NOINLET, A_GIMME, 0); + (t_method)mux_free, sizeof(t_mux), CLASS_NOINLET, A_GIMME, 0); class_addcreator((t_newmethod)mux_new, gensym("mux"), A_GIMME, 0); - - class_addmethod (mux_class, (t_method)mux_select, gensym(""), A_DEFFLOAT, 0); + + class_addmethod (mux_class, (t_method)mux_select, gensym(""), A_DEFFLOAT, + 0); muxproxy_class = class_new(0, 0, 0, - sizeof(t_muxproxy), - CLASS_PD | CLASS_NOINLET, 0); + sizeof(t_muxproxy), + CLASS_PD | CLASS_NOINLET, 0); class_addanything(muxproxy_class, mux_anything); diff --git a/src/multiplex~.c b/src/multiplex~.c index 82d76d5..3cbf500 100644 --- a/src/multiplex~.c +++ b/src/multiplex~.c @@ -1,5 +1,5 @@ -/* - * mux~ : multiplex a specified signal to the output +/* + * mux~ : multiplex a specified signal to the output * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) * @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -32,10 +32,11 @@ typedef struct _mux { static void mux_tilde_input(t_mux *x, t_floatarg f) { - if ((f>=0)&&(fn_in)){ + if ((f>=0)&&(fn_in)) { x->input=f; - } else + } else { error("multiplex~: %d is channel out of range (0..%d)", (int)f, x->n_in); + } } @@ -44,10 +45,12 @@ static t_int *mux_tilde_perform(t_int *w) t_mux *x = (t_mux *)(w[1]); t_sample *out = (t_sample *)(w[2]); int n = (int)(w[3]); - + t_sample *in = x->in[x->input]; - while(n--)*out++=*in++; + while(n--) { + *out++=*in++; + } return (w+4); } @@ -57,7 +60,9 @@ static void mux_tilde_dsp(t_mux *x, t_signal **sp) int n = 0; t_sample **dummy=x->in; - for(n=0;nn_in;n++)*dummy++=sp[n]->s_vec; + for(n=0; nn_in; n++) { + *dummy++=sp[n]->s_vec; + } dsp_add(mux_tilde_perform, 3, x, sp[n]->s_vec, sp[0]->s_n); } @@ -75,20 +80,27 @@ static void mux_tilde_free(t_mux *x) freebytes(x->in, x->n_in * sizeof(t_sample *)); } -static void *mux_tilde_new(t_symbol* UNUSED(s), int argc, t_atom* UNUSED(argv)) +static void *mux_tilde_new(t_symbol* UNUSED(s), int argc, + t_atom* UNUSED(argv)) { t_mux *x = (t_mux *)pd_new(mux_tilde_class); int i; - if (!argc)argc=2; + if (!argc) { + argc=2; + } x->n_in=argc; x->input=0; argc--; - while(argc--)inlet_new(&x->x_obj,&x->x_obj.ob_pd,gensym("signal"),gensym("signal")); + while(argc--) { + inlet_new(&x->x_obj,&x->x_obj.ob_pd,gensym("signal"),gensym("signal")); + } x->in = (t_sample **)getbytes(x->n_in * sizeof(t_sample *)); i=x->n_in; - while(i--)x->in[i]=0; + while(i--) { + x->in[i]=0; + } outlet_new(&x->x_obj, gensym("signal")); @@ -97,14 +109,18 @@ static void *mux_tilde_new(t_symbol* UNUSED(s), int argc, t_atom* UNUSED(argv)) void multiplex_tilde_setup(void) { - mux_tilde_class = class_new(gensym("multiplex~"), (t_newmethod)mux_tilde_new, (t_method)mux_tilde_free, sizeof(t_mux), 0, A_GIMME, 0); + mux_tilde_class = class_new(gensym("multiplex~"), + (t_newmethod)mux_tilde_new, (t_method)mux_tilde_free, sizeof(t_mux), 0, + A_GIMME, 0); class_addcreator((t_newmethod)mux_tilde_new, gensym("mux~"), A_GIMME, 0); class_addfloat(mux_tilde_class, mux_tilde_input); - class_addmethod(mux_tilde_class, (t_method)mux_tilde_dsp, gensym("dsp"), 0); + class_addmethod(mux_tilde_class, (t_method)mux_tilde_dsp, gensym("dsp"), + 0); class_addmethod(mux_tilde_class, nullfn, gensym("signal"), 0); - class_addmethod(mux_tilde_class, (t_method)mux_tilde_helper, gensym("help"), 0); + class_addmethod(mux_tilde_class, (t_method)mux_tilde_helper, + gensym("help"), 0); zexy_register("multiplex~"); } void mux_tilde_setup(void) diff --git a/src/multireceive.c b/src/multireceive.c index cfb65fd..77c4707 100644 --- a/src/multireceive.c +++ b/src/multireceive.c @@ -1,4 +1,4 @@ -/* +/* * multireceive: receive messages for various receive-names * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -26,40 +26,39 @@ static t_class *multireceive_class=NULL; static t_class *multireceive_proxy_class=NULL; -typedef struct _symlist -{ +typedef struct _symlist { t_symbol*s; struct _symlist*next; } t_symlist; -typedef struct _multireceive_proxy -{ +typedef struct _multireceive_proxy { t_object x_obj; struct _multireceive*x_parent; } t_multireceive_proxy; -typedef struct _multireceive -{ +typedef struct _multireceive { t_object x_obj; t_multireceive_proxy*x_proxy; t_symlist*x_symlist; t_outlet *x_out; } t_multireceive; -static void multireceive_any(t_multireceive_proxy *x, t_symbol*s, int argc, t_atom*argv) +static void multireceive_any(t_multireceive_proxy *x, t_symbol*s, int argc, + t_atom*argv) { outlet_anything(x->x_parent->x_out, s, argc, argv); } -static void multireceive_add(t_multireceive *x, t_symbol*s) { +static void multireceive_add(t_multireceive *x, t_symbol*s) +{ t_symlist*sl=x->x_symlist; t_symlist*element=NULL; if(sl) { while(sl->next) { if(s==sl->s) { - // already bound to this symbol - return; + // already bound to this symbol + return; } sl=sl->next; } @@ -69,7 +68,7 @@ static void multireceive_add(t_multireceive *x, t_symbol*s) { element->s=s; element->next=NULL; pd_bind(&x->x_proxy->x_obj.ob_pd, s); - + if(sl) { sl->next=element; } else { @@ -77,7 +76,8 @@ static void multireceive_add(t_multireceive *x, t_symbol*s) { } } -static void multireceive_clear(t_multireceive *x) { +static void multireceive_clear(t_multireceive *x) +{ t_symlist*sl=x->x_symlist; t_symlist*current=NULL; while(sl) { @@ -94,10 +94,11 @@ static void multireceive_clear(t_multireceive *x) { } -static void multireceive_set(t_multireceive *x, t_symbol*s, int argc, t_atom*argv) +static void multireceive_set(t_multireceive *x, t_symbol*s, int argc, + t_atom*argv) { multireceive_clear(x); - + while(argc-->0) { t_symbol*s=atom_getsymbol(argv); if(A_SYMBOL==argv->a_type) { @@ -120,40 +121,41 @@ static void multireceive_free(t_multireceive *x) static void *multireceive_new(t_symbol *s, int argc, t_atom *argv) { - t_multireceive *x = (t_multireceive *)pd_new(multireceive_class); - x->x_proxy=(t_multireceive_proxy*)pd_new(multireceive_proxy_class); - x->x_proxy->x_parent=x; - x->x_symlist=NULL; - x->x_out = outlet_new(&x->x_obj, 0); - - multireceive_set(x, 0, argc, argv); - return (x); + t_multireceive *x = (t_multireceive *)pd_new(multireceive_class); + x->x_proxy=(t_multireceive_proxy*)pd_new(multireceive_proxy_class); + x->x_proxy->x_parent=x; + x->x_symlist=NULL; + x->x_out = outlet_new(&x->x_obj, 0); + + multireceive_set(x, 0, argc, argv); + return (x); } void multireceive_setup(void) { - multireceive_class = class_new(gensym("multireceive"), - (t_newmethod)multireceive_new, - (t_method)multireceive_free, - sizeof(t_multireceive), - 0, - A_GIMME, 0); - class_addmethod(multireceive_class, - (t_method)multireceive_set, - gensym("set"), - A_GIMME, 0); - - class_addmethod(multireceive_class, - (t_method)multireceive_add, - gensym("add"), - A_SYMBOL, 0); - - multireceive_proxy_class = class_new(gensym("multireceive proxy "__DATE__""__TIME__""), - 0, 0, - sizeof(t_multireceive_proxy), - CLASS_PD | CLASS_NOINLET, 0); - - class_addanything(multireceive_proxy_class, multireceive_any); - - zexy_register("multireceive"); + multireceive_class = class_new(gensym("multireceive"), + (t_newmethod)multireceive_new, + (t_method)multireceive_free, + sizeof(t_multireceive), + 0, + A_GIMME, 0); + class_addmethod(multireceive_class, + (t_method)multireceive_set, + gensym("set"), + A_GIMME, 0); + + class_addmethod(multireceive_class, + (t_method)multireceive_add, + gensym("add"), + A_SYMBOL, 0); + + multireceive_proxy_class = class_new( + gensym("multireceive proxy "__DATE__""__TIME__""), + 0, 0, + sizeof(t_multireceive_proxy), + CLASS_PD | CLASS_NOINLET, 0); + + class_addanything(multireceive_proxy_class, multireceive_any); + + zexy_register("multireceive"); } diff --git a/src/niagara.c b/src/niagara.c index ae2c9bb..ccedb42 100644 --- a/src/niagara.c +++ b/src/niagara.c @@ -1,4 +1,4 @@ -/* +/* * niagara: split a list into 2 (use [list split] instead) * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -30,8 +30,7 @@ static t_class *niagara_class; -typedef struct _niagara -{ +typedef struct _niagara { t_object x_obj; t_float rock; t_outlet *left, *right; @@ -50,8 +49,12 @@ static void niagara_list(t_niagara *x, t_symbol *s, int argc, t_atom *argv) n_r = argc - n_l; ap_r = &argv[n_l]; - if (n_r) outlet_list(x->right, s, n_r, ap_r); - if (n_l) outlet_list(x->left, s, n_l, ap_l); + if (n_r) { + outlet_list(x->right, s, n_r, ap_r); + } + if (n_l) { + outlet_list(x->left, s, n_l, ap_l); + } } static void niagara_any(t_niagara *x, t_symbol *s, int argc, t_atom *argv) @@ -71,8 +74,9 @@ static void niagara_any(t_niagara *x, t_symbol *s, int argc, t_atom *argv) if (n_r) { s_r = 0; - if (ap_r->a_type == A_FLOAT) s_r = gensym("list"); - else { + if (ap_r->a_type == A_FLOAT) { + s_r = gensym("list"); + } else { s_r = atom_getsymbol(ap_r); ap_r++; n_r--; @@ -80,7 +84,9 @@ static void niagara_any(t_niagara *x, t_symbol *s, int argc, t_atom *argv) outlet_anything(x->right, s_r, n_r, ap_r); } - if (n_l+1 ) outlet_anything(x->left, s_l, n_l, ap_l); + if (n_l+1 ) { + outlet_anything(x->left, s_l, n_l, ap_l); + } } static void *niagara_new(t_floatarg f) @@ -99,9 +105,9 @@ static void *niagara_new(t_floatarg f) void niagara_setup(void) { - niagara_class = class_new(gensym("niagara"), (t_newmethod)niagara_new, - 0, sizeof(t_niagara), 0, A_DEFFLOAT, 0); - + niagara_class = class_new(gensym("niagara"), (t_newmethod)niagara_new, + 0, sizeof(t_niagara), 0, A_DEFFLOAT, 0); + class_addlist (niagara_class, niagara_list); class_addanything(niagara_class, niagara_any); diff --git a/src/noish~.c b/src/noish~.c index 8d5c875..b4b7829 100644 --- a/src/noish~.c +++ b/src/noish~.c @@ -1,4 +1,4 @@ -/* +/* * noish~: bandlimited noise generator * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -21,11 +21,11 @@ /* 30041999 - two bandlimited noise gnerators based on DODGE/JERSE "computer music" c3.9 : RANDI & RANDH - + two bandlimited noise gnerators based on DODGE/JERSE "computer music" c3.9 : RANDI & RANDH + I do not care for copyrights - (all in all, the used noise~-code (in fact, the pseude-random-code) is from Miller Puckette - and I made only very few modifications so look out for the LICENSE.TXT delivered with + (all in all, the used noise~-code (in fact, the pseude-random-code) is from Miller Puckette + and I made only very few modifications so look out for the LICENSE.TXT delivered with puredata for further (c)-information forum für umläute 1999 @@ -41,13 +41,12 @@ /* general */ -typedef struct _nois -{ +typedef struct _nois { t_object x_obj; int val; t_sample current; t_sample decrement; - t_sample updater; + t_sample updater; t_sample to_go; } t_nois; @@ -55,10 +54,9 @@ typedef struct _nois static void set_freq(t_nois *x, t_floatarg freq) { x->updater = (freq > 0) ? sys_getsr() / freq : 1; - if (x->updater < 1) - { - x->updater = 1; - } + if (x->updater < 1) { + x->updater = 1; + } x->to_go = 0; } @@ -68,7 +66,7 @@ static void set_noisseed(t_nois *x, t_floatarg seed) x->val = seed; } -/* ------------------------ noish~ ----------------------------- */ +/* ------------------------ noish~ ----------------------------- */ static t_class *noish_class; @@ -77,69 +75,61 @@ static t_int *noish_perform(t_int *w) t_nois *x = (t_nois *)(w[1]); t_sample *out = (t_sample *)(w[2]); int n = (int)(w[3]); - + int *vp = (int *)(&x->val); int i_value = *vp; t_sample f_value = ((t_sample)((i_value & 0x7fffffff) - 0x40000000)) * - (t_sample)(1.0 / 0x40000000); + (t_sample)(1.0 / 0x40000000); t_sample all_to_go = x->updater; t_sample still_to_go = x->to_go; - if (all_to_go == 1) - { /* this is "pure white" noise, so we have to calculate each sample */ - while (n--) - { - i_value *= 435898247; - i_value += 382842987; - *out++ = ((t_sample)((i_value & 0x7fffffff) - 0x40000000)) * (t_sample)(1.0 / 0x40000000); - } + if (all_to_go == 1) { + /* this is "pure white" noise, so we have to calculate each sample */ + while (n--) { + i_value *= 435898247; + i_value += 382842987; + *out++ = ((t_sample)((i_value & 0x7fffffff) - 0x40000000)) * (t_sample)( + 1.0 / 0x40000000); + } + } else if (n < still_to_go) { + /* signal won't change for the next 64 samples */ + still_to_go -= n; + while (n--) { + *out++ = f_value; + } + } else if (all_to_go + still_to_go > n) { + /* only one update calculation necessary for 64 samples !!! */ + while (still_to_go-- > 0) { + n--; + *out++ = f_value; + } + + still_to_go += all_to_go + 1; + + i_value *= 435898247; + i_value += 382842987; + f_value = ( (t_sample)((i_value & 0x7fffffff) - 0x40000000) ) * (t_sample)( + 1.0 / 0x40000000); + + while (n--) { + still_to_go--; + *out++ = f_value; } - else - if (n < still_to_go) - { /* signal won't change for the next 64 samples */ - still_to_go -= n; - while (n--) - { - *out++ = f_value; - } + } else { + /* anything else */ + while (n--) { + if (still_to_go-- <= 0) { /* update only if all time has elapsed */ + still_to_go += all_to_go; + + i_value *= 435898247; + i_value += 382842987; + + f_value = ( (t_sample)((i_value & 0x7fffffff) - 0x40000000) ) * (t_sample)( + 1.0 / 0x40000000); } - else - if (all_to_go + still_to_go > n) - { /* only one update calculation necessary for 64 samples !!! */ - while (still_to_go-- > 0) - { - n--; - *out++ = f_value; - } - - still_to_go += all_to_go + 1; - - i_value *= 435898247; - i_value += 382842987; - f_value = ( (t_sample)((i_value & 0x7fffffff) - 0x40000000) ) * (t_sample)(1.0 / 0x40000000); - - while (n--) - { - still_to_go--; - *out++ = f_value; - } - } - else - { /* anything else */ - while (n--) - { - if (still_to_go-- <= 0) /* update only if all time has elapsed */ - { - still_to_go += all_to_go; - - i_value *= 435898247; - i_value += 382842987; - - f_value = ( (t_sample)((i_value & 0x7fffffff) - 0x40000000) ) * (t_sample)(1.0 / 0x40000000); - } - *out++ = f_value; - } - } + *out++ = f_value; + } + } *vp = i_value; @@ -182,12 +172,14 @@ static void *noish_new(t_floatarg f) void noish_tilde_setup(void) { - noish_class = class_new(gensym("noish~"), (t_newmethod)noish_new, 0, sizeof(t_nois), 0, A_DEFFLOAT, 0); + noish_class = class_new(gensym("noish~"), (t_newmethod)noish_new, 0, + sizeof(t_nois), 0, A_DEFFLOAT, 0); class_addfloat(noish_class, set_freq); class_addmethod(noish_class, (t_method)noish_dsp, gensym("dsp"), 0); - class_addmethod(noish_class, (t_method)set_noisseed, gensym("seed"), A_FLOAT, 0); + class_addmethod(noish_class, (t_method)set_noisseed, gensym("seed"), + A_FLOAT, 0); class_addmethod(noish_class, (t_method)noish_helper, gensym("help"), 0); zexy_register("noish~"); diff --git a/src/noisi~.c b/src/noisi~.c index b62d5d3..8577ac9 100644 --- a/src/noisi~.c +++ b/src/noisi~.c @@ -1,4 +1,4 @@ -/* +/* * noisi~: bandlimited noise generator * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -20,11 +20,11 @@ /* 30041999 - two bandlimited noise gnerators based on DODGE/JERSE "computer music" c3.9 : RANDI & RANDH - + two bandlimited noise gnerators based on DODGE/JERSE "computer music" c3.9 : RANDI & RANDH + I do not care for copyrights - (all in all, the used noise~-code (in fact, the pseude-random-code) is from Miller Puckette - and I made only very few modifications so look out for the LICENSE.TXT delivered with + (all in all, the used noise~-code (in fact, the pseude-random-code) is from Miller Puckette + and I made only very few modifications so look out for the LICENSE.TXT delivered with puredata for further (c)-information forum für umläute 1999 @@ -40,13 +40,12 @@ /* general */ -typedef struct _nois -{ +typedef struct _nois { t_object x_obj; int val; t_sample current; t_sample decrement; - t_sample updater; + t_sample updater; t_sample to_go; } t_nois; @@ -54,10 +53,9 @@ typedef struct _nois static void set_noisfreq(t_nois *x, t_floatarg freq) { x->updater = (freq > 0) ? sys_getsr() / freq : 1; - if (x->updater < 1) - { - x->updater = 1; - } + if (x->updater < 1) { + x->updater = 1; + } x->to_go = 0; } @@ -69,20 +67,24 @@ static void set_noisseed(t_nois *x, t_floatarg seed) -/* ------------------------ noisi~ ----------------------------- */ +/* ------------------------ noisi~ ----------------------------- */ static t_class *noisi_class; -static inline t_sample int2sample(int i) { - return ((t_sample)(i & 0x7fffffff) - 0x40000000) * (t_sample)(1.0 / 0x40000000); +static inline t_sample int2sample(int i) +{ + return ((t_sample)(i & 0x7fffffff) - 0x40000000) * (t_sample)( + 1.0 / 0x40000000); } -static inline int update_intNoise(int i) { +static inline int update_intNoise(int i) +{ i *= 435898247; i += 382842987; return i; } -static t_int *noisi_perform(t_int *w){ +static t_int *noisi_perform(t_int *w) +{ t_nois *x = (t_nois *)(w[1]); t_sample *out = (t_sample *)(w[2]); int n = (int)(w[3]); @@ -94,18 +96,18 @@ static t_int *noisi_perform(t_int *w){ t_sample still_to_go = x->to_go; if (all_to_go == 1) { - /* this is "pure white" noise, so we have to calculate each sample */ + /* this is "pure white" noise, so we have to calculate each sample */ while (n--) { *out++ = int2sample(i_value=update_intNoise(i_value)); } } else if (n < still_to_go) { - /* signal won't change for the next 64 samples */ + /* signal won't change for the next 64 samples */ still_to_go -= n; - while (n--){ + while (n--) { *out++ = (f_value -= decrement); } } else if (all_to_go + still_to_go > n) { - /* only one update calculation necessary for 64 samples !!! */ + /* only one update calculation necessary for 64 samples !!! */ while (still_to_go-- > 0) { n--; *out++ = (f_value -= decrement); @@ -120,13 +122,13 @@ static t_int *noisi_perform(t_int *w){ *out++ = (f_value -= decrement); } } else { - /* anything else */ + /* anything else */ while (n--) { - if (still_to_go-- <= 0) { /* update only if all time has elapsed */ - still_to_go += all_to_go; - f_value=int2sample(i_value); - i_value=update_intNoise(i_value); - decrement = (f_value - int2sample(i_value)) / all_to_go; + if (still_to_go-- <= 0) { /* update only if all time has elapsed */ + still_to_go += all_to_go; + f_value=int2sample(i_value); + i_value=update_intNoise(i_value); + decrement = (f_value - int2sample(i_value)) / all_to_go; } *out++ = (f_value -= decrement); } @@ -136,16 +138,18 @@ static t_int *noisi_perform(t_int *w){ x->current = f_value; x->decrement = decrement; x->to_go = still_to_go; - + return (w+4); } -static void noisi_dsp(t_nois *x, t_signal **sp){ +static void noisi_dsp(t_nois *x, t_signal **sp) +{ dsp_add(noisi_perform, 3, x, sp[0]->s_vec, sp[0]->s_n); } -static void noisi_helper(void){ +static void noisi_helper(void) +{ post("\n"HEARTSYMBOL" noisi~\t:: a bandlimited interpolating pseudo-noise generator"); post("\t : sampling-frequency (in Hz)\n" "'help'\t : view this"); @@ -157,9 +161,10 @@ static void noisi_helper(void){ post("for further details see DODGE/JERSE \"computer music\" c3.9\n"); } -static void *noisi_new(t_floatarg f){ +static void *noisi_new(t_floatarg f) +{ t_nois *x = (t_nois *)pd_new(noisi_class); - + static int init = 4259; x->val = (init *= 17); @@ -169,13 +174,16 @@ static void *noisi_new(t_floatarg f){ return (x); } -void noisi_tilde_setup(void){ - noisi_class = class_new(gensym("noisi~"), (t_newmethod)noisi_new, 0, sizeof(t_nois), 0, A_DEFFLOAT, 0); +void noisi_tilde_setup(void) +{ + noisi_class = class_new(gensym("noisi~"), (t_newmethod)noisi_new, 0, + sizeof(t_nois), 0, A_DEFFLOAT, 0); class_addfloat(noisi_class, set_noisfreq); class_addmethod(noisi_class, (t_method)noisi_dsp, gensym("dsp"), 0); - class_addmethod(noisi_class, (t_method)set_noisseed, gensym("seed"), A_FLOAT, 0); + class_addmethod(noisi_class, (t_method)set_noisseed, gensym("seed"), + A_FLOAT, 0); class_addmethod(noisi_class, (t_method)noisi_helper, gensym("help"), 0); zexy_register("noisi~"); diff --git a/src/operating_system.c b/src/operating_system.c index a02b406..4d58466 100644 --- a/src/operating_system.c +++ b/src/operating_system.c @@ -1,4 +1,4 @@ -/* +/* * operating_system : get currently used OS * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -27,8 +27,7 @@ MESSAGE OPERATING_SYSTEM: simple and easy static t_class *operating_system_class; -typedef struct _operating_system -{ +typedef struct _operating_system { t_object x_obj; } t_operating_system; @@ -50,7 +49,8 @@ static void operating_system_bang(t_operating_system *x) static void *operating_system_new(void) { - t_operating_system *x = (t_operating_system *)pd_new(operating_system_class); + t_operating_system *x = (t_operating_system *)pd_new( + operating_system_class); outlet_new(&x->x_obj, 0); return (x); } @@ -62,10 +62,12 @@ static void operating_system_help(t_operating_system*x) void operating_system_setup(void) { - operating_system_class = class_new(gensym("operating_system"), (t_newmethod)operating_system_new, + operating_system_class = class_new(gensym("operating_system"), + (t_newmethod)operating_system_new, 0, sizeof(t_operating_system), 0, A_NULL); - + class_addbang (operating_system_class, operating_system_bang); - class_addmethod(operating_system_class, (t_method)operating_system_help, gensym("help"), A_NULL); + class_addmethod(operating_system_class, (t_method)operating_system_help, + gensym("help"), A_NULL); zexy_register("operating_system"); } diff --git a/src/pack.c b/src/pack.c index 9e924e3..b07f6a8 100644 --- a/src/pack.c +++ b/src/pack.c @@ -1,4 +1,4 @@ -/* +/* * pack: a type-agnostic version of [pack] * * (c) 2007-2011 forum::für::umläute @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -33,8 +33,7 @@ static t_class *zpack_class; static t_class *zpackproxy_class; -typedef struct _zpack -{ +typedef struct _zpack { t_object x_obj; struct _zpackproxy **x_proxy; @@ -45,25 +44,27 @@ typedef struct _zpack } t_zpack; -typedef struct _zpackproxy -{ +typedef struct _zpackproxy { t_pd p_pd; t_zpack *p_master; int id; } t_zpackproxy; -static void setatom(t_zpack *x, t_atom*from, int to) { +static void setatom(t_zpack *x, t_atom*from, int to) +{ x->x_argv[to].a_type=from->a_type; x->x_argv[to].a_w =from->a_w; } -static void zpack_bang(t_zpack*x) { +static void zpack_bang(t_zpack*x) +{ outlet_list(x->x_obj.ob_outlet, gensym("list"), x->x_argc, x->x_argv); } -static void zpack_any(t_zpack*x, t_symbol *s, int argc, t_atom *argv) { +static void zpack_any(t_zpack*x, t_symbol *s, int argc, t_atom *argv) +{ int i=0; int count=x->x_argc; @@ -74,32 +75,37 @@ static void zpack_any(t_zpack*x, t_symbol *s, int argc, t_atom *argv) { count--; } - if(count>argc) + if(count>argc) { count=argc; + } while(count-->0) { setatom(x, argv++, i++); } - - zpack_bang(x); + + zpack_bang(x); } -static void zpack_list(t_zpack*x, t_symbol *s, int argc, t_atom *argv) { +static void zpack_list(t_zpack*x, t_symbol *s, int argc, t_atom *argv) +{ zpack_any(x, 0, argc, argv); } -static void zpack_proxy_list(t_zpackproxy *y, t_symbol *s, int argc, t_atom *argv) +static void zpack_proxy_list(t_zpackproxy *y, t_symbol *s, int argc, + t_atom *argv) { /* until we have lists of lists, this only uses the 1st element */ - if(argc>0) /* this filters out 'bang', and allows 'list', 'float' and 'symbol' */ + if(argc>0) { /* this filters out 'bang', and allows 'list', 'float' and 'symbol' */ setatom(y->p_master, argv, y->id); + } } -static void zpack_proxy_any(t_zpackproxy *y, t_symbol *s, int argc, t_atom *argv) +static void zpack_proxy_any(t_zpackproxy *y, t_symbol *s, int argc, + t_atom *argv) { /* until we have lists of lists, this only uses the selector */ t_atom a; - SETSYMBOL(&a, s); + SETSYMBOL(&a, s); setatom(y->p_master, &a, y->id); } @@ -118,8 +124,9 @@ static void *zpack_new(t_symbol *s, int argc, t_atom *argv) } else { int i=0; x->x_argv=(t_atom*)getbytes(x->x_argc*sizeof(t_atom)); - for(i=0; ix_argc; i++) + for(i=0; ix_argc; i++) { setatom(x, argv+i, i); + } } x->in = (t_inlet **)getbytes(x->x_argc * sizeof(t_inlet *)); @@ -139,23 +146,24 @@ static void *zpack_new(t_symbol *s, int argc, t_atom *argv) return (x); } -static void zpack_free(t_zpack*x){ +static void zpack_free(t_zpack*x) +{ const int count = x->x_argc; - if(x->in && x->x_proxy){ + if(x->in && x->x_proxy) { int n=0; - for(n=0; nin[n]){ + for(n=0; nin[n]) { inlet_free(x->in[n]); } x->in[n]=0; - if(x->x_proxy[n]){ + if(x->x_proxy[n]) { t_zpackproxy *y=x->x_proxy[n]; y->p_master=0; y->id=0; - pd_free(&y->p_pd); + pd_free(&y->p_pd); } - x->x_proxy[n]=0; + x->x_proxy[n]=0; } freebytes(x->in, x->x_argc * sizeof(t_inlet *)); freebytes(x->x_proxy, x->x_argc * sizeof(t_zpackproxy*)); @@ -165,7 +173,7 @@ static void zpack_free(t_zpack*x){ void zpack_setup(void) { zpack_class = class_new(gensym("zexy/pack"), (t_newmethod)zpack_new, - (t_method)zpack_free, sizeof(t_zpack), 0, A_GIMME, 0); + (t_method)zpack_free, sizeof(t_zpack), 0, A_GIMME, 0); #if 0 /* oops Pd>=0.42 allows us to override built-ins * this is bad as long as the 2 objects are not compatible */ @@ -176,8 +184,8 @@ void zpack_setup(void) class_addanything(zpack_class, zpack_any); zpackproxy_class = class_new(gensym("zpack proxy"), 0, 0, - sizeof(t_zpackproxy), - CLASS_PD | CLASS_NOINLET, 0); + sizeof(t_zpackproxy), + CLASS_PD | CLASS_NOINLET, 0); class_addlist(zpackproxy_class, zpack_proxy_list); class_addanything(zpackproxy_class, zpack_proxy_any); diff --git a/src/packel.c b/src/packel.c index c1fb15b..5329908 100644 --- a/src/packel.c +++ b/src/packel.c @@ -1,4 +1,4 @@ -/* +/* * packel: get the nth element of a package * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -21,8 +21,7 @@ static t_class *packel_class; -typedef struct _packel -{ +typedef struct _packel { t_object x_obj; t_float *position; int count; @@ -34,21 +33,26 @@ typedef struct _packel } t_packel; -static void packel_outelement(t_packel*x, int id, t_symbol*s,int argc, t_atom*argv) +static void packel_outelement(t_packel*x, int id, t_symbol*s,int argc, + t_atom*argv) { t_outlet*out=x->x_outlet[id]; int index= x->position[id]; - + if (index) { t_atom *current; int pos = (index < 0)?(argc+index):(index-1); - if(argc==0){ - if (pos==0||pos==-1)outlet_bang(out); + if(argc==0) { + if (pos==0||pos==-1) { + outlet_bang(out); + } + return; + } + + if (pos < 0 || pos >= argc) { return; } - - if (pos < 0 || pos >= argc)return; current = &(argv[pos]); @@ -58,7 +62,9 @@ static void packel_outelement(t_packel*x, int id, t_symbol*s,int argc, t_atom*ar default: outlet_list(out, gensym("list"), 1, current); } - } else outlet_list(out, s, argc, argv); + } else { + outlet_list(out, s, argc, argv); + } } static void packel_list(t_packel *x, t_symbol *s, int argc, t_atom *argv) @@ -69,18 +75,21 @@ static void packel_list(t_packel *x, t_symbol *s, int argc, t_atom *argv) } } -static void packel_anything(t_packel *x, t_symbol *s, int argc, t_atom *argv) +static void packel_anything(t_packel *x, t_symbol *s, int argc, + t_atom *argv) { t_atom *av2 = (t_atom *)getbytes((argc + 1) * sizeof(t_atom)); int i; - if(x->x_warningflag){ - pd_error(x, "deprecation warning: you should only use lists for list data"); + if(x->x_warningflag) { + pd_error(x, + "deprecation warning: you should only use lists for list data"); x->x_warningflag=0; } - for (i = 0; i < argc; i++) + for (i = 0; i < argc; i++) { av2[i + 1] = argv[i]; + } SETSYMBOL(av2, s); packel_list(x, gensym("list"), argc+1, av2); freebytes(av2, (argc + 1) * sizeof(t_atom)); @@ -92,13 +101,23 @@ static void packel_free(t_packel *x) int i=0; for(i=0; icount; i++) { - if(x->x_inlet &&x->x_inlet [i])inlet_free (x->x_inlet [i]); - if(x->x_outlet&&x->x_outlet[i])outlet_free(x->x_outlet[i]); + if(x->x_inlet &&x->x_inlet [i]) { + inlet_free (x->x_inlet [i]); + } + if(x->x_outlet&&x->x_outlet[i]) { + outlet_free(x->x_outlet[i]); + } } - if(x->position)freebytes(x->position, x->count*sizeof(t_float)); - if(x->x_inlet) freebytes(x->x_inlet, x->count*sizeof(t_inlet*)); - if(x->x_outlet)freebytes(x->x_outlet, x->count*sizeof(t_outlet*)); + if(x->position) { + freebytes(x->position, x->count*sizeof(t_float)); + } + if(x->x_inlet) { + freebytes(x->x_inlet, x->count*sizeof(t_inlet*)); + } + if(x->x_outlet) { + freebytes(x->x_outlet, x->count*sizeof(t_outlet*)); + } } @@ -106,7 +125,7 @@ static void packel_free(t_packel *x) static void *packel_new(t_symbol*s, int argc, t_atom*argv) { t_packel *x = (t_packel *)pd_new(packel_class); - + x->count=(argc>0)?argc:1; x->position=(t_float*)getbytes(x->count*sizeof(t_float)); @@ -133,8 +152,8 @@ static void *packel_new(t_symbol*s, int argc, t_atom*argv) void packel_setup(void) { - packel_class = class_new(gensym("packel"), - (t_newmethod)packel_new, (t_method)packel_free, + packel_class = class_new(gensym("packel"), + (t_newmethod)packel_new, (t_method)packel_free, sizeof(t_packel), 0, A_GIMME, 0); diff --git a/src/pack~.c b/src/pack~.c index 89901b3..5ec6085 100644 --- a/src/pack~.c +++ b/src/pack~.c @@ -1,4 +1,4 @@ -/* +/* * pack~: pack the signal-vector to a list of floats * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -21,8 +21,7 @@ static t_class *sigpack_class; -typedef struct _sigpack -{ +typedef struct _sigpack { t_object x_obj; int vector_length; @@ -33,7 +32,8 @@ typedef struct _sigpack static void sigpack_tick(t_sigpack*x) { - outlet_list(x->x_obj.ob_outlet, gensym("list"), x->vector_length, x->buffer); + outlet_list(x->x_obj.ob_outlet, gensym("list"), x->vector_length, + x->buffer); } static t_int *sigpack_perform(t_int *w) @@ -92,7 +92,8 @@ static void sigpack_help(void) void pack_tilde_setup(void) { - sigpack_class = class_new(gensym("pack~"), (t_newmethod)sigpack_new, (t_method)sigpack_free, + sigpack_class = class_new(gensym("pack~"), (t_newmethod)sigpack_new, + (t_method)sigpack_free, sizeof(t_sigpack), 0, A_DEFFLOAT, 0); class_addmethod(sigpack_class, nullfn, gensym("signal"), 0); class_addmethod(sigpack_class, (t_method)sigpack_dsp, gensym("dsp"), 0); diff --git a/src/pdf~.c b/src/pdf~.c index aee193c..5002a20 100644 --- a/src/pdf~.c +++ b/src/pdf~.c @@ -1,4 +1,4 @@ -/* +/* * pdf~: get the ProbabilityDensityFunction of a signal * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -23,8 +23,7 @@ static t_class *pdf_class; -typedef struct _pdf -{ +typedef struct _pdf { t_object x_obj; t_float *buf; @@ -37,7 +36,9 @@ static void clear_pdfbuf(t_pdf *x) int n = x->size; t_float *buf = x->buf; - while (n--) *buf++=0.; + while (n--) { + *buf++=0.; + } } static void pdf_bang(t_pdf *x) @@ -46,25 +47,32 @@ static void pdf_bang(t_pdf *x) t_float *buf = x->buf, max = 0; t_atom a[2]; - while (n--) if (max < *buf++) max = buf[-1]; + while (n--) if (max < *buf++) { + max = buf[-1]; + } n=x->size; buf = x->buf; - if (max==0.) max=1.; + if (max==0.) { + max=1.; + } max = 1./max; - while (n--) - { - SETFLOAT(a, *buf++*max); - SETFLOAT(a+1,x->size-n-1); - outlet_list(x->x_obj.ob_outlet, gensym("list"), 2, (t_atom*)&a); - } + while (n--) { + SETFLOAT(a, *buf++*max); + SETFLOAT(a+1,x->size-n-1); + outlet_list(x->x_obj.ob_outlet, gensym("list"), 2, (t_atom*)&a); + } } static void pdf_float(t_pdf *x, t_floatarg f) { - if (f) pdf_bang(x); else clear_pdfbuf(x); + if (f) { + pdf_bang(x); + } else { + clear_pdfbuf(x); + } } static t_int *pdf_perform(t_int *w) @@ -76,12 +84,11 @@ static t_int *pdf_perform(t_int *w) t_float *buf = x->buf; t_float halfsize = x->halfsize; - while (n--) - { - t_sample f = *in++; - int iindex = ((f + 1.0) * halfsize)+0.5; - buf[(iindex<0)?0:((iindex>=x->size)?x->size-1:iindex)]+=1.; - } + while (n--) { + t_sample f = *in++; + int iindex = ((f + 1.0) * halfsize)+0.5; + buf[(iindex<0)?0:((iindex>=x->size)?x->size-1:iindex)]+=1.; + } return (w+4); } @@ -102,14 +109,15 @@ static void *pdf_new(t_floatarg f) clear_pdfbuf(x); outlet_new(&x->x_obj, gensym("list")); - + return (x); } static void pdf_free(t_pdf *x) { - if(x->buf) + if(x->buf) { freebytes(x->buf, x->size*sizeof(*x->buf)); + } } static void pdf_tilde_helper(void) @@ -124,8 +132,9 @@ static void pdf_tilde_helper(void) void pdf_tilde_setup(void) { - pdf_class = class_new(gensym("pdf~"), (t_newmethod)pdf_new, (t_method)pdf_free, - sizeof(t_pdf), 0, A_DEFFLOAT, 0); + pdf_class = class_new(gensym("pdf~"), (t_newmethod)pdf_new, + (t_method)pdf_free, + sizeof(t_pdf), 0, A_DEFFLOAT, 0); class_addmethod(pdf_class, nullfn, gensym("signal"), 0); class_addmethod(pdf_class, (t_method)pdf_dsp, gensym("dsp"), 0); diff --git a/src/prime.c b/src/prime.c index 66ffb49..7acd9c4 100644 --- a/src/prime.c +++ b/src/prime.c @@ -1,4 +1,4 @@ -/* +/* * prime: get the n-th prime number * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -34,12 +34,12 @@ static void prime_float(t_prime *x, t_float f) unsigned int max_divisor; unsigned int divisor=1; - if (f<2){ + if (f<2) { outlet_float(x->x_obj.ob_outlet, 0.0); return; } - if (!(i%2)){ + if (!(i%2)) { outlet_float(x->x_obj.ob_outlet, (t_float)(i==2)); return; } @@ -70,11 +70,12 @@ static void prime_help(t_prime*x) } -void prime_setup(void) { +void prime_setup(void) +{ prime_class = class_new(gensym("prime"), - (t_newmethod)prime_new, - 0, sizeof(t_prime), - CLASS_DEFAULT, 0); + (t_newmethod)prime_new, + 0, sizeof(t_prime), + CLASS_DEFAULT, 0); class_addfloat(prime_class, prime_float); class_addmethod(prime_class, (t_method)prime_help, gensym("help"), A_NULL); diff --git a/src/quantize~.c b/src/quantize~.c index b561243..64bc317 100644 --- a/src/quantize~.c +++ b/src/quantize~.c @@ -1,4 +1,4 @@ -/* +/* * quantize~: quantize a signal to various bit-depths * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -30,8 +30,7 @@ static t_class *quantize_class; -typedef struct _quantize -{ +typedef struct _quantize { t_object x_obj; t_sample quantiz, dequantiz; } t_quantize; @@ -64,8 +63,12 @@ static t_int *quantize_perform(t_int *w) t_sample quantiz = x->quantiz, dequantiz = x->dequantiz; if (quantiz) - while (n--) *out++ = dequantiz*(int)(quantiz**in++); - else while (n--) *out++ = *in++; + while (n--) { + *out++ = dequantiz*(int)(quantiz**in++); + } + else while (n--) { + *out++ = *in++; + } return (w+5); } @@ -92,23 +95,30 @@ static void *quantize_new(t_floatarg f) { t_quantize *x = (t_quantize *)pd_new(quantize_class); outlet_new(&x->x_obj, gensym("signal")); - if (f) quantize_float(x, f); - else quantize_16bit(x); - + if (f) { + quantize_float(x, f); + } else { + quantize_16bit(x); + } + return (x); } void quantize_tilde_setup(void) { - quantize_class = class_new(gensym("quantize~"), (t_newmethod)quantize_new, 0, - sizeof(t_quantize), 0, A_DEFFLOAT, 0); + quantize_class = class_new(gensym("quantize~"), (t_newmethod)quantize_new, + 0, + sizeof(t_quantize), 0, A_DEFFLOAT, 0); class_addmethod(quantize_class, nullfn, gensym("signal"), 0); class_addmethod(quantize_class, (t_method)quantize_dsp, gensym("dsp"), 0); class_addfloat(quantize_class, quantize_float); - class_addmethod(quantize_class, (t_method)quantize_8bit, gensym("8bit"), 0); - class_addmethod(quantize_class, (t_method)quantize_16bit, gensym("16bit"), 0); - - class_addmethod(quantize_class, (t_method)quantize_tilde_helper, gensym("help"), 0); + class_addmethod(quantize_class, (t_method)quantize_8bit, gensym("8bit"), + 0); + class_addmethod(quantize_class, (t_method)quantize_16bit, gensym("16bit"), + 0); + + class_addmethod(quantize_class, (t_method)quantize_tilde_helper, + gensym("help"), 0); zexy_register("quantize~"); } diff --git a/src/rawprint.c b/src/rawprint.c index 68aac73..68b4244 100644 --- a/src/rawprint.c +++ b/src/rawprint.c @@ -1,4 +1,4 @@ -/* +/* * rawprint: print the incoming message as raw as possible * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -20,7 +20,7 @@ #include "zexy.h" #include -#ifdef _MSC_VER +#ifdef _MSC_VER # define snprintf _snprintf #endif @@ -71,7 +71,8 @@ static void rawprint_any(t_rawprint *x, t_symbol*s, int argc, t_atom*argv) snprintf(buf, MAXPDSTRING-1, "DOLLAR['%s']", atom_getsymbol(argv)->s_name); break; case A_DOLLSYM: - snprintf(buf, MAXPDSTRING-1, "DOLLSYM['%s']", atom_getsymbol(argv)->s_name); + snprintf(buf, MAXPDSTRING-1, "DOLLSYM['%s']", + atom_getsymbol(argv)->s_name); break; case A_GIMME: snprintf(buf, MAXPDSTRING-1, "GIMME"); @@ -83,7 +84,7 @@ static void rawprint_any(t_rawprint *x, t_symbol*s, int argc, t_atom*argv) snprintf(buf, MAXPDSTRING-1, "unknown[%d]", argv->a_type); } buf[MAXPDSTRING-1]=0; - + startpost(" %s", buf); argv++; } @@ -95,13 +96,15 @@ static void *rawprint_new(t_symbol*s) { t_rawprint *x = (t_rawprint *)pd_new(rawprint_class); x->label=NULL; - if(s&&gensym("")!=s) + if(s&&gensym("")!=s) { x->label=s; + } return (x); } -void rawprint_setup(void) { +void rawprint_setup(void) +{ rawprint_class = class_new(gensym("rawprint"), (t_newmethod)rawprint_new, 0, sizeof(t_rawprint), diff --git a/src/regex.c b/src/regex.c index 83f852e..163b86f 100644 --- a/src/regex.c +++ b/src/regex.c @@ -1,4 +1,4 @@ -/* +/* * regex: regular expression pattern matcher * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -36,12 +36,11 @@ static t_class *regex_class; -typedef struct _regex -{ +typedef struct _regex { t_object x_obj; #ifdef HAVE_REGEX_H char *x_regexstring; /* the uncompiled regular expression */ - int x_regexstringlength; + int x_regexstringlength; regex_t *x_regexp; int x_matchnum; @@ -62,19 +61,24 @@ static char*regex_l2s(int *reslen, t_symbol*s, int argc, t_atom*argv) int pos=0, i=0; t_atom*ap; int length=0; - if(reslen)*reslen=length; + if(reslen) { + *reslen=length; + } /* 1st get the length of the symbol */ - if(s)length+=strlen(s->s_name); - else length-=1; + if(s) { + length+=strlen(s->s_name); + } else { + length-=1; + } length+=argc; i=argc; ap=argv; - while(i--){ + while(i--) { char buffer[MAXPDSTRING]; int len=0; - if(A_SYMBOL==ap->a_type){ + if(A_SYMBOL==ap->a_type) { len=strlen(ap->a_w.w_symbol->s_name); } else { atom_string(ap, buffer, MAXPDSTRING); @@ -84,7 +88,9 @@ static char*regex_l2s(int *reslen, t_symbol*s, int argc, t_atom*argv) ap++; } - if(length<=0)return(0); + if(length<=0) { + return(0); + } result = (char*)getbytes((length+1)*sizeof(char)); @@ -92,7 +98,7 @@ static char*regex_l2s(int *reslen, t_symbol*s, int argc, t_atom*argv) char *buf = s->s_name; strcpy(result+pos, buf); pos+=strlen(buf); - if(i){ + if(i) { strcpy(result+pos, " "); pos += 1; } @@ -100,8 +106,8 @@ static char*regex_l2s(int *reslen, t_symbol*s, int argc, t_atom*argv) ap=argv; i=argc; - while(i--){ - if(A_SYMBOL==ap->a_type){ + while(i--) { + if(A_SYMBOL==ap->a_type) { strcpy(result+pos, ap->a_w.w_symbol->s_name); pos+= strlen(ap->a_w.w_symbol->s_name); } else { @@ -111,14 +117,16 @@ static char*regex_l2s(int *reslen, t_symbol*s, int argc, t_atom*argv) pos += strlen(buffer); } ap++; - if(i){ + if(i) { strcpy(result+pos, " "); pos++; } } result[length]=0; - if(reslen)*reslen=length; + if(reslen) { + *reslen=length; + } return result; } @@ -127,34 +135,38 @@ static void regex_compile(t_regex *x) int flags = x->x_flags; flags |= REG_EXTENDED; - if(0==x->x_regexstring || 0==x->x_regexstringlength){ + if(0==x->x_regexstring || 0==x->x_regexstringlength) { pd_error(x, "[regex]: no regular expression given"); return; } - if(x->x_regexp){ - regfree(x->x_regexp); - freebytes(x->x_regexp, sizeof(t_regex)); - x->x_regexp=0; + if(x->x_regexp) { + regfree(x->x_regexp); + freebytes(x->x_regexp, sizeof(t_regex)); + x->x_regexp=0; } x->x_regexp=(regex_t*)getbytes(sizeof(t_regex)); if(regcomp(x->x_regexp, x->x_regexstring, flags)) { pd_error(x, "[regex]: invalid regular expression: %s", x->x_regexstring); - if(x->x_regexp)freebytes(x->x_regexp, sizeof(t_regex)); + if(x->x_regexp) { + freebytes(x->x_regexp, sizeof(t_regex)); + } x->x_regexp=0; } } #endif -static void regex_case(t_regex *x, t_float f){ +static void regex_case(t_regex *x, t_float f) +{ #if HAVE_REGEX_H - if(f>0.f) + if(f>0.f) { x->x_flags |= REG_ICASE; - else + } else { x->x_flags ^= REG_ICASE; + } regex_compile(x); #endif @@ -169,7 +181,7 @@ static void regex_regex(t_regex *x, t_symbol*s, int argc, t_atom*argv) result=regex_l2s(&length, 0, argc, argv); - if(0==result || 0==length){ + if(0==result || 0==length) { pd_error(x, "[regex]: no regular expression given"); return; } @@ -179,7 +191,7 @@ static void regex_regex(t_regex *x, t_symbol*s, int argc, t_atom*argv) x->x_regexstring=0; x->x_regexstringlength=0; } - + x->x_regexstring=result; x->x_regexstringlength=length; @@ -200,25 +212,25 @@ static void regex_symbol(t_regex *x, t_symbol *s, int argc, t_atom*argv) int err=0; - if(!x->x_regexp){ + if(!x->x_regexp) { pd_error(x, "[regex]: no regular expression!"); goto cleanup; } teststring=regex_l2s(&length, 0, argc, argv); - if(!teststring||!length){ + if(!teststring||!length) { pd_error(x, "[regex]: cannot evaluate string"); goto cleanup; } /* do the actual comparing against the regex */ err=regexec(x->x_regexp, teststring, num_matches, match, 0); - if(teststring){ + if(teststring) { freebytes(teststring, length); teststring=0; } if(err) { /* NO match */ - if(match){ + if(match) { freebytes(match, sizeof(regmatch_t)*num_matches); match=0; } @@ -229,10 +241,11 @@ static void regex_symbol(t_regex *x, t_symbol *s, int argc, t_atom*argv) int i=0; t_atom*ap2=ap; - for(i=0; i0 && (match[i].rm_so==match[i-1].rm_so) && (match[i].rm_eo==match[i-1].rm_eo)){ + if(i>0 && (match[i].rm_so==match[i-1].rm_so) + && (match[i].rm_eo==match[i-1].rm_eo)) { /* duplicate matches */ } else { SETFLOAT(ap2+0, (t_float)i); @@ -243,21 +256,25 @@ static void regex_symbol(t_regex *x, t_symbol *s, int argc, t_atom*argv) } } } - if(match){ + if(match) { freebytes(match, sizeof(regmatch_t)*num_matches); match=0; } outlet_float(x->x_outNumDetails, (t_float)num_results); - for(i=0; ix_outDetails, gensym("list"), 3, ap+(i*3)); } outlet_float(x->x_outResult, 1.f); } - cleanup: - if(teststring)freebytes(teststring, length); - if(match)freebytes(match, sizeof(regmatch_t)*num_matches); +cleanup: + if(teststring) { + freebytes(teststring, length); + } + if(match) { + freebytes(match, sizeof(regmatch_t)*num_matches); + } - if(ap){ + if(ap) { freebytes(ap, sizeof(t_atom)*(1+2*num_matches)); } #endif @@ -282,8 +299,9 @@ static void *regex_new(t_symbol *s, int argc, t_atom*argv) x->x_regexp=0; x->x_matchnum=NUM_REGMATCHES; - if(argc)regex_regex(x, gensym(""), argc, argv); - else{ + if(argc) { + regex_regex(x, gensym(""), argc, argv); + } else { t_atom a; SETSYMBOL(&a, gensym(".*")); regex_regex(x, 0, 1, &a); @@ -298,7 +316,7 @@ static void *regex_new(t_symbol *s, int argc, t_atom*argv) static void regex_free(t_regex *x) { #ifdef HAVE_REGEX_H - if(x->x_regexstring){ + if(x->x_regexstring) { freebytes(x->x_regexstring, x->x_regexstringlength); x->x_regexstring=0; x->x_regexstringlength=0; @@ -319,13 +337,15 @@ static void regex_help(t_regex*x) void regex_setup(void) { - regex_class = class_new(gensym("regex"), (t_newmethod)regex_new, - (t_method)regex_free, sizeof(t_regex), 0, A_GIMME, 0); + regex_class = class_new(gensym("regex"), (t_newmethod)regex_new, + (t_method)regex_free, sizeof(t_regex), 0, A_GIMME, 0); class_addlist (regex_class, regex_symbol); - class_addmethod(regex_class, (t_method)regex_regex, gensym("regex"), A_GIMME, 0); + class_addmethod(regex_class, (t_method)regex_regex, gensym("regex"), + A_GIMME, 0); - class_addmethod(regex_class, (t_method)regex_case, gensym("case"), A_FLOAT, 0); + class_addmethod(regex_class, (t_method)regex_case, gensym("case"), A_FLOAT, + 0); class_addmethod(regex_class, (t_method)regex_help, gensym("help"), A_NULL); zexy_register("regex"); diff --git a/src/relay.c b/src/relay.c index 8fcd34e..e1ea476 100644 --- a/src/relay.c +++ b/src/relay.c @@ -1,4 +1,4 @@ -/* +/* * relay: route without stripping selector * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,17 +7,17 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ -/* +/* (c) 2106:forum::für::umläute:2005 "relay" is like "route" but doesn't change the incoming list @@ -26,7 +26,7 @@ [foo bar( --> [route foo] --> [bar( [foo bar( --> [relay foo] --> [foor bar( - namings: + namings: direct, channel, relay, steer, guide, ?? in the meantime i choose [relay] (as in mail-relay) @@ -40,14 +40,12 @@ static t_class *relay_class; -typedef struct _relayelement -{ +typedef struct _relayelement { t_word e_w; t_outlet *e_outlet; } t_relayelement; -typedef struct _relay -{ +typedef struct _relay { t_object x_obj; t_atomtype x_type; t_int x_nelement; @@ -55,15 +53,16 @@ typedef struct _relay t_outlet *x_rejectout; } t_relay; -static void relay_anything(t_relay *x, t_symbol *sel, int argc, t_atom *argv) +static void relay_anything(t_relay *x, t_symbol *sel, int argc, + t_atom *argv) { t_relayelement *e; int nelement; if (x->x_type == A_SYMBOL) { for (nelement = x->x_nelement, e = x->x_vec; nelement--; e++) { if (e->e_w.w_symbol == sel) { - outlet_anything(e->e_outlet, sel, argc, argv); - return; + outlet_anything(e->e_outlet, sel, argc, argv); + return; } } } @@ -83,38 +82,38 @@ static void relay_list(t_relay *x, t_symbol *sel, int argc, t_atom *argv) f = atom_getfloat(argv); for (nelement = x->x_nelement, e = x->x_vec; nelement--; e++) { if (e->e_w.w_float == f) { - outlet_anything(e->e_outlet, sel, argc, argv); - return; + outlet_anything(e->e_outlet, sel, argc, argv); + return; } } } else { /* symbol arguments */ if (argc == 0) { /* no args: treat as "bang" */ for (nelement = x->x_nelement, e = x->x_vec; nelement--; e++) { - if (e->e_w.w_symbol == gensym("bang")) { - outlet_bang(e->e_outlet); - return; - } + if (e->e_w.w_symbol == gensym("bang")) { + outlet_bang(e->e_outlet); + return; + } } } else if (argc>1) { - for (nelement = x->x_nelement, e = x->x_vec; nelement--; e++) { - if (e->e_w.w_symbol == gensym("list")) { - outlet_anything(e->e_outlet, sel, argc, argv); - return; - } + for (nelement = x->x_nelement, e = x->x_vec; nelement--; e++) { + if (e->e_w.w_symbol == gensym("list")) { + outlet_anything(e->e_outlet, sel, argc, argv); + return; + } } } else if (argv[0].a_type == A_FLOAT) { /* one float arg */ for (nelement = x->x_nelement, e = x->x_vec; nelement--; e++) { - if (e->e_w.w_symbol == gensym("float")) { - outlet_float(e->e_outlet, argv[0].a_w.w_float); - return; - } + if (e->e_w.w_symbol == gensym("float")) { + outlet_float(e->e_outlet, argv[0].a_w.w_float); + return; + } } } else { for (nelement = x->x_nelement, e = x->x_vec; nelement--; e++) { - if (e->e_w.w_symbol == gensym("symbol")) { - outlet_symbol(e->e_outlet, argv[0].a_w.w_symbol); - return; - } + if (e->e_w.w_symbol == gensym("symbol")) { + outlet_symbol(e->e_outlet, argv[0].a_w.w_symbol); + return; + } } } } @@ -143,9 +142,11 @@ static void *relay_new(t_symbol* UNUSED(s), int argc, t_atom *argv) x->x_vec = (t_relayelement *)getbytes(argc * sizeof(*x->x_vec)); for (n = 0, e = x->x_vec; n < argc; n++, e++) { e->e_outlet = outlet_new(&x->x_obj, gensym("list")); - if (x->x_type == A_FLOAT) + if (x->x_type == A_FLOAT) { e->e_w.w_float = atom_getfloatarg(n, argc, argv); - else e->e_w.w_symbol = atom_getsymbolarg(n, argc, argv); + } else { + e->e_w.w_symbol = atom_getsymbolarg(n, argc, argv); + } } x->x_rejectout = outlet_new(&x->x_obj, gensym("list")); return (x); @@ -154,7 +155,7 @@ static void *relay_new(t_symbol* UNUSED(s), int argc, t_atom *argv) void relay_setup(void) { relay_class = class_new(gensym("relay"), (t_newmethod)relay_new, - (t_method)relay_free, sizeof(t_relay), 0, A_GIMME, 0); + (t_method)relay_free, sizeof(t_relay), 0, A_GIMME, 0); class_addlist(relay_class, relay_list); class_addanything(relay_class, relay_anything); zexy_register("relay"); diff --git a/src/repack.c b/src/repack.c index 044d369..51ceb14 100644 --- a/src/repack.c +++ b/src/repack.c @@ -1,4 +1,4 @@ -/* +/* * repack : (re)pack floats/symbols/pointers to fixed-length packages * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -31,8 +31,7 @@ the second inlet lets you change the default package size static t_class *repack_class; -typedef struct _repack -{ +typedef struct _repack { t_object x_obj; t_atom *buffer; int bufsize; @@ -59,12 +58,13 @@ static void repack_set(t_repack *x, t_float f) dumbuf += n; } - if (dumcur < 0) error("this should never happen :: dumcur = %d < 0", dumcur); - else { + if (dumcur < 0) { + error("this should never happen :: dumcur = %d < 0", dumcur); + } else { memcpy(x->buffer, dumbuf, dumcur * sizeof(t_atom)); x->current = dumcur; } - + if (n > x->bufsize) { dumbuf = (t_atom *)getbytes(n * sizeof(t_atom)); memcpy(dumbuf, x->buffer, x->current * sizeof(t_atom)); @@ -72,7 +72,7 @@ static void repack_set(t_repack *x, t_float f) x->buffer = dumbuf; x->bufsize = n; } - + x->outputsize = n; } } @@ -89,7 +89,9 @@ static void repack_float(t_repack *x, t_float f) /* add a float-atom to the list */ SETFLOAT(&x->buffer[x->current], f); x->current++; - if (x->current >= x->outputsize) repack_bang(x); + if (x->current >= x->outputsize) { + repack_bang(x); + } } static void repack_symbol(t_repack *x, t_symbol *s) @@ -97,16 +99,21 @@ static void repack_symbol(t_repack *x, t_symbol *s) /* add a sym-atom to the list */ SETSYMBOL(&x->buffer[x->current], s); x->current++; - if (x->current >= x->outputsize) repack_bang(x); + if (x->current >= x->outputsize) { + repack_bang(x); + } } static void repack_pointer(t_repack *x, t_gpointer *p) { /* add a pointer-atom to the list */ SETPOINTER(&x->buffer[x->current], p); x->current++; - if (x->current >= x->outputsize) repack_bang(x); + if (x->current >= x->outputsize) { + repack_bang(x); + } } -static void repack_list(t_repack *x, t_symbol* UNUSED(s), int argc, t_atom *argv) +static void repack_list(t_repack *x, t_symbol* UNUSED(s), int argc, + t_atom *argv) { int remain = x->outputsize - x->current; t_atom *ap = argv; @@ -128,7 +135,8 @@ static void repack_list(t_repack *x, t_symbol* UNUSED(s), int argc, t_atom *argv memcpy(x->buffer + x->current, ap, argc * sizeof(t_atom)); x->current += argc; } -static void repack_anything(t_repack *x, t_symbol *s, int argc, t_atom *argv) +static void repack_anything(t_repack *x, t_symbol *s, int argc, + t_atom *argv) { SETSYMBOL(&x->buffer[x->current], s); x->current++; @@ -159,16 +167,17 @@ static void *repack_new(t_floatarg f) void repack_setup(void) { - repack_class = class_new(gensym("repack"), (t_newmethod)repack_new, - 0, sizeof(t_repack), 0, A_DEFFLOAT, 0); - + repack_class = class_new(gensym("repack"), (t_newmethod)repack_new, + 0, sizeof(t_repack), 0, A_DEFFLOAT, 0); + class_addbang (repack_class, repack_bang); class_addfloat (repack_class, repack_float); class_addsymbol (repack_class, repack_symbol); class_addpointer (repack_class, repack_pointer); class_addlist (repack_class, repack_list); class_addanything(repack_class, repack_anything); - class_addmethod (repack_class, (t_method)repack_set, gensym(""), A_DEFFLOAT, 0); + class_addmethod (repack_class, (t_method)repack_set, gensym(""), + A_DEFFLOAT, 0); zexy_register("repack"); } diff --git a/src/repeat.c b/src/repeat.c index de9e719..dfd07b1 100644 --- a/src/repeat.c +++ b/src/repeat.c @@ -1,4 +1,4 @@ -/* +/* * repeat: repeat a message multiple times * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -23,28 +23,36 @@ static t_class *repeat_class; -typedef struct _repeat -{ +typedef struct _repeat { t_object x_obj; t_float fcount; } t_repeat; -static void repeat_anything(t_repeat *x, t_symbol *s, int argc, t_atom *argv) -{ +static void repeat_anything(t_repeat *x, t_symbol *s, int argc, + t_atom *argv) +{ int i; i=x->fcount; - if (i<0)i=1; - while(i--)outlet_anything(x->x_obj.ob_outlet, s, argc, argv); + if (i<0) { + i=1; + } + while(i--) { + outlet_anything(x->x_obj.ob_outlet, s, argc, argv); + } } static void *repeat_new(t_symbol* UNUSED(s), int argc, t_atom*argv) { t_repeat *x = (t_repeat *)pd_new(repeat_class); - if(argc){ - if(A_FLOAT==argv->a_type) + if(argc) { + if(A_FLOAT==argv->a_type) { x->fcount = atom_getfloat(argv); - else return 0; - } else x->fcount=2; + } else { + return 0; + } + } else { + x->fcount=2; + } floatinlet_new(&x->x_obj, &x->fcount); outlet_new(&x->x_obj, 0); return (x); @@ -52,8 +60,8 @@ static void *repeat_new(t_symbol* UNUSED(s), int argc, t_atom*argv) void repeat_setup(void) { - repeat_class = class_new(gensym("repeat"), (t_newmethod)repeat_new, - 0, sizeof(t_repeat), 0, A_GIMME, 0); + repeat_class = class_new(gensym("repeat"), (t_newmethod)repeat_new, + 0, sizeof(t_repeat), 0, A_GIMME, 0); class_addanything(repeat_class, repeat_anything); zexy_register("repeat"); diff --git a/src/route~.c b/src/route~.c index c69d94e..aa073ba 100644 --- a/src/route~.c +++ b/src/route~.c @@ -1,4 +1,4 @@ -/* +/* * [route~]: 1-to-n signal routing * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -20,32 +20,34 @@ #include "zexy.h" static t_class *route_tilde_class; -typedef struct _route_tilde -{ +typedef struct _route_tilde { t_object x_obj; t_outlet*x_sigout, *x_msgout; } t_route_tilde; -static void route_tilde_any(t_route_tilde *x, t_symbol *s, int argc, t_atom *argv) +static void route_tilde_any(t_route_tilde *x, t_symbol *s, int argc, + t_atom *argv) { outlet_anything(x->x_msgout, s, argc, argv); } t_int *route_tilde_perform(t_int *w) { - t_sample *in = (t_sample *)(w[1]); - t_sample *out = (t_sample *)(w[2]); - int n = (int)(w[3]); - while (n--) *out++ = *in++; - return (w+4); + t_sample *in = (t_sample *)(w[1]); + t_sample *out = (t_sample *)(w[2]); + int n = (int)(w[3]); + while (n--) { + *out++ = *in++; + } + return (w+4); } static void route_tilde_dsp(t_route_tilde *x, t_signal **sp) { - if(sp) + if(sp) { dsp_add(route_tilde_perform, 3, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n); - else { + } else { route_tilde_any(x, gensym("dsp"), 0, 0); } } @@ -65,12 +67,14 @@ static void *route_tilde_new(void) void route_tilde_setup(void) { - route_tilde_class = class_new(gensym("route~"), (t_newmethod)route_tilde_new, (t_method)route_tilde_free, - sizeof(t_route_tilde), 0, A_NULL); + route_tilde_class = class_new(gensym("route~"), + (t_newmethod)route_tilde_new, (t_method)route_tilde_free, + sizeof(t_route_tilde), 0, A_NULL); class_addanything(route_tilde_class, (t_method)route_tilde_any); class_addmethod(route_tilde_class, nullfn, gensym("signal"), 0); - class_addmethod(route_tilde_class, (t_method)route_tilde_dsp, gensym("dsp"), A_CANT, 0); + class_addmethod(route_tilde_class, (t_method)route_tilde_dsp, + gensym("dsp"), A_CANT, 0); zexy_register("route~"); } diff --git a/src/sfplay.c b/src/sfplay.c index b5db0b3..d762a5a 100644 --- a/src/sfplay.c +++ b/src/sfplay.c @@ -1,4 +1,4 @@ -/* +/* * sfplay: multichannel soundfile player (use [readsf~] instead) * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,56 +7,56 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ /* -sfplay.c - Author: Winfried Ritsch - IEM Graz 10.Mai 99 - +sfplay.c - Author: Winfried Ritsch - IEM Graz 10.Mai 99 - Modified: Description: - + Soundfile player for playing many soundfiles in single speed. (Made for "3 Farben Schwarz" - exhibition in Graz 99 ) - + Filename must have the path or actual directory, since pathname search ist not supported to garantuee a fast open call. - + They idea is a state machine which handles open, skip, play, close, error so that a minimum intervall between OS-calls are made, to avoid peak load. - + It has shown, that the open call is slow if there are a lot of files to search for, then with the first skip the first part of a - soundfile is also loaded by the OS. - + soundfile is also loaded by the OS. + I experimented with asynchronous buffering with paralell process,which has shown no much performance hit, since more processes has to be handled and the modern OS's do caching anyway also caching is done in modern hard disk, so an additional cache woud be an overhead, if not special behaviour is needed (big jumps etc). - + This sfplayers should be used with an appropriate audio buffer for good performance, so also buffering on the object is an overhead. - - The sfread for linux using mmap has also not much improvement over this, if plain playing in one + + The sfread for linux using mmap has also not much improvement over this, if plain playing in one direction is done for random access the sfread should be used, even not knowing how to mmap in NT. - + Todo: Add the SPEED feature, but therefore there should be an own external using e.g. a 4-point interpolation. so overhead is reduced in this one. Split open to an own object called sfopen to hold more soundfiles then players and to enable glueless switching between soundfiles. - + please mail problems and ideas for improvements to ritsch@iem.kug.ac.at */ @@ -83,38 +83,37 @@ ritsch@iem.kug.ac.at */ static t_class *sfplay_class; -typedef struct _sfplay -{ - t_object x_obj; - - t_outlet *bangout; /* end of file */ - - void* filep; /* pointer to file data read in mem */ - t_symbol* filename; /* filename */ - /* - because there is no command queue, - flags are used instead - */ - t_int play; /* play: 1, stop: 0 */ - t_int please_stop; /* can be reset only by stop-state itself */ - t_int please_close; /* can be reset only by close-state */ - t_int x_channels; /* channels to play */ - t_float x_offset; /* offsetto start reading */ - t_float offset; /* inlet value offset in secs */ - t_float x_skip; /* skip bytes because header */ - t_int skip; /* pending skip if 1 */ - t_float x_speed; /* play speed, not supported in this version */ - t_int size; /* size of file (if memory mapped) */ - t_int swap; /* swap bytes from l->b or b->m */ - FILE *fp; /* file oper non-NULL of open */ - t_int state; /* which state is player in */ - t_int count; /* count for ticks before next step */ +typedef struct _sfplay { + t_object x_obj; + + t_outlet *bangout; /* end of file */ + + void* filep; /* pointer to file data read in mem */ + t_symbol* filename; /* filename */ + /* + because there is no command queue, + flags are used instead + */ + t_int play; /* play: 1, stop: 0 */ + t_int please_stop; /* can be reset only by stop-state itself */ + t_int please_close; /* can be reset only by close-state */ + t_int x_channels; /* channels to play */ + t_float x_offset; /* offsetto start reading */ + t_float offset; /* inlet value offset in secs */ + t_float x_skip; /* skip bytes because header */ + t_int skip; /* pending skip if 1 */ + t_float x_speed; /* play speed, not supported in this version */ + t_int size; /* size of file (if memory mapped) */ + t_int swap; /* swap bytes from l->b or b->m */ + FILE *fp; /* file oper non-NULL of open */ + t_int state; /* which state is player in */ + t_int count; /* count for ticks before next step */ } t_sfplay; /* states of statemachine */ #define SFPLAY_WAIT 0 /* wait for open */ -#define SFPLAY_OPEN 1 +#define SFPLAY_OPEN 1 #define SFPLAY_CLOSE 2 #define SFPLAY_SKIP 3 #define SFPLAY_PLAY 4 @@ -123,72 +122,74 @@ typedef struct _sfplay #define SFPLAY_WAITTICKS 10 /* 1 tick of 64 Samples is ca. 1.5ms on 441000 */ -/* split the os-calls in as many steps as possible +/* split the os-calls in as many steps as possible to split them on different ticks in steps of SFPLAY_WAITTICKS to avoid peak performance */ /* like the one from garray */ -static int sfplay_am_i_big_endian(void) +static int sfplay_am_i_big_endian(void) { - unsigned short s = 1; - unsigned char c = *(char *) (&s); - return(c==0); + unsigned short s = 1; + unsigned char c = *(char *) (&s); + return(c==0); } static void sfplay_helper(t_sfplay* UNUSED(x)) { - post("\nsfplay :: a soundfile-player (c) winfried ritsch 1999"); - post("\ncreation :: sfplay : channels set the number of channels, bytes skip fileheader"); - post("\nopen [] []\t::open b(ig) or l(ittle) endian file" - "\nclose\t\t\t::close file (aka eject)" - "\nstart\t\t\t::start playing" - "\nstop\t\t\t::stop playing" - "\nrewind\t\t\t::rewind tape" - "\ngoto \t\t::play from byte n"); - post("\n\nyou can also start playing with a 'bang' or a '1', and stop with a '0'" - "\nthe last outlet will do a bang after the last sample has been played"); + post("\nsfplay :: a soundfile-player (c) winfried ritsch 1999"); + post("\ncreation :: sfplay : channels set the number of channels, bytes skip fileheader"); + post("\nopen [] []\t::open b(ig) or l(ittle) endian file" + "\nclose\t\t\t::close file (aka eject)" + "\nstart\t\t\t::start playing" + "\nstop\t\t\t::stop playing" + "\nrewind\t\t\t::rewind tape" + "\ngoto \t\t::play from byte n"); + post("\n\nyou can also start playing with a 'bang' or a '1', and stop with a '0'" + "\nthe last outlet will do a bang after the last sample has been played"); } /* METHOD: "open" file */ -/* this dont use memory map, because I dont know about this on NT ? -Use of the buffered functions fopen, fseek fread fclose instead the +/* this dont use memory map, because I dont know about this on NT ? +Use of the buffered functions fopen, fseek fread fclose instead the non buffered ones open read close */ static void sfplay_open(t_sfplay *x,t_symbol *filename,t_symbol *endian) { - if(x->state != SFPLAY_WAIT) - { - post("sfplay: first close %s before open %s",x->filename->s_name,filename->s_name); - return; - } - -/* test if big endian else asume little endian - should be 'l' but could be anything*/ - - if(sfplay_am_i_big_endian()) - x->swap = !(endian->s_name[0] == 'b'); - else - x->swap = (endian->s_name[0] == 'b'); - - x->skip = 1; /* skip header after open */ - - x->filename = filename; - + if(x->state != SFPLAY_WAIT) { + post("sfplay: first close %s before open %s",x->filename->s_name, + filename->s_name); + return; + } + + /* test if big endian else asume little endian + should be 'l' but could be anything*/ + + if(sfplay_am_i_big_endian()) { + x->swap = !(endian->s_name[0] == 'b'); + } else { + x->swap = (endian->s_name[0] == 'b'); + } + + x->skip = 1; /* skip header after open */ + + x->filename = filename; + #ifdef DEBUG_ME - post("sfplay: filename = %s",x->filename->s_name); + post("sfplay: filename = %s",x->filename->s_name); #endif - - if (x->fp != NULL)fclose(x->fp); /* should not happen */ - - if (!(x->fp = fopen(x->filename->s_name,BINREADMODE))) - { - error("sfplay: can't open %s", x->filename->s_name); - } + + if (x->fp != NULL) { + fclose(x->fp); /* should not happen */ + } + + if (!(x->fp = fopen(x->filename->s_name,BINREADMODE))) { + error("sfplay: can't open %s", x->filename->s_name); + } } @@ -196,347 +197,352 @@ static void sfplay_open(t_sfplay *x,t_symbol *filename,t_symbol *endian) /* METHOD: close */ static void sfplay_close(t_sfplay *x) { - x->play = 0; - x->please_close = 1; + x->play = 0; + x->please_close = 1; - /* now in state machine - if(x->fp != NULL) - { - fclose(x->fp); - x->fp = NULL; - } - */ + /* now in state machine + if(x->fp != NULL) + { + fclose(x->fp); + x->fp = NULL; + } + */ #ifdef DEBUG_ME - post("sfplay: close "); + post("sfplay: close "); #endif - return; + return; } /* for skipping header of soundfile Dont use this for memory map */ static int sfplay_skip(t_sfplay *x) { - if(!x->skip) return 0; - - x->skip = 0; - - if(fseek(x->fp, (long) x->x_offset, SEEK_SET) < 0) - { - error(" sfplay can't seek to byte %ld",(long) x->x_offset); - x->x_offset = x->x_skip; - x->skip = 1; - return 0; - } - + if(!x->skip) { + return 0; + } + + x->skip = 0; + + if(fseek(x->fp, (long) x->x_offset, SEEK_SET) < 0) { + error(" sfplay can't seek to byte %ld",(long) x->x_offset); + x->x_offset = x->x_skip; + x->skip = 1; + return 0; + } + #ifdef DEBUG_ME - post("sfplay:skip to %f",x->x_offset); + post("sfplay:skip to %f",x->x_offset); #endif - return 1; + return 1; } /* Input, method for Start stop */ static void sfplay_start(t_sfplay *x) { - long of = x->offset * sys_getsr() * x->x_channels; - - if(of < 0) of = x->x_skip; - else of += x->x_skip; /* offset in sec */ + long of = x->offset * sys_getsr() * x->x_channels; + + if(of < 0) { + of = x->x_skip; + } else { + of += x->x_skip; /* offset in sec */ + } + + of &= ~0x111l; /* no odds please (8 channels boundary) */ - of &= ~0x111l; /* no odds please (8 channels boundary) */ - #ifdef DEBUG_ME - post("sfplay: start"); + post("sfplay: start"); #endif - - /* new offset postion ? (fom inlet offset) */ - if( ((t_float) of) != x->x_offset) - { - x->skip=1; - x->x_offset = of; - } - x->play=1; + + /* new offset postion ? (fom inlet offset) */ + if( ((t_float) of) != x->x_offset) { + x->skip=1; + x->x_offset = of; + } + x->play=1; } static void sfplay_stop(t_sfplay *x) { -#ifdef DEBUG_ME - post("sfplay: stop"); +#ifdef DEBUG_ME + post("sfplay: stop"); #endif - x->play=0; - x->please_stop = 1; + x->play=0; + x->please_stop = 1; } static void sfplay_float(t_sfplay *x, t_floatarg f) { - int t = f; - if (t) sfplay_start(x); - else sfplay_stop(x); + int t = f; + if (t) { + sfplay_start(x); + } else { + sfplay_stop(x); + } } /* start playing at position offset*/ static void sfplay_offset(t_sfplay *x, t_floatarg f) { - x->offset = f; - x->skip = 1; - /* correction in sfplay_play() */ - + x->offset = f; + x->skip = 1; + /* correction in sfplay_play() */ + #ifdef DEBUG_ME - post("sfplay: offset %f",f); + post("sfplay: offset %f",f); #endif - return; + return; } static void sfplay_rewind(t_sfplay *x) { #ifdef DEBUG_ME - post("sfplay: rewind to %f",x->x_skip); + post("sfplay: rewind to %f",x->x_skip); #endif - - if(!x->fp)return; - - x->play=0; - fseek(x->fp,(long) x->x_skip,SEEK_SET); + + if(!x->fp) { + return; + } + + x->play=0; + fseek(x->fp,(long) x->x_skip,SEEK_SET); } /* restart with bang */ static void sfplay_bang(t_sfplay* x) { - x->skip = 1; - sfplay_start(x); + x->skip = 1; + sfplay_start(x); } static t_int *sfplay_perform(t_int *w) { - t_sfplay* x = (t_sfplay*)(w[1]); - short* buf = x->filep; - int c = x->x_channels; - - int i,j,n; - t_float* out[MAX_CHANS]; - - short s; - int swap = x->swap; - - for (i=0;istate){ - - /* just wait */ - case SFPLAY_WAIT: - - if(x->fp != NULL){ + t_sfplay* x = (t_sfplay*)(w[1]); + short* buf = x->filep; + int c = x->x_channels; + + int i,j,n; + t_float* out[MAX_CHANS]; + + short s; + int swap = x->swap; + + for (i=0; istate) { + + /* just wait */ + case SFPLAY_WAIT: + + if(x->fp != NULL) { #ifdef DEBUG_ME - post("wait -> open"); + post("wait -> open"); #endif - x->state = SFPLAY_OPEN; - x->count = SFPLAY_WAITTICKS; - }; - break; - - /* if in open state, already opened but wait for skip */ - case SFPLAY_OPEN: /* file hase opened wait some time */ - - if(!(x->count--)){ + x->state = SFPLAY_OPEN; + x->count = SFPLAY_WAITTICKS; + }; + break; + + /* if in open state, already opened but wait for skip */ + case SFPLAY_OPEN: /* file hase opened wait some time */ + + if(!(x->count--)) { #ifdef DEBUG_ME - post("open -> skip"); + post("open -> skip"); #endif - x->state = SFPLAY_SKIP; - x->count = SFPLAY_WAITTICKS; - }; - - break; - - - /* in skipmode wait until ready for stop */ - case SFPLAY_SKIP: - - - if(x->count == SFPLAY_WAITTICKS) - { - if(!x->fp) - { - x->state = SFPLAY_CLOSE; - x->count=1; + x->state = SFPLAY_SKIP; + x->count = SFPLAY_WAITTICKS; + }; + + break; + + + /* in skipmode wait until ready for stop */ + case SFPLAY_SKIP: + + + if(x->count == SFPLAY_WAITTICKS) { + if(!x->fp) { + x->state = SFPLAY_CLOSE; + x->count=1; #ifdef DEBUG_ME - post("skip -> close"); + post("skip -> close"); #endif - break; - } - sfplay_skip(x); + break; } - if(!(x->count--)) - { + sfplay_skip(x); + } + if(!(x->count--)) { #ifdef DEBUG_ME - post("skip -> stop"); + post("skip -> stop"); #endif - x->state = SFPLAY_STOP; - x->count = SFPLAY_WAITTICKS; - }; - break; - - - - case SFPLAY_STOP: /* in stop state mainly waits for play */ - - x->please_stop = 0; - - if(x->please_close) - { - x->state = SFPLAY_CLOSE; - x->count = SFPLAY_WAITTICKS; + x->state = SFPLAY_STOP; + x->count = SFPLAY_WAITTICKS; + }; + break; + + + + case SFPLAY_STOP: /* in stop state mainly waits for play */ + + x->please_stop = 0; + + if(x->please_close) { + x->state = SFPLAY_CLOSE; + x->count = SFPLAY_WAITTICKS; #ifdef DEBUG_ME - post("stop -> close"); + post("stop -> close"); #endif - } - else if(x->skip) - { - x->state = SFPLAY_SKIP; - x->count = SFPLAY_WAITTICKS; + } else if(x->skip) { + x->state = SFPLAY_SKIP; + x->count = SFPLAY_WAITTICKS; #ifdef DEBUG_ME - post("stop -> skip"); + post("stop -> skip"); #endif - } - else if(x->play) - { + } else if(x->play) { #ifdef DEBUG_ME - post("stop -> play"); + post("stop -> play"); #endif - x->state = SFPLAY_PLAY; - } - break; - - - case SFPLAY_PLAY: /* yes play now */ - - - if(!x->play || x->please_stop) - { - - /* if closing dont need o go to stop */ - if(x->please_close) - { - x->state = SFPLAY_CLOSE; - x->count = SFPLAY_WAITTICKS; + x->state = SFPLAY_PLAY; + } + break; + + + case SFPLAY_PLAY: /* yes play now */ + + + if(!x->play || x->please_stop) { + + /* if closing dont need o go to stop */ + if(x->please_close) { + x->state = SFPLAY_CLOSE; + x->count = SFPLAY_WAITTICKS; #ifdef DEBUG_ME - post("play -> close"); + post("play -> close"); #endif - } - else - { - x->state = SFPLAY_STOP; + } else { + x->state = SFPLAY_STOP; #ifdef DEBUG_ME - post("play -> stop"); + post("play -> stop"); #endif - }; - break; - } - - /* should never happen */ - if(!x->filep){ - x->state = SFPLAY_ERROR; - error("sfplay: playing but no buffer ???? play"); - return (w+4+c); + }; + break; + } + + /* should never happen */ + if(!x->filep) { + x->state = SFPLAY_ERROR; + error("sfplay: playing but no buffer ???? play"); + return (w+4+c); + } + + /* first read soundfile 16 bit*/ + if((j=fread(buf,sizeof(short),c*n,x->fp)) < n) { + + outlet_bang(x->bangout); + + if(feof(x->fp)) { + + while (n--) { + for (i=0; i 0) { + s = *buf++; + if(swap) { + s = ((s & 0xFF)<< 8) | ((s& 0xFF00) >> 8); + } + *out[i]++ = s*(1./32768.); + } else { + *out[i]++ = 0; + } + } + } + + x->state = SFPLAY_STOP; + x->play = 0; + return(w+c+4); } - - /* first read soundfile 16 bit*/ - if((j=fread(buf,sizeof(short),c*n,x->fp)) < n) - { - - outlet_bang(x->bangout); - - if(feof(x->fp)){ - - while (n--) { - for (i=0;i 0){ - s = *buf++; - if(swap) s = ((s & 0xFF)<< 8) | ((s& 0xFF00) >> 8); - *out[i]++ = s*(1./32768.); - } - else *out[i]++ = 0; - } - } - - x->state = SFPLAY_STOP; - x->play = 0; - return(w+c+4); - } - - /* or error if(ferror()) */ - x->state = SFPLAY_ERROR; - x->count = SFPLAY_WAITTICKS; + + /* or error if(ferror()) */ + x->state = SFPLAY_ERROR; + x->count = SFPLAY_WAITTICKS; #ifdef DEBUG_ME - post("play -> read error"); + post("play -> read error"); #endif - break; - }; - - /* copy 16 Bit to floats and swap if neccesairy */ - while (n--) { - for (i=0;i> 8); - *out[i]++ = s*(1./32768.); - } + break; + }; + + /* copy 16 Bit to floats and swap if neccesairy */ + while (n--) { + for (i=0; i> 8); + } + *out[i]++ = s*(1./32768.); } - return (w+c+4); /* dont zero out outs */ - - /* ok read error please close */ - case SFPLAY_ERROR: - - if(!(x->count--)){ - x->state = SFPLAY_CLOSE; - sfplay_close(x); + } + return (w+c+4); /* dont zero out outs */ + + /* ok read error please close */ + case SFPLAY_ERROR: + + if(!(x->count--)) { + x->state = SFPLAY_CLOSE; + sfplay_close(x); #ifdef DEBUG_ME - post("sfplay error reading sf: error -> close"); + post("sfplay error reading sf: error -> close"); #endif - x->count = SFPLAY_WAITTICKS; - } - break; - - /* in close state go to wait afterwards */ - case SFPLAY_CLOSE: - - x->please_close = 0; + x->count = SFPLAY_WAITTICKS; + } + break; + + /* in close state go to wait afterwards */ + case SFPLAY_CLOSE: - /* wait until ready for close operation */ - if(!(x->count--)){ + x->please_close = 0; - x->state = SFPLAY_WAIT; - x->count = SFPLAY_WAITTICKS; - - /* avoid openfiles */ - if(x->fp){fclose(x->fp);x->fp = NULL;}; + /* wait until ready for close operation */ + if(!(x->count--)) { + + x->state = SFPLAY_WAIT; + x->count = SFPLAY_WAITTICKS; + + /* avoid openfiles */ + if(x->fp) { + fclose(x->fp); + x->fp = NULL; + }; #ifdef DEBUG_ME - post("sfplay: close -> wait"); + post("sfplay: close -> wait"); #endif - } - break; - - }; /*case */ - - /* zero out outs */ - while (n--) { - for (i=0;ix_channels) { - case 1: - dsp_add(sfplay_perform, 4, x, - sp[0]->s_vec, - sp[1]->s_vec, /* out 1 */ - sp[0]->s_n); - break; - case 2: - dsp_add(sfplay_perform, 5, x, - sp[0]->s_vec, /* out 1*/ - sp[1]->s_vec, /* out 2*/ - sp[2]->s_vec, - sp[0]->s_n); - break; - case 4: - dsp_add(sfplay_perform, 7, x, - sp[0]->s_vec, - sp[1]->s_vec, - sp[2]->s_vec, - sp[3]->s_vec, - sp[4]->s_vec, - sp[0]->s_n); - break; - case 8: - dsp_add(sfplay_perform, 11, x, - sp[0]->s_vec, - sp[1]->s_vec, - sp[2]->s_vec, - sp[3]->s_vec, - sp[4]->s_vec, - sp[5]->s_vec, - sp[6]->s_vec, - sp[7]->s_vec, - sp[8]->s_vec, - sp[0]->s_n); - break; - } + switch (x->x_channels) { + case 1: + dsp_add(sfplay_perform, 4, x, + sp[0]->s_vec, + sp[1]->s_vec, /* out 1 */ + sp[0]->s_n); + break; + case 2: + dsp_add(sfplay_perform, 5, x, + sp[0]->s_vec, /* out 1*/ + sp[1]->s_vec, /* out 2*/ + sp[2]->s_vec, + sp[0]->s_n); + break; + case 4: + dsp_add(sfplay_perform, 7, x, + sp[0]->s_vec, + sp[1]->s_vec, + sp[2]->s_vec, + sp[3]->s_vec, + sp[4]->s_vec, + sp[0]->s_n); + break; + case 8: + dsp_add(sfplay_perform, 11, x, + sp[0]->s_vec, + sp[1]->s_vec, + sp[2]->s_vec, + sp[3]->s_vec, + sp[4]->s_vec, + sp[5]->s_vec, + sp[6]->s_vec, + sp[7]->s_vec, + sp[8]->s_vec, + sp[0]->s_n); + break; + } } /* create sfplay with args */ static void *sfplay_new(t_floatarg chan,t_floatarg skip) { - t_sfplay *x = (t_sfplay *)pd_new(sfplay_class); - t_int c = chan; - - switch(c){ - /* ok */ - case 1: case 2: case 4: case 8: break; - /* try it, good luck ... */ - case 3: c = 2; break; - case 5: case 6: case 7: c=7; break; - default: c=1; break; - } - - floatinlet_new(&x->x_obj, &x->offset); /* inlet 2 */ - /* floatinlet_new(&x->x_obj, &x->speed); *//* inlet 3 */ - - x->x_channels = c; - x->x_skip = x->x_offset = skip; - x->offset = 0.; - x->skip = 1; - x->x_speed = 1.0; - x->play = 0; - x->please_stop = 0; - x->please_close = 0; - x->state = SFPLAY_WAIT; - x->count = 0; - x->filename = NULL; - x->fp = NULL; - x->swap = 1; - - while (c--) { - outlet_new(&x->x_obj, gensym("signal")); /* channels outlet */ - } - x->bangout = outlet_new(&x->x_obj, gensym("bang")); - - x->filep = t_getbytes(DACBLKSIZE*sizeof(short)*x->x_channels); - + t_sfplay *x = (t_sfplay *)pd_new(sfplay_class); + t_int c = chan; + + switch(c) { + /* ok */ + case 1: + case 2: + case 4: + case 8: + break; + /* try it, good luck ... */ + case 3: + c = 2; + break; + case 5: + case 6: + case 7: + c=7; + break; + default: + c=1; + break; + } + + floatinlet_new(&x->x_obj, &x->offset); /* inlet 2 */ + /* floatinlet_new(&x->x_obj, &x->speed); *//* inlet 3 */ + + x->x_channels = c; + x->x_skip = x->x_offset = skip; + x->offset = 0.; + x->skip = 1; + x->x_speed = 1.0; + x->play = 0; + x->please_stop = 0; + x->please_close = 0; + x->state = SFPLAY_WAIT; + x->count = 0; + x->filename = NULL; + x->fp = NULL; + x->swap = 1; + + while (c--) { + outlet_new(&x->x_obj, gensym("signal")); /* channels outlet */ + } + x->bangout = outlet_new(&x->x_obj, gensym("bang")); + + x->filep = t_getbytes(DACBLKSIZE*sizeof(short)*x->x_channels); + #ifdef DEBUG_ME - post("get_bytes DACBLKSIZE*%d*%d->%ld",sizeof(short),x->x_channels,x->filep); - post("sfplay: x_channels = %d, x_speed = %f, x_skip = %f",x->x_channels,x->x_speed,x->x_skip); + post("get_bytes DACBLKSIZE*%d*%d->%ld",sizeof(short),x->x_channels, + x->filep); + post("sfplay: x_channels = %d, x_speed = %f, x_skip = %f",x->x_channels, + x->x_speed,x->x_skip); #endif - - return (x); + + return (x); } static void sfplay_free(t_sfplay *x) { - freebytes(x->filep, DACBLKSIZE*sizeof(short)*x->x_channels); + freebytes(x->filep, DACBLKSIZE*sizeof(short)*x->x_channels); } void sfplay_setup(void) { - sfplay_class = class_new(gensym("sfplay"), (t_newmethod)sfplay_new, (t_method)sfplay_free, - sizeof(t_sfplay), 0, A_DEFFLOAT, A_DEFFLOAT,0); - class_addmethod(sfplay_class, nullfn, gensym("signal"), 0); - class_addmethod(sfplay_class, (t_method)sfplay_dsp, gensym("dsp"), 0); - - class_addmethod(sfplay_class, (t_method)sfplay_helper, gensym("help"), A_NULL); - class_sethelpsymbol(sfplay_class, gensym("sf-play_record")); - - /* method open with filename */ - class_addmethod(sfplay_class, (t_method)sfplay_open, gensym("open"), A_SYMBOL,A_SYMBOL,A_NULL); - class_addmethod(sfplay_class, (t_method)sfplay_close, gensym("close"), A_NULL); - - class_addmethod(sfplay_class, (t_method)sfplay_start, gensym("start"), A_NULL); - class_addmethod(sfplay_class, (t_method)sfplay_stop, gensym("stop"), A_NULL); - class_addmethod(sfplay_class, (t_method)sfplay_rewind, gensym("rewind"), A_NULL); - class_addmethod(sfplay_class, (t_method)sfplay_offset, gensym("goto"), A_DEFFLOAT, A_NULL); - - /* start stop with 0 and 1 */ - class_addfloat(sfplay_class, sfplay_float); - /* start with bang */ - class_addbang(sfplay_class,sfplay_bang); + sfplay_class = class_new(gensym("sfplay"), (t_newmethod)sfplay_new, + (t_method)sfplay_free, + sizeof(t_sfplay), 0, A_DEFFLOAT, A_DEFFLOAT,0); + class_addmethod(sfplay_class, nullfn, gensym("signal"), 0); + class_addmethod(sfplay_class, (t_method)sfplay_dsp, gensym("dsp"), 0); + + class_addmethod(sfplay_class, (t_method)sfplay_helper, gensym("help"), + A_NULL); + class_sethelpsymbol(sfplay_class, gensym("sf-play_record")); + + /* method open with filename */ + class_addmethod(sfplay_class, (t_method)sfplay_open, gensym("open"), + A_SYMBOL,A_SYMBOL,A_NULL); + class_addmethod(sfplay_class, (t_method)sfplay_close, gensym("close"), + A_NULL); + + class_addmethod(sfplay_class, (t_method)sfplay_start, gensym("start"), + A_NULL); + class_addmethod(sfplay_class, (t_method)sfplay_stop, gensym("stop"), + A_NULL); + class_addmethod(sfplay_class, (t_method)sfplay_rewind, gensym("rewind"), + A_NULL); + class_addmethod(sfplay_class, (t_method)sfplay_offset, gensym("goto"), + A_DEFFLOAT, A_NULL); + + /* start stop with 0 and 1 */ + class_addfloat(sfplay_class, sfplay_float); + /* start with bang */ + class_addbang(sfplay_class,sfplay_bang); zexy_register("sfplay"); } diff --git a/src/sfrecord.c b/src/sfrecord.c index b4329ce..f215621 100644 --- a/src/sfrecord.c +++ b/src/sfrecord.c @@ -1,4 +1,4 @@ -/* +/* * sfrecord: multichannel soundfile recorder (try [writesf~] instead) * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,18 +7,18 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ /* -sfplay.c - Author: Winfried Ritsch - IEM Graz 10.Mai 99 - +sfplay.c - Author: Winfried Ritsch - IEM Graz 10.Mai 99 - Modified: sfrecord.c - hacked from sfplay ::: 2308:forum::für::umläute:1999 @ iem @@ -55,31 +55,30 @@ zmoelnig@iem.kug.ac.at static t_class *sfrecord_class; -typedef struct _sfrecord -{ - t_object x_obj; - - void* filep; /* pointer to file data read in mem */ - t_symbol* filename; /* filename */ - - /* - because there is no command queue, - flags are used instead - */ - t_int write; /* write: 1, stop: 0 */ - t_int please_stop; /* can be reset only by stop-state itself */ - t_int please_close; /* can be reset only by close-state */ - t_int x_channels; /* channels to write */ - t_float x_offset; /* offset to start writing */ - t_float offset; /* inlet value offset in secs */ - t_float x_skip; /* skip bytes because header */ - t_int skip; /* pending skip if 1 */ - t_float x_speed; /* write speed, not supported in this version */ - t_int size; /* size of file (if memory mapped) */ - t_int swap; /* swap bytes from l->b or b->m */ - FILE *fp; /* file oper non-NULL of open */ - t_int state; /* which state is writer in */ - t_int count; /* count for ticks before next step */ +typedef struct _sfrecord { + t_object x_obj; + + void* filep; /* pointer to file data read in mem */ + t_symbol* filename; /* filename */ + + /* + because there is no command queue, + flags are used instead + */ + t_int write; /* write: 1, stop: 0 */ + t_int please_stop; /* can be reset only by stop-state itself */ + t_int please_close; /* can be reset only by close-state */ + t_int x_channels; /* channels to write */ + t_float x_offset; /* offset to start writing */ + t_float offset; /* inlet value offset in secs */ + t_float x_skip; /* skip bytes because header */ + t_int skip; /* pending skip if 1 */ + t_float x_speed; /* write speed, not supported in this version */ + t_int size; /* size of file (if memory mapped) */ + t_int swap; /* swap bytes from l->b or b->m */ + FILE *fp; /* file oper non-NULL of open */ + t_int state; /* which state is writer in */ + t_int count; /* count for ticks before next step */ } t_sfrecord; @@ -94,67 +93,71 @@ typedef struct _sfrecord #define SFRECORD_WAITTICKS 10 /* 1 tick of 64 Samples is ca.1.5ms on 441000 */ -/* split the os-calls in as many steps as possible +/* split the os-calls in as many steps as possible to split them on different ticks in steps of SFRECORD_WAITTICKS to avoid peak performance */ /* like the one from garray */ -static int sfrecord_am_i_big_endian(void) +static int sfrecord_am_i_big_endian(void) { - unsigned short s = 1; - unsigned char c = *(char *) (&s); + unsigned short s = 1; + unsigned char c = *(char *) (&s); #ifdef DEBUG_ME - post("i am %s-endian", c?"little":"big"); + post("i am %s-endian", c?"little":"big"); #endif - return(c==0); + return(c==0); } static void state_out(t_sfrecord *x, int state) -{ /* outlet the actual state */ - outlet_float(x->x_obj.ob_outlet, state); +{ + /* outlet the actual state */ + outlet_float(x->x_obj.ob_outlet, state); } /* METHOD: "open" file */ -/* this dont use memory map, because I dont know about this on NT ? -Use of the buffered functions fopen, fseek fread fclose instead the +/* this dont use memory map, because I dont know about this on NT ? +Use of the buffered functions fopen, fseek fread fclose instead the non buffered ones open read close */ -static void sfrecord_open(t_sfrecord *x,t_symbol *filename,t_symbol *endian) +static void sfrecord_open(t_sfrecord *x,t_symbol *filename, + t_symbol *endian) { - if(x->state != SFRECORD_WAIT) - { - post("sfrecord: first close %s before open %s",x->filename->s_name,filename->s_name); - return; - } - - /* test if big endian else asume little endian + if(x->state != SFRECORD_WAIT) { + post("sfrecord: first close %s before open %s",x->filename->s_name, + filename->s_name); + return; + } + + /* test if big endian else asume little endian * should be 'l' but could be anything */ - if(sfrecord_am_i_big_endian()) - x->swap = !(endian->s_name[0] == 'b'); - else - x->swap = (endian->s_name[0] == 'b'); - - /* - * skip header after open;; sometimes weŽll have to write a header using the x->skip; so donŽt delete it completely + if(sfrecord_am_i_big_endian()) { + x->swap = !(endian->s_name[0] == 'b'); + } else { + x->swap = (endian->s_name[0] == 'b'); + } + + /* + * skip header after open;; sometimes weŽll have to write a header using the x->skip; so donŽt delete it completely */ /* x->skip = 1; */ - x->filename = filename; + x->filename = filename; #ifdef DEBUG_ME - post("sfrecord: opening %s",x->filename->s_name); + post("sfrecord: opening %s",x->filename->s_name); #endif - if (x->fp != NULL)fclose(x->fp); /* should not happen */ + if (x->fp != NULL) { + fclose(x->fp); /* should not happen */ + } - if (!(x->fp = fopen(x->filename->s_name,BINWRITEMODE))) - { - error("sfrecord: can't open %s", x->filename->s_name); - } + if (!(x->fp = fopen(x->filename->s_name,BINWRITEMODE))) { + error("sfrecord: can't open %s", x->filename->s_name); + } } @@ -162,35 +165,37 @@ static void sfrecord_open(t_sfrecord *x,t_symbol *filename,t_symbol *endian) /* METHOD: close */ static void sfrecord_close(t_sfrecord *x) { - x->write = 0; - x->please_close = 1; + x->write = 0; + x->please_close = 1; - /* now in state machine - if(x->fp != NULL) - { - fclose(x->fp); - x->fp = NULL; - } - */ + /* now in state machine + if(x->fp != NULL) + { + fclose(x->fp); + x->fp = NULL; + } + */ #ifdef DEBUG_ME - post("sfrecord: closing "); + post("sfrecord: closing "); #endif - return; + return; } /* for skipping header of soundfile DonŽt use this for memory map */ static int sfrecord_skip(t_sfrecord *x) { - if(!x->skip) return 0; + if(!x->skip) { + return 0; + } #ifdef DEBUG_ME - post("sfrecord:skip to %f",x->x_skip); + post("sfrecord:skip to %f",x->x_skip); #endif - x->skip = 0; - return 1; + x->skip = 0; + return 1; } /* Input, method for Start stop */ @@ -198,35 +203,42 @@ static int sfrecord_skip(t_sfrecord *x) static void sfrecord_start(t_sfrecord *x) { #ifdef DEBUG_ME - post("sfrecord: start at %d", x->x_offset); + post("sfrecord: start at %d", x->x_offset); #endif - state_out(x, 1); - x->write=1; + state_out(x, 1); + x->write=1; } static void sfrecord_stop(t_sfrecord *x) { #ifdef DEBUG_ME - post("sfrecord: stop"); + post("sfrecord: stop"); #endif - state_out(x, 0); + state_out(x, 0); - x->write=0; - x->please_stop = 1; + x->write=0; + x->please_stop = 1; } static void sfrecord_float(t_sfrecord *x, t_floatarg f) { - int t = f; - if (t) sfrecord_start(x); - else sfrecord_stop(x); + int t = f; + if (t) { + sfrecord_start(x); + } else { + sfrecord_stop(x); + } } /* say what state weŽre in */ static void sfrecord_bang(t_sfrecord* x) { - if (x->state == SFRECORD_WRITE) state_out(x, 1); else state_out(x, 0); + if (x->state == SFRECORD_WRITE) { + state_out(x, 1); + } else { + state_out(x, 0); + } } /* ******************************************************************************** */ @@ -236,229 +248,227 @@ static void sfrecord_bang(t_sfrecord* x) static t_int *sfrecord_perform(t_int *w) { - t_sfrecord* x = (t_sfrecord*)(w[1]); - short* buf = x->filep; - short* bufstart = buf; - int c = x->x_channels; + t_sfrecord* x = (t_sfrecord*)(w[1]); + short* buf = x->filep; + short* bufstart = buf; + int c = x->x_channels; - int i,j,n, s_n; - t_float* in[MAX_CHANS]; + int i,j,n, s_n; + t_float* in[MAX_CHANS]; - short s; - int swap = x->swap; + short s; + int swap = x->swap; - for (i=0;istate){ + switch(x->state) { - /* just wait */ - case SFRECORD_WAIT: + /* just wait */ + case SFRECORD_WAIT: - if(x->fp != NULL){ + if(x->fp != NULL) { #ifdef DEBUG_ME - post("wait -> open"); + post("wait -> open"); #endif - x->state = SFRECORD_OPEN; - x->count = SFRECORD_WAITTICKS; - }; - break; + x->state = SFRECORD_OPEN; + x->count = SFRECORD_WAITTICKS; + }; + break; - /* if in open state, already opened but wait for skip */ - case SFRECORD_OPEN: /* file has opened wait some time */ + /* if in open state, already opened but wait for skip */ + case SFRECORD_OPEN: /* file has opened wait some time */ - if(!(x->count--)){ + if(!(x->count--)) { #ifdef DEBUG_ME - post("open -> skip"); + post("open -> skip"); #endif - x->state = SFRECORD_SKIP; - x->count = SFRECORD_WAITTICKS; - }; + x->state = SFRECORD_SKIP; + x->count = SFRECORD_WAITTICKS; + }; - break; + break; - /* in skipmode wait until ready for stop */ - case SFRECORD_SKIP: + /* in skipmode wait until ready for stop */ + case SFRECORD_SKIP: - if(x->count == SFRECORD_WAITTICKS) - { - if(!x->fp) - { - x->state = SFRECORD_CLOSE; - x->count=1; + if(x->count == SFRECORD_WAITTICKS) { + if(!x->fp) { + x->state = SFRECORD_CLOSE; + x->count=1; #ifdef DEBUG_ME - post("skip -> close"); + post("skip -> close"); #endif - break; - } - sfrecord_skip(x); - } - if(!(x->count--)) - { + break; + } + sfrecord_skip(x); + } + if(!(x->count--)) { #ifdef DEBUG_ME - post("skip -> stop"); + post("skip -> stop"); #endif - x->state = SFRECORD_STOP; - x->count = SFRECORD_WAITTICKS; - }; - break; + x->state = SFRECORD_STOP; + x->count = SFRECORD_WAITTICKS; + }; + break; - case SFRECORD_STOP: /* in stop state mainly waits for write */ + case SFRECORD_STOP: /* in stop state mainly waits for write */ - x->please_stop = 0; + x->please_stop = 0; - if(x->please_close) - { - x->state = SFRECORD_CLOSE; - x->count = SFRECORD_WAITTICKS; + if(x->please_close) { + x->state = SFRECORD_CLOSE; + x->count = SFRECORD_WAITTICKS; #ifdef DEBUG_ME - post("stop -> close"); + post("stop -> close"); #endif - } - else if(x->skip) - { - x->state = SFRECORD_SKIP; - x->count = SFRECORD_WAITTICKS; + } else if(x->skip) { + x->state = SFRECORD_SKIP; + x->count = SFRECORD_WAITTICKS; #ifdef DEBUG_ME - post("stop -> skip"); + post("stop -> skip"); #endif - } - else if(x->write) - { + } else if(x->write) { #ifdef DEBUG_ME - post("stop -> write"); + post("stop -> write"); #endif - x->state = SFRECORD_WRITE; - state_out(x, 1); - } - break; - - case SFRECORD_WRITE: /* yes write now */ - - if(!x->write || x->please_stop) - { - /* if closing dont need to go to stop */ - if(x->please_close) { - x->state = SFRECORD_CLOSE; - x->count = SFRECORD_WAITTICKS; + x->state = SFRECORD_WRITE; + state_out(x, 1); + } + break; + + case SFRECORD_WRITE: /* yes write now */ + + if(!x->write || x->please_stop) { + /* if closing dont need to go to stop */ + if(x->please_close) { + x->state = SFRECORD_CLOSE; + x->count = SFRECORD_WAITTICKS; #ifdef DEBUG_ME - post("write -> close"); + post("write -> close"); #endif - state_out(x, 0); + state_out(x, 0); - } - else { - x->state = SFRECORD_STOP; + } else { + x->state = SFRECORD_STOP; #ifdef DEBUG_ME - post("write -> stop"); + post("write -> stop"); #endif - }; - break; - } - - /* should never happen */ - if(!x->filep){ - x->state = SFRECORD_ERROR; - error("sfrecord: writing but no buffer ???? write"); - return (w+4+c); - } - - /* copy float to 16 Bit and swap if neccesairy */ /* LATER treat overflows */ - while (n--) { - for (i=0;i> 8); - *buf++ = s; - } - } - - /* then write soundfile 16 bit*/ - if ( (j = fwrite(bufstart, sizeof(short), c*s_n, x->fp)) < 1) { - x->state = SFRECORD_ERROR; - x->count = SFRECORD_WAITTICKS; + }; + break; + } + + /* should never happen */ + if(!x->filep) { + x->state = SFRECORD_ERROR; + error("sfrecord: writing but no buffer ???? write"); + return (w+4+c); + } + + /* copy float to 16 Bit and swap if neccesairy */ /* LATER treat overflows */ + while (n--) { + for (i=0; i> 8); + } + *buf++ = s; + } + } + + /* then write soundfile 16 bit*/ + if ( (j = fwrite(bufstart, sizeof(short), c*s_n, x->fp)) < 1) { + x->state = SFRECORD_ERROR; + x->count = SFRECORD_WAITTICKS; #ifdef DEBUG_ME - post("write -> write error\t %xd\t%xd\t%d\t%d", x->filep, buf, c*s_n*sizeof(short), j); + post("write -> write error\t %xd\t%xd\t%d\t%d", x->filep, buf, + c*s_n*sizeof(short), j); #endif - break; - } + break; + } #if 0 - if((j=fwrite(buf,sizeof(short),c*n,x->fp)) < (unsigned int) n) - { - if(feof(x->fp)){ - - while (n--) { - for (i=0;i 0){ - s = *buf++; - if(swap) s = ((s & 0xFF)<< 8) | ((s& 0xFF00) >> 8); - *out[i]++ = s*(1./32768.); - } - else - *out[i]++ = 0; - } - } - } - - x->state = SFRECORD_STOP; - x->write = 0; - return(w+c+3); - } - /* or error if(ferror()) */ - x->state = SFRECORD_ERROR; - x->count = SFRECORD_WAITTICKS; + if((j=fwrite(buf,sizeof(short),c*n,x->fp)) < (unsigned int) n) { + if(feof(x->fp)) { + + while (n--) { + for (i=0; i 0) { + s = *buf++; + if(swap) { + s = ((s & 0xFF)<< 8) | ((s& 0xFF00) >> 8); + } + *out[i]++ = s*(1./32768.); + } else { + *out[i]++ = 0; + } + } + } + } + + x->state = SFRECORD_STOP; + x->write = 0; + return(w+c+3); + } + /* or error if(ferror()) */ + x->state = SFRECORD_ERROR; + x->count = SFRECORD_WAITTICKS; #ifdef DEBUG_ME - post("write -> write error"); + post("write -> write error"); #endif - break; - }; + break; + }; #endif /* 0 */ - return (w+c+3); /* writing was fine */ + return (w+c+3); /* writing was fine */ - /* ok :?: write error, please close */ - case SFRECORD_ERROR: + /* ok :?: write error, please close */ +case SFRECORD_ERROR: - if(!(x->count--)) { - x->state = SFRECORD_CLOSE; - sfrecord_close(x); + if(!(x->count--)) { + x->state = SFRECORD_CLOSE; + sfrecord_close(x); #ifdef DEBUG_ME - post("sfrecord error writing sf: error -> close"); + post("sfrecord error writing sf: error -> close"); #endif - x->count = SFRECORD_WAITTICKS; - } - break; + x->count = SFRECORD_WAITTICKS; + } + break; - /* in close state go to wait afterwards */ - case SFRECORD_CLOSE: + /* in close state go to wait afterwards */ +case SFRECORD_CLOSE: - x->please_close = 0; + x->please_close = 0; - /* wait until ready for close operation */ - if(!(x->count--)){ + /* wait until ready for close operation */ + if(!(x->count--)) { - x->state = SFRECORD_WAIT; - x->count = SFRECORD_WAITTICKS; + x->state = SFRECORD_WAIT; + x->count = SFRECORD_WAITTICKS; - /* avoid openfiles */ - if(x->fp){fclose(x->fp);x->fp = NULL;}; + /* avoid openfiles */ + if(x->fp) { + fclose(x->fp); + x->fp = NULL; + }; #ifdef DEBUG_ME - post("sfrecord: close -> wait"); + post("sfrecord: close -> wait"); #endif - } - break; + } + break; - }; /*case */ +}; /*case */ - return(w+c+3); +return(w+c+3); } @@ -470,139 +480,160 @@ static void sfrecord_dsp(t_sfrecord *x, t_signal **sp) { #ifdef DEBUG_ME - post("sfrecord: dsp"); - post("offset = %f\tspeed = %f\t", x->offset, x->x_speed); + post("sfrecord: dsp"); + post("offset = %f\tspeed = %f\t", x->offset, x->x_speed); #endif - switch (x->x_channels) { - case 1: - dsp_add(sfrecord_perform, 3, x, - sp[0]->s_vec, /* in 1 */ - sp[0]->s_n); - break; - case 2: - dsp_add(sfrecord_perform, 4, x, - sp[0]->s_vec, - sp[1]->s_vec, - sp[0]->s_n); - break; - case 4: - dsp_add(sfrecord_perform, 6, x, - sp[0]->s_vec, - sp[1]->s_vec, - sp[2]->s_vec, - sp[3]->s_vec, - sp[0]->s_n); - break; - case 8: - dsp_add(sfrecord_perform, 9, x, - sp[0]->s_vec, - sp[1]->s_vec, - sp[2]->s_vec, - sp[3]->s_vec, - sp[4]->s_vec, - sp[5]->s_vec, - sp[6]->s_vec, - sp[7]->s_vec, - sp[0]->s_n); - break; - } + switch (x->x_channels) { + case 1: + dsp_add(sfrecord_perform, 3, x, + sp[0]->s_vec, /* in 1 */ + sp[0]->s_n); + break; + case 2: + dsp_add(sfrecord_perform, 4, x, + sp[0]->s_vec, + sp[1]->s_vec, + sp[0]->s_n); + break; + case 4: + dsp_add(sfrecord_perform, 6, x, + sp[0]->s_vec, + sp[1]->s_vec, + sp[2]->s_vec, + sp[3]->s_vec, + sp[0]->s_n); + break; + case 8: + dsp_add(sfrecord_perform, 9, x, + sp[0]->s_vec, + sp[1]->s_vec, + sp[2]->s_vec, + sp[3]->s_vec, + sp[4]->s_vec, + sp[5]->s_vec, + sp[6]->s_vec, + sp[7]->s_vec, + sp[0]->s_n); + break; + } } /* create sfrecord with args */ static void *sfrecord_new(t_floatarg chan) { - t_sfrecord *x = (t_sfrecord *)pd_new(sfrecord_class); - t_int c = chan; - - switch(c){ - /* ok */ - case 1: case 2: case 4: case 8: break; - /* try it, good luck ... */ - case 3: c = 2; break; - case 5: case 6: case 7: c=7; break; - default: c=1; break; - } - - outlet_new(&x->x_obj, gensym("float")); - - x->x_channels = c; - x->x_skip = x->x_offset = 0; - x->skip = 1; - x->offset = 0.; - x->x_speed = 1.0; - x->write = 0; - x->please_stop = 0; - x->please_close = 0; - x->state = SFRECORD_WAIT; - x->count = 0; - x->filename = NULL; - x->fp = NULL; - x->swap = 1; - - c--; - - while (c--) { + t_sfrecord *x = (t_sfrecord *)pd_new(sfrecord_class); + t_int c = chan; + + switch(c) { + /* ok */ + case 1: + case 2: + case 4: + case 8: + break; + /* try it, good luck ... */ + case 3: + c = 2; + break; + case 5: + case 6: + case 7: + c=7; + break; + default: + c=1; + break; + } + + outlet_new(&x->x_obj, gensym("float")); + + x->x_channels = c; + x->x_skip = x->x_offset = 0; + x->skip = 1; + x->offset = 0.; + x->x_speed = 1.0; + x->write = 0; + x->please_stop = 0; + x->please_close = 0; + x->state = SFRECORD_WAIT; + x->count = 0; + x->filename = NULL; + x->fp = NULL; + x->swap = 1; + + c--; + + while (c--) { #ifdef DEBUG_ME - post("create extra channel #%d", c); + post("create extra channel #%d", c); #endif - inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("signal"), gensym("signal")); /* channels inlet */ - } + inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("signal"), + gensym("signal")); /* channels inlet */ + } - x->filep = t_getbytes(DACBLKSIZE*sizeof(short)*x->x_channels); + x->filep = t_getbytes(DACBLKSIZE*sizeof(short)*x->x_channels); #ifdef DEBUG_ME - post("get_bytes DACBLKSIZE*%d*%d->%ld",sizeof(short),x->x_channels,x->filep); - post("sfrecord: x_channels = %d, x_speed = %f, x_skip = %f",x->x_channels,x->x_speed,x->x_skip); + post("get_bytes DACBLKSIZE*%d*%d->%ld",sizeof(short),x->x_channels, + x->filep); + post("sfrecord: x_channels = %d, x_speed = %f, x_skip = %f",x->x_channels, + x->x_speed,x->x_skip); #endif - return (x); + return (x); } static void sfrecord_helper(void) { - post("\nsfplay :: a raw-data soundfile-recorder"); - post("\ncreation :: sfrecord \t: channels set the number of channels"); - post("\nopen [] []\t:: open b(ig) or l(ittle) endian file" - "\nclose\t\t\t:: close file (aka eject)" - "\nstart\t\t\t:: start playing" - "\nstop\t\t\t:: stop playing" - "\nbang\t\t\t:: outputs the current state (1_recording, 0_not-recording)"); - - post("\n\nyou can also start recording with a '1', and stop with a '0'"); + post("\nsfplay :: a raw-data soundfile-recorder"); + post("\ncreation :: sfrecord \t: channels set the number of channels"); + post("\nopen [] []\t:: open b(ig) or l(ittle) endian file" + "\nclose\t\t\t:: close file (aka eject)" + "\nstart\t\t\t:: start playing" + "\nstop\t\t\t:: stop playing" + "\nbang\t\t\t:: outputs the current state (1_recording, 0_not-recording)"); + + post("\n\nyou can also start recording with a '1', and stop with a '0'"); } static void sfrecord_free(t_sfrecord *x) { - freebytes(x->filep, DACBLKSIZE*sizeof(short)*x->x_channels); + freebytes(x->filep, DACBLKSIZE*sizeof(short)*x->x_channels); } void sfrecord_setup(void) { - sfrecord_class = class_new(gensym("sfrecord"), (t_newmethod)sfrecord_new, (t_method)sfrecord_free, - sizeof(t_sfrecord), 0, A_DEFFLOAT, A_DEFFLOAT,0); - class_addmethod(sfrecord_class, nullfn, gensym("signal"), 0); - class_addmethod(sfrecord_class, (t_method)sfrecord_dsp, gensym("dsp"), 0); - - /* method open with filename */ - class_addmethod(sfrecord_class, (t_method)sfrecord_open, gensym("open"), A_SYMBOL,A_SYMBOL,A_NULL); - class_addmethod(sfrecord_class, (t_method)sfrecord_close, gensym("close"), A_NULL); - - class_addmethod(sfrecord_class, (t_method)sfrecord_start, gensym("start"), A_NULL); - class_addmethod(sfrecord_class, (t_method)sfrecord_stop, gensym("stop"), A_NULL); - - /* start/stop with 0/1 */ - class_addfloat(sfrecord_class, sfrecord_float); - - /* bang out the current-state to the outlet*/ - class_addbang(sfrecord_class,sfrecord_bang); - - /* some help */ - class_addmethod(sfrecord_class, (t_method)sfrecord_helper, gensym("help"), A_NULL); - class_sethelpsymbol(sfrecord_class, gensym("sf-play_record")); + sfrecord_class = class_new(gensym("sfrecord"), (t_newmethod)sfrecord_new, + (t_method)sfrecord_free, + sizeof(t_sfrecord), 0, A_DEFFLOAT, A_DEFFLOAT,0); + class_addmethod(sfrecord_class, nullfn, gensym("signal"), 0); + class_addmethod(sfrecord_class, (t_method)sfrecord_dsp, gensym("dsp"), 0); + + /* method open with filename */ + class_addmethod(sfrecord_class, (t_method)sfrecord_open, gensym("open"), + A_SYMBOL,A_SYMBOL,A_NULL); + class_addmethod(sfrecord_class, (t_method)sfrecord_close, gensym("close"), + A_NULL); + + class_addmethod(sfrecord_class, (t_method)sfrecord_start, gensym("start"), + A_NULL); + class_addmethod(sfrecord_class, (t_method)sfrecord_stop, gensym("stop"), + A_NULL); + + /* start/stop with 0/1 */ + class_addfloat(sfrecord_class, sfrecord_float); + + /* bang out the current-state to the outlet*/ + class_addbang(sfrecord_class,sfrecord_bang); + + /* some help */ + class_addmethod(sfrecord_class, (t_method)sfrecord_helper, gensym("help"), + A_NULL); + class_sethelpsymbol(sfrecord_class, gensym("sf-play_record")); zexy_register("sfrecord"); } diff --git a/src/sgn~.c b/src/sgn~.c index 5341694..3bba110 100644 --- a/src/sgn~.c +++ b/src/sgn~.c @@ -1,4 +1,4 @@ -/* +/* * sgn~: sign of a signal * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,20 +7,19 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ #include "zexySIMD.h" -typedef struct _sgnTilde -{ +typedef struct _sgnTilde { t_object x_obj; } t_sgnTilde; @@ -37,11 +36,15 @@ static t_int *sgnTilde_perform(t_int *w) t_sample x; while (n--) { x=*in++; - if (x>0.) *out++=1.; - else if (x<0.) *out++=-1.; - else *out++=0.; + if (x>0.) { + *out++=1.; + } else if (x<0.) { + *out++=-1.; + } else { + *out++=0.; + } } - + return (w+4); } static t_int *sgnTilde_perform8(t_int *w) @@ -51,26 +54,74 @@ static t_int *sgnTilde_perform8(t_int *w) int n = (int)(w[3])>>3; t_sample x; - while(n--){ + while(n--) { /* weirdly enough, the if/else/if/else is a lot faster than ()?:(()?:) */ - if ((x=in[0])>0.) out[0]=1.; else if(x<0.) out[0]=-1.; else out[0]=0.; - if ((x=in[1])>0.) out[1]=1.; else if(x<0.) out[1]=-1.; else out[1]=0.; - if ((x=in[2])>0.) out[2]=1.; else if(x<0.) out[2]=-1.; else out[2]=0.; - if ((x=in[3])>0.) out[3]=1.; else if(x<0.) out[3]=-1.; else out[3]=0.; - if ((x=in[4])>0.) out[4]=1.; else if(x<0.) out[4]=-1.; else out[4]=0.; - if ((x=in[5])>0.) out[5]=1.; else if(x<0.) out[5]=-1.; else out[5]=0.; - if ((x=in[6])>0.) out[6]=1.; else if(x<0.) out[6]=-1.; else out[6]=0.; - if ((x=in[7])>0.) out[7]=1.; else if(x<0.) out[7]=-1.; else out[7]=0.; + if ((x=in[0])>0.) { + out[0]=1.; + } else if(x<0.) { + out[0]=-1.; + } else { + out[0]=0.; + } + if ((x=in[1])>0.) { + out[1]=1.; + } else if(x<0.) { + out[1]=-1.; + } else { + out[1]=0.; + } + if ((x=in[2])>0.) { + out[2]=1.; + } else if(x<0.) { + out[2]=-1.; + } else { + out[2]=0.; + } + if ((x=in[3])>0.) { + out[3]=1.; + } else if(x<0.) { + out[3]=-1.; + } else { + out[3]=0.; + } + if ((x=in[4])>0.) { + out[4]=1.; + } else if(x<0.) { + out[4]=-1.; + } else { + out[4]=0.; + } + if ((x=in[5])>0.) { + out[5]=1.; + } else if(x<0.) { + out[5]=-1.; + } else { + out[5]=0.; + } + if ((x=in[6])>0.) { + out[6]=1.; + } else if(x<0.) { + out[6]=-1.; + } else { + out[6]=0.; + } + if ((x=in[7])>0.) { + out[7]=1.; + } else if(x<0.) { + out[7]=-1.; + } else { + out[7]=0.; + } in+=8; out+=8; } - + return (w+4); } #ifdef __SSE__ -static int l_bitmask[]={0x80000000, 0x80000000, 0x80000000, 0x80000000}; /* sign bitmask */ +static int l_bitmask[]= {0x80000000, 0x80000000, 0x80000000, 0x80000000}; /* sign bitmask */ static t_int *sgnTilde_performSSE(t_int *w) { __m128 *in = (__m128 *)(w[1]); @@ -111,17 +162,17 @@ static void sgnTilde_dsp(t_sgnTilde *x, t_signal **sp) { #ifdef __SSE__ if( - Z_SIMD_CHKBLOCKSIZE(sp[0]->s_n) && - Z_SIMD_CHKALIGN(sp[0]->s_vec) && - Z_SIMD_CHKALIGN(sp[1]->s_vec) && - ZEXY_TYPE_EQUAL(t_sample, float) && /* currently SSE2 code is only for float (not for double) */ - zexy_testSSE(sgnTilde_perform, - sgnTilde_performSSE, - 1,1) - ) - { - dsp_add(sgnTilde_performSSE, 3, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n); - } else + Z_SIMD_CHKBLOCKSIZE(sp[0]->s_n) && + Z_SIMD_CHKALIGN(sp[0]->s_vec) && + Z_SIMD_CHKALIGN(sp[1]->s_vec) && + ZEXY_TYPE_EQUAL(t_sample, float) + && /* currently SSE2 code is only for float (not for double) */ + zexy_testSSE(sgnTilde_perform, + sgnTilde_performSSE, + 1,1) + ) { + dsp_add(sgnTilde_performSSE, 3, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n); + } else #endif if (sp[0]->s_n & 7) { dsp_add(sgnTilde_perform , 3, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n); @@ -140,7 +191,7 @@ static void *sgnTilde_new(void) { t_sgnTilde *x = (t_sgnTilde *)pd_new(sgnTilde_class); outlet_new(&x->x_obj, gensym("signal")); - + return (x); } @@ -150,8 +201,9 @@ void sgn_tilde_setup(void) sizeof(t_sgnTilde), 0, A_DEFFLOAT, 0); class_addmethod(sgnTilde_class, nullfn, gensym("signal"), 0); class_addmethod(sgnTilde_class, (t_method)sgnTilde_dsp, gensym("dsp"), 0); - - class_addmethod(sgnTilde_class, (t_method)sgnTilde_helper, gensym("help"), 0); + + class_addmethod(sgnTilde_class, (t_method)sgnTilde_helper, gensym("help"), + 0); class_sethelpsymbol(sgnTilde_class, gensym("zigbinops")); zexy_register("sgn~"); } diff --git a/src/sigzero~.c b/src/sigzero~.c index e78f1a0..8494b04 100644 --- a/src/sigzero~.c +++ b/src/sigzero~.c @@ -1,4 +1,4 @@ -/* +/* * sigzero~: detect whether an entire signal vector is 0 * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -28,8 +28,7 @@ static t_class *sigzero_class; -typedef struct _sigzero -{ +typedef struct _sigzero { t_object x_obj; int activate; int current; /* 0 == (signalblock == 0); 1==(signalblock != 0) */ @@ -59,13 +58,12 @@ static t_int *sigzero_perform(t_int *w) int non_zero = 0; if (x->activate) { - while (n--) - { - if (*in++ != 0.) { - non_zero = 1; - break; - } + while (n--) { + if (*in++ != 0.) { + non_zero = 1; + break; } + } if (non_zero != x->current) { outlet_float(x->x_obj.ob_outlet, x->current = non_zero); } @@ -108,6 +106,7 @@ void sigzero_tilde_setup(void) class_addmethod(sigzero_class, nullfn, gensym("signal"), 0); class_addmethod(sigzero_class, (t_method)sigzero_dsp, gensym("dsp"), 0); - class_addmethod(sigzero_class, (t_method)sigzero_tilde_helper, gensym("help"), 0); + class_addmethod(sigzero_class, (t_method)sigzero_tilde_helper, + gensym("help"), 0); zexy_register("sigzero~"); } diff --git a/src/sleepgrain.c b/src/sleepgrain.c index 8805ff8..8fe75ce 100644 --- a/src/sleepgrain.c +++ b/src/sleepgrain.c @@ -1,4 +1,4 @@ -/* +/* * sleepgrain : get (and set?) the sleepgrain of Pd * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -26,8 +26,7 @@ EXTERN int* get_sys_sleepgrain(void ) ; static t_class *sleepgrain_class; -typedef struct _sleepgrain -{ +typedef struct _sleepgrain { t_object x_obj; } t_sleepgrain; @@ -64,9 +63,10 @@ static void *sleepgrain_new(void) void sleepgrain_setup(void) { - sleepgrain_class = class_new(gensym("sleepgrain"), (t_newmethod)sleepgrain_new, - 0, sizeof(t_sleepgrain), 0, A_NULL); - + sleepgrain_class = class_new(gensym("sleepgrain"), + (t_newmethod)sleepgrain_new, + 0, sizeof(t_sleepgrain), 0, A_NULL); + class_addbang (sleepgrain_class, sleepgrain_bang); class_addfloat (sleepgrain_class, sleepgrain_float); zexy_register("sleepgrain"); diff --git a/src/sort.c b/src/sort.c index 0850445..4bd92c0 100644 --- a/src/sort.c +++ b/src/sort.c @@ -1,4 +1,4 @@ -/* +/* * sort : sort a list of floats * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -27,8 +27,7 @@ static t_class *sort_class; -typedef struct _sort -{ +typedef struct _sort { t_object x_obj; int bufsize; @@ -53,8 +52,12 @@ static void sort_buffer(t_sort *x, int argc, t_atom *argv) t_atom *atombuf = argv; if (argc != x->bufsize) { - if (x->buffer) freebytes(x->buffer, x->bufsize * sizeof(t_float)); - if (x->indices)freebytes(x->indices, x->bufsize * sizeof(t_int)); + if (x->buffer) { + freebytes(x->buffer, x->bufsize * sizeof(t_float)); + } + if (x->indices) { + freebytes(x->indices, x->bufsize * sizeof(t_int)); + } x->bufsize = argc; x->buffer = getbytes(x->bufsize * sizeof(t_float)); @@ -62,7 +65,7 @@ static void sort_buffer(t_sort *x, int argc, t_atom *argv) } buf = x->buffer; - while (n--){ + while (n--) { *buf++ = atom_getfloat(atombuf++); x->indices[n] = n; } @@ -101,17 +104,25 @@ static void sort_list(t_sort *x, t_symbol *s, int argc, t_atom *argv) } } - if (x->ascending) - for (n = 0; n < argc; n++) SETFLOAT(&atombuf[n], idx[n]); + if (x->ascending) + for (n = 0; n < argc; n++) { + SETFLOAT(&atombuf[n], idx[n]); + } else - for (n = 0, i=argc-1; n < argc; n++, i--) SETFLOAT(&atombuf[n], idx[i]); + for (n = 0, i=argc-1; n < argc; n++, i--) { + SETFLOAT(&atombuf[n], idx[i]); + } outlet_list(x->indexOut , gensym("list"), n, atombuf); - if (x->ascending) - for (n = 0; n < argc; n++) SETFLOAT(&atombuf[n], buf[n]); + if (x->ascending) + for (n = 0; n < argc; n++) { + SETFLOAT(&atombuf[n], buf[n]); + } else - for (n = 0, i=argc-1; n < argc; n++, i--) SETFLOAT(&atombuf[n], buf[i]); + for (n = 0, i=argc-1; n < argc; n++, i--) { + SETFLOAT(&atombuf[n], buf[i]); + } outlet_list(x->sortedOut, gensym("list"), n, atombuf); @@ -129,7 +140,8 @@ static void *sort_new(t_floatarg f) x->bufsize = 0; x->buffer = NULL; - inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("direction")); + inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), + gensym("direction")); return (x); } @@ -140,11 +152,12 @@ static void sort_help(t_sort*x) } void sort_setup(void) { - sort_class = class_new(gensym("sort"), (t_newmethod)sort_new, + sort_class = class_new(gensym("sort"), (t_newmethod)sort_new, 0, sizeof(t_sort), 0, A_DEFFLOAT, 0); - + class_addlist (sort_class, sort_list); - class_addmethod (sort_class, (t_method)sort_dir, gensym("direction"), A_DEFFLOAT, 0); + class_addmethod (sort_class, (t_method)sort_dir, gensym("direction"), + A_DEFFLOAT, 0); class_addmethod(sort_class, (t_method)sort_help, gensym("help"), A_NULL); zexy_register("sort"); diff --git a/src/step~.c b/src/step~.c index 4558819..d55d1c5 100644 --- a/src/step~.c +++ b/src/step~.c @@ -1,4 +1,4 @@ -/* +/* * step~: unity step function * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,18 +7,18 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ /* - step~ : will make a unity step at a desired point in the signal-vector; the second input specifies a + step~ : will make a unity step at a desired point in the signal-vector; the second input specifies a length: after the so-specified time has elapsed, the step will toggle back to the previous value; the length can be passed as an argument when creating the object @@ -31,12 +31,11 @@ #include "zexy.h" -/* ------------------------ step~ ----------------------------- */ +/* ------------------------ step~ ----------------------------- */ static t_class *step_class; -typedef struct _step -{ +typedef struct _step { t_object x_obj; int position; int length; @@ -54,10 +53,10 @@ static void step_bang(t_step *x) static void step_float(t_step *x, t_float where) { - x->wait4stop = x->length + - (x->wait4start = - (x->position = (where>0)*where) - ); + x->wait4stop = x->length + + (x->wait4start = + (x->position = (where>0)*where) + ); } static void step_setlength(t_step *x, t_float arg) @@ -77,15 +76,17 @@ static t_int *step_perform(t_int *w) int wait4start = x->wait4start, wait4stop = x->wait4stop; - while (n--) - { - wait4stop--; - if (!wait4start--) toggle ^= 1; - else if (!wait4stop) toggle ^= 1; - - *out++ = toggle; + while (n--) { + wait4stop--; + if (!wait4start--) { + toggle ^= 1; + } else if (!wait4stop) { + toggle ^= 1; } + *out++ = toggle; + } + x->wait4start = wait4start; x->wait4stop = wait4stop; @@ -127,15 +128,16 @@ static void *step_new(t_floatarg farg) return (x); } - + void step_tilde_setup(void) { step_class = class_new(gensym("step~"), (t_newmethod)step_new, 0, sizeof(t_step), 0, A_DEFFLOAT, 0); class_addfloat(step_class, step_float); - class_addbang(step_class, step_bang); - class_addmethod(step_class, (t_method)step_setlength, gensym("ft1"), A_FLOAT, 0); + class_addbang(step_class, step_bang); + class_addmethod(step_class, (t_method)step_setlength, gensym("ft1"), + A_FLOAT, 0); class_addmethod(step_class, (t_method)step_dsp, gensym("dsp"), 0); class_addmethod(step_class, (t_method)step_helper, gensym("help"), 0); diff --git a/src/strcmp.c b/src/strcmp.c index bf5a4dc..15d5890 100644 --- a/src/strcmp.c +++ b/src/strcmp.c @@ -1,4 +1,4 @@ -/* +/* * strcmp : compare 2 lists as if they were strings * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -29,8 +29,7 @@ static t_class *strcmp_class; static t_class *strcmp_proxy_class; -typedef struct _strcmp -{ +typedef struct _strcmp { t_object x_obj; struct _strcmp_proxy *x_proxy; @@ -39,8 +38,7 @@ typedef struct _strcmp int n1, n2; } t_strcmp; -typedef struct _strcmp_proxy -{ +typedef struct _strcmp_proxy { t_pd p_pd; t_strcmp *p_master; t_inlet *p_in; @@ -49,26 +47,31 @@ typedef struct _strcmp_proxy static void strcmp_bang(t_strcmp *x) { int result = 0; - if(x->str1){ - if(x->str2) + if(x->str1) { + if(x->str2) { result = strcmp(x->str1, x->str2); - else + } else { result = *x->str1; + } } else { - if(x->str2) + if(x->str2) { result = -*x->str2; - else + } else { result = 0; + } } outlet_float(x->x_obj.ob_outlet, result); } -static void list2binbuf(t_binbuf**bbuf, int *n, char**str, int argc, t_atom*argv) +static void list2binbuf(t_binbuf**bbuf, int *n, char**str, int argc, + t_atom*argv) { int i=0; char*s=0; - if(*str&&*n)freebytes(*str, *n); + if(*str&&*n) { + freebytes(*str, *n); + } binbuf_clear(*bbuf); binbuf_add(*bbuf, argc, argv); @@ -76,40 +79,51 @@ static void list2binbuf(t_binbuf**bbuf, int *n, char**str, int argc, t_atom*argv i=*n; s=*str; - if(' '==s[i])s[i]=0; + if(' '==s[i]) { + s[i]=0; + } } -static void strcmp_list(t_strcmp *x, t_symbol* UNUSED(s), int argc, t_atom *argv) +static void strcmp_list(t_strcmp *x, t_symbol* UNUSED(s), int argc, + t_atom *argv) { list2binbuf(&x->bbuf1, &x->n1, &x->str1, argc, argv); strcmp_bang(x); } static void strcmp_symbol(t_strcmp *x, t_symbol *s) { - if(x->str1&&x->n1)freebytes(x->str1, x->n1); + if(x->str1&&x->n1) { + freebytes(x->str1, x->n1); + } x->n1=0; x->str1=s->s_name; strcmp_bang(x); } -static void strcmp_secondlist(t_strcmp *x, t_symbol* UNUSED(s), int argc, t_atom *argv) +static void strcmp_secondlist(t_strcmp *x, t_symbol* UNUSED(s), int argc, + t_atom *argv) { list2binbuf(&x->bbuf2, &x->n2, &x->str2, argc, argv); } static void strcmp_secondsymbol(t_strcmp *x, t_symbol *s) { - if(x->str2&&x->n2)freebytes(x->str2, x->n2); + if(x->str2&&x->n2) { + freebytes(x->str2, x->n2); + } x->n2=0; x->str2=s->s_name; } -static void strcmp_proxy_list(t_strcmp_proxy *y, t_symbol *s, int argc, t_atom *argv) +static void strcmp_proxy_list(t_strcmp_proxy *y, t_symbol *s, int argc, + t_atom *argv) { strcmp_secondlist(y->p_master, s, argc, argv); } static void strcmp_proxy_symbol(t_strcmp_proxy *y, t_symbol *s) { - if(s)strcmp_secondsymbol(y->p_master, s); + if(s) { + strcmp_secondsymbol(y->p_master, s); + } } static void *strcmp_new(t_symbol* UNUSED(s), int argc, t_atom *argv) @@ -130,7 +144,9 @@ static void *strcmp_new(t_symbol* UNUSED(s), int argc, t_atom *argv) x->n1=0; x->n2=0; - if(argc)strcmp_secondlist(x, gensym("list"), argc, argv); + if(argc) { + strcmp_secondlist(x, gensym("list"), argc, argv); + } return (x); } @@ -139,8 +155,12 @@ static void strcmp_free(t_strcmp *x) { binbuf_free(x->bbuf1); binbuf_free(x->bbuf2); - if(x->str1&&x->n1)freebytes(x->str1, x->n1); - if(x->str2&&x->n2)freebytes(x->str2, x->n2); + if(x->str1&&x->n1) { + freebytes(x->str1, x->n1); + } + if(x->str2&&x->n2) { + freebytes(x->str2, x->n2); + } inlet_free(x->x_proxy->p_in); x->x_proxy->p_master=0; @@ -156,8 +176,8 @@ static void strcmp_help(t_strcmp*x) void strcmp_setup(void) { - strcmp_class = class_new(gensym("strcmp"), (t_newmethod)strcmp_new, - (t_method)strcmp_free, sizeof(t_strcmp), 0, A_GIMME, 0); + strcmp_class = class_new(gensym("strcmp"), (t_newmethod)strcmp_new, + (t_method)strcmp_free, sizeof(t_strcmp), 0, A_GIMME, 0); class_addbang (strcmp_class, strcmp_bang); class_addsymbol (strcmp_class, strcmp_symbol); @@ -168,6 +188,7 @@ void strcmp_setup(void) CLASS_PD | CLASS_NOINLET, 0); class_addsymbol(strcmp_proxy_class, strcmp_proxy_symbol); class_addlist(strcmp_proxy_class, strcmp_proxy_list); - class_addmethod(strcmp_class, (t_method)strcmp_help, gensym("help"), A_NULL); + class_addmethod(strcmp_class, (t_method)strcmp_help, gensym("help"), + A_NULL); zexy_register("strcmp"); } diff --git a/src/sum.c b/src/sum.c index 606e082..419b9d0 100644 --- a/src/sum.c +++ b/src/sum.c @@ -1,4 +1,4 @@ -/* +/* * sum :: the sum of a list of floats * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -21,8 +21,7 @@ static t_class *sum_class; -typedef struct _sum -{ +typedef struct _sum { t_object x_obj; } t_sum; @@ -30,7 +29,9 @@ static void sum_list(t_sum *x, t_symbol* UNUSED(s), int argc, t_atom *argv) { t_float sum = 0.f; - while(argc--)sum+=atom_getfloat(argv++); + while(argc--) { + sum+=atom_getfloat(argv++); + } outlet_float(x->x_obj.ob_outlet,sum); } @@ -52,7 +53,7 @@ static void sum_help(void) void sum_setup(void) { sum_class = class_new(gensym("sum"), (t_newmethod)sum_new, 0, - sizeof(t_sum), 0, A_DEFFLOAT, 0); + sizeof(t_sum), 0, A_DEFFLOAT, 0); class_addlist(sum_class, (t_method)sum_list); class_addmethod(sum_class, (t_method)sum_help, gensym("help"), 0); diff --git a/src/swap~.c b/src/swap~.c index 05fd4b9..4f26cdb 100644 --- a/src/swap~.c +++ b/src/swap~.c @@ -1,4 +1,4 @@ -/* +/* * swap~: byteswap a 16bit signal * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -32,8 +32,7 @@ static t_class *swap_class; -typedef struct _swap -{ +typedef struct _swap { t_object x_obj; int swapper; } t_swap; @@ -56,13 +55,16 @@ static t_int *swap_perform(t_int *w) int n = (int)(w[4]); - if (x->swapper) + if (x->swapper) while (n--) { - short dummy = FLOAT2SHORT * *in++; - *out++ = SHORT2FLOAT * (short)( ((dummy & 0xFF) << 8) | ((dummy & 0xFF00) >> 8) ); + short dummy = FLOAT2SHORT **in++; + *out++ = SHORT2FLOAT * (short)( ((dummy & 0xFF) << 8) | (( + dummy & 0xFF00) >> 8) ); } - else while (n--) *out++ = *in++; - + else while (n--) { + *out++ = *in++; + } + return (w+5); } @@ -92,13 +94,13 @@ static void *swap_new(void) void swap_tilde_setup(void) { swap_class = class_new(gensym("swap~"), (t_newmethod)swap_new, 0, - sizeof(t_swap), 0, A_NULL); + sizeof(t_swap), 0, A_NULL); class_addmethod(swap_class, nullfn, gensym("signal"), 0); class_addmethod(swap_class, (t_method)swap_dsp, gensym("dsp"), 0); - + class_addfloat(swap_class, swap_float); class_addbang(swap_class, swap_bang); - + class_addmethod(swap_class, (t_method)swap_helper, gensym("help"), 0); zexy_register("swap~"); } diff --git a/src/symbol2list.c b/src/symbol2list.c index 5d7e74a..5c49481 100644 --- a/src/symbol2list.c +++ b/src/symbol2list.c @@ -1,4 +1,4 @@ -/* +/* * symbol2list: convert a symbol into a list (with given delimiters) * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -25,19 +25,21 @@ static t_class *symbol2list_class; -typedef struct _symbol2list -{ +typedef struct _symbol2list { t_object x_obj; t_symbol *s, *delimiter; t_atom *argv; - int argc, argnum; /* "argnum" is the number of reserved atoms (might be >argc) */ + int argc, + argnum; /* "argnum" is the number of reserved atoms (might be >argc) */ } t_symbol2list; -static void symbol2list_delimiter(t_symbol2list *x, t_symbol *s){ +static void symbol2list_delimiter(t_symbol2list *x, t_symbol *s) +{ x->delimiter = s; } -STATIC_INLINE void string2atom(t_atom *ap, char* cp, int clen){ +STATIC_INLINE void string2atom(t_atom *ap, char* cp, int clen) +{ char *buffer=getbytes(sizeof(char)*(clen+1)); char *endptr[1]; t_float ftest; @@ -49,9 +51,9 @@ STATIC_INLINE void string2atom(t_atom *ap, char* cp, int clen){ * symbol "hallo 0x12" will become "list hallo 18" * do we want this ?? */ - if (buffer+clen!=*endptr){ + if (buffer+clen!=*endptr) { /* strtof() failed, we have a symbol */ - SETSYMBOL(ap, gensym(buffer)); + SETSYMBOL(ap, gensym(buffer)); } else { /* it is a number. */ SETFLOAT(ap,ftest); @@ -66,39 +68,41 @@ static void symbol2list_process(t_symbol2list *x) char *cp, *d; int i=1; - if (x->s==NULL){ + if (x->s==NULL) { x->argc=0; return; } cc=x->s->s_name; cp=cc; - - if (x->delimiter==NULL || x->delimiter==gensym("")){ + + if (x->delimiter==NULL || x->delimiter==gensym("")) { i=strlen(cc); - if(x->argnumargnumargv, x->argnum*sizeof(t_atom)); x->argnum=i+10; x->argv=getbytes(x->argnum*sizeof(t_atom)); } x->argc=i; - while(i--)string2atom(x->argv+i, cc+i, 1); + while(i--) { + string2atom(x->argv+i, cc+i, 1); + } return; } deli=x->delimiter->s_name; dell=strlen(deli); - + /* get the number of tokens */ - while((d=strstr(cp, deli))){ - if (d!=NULL && d!=cp){ + while((d=strstr(cp, deli))) { + if (d!=NULL && d!=cp) { i++; } cp=d+dell; } /* resize the list-buffer if necessary */ - if(x->argnumargnumargv, x->argnum*sizeof(t_atom)); x->argnum=i+10; x->argv=getbytes(x->argnum*sizeof(t_atom)); @@ -106,29 +110,37 @@ static void symbol2list_process(t_symbol2list *x) x->argc=i; /* parse the tokens into the list-buffer */ i=0; - - /* find the first token */ - cp=cc; - while(cp==(d=strstr(cp,deli))){cp+=dell;} - while((d=strstr(cp, deli))){ - if(d!=cp){ - string2atom(x->argv+i, cp, d-cp); - i++; - } - cp=d+dell; + + /* find the first token */ + cp=cc; + while(cp==(d=strstr(cp,deli))) { + cp+=dell; + } + while((d=strstr(cp, deli))) { + if(d!=cp) { + string2atom(x->argv+i, cp, d-cp); + i++; } + cp=d+dell; + } - if(cp)string2atom(x->argv+i, cp, strlen(cp)); + if(cp) { + string2atom(x->argv+i, cp, strlen(cp)); + } } -static void symbol2list_bang(t_symbol2list *x){ - if(!(x->s) || x->s==gensym("")){ +static void symbol2list_bang(t_symbol2list *x) +{ + if(!(x->s) || x->s==gensym("")) { outlet_bang(x->x_obj.ob_outlet); return; } symbol2list_process(x); - if(x->argc)outlet_list(x->x_obj.ob_outlet, 0, x->argc, x->argv); + if(x->argc) { + outlet_list(x->x_obj.ob_outlet, 0, x->argc, x->argv); + } } -static void symbol2list_symbol(t_symbol2list *x, t_symbol *s){ +static void symbol2list_symbol(t_symbol2list *x, t_symbol *s) +{ x->s = s; symbol2list_bang(x); } @@ -143,7 +155,7 @@ static void *symbol2list_new(t_symbol* UNUSED(s), int argc, t_atom *argv) x->argnum=16; x->argv=getbytes(x->argnum*sizeof(t_atom)); symbol2list_delimiter(x, (argc)?atom_getsymbol(argv):gensym(" ")); - + return (x); } @@ -157,14 +169,17 @@ static void symbol2list_help(t_symbol2list*x) void symbol2list_setup(void) { - symbol2list_class = class_new(gensym("symbol2list"), (t_newmethod)symbol2list_new, - (t_method)symbol2list_free, sizeof(t_symbol2list), 0, A_GIMME, 0); + symbol2list_class = class_new(gensym("symbol2list"), + (t_newmethod)symbol2list_new, + (t_method)symbol2list_free, sizeof(t_symbol2list), 0, A_GIMME, 0); class_addcreator((t_newmethod)symbol2list_new, gensym("s2l"), A_GIMME, 0); class_addsymbol (symbol2list_class, symbol2list_symbol); class_addbang (symbol2list_class, symbol2list_bang); - class_addmethod (symbol2list_class, (t_method)symbol2list_delimiter, gensym(""), A_SYMBOL, 0); - class_addmethod(symbol2list_class, (t_method)symbol2list_help, gensym("help"), A_NULL); + class_addmethod (symbol2list_class, (t_method)symbol2list_delimiter, + gensym(""), A_SYMBOL, 0); + class_addmethod(symbol2list_class, (t_method)symbol2list_help, + gensym("help"), A_NULL); zexy_register("symbol2list"); } diff --git a/src/tabdump.c b/src/tabdump.c index ad1b86f..3129d6e 100644 --- a/src/tabdump.c +++ b/src/tabdump.c @@ -1,4 +1,4 @@ -/* +/* * tabdump: get the content of a table as a list of floats * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -23,8 +23,7 @@ static t_class *tabdump_class; -typedef struct _tabdump -{ +typedef struct _tabdump { t_object x_obj; t_symbol *x_arrayname; t_int startindex, stopindex; @@ -36,32 +35,38 @@ static void tabdump_bang(t_tabdump *x) int npoints; zarray_t *vec; - if (!(A = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) + if (!(A = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) { error("%s: no such array", x->x_arrayname->s_name); - else if (!zarray_getarray(A, &npoints, &vec)) + } else if (!zarray_getarray(A, &npoints, &vec)) { error("%s: bad template for tabdump", x->x_arrayname->s_name); - else - { - int n; - t_atom *atombuf; - - int start=x->startindex; - int stop =x->stopindex; - if(start<0||start>stop)start=0; - if(stopnpoints)stop=npoints; - npoints=stop-start; - - atombuf = (t_atom *)getbytes(sizeof(t_atom)*npoints); - for (n = 0; n < npoints; n++) SETFLOAT(&atombuf[n], zarray_getfloat(vec, start+n)); - outlet_list(x->x_obj.ob_outlet, gensym("list"), npoints, atombuf); - freebytes(atombuf,sizeof(t_atom)*npoints); + } else { + int n; + t_atom *atombuf; + + int start=x->startindex; + int stop =x->stopindex; + if(start<0||start>stop) { + start=0; + } + if(stopnpoints) { + stop=npoints; } + npoints=stop-start; + + atombuf = (t_atom *)getbytes(sizeof(t_atom)*npoints); + for (n = 0; n < npoints; n++) { + SETFLOAT(&atombuf[n], zarray_getfloat(vec, start+n)); + } + outlet_list(x->x_obj.ob_outlet, gensym("list"), npoints, atombuf); + freebytes(atombuf,sizeof(t_atom)*npoints); + } } -static void tabdump_list(t_tabdump *x, t_symbol* UNUSED(s),int argc, t_atom*argv) +static void tabdump_list(t_tabdump *x, t_symbol* UNUSED(s),int argc, + t_atom*argv) { int a,b; - switch(argc){ + switch(argc) { case 2: a=atom_getint(argv); b=atom_getint(argv+1); @@ -103,13 +108,14 @@ static void tabdump_helper(void) void tabdump_setup(void) { tabdump_class = class_new(gensym("tabdump"), (t_newmethod)tabdump_new, - 0, sizeof(t_tabdump), 0, A_DEFSYM, 0); + 0, sizeof(t_tabdump), 0, A_DEFSYM, 0); class_addbang(tabdump_class, (t_method)tabdump_bang); class_addlist(tabdump_class, (t_method)tabdump_list); class_addmethod(tabdump_class, (t_method)tabdump_set, gensym("set"), - A_SYMBOL, 0); + A_SYMBOL, 0); - class_addmethod(tabdump_class, (t_method)tabdump_helper, gensym("help"), 0); + class_addmethod(tabdump_class, (t_method)tabdump_helper, gensym("help"), + 0); zexy_register("tabdump"); } diff --git a/src/tabminmax.c b/src/tabminmax.c index 8353ae3..796d8f7 100644 --- a/src/tabminmax.c +++ b/src/tabminmax.c @@ -1,4 +1,4 @@ -/* +/* * tabminmax: get minimum and maximum of a table * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -24,8 +24,7 @@ static t_class *tabminmax_class; -typedef struct _tabminmax -{ +typedef struct _tabminmax { t_object x_obj; t_outlet*min_out, *max_out; t_symbol *x_arrayname; @@ -38,55 +37,59 @@ static void tabminmax_bang(t_tabminmax *x) int npoints; zarray_t *vec; - if (!(A = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) + if (!(A = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) { error("%s: no such array", x->x_arrayname->s_name); - else if (!zarray_getarray(A, &npoints, &vec)) + } else if (!zarray_getarray(A, &npoints, &vec)) { error("%s: bad template for tabminmax", x->x_arrayname->s_name); - else - { - int n; - t_atom atombuf[2]; - t_float min, max; - int mindex, maxdex; - - int start=x->startindex; - int stop =x->stopindex; - if(start<0||start>stop)start=0; - if(stopnpoints)stop=npoints; - npoints=stop-start; - - min=zarray_getfloat(vec, start); - max=min; - - mindex=start; - maxdex=start; - - for (n = 1; n < npoints; n++){ - t_float val=zarray_getfloat(vec, start+n); - if(valmax){ - maxdex=start+n; - max=val; - } + } else { + int n; + t_atom atombuf[2]; + t_float min, max; + int mindex, maxdex; + + int start=x->startindex; + int stop =x->stopindex; + if(start<0||start>stop) { + start=0; + } + if(stopnpoints) { + stop=npoints; + } + npoints=stop-start; + + min=zarray_getfloat(vec, start); + max=min; + + mindex=start; + maxdex=start; + + for (n = 1; n < npoints; n++) { + t_float val=zarray_getfloat(vec, start+n); + if(valmax) { + maxdex=start+n; + max=val; } - - SETFLOAT(atombuf, max); - SETFLOAT(atombuf+1, maxdex); - outlet_list(x->max_out, gensym("list"), 2, atombuf); - - SETFLOAT(atombuf, min); - SETFLOAT(atombuf+1, mindex); - outlet_list(x->min_out, gensym("list"), 2, atombuf); } + + SETFLOAT(atombuf, max); + SETFLOAT(atombuf+1, maxdex); + outlet_list(x->max_out, gensym("list"), 2, atombuf); + + SETFLOAT(atombuf, min); + SETFLOAT(atombuf+1, mindex); + outlet_list(x->min_out, gensym("list"), 2, atombuf); + } } -static void tabminmax_list(t_tabminmax *x, t_symbol* UNUSED(s),int argc, t_atom*argv) +static void tabminmax_list(t_tabminmax *x, t_symbol* UNUSED(s),int argc, + t_atom*argv) { int a,b; - switch(argc){ + switch(argc) { case 2: a=atom_getint(argv); b=atom_getint(argv+1); @@ -128,14 +131,16 @@ static void tabminmax_helper(void) void tabminmax_setup(void) { - tabminmax_class = class_new(gensym("tabminmax"), (t_newmethod)tabminmax_new, - 0, sizeof(t_tabminmax), 0, A_DEFSYM, 0); + tabminmax_class = class_new(gensym("tabminmax"), + (t_newmethod)tabminmax_new, + 0, sizeof(t_tabminmax), 0, A_DEFSYM, 0); class_addbang(tabminmax_class, (t_method)tabminmax_bang); class_addlist(tabminmax_class, (t_method)tabminmax_list); class_addmethod(tabminmax_class, (t_method)tabminmax_set, gensym("set"), - A_SYMBOL, 0); + A_SYMBOL, 0); - class_addmethod(tabminmax_class, (t_method)tabminmax_helper, gensym("help"), 0); + class_addmethod(tabminmax_class, (t_method)tabminmax_helper, + gensym("help"), 0); zexy_register("tabminmax"); } diff --git a/src/tabread4~~.c b/src/tabread4~~.c index 6c53508..96d2003 100644 --- a/src/tabread4~~.c +++ b/src/tabread4~~.c @@ -1,4 +1,4 @@ -/* +/* * tabread4~~: a tabread with 2 inputs for higher precision * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -25,8 +25,7 @@ static t_class *tabread4_tilde_class; -typedef struct _tabread4_tilde -{ +typedef struct _tabread4_tilde { t_object x_obj; int x_npoints; zarray_t *x_vec; @@ -53,64 +52,66 @@ static t_int *tabread4_tilde_perform(t_int *w) t_sample *in = (t_sample *)(w[2]); t_sample *in1 = (t_sample *)(w[3]); t_sample *out = (t_sample *)(w[4]); - int n = (int)(w[5]); + int n = (int)(w[5]); int maxindex; zarray_t *buf = x->x_vec, *wp; int i; - + maxindex = x->x_npoints - 3; - if (!buf){ - while (n--) *out++ = 0; + if (!buf) { + while (n--) { + *out++ = 0; + } return (w+6); } - for (i = 0; i < n; i++) - { - t_sample in0_s=*in++; - t_sample in1_s=*in1++; - double findex = (double)in0_s + (double)in1_s; - long int index = findex; - double frac; - t_sample a, b, c, d, cminusb; - if (index < 1) - index = 1, frac = 0; - else if (index > maxindex) - index = maxindex, frac = 1; - else frac = findex - index; - - wp = buf + index; - - a = zarray_getfloat(wp,-1); - b = zarray_getfloat(wp, 0); - c = zarray_getfloat(wp, 1); - d = zarray_getfloat(wp, 2); - - cminusb = c-b; - *out++ = b + frac * ( - cminusb - 0.1666667f * (1.-frac) * ( - (d - a - 3.0f * cminusb) * frac + (d + 2.0f*a - 3.0f*b) - ) - ); + for (i = 0; i < n; i++) { + t_sample in0_s=*in++; + t_sample in1_s=*in1++; + double findex = (double)in0_s + (double)in1_s; + long int index = findex; + double frac; + t_sample a, b, c, d, cminusb; + if (index < 1) { + index = 1, frac = 0; + } else if (index > maxindex) { + index = maxindex, frac = 1; + } else { + frac = findex - index; } + + wp = buf + index; + + a = zarray_getfloat(wp,-1); + b = zarray_getfloat(wp, 0); + c = zarray_getfloat(wp, 1); + d = zarray_getfloat(wp, 2); + + 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+6); } static void tabread4_tilde_set(t_tabread4_tilde *x, t_symbol *s) { t_garray *a; - + 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; - } - else if (!zarray_getarray(a, &x->x_npoints, &x->x_vec)) - { - pd_error(x, "%s: bad template for tabread4~~", x->x_arrayname->s_name); - x->x_vec = 0; + 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); } - else garray_usedindsp(a); + x->x_vec = 0; + } else if (!zarray_getarray(a, &x->x_npoints, &x->x_vec)) { + pd_error(x, "%s: bad template for tabread4~~", x->x_arrayname->s_name); + x->x_vec = 0; + } else { + garray_usedindsp(a); + } } static void tabread4_tilde_dsp(t_tabread4_tilde *x, t_signal **sp) diff --git a/src/tabset.c b/src/tabset.c index f7b0eec..33909f1 100644 --- a/src/tabset.c +++ b/src/tabset.c @@ -1,4 +1,4 @@ -/* +/* * tabset: set a table with a list of floats * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -26,8 +26,7 @@ static t_class *tabset_class; -typedef struct _tabset -{ +typedef struct _tabset { t_object x_obj; t_symbol *x_arrayname; } t_tabset; @@ -38,12 +37,12 @@ static void tabset_float(t_tabset *x, t_floatarg f) int npoints; zarray_t *vec; - if (!(A = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) + if (!(A = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) { error("%s: no such array", x->x_arrayname->s_name); - else if (!zarray_getarray(A, &npoints, &vec)) + } else if (!zarray_getarray(A, &npoints, &vec)) { error("%s: bad template for tabset", x->x_arrayname->s_name); - else { - while(npoints--){ + } else { + while(npoints--) { zarray_setfloat(vec, 0, f); vec++; } @@ -51,31 +50,32 @@ static void tabset_float(t_tabset *x, t_floatarg f) } } -static void tabset_list(t_tabset *x, t_symbol* UNUSED(s), int argc, t_atom* argv) +static void tabset_list(t_tabset *x, t_symbol* UNUSED(s), int argc, + t_atom* argv) { t_garray *A; int npoints; zarray_t *vec; - if (!(A = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) + if (!(A = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) { error("%s: no such array", x->x_arrayname->s_name); - else if (!zarray_getarray(A, &npoints, &vec)) + } else if (!zarray_getarray(A, &npoints, &vec)) { error("%s: bad template for tabset", x->x_arrayname->s_name); - else { + } else { if (argc>=npoints) - while(npoints--){ + while(npoints--) { t_float f= atom_getfloat(argv++); zarray_setfloat(vec, 0, f); vec++; } else { npoints-=argc; - while (argc--){ + while (argc--) { t_float f= atom_getfloat(argv++); zarray_setfloat(vec, 0, f); vec++; } - while (npoints--){ + while (npoints--) { zarray_setfloat(vec, 0, 0); vec++; } @@ -108,11 +108,11 @@ static void tabset_helper(void) void tabset_setup(void) { tabset_class = class_new(gensym("tabset"), (t_newmethod)tabset_new, - 0, sizeof(t_tabset), 0, A_DEFSYM, 0); + 0, sizeof(t_tabset), 0, A_DEFSYM, 0); class_addfloat(tabset_class, (t_method)tabset_float); class_addlist (tabset_class, (t_method)tabset_list); class_addmethod(tabset_class, (t_method)tabset_set, gensym("set"), - A_SYMBOL, 0); + A_SYMBOL, 0); class_addmethod(tabset_class, (t_method)tabset_helper, gensym("help"), 0); zexy_register("tabset"); diff --git a/src/tavg~.c b/src/tavg~.c index 0d0231a..6d5ef51 100644 --- a/src/tavg~.c +++ b/src/tavg~.c @@ -1,4 +1,4 @@ -/* +/* * tavg~: arithmetic mean between last and current 'bang' (triggered average on signals) * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -21,8 +21,7 @@ static t_class *tavg_class; -typedef struct _tavg -{ +typedef struct _tavg { t_object x_obj; t_sample n_inv; t_sample buf; @@ -47,7 +46,9 @@ static t_int *tavg_perform(t_int *w) int n = (int)(w[3]); t_sample buf = x->buf; - while (n--) buf += *in++; + while (n--) { + buf += *in++; + } x->buf = buf; x->blocks++; return (w+4); diff --git a/src/time.c b/src/time.c index 9db6195..680d7fc 100644 --- a/src/time.c +++ b/src/time.c @@ -1,4 +1,4 @@ -/* +/* * time:: gets the current time from the system * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,18 +7,18 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ -/* - * 1506:forum::für::umläute:2003: use timeb only if needed (like on windoze) +/* + * 1506:forum::für::umläute:2003: use timeb only if needed (like on windoze) */ #include "zexy.h" @@ -45,12 +45,11 @@ static t_class *time_class; -typedef struct _time -{ +typedef struct _time { t_object x_obj; - + int GMT; - + t_outlet *x_outlet1; t_outlet *x_outlet2; t_outlet *x_outlet3; @@ -61,19 +60,20 @@ static void *time_new(t_symbol* UNUSED(s), int argc, t_atom *argv) { t_time *x = (t_time *)pd_new(time_class); char buf[5]; - + x->GMT=0; if (argc) { atom_string(argv, buf, 5); - if (buf[0]=='G' && buf[1]=='M' && buf[2]=='T') + if (buf[0]=='G' && buf[1]=='M' && buf[2]=='T') { x->GMT = 1; + } } - + x->x_outlet1 = outlet_new(&x->x_obj, gensym("float")); x->x_outlet2 = outlet_new(&x->x_obj, gensym("float")); x->x_outlet3 = outlet_new(&x->x_obj, gensym("float")); x->x_outlet4 = outlet_new(&x->x_obj, gensym("float")); - + return (x); } @@ -94,7 +94,7 @@ static void time_bang(t_time *x) #endif outlet_float(x->x_outlet4, (t_float)(ms)); outlet_float(x->x_outlet3, (t_float)resolvetime->tm_sec); - outlet_float(x->x_outlet2, (t_float)resolvetime->tm_min); + outlet_float(x->x_outlet2, (t_float)resolvetime->tm_min); outlet_float(x->x_outlet1, (t_float)resolvetime->tm_hour); } @@ -108,11 +108,11 @@ static void help_time(t_time* UNUSED(x)) void time_setup(void) { time_class = class_new(gensym("time"), - (t_newmethod)time_new, 0, - sizeof(t_time), 0, A_GIMME, 0); - + (t_newmethod)time_new, 0, + sizeof(t_time), 0, A_GIMME, 0); + class_addbang(time_class, time_bang); - + class_addmethod(time_class, (t_method)help_time, gensym("help"), 0); zexy_register("time"); } diff --git a/src/unpack.c b/src/unpack.c index baf5246..7998616 100644 --- a/src/unpack.c +++ b/src/unpack.c @@ -1,4 +1,4 @@ -/* +/* * unpack: a type-agnostic version of [unpack] * * (c) 2007-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -34,8 +34,7 @@ static t_class *zunpack_class; -typedef struct _zunpack -{ +typedef struct _zunpack { t_object x_obj; t_outlet**x_out; t_int x_numouts; @@ -74,7 +73,7 @@ static void zunpack_free(t_zunpack *x) freebytes(x->x_out, x->x_numouts*sizeof(t_outlet*)); x->x_numouts=0; - x->x_out=0; + x->x_out=0; } static void *zunpack_new(t_symbol*s, int argc, t_atom*argv) @@ -82,22 +81,22 @@ static void *zunpack_new(t_symbol*s, int argc, t_atom*argv) t_zunpack *x = (t_zunpack *)pd_new(zunpack_class); int count=(argc>0)?argc:2; int i=0; - + x->x_numouts=count; x->x_out=(t_outlet**)getbytes(count*sizeof(t_outlet*)); for(i=0; ix_out[i] =outlet_new(&x->x_obj, 0); - } + } return (x); } void zunpack_setup(void) { - - zunpack_class = class_new(gensym("zexy/unpack"), - (t_newmethod)zunpack_new, (t_method)zunpack_free, sizeof(t_zunpack), + + zunpack_class = class_new(gensym("zexy/unpack"), + (t_newmethod)zunpack_new, (t_method)zunpack_free, sizeof(t_zunpack), 0, A_GIMME, 0); #if 0 /* oops Pd-0.42 allows us to override built-ins diff --git a/src/unpack~.c b/src/unpack~.c index 7745e2c..091f9d3 100644 --- a/src/unpack~.c +++ b/src/unpack~.c @@ -1,4 +1,4 @@ -/* +/* * unpack~ :: convert (list-of-) float inputs to signals * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -21,8 +21,7 @@ static t_class *sigunpack_class; -typedef struct _sigunpack -{ +typedef struct _sigunpack { t_object x_obj; t_sample *buffer; t_sample *rp, *wp; @@ -34,19 +33,24 @@ static void sigunpack_float(t_sigunpack *x, t_float f) { if (x->wp + 1 != x->rp) { *(x->wp)++ = f; - if (x->wp == x->buffer + x->bufsize) x->wp = x->buffer; + if (x->wp == x->buffer + x->bufsize) { + x->wp = x->buffer; + } } } -static void sigunpack_list(t_sigunpack *x, t_symbol *s, int argc, t_atom *argv) +static void sigunpack_list(t_sigunpack *x, t_symbol *s, int argc, + t_atom *argv) { t_atom *ap = argv; int i; for (i = 0, ap = argv; i < argc; ap++, i++) { if (x->wp + 1 != x->rp) { *(x->wp)++ = atom_getfloat(ap); - if (x->wp == x->buffer + x->bufsize) x->wp = x->buffer; - } + if (x->wp == x->buffer + x->bufsize) { + x->wp = x->buffer; + } + } } } @@ -60,10 +64,16 @@ static t_int *sigunpack_perform(t_int *w) t_sample *buf = x->rp; int hitchhike = 0; - if ((x->wp >= x->rp) && (x->wp < x->rp+n)) hitchhike=1; + if ((x->wp >= x->rp) && (x->wp < x->rp+n)) { + hitchhike=1; + } x->rp += n; - if (x->rp == x->buffer + x->bufsize) x->rp = x->buffer; - if (hitchhike) x->wp = x->rp; + if (x->rp == x->buffer + x->bufsize) { + x->rp = x->buffer; + } + if (hitchhike) { + x->wp = x->rp; + } while (n--) { *out++ = *buf; @@ -93,8 +103,12 @@ static void *sigunpack_new(t_floatarg f) int suggestedsize = (int)f; int bufsize; - if (!suggestedsize) bufsize = 64; - else bufsize = (suggestedsize % 64)?(64*(1+(int)(suggestedsize/64))):suggestedsize; + if (!suggestedsize) { + bufsize = 64; + } else { + bufsize = (suggestedsize % 64)?(64*(1+(int)(suggestedsize/64))): + suggestedsize; + } x->buffer = (t_sample *)getbytes(bufsize * sizeof(*x->buffer)); x->bufsize = bufsize; @@ -112,13 +126,16 @@ static void sigunpack_help(void) void unpack_tilde_setup(void) { - sigunpack_class = class_new(gensym("unpack~"), (t_newmethod)sigunpack_new, 0, + sigunpack_class = class_new(gensym("unpack~"), (t_newmethod)sigunpack_new, + 0, sizeof(t_sigunpack), 0, A_DEFFLOAT, 0); - class_addmethod(sigunpack_class, (t_method)sigunpack_dsp, gensym("dsp"), 0); + class_addmethod(sigunpack_class, (t_method)sigunpack_dsp, gensym("dsp"), + 0); class_addfloat(sigunpack_class, (t_method)sigunpack_float); class_addlist (sigunpack_class, (t_method)sigunpack_list); - class_addmethod(sigunpack_class, (t_method)sigunpack_help, gensym("help"), 0); + class_addmethod(sigunpack_class, (t_method)sigunpack_help, gensym("help"), + 0); zexy_register("unpack~"); } diff --git a/src/urn.c b/src/urn.c index 602fd13..9a86736 100644 --- a/src/urn.c +++ b/src/urn.c @@ -1,4 +1,4 @@ -/* +/* * urn : "generate random numbers without duplicates" (very max-like) * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -23,13 +23,13 @@ static t_class *urn_class; -typedef struct _urn -{ +typedef struct _urn { t_object x_obj; unsigned int x_seed; /* the seed of the generator */ unsigned int x_range; /* max. random-number + 1 */ - unsigned int x_count; /* how many random numbers have we generated ? */ + unsigned int + x_count; /* how many random numbers have we generated ? */ char *x_state; /* has this number been generated already ? */ t_outlet *x_floatout, *x_bangout; @@ -45,7 +45,9 @@ static int makeseed(void) static void makestate(t_urn *x, unsigned int newrange) { - if (x->x_range == newrange)return; + if (x->x_range == newrange) { + return; + } if (x->x_range && x->x_state) { freebytes(x->x_state, sizeof(char)*x->x_range); @@ -60,8 +62,12 @@ static void urn_clear(t_urn *x) { unsigned int i=x->x_range; char *dummy=x->x_state; - if (!dummy || !i)return; - while(i--)*dummy++=0; + if (!dummy || !i) { + return; + } + while(i--) { + *dummy++=0; + } x->x_count=0; } static void urn_bang(t_urn *x) @@ -71,17 +77,21 @@ static void urn_bang(t_urn *x) unsigned int nval=0, used=1; - if (x->x_count>=range){ + if (x->x_count>=range) { outlet_bang(x->x_bangout); - if (x->x_noauto)return; + if (x->x_noauto) { + return; + } urn_clear(x); } while (used) { randval = randval * 472940017 + 832416023; nval = ((double)range) * ((double)randval) - * (1./4294967296.); - if (nval >= range) nval = range-1; + * (1./4294967296.); + if (nval >= range) { + nval = range-1; + } used=x->x_state[nval]; } @@ -116,16 +126,20 @@ static void *urn_new(t_symbol* UNUSED(s), int argc, t_atom *argv) x->x_seed = makeseed(); x->x_noauto = 0; - while(argc--){ + while(argc--) { if (argv->a_type==A_SYMBOL) { if (atom_getsymbol(argv)==gensym("no_auto")) { - x->x_noauto=1; + x->x_noauto=1; } - } else f = atom_getfloat(argv); + } else { + f = atom_getfloat(argv); + } argv++; } - if (f<1.0)f=1.0; + if (f<1.0) { + f=1.0; + } makestate(x, f); x->x_range = f; urn_clear(x); @@ -140,14 +154,15 @@ static void urn_help(t_urn*x) void urn_setup(void) { - urn_class = class_new(gensym("urn"), (t_newmethod)urn_new, - 0, sizeof(t_urn), 0, A_GIMME, 0); - + urn_class = class_new(gensym("urn"), (t_newmethod)urn_new, + 0, sizeof(t_urn), 0, A_GIMME, 0); + class_addbang (urn_class, urn_bang); class_addmethod(urn_class, (t_method)urn_clear, gensym("clear"), 0); class_addmethod(urn_class, (t_method)urn_flt2, gensym(""), A_DEFFLOAT, 0); - class_addmethod(urn_class, (t_method)urn_seed, gensym("seed"), A_DEFFLOAT, 0); - + class_addmethod(urn_class, (t_method)urn_seed, gensym("seed"), A_DEFFLOAT, + 0); + class_addmethod(urn_class, (t_method)urn_help, gensym("help"), A_NULL); zexy_register("urn"); diff --git a/src/winNT_portio.c b/src/winNT_portio.c index 1138ca7..b514912 100644 --- a/src/winNT_portio.c +++ b/src/winNT_portio.c @@ -19,17 +19,17 @@ static BOOL bPrivException = FALSE; int read_parport(int port) { - unsigned char value; + unsigned char value; #ifdef _MSC_VER - __asm mov edx,port - __asm in al,dx - __asm mov value,al + __asm mov edx,port + __asm in al,dx + __asm mov value,al #else - /* hmm, i should read some documentation about inline assembler */ - post("lpt: cannot read from parport (recompile!)"); - return 0; + /* hmm, i should read some documentation about inline assembler */ + post("lpt: cannot read from parport (recompile!)"); + return 0; #endif - return (int)value; + return (int)value; } void write_parport(int port, int invalue) @@ -41,88 +41,88 @@ void write_parport(int port, int invalue) __asm mov al,value __asm out dx,al #else - /* - * hmm, i should read some documentation about inline assembler - * and probably about assembler in general... - */ - post("lpt: cannot write to parport (recompile!)"); - /* - asm( - "mov %%edx,%0\n" - "mov %%al,%1\n" - "out %%dx,%%al\n" - : - : "a"(port),"b"(value) - ); - */ + /* + * hmm, i should read some documentation about inline assembler + * and probably about assembler in general... + */ + post("lpt: cannot write to parport (recompile!)"); + /* + asm( + "mov %%edx,%0\n" + "mov %%al,%1\n" + "out %%dx,%%al\n" + : + : "a"(port),"b"(value) + ); + */ #endif } static LONG WINAPI HandlerExceptionFilter ( EXCEPTION_POINTERS *pExPtrs ) { - if (pExPtrs->ExceptionRecord->ExceptionCode == EXCEPTION_PRIV_INSTRUCTION) - { - pExPtrs->ContextRecord->Eip ++; /* Skip the OUT or IN instruction that caused the exception */ - bPrivException = TRUE; - return EXCEPTION_CONTINUE_EXECUTION; - } - else - return EXCEPTION_CONTINUE_SEARCH; + if (pExPtrs->ExceptionRecord->ExceptionCode == + EXCEPTION_PRIV_INSTRUCTION) { + pExPtrs->ContextRecord->Eip + ++; /* Skip the OUT or IN instruction that caused the exception */ + bPrivException = TRUE; + return EXCEPTION_CONTINUE_EXECUTION; + } else { + return EXCEPTION_CONTINUE_SEARCH; + } } -static BOOL StartUpIoPorts(UINT PortToAccess, BOOL bShowMessageBox, HWND hParentWnd) +static BOOL StartUpIoPorts(UINT PortToAccess, BOOL bShowMessageBox, + HWND hParentWnd) { - HANDLE hUserPort; + HANDLE hUserPort; + + hUserPort = CreateFile("\\\\.\\UserPort", GENERIC_READ, 0, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + CloseHandle(hUserPort); /* Activate the driver */ + Sleep(100); /* We must make a process switch */ - hUserPort = CreateFile("\\\\.\\UserPort", GENERIC_READ, 0, NULL,OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - CloseHandle(hUserPort); /* Activate the driver */ - Sleep(100); /* We must make a process switch */ + SetUnhandledExceptionFilter(HandlerExceptionFilter); - SetUnhandledExceptionFilter(HandlerExceptionFilter); - - bPrivException = FALSE; - read_parport(PortToAccess); /* Try to access the given port address */ + bPrivException = FALSE; + read_parport(PortToAccess); /* Try to access the given port address */ - if (bPrivException) - { - if (bShowMessageBox) - { + if (bPrivException) { + if (bShowMessageBox) { #if 0 - MessageBox(hParentWnd,"Privileged instruction exception has occured!\r\n\r\n" - "To use this external under Windows NT, 2000 or XP\r\n" - "you need to install the driver 'UserPort.sys' and grant\r\n" - "access to the ports used by this program.\r\n\r\n" - "See the file README for further information!\r\n", NULL, MB_OK); + MessageBox(hParentWnd, + "Privileged instruction exception has occured!\r\n\r\n" + "To use this external under Windows NT, 2000 or XP\r\n" + "you need to install the driver 'UserPort.sys' and grant\r\n" + "access to the ports used by this program.\r\n\r\n" + "See the file README for further information!\r\n", NULL, MB_OK); #endif - } - return FALSE; - } - return TRUE; + } + return FALSE; + } + return TRUE; } - /* check if we are running NT/2k/XP */ +/* check if we are running NT/2k/XP */ static int IsWinNT(void) { - OSVERSIONINFO OSVersionInfo; - OSVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + OSVERSIONINFO OSVersionInfo; + OSVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - GetVersionEx(&OSVersionInfo); + GetVersionEx(&OSVersionInfo); - return OSVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT; + return OSVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT; } - /* open parport */ +/* open parport */ int open_port(int port) { - if(IsWinNT()) /* we are under NT and need kernel driver */ - { - if(StartUpIoPorts(port, 1, 0)) - return(0); - return(-1); - } - else /* no need to use kernel driver */ - { - return(0); - } + if(IsWinNT()) { /* we are under NT and need kernel driver */ + if(StartUpIoPorts(port, 1, 0)) { + return(0); + } + return(-1); + } else { /* no need to use kernel driver */ + return(0); + } } #endif /* __WIN32__ & Z_WANT_LPT */ diff --git a/src/wrap.c b/src/wrap.c index 1ecc7c1..fb1c598 100644 --- a/src/wrap.c +++ b/src/wrap.c @@ -1,4 +1,4 @@ -/* +/* * wrap: wrap floats between two limits * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -28,18 +28,22 @@ typedef struct _wrap { static void wrap_float(t_wrap *x, t_float f) { - if (x->f_lower==x->f_upper) + if (x->f_lower==x->f_upper) { outlet_float(x->x_obj.ob_outlet, x->f_lower); - else { + } else { t_float modulo = fmod((f-x->f_lower),(x->f_upper-x->f_lower)); - if (modulo<0)modulo+=(x->f_upper-x->f_lower); - + if (modulo<0) { + modulo+=(x->f_upper-x->f_lower); + } + outlet_float(x->x_obj.ob_outlet, x->f_lower+modulo); } } -static void wrap_set(t_wrap *x, t_symbol* UNUSED(s), int argc, t_atom *argv){ +static void wrap_set(t_wrap *x, t_symbol* UNUSED(s), int argc, + t_atom *argv) +{ t_float f1, f2; - switch (argc){ + switch (argc) { case 0: f1=0.0; f2=1.0; @@ -72,11 +76,12 @@ static void wrap_help(t_wrap*x) post("\n"HEARTSYMBOL" wrap\t\t:: wrap a float between to boundaries"); } -void wrap_setup(void) { +void wrap_setup(void) +{ wrap_class = class_new(gensym("wrap"), - (t_newmethod)wrap_new, - 0, sizeof(t_wrap), - CLASS_DEFAULT, A_GIMME, A_NULL); + (t_newmethod)wrap_new, + 0, sizeof(t_wrap), + CLASS_DEFAULT, A_GIMME, A_NULL); class_addfloat (wrap_class, wrap_float); class_addmethod(wrap_class, (t_method)wrap_set, gensym("set"), A_GIMME, 0); diff --git a/src/z_zexy.c b/src/z_zexy.c index 0a6c5b5..8a15960 100644 --- a/src/z_zexy.c +++ b/src/z_zexy.c @@ -7,91 +7,91 @@ void z_zexy_setup(void) { - setup_0x260x260x7e(); /* 0x260x260x7e */ - setup_0x2e(); /* 0x2e */ - setup_0x3c0x7e(); /* 0x3c0x7e */ - setup_0x3d0x3d0x7e(); /* 0x3d0x3d0x7e */ - setup_0x3e0x7e(); /* 0x3e0x7e */ - setup_0x7c0x7c0x7e(); /* 0x7c0x7c0x7e */ - a2l_setup(); /* a2l */ - abs_tilde_setup(); /* abs~ */ - absgn_tilde_setup(); /* absgn~ */ - atof_setup(); /* atof */ - atoi_setup(); /* atoi */ - avg_tilde_setup(); /* avg~ */ - blockmirror_tilde_setup(); /* blockmirror~ */ - blockshuffle_tilde_setup(); /* blockshuffle~ */ - blockswap_tilde_setup(); /* blockswap~ */ - date_setup(); /* date */ - demultiplex_tilde_setup(); /* demultiplex~ */ - demultiplex_setup(); /* demultiplex */ - dfreq_tilde_setup(); /* dfreq~ */ - dirac_tilde_setup(); /* dirac~ */ - doublepole_tilde_setup(); /* doublepole~ */ - drip_setup(); /* drip */ - envrms_tilde_setup(); /* envrms~ */ - fifop_setup(); /* fifop */ - freadln_setup(); /* freadln */ - fwriteln_setup(); /* fwriteln */ - glue_setup(); /* glue */ - index_setup(); /* index */ - length_setup(); /* length */ - lifop_setup(); /* lifop */ - limiter_tilde_setup(); /* limiter~ */ - list2int_setup(); /* list2int */ - list2lists_setup(); /* list2lists */ - list2symbol_setup(); /* list2symbol */ - lister_setup(); /* lister */ - listfind_setup(); /* listfind */ - liststorage_setup(); /* liststorage */ - longload_setup(); /* longload */ - lpt_setup(); /* lpt */ - makesymbol_setup(); /* makesymbol */ - matchbox_setup(); /* matchbox */ - mavg_setup(); /* mavg */ - minmax_setup(); /* minmax */ - msgfile_setup(); /* msgfile */ - multiline_tilde_setup(); /* multiline~ */ - multiplex_tilde_setup(); /* multiplex~ */ - multiplex_setup(); /* multiplex */ - multireceive_setup(); /* multireceive */ - niagara_setup(); /* niagara */ - noish_tilde_setup(); /* noish~ */ - noisi_tilde_setup(); /* noisi~ */ - operating_system_setup(); /* operating_system */ - pack_tilde_setup(); /* pack~ */ - pack_setup(); /* pack */ - packel_setup(); /* packel */ - pdf_tilde_setup(); /* pdf~ */ - prime_setup(); /* prime */ - quantize_tilde_setup(); /* quantize~ */ - rawprint_setup(); /* rawprint */ - regex_setup(); /* regex */ - relay_setup(); /* relay */ - repack_setup(); /* repack */ - repeat_setup(); /* repeat */ - route_tilde_setup(); /* route~ */ - sfplay_setup(); /* sfplay */ - sfrecord_setup(); /* sfrecord */ - sgn_tilde_setup(); /* sgn~ */ - sigzero_tilde_setup(); /* sigzero~ */ - sleepgrain_setup(); /* sleepgrain */ - sort_setup(); /* sort */ - step_tilde_setup(); /* step~ */ - strcmp_setup(); /* strcmp */ - sum_setup(); /* sum */ - swap_tilde_setup(); /* swap~ */ - symbol2list_setup(); /* symbol2list */ - tabdump_setup(); /* tabdump */ - tabminmax_setup(); /* tabminmax */ - tabread4_tilde_tilde_setup(); /* tabread4~~ */ - tabset_setup(); /* tabset */ - tavg_tilde_setup(); /* tavg~ */ - time_setup(); /* time */ - unpack_tilde_setup(); /* unpack~ */ - unpack_setup(); /* unpack */ - urn_setup(); /* urn */ - wrap_setup(); /* wrap */ - z_tilde_setup(); /* z~ */ + setup_0x260x260x7e(); /* 0x260x260x7e */ + setup_0x2e(); /* 0x2e */ + setup_0x3c0x7e(); /* 0x3c0x7e */ + setup_0x3d0x3d0x7e(); /* 0x3d0x3d0x7e */ + setup_0x3e0x7e(); /* 0x3e0x7e */ + setup_0x7c0x7c0x7e(); /* 0x7c0x7c0x7e */ + a2l_setup(); /* a2l */ + abs_tilde_setup(); /* abs~ */ + absgn_tilde_setup(); /* absgn~ */ + atof_setup(); /* atof */ + atoi_setup(); /* atoi */ + avg_tilde_setup(); /* avg~ */ + blockmirror_tilde_setup(); /* blockmirror~ */ + blockshuffle_tilde_setup(); /* blockshuffle~ */ + blockswap_tilde_setup(); /* blockswap~ */ + date_setup(); /* date */ + demultiplex_tilde_setup(); /* demultiplex~ */ + demultiplex_setup(); /* demultiplex */ + dfreq_tilde_setup(); /* dfreq~ */ + dirac_tilde_setup(); /* dirac~ */ + doublepole_tilde_setup(); /* doublepole~ */ + drip_setup(); /* drip */ + envrms_tilde_setup(); /* envrms~ */ + fifop_setup(); /* fifop */ + freadln_setup(); /* freadln */ + fwriteln_setup(); /* fwriteln */ + glue_setup(); /* glue */ + index_setup(); /* index */ + length_setup(); /* length */ + lifop_setup(); /* lifop */ + limiter_tilde_setup(); /* limiter~ */ + list2int_setup(); /* list2int */ + list2lists_setup(); /* list2lists */ + list2symbol_setup(); /* list2symbol */ + lister_setup(); /* lister */ + listfind_setup(); /* listfind */ + liststorage_setup(); /* liststorage */ + longload_setup(); /* longload */ + lpt_setup(); /* lpt */ + makesymbol_setup(); /* makesymbol */ + matchbox_setup(); /* matchbox */ + mavg_setup(); /* mavg */ + minmax_setup(); /* minmax */ + msgfile_setup(); /* msgfile */ + multiline_tilde_setup(); /* multiline~ */ + multiplex_tilde_setup(); /* multiplex~ */ + multiplex_setup(); /* multiplex */ + multireceive_setup(); /* multireceive */ + niagara_setup(); /* niagara */ + noish_tilde_setup(); /* noish~ */ + noisi_tilde_setup(); /* noisi~ */ + operating_system_setup(); /* operating_system */ + pack_tilde_setup(); /* pack~ */ + pack_setup(); /* pack */ + packel_setup(); /* packel */ + pdf_tilde_setup(); /* pdf~ */ + prime_setup(); /* prime */ + quantize_tilde_setup(); /* quantize~ */ + rawprint_setup(); /* rawprint */ + regex_setup(); /* regex */ + relay_setup(); /* relay */ + repack_setup(); /* repack */ + repeat_setup(); /* repeat */ + route_tilde_setup(); /* route~ */ + sfplay_setup(); /* sfplay */ + sfrecord_setup(); /* sfrecord */ + sgn_tilde_setup(); /* sgn~ */ + sigzero_tilde_setup(); /* sigzero~ */ + sleepgrain_setup(); /* sleepgrain */ + sort_setup(); /* sort */ + step_tilde_setup(); /* step~ */ + strcmp_setup(); /* strcmp */ + sum_setup(); /* sum */ + swap_tilde_setup(); /* swap~ */ + symbol2list_setup(); /* symbol2list */ + tabdump_setup(); /* tabdump */ + tabminmax_setup(); /* tabminmax */ + tabread4_tilde_tilde_setup(); /* tabread4~~ */ + tabset_setup(); /* tabset */ + tavg_tilde_setup(); /* tavg~ */ + time_setup(); /* time */ + unpack_tilde_setup(); /* unpack~ */ + unpack_setup(); /* unpack */ + urn_setup(); /* urn */ + wrap_setup(); /* wrap */ + z_tilde_setup(); /* z~ */ } diff --git a/src/zexy.c b/src/zexy.c index b8ef63a..46fdcbe 100644 --- a/src/zexy.c +++ b/src/zexy.c @@ -1,4 +1,4 @@ -/* +/* * zexy: the swiss army knife for Pure Data * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -34,8 +34,7 @@ /* do a little help thing */ -typedef struct zexy -{ +typedef struct zexy { t_object t_ob; } t_zexy; @@ -43,7 +42,8 @@ t_class *zexy_class; static void zexy_help(void) { - endpost(); endpost(); + endpost(); + endpost(); post("...this is the zexy external "VERSION"..."); endpost(); post(""HEARTSYMBOL" handling signals"); @@ -54,29 +54,34 @@ static void zexy_help(void) post("sfplay\t\t:: play back a (multichannel) soundfile : (c) ritsch 1999"); post("sfrecord\t:: record a (multichannel) soundfile : based on ritsch"); - endpost(); post(""HEARTSYMBOL" generating signals"); + endpost(); + post(""HEARTSYMBOL" generating signals"); post("noish~\t\t:: generate bandlimited noise"); post("noisi~\t\t:: generate bandlimited noise"); post("dirac~\t\t:: generate a dirac-pulse"); post("step~\t\t:: generate a unity-step"); post("dfreq~\t\t:: detect frequency by counting zero-crossings : (c) ritsch 1998"); - endpost(); post(""HEARTSYMBOL" manipulating signals"); + endpost(); + post(""HEARTSYMBOL" manipulating signals"); post("limiter~\t:: limit/compress one or more signals"); post("nop~\t\t:: pass through a signal (delay 1 block)"); post("z~\t\t:: samplewise delay"); post("swap~\t\t:: byte-swap a signal"); post("quantize~\t:: quantize a signal"); - endpost(); post(""HEARTSYMBOL" binary operations on signals"); + endpost(); + post(""HEARTSYMBOL" binary operations on signals"); post("abs~, sgn~, >~, <~, ==~, &&~, ||~"); - endpost(); post(""HEARTSYMBOL" multary operations on signals"); + endpost(); + post(""HEARTSYMBOL" multary operations on signals"); post("multiline~\t:: multiple line~ multiplication"); post("multiplex~\t:: multiplex 1 inlet~ to 1-of-various outlet~s"); post("demultiplex~\t:: demultiplex 1-of-various inlet~s to 1 outlet~"); - endpost(); post(""HEARTSYMBOL" investigating signals in message-domain"); + endpost(); + post(""HEARTSYMBOL" investigating signals in message-domain"); post("pack~\t\t:: convert a signal into a list of floats"); post("unpack~\t\t:: convert packages of floats into a signal"); @@ -85,8 +90,9 @@ static void zexy_help(void) post("tavg~\t\t:: outputs average of a signal between two bangs"); post("envrms~\t\t:: an env~-object that ouputs rms instead of db"); post("pdf~\t\t:: power density function"); - - endpost(); post(""HEARTSYMBOL" basic message objects"); + + endpost(); + post(""HEARTSYMBOL" basic message objects"); post("nop\t\t:: a no-operation"); post("lister\t\t:: stores lists"); post("any2list\t\t:: converts \"anything\" to lists"); @@ -104,7 +110,8 @@ static void zexy_help(void) post("segregate\t:: sort inputs by type"); post(".\t\t:: scalar multiplication of vectors (lists of floats)"); - endpost(); post(""HEARTSYMBOL" advanced message objects"); + endpost(); + post(""HEARTSYMBOL" advanced message objects"); post("tabread4\t:: 4-point interpolating table-read object"); post("tabdump\t\t:: dump the table as a list"); post("tabset\t\t:: set a table with a list"); @@ -124,7 +131,8 @@ static void zexy_help(void) post("urn\t\t:: unique random numbers"); post("operating_system\t:: information on the OS"); - endpost(); post("\n(l) forum::für::umläute except where indicated"); + endpost(); + post("\n(l) forum::für::umläute except where indicated"); post("this software is released under the GnuGPL that is provided with these files"); endpost(); } @@ -135,12 +143,14 @@ static void *zexy_new(void) return (x); } -void zexy_setup(void) +void zexy_setup(void) { int i; startpost("\n\t"); - for (i=0; i<3; i++) startpost(""HEARTSYMBOL""); + for (i=0; i<3; i++) { + startpost(""HEARTSYMBOL""); + } endpost(); post("\t"HEARTSYMBOL" the zexy external "VERSION); post("\t"HEARTSYMBOL" (c) 1999-2012 IOhannes m zmölnig"); @@ -149,9 +159,12 @@ void zexy_setup(void) post("\t"HEARTSYMBOL" compiled: "__DATE__); post("\t"HEARTSYMBOL" send me a 'help' message"); startpost("\t"); - for (i=0; i<3; i++) startpost(""HEARTSYMBOL""); - endpost(); endpost(); - + for (i=0; i<3; i++) { + startpost(""HEARTSYMBOL""); + } + endpost(); + endpost(); + zexy_class = class_new(gensym("zexy"), zexy_new, 0, sizeof(t_zexy), 0, 0); class_addmethod(zexy_class, zexy_help, gensym("help"), 0); @@ -162,10 +175,11 @@ void zexy_setup(void) } #ifndef __WIN32__ -void verbose(int level, const char *fmt, ...){ +void verbose(int level, const char *fmt, ...) +{ char buf[MAXPDSTRING]; va_list ap; - + va_start(ap, fmt); vsnprintf(buf, MAXPDSTRING-1, fmt, ap); va_end(ap); diff --git a/src/zexy.h b/src/zexy.h index aa1e650..b8561cd 100644 --- a/src/zexy.h +++ b/src/zexy.h @@ -18,7 +18,7 @@ http://puredata.info/community/projects/software/zexy/ ftp://iem.at/pd/Externals/ZEXY - * + * * ZEXY is published under the GNU GeneralPublicLicense, that must be shipped with ZEXY. * if you are using Debian GNU/linux, the GNU-GPL can be found under /usr/share/common-licenses/GPL * if you still haven't found a copy of the GNU-GPL, have a look at http://www.gnu.org @@ -40,7 +40,7 @@ # endif #endif -/* +/* * to use the zexyconf.h compile-time configurations, you have to set HAVE_CONFIG_H * usually this is done in Make.config by configure */ @@ -111,8 +111,7 @@ #define ZEXY_TYPE_EQUAL(type1, type2) (sizeof(type1) == sizeof(type2)) -typedef struct _mypdlist -{ +typedef struct _mypdlist { t_object x_obj; int x_n; @@ -120,18 +119,22 @@ typedef struct _mypdlist } t_mypdlist; #ifndef ZEXY_LIBRARY -static void zexy_register(char*object){ - if(object!=0){ +static void zexy_register(char*object) +{ + if(object!=0) { post("[%s] part of zexy-%s (compiled: "__DATE__")", object, VERSION); post("\tCopyright (c) 1999-2012 IOhannes m zmölnig, forum::für::umläute & IEM"); } } #else -static void zexy_register(char*object){object=0;} +static void zexy_register(char*object) +{ + object=0; +} #endif /* ZEXY_LIBRARY */ #if (defined PD_MAJOR_VERSION && defined PD_MINOR_VERSION) && (PD_MAJOR_VERSION > 0 || PD_MINOR_VERSION > 38) -/* +/* * pd>=0.39 has a verbose() function; older versions don't * btw, this finally makes zexy binary incompatible with older version */ @@ -142,10 +145,10 @@ static void zexy_register(char*object){object=0;} * this should make zexy binary compatible with older pd versions again */ # ifndef __WIN32__ - void verbose(int level, const char *fmt, ...); +void verbose(int level, const char *fmt, ...); # endif #else -/* +/* * on older version we just shut up! */ # define z_verbose diff --git a/src/zexySIMD.h b/src/zexySIMD.h index 893a857..a9048c0 100644 --- a/src/zexySIMD.h +++ b/src/zexySIMD.h @@ -17,10 +17,11 @@ typedef union { * runs a check whether the SSE-optimized perform routine returns the same result as the generic routine * if the results differ, the SSE-code is probably broken, so we should fallback to the generic code */ -static int zexy_testSSE(t_perfroutine genericperf, t_perfroutine sseperf, unsigned int numinchannels, unsigned int numoutchannels) +static int zexy_testSSE(t_perfroutine genericperf, t_perfroutine sseperf, + unsigned int numinchannels, unsigned int numoutchannels) { -/* this currently only works with single input, single output */ -/* LATER make it work truely multichannel */ + /* this currently only works with single input, single output */ + /* LATER make it work truely multichannel */ if(1==numinchannels && 1==numoutchannels) { t_int w1[4], w2[4]; t_sample4 in, in1[4], in2[4], out1[4], out2[4]; @@ -34,28 +35,43 @@ static int zexy_testSSE(t_perfroutine genericperf, t_perfroutine sseperf, unsign in.f[1]=5.; for(i=0; i<4; i++) { - in1[i].f[0]=in.f[i]; in1[i].f[1]=in.f[i]; in1[i].f[3]=in.f[i]; in1[i].f[2]=in.f[i]; + in1[i].f[0]=in.f[i]; + in1[i].f[1]=in.f[i]; + in1[i].f[3]=in.f[i]; + in1[i].f[2]=in.f[i]; out1[i].f[0]=out1[i].f[1]=out1[i].f[2]=out1[i].f[3]=0.f; - in2[i].f[0]=in.f[i]; in2[i].f[1]=in.f[i]; in2[i].f[3]=in.f[i]; in2[i].f[2]=in.f[i]; + in2[i].f[0]=in.f[i]; + in2[i].f[1]=in.f[i]; + in2[i].f[3]=in.f[i]; + in2[i].f[2]=in.f[i]; out2[i].f[0]=out2[i].f[1]=out2[i].f[2]=out2[i].f[3]=0.f; } - w1[0]=(t_int)0; w1[1]=(t_int)&in1; w1[2]=(t_int)&out1; w1[3]=(t_int)16; (*genericperf)(w1); - w2[0]=(t_int)0; w2[1]=(t_int)&in2; w2[2]=(t_int)&out2; w2[3]=(t_int)16; (*sseperf)(w2); + w1[0]=(t_int)0; + w1[1]=(t_int)&in1; + w1[2]=(t_int)&out1; + w1[3]=(t_int)16; + (*genericperf)(w1); + w2[0]=(t_int)0; + w2[1]=(t_int)&in2; + w2[2]=(t_int)&out2; + w2[3]=(t_int)16; + (*sseperf)(w2); for(i=0; i<4; i++) { for(j=0; j<4; j++) { - if(fabsf(out1[i].f[j]-out2[i].f[j])>1e-17) { - z_verbose(2, "generic and optimized routines return different results: skipping optimization"); - z_verbose(2, "[%d,%d]: ((%f->%f)!=(%f->%f))", - i, j, - in1[i].f[j], out1[i].f[j], - in2[i].f[j], out2[i].f[j] - ); - return 0; - } + if(fabsf(out1[i].f[j]-out2[i].f[j])>1e-17) { + z_verbose(2, + "generic and optimized routines return different results: skipping optimization"); + z_verbose(2, "[%d,%d]: ((%f->%f)!=(%f->%f))", + i, j, + in1[i].f[j], out1[i].f[j], + in2[i].f[j], out2[i].f[j] + ); + return 0; + } } } } else { diff --git a/src/zexyconf.h b/src/zexyconf.h index 2fca57b..a592ae7 100644 --- a/src/zexyconf.h +++ b/src/zexyconf.h @@ -7,7 +7,7 @@ /* Define if you have the header file. */ /* -#undef HAVE_REGEX_H +#undef HAVE_REGEX_H */ /* Define if you have the header file. */ @@ -21,8 +21,8 @@ */ /* define if you have the header file. - * (for parport _device_ support) - * you need Z_WANT_LPT for this to have an effect ! + * (for parport _device_ support) + * you need Z_WANT_LPT for this to have an effect ! */ /* #undef HAVE_LINUX_PPDEV_H diff --git a/src/z~.c b/src/z~.c index 9f32696..aa51731 100644 --- a/src/z~.c +++ b/src/z~.c @@ -1,5 +1,5 @@ -/* - * z~: samplewise delay (z^-N) +/* + * z~: samplewise delay (z^-N) * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) * @@ -7,12 +7,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -31,8 +31,7 @@ static t_class *zNdelay_class; -typedef struct _zNdelay -{ +typedef struct _zNdelay { t_object x_obj; t_sample *buf; @@ -43,8 +42,12 @@ typedef struct _zNdelay static void zdel_float(t_zNdelay *x, t_floatarg f) { int i = f+1; - if (i<1)i=1; - if (i==x->bufsize)return; + if (i<1) { + i=1; + } + if (i==x->bufsize) { + return; + } freebytes(x->buf, x->bufsize*sizeof(t_sample)); x->bufsize=i; x->buf=(t_sample *)getbytes(x->bufsize*sizeof(t_sample)); @@ -62,10 +65,12 @@ static t_int *zN_perform(t_int *w) int bufsize=x->bufsize, ph=x->phase; if (bufsize==1) { - if (in!=out)while(n--)*out++=*in++; + if (in!=out)while(n--) { + *out++=*in++; + } } else if (bufsize==2) { register t_sample f, last=*buf; - while(n--){ + while(n--) { f=*in++; *out++=last; last=f; @@ -106,10 +111,12 @@ static void *zNdelay_new(t_symbol*s, int argc, t_atom*argv) error("Bad arguments for [z~]: must be nought or initial delay [in samples]"); return 0; } - + x=(t_zNdelay *)pd_new(zNdelay_class); - if (i<=0) i=0; + if (i<=0) { + i=0; + } i++; x->bufsize = i; @@ -121,7 +128,7 @@ static void *zNdelay_new(t_symbol*s, int argc, t_atom*argv) x->phase = 0; inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("ft1")); - outlet_new(&x->x_obj, gensym("signal")); + outlet_new(&x->x_obj, gensym("signal")); return (x); } @@ -140,13 +147,15 @@ static void zdel_helper(void) void z_tilde_setup(void) { - zNdelay_class = class_new(gensym("z~"), (t_newmethod)zNdelay_new, (t_method)zNdelay_free, - sizeof(t_zNdelay), 0, A_GIMME, 0); + zNdelay_class = class_new(gensym("z~"), (t_newmethod)zNdelay_new, + (t_method)zNdelay_free, + sizeof(t_zNdelay), 0, A_GIMME, 0); class_addmethod(zNdelay_class, nullfn, gensym("signal"), 0); class_addmethod(zNdelay_class, (t_method)zNdelay_dsp, gensym("dsp"), 0); class_addfloat(zNdelay_class, zdel_float); - class_addmethod(zNdelay_class, (t_method)zdel_float, gensym("ft1"), A_FLOAT, 0); + class_addmethod(zNdelay_class, (t_method)zdel_float, gensym("ft1"), + A_FLOAT, 0); class_addmethod(zNdelay_class, (t_method)zdel_helper, gensym("help"), 0); zexy_register("z~"); } -- cgit v1.2.1