From 8bd1de9a3da2bbae57c381c5f80adc6068349e8e Mon Sep 17 00:00:00 2001 From: Cyrille Henry Date: Wed, 21 May 2014 14:20:50 +0000 Subject: update setK for Id=float and value from table svn path=/trunk/externals/pmpd/; revision=17311 --- pmpd2d-help.pd | 8 ++-- pmpd2d_set.c | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 114 insertions(+), 8 deletions(-) diff --git a/pmpd2d-help.pd b/pmpd2d-help.pd index 566515e..5fed962 100644 --- a/pmpd2d-help.pd +++ b/pmpd2d-help.pd @@ -1,4 +1,4 @@ -#N canvas 291 164 572 750 10; +#N canvas 289 169 572 750 10; #X declare -lib Gem; #X obj 4 309 cnv 15 550 15 empty empty empty 20 12 0 14 -158509 -66577 0; @@ -574,7 +574,7 @@ the model. Messages create links and masses or destroy them.; links. They work as general links but their calculation is made following a vector.; #X restore 12 407 pd creation____________; -#N canvas 84 119 1057 814 dynamic 0; +#N canvas 82 124 1057 814 dynamic 0; #X obj -35 3 cnv 15 900 15 empty empty empty 20 12 0 14 -233017 -66577 0; #X obj -30 85 cnv 15 150 670 empty empty empty 20 12 0 14 -233017 -66577 @@ -662,8 +662,6 @@ a vector.; #X msg 442 271 setLCurrent \$1 [\$2]; #X text 607 308 \$2 : mix between link size (0) and curent length (1) ; -#X msg 444 576 setActive \$1 \$2; -#X msg 443 532 setInactive \$1 \$2; #X text 574 576 compute the link at each bang; #X msg 444 620 setOverdamp \$1 \$2; #X text 609 664 \$2 : overdamp value; @@ -699,6 +697,8 @@ uses this argument as the value applied to all masses (or links); #X text 160 693 \$2 : damping (float or table); #X text 159 445 \$2 : New Id; #X text 152 202 \$2 / \$3 : Value (float or symbol); +#X msg 443 532 setInactive \$1; +#X msg 444 576 setActive \$1; #X restore 12 427 pd dynamic settings ___; #X text 112 658 54_pmpd2dtest.pd; #X obj 325 272 print; diff --git a/pmpd2d_set.c b/pmpd2d_set.c index d78a48b..afbc6ac 100644 --- a/pmpd2d_set.c +++ b/pmpd2d_set.c @@ -1,6 +1,6 @@ void pmpd2d_setK(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) { - int tmp, i; + int tmp, i, offset; t_garray *a; int npoints, n; t_word *vec; @@ -44,6 +44,24 @@ void pmpd2d_setK(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) } } } + else if ( (argc >= 2) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_SYMBOL ) ) + { + K=1; + if ((argc >= 3) && ( argv[2].a_type == A_FLOAT )) K=atom_getfloatarg(2, argc, argv); + if (!(a = (t_garray *)pd_findbyclass(atom_getsymbolarg(1,argc,argv), garray_class))) + pd_error(x, "%s: no such array", atom_getsymbolarg(1,argc,argv)->s_name); + else if (!garray_getfloatwords(a, &npoints, &vec)) + pd_error(x, "%s: bad template for tabLink", atom_getsymbolarg(1,argc,argv)->s_name); + else + { + offset = atom_getfloatarg(1, argc, argv); + n=min(npoints,x->nb_link-atom_getfloatarg(1, argc, argv)); + for (i=0; i < n; i++) + { + x->link[i+offset].K = K*vec[i].w_float; + } + } + } } void pmpd2d_setD(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) @@ -682,8 +700,12 @@ void pmpd2d_pos(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) void pmpd2d_posX(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) { // displace a mass to a certain position - int tmp, i; - + int tmp, i, offset; + t_garray *a; + int npoints, n; + t_word *vec; + t_float K; + if ( (argc == 2) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) { tmp = atom_getfloatarg(0, argc, argv); @@ -704,12 +726,56 @@ void pmpd2d_posX(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) } } } + else if ( (argc >= 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_SYMBOL ) ) + { + K=1; + if ((argc >= 3) && ( argv[2].a_type == A_FLOAT )) K=atom_getfloatarg(2, argc, argv); + if (!(a = (t_garray *)pd_findbyclass(atom_getsymbolarg(1,argc,argv), garray_class))) + pd_error(x, "%s: no such array", atom_getsymbolarg(1,argc,argv)->s_name); + else if (!garray_getfloatwords(a, &npoints, &vec)) + pd_error(x, "%s: bad template for tabLink", atom_getsymbolarg(1,argc,argv)->s_name); + else + { + n=0; + for (i=0; i < x->nb_mass; i++) + { + if ( atom_getsymbolarg(0,argc,argv) == x->mass[i].Id) + { + x->mass[i].posX = K*vec[n].w_float; + n++; + if (n >= npoints) break; + } + } + } + } + else if ( (argc >= 2) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_SYMBOL ) ) + { + K=1; + if ((argc >= 3) && ( argv[2].a_type == A_FLOAT )) K=atom_getfloatarg(2, argc, argv); + if (!(a = (t_garray *)pd_findbyclass(atom_getsymbolarg(1,argc,argv), garray_class))) + pd_error(x, "%s: no such array", atom_getsymbolarg(1,argc,argv)->s_name); + else if (!garray_getfloatwords(a, &npoints, &vec)) + pd_error(x, "%s: bad template for tabLink", atom_getsymbolarg(1,argc,argv)->s_name); + else + { + offset = atom_getfloatarg(1, argc, argv); + n=min(npoints,x->nb_mass-atom_getfloatarg(1, argc, argv)); + for (i=0; i < n; i++) + { + x->mass[i+offset].posX = K*vec[i].w_float; + } + } + } } void pmpd2d_posY(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) { // displace a mass to a certain position - int tmp, i; + int tmp, i, offset; + t_garray *a; + int npoints, n; + t_word *vec; + t_float K; if ( (argc == 2) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) { @@ -732,6 +798,46 @@ void pmpd2d_posY(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) } } } + else if ( (argc >= 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_SYMBOL ) ) + { + K=1; + if ((argc >= 3) && ( argv[2].a_type == A_FLOAT )) K=atom_getfloatarg(2, argc, argv); + if (!(a = (t_garray *)pd_findbyclass(atom_getsymbolarg(1,argc,argv), garray_class))) + pd_error(x, "%s: no such array", atom_getsymbolarg(1,argc,argv)->s_name); + else if (!garray_getfloatwords(a, &npoints, &vec)) + pd_error(x, "%s: bad template for tabLink", atom_getsymbolarg(1,argc,argv)->s_name); + else + { + n=0; + for (i=0; i < x->nb_mass; i++) + { + if ( atom_getsymbolarg(0,argc,argv) == x->mass[i].Id) + { + x->mass[i].posY = K*vec[n].w_float; + n++; + if (n >= npoints) break; + } + } + } + } + else if ( (argc >= 2) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_SYMBOL ) ) + { + K=1; + if ((argc >= 3) && ( argv[2].a_type == A_FLOAT )) K=atom_getfloatarg(2, argc, argv); + if (!(a = (t_garray *)pd_findbyclass(atom_getsymbolarg(1,argc,argv), garray_class))) + pd_error(x, "%s: no such array", atom_getsymbolarg(1,argc,argv)->s_name); + else if (!garray_getfloatwords(a, &npoints, &vec)) + pd_error(x, "%s: bad template for tabLink", atom_getsymbolarg(1,argc,argv)->s_name); + else + { + offset = atom_getfloatarg(1, argc, argv); + n=min(npoints,x->nb_mass-atom_getfloatarg(1, argc, argv)); + for (i=0; i < n; i++) + { + x->mass[i+offset].posY = K*vec[i].w_float; + } + } + } } void pmpd2d_overdamp(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) -- cgit v1.2.1