From d8736fef3f30c718aa04d3578a190c47602ef93a Mon Sep 17 00:00:00 2001 From: Cyrille Henry Date: Sat, 30 Aug 2014 14:01:56 +0000 Subject: new addL message to increase / decrease link length svn path=/trunk/externals/pmpd/; revision=17344 --- pmpd_set.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) (limited to 'pmpd_set.c') diff --git a/pmpd_set.c b/pmpd_set.c index 4234345..03d3225 100644 --- a/pmpd_set.c +++ b/pmpd_set.c @@ -338,6 +338,71 @@ void pmpd_setL(t_pmpd *x, t_symbol *s, int argc, t_atom *argv) } } +void pmpd_addL(t_pmpd *x, t_symbol *s, int argc, t_atom *argv) +{ + int tmp, i; + 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); + tmp = max(0, min( x->nb_link-1, tmp)); + x->link[tmp].L += atom_getfloatarg(1, argc, argv); + } + else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) + { + for (i=0; i< x->nb_link; i++) + { + if ( atom_getsymbolarg(0,argc,argv) == x->link[i].Id) + { + x->link[i].L += atom_getfloatarg(1, argc, argv); + } + } + } + else if ( ( argv[0].a_type == A_FLOAT ) && ( argc == 1 ) ) + { + tmp = atom_getfloatarg(0, argc, argv); + tmp = max(0, min( x->nb_link-1, tmp)); + x->link[tmp].L += x->link[tmp].mass2->posX - x->link[tmp].mass1->posX; + } + else if ( ( argv[0].a_type == A_SYMBOL ) && ( argc == 1 ) ) + { + for (i=0; i< x->nb_link; i++) + { + if ( atom_getsymbolarg(0,argc,argv) == x->link[i].Id) + { + x->link[i].L += x->link[i].mass2->posX - x->link[i].mass1->posX; + } + } + } + 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_link; i++) + { + if ( atom_getsymbolarg(0,argc,argv) == x->link[i].Id) + { + x->link[i].L += K*vec[n].w_float; + // post("linkL %d = table %d : %f", i, n, vec[n].w_float); + n++; + if (n >= npoints) break; + } + } + } + } +} + void pmpd_setLCurrent(t_pmpd *x, t_symbol *s, int argc, t_atom *argv) { int tmp, i; -- cgit v1.2.1