aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFranz Zotter <fzotter@users.sourceforge.net>2006-08-14 12:43:53 +0000
committerFranz Zotter <fzotter@users.sourceforge.net>2006-08-14 12:43:53 +0000
commit81eaaab1c44599515b2b2bf14b2384adbba1f273 (patch)
treee415527af594f2932be164e243b98077a57ea869 /src
parent97ceb7794f0f9937176593283f2b19780035c61c (diff)
corrections to mtx_fill:
passive inlet matrix can pass through if invalid indices/ empty indexing vectors are defined. this is useful when combining with mtx_find and the result of mtx_find is empty or undefined (=0 indices). svn path=/trunk/externals/iem/iemmatrix/; revision=5591
Diffstat (limited to 'src')
-rw-r--r--src/mtx_fill.c115
1 files changed, 46 insertions, 69 deletions
diff --git a/src/mtx_fill.c b/src/mtx_fill.c
index 90fc7aa..29b4fd0 100644
--- a/src/mtx_fill.c
+++ b/src/mtx_fill.c
@@ -17,7 +17,8 @@
typedef enum {
FILL_SUBMATRIX,
- FILL_INDEXED_ELEMENTS
+ FILL_INDEXED_ELEMENTS,
+ DONT_FILL_JUST_PASS
} FillStyle;
static t_class *mtx_fill_class;
@@ -35,20 +36,18 @@ struct _MTXfill_
int *index;
int index_size;
+ int num_idcs_used;
int max_index;
FillStyle fill_type;
t_outlet *list_outlet;
- t_atom *list_in;
t_atom *list_out;
};
static void deleteMTXFill (MTXfill *mtx_fill_obj)
{
- if (mtx_fill_obj->list_in)
- freebytes (mtx_fill_obj->list_in, sizeof(t_atom)*(mtx_fill_obj->size+2));
if (mtx_fill_obj->list_out)
freebytes (mtx_fill_obj->list_out, sizeof(t_atom)*(mtx_fill_obj->size+2));
if (mtx_fill_obj->index)
@@ -106,13 +105,14 @@ static void mTXFillIndexMatrix (MTXfill *mtx_fill_obj, t_symbol *s,
// size check
if (!size) {
- post("mtx_fill: invalid dimensions/invalid start index");
+ mtx_fill_obj->fill_type = DONT_FILL_JUST_PASS;
return;
}
if (list_size == 0) {
if ((rows<1) || (columns<1)){
post("mtx_fill: row and column indices must be >0");
+ mtx_fill_obj->fill_type = DONT_FILL_JUST_PASS;
return;
}
mtx_fill_obj->fill_startrow = rows;
@@ -120,7 +120,7 @@ static void mTXFillIndexMatrix (MTXfill *mtx_fill_obj, t_symbol *s,
mtx_fill_obj->fill_type = FILL_SUBMATRIX;
}
else if (list_size<size) {
- post("mtx_fill: sparse matrix not yet supported: use \"mtx_check\"");
+ mtx_fill_obj->fill_type = DONT_FILL_JUST_PASS;
return;
}
else {
@@ -132,21 +132,15 @@ static void mTXFillIndexMatrix (MTXfill *mtx_fill_obj, t_symbol *s,
sizeof (int) * (mtx_fill_obj->index_size+2),
sizeof (t_atom) * (size + 2));
mtx_fill_obj->index_size = size;
+ mtx_fill_obj->index = index;
}
mtx_fill_obj->max_index =
copyNonZeroAtomsToIntegerArrayMax (&size, argv++, index);
- if (!size) {
- post("mtx_fill: indexing matrix contains zero-values only!!!");
- return;
- }
- if (size != mtx_fill_obj->index_size) {
- index = (int *) resizebytes (index,
- sizeof (int) * (mtx_fill_obj->index_size+2),
- sizeof (t_atom) * (size + 2));
- mtx_fill_obj->index_size = size;
- }
- mtx_fill_obj->fill_type = FILL_INDEXED_ELEMENTS;
- mtx_fill_obj->index = index;
+ mtx_fill_obj->num_idcs_used = size;
+ if (!size)
+ mtx_fill_obj->fill_type = DONT_FILL_JUST_PASS;
+ else
+ mtx_fill_obj->fill_type = FILL_INDEXED_ELEMENTS;
}
}
@@ -154,9 +148,10 @@ static void *newMTXFill (t_symbol *s, int argc, t_atom *argv)
{
MTXfill *mtx_fill_obj = (MTXfill *) pd_new (mtx_fill_class);
+ mtx_fill_obj->size = 0;
mtx_fill_obj->fill_startrow = 1;
mtx_fill_obj->fill_startcol = 1;
- mtx_fill_obj->fill_type = FILL_SUBMATRIX;
+ mtx_fill_obj->fill_type = DONT_FILL_JUST_PASS;
error("[mtx_fill]: this object _might_ change in the future!");
if (argc) {
if (atom_getsymbol(argv)==gensym("matrix"))
@@ -174,11 +169,10 @@ static void *newMTXFill (t_symbol *s, int argc, t_atom *argv)
static void mTXBigMatrix (MTXfill *mtx_fill_obj, t_symbol *s,
int argc, t_atom *argv)
{
- int rows = atom_getint (argv++);
- int columns = atom_getint (argv++);
+ int rows = atom_getint (argv);
+ int columns = atom_getint (argv+1);
int size = rows * columns;
int list_size = argc - 2;
- t_atom *list_in = mtx_fill_obj->list_in;
t_atom *list_out = mtx_fill_obj->list_out;
// size check
@@ -198,21 +192,14 @@ static void mTXBigMatrix (MTXfill *mtx_fill_obj, t_symbol *s,
list_out = (t_atom *) resizebytes (list_out,
sizeof (t_atom) * (mtx_fill_obj->size+2),
sizeof (t_atom) * (size + 2));
- if (!list_in)
- list_in = (t_atom *) getbytes (sizeof (t_atom) * (size + 2));
- else
- list_in = (t_atom *) resizebytes (list_in,
- sizeof (t_atom) * (mtx_fill_obj->size+2),
- sizeof (t_atom) * (size + 2));
}
mtx_fill_obj->size = size;
mtx_fill_obj->columns = columns;
mtx_fill_obj->rows = rows;
mtx_fill_obj->list_out = list_out;
- mtx_fill_obj->list_in = list_in;
- copyList (size, argv, list_in);
+ memcpy(list_out,argv,argc*sizeof(t_atom));
}
@@ -232,34 +219,29 @@ static void writeFillMatrixIntoList (int fillrows, const int fillcols, int colum
static void mTXFillScalar (MTXfill *mtx_fill_obj, t_float f)
{
t_atom *list_out = mtx_fill_obj->list_out;
- t_atom *list_in = mtx_fill_obj->list_in;
int rows = mtx_fill_obj->rows;
int columns = mtx_fill_obj->columns;
- if (mtx_fill_obj->fill_type == FILL_INDEXED_ELEMENTS) {
- if (mtx_fill_obj->max_index > mtx_fill_obj->size) {
- post("mtx_fill: index matrix index exceeds matrix borders");
- return;
- }
- else if (mtx_fill_obj->size == 0) {
- post("mtx_fill: no matrix defined for filling");
- return;
- }
-
- // main part
- list_out += 2;
- copyList (mtx_fill_obj->size, list_in, list_out);
- writeFloatIndexedIntoMatrix (mtx_fill_obj->index_size,
- mtx_fill_obj->index, f,list_out);
- list_out = mtx_fill_obj->list_out;
- SETSYMBOL(list_out, gensym("matrix"));
- SETFLOAT(list_out, rows);
- SETFLOAT(&list_out[1], columns);
- outlet_anything(mtx_fill_obj->list_outlet, gensym("matrix"),
- mtx_fill_obj->size+2, list_out);
+ switch (mtx_fill_obj->fill_type) {
+ case FILL_SUBMATRIX:
+ post("mtx_fill: scalar fill for submatrices not supported yet");
+ return;
+ break;
+ case FILL_INDEXED_ELEMENTS:
+ if (mtx_fill_obj->max_index > mtx_fill_obj->size) {
+ post("mtx_fill: index matrix index exceeds matrix borders");
+ return;
+ }
+ if (mtx_fill_obj->size == 0) {
+ post("mtx_fill: no matrix defined for filling");
+ return;
+ }
+ // main part
+ writeFloatIndexedIntoMatrix (mtx_fill_obj->num_idcs_used,
+ mtx_fill_obj->index, f,list_out+2);
+ default:
+ mTXFillBang(mtx_fill_obj);
}
- else
- post("mtx_fill: scalar fill for submatrices not supported yet");
}
@@ -273,11 +255,15 @@ static void mTXFillMatrix (MTXfill *mtx_fill_obj, t_symbol *s,
int rows = mtx_fill_obj->rows;
int columns = mtx_fill_obj->columns;
t_atom *fill_mtx = argv;
- t_atom *list_in = mtx_fill_obj->list_in;
t_atom *list_out = mtx_fill_obj->list_out;
int stopcol = mtx_fill_obj->fill_startcol+fill_columns-1;
int stoprow = mtx_fill_obj->fill_startrow+fill_rows-1;
+ if (mtx_fill_obj->fill_type == DONT_FILL_JUST_PASS) {
+ mTXFillBang(mtx_fill_obj);
+ return;
+ }
+
// size check
if (!list_size) {
post("mtx_fill: invalid dimensions");
@@ -296,7 +282,7 @@ static void mTXFillMatrix (MTXfill *mtx_fill_obj, t_symbol *s,
}
break;
case FILL_INDEXED_ELEMENTS:
- if (list_size < mtx_fill_obj->index_size) {
+ if (list_size < mtx_fill_obj->num_idcs_used) {
post("mtx_fill: fill matrix smaller than indexing vector");
return;
}
@@ -311,29 +297,20 @@ static void mTXFillMatrix (MTXfill *mtx_fill_obj, t_symbol *s,
return;
}
-
// main part
- list_out += 2;
- copyList (mtx_fill_obj->size, list_in, list_out);
-
switch (mtx_fill_obj->fill_type) {
case FILL_SUBMATRIX:
list_out += columns * (mtx_fill_obj->fill_startrow-1) +
mtx_fill_obj->fill_startcol-1;
writeFillMatrixIntoList (fill_rows, fill_columns,
- columns, fill_mtx, list_out);
+ columns, fill_mtx, list_out+2);
break;
case FILL_INDEXED_ELEMENTS:
- writeIndexedValuesIntoMatrix (mtx_fill_obj->index_size,
- mtx_fill_obj->index, fill_mtx,list_out);
+ writeIndexedValuesIntoMatrix (mtx_fill_obj->num_idcs_used,
+ mtx_fill_obj->index, fill_mtx,list_out+2);
break;
}
- list_out = mtx_fill_obj->list_out;
- SETSYMBOL(list_out, gensym("matrix"));
- SETFLOAT(list_out, rows);
- SETFLOAT(&list_out[1], columns);
- outlet_anything(mtx_fill_obj->list_outlet, gensym("matrix"),
- mtx_fill_obj->size+2, list_out);
+ mTXFillBang(mtx_fill_obj);
}
void mtx_fill_setup (void)