aboutsummaryrefslogtreecommitdiff
path: root/src/mtx_decay.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mtx_decay.c')
-rw-r--r--src/mtx_decay.c95
1 files changed, 70 insertions, 25 deletions
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){