diff options
-rw-r--r-- | nusmuk-utils/mtx_preset-help.pd | 31 | ||||
-rw-r--r-- | nusmuk-utils/mtx_preset.c | 80 |
2 files changed, 84 insertions, 27 deletions
diff --git a/nusmuk-utils/mtx_preset-help.pd b/nusmuk-utils/mtx_preset-help.pd index afe6d9e..644fed1 100644 --- a/nusmuk-utils/mtx_preset-help.pd +++ b/nusmuk-utils/mtx_preset-help.pd @@ -1,4 +1,4 @@ -#N canvas 627 385 770 468 10; +#N canvas 512 337 1007 561 10; #X msg 116 142 matrix 10 3 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29; #X msg 124 175 matrix 9 2 0 1 2 3 4 5 6 7 8 10 11 12 13 14 15 16 17 @@ -8,10 +8,10 @@ #X msg 138 198 matrix 11 4 0 1 2 3 4 5 6 7 8 9 111 10 11 12 13 14 15 16 17 18 19 199 20 21 22 23 24 25 26 27 28 29 299 30 31 32 33 34 35 36 37 38 39 333; -#X msg 151 244 row 2 0 1 2 3 4 5 6 7 8 9 10 11 12; +#X msg 171 270 row 2 0 1 2 3 4 5 6 7 8 9 10 11 12; #X floatatom 610 295 5 0 0 0 - - -, f 5; #X msg 557 106 getMatrix; -#X msg 212 338 element 0 2 200; +#X msg 232 364 element 0 2 200; #X msg 569 135 getRow; #X msg 581 166 getRow 1; #X msg 595 211 getRow \$1; @@ -19,15 +19,22 @@ #X msg 609 238 mixRow 1 1; #X msg 611 266 mixRow 0 1; #X msg 610 314 mixRow 0 0 \$1; -#X obj 102 411 mtx_preset 10 3; -#X obj 102 438 print; -#X msg 180 292 col 8 4 5 6; -#X obj 557 366 t a; +#X obj 102 481 mtx_preset 10 3; +#X obj 102 508 print; +#X msg 200 318 col 8 4 5 6; +#X obj 557 422 t a; #X text 180 18 preset interpolation object; #X text 113 79 set values; #X text 557 82 get values; -#X msg 167 267 setRow 2 10; -#X msg 195 313 setCol 9 11; +#X msg 187 293 setRow 2 10; +#X msg 215 339 setCol 9 11; +#X msg 153 249 matrix 10; +#X msg 625 342 getElement 1 2; +#X msg 629 397 getElement \$1; +#X floatatom 629 376 5 0 0 0 - - -, f 5; +#X msg 820 111 copyRow 1 2; +#X obj 820 422 t a; +#X text 837 140 copy row 1 value to row 2; #X connect 0 0 15 0; #X connect 1 0 15 0; #X connect 2 0 15 0; @@ -48,3 +55,9 @@ #X connect 18 0 15 0; #X connect 22 0 15 0; #X connect 23 0 15 0; +#X connect 24 0 15 0; +#X connect 25 0 18 0; +#X connect 26 0 18 0; +#X connect 27 0 26 0; +#X connect 28 0 29 0; +#X connect 29 0 18 0; 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 } |