aboutsummaryrefslogtreecommitdiff
path: root/nusmuk-utils
diff options
context:
space:
mode:
authorCyrille Henry <nusmuk@users.sourceforge.net>2015-01-14 19:46:48 +0000
committerCyrille Henry <nusmuk@users.sourceforge.net>2015-01-14 19:46:48 +0000
commit68404305ac5116d8d76ac538748fa206c44a5a93 (patch)
treefec7654941ce2f19b94c76b0770ef30d3c63363d /nusmuk-utils
parent4333ed8e4785cb72155cfaa7ec62b213e04d7d1a (diff)
more coherent function name, and examples
svn path=/trunk/externals/nusmuk/; revision=17408
Diffstat (limited to 'nusmuk-utils')
-rw-r--r--nusmuk-utils/mtx_preset-help.pd209
-rw-r--r--nusmuk-utils/mtx_preset.c169
-rw-r--r--nusmuk-utils/preset_param.pd23
3 files changed, 295 insertions, 106 deletions
diff --git a/nusmuk-utils/mtx_preset-help.pd b/nusmuk-utils/mtx_preset-help.pd
index fee8c1a..e062c1a 100644
--- a/nusmuk-utils/mtx_preset-help.pd
+++ b/nusmuk-utils/mtx_preset-help.pd
@@ -1,4 +1,4 @@
-#N canvas -1735 166 1135 557 10;
+#N canvas 287 198 1260 717 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
@@ -9,13 +9,9 @@
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 171 270 row 2 0 1 2 3 4 5 6 7 8 9 10 11 12;
-#X floatatom 645 425 5 0 0 0 - - -;
#X msg 557 106 getMatrix;
#X msg 232 364 element 0 2 200;
#X msg 581 166 getRow 1;
-#X msg 644 368 mixRow 1 1;
-#X msg 646 396 mixRow 0 1;
-#X msg 645 444 mixRow 0 0 \$1;
#X obj 102 481 mtx_preset 10 3;
#X obj 102 508 print;
#X msg 200 318 col 8 4 5 6;
@@ -26,57 +22,168 @@
#X msg 187 293 setRow 2 10;
#X msg 215 339 setCol 9 11;
#X msg 153 249 matrix 10;
-#X msg 644 479 copyRow 1 2;
-#X obj 644 506 t a;
-#X text 728 476 copy row 1 value to row 2;
-#X obj 184 508 route element;
-#X msg 184 531 \; value-\$1 \$2;
#X msg 569 135 getRows;
-#X msg 607 239 getElements;
#X msg 595 201 getRow 1.5;
-#X text 718 370 comment;
-#X msg 617 267 getElements 1;
-#X msg 623 291 getElements 1.5;
-#X msg 635 329 getElement 1.5 2;
+#X msg 613 251 getElements 1;
+#X msg 622 275 getElements 1.5;
#X text 630 105 get matrix in one line (selector: matrix sizex sizey
);
#X text 628 135 get matrix row by row (selector: rows y);
#X text 646 166 get row 1 in one line (selector: row);
-#X text 667 199 get interpolation between row 1 and 2 in one line (selector:
+#X text 666 199 get interpolation between row 1 and 2 in one line (selector:
row);
-#X text 688 239 get matrix element by element (selector: elements x
-y);
-#X text 718 267 get row 1 element by element (selector: elements x
-y??);
-#X text 724 292 get interpolation between line 1 and 2 element by element
-(??);
-#X text 743 329 get interpolation between element row 1 \, column 2
-and element row 2 column 2 (selector element);
-#X connect 0 0 12 0;
-#X connect 1 0 12 0;
-#X connect 2 0 12 0;
-#X connect 3 0 12 0;
-#X connect 4 0 12 0;
-#X connect 5 0 11 0;
-#X connect 6 0 15 0;
-#X connect 7 0 12 0;
-#X connect 8 0 15 0;
-#X connect 9 0 15 0;
-#X connect 10 0 15 0;
-#X connect 11 0 15 0;
+#N canvas 385 340 710 447 simple_example 0;
+#X obj 34 203 route row;
+#X obj 34 272 vsl 15 128 0 127 0 0 empty empty empty 0 -9 0 10 -262144
+-1 -1 0 1;
+#X msg 255 124 getRow \$1;
+#X floatatom 255 104 5 0 4 0 - - -, f 5;
+#X obj 34 229 unpack f f f f f f f f f f;
+#X obj 54 272 vsl 15 128 0 127 0 0 empty empty empty 0 -9 0 10 -262144
+-1 -1 0 1;
+#X obj 74 272 vsl 15 128 0 127 0 0 empty empty empty 0 -9 0 10 -262144
+-1 -1 0 1;
+#X obj 94 272 vsl 15 128 0 127 0 0 empty empty empty 0 -9 0 10 -262144
+-1 -1 0 1;
+#X obj 114 272 vsl 15 128 0 127 0 0 empty empty empty 0 -9 0 10 -262144
+-1 -1 0 1;
+#X obj 134 272 vsl 15 128 0 127 0 0 empty empty empty 0 -9 0 10 -262144
+-1 -1 0 1;
+#X obj 154 272 vsl 15 128 0 127 0 0 empty empty empty 0 -9 0 10 -262144
+-1 -1 0 1;
+#X obj 174 272 vsl 15 128 0 127 0 0 empty empty empty 0 -9 0 10 -262144
+-1 -1 0 1;
+#X obj 194 272 vsl 15 128 0 127 0 0 empty empty empty 0 -9 0 10 -262144
+-1 -1 0 1;
+#X obj 214 272 vsl 15 128 0 127 0 0 empty empty empty 0 -9 0 10 -262144
+-1 -1 0 1;
+#X obj 34 27 loadbang;
+#X msg 34 55 matrix 10 4 0 0 0 0 0 0 0 0 0 0 10 20 30 40 50 60 70 80
+90 100 100 90 80 70 60 50 40 30 20 10 0 0 0 0 0 0 0 0 0 0;
+#X obj 34 170 mtx_preset 10 4;
+#X connect 0 0 4 0;
+#X connect 2 0 16 0;
+#X connect 3 0 2 0;
+#X connect 4 0 1 0;
+#X connect 4 1 5 0;
+#X connect 4 2 6 0;
+#X connect 4 3 7 0;
+#X connect 4 4 8 0;
+#X connect 4 5 9 0;
+#X connect 4 6 10 0;
+#X connect 4 7 11 0;
+#X connect 4 8 12 0;
+#X connect 4 9 13 0;
+#X connect 14 0 15 0;
+#X connect 15 0 16 0;
+#X connect 16 0 0 0;
+#X restore 93 620 pd simple_example;
+#N canvas 953 386 795 409 complex_example 0;
+#X obj 53 165 mtx_preset 100 10;
+#X floatatom 309 119 5 0 0 0 - - -, f 5;
+#X obj 53 94 r to_mtx_preset;
+#X floatatom 309 139 5 0 0 0 - - -, f 5;
+#X floatatom 309 159 5 0 0 0 - - -, f 5;
+#X floatatom 309 179 5 0 0 0 - - -, f 5;
+#X floatatom 309 198 5 0 0 0 - - -, f 5;
+#X floatatom 309 99 5 0 0 0 - - -, f 5;
+#X obj 574 105 vradio 15 1 0 10 save_parametters empty empty 0 -8 0
+10 -258113 -1 -1 2;
+#X text 487 164 save_presets;
+#X obj 599 105 vsl 15 150 10 0 0 0 getElement empty empty 0 -9 0 10
+-4034 -1 -1 14900 1;
+#X text 630 167 load / interpol presets;
+#X obj 70 118 r getElement;
+#X msg 70 142 getElements \$1;
+#X obj 51 330 r paramettre_0;
+#X floatatom 51 358 5 0 0 0 - - -, f 5;
+#X floatatom 147 358 5 0 0 0 - - -, f 5;
+#X obj 147 330 r paramettre_1;
+#X obj 53 187 route elements;
+#X obj 361 197 preset_param 5;
+#X obj 110 269 send;
+#X obj 53 233 unpack f f;
+#X obj 53 209 t a a;
+#X msg 131 247 symbol from_mtx_preset_\$1;
+#X obj 361 118 preset_param 1;
+#X obj 361 138 preset_param 2;
+#X obj 361 158 preset_param 3;
+#X obj 361 178 preset_param 4;
+#X obj 361 98 preset_param 0;
+#X text 322 336 use _mtx_preset if you want to save and read this preset
+on a file;
+#X floatatom 309 278 5 0 0 0 - - -, f 5;
+#X obj 361 277 preset_param 99;
+#X text 159 20 using mtx_preset for a complex preset system management
+;
+#X connect 0 0 18 0;
+#X connect 1 0 24 0;
+#X connect 2 0 0 0;
+#X connect 3 0 25 0;
+#X connect 4 0 26 0;
+#X connect 5 0 27 0;
+#X connect 6 0 19 0;
+#X connect 7 0 28 0;
#X connect 12 0 13 0;
-#X connect 12 0 25 0;
-#X connect 14 0 12 0;
-#X connect 15 0 12 0;
-#X connect 19 0 12 0;
-#X connect 20 0 12 0;
-#X connect 21 0 12 0;
-#X connect 22 0 23 0;
-#X connect 23 0 15 0;
-#X connect 25 0 26 0;
-#X connect 27 0 15 0;
-#X connect 28 0 15 0;
-#X connect 29 0 15 0;
-#X connect 31 0 15 0;
-#X connect 32 0 15 0;
-#X connect 33 0 15 0;
+#X connect 13 0 0 0;
+#X connect 14 0 15 0;
+#X connect 17 0 16 0;
+#X connect 18 0 22 0;
+#X connect 19 0 6 0;
+#X connect 21 1 20 0;
+#X connect 22 0 21 0;
+#X connect 22 1 23 0;
+#X connect 23 0 20 1;
+#X connect 24 0 1 0;
+#X connect 25 0 3 0;
+#X connect 26 0 4 0;
+#X connect 27 0 5 0;
+#X connect 28 0 7 0;
+#X connect 30 0 31 0;
+#X connect 31 0 30 0;
+#X restore 92 646 pd complex_example;
+#X text 723 276 get interpolation between line 1 and 2 element by element
+;
+#X msg 252 393 resize 5 4;
+#X msg 267 419 copyRow 1 2;
+#X text 348 419 copy row 1 value to row 2;
+#X text 1023 229 (???);
+#X msg 649 338 mixRows 1 1 1.5;
+#X text 746 339 mix row together \, output a row in 1 line (selector
+mixRows);
+#X msg 659 358 mixElements 1 1 1.5;
+#X msg 605 229 getElementss;
+#X text 685 229 get matrix element by element (selector: elementss
+x y);
+#X text 213 481 10 col and 3 row;
+#X msg 635 302 getElement 3 1.5;
+#X text 743 302 get interpolation between element colum 3 \, row 1
+\, and element column 3 \, row 2(selector element);
+#X text 779 358 mix row together \, output a row elements by element
+line (selector mixElements x);
+#X text 714 251 get row 1 element by element (selector: elements x)
+;
+#X connect 0 0 8 0;
+#X connect 1 0 8 0;
+#X connect 2 0 8 0;
+#X connect 3 0 8 0;
+#X connect 4 0 8 0;
+#X connect 5 0 11 0;
+#X connect 6 0 8 0;
+#X connect 7 0 11 0;
+#X connect 8 0 9 0;
+#X connect 10 0 8 0;
+#X connect 11 0 8 0;
+#X connect 15 0 8 0;
+#X connect 16 0 8 0;
+#X connect 17 0 8 0;
+#X connect 18 0 11 0;
+#X connect 19 0 11 0;
+#X connect 20 0 11 0;
+#X connect 21 0 11 0;
+#X connect 29 0 8 0;
+#X connect 30 0 8 0;
+#X connect 33 0 11 0;
+#X connect 35 0 11 0;
+#X connect 36 0 11 0;
+#X connect 39 0 11 0;
diff --git a/nusmuk-utils/mtx_preset.c b/nusmuk-utils/mtx_preset.c
index 2291bd8..4b62acb 100644
--- a/nusmuk-utils/mtx_preset.c
+++ b/nusmuk-utils/mtx_preset.c
@@ -204,72 +204,101 @@ void mtx_preset_getMatrix(t_mtx_preset *x)
outlet_anything(x->main_outlet, gensym("matrix"),x->sizeX*x->sizeY+2,std_out);
}
-void mtx_preset_getRow(t_mtx_preset *x, t_symbol *s, int argc, t_atom *argv)
+void mtx_preset_getRows(t_mtx_preset *x)
{
- int i,j, a,b;
- t_float c;
+ int i,j;
t_atom std_out[x->sizeX+1];
- if (argc == 0)
- for (i=0; i< x->sizeY; i++) {
- SETFLOAT(&(std_out[0]),i);
- for (j=0; j < x->sizeX; j++) {
- SETFLOAT(&(std_out[j+1]),x->matrix[j][i]);
- }
- outlet_anything(x->main_outlet, gensym("row"),x->sizeX+1,std_out);
- }
- 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)-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));
+ for (i=0; i< x->sizeY; i++) {
+ SETFLOAT(&(std_out[0]),i);
+ for (j=0; j < x->sizeX; j++) {
+ SETFLOAT(&(std_out[j+1]),x->matrix[j][i]);
}
- outlet_list(x->main_outlet, gensym("list"), x->sizeX, std_out);
+ outlet_anything(x->main_outlet, gensym("rows"),x->sizeX+1,std_out);
}
}
-void mtx_preset_getElement(t_mtx_preset *x, t_symbol *s, int argc, t_atom *argv)
+void mtx_preset_getRow(t_mtx_preset *x, t_float row)
{
- int i, a, b;
+ int i,a,b;
t_float c;
- t_atom std_out[2];
+ t_atom std_out[x->sizeX+1];
+
+ a = floor(row);
+ b = a+1;
+ c = row-a;
- 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]);
+ a = min(a, x->sizeY-1);
+ a = max(a,0);
+ b = min(b, x->sizeY-1);
+ 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));
}
- 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);
-
+ outlet_anything(x->main_outlet, gensym("row"), x->sizeX, std_out);
+}
+
+void mtx_preset_getElementss(t_mtx_preset *x)
+{
+ int i, j;
+ t_atom std_out[3];
+
+ for (j=0; j < x->sizeY; j++) {
+ SETFLOAT(&(std_out[1]),j);
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_anything(x->main_outlet, gensym("element"), 2, std_out);
+ SETFLOAT(&(std_out[2]),x->matrix[i][j]);
+ outlet_anything(x->main_outlet, gensym("elementss"), 3, std_out);
}
}
- else {
- error("bad arguments for getElement");
+}
+
+void mtx_preset_getElements(t_mtx_preset *x, t_float row)
+{
+ int i, a, b;
+ t_float c;
+ t_atom std_out[2];
+
+ a = floor(row);
+ b = a+1;
+ c = row-a;
+
+ a = min(a, x->sizeY-1);
+ a = max(a,0);
+ b = min(b, x->sizeY-1);
+ 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_anything(x->main_outlet, gensym("elements"), 2, std_out);
}
}
-void mtx_preset_mixRow(t_mtx_preset *x, t_symbol *s, int argc, t_atom *argv)
+void mtx_preset_getElement(t_mtx_preset *x, t_float col, t_float row)
+{
+ int a, b, d;
+ t_float c;
+ t_atom std_out[1];
+
+ a = floor(row);
+ b = a+1;
+ c = row-a;
+
+ a = min(a, x->sizeY-1);
+ a = max(a,0);
+ b = min(b, x->sizeY-1);
+ b = max(b,0);
+
+ d = min(col, x->sizeX-1);
+ d = max(d,0);
+
+ SETFLOAT(&(std_out[0]),mix(x->matrix[d][a], x->matrix[d][b], c));
+ outlet_anything(x->main_outlet, gensym("element"), 1, std_out);
+}
+
+void mtx_preset_mixRows(t_mtx_preset *x, t_symbol *s, int argc, t_atom *argv)
{
int i, j;
t_atom std_out[x->sizeX];
@@ -279,12 +308,34 @@ void mtx_preset_mixRow(t_mtx_preset *x, t_symbol *s, int argc, t_atom *argv)
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);
+ if ((argv[j].a_type == A_FLOAT) && (atom_getfloatarg(j, argc, argv) != 0))
+ for (i=0; i < x->sizeX; i++)
+ row[i] += x->matrix[i][j] * atom_getfloatarg(j, argc, argv);
for (i=0; i < x->sizeX; i++)
SETFLOAT(&(std_out[i]),row[i]);
- outlet_list(x->main_outlet, gensym("list"), x->sizeX, std_out);
+ outlet_anything(x->main_outlet, gensym("mixRows"), x->sizeX, std_out);
+}
+
+void mtx_preset_mixElements(t_mtx_preset *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int i, j;
+ t_atom std_out[x->sizeX];
+ t_float row[2];
+
+ for (i=0; i < x->sizeX; i++)
+ row[i] = 0;
+
+ for (j=0; j<min(argc, x->sizeY); j++)
+ if ((argv[j].a_type == A_FLOAT) && (atom_getfloatarg(j, argc, argv) != 0))
+ for (i=0; i < x->sizeX; i++)
+ row[i] += x->matrix[i][j] * atom_getfloatarg(j, argc, argv);
+
+ for (i=0; i < x->sizeX; i++){
+ SETFLOAT(&(std_out[0]),i);
+ SETFLOAT(&(std_out[1]),row[i]);
+ outlet_anything(x->main_outlet, gensym("mixElements"), 2, std_out);
+ }
}
void mtx_preset_copyRow(t_mtx_preset *x, t_float row1, t_float row2)
@@ -320,16 +371,24 @@ void mtx_preset_setup(void) {
class_addmethod(mtx_preset_class, (t_method)mtx_preset_element, gensym("element"),A_FLOAT, A_FLOAT, A_FLOAT, 0); // put 1 element
// element posX posY value
class_addmethod(mtx_preset_class, (t_method)mtx_preset_getMatrix, gensym("getMatrix"), 0); // get matrix (matrix sizeX sizeY value)
- class_addmethod(mtx_preset_class, (t_method)mtx_preset_getRow, gensym("getRow"), A_GIMME, 0); // get row
+
+ class_addmethod(mtx_preset_class, (t_method)mtx_preset_getRows, gensym("getRows"), 0); // get row
// getRow -> dump all row (row now_number row values)
+ class_addmethod(mtx_preset_class, (t_method)mtx_preset_getRow, gensym("getRow"), A_FLOAT, 0); // get row
// 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_GIMME, 0); // get element
- // get posX posY -> dump 1 element
+ class_addmethod(mtx_preset_class, (t_method)mtx_preset_getElementss,gensym("getElementss"), 0); // get elements
+
+ class_addmethod(mtx_preset_class, (t_method)mtx_preset_getElements,gensym("getElements"), A_FLOAT, 0); // get elements
// 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
+ class_addmethod(mtx_preset_class, (t_method)mtx_preset_getElement,gensym("getElement"), A_FLOAT, A_FLOAT, 0); // get element
+ // get posX posY -> dump 1 element
+ // row_number can be float : row will be interpolated
+ class_addmethod(mtx_preset_class, (t_method)mtx_preset_mixRows, gensym("mixRows"), 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_mixElements,gensym("mixElements"), A_GIMME, 0); // interpol between all row
+ // mixELments 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
}
diff --git a/nusmuk-utils/preset_param.pd b/nusmuk-utils/preset_param.pd
new file mode 100644
index 0000000..f05b99f
--- /dev/null
+++ b/nusmuk-utils/preset_param.pd
@@ -0,0 +1,23 @@
+#N canvas 443 570 450 300 10;
+#X obj 37 27 inlet;
+#X obj 37 259 outlet;
+#X obj 37 82 change;
+#X obj 215 174 f;
+#X obj 215 117 r save_parametters;
+#X obj 215 144 t b f;
+#X obj 215 202 pack f f \$1;
+#X obj 64 228 s paramettre_\$1;
+#X obj 122 41 r from_mtx_preset_\$1;
+#X msg 215 235 element \$3 \$2 \$1;
+#X obj 215 261 s to_mtx_preset;
+#X connect 0 0 2 0;
+#X connect 2 0 1 0;
+#X connect 2 0 3 1;
+#X connect 2 0 7 0;
+#X connect 3 0 6 0;
+#X connect 4 0 5 0;
+#X connect 5 0 3 0;
+#X connect 5 1 6 1;
+#X connect 6 0 9 0;
+#X connect 8 0 2 0;
+#X connect 9 0 10 0;