aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranz Zotter <fzotter@users.sourceforge.net>2005-09-26 07:57:02 +0000
committerFranz Zotter <fzotter@users.sourceforge.net>2005-09-26 07:57:02 +0000
commitb810cd1f4f95524debe30fe8805565aedfb151a3 (patch)
tree6705811e7282cde3a8a5273301cb15765e7d7b03
parenta0c0bb9a550d0164f7d684da5e6799129898868f (diff)
added symbolic creation arguments or mode parameters "row" "col" ["mtx"] to below described externals.
now the operation mode of these externs can be selected by arbitrary ordered creation argumens containing above symbols, or by a "mode col" etc. command. This makes it easier/more intuitive to patch without using help patches. svn path=/trunk/externals/iem/iemmatrix/; revision=3634
-rw-r--r--src/mtx_colon.c22
-rw-r--r--src/mtx_find.c79
-rw-r--r--src/mtx_minmax.c10
-rw-r--r--src/mtx_reverse.c44
4 files changed, 137 insertions, 18 deletions
diff --git a/src/mtx_colon.c b/src/mtx_colon.c
index c6ce8ff..269422a 100644
--- a/src/mtx_colon.c
+++ b/src/mtx_colon.c
@@ -16,12 +16,15 @@
#include "iemmatrix.h"
static t_class *mtx_colon_class;
+static t_symbol *col_sym;
+static t_symbol *col_sym2;
typedef struct _MTXColon_ MTXColon;
struct _MTXColon_
{
t_object x_obj;
int size;
+ t_symbol *colon_mode;
t_atom *list_out;
t_outlet *list_outlet;
@@ -33,6 +36,11 @@ static void deleteMTXColon (MTXColon *mtx_colon_obj)
freebytes (mtx_colon_obj->list_out, sizeof(t_atom)*(mtx_colon_obj->size+2));
}
+static void mTXSetColonMode (MTXColon *mtx_colon_obj, t_symbol *c_mode)
+{
+ mtx_colon_obj->colon_mode = c_mode;
+}
+
static void *newMTXColon (t_symbol *s, int argc, t_atom *argv)
{
MTXColon *mtx_colon_obj = (MTXColon *) pd_new (mtx_colon_class);
@@ -85,8 +93,15 @@ static void mTXColonList (MTXColon *mtx_colon_obj, t_symbol *s,
}
mtx_colon_obj->list_out = list_out;
- SETFLOAT (&list_out[0],1.0f);
- SETFLOAT (&list_out[1],(t_float)size);
+ if ((mtx_colon_obj->colon_mode == col_sym)||
+ (mtx_colon_obj->colon_mode == col_sym2)) {
+ SETFLOAT (&list_out[1],1.0f);
+ SETFLOAT (&list_out[0],(t_float)size);
+ }
+ else {
+ SETFLOAT (&list_out[0],1.0f);
+ SETFLOAT (&list_out[1],(t_float)size);
+ }
list_out += 2;
for (;size--;list_out++,startval+=step)
SETFLOAT(list_out,startval);
@@ -104,9 +119,12 @@ void mtx_colon_setup (void)
sizeof (MTXColon),
CLASS_DEFAULT, A_GIMME, 0);
class_addbang (mtx_colon_class, (t_method) mTXColonBang);
+ class_addmethod (mtx_colon_class, (t_method) mTXSetColonMode, gensym("mode"), A_DEFSYMBOL, 0);
class_addlist (mtx_colon_class, (t_method) mTXColonList);
class_addcreator ((t_newmethod) newMTXColon, gensym("mtx_:"), A_GIMME, 0);
class_sethelpsymbol (mtx_colon_class, gensym("iemmatrix/mtx_colon"));
+ col_sym = gensym("col");
+ col_sym2 = gensym("column");
}
void iemtx_colon_setup(void){
diff --git a/src/mtx_find.c b/src/mtx_find.c
index 6fdbee7..ca16060 100644
--- a/src/mtx_find.c
+++ b/src/mtx_find.c
@@ -16,6 +16,11 @@
#include "iemmatrix.h"
static t_class *mtx_find_class;
+static t_symbol *row_sym;
+static t_symbol *col_sym;
+static t_symbol *col_sym2;
+static t_symbol *mtx_sym;
+static t_symbol *mtx_sym2;
typedef struct _MTXfind_ MTXfind;
struct _MTXfind_
@@ -23,7 +28,8 @@ struct _MTXfind_
t_object x_obj;
int size;
int outsize;
- int find_dimension;
+ //int find_dimension;
+ t_symbol *find_mode;
int find_direction;
t_outlet *list_outlet;
@@ -45,7 +51,7 @@ static void mTXSetFindDirection (MTXfind *mtx_find_obj, t_float c_dir)
direction = 1;
mtx_find_obj->find_direction = direction;
}
-
+/*
static void mTXSetFindDimension (MTXfind *mtx_find_obj, t_float c_dim)
{
int dimension = (int) c_dim;
@@ -53,13 +59,40 @@ static void mTXSetFindDimension (MTXfind *mtx_find_obj, t_float c_dim)
dimension = (dimension < 3)?dimension:3;
mtx_find_obj->find_dimension = dimension;
}
+*/
+static void mTXSetFindMode (MTXfind *mtx_find_obj, t_symbol *c_dim)
+{
+ mtx_find_obj->find_mode = c_dim;
+}
static void *newMTXFind (t_symbol *s, int argc, t_atom *argv)
{
MTXfind *mtx_find_obj = (MTXfind *) pd_new (mtx_find_class);
- int c_dim = 0;
- int c_dir = 1;
+// int c_dim = 0;
+// int c_dir = 1;
+ mTXSetFindMode (mtx_find_obj, gensym(":"));
+ mTXSetFindDirection (mtx_find_obj, 1);
+ if (argc>=1) {
+ if (argv[0].a_type == A_SYMBOL) {
+ mTXSetFindMode (mtx_find_obj, atom_getsymbol (argv));
+ if (argc>=2)
+ if (argv[1].a_type != A_SYMBOL)
+ mTXSetFindDirection (mtx_find_obj, atom_getfloat (argv+1));
+ else
+ post("mtx_find: 2nd arg ignored. supposed to be float");
+ }
+ else {
+ mTXSetFindDirection (mtx_find_obj, atom_getfloat (argv));
+ if (argc>=2) {
+ if (argv[1].a_type == A_SYMBOL)
+ mTXSetFindMode (mtx_find_obj, atom_getsymbol (argv+1));
+ else
+ post("mtx_find: 2nd arg ignored. supposed to be symbolic, e.g. \"row\", \"col\", \":\", \"mtx\"");
+ }
+ }
+ }
+/*
switch ((argc>2)?2:argc) {
case 2:
c_dir = atom_getint(argv+1);
@@ -68,6 +101,7 @@ static void *newMTXFind (t_symbol *s, int argc, t_atom *argv)
}
mTXSetFindDimension (mtx_find_obj, (t_float) c_dim);
mTXSetFindDirection (mtx_find_obj, (t_float) c_dir);
+ */
mtx_find_obj->list_outlet = outlet_new (&mtx_find_obj->x_obj, gensym("matrix"));
@@ -229,6 +263,34 @@ static void mTXFindMatrix (MTXfind *mtx_find_obj, t_symbol *s,
list_out += 2;
//copyList (size, argv, list_out);
rows_out = 1;
+ if (mtx_find_obj->find_mode == row_sym) {
+ if (mtx_find_obj->find_direction == -1)
+ findLastNonZeroRow (rows, columns, list_in, list_out);
+ else
+ findFirstNonZeroRow (rows, columns, list_in, list_out);
+ rows_out = rows;
+ columns_out = 1;
+ }
+ else if ((mtx_find_obj->find_mode == col_sym)||
+ (mtx_find_obj->find_mode == col_sym2)) {
+ if (mtx_find_obj->find_direction == -1)
+ findLastNonZeroColumn (rows, columns, list_in, list_out);
+ else
+ findFirstNonZeroColumn (rows, columns, list_in, list_out);
+ columns_out = columns;
+ rows_out = 1;
+ }
+ else if ((mtx_find_obj->find_mode == mtx_sym)||
+ (mtx_find_obj->find_mode == mtx_sym2)) {
+ findReplaceNonZerosWithIndex (size, list_in, list_out);
+ rows_out = rows;
+ columns_out = columns;
+ }
+ else {
+ columns_out = findAllNonZeros (size, list_in, list_out);
+ rows_out = 1;
+ }
+ /*
switch (mtx_find_obj->find_dimension) {
case 0:
columns_out = findAllNonZeros (size, list_in, list_out);
@@ -256,6 +318,7 @@ static void mTXFindMatrix (MTXfind *mtx_find_obj, t_symbol *s,
columns_out = 1;
break;
}
+ */
mtx_find_obj->outsize = columns_out * rows_out;
list_out = mtx_find_obj->list_out;
@@ -276,9 +339,15 @@ void mtx_find_setup (void)
CLASS_DEFAULT, A_GIMME, 0);
class_addbang (mtx_find_class, (t_method) mTXFindBang);
class_addmethod (mtx_find_class, (t_method) mTXFindMatrix, gensym("matrix"), A_GIMME,0);
- class_addmethod (mtx_find_class, (t_method) mTXSetFindDimension, gensym("dimension"), A_DEFFLOAT,0);
+// class_addmethod (mtx_find_class, (t_method) mTXSetFindDimension, gensym("dimension"), A_DEFFLOAT,0);
+ class_addmethod (mtx_find_class, (t_method) mTXSetFindMode, gensym("mode"), A_DEFSYMBOL,0);
class_addmethod (mtx_find_class, (t_method) mTXSetFindDirection, gensym("direction"), A_DEFFLOAT,0);
class_sethelpsymbol (mtx_find_class, gensym("iemmatrix/mtx_find"));
+ row_sym = gensym("row");
+ col_sym = gensym("col");
+ col_sym2 = gensym("columns");
+ mtx_sym = gensym("mtx");
+ mtx_sym2 = gensym ("matrix");
}
void iemtx_find_setup(void){
diff --git a/src/mtx_minmax.c b/src/mtx_minmax.c
index 10f1453..03b81be 100644
--- a/src/mtx_minmax.c
+++ b/src/mtx_minmax.c
@@ -49,14 +49,13 @@ static void mTXSetMinMaxMode (MTXminmax *mtx_minmax_obj, t_symbol *m_sym)
static void *newMTXMin (t_symbol *s, int argc, t_atom *argv)
{
MTXminmax *mtx_minmax_obj = (MTXminmax *) pd_new (mtx_minmax_class);
- t_symbol *c_mode = 0;
+ mTXSetMinMaxMode (mtx_minmax_obj, gensym(":"));
switch ((argc>1)?1:argc) {
case 1:
- c_mode = atom_getsymbol (argv);
+ mTXSetMinMaxMode (mtx_minmax_obj, atom_getsymbol (argv));
}
mtx_minmax_obj->operator_minimum = 1;
- mTXSetMinMaxMode (mtx_minmax_obj, c_mode);
mtx_minmax_obj->list_outlet = outlet_new (&mtx_minmax_obj->x_obj, gensym("matrix"));
return ((void *) mtx_minmax_obj);
@@ -64,14 +63,13 @@ static void *newMTXMin (t_symbol *s, int argc, t_atom *argv)
static void *newMTXMax (t_symbol *s, int argc, t_atom *argv)
{
MTXminmax *mtx_minmax_obj = (MTXminmax *) pd_new (mtx_minmax_class);
- t_symbol *c_mode = 0;
+ mTXSetMinMaxMode (mtx_minmax_obj, gensym(":"));
switch ((argc>1)?1:argc) {
case 1:
- c_mode = atom_getsymbol (argv);
+ mTXSetMinMaxMode (mtx_minmax_obj, atom_getsymbol (argv));
}
mtx_minmax_obj->operator_minimum = 0;
- mTXSetMinMaxMode (mtx_minmax_obj, c_mode);
mtx_minmax_obj->list_outlet = outlet_new (&mtx_minmax_obj->x_obj, gensym("matrix"));
return ((void *) mtx_minmax_obj);
diff --git a/src/mtx_reverse.c b/src/mtx_reverse.c
index b95d23d..825a3b2 100644
--- a/src/mtx_reverse.c
+++ b/src/mtx_reverse.c
@@ -16,13 +16,17 @@
#include "iemmatrix.h"
static t_class *mtx_reverse_class;
+static t_symbol *row_sym;
+static t_symbol *col_sym;
+static t_symbol *col_sym2;
typedef struct _MTXreverse_ MTXreverse;
struct _MTXreverse_
{
t_object x_obj;
int size;
- int reverse_dimension;
+ //int reverse_dimension;
+ t_symbol *reverse_mode;
t_outlet *list_outlet;
@@ -35,7 +39,11 @@ static void deleteMTXreverse (MTXreverse *mtx_reverse_obj)
if (mtx_reverse_obj->list_out)
freebytes (mtx_reverse_obj->list_out, sizeof(t_atom)*(mtx_reverse_obj->size+2));
}
-
+static void mTXSetReverseMode (MTXreverse *mtx_reverse_obj, t_symbol *c_mode)
+{
+ mtx_reverse_obj->reverse_mode = c_mode;
+}
+/*
static void mTXSetreverseDimension (MTXreverse *mtx_reverse_obj, t_float c_dim)
{
int dimension = (int) c_dim;
@@ -43,11 +51,18 @@ static void mTXSetreverseDimension (MTXreverse *mtx_reverse_obj, t_float c_dim)
dimension = (dimension < 2)?dimension:2;
mtx_reverse_obj->reverse_dimension = dimension;
}
+*/
+
static void *newMTXreverse (t_symbol *s, int argc, t_atom *argv)
{
MTXreverse *mtx_reverse_obj = (MTXreverse *) pd_new (mtx_reverse_class);
- int c_dim = 0;
+ mTXSetReverseMode (mtx_reverse_obj, gensym(":"));
+ switch ((argc>1)?1:argc) {
+ case 1:
+ mTXSetReverseMode (mtx_reverse_obj, atom_getsymbol (argv));
+ }
+ /*int c_dim = 0;
mtx_reverse_obj->reverse_dimension = c_dim;
switch ((argc>1)?1:argc) {
@@ -55,7 +70,7 @@ static void *newMTXreverse (t_symbol *s, int argc, t_atom *argv)
c_dim = atom_getint(argv);
}
mTXSetreverseDimension (mtx_reverse_obj, (t_float) c_dim);
-
+*/
mtx_reverse_obj->list_outlet = outlet_new (&mtx_reverse_obj->x_obj, gensym("matrix"));
return ((void *) mtx_reverse_obj);
}
@@ -134,6 +149,20 @@ static void mTXreverseMatrix (MTXreverse *mtx_reverse_obj, t_symbol *s,
// main part
list_out += 2;
copyList (size, argv, list_out);
+
+ if ((mtx_reverse_obj->reverse_mode == col_sym)||
+ (mtx_reverse_obj->reverse_mode == col_sym2)) {
+ for (count = columns; count--; list_out++)
+ reverseListStep (size, columns, list_out);
+ }
+ else if (mtx_reverse_obj->reverse_mode == row_sym) {
+ for (count = rows; count--; list_out += columns)
+ reverseList (columns, list_out);
+ }
+ else
+ reverseList (size, list_out);
+
+/*
switch (mtx_reverse_obj->reverse_dimension) {
case 2:
for (count = columns; count--; list_out++)
@@ -147,6 +176,7 @@ static void mTXreverseMatrix (MTXreverse *mtx_reverse_obj, t_symbol *s,
reverseList (size, list_out);
break;
}
+ */
list_out = mtx_reverse_obj->list_out;
@@ -167,8 +197,12 @@ void mtx_reverse_setup (void)
CLASS_DEFAULT, A_GIMME, 0);
class_addbang (mtx_reverse_class, (t_method) mTXreverseBang);
class_addmethod (mtx_reverse_class, (t_method) mTXreverseMatrix, gensym("matrix"), A_GIMME,0);
- class_addmethod (mtx_reverse_class, (t_method) mTXSetreverseDimension, gensym("dimension"), A_DEFFLOAT,0);
+// class_addmethod (mtx_reverse_class, (t_method) mTXSetreverseDimension, gensym("dimension"), A_DEFFLOAT,0);
+ class_addmethod (mtx_reverse_class, (t_method) mTXSetReverseMode, gensym("mode"), A_DEFSYMBOL,0);
class_sethelpsymbol (mtx_reverse_class, gensym("iemmatrix/mtx_reverse"));
+ row_sym = gensym("row");
+ col_sym = gensym("col");
+ col_sym2 = gensym("column");
}
void iemtx_reverse_setup(void){