diff options
Diffstat (limited to 'src/pack.c')
-rw-r--r-- | src/pack.c | 66 |
1 files changed, 37 insertions, 29 deletions
@@ -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 <http://www.gnu.org/licenses/>. */ @@ -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; i<x->x_argc; i++) + for(i=0; i<x->x_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; n<count; n++){ - if(x->in[n]){ + for(n=0; n<count; n++) { + if(x->in[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); |