From 0ce3122718cfadf4104f7b4fb7d959f294d63918 Mon Sep 17 00:00:00 2001 From: Franz Zotter Date: Thu, 22 Sep 2005 09:28:55 +0000 Subject: re-newed column and row-wise operation selector. now [mode row(, [mode col( / [mode column( or [mode :( work in cumsum, decay, diff, sort, (and minmax) external. The order of creation arguments is in some kind arbitrary. svn path=/trunk/externals/iem/iemmatrix/; revision=3617 --- src/mtx_diff.c | 76 ++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 53 insertions(+), 23 deletions(-) (limited to 'src/mtx_diff.c') diff --git a/src/mtx_diff.c b/src/mtx_diff.c index 3f491ad..cf58ead 100644 --- a/src/mtx_diff.c +++ b/src/mtx_diff.c @@ -14,6 +14,9 @@ #include "iemmatrix.h" static t_class *mtx_diff_class; +static t_symbol *row_sym; +static t_symbol *col_sym; +static t_symbol *col_sym2; typedef struct _MTXdiff_ MTXdiff; struct _MTXdiff_ @@ -22,8 +25,8 @@ struct _MTXdiff_ int rows; int columns; int size; - int diff_dimension; int diff_direction; + t_symbol *diff_mode; t_outlet *list_outlet; @@ -48,27 +51,35 @@ static void mTXSetdiffDirection (MTXdiff *mtx_diff_obj, t_float c_dir) int direction = (int) c_dir; mtx_diff_obj->diff_direction = (direction==-1)?direction:1; } -static void mTXSetdiffDimension (MTXdiff *mtx_diff_obj, t_float c_dim) +static void mTXSetdiffMode (MTXdiff *mtx_diff_obj, t_symbol *c_mode) { - int dimension = (int) c_dim; - mtx_diff_obj->diff_dimension = (dimension==2)?dimension:1; + mtx_diff_obj->diff_mode = c_mode; } static void *newMTXdiff (t_symbol *s, int argc, t_atom *argv) { MTXdiff *mtx_diff_obj = (MTXdiff *) pd_new (mtx_diff_class); - int c_dir = 1; - int c_dim = 1; - - mtx_diff_obj->diff_dimension = c_dim; - switch ((argc>2)?2:argc) { - case 2: - c_dir = atom_getint(argv+1); - case 1: - c_dim = atom_getint(argv); + mTXSetdiffMode (mtx_diff_obj, gensym(":")); + mTXSetdiffDirection (mtx_diff_obj, 1.0f); + if (argc>=1) { + if (argv[0].a_type == A_SYMBOL) { + mTXSetdiffMode (mtx_diff_obj, atom_getsymbol (argv)); + if (argc>=2) + if (argv[1].a_type != A_SYMBOL) + mTXSetdiffDirection (mtx_diff_obj, atom_getfloat (argv+1)); + else + post("mtx_diff: 2nd arg ignored. supposed to be float"); + } + else { + mTXSetdiffDirection (mtx_diff_obj, atom_getfloat (argv)); + if (argc>=2) { + if (argv[1].a_type == A_SYMBOL) + mTXSetdiffMode (mtx_diff_obj, atom_getsymbol (argv+1)); + else + post("mtx_diff: 2nd arg ignored. supposed to be symbolic, e.g. \"row\", \"col\", \":\""); + } + } } - mTXSetdiffDirection (mtx_diff_obj, (t_float) c_dir); - mTXSetdiffDimension (mtx_diff_obj, (t_float) c_dim); mtx_diff_obj->list_outlet = outlet_new (&mtx_diff_obj->x_obj, gensym("matrix")); return ((void *) mtx_diff_obj); @@ -175,7 +186,8 @@ static void mTXdiffMatrix (MTXdiff *mtx_diff_obj, t_symbol *s, // main part // reading matrix from inlet - if (mtx_diff_obj->diff_dimension == 2) { + if ((mtx_diff_obj->diff_mode == col_sym) || + (mtx_diff_obj->diff_mode == col_sym2)) { readFloatFromListModulo (size, columns, list_ptr, x); columns = mtx_diff_obj->rows; rows = mtx_diff_obj->columns; @@ -185,19 +197,34 @@ static void mTXdiffMatrix (MTXdiff *mtx_diff_obj, t_symbol *s, // calculating diff if (mtx_diff_obj->diff_direction == -1) { - x += columns-1; - y += columns-1; - for (count = rows; count--; x += columns, y += columns) - diffReverse (columns,x,y); + if ((mtx_diff_obj->diff_mode == row_sym) || + (mtx_diff_obj->diff_mode == col_sym) || + (mtx_diff_obj->diff_mode == col_sym2)) { + x += columns-1; + y += columns-1; + for (count = rows; count--; x += columns, y += columns) + diffReverse (columns,x,y); + } + else { + x += size-1; + y += size-1; + diffReverse (size, x, y); + } } - else + else if ((mtx_diff_obj->diff_mode == row_sym) || + (mtx_diff_obj->diff_mode == col_sym) || + (mtx_diff_obj->diff_mode == col_sym2)) { for (count = rows; count--; x += columns, y += columns) diff (columns,x,y); + } + else + diff (size,x,y); x = mtx_diff_obj->x; y = mtx_diff_obj->y; // writing matrix to outlet - if (mtx_diff_obj->diff_dimension == 2) { + if ((mtx_diff_obj->diff_mode == col_sym) || + (mtx_diff_obj->diff_mode == col_sym2)) { columns = mtx_diff_obj->columns; rows = mtx_diff_obj->rows; writeFloatIntoListModulo (size, columns, list_out+2, y); @@ -222,9 +249,12 @@ void mtx_diff_setup (void) CLASS_DEFAULT, A_GIMME, 0); class_addbang (mtx_diff_class, (t_method) mTXdiffBang); class_addmethod (mtx_diff_class, (t_method) mTXdiffMatrix, gensym("matrix"), A_GIMME,0); - class_addmethod (mtx_diff_class, (t_method) mTXSetdiffDimension, gensym("dimension"), A_DEFFLOAT,0); + class_addmethod (mtx_diff_class, (t_method) mTXSetdiffMode, gensym("mode"), A_DEFSYMBOL,0); class_addmethod (mtx_diff_class, (t_method) mTXSetdiffDirection, gensym("direction"), A_DEFFLOAT,0); class_sethelpsymbol (mtx_diff_class, gensym("iemmatrix/mtx_diff")); + row_sym = gensym("row"); + col_sym = gensym("col"); + col_sym2 = gensym("column"); } void iemtx_diff_setup(void){ -- cgit v1.2.1