diff options
Diffstat (limited to 'nusmuk-utils/mtx_preset.c')
-rw-r--r-- | nusmuk-utils/mtx_preset.c | 80 |
1 files changed, 62 insertions, 18 deletions
diff --git a/nusmuk-utils/mtx_preset.c b/nusmuk-utils/mtx_preset.c index 912d4c6..4c4f8d4 100644 --- a/nusmuk-utils/mtx_preset.c +++ b/nusmuk-utils/mtx_preset.c @@ -108,7 +108,7 @@ void mtx_preset_matrix(t_mtx_preset *x, t_symbol *s, int argc, t_atom *argv) } } } - else if ((argc > 1) && (argv[1].a_type == A_FLOAT)) { + else if ((argc > 0) && (argv[0].a_type == A_FLOAT)) { // reception de matrix value for (i=0; i < x->sizeX; i++) { for (j=0; j < x->sizeY; j++) { @@ -133,7 +133,8 @@ void mtx_preset_row(t_mtx_preset *x, t_symbol *s, int argc, t_atom *argv) error("bad row"); return; } - row = min(x->sizeY, row); + row = min(x->sizeY-1, row); + row = max(0, row); for (i=0; i < x->sizeX; i++) if ((argc > i+1) && (argv[i+1].a_type == A_FLOAT)) x->matrix[i][row] = atom_getfloatarg(i+1,argc,argv); @@ -150,7 +151,8 @@ void mtx_preset_col(t_mtx_preset *x, t_symbol *s, int argc, t_atom *argv) error("bad col"); return; } - col = min(x->sizeX, col); + col = min(x->sizeX-1, col); + col = max(0, col); for (i=0; i < x->sizeY; i++) if ((argc > i+1) && (argv[i+1].a_type == A_FLOAT)) x->matrix[col][i] = atom_getfloatarg(i+1,argc,argv); @@ -161,7 +163,7 @@ void mtx_preset_setrow(t_mtx_preset *x, t_float rowtoset, t_float value) // reception de row Y value int row, i; - row = min(x->sizeY, rowtoset); + row = min(x->sizeY-1, rowtoset); row = max(0, row); for (i=0; i < x->sizeX; i++) @@ -173,7 +175,7 @@ void mtx_preset_setcol(t_mtx_preset *x, t_float coltoset, t_float value) // reception de col X value int col, i; - col = min(x->sizeX, coltoset); + col = min(x->sizeX-1, coltoset); col = max(0, col); for (i=0; i < x->sizeY; i++) @@ -183,7 +185,7 @@ void mtx_preset_setcol(t_mtx_preset *x, t_float coltoset, t_float value) void mtx_preset_element(t_mtx_preset *x, t_float posX, t_float posY, t_float value) { // reception de element X Y value - if ((posX < x->sizeX) && (posX < x->sizeX)) { + if ((posX < x->sizeX) && (posY < x->sizeY) && (posX >= 0) && (posY >= 0)) { x->matrix[(int)posX][(int)posY] = value; } } @@ -221,6 +223,11 @@ void mtx_preset_getRow(t_mtx_preset *x, t_symbol *s, int argc, t_atom *argv) b = a+1; c = atom_getfloatarg(0,argc,argv)-a; + a = min(a, x->sizeX); + a = max(a,0); + b = min(a, x->sizeX); + b = max(b,0); + for (i=0; i < x->sizeX; i++) { SETFLOAT(&(std_out[i]),mix(x->matrix[i][a], x->matrix[i][b], c)); } @@ -228,16 +235,38 @@ void mtx_preset_getRow(t_mtx_preset *x, t_symbol *s, int argc, t_atom *argv) } } -void mtx_preset_getElement(t_mtx_preset *x, t_float posX, t_float posY) +void mtx_preset_getElement(t_mtx_preset *x, t_symbol *s, int argc, t_atom *argv) { - int a,b; - - a = min(posX, x->sizeX); - a = max(a,0); - b = min(posY, x->sizeY); - b = max(b,0); - - outlet_float(x->main_outlet, x->matrix[a][b]); + int i, a, b; + t_float c; + t_atom std_out[2]; + + if ((argc > 1) && (argv[0].a_type == A_FLOAT) && (argv[1].a_type == A_FLOAT)) { + a = min(atom_getfloatarg(0,argc,argv), x->sizeX); + a = max(a,0); + b = min(atom_getfloatarg(1,argc,argv), x->sizeY); + b = max(b,0); + outlet_float(x->main_outlet, x->matrix[a][b]); + } + else if ((argc > 0) && (argv[0].a_type == A_FLOAT)) { + a = floor(atom_getfloatarg(0,argc,argv)); + b = a+1; + c = atom_getfloatarg(0,argc,argv)-floor(atom_getfloatarg(0,argc,argv)); + + a = min(a, x->sizeX); + a = max(a,0); + b = min(b, x->sizeX); + b = max(b,0); + + for (i=0; i < x->sizeX; i++) { + SETFLOAT(&(std_out[0]),i); + SETFLOAT(&(std_out[1]),mix(x->matrix[i][a], x->matrix[i][b], c)); + outlet_list(x->main_outlet, gensym("element"), 2, std_out); + } + } + else { + error("bad arguments for getElement"); + } } void mtx_preset_mixRow(t_mtx_preset *x, t_symbol *s, int argc, t_atom *argv) @@ -249,7 +278,6 @@ void mtx_preset_mixRow(t_mtx_preset *x, t_symbol *s, int argc, t_atom *argv) for (i=0; i < x->sizeX; i++) row[i] = 0; - for (j=0; j<min(argc, x->sizeY); j++) for (i=0; i < x->sizeX; i++) row[i] += x->matrix[i][j] * atom_getfloatarg(j, argc, argv); @@ -259,6 +287,20 @@ void mtx_preset_mixRow(t_mtx_preset *x, t_symbol *s, int argc, t_atom *argv) outlet_list(x->main_outlet, gensym("list"), x->sizeX, std_out); } +void mtx_preset_copyRow(t_mtx_preset *x, t_float row1, t_float row2) +{ + int i, rowA, rowB; + + rowA = min(x->sizeY-1, row1); + rowA = max(0, rowA); + + rowB = min(x->sizeY-1, row2); + rowB = max(0, rowB); + + for (i=0; i < x->sizeX; i++) + x->matrix[i][rowB] = x->matrix[i][rowA]; +} + void mtx_preset_setup(void) { mtx_preset_class = class_new(gensym("mtx_preset"), (t_newmethod)mtx_preset_new, @@ -282,10 +324,12 @@ void mtx_preset_setup(void) { // getRow -> dump all row (row now_number row values) // getRow row_number -> dump 1 row (values) // row_number can be float : row will be interpolated - class_addmethod(mtx_preset_class, (t_method)mtx_preset_getElement,gensym("getElement"),A_FLOAT, A_FLOAT, 0); // get 1 element + class_addmethod(mtx_preset_class, (t_method)mtx_preset_getElement,gensym("getElement"), A_GIMME, 0); // get element // get posX posY -> dump 1 element - // posX and posY can be float : value will be interpolated in X and Y + // get posX -> dump elements from 1 row + // row_number can be float : row will be interpolated class_addmethod(mtx_preset_class, (t_method)mtx_preset_mixRow, gensym("mixRow"), A_GIMME, 0); // interpol between all row // mixRow value0 value1 value2 : (value0*row0 + value1*row1 + value2*row2) + class_addmethod(mtx_preset_class, (t_method)mtx_preset_copyRow, gensym("copyRow"), A_FLOAT, A_FLOAT, 0); // copy row 1 to row 2 class_addmethod(mtx_preset_class, (t_method)mtx_preset_resize, gensym("resize"),A_FLOAT, A_FLOAT, 0); // resize matrix } |