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 --- pmpd2d_set.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) (limited to 'pmpd2d_set.c') diff --git a/pmpd2d_set.c b/pmpd2d_set.c index f415221..d958bda 100644 --- a/pmpd2d_set.c +++ b/pmpd2d_set.c @@ -425,6 +425,88 @@ void pmpd2d_setL(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) } } +void pmpd2d_addL(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) +{ + 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 ) ) + { // set a link to a specific length + 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 ) ) + { // set a class of link to a specific length + 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 ( (argc == 1) && ( argv[0].a_type == A_FLOAT ) && ( argc == 1 ) ) + { // set a link to it's current length + tmp = atom_getfloatarg(0, argc, argv); + tmp = max(0, min( x->nb_link-1, tmp)); + x->link[tmp].L += x->link[tmp].distance; + } + else if ( (argc == 1) && ( argv[0].a_type == A_SYMBOL ) && ( argc == 1 ) ) + { // set a class of link to there current length + 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].distance; + } + } + } + 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; + 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(0, argc, argv); + n=min(npoints,x->nb_link-atom_getfloatarg(1, argc, argv)); + for (i=0; i < n; i++) + { + x->link[i+offset].L += K*vec[i].w_float; + } + } + } +} + void pmpd2d_setLCurrent(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) { int tmp, i; -- cgit v1.2.1