aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFranz Zotter <fzotter@users.sourceforge.net>2005-09-22 09:28:55 +0000
committerFranz Zotter <fzotter@users.sourceforge.net>2005-09-22 09:28:55 +0000
commit0ce3122718cfadf4104f7b4fb7d959f294d63918 (patch)
tree14899bba1075568ce20c59dd42d0b5cf1c1b43dc /src
parent0cb8519f8650bca7fed7cfa6d4907db115094beb (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/mtx_cumsum.c78
-rw-r--r--src/mtx_decay.c95
-rw-r--r--src/mtx_diff.c76
-rw-r--r--src/mtx_sort.c87
4 files changed, 243 insertions, 93 deletions
diff --git a/src/mtx_cumsum.c b/src/mtx_cumsum.c
index a5c12ba..da6b148 100644
--- a/src/mtx_cumsum.c
+++ b/src/mtx_cumsum.c
@@ -16,6 +16,9 @@
#include "iemmatrix.h"
static t_class *mtx_cumsum_class;
+static t_symbol *row_sym;
+static t_symbol *col_sym;
+static t_symbol *col_sym2;
typedef struct _MTXCumsum_ MTXCumsum;
struct _MTXCumsum_
@@ -24,8 +27,8 @@ struct _MTXCumsum_
int rows;
int columns;
int size;
- int cumsum_dimension;
int cumsum_direction;
+ t_symbol *cumsum_mode;
t_outlet *list_outlet;
@@ -50,27 +53,36 @@ static void mTXSetCumsumDirection (MTXCumsum *mtx_cumsum_obj, t_float c_dir)
int direction = (int) c_dir;
mtx_cumsum_obj->cumsum_direction = (direction==-1)?direction:1;
}
-static void mTXSetCumsumDimension (MTXCumsum *mtx_cumsum_obj, t_float c_dim)
+
+static void mTXSetCumsumMode (MTXCumsum *mtx_cumsum_obj, t_symbol *m_sym)
{
- int dimension = (int) c_dim;
- mtx_cumsum_obj->cumsum_dimension = (dimension==2)?dimension:1;
+ mtx_cumsum_obj->cumsum_mode = m_sym;
}
static void *newMTXCumsum (t_symbol *s, int argc, t_atom *argv)
{
MTXCumsum *mtx_cumsum_obj = (MTXCumsum *) pd_new (mtx_cumsum_class);
- int c_dir = 1;
- int c_dim = 1;
-
- mtx_cumsum_obj->cumsum_dimension = c_dim;
- switch ((argc>2)?2:argc) {
- case 2:
- c_dir = atom_getint(argv+1);
- case 1:
- c_dim = atom_getint(argv);
+ mTXSetCumsumMode (mtx_cumsum_obj, gensym(":"));
+ mTXSetCumsumDirection (mtx_cumsum_obj, 1.0f);
+ if (argc>=1) {
+ if (argv[0].a_type == A_SYMBOL) {
+ mTXSetCumsumMode (mtx_cumsum_obj, atom_getsymbol (argv));
+ if (argc>=2)
+ if (argv[1].a_type != A_SYMBOL)
+ mTXSetCumsumDirection (mtx_cumsum_obj, atom_getfloat (argv+1));
+ else
+ post("mtx_cumsum: 2nd arg ignored. supposed to be float");
+ }
+ else {
+ mTXSetCumsumDirection (mtx_cumsum_obj, atom_getfloat (argv));
+ if (argc>=2) {
+ if (argv[1].a_type == A_SYMBOL)
+ mTXSetCumsumMode (mtx_cumsum_obj, atom_getsymbol (argv+1));
+ else
+ post("mtx_cumsum: 2nd arg ignored. supposed to be symbolic, e.g. \"row\", \"col\", \":\"");
+ }
+ }
}
- mTXSetCumsumDirection (mtx_cumsum_obj, (t_float) c_dir);
- mTXSetCumsumDimension (mtx_cumsum_obj, (t_float) c_dim);
mtx_cumsum_obj->list_outlet = outlet_new (&mtx_cumsum_obj->x_obj, gensym("matrix"));
return ((void *) mtx_cumsum_obj);
@@ -181,7 +193,8 @@ static void mTXCumsumMatrix (MTXCumsum *mtx_cumsum_obj, t_symbol *s,
// main part
// reading matrix from inlet
- if (mtx_cumsum_obj->cumsum_dimension == 2) {
+ if ((mtx_cumsum_obj->cumsum_mode == col_sym) ||
+ (mtx_cumsum_obj->cumsum_mode == col_sym2)) {
readFloatFromListModulo (size, columns, list_ptr, x);
columns = mtx_cumsum_obj->rows;
rows = mtx_cumsum_obj->columns;
@@ -191,19 +204,35 @@ static void mTXCumsumMatrix (MTXCumsum *mtx_cumsum_obj, t_symbol *s,
// calculating cumsum
if (mtx_cumsum_obj->cumsum_direction == -1) {
- x += columns-1;
- y += columns-1;
- for (count = rows; count--; x += columns, y += columns)
- cumSumReverse (columns,x,y);
+ if ((mtx_cumsum_obj->cumsum_mode == row_sym) ||
+ (mtx_cumsum_obj->cumsum_mode == col_sym) ||
+ (mtx_cumsum_obj->cumsum_mode == col_sym2)) {
+ x += columns-1;
+ y += columns-1;
+
+ for (count = rows; count--; x += columns, y += columns)
+ cumSumReverse (columns,x,y);
+ }
+ else {
+ x += size-1;
+ y += size-1;
+ cumSumReverse (size, x, y);
+ }
}
- else
+ else if ((mtx_cumsum_obj->cumsum_mode == row_sym) ||
+ (mtx_cumsum_obj->cumsum_mode == col_sym) ||
+ (mtx_cumsum_obj->cumsum_mode == col_sym2))
for (count = rows; count--; x += columns, y += columns)
cumSum (columns,x,y);
+ else
+ cumSum (size, x, y);
+
x = mtx_cumsum_obj->x;
y = mtx_cumsum_obj->y;
// writing matrix to outlet
- if (mtx_cumsum_obj->cumsum_dimension == 2) {
+ if ((mtx_cumsum_obj->cumsum_mode == col_sym) ||
+ (mtx_cumsum_obj->cumsum_mode == col_sym2)) {
columns = mtx_cumsum_obj->columns;
rows = mtx_cumsum_obj->rows;
writeFloatIntoListModulo (size, columns, list_out+2, y);
@@ -228,9 +257,12 @@ void mtx_cumsum_setup (void)
CLASS_DEFAULT, A_GIMME, 0);
class_addbang (mtx_cumsum_class, (t_method) mTXCumsumBang);
class_addmethod (mtx_cumsum_class, (t_method) mTXCumsumMatrix, gensym("matrix"), A_GIMME,0);
- class_addmethod (mtx_cumsum_class, (t_method) mTXSetCumsumDimension, gensym("dimension"), A_DEFFLOAT,0);
+ class_addmethod (mtx_cumsum_class, (t_method) mTXSetCumsumMode, gensym("mode"), A_DEFSYMBOL,0);
class_addmethod (mtx_cumsum_class, (t_method) mTXSetCumsumDirection, gensym("direction"), A_DEFFLOAT,0);
class_sethelpsymbol (mtx_cumsum_class, gensym("iemmatrix/mtx_cumsum"));
+ row_sym = gensym("row");
+ col_sym = gensym("col");
+ col_sym2 = gensym("column");
}
void iemtx_cumsum_setup(void){
diff --git a/src/mtx_decay.c b/src/mtx_decay.c
index 9170d43..293ef16 100644
--- a/src/mtx_decay.c
+++ b/src/mtx_decay.c
@@ -15,6 +15,10 @@
#include "iemmatrix.h"
static t_class *mtx_decay_class;
+static t_symbol *row_sym;
+static t_symbol *col_sym;
+static t_symbol *col_sym2;
+
typedef struct _MTXDecay_ MTXDecay;
struct _MTXDecay_
@@ -23,8 +27,8 @@ struct _MTXDecay_
int rows;
int columns;
int size;
- int decay_dimension;
int decay_direction;
+ t_symbol *decay_mode;
t_float decay_parameter;
t_outlet *list_outlet;
@@ -56,31 +60,51 @@ static void mTXSetDecayDirection (MTXDecay *mtx_decay_obj, t_float c_dir)
int direction = (int) c_dir;
mtx_decay_obj->decay_direction = (direction==-1)?direction:1;
}
-static void mTXSetDecayDimension (MTXDecay *mtx_decay_obj, t_float c_dim)
+static void mTXSetDecayMode (MTXDecay *mtx_decay_obj, t_symbol *c_mode)
{
- int dimension = (int) c_dim;
- mtx_decay_obj->decay_dimension = (dimension==2)?dimension:1;
+ mtx_decay_obj->decay_mode = c_mode;
}
static void *newMTXDecay (t_symbol *s, int argc, t_atom *argv)
{
MTXDecay *mtx_decay_obj = (MTXDecay *) pd_new (mtx_decay_class);
- int c_dir = 1;
- int c_dim = 1;
- t_float c_par = 0.9f;
+ int sym_count=0;
+ int first_sym=argc;
+ int n=0;
+
+ mTXSetDecayMode (mtx_decay_obj, gensym(":"));
+ mTXSetDecayDirection (mtx_decay_obj, 1);
+ mTXSetDecayParameter (mtx_decay_obj, .9f);
- mtx_decay_obj->decay_dimension = c_dim;
- switch ((argc>3)?3:argc) {
+ argc = ((argc<3)?argc:3);
+ while (n < argc) {
+ if (argv[n].a_type == A_SYMBOL) {
+ post("postition %d",n);
+ sym_count++;
+ first_sym = (first_sym<n)?first_sym:n;
+ }
+ n++;
+ }
+ if (sym_count >= 1)
+ mTXSetDecayMode (mtx_decay_obj, atom_getsymbol(argv+first_sym));
+ if (sym_count > 1) {
+ post("mtx_decay: args after pos %d ignored. supposed to be non-symbolic",first_sym);
+ argc = first_sym+1;
+ }
+
+ switch (argc) {
case 3:
- c_dir = atom_getint(argv+2);
+ if (first_sym < 2)
+ mTXSetDecayDirection (mtx_decay_obj, atom_getfloat (argv+2));
case 2:
- c_dim = atom_getint(argv+1);
+ if (first_sym < 1)
+ mTXSetDecayParameter (mtx_decay_obj, atom_getfloat (argv+1));
+ else if (first_sym > 1)
+ mTXSetDecayDirection (mtx_decay_obj, atom_getfloat(argv+1));
case 1:
- c_par = atom_getfloat(argv);
+ if (first_sym != 0)
+ mTXSetDecayParameter (mtx_decay_obj, atom_getfloat (argv));
}
- mTXSetDecayParameter (mtx_decay_obj, c_par);
- mTXSetDecayDirection (mtx_decay_obj, (t_float) c_dir);
- mTXSetDecayDimension (mtx_decay_obj, (t_float) c_dim);
mtx_decay_obj->list_outlet = outlet_new (&mtx_decay_obj->x_obj, gensym("matrix"));
return ((void *) mtx_decay_obj);
@@ -193,7 +217,9 @@ static void mTXDecayMatrix (MTXDecay *mtx_decay_obj, t_symbol *s,
// main part
// reading matrix from inlet
- if (mtx_decay_obj->decay_dimension == 2) {
+
+ if ((mtx_decay_obj->decay_mode == col_sym) ||
+ (mtx_decay_obj->decay_mode == col_sym2)) {
readFloatFromListModulo (size, columns, list_ptr, x);
columns = mtx_decay_obj->rows;
rows = mtx_decay_obj->columns;
@@ -203,19 +229,35 @@ static void mTXDecayMatrix (MTXDecay *mtx_decay_obj, t_symbol *s,
// calculating decay
if (mtx_decay_obj->decay_direction == -1) {
- x += columns-1;
- y += columns-1;
- for (count = rows; count--; x += columns, y += columns)
- deCayReverse (columns,x,y,mtx_decay_obj->decay_parameter);
+ if ((mtx_decay_obj->decay_mode == col_sym) ||
+ (mtx_decay_obj->decay_mode == col_sym2) ||
+ (mtx_decay_obj->decay_mode == row_sym)) {
+ x += columns-1;
+ y += columns-1;
+ for (count = rows; count--; x += columns, y += columns)
+ deCayReverse (columns,x,y,mtx_decay_obj->decay_parameter);
+ }
+ else {
+ x += size-1;
+ y += size-1;
+ deCayReverse (size,x,y,mtx_decay_obj->decay_parameter);
+ }
+ }
+ else {
+ if ((mtx_decay_obj->decay_mode == col_sym) ||
+ (mtx_decay_obj->decay_mode == col_sym2) ||
+ (mtx_decay_obj->decay_mode == row_sym))
+ for (count = rows; count--; x += columns, y += columns)
+ deCay (columns,x,y,mtx_decay_obj->decay_parameter);
+ else
+ deCay (size,x,y,mtx_decay_obj->decay_parameter);
}
- else
- for (count = rows; count--; x += columns, y += columns)
- deCay (columns,x,y,mtx_decay_obj->decay_parameter);
x = mtx_decay_obj->x;
y = mtx_decay_obj->y;
// writing matrix to outlet
- if (mtx_decay_obj->decay_dimension == 2) {
+ if ((mtx_decay_obj->decay_mode == col_sym) ||
+ (mtx_decay_obj->decay_mode == col_sym2)) {
columns = mtx_decay_obj->columns;
rows = mtx_decay_obj->rows;
writeFloatIntoListModulo (size, columns, list_out+2, y);
@@ -241,9 +283,12 @@ void mtx_decay_setup (void)
class_addbang (mtx_decay_class, (t_method) mTXDecayBang);
class_addmethod (mtx_decay_class, (t_method) mTXDecayMatrix, gensym("matrix"), A_GIMME,0);
class_addmethod (mtx_decay_class, (t_method) mTXSetDecayParameter, gensym("alpha"), A_DEFFLOAT,0);
- class_addmethod (mtx_decay_class, (t_method) mTXSetDecayDimension, gensym("dimension"), A_DEFFLOAT,0);
+ class_addmethod (mtx_decay_class, (t_method) mTXSetDecayMode, gensym("mode"), A_DEFSYMBOL,0);
class_addmethod (mtx_decay_class, (t_method) mTXSetDecayDirection, gensym("direction"), A_DEFFLOAT,0);
class_sethelpsymbol (mtx_decay_class, gensym("iemmatrix/mtx_decay"));
+ row_sym = gensym("row");
+ col_sym = gensym("col");
+ col_sym2 = gensym("column");
}
void iemtx_decay_setup(void){
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){
diff --git a/src/mtx_sort.c b/src/mtx_sort.c
index fb47ed6..f2cf81e 100644
--- a/src/mtx_sort.c
+++ b/src/mtx_sort.c
@@ -15,6 +15,9 @@
#include "iemmatrix.h"
static t_class *mtx_sort_class;
+static t_symbol *row_sym;
+static t_symbol *col_sym;
+static t_symbol *col_sym2;
typedef struct _MTXSort_ MTXSort;
struct _MTXSort_
@@ -23,7 +26,7 @@ struct _MTXSort_
int rows;
int columns;
int size;
- int sort_dimension;
+ t_symbol *sort_mode;
int sort_direction;
t_outlet *list_outlet1;
@@ -56,29 +59,38 @@ static void mTXSetSortDirection (MTXSort *mtx_sort_obj, t_float s_dir)
int direction = (int) s_dir;
mtx_sort_obj->sort_direction = (direction==-1)?direction:1;
}
-static void mTXSetSortDimension (MTXSort *mtx_sort_obj, t_float s_dim)
+
+static void mTXSetSortMode (MTXSort *mtx_sort_obj, t_symbol *m_sym)
{
- int dimension = (int) s_dim;
- dimension = (dimension<2)?dimension:2;
- dimension = (dimension>0)?dimension:0;
- mtx_sort_obj->sort_dimension = dimension;
+ mtx_sort_obj->sort_mode = m_sym;
}
static void *newMTXSort (t_symbol *s, int argc, t_atom *argv)
{
MTXSort *mtx_sort_obj = (MTXSort *) pd_new (mtx_sort_class);
- int c_dir = 1;
- int c_dim = 1;
-
- mtx_sort_obj->sort_dimension = c_dim;
- switch ((argc>2)?2:argc) {
- case 2:
- c_dir = atom_getint(argv+1);
- case 1:
- c_dim = atom_getint(argv);
+
+ // defaults:
+ mTXSetSortMode (mtx_sort_obj, gensym(":"));
+ mTXSetSortDirection (mtx_sort_obj, 1.0f);
+ if (argc>=1) {
+ if (argv[0].a_type == A_SYMBOL) {
+ mTXSetSortMode (mtx_sort_obj, atom_getsymbol (argv));
+ if (argc>=2)
+ if (argv[1].a_type != A_SYMBOL)
+ mTXSetSortDirection (mtx_sort_obj, atom_getfloat (argv+1));
+ else
+ post("mtx_sort: 2nd arg ignored. supposed to be float");
+ }
+ else {
+ mTXSetSortDirection (mtx_sort_obj, atom_getfloat (argv));
+ if (argc>=2) {
+ if (argv[1].a_type == A_SYMBOL)
+ mTXSetSortMode (mtx_sort_obj, atom_getsymbol (argv+1));
+ else
+ post("mtx_sort: 2nd arg ignored. supposed to be symbolic, e.g. \"row\", \"col\", \":\"");
+ }
+ }
}
- mTXSetSortDirection (mtx_sort_obj, (t_float) c_dir);
- mTXSetSortDimension (mtx_sort_obj, (t_float) c_dim);
mtx_sort_obj->list_outlet1 = outlet_new (&mtx_sort_obj->x_obj, gensym("matrix"));
mtx_sort_obj->list_outlet2 = outlet_new (&mtx_sort_obj->x_obj, gensym("matrix"));
@@ -173,6 +185,7 @@ static void sortVector (int n, t_float *x, t_float *i, int direction)
}
}
+/*
static void indexingVector (int n, int m, int dimension, t_float *i)
{
int count;
@@ -195,6 +208,28 @@ static void indexingVector (int n, int m, int dimension, t_float *i)
*--i = idx--;
}
}
+*/
+static void indexingVector (int n, int m, t_symbol *sort_mode, t_float *i)
+{
+ int count;
+ int count2;
+ int idx = n;
+ t_float *ptr;
+ i += n;
+ if ((sort_mode == col_sym)||(sort_mode == col_sym2)) {
+ n /= m;
+ for (count = m; count--;) {
+ ptr = --i;
+ for (count2 = n; count2--; ptr -= m)
+ *ptr = idx--;
+ }
+ }
+ else {
+ for (; idx;)
+ *--i = idx--;
+ }
+}
+
static void mTXSortMatrix (MTXSort *mtx_sort_obj, t_symbol *s,
int argc, t_atom *argv)
@@ -260,11 +295,12 @@ static void mTXSortMatrix (MTXSort *mtx_sort_obj, t_symbol *s,
mtx_sort_obj->columns = columns;
// generating indexing vector
- indexingVector (size, columns, mtx_sort_obj->sort_dimension, i);
+ indexingVector (size, columns, mtx_sort_obj->sort_mode, i);
// main part
// reading matrix from inlet
- if (mtx_sort_obj->sort_dimension == 2) {
+ if ((mtx_sort_obj->sort_mode == col_sym)||
+ (mtx_sort_obj->sort_mode == col_sym2)) {
readFloatFromListModulo (size, columns, list_ptr, x);
columns = mtx_sort_obj->rows;
rows = mtx_sort_obj->columns;
@@ -273,7 +309,9 @@ static void mTXSortMatrix (MTXSort *mtx_sort_obj, t_symbol *s,
readFloatFromList (size, list_ptr, x);
// calculating sort
- if (mtx_sort_obj->sort_dimension == 0)
+ if ((mtx_sort_obj->sort_mode != col_sym) &&
+ (mtx_sort_obj->sort_mode != col_sym2) &&
+ (mtx_sort_obj->sort_mode != row_sym))
sortVector (size,x,i,mtx_sort_obj->sort_direction);
else
for (count = rows; count--;x+=columns,i+=columns)
@@ -282,7 +320,8 @@ static void mTXSortMatrix (MTXSort *mtx_sort_obj, t_symbol *s,
i = mtx_sort_obj->i;
// writing matrix to outlet
- if (mtx_sort_obj->sort_dimension == 2) {
+ if ((mtx_sort_obj->sort_mode == col_sym)||
+ (mtx_sort_obj->sort_mode == col_sym2)) {
columns = mtx_sort_obj->columns;
rows = mtx_sort_obj->rows;
writeFloatIntoListModulo (size, columns, list_out1+2, x);
@@ -315,9 +354,13 @@ void mtx_sort_setup (void)
CLASS_DEFAULT, A_GIMME, 0);
class_addbang (mtx_sort_class, (t_method) mTXSortBang);
class_addmethod (mtx_sort_class, (t_method) mTXSortMatrix, gensym("matrix"), A_GIMME,0);
- class_addmethod (mtx_sort_class, (t_method) mTXSetSortDimension, gensym("dimension"), A_DEFFLOAT,0);
+ class_addmethod (mtx_sort_class, (t_method) mTXSetSortMode, gensym("mode"), A_DEFSYMBOL,0);
+// class_addmethod (mtx_sort_class, (t_method) mTXSetSortDimension, gensym("dimension"), A_DEFFLOAT,0);
class_addmethod (mtx_sort_class, (t_method) mTXSetSortDirection, gensym("direction"), A_DEFFLOAT,0);
class_sethelpsymbol (mtx_sort_class, gensym("iemmatrix/mtx_sort"));
+ row_sym = gensym("row");
+ col_sym = gensym("col");
+ col_sym2 = gensym("column");
}
void iemtx_sort_setup(void){