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-help.pd | 83 ++++++++++++++++++++++++++++++---------------------------- pmpd.c | 1 + pmpd2d-help.pd | 82 ++++++++++++++++++++++++++++++--------------------------- pmpd2d.c | 1 + pmpd2d_set.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ pmpd3d-help.pd | 81 +++++++++++++++++++++++++++++--------------------------- pmpd3d.c | 1 + pmpd3d_set.c | 64 ++++++++++++++++++++++++++++++++++++++++++++ pmpd_set.c | 65 +++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 342 insertions(+), 118 deletions(-) diff --git a/pmpd-help.pd b/pmpd-help.pd index 03eaeee..6a2e392 100644 --- a/pmpd-help.pd +++ b/pmpd-help.pd @@ -1,4 +1,4 @@ -#N canvas 540 177 584 778 10; +#N canvas 538 182 584 778 10; #X obj 4 369 cnv 15 550 15 empty empty empty 20 12 0 14 -158509 -66577 0; #X obj 5 729 cnv 15 550 40 empty empty empty 20 12 0 14 -158509 -66577 @@ -187,7 +187,7 @@ filter on link Id is possible; #X msg 14 172 linkLength [\$1]; #X text 216 174 linkLength symbolId number length; #X restore 12 517 pd links_attributes ___; -#N canvas 157 131 997 789 dynamic 0; +#N canvas 155 136 997 789 dynamic 0; #X obj 5 3 cnv 15 900 15 empty empty empty 20 12 0 14 -233017 -66577 0; #X obj 10 85 cnv 15 130 650 empty empty empty 20 12 0 14 -233017 -66577 @@ -216,25 +216,24 @@ filter on link Id is possible; #X msg 470 99 setK \$1 \$2; #X text 607 100 Set rigidity of link(s); #X text 606 156 Set damping of link(s); -#X msg 472 205 setL \$1 \$2; #X text 639 118 \$1 : Id (symbol) or No; #X text 639 174 \$1 : Id (symbol) or No; -#X text 639 227 \$1 : Id (symbol) or No; +#X text 639 225 \$1 : Id (symbol) or No; #X text 189 261 \$1 : Id (symbol) or No; #X msg 21 610 setDEnv \$1; #X text 148 612 Change environement damping; -#X msg 472 342 setLinkId \$1 \$2; -#X text 608 343 Change the Id of a link; -#X text 639 360 \$1 : link (number or Id); -#X text 639 377 \$2 : New Id; -#X msg 472 399 setLKTab \$1 \$2; -#X text 606 399 change the table (K) size of a non linear link; -#X text 637 419 \$1 : link (number or Id); -#X text 638 436 \$2 : New KL; -#X text 637 469 \$1 : link (number or Id); -#X msg 472 456 setLDTab \$1 \$2; -#X text 606 456 change the table (D) size of a non linear link; -#X text 638 479 \$2 : New DL; +#X msg 472 347 setLinkId \$1 \$2; +#X text 608 348 Change the Id of a link; +#X text 639 365 \$1 : link (number or Id); +#X text 639 382 \$2 : New Id; +#X msg 472 404 setLKTab \$1 \$2; +#X text 606 404 change the table (K) size of a non linear link; +#X text 637 424 \$1 : link (number or Id); +#X text 638 441 \$2 : New KL; +#X text 637 474 \$1 : link (number or Id); +#X msg 472 461 setLDTab \$1 \$2; +#X text 606 461 change the table (D) size of a non linear link; +#X text 638 484 \$2 : New DL; #X text 190 401 \$2 : New Id; #X msg 22 367 setMassId \$1 \$2; #X text 148 367 Change the Id of a mass; @@ -268,43 +267,47 @@ filter on link Id is possible; #X msg 22 448 setForceX \$1 \$2; #X msg 22 516 setSpeedX \$1 \$2; #X msg 21 579 addPosX \$1 \$2; -#X text 637 284 \$1 : Id (symbol) or No; -#X msg 472 265 setLCurrent \$1 [\$2]; -#X text 637 302 \$2 : mix between link size (0) and curent length (1) +#X text 637 293 \$1 : Id (symbol) or No; +#X msg 472 274 setLCurrent \$1 [\$2]; +#X text 637 311 \$2 : mix between link size (0) and curent length (1) ; -#X text 636 561 \$1 : link (number or Id); -#X text 635 517 \$1 : link (number or Id); -#X msg 472 541 setActive \$1 \$2; -#X msg 472 497 setInactive \$1 \$2; -#X text 603 541 compute the link at each bang; -#X text 631 628 \$1 : link (number or Id); -#X msg 471 585 setOverdamp \$1 \$2; -#X text 633 685 \$1 : link (number or Id); -#X msg 473 666 setEnd \$1 \$2 \$3; -#X text 632 701 \$2 : mass number for end 1; -#X text 602 668 Change the masses a link is connected to; -#X text 631 717 \$3 : mass number for end 2; -#X msg 493 689 setEnd1 \$1 \$2; -#X msg 493 711 setEnd2 \$1 \$2; +#X text 636 566 \$1 : link (number or Id); +#X text 635 522 \$1 : link (number or Id); +#X msg 472 546 setActive \$1 \$2; +#X msg 472 502 setInactive \$1 \$2; +#X text 603 546 compute the link at each bang; +#X text 631 633 \$1 : link (number or Id); +#X msg 471 590 setOverdamp \$1 \$2; +#X text 633 690 \$1 : link (number or Id); +#X msg 473 671 setEnd \$1 \$2 \$3; +#X text 632 706 \$2 : mass number for end 1; +#X text 602 673 Change the masses a link is connected to; +#X text 631 722 \$3 : mass number for end 2; +#X msg 493 694 setEnd1 \$1 \$2; +#X msg 493 716 setEnd2 \$1 \$2; #X text 10 25 Dynamic settings messages allow the user to redefine internal parameters of links and masses.; -#X text 636 320 if no \$2 arg is provided \, then L is set to curent +#X text 636 329 if no \$2 arg is provided \, then L is set to curent length; #X text 489 750 if only 1 argument is provided \, message generally uses this argument as the value applayed to all masses (or link); -#X text 604 497 do not compute a link anymore; -#X text 603 586 Change the overdamp of a link. i.e a strange parametter +#X text 604 502 do not compute a link anymore; +#X text 603 591 Change the overdamp of a link. i.e a strange parametter that amplifies forces that oppose to movment. Use at your own risk. ; -#X text 603 209 Set initial length of link(s); -#X text 611 266 Set initial length of link(s); +#X text 611 275 Set initial length of link(s); #X text 639 136 \$2 : New value (float or table); #X text 639 192 \$2 : New value (float or table); -#X text 639 245 \$2 : New value (float or table); -#X text 631 642 \$2 : overdamp value (float or table); +#X text 639 242 \$2 : New value (float or table); +#X text 631 647 \$2 : overdamp value (float or table); #X text 183 690 \$2 : damping (float or table); #X text 184 629 \$1 : damping (float or table); #X text 188 179 \$2 : Value (float or symbol); +#X msg 472 205 setL \$1 \$2 [\$3]; +#X msg 472 225 addL \$1 \$2 [\$3]; +#X text 602 209 Set initial length of link(s) / add value to link length +; +#X text 639 255 [\$3] : optional multiplicator value to the table; #X restore 12 477 pd dynamic settings ___; #N canvas 573 185 571 697 creation____________ 0; #X obj 11 95 cnv 15 100 60 empty empty empty 20 12 0 14 -233017 -66577 diff --git a/pmpd.c b/pmpd.c index 5fc12f8..9e3edc0 100644 --- a/pmpd.c +++ b/pmpd.c @@ -72,6 +72,7 @@ void pmpd_setup(void) class_addmethod(pmpd_class, (t_method)pmpd_setPow, gensym("setPow"), A_GIMME, 0); class_addmethod(pmpd_class, (t_method)pmpd_setD2, gensym("setDEnv"), A_GIMME, 0); class_addmethod(pmpd_class, (t_method)pmpd_setL, gensym("setL"), A_GIMME, 0); + class_addmethod(pmpd_class, (t_method)pmpd_addL, gensym("addL"), A_GIMME, 0); class_addmethod(pmpd_class, (t_method)pmpd_setLCurrent, gensym("setLCurrent"), A_GIMME, 0); class_addmethod(pmpd_class, (t_method)pmpd_setLKTab, gensym("setLKTab"), A_GIMME, 0); class_addmethod(pmpd_class, (t_method)pmpd_setLDTab, gensym("setLDTab"), A_GIMME, 0); diff --git a/pmpd2d-help.pd b/pmpd2d-help.pd index d5c3329..0c86017 100644 --- a/pmpd2d-help.pd +++ b/pmpd2d-help.pd @@ -1,4 +1,4 @@ -#N canvas 277 199 572 750 10; +#N canvas 273 209 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; @@ -383,7 +383,7 @@ pmpd object. They are of three types :; #X text 11 19 DESCRIPTION: Physical modeling for Pd in 2d; #X text 265 709 - Cyrille Henry 2011; #X text 265 721 based on MSD by Nicolas Montgermont \, 2005; -#N canvas 586 356 1173 699 links_attributes 0; +#N canvas 584 356 1173 699 links_attributes 0; #X obj 5 3 cnv 15 550 15 empty empty empty 20 12 0 14 -233017 -66577 0; #X obj 8 250 cnv 15 170 380 empty empty empty 20 12 0 14 -233017 -66577 @@ -577,7 +577,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 100 142 1031 818 dynamic 0; +#N canvas 94 157 1031 818 dynamic 0; #X obj 5 3 cnv 15 900 15 empty empty empty 20 12 0 14 -233017 -66577 0; #X obj 10 85 cnv 15 150 670 empty empty empty 20 12 0 14 -233017 -66577 @@ -603,8 +603,6 @@ a vector.; #X msg 483 99 setK \$1 \$2; #X text 611 98 Set rigidity of link(s); #X text 611 154 Set damping of link(s); -#X msg 483 205 setL \$1 \$2; -#X text 611 207 Set initial lenght of link(s); #X text 647 116 \$1 : Id (symbol) or No; #X text 647 172 \$1 : Id (symbol) or No; #X text 647 225 \$1 : Id (symbol) or No; @@ -633,15 +631,15 @@ a vector.; #X text 200 567 \$2 / \$3 : Value; #X text 201 628 \$2 / \$3 : Value; #X msg 20 592 addPos \$1 \$2 \$3; -#X msg 483 346 setLinkId \$1 \$2; -#X text 612 347 Change the Id of a link; -#X text 647 379 \$2 : New Id; -#X msg 483 406 setLKTab \$1 \$2; -#X text 611 406 change the table (K) size of a non linear link; -#X text 649 443 \$2 : New KL; -#X msg 483 468 setLDTab \$1 \$2; -#X text 611 468 change the table (D) size of a non linear link; -#X text 647 505 \$2 : New DL; +#X msg 483 352 setLinkId \$1 \$2; +#X text 612 353 Change the Id of a link; +#X text 647 385 \$2 : New Id; +#X msg 483 412 setLKTab \$1 \$2; +#X text 611 412 change the table (K) size of a non linear link; +#X text 649 449 \$2 : New KL; +#X msg 483 474 setLDTab \$1 \$2; +#X text 611 474 change the table (D) size of a non linear link; +#X text 647 511 \$2 : New DL; #X msg 21 225 min \$1 \$2; #X msg 21 245 max \$1 \$2; #X msg 40 611 addPosX \$1 \$2; @@ -659,39 +657,39 @@ a vector.; #X msg 21 96 setPos \$1 \$2 \$3; #X msg 41 116 setPosX \$1 \$2; #X msg 41 137 setPosY \$1 \$2; -#X text 615 272 Set initial lenght of link(s); -#X text 647 290 \$1 : Id (symbol) or No; -#X msg 482 271 setLCurrent \$1 [\$2]; -#X text 647 308 \$2 : mix between link size (0) and curent length (1) +#X text 615 278 Set initial lenght of link(s); +#X text 647 296 \$1 : Id (symbol) or No; +#X msg 482 277 setLCurrent \$1 [\$2]; +#X text 647 314 \$2 : mix between link size (0) and curent length (1) ; -#X text 614 576 compute the link at each bang; -#X msg 484 620 setOverdamp \$1 \$2; -#X text 649 664 \$2 : overdamp value; -#X msg 486 685 setEnd \$1 \$2 \$3; -#X text 643 720 \$2 : mass number for end 1; -#X text 611 686 Change the masses a link is connected to; -#X text 643 736 \$3 : mass number for end 2; -#X msg 500 708 setEnd1 \$1 \$2; -#X msg 500 730 setEnd2 \$1 \$2; +#X text 614 582 compute the link at each bang; +#X msg 484 626 setOverdamp \$1 \$2; +#X text 649 670 \$2 : overdamp value; +#X msg 486 691 setEnd \$1 \$2 \$3; +#X text 643 726 \$2 : mass number for end 1; +#X text 611 692 Change the masses a link is connected to; +#X text 643 742 \$3 : mass number for end 2; +#X msg 500 714 setEnd1 \$1 \$2; +#X msg 500 736 setEnd2 \$1 \$2; #X text 171 352 Grab nearest mass and move it; #X text 201 372 \$1 \$2 : position; #X text 10 25 Dynamic settings messages allow the user to redefine internal parameters of links and masses.; #X text 171 163 Add force to mass(es); -#X text 672 326 if no \$2 arg is provided \, then L is set to current +#X text 672 332 if no \$2 arg is provided \, then L is set to current length; -#X text 614 532 do not compute a link anymore; -#X text 610 621 Change the overdamp of a link. i.e a strange parameter +#X text 614 538 do not compute a link anymore; +#X text 610 627 Change the overdamp of a link. i.e a strange parameter that amplifies forces opposed to movment. Use at your own risk.; #X text 525 771 if only 1 argument is provided \, message generally uses this argument as the value applied to all masses (or links); -#X text 647 363 \$1 : link (Id (symbol) or No); -#X text 648 426 \$1 : link (Id (symbol) or No); -#X text 647 488 \$1 : link (Id (symbol) or No); -#X text 648 552 \$1 : link (Id (symbol) or No); -#X text 648 596 \$1 : link (Id (symbol) or No); -#X text 649 650 \$1 : link (Id (symbol) or No); -#X text 643 704 \$1 : link (Id (symbol) or No); +#X text 647 369 \$1 : link (Id (symbol) or No); +#X text 648 432 \$1 : link (Id (symbol) or No); +#X text 647 494 \$1 : link (Id (symbol) or No); +#X text 648 558 \$1 : link (Id (symbol) or No); +#X text 648 602 \$1 : link (Id (symbol) or No); +#X text 649 656 \$1 : link (Id (symbol) or No); +#X text 643 710 \$1 : link (Id (symbol) or No); #X text 647 134 \$2 : New value (float or table); #X text 647 190 \$2 : New value (float or table); #X text 647 243 \$2 : New value (float or table); @@ -699,9 +697,15 @@ uses this argument as the value applied to all masses (or links); #X text 200 693 \$2 : damping (float or table); #X text 199 445 \$2 : New Id; #X text 192 202 \$2 / \$3 : Value (float or symbol); -#X msg 483 532 setInactive \$1; -#X msg 484 576 setActive \$1; +#X msg 483 538 setInactive \$1; +#X msg 484 582 setActive \$1; #X text 190 131 \$2 / \$3 : Value (float or table); +#X msg 483 205 setL \$1 \$2 [\$3]; +#X text 646 259 \$3 : optional multiplicator coeficient for the table +; +#X msg 484 227 addL \$1 \$2 [\$3]; +#X text 611 207 Set initial lenght of link(s) / add value to link length +; #X restore 12 427 pd dynamic settings ___; #X text 112 658 54_pmpd2dtest.pd; #X obj 325 272 print; diff --git a/pmpd2d.c b/pmpd2d.c index 7e0c99b..94e2b99 100644 --- a/pmpd2d.c +++ b/pmpd2d.c @@ -76,6 +76,7 @@ void pmpd2d_setup(void) class_addmethod(pmpd2d_class, (t_method)pmpd2d_setDEnv, gensym("setDEnv"), A_GIMME, 0); class_addmethod(pmpd2d_class, (t_method)pmpd2d_setDEnvOffset, gensym("setDEnvOffset"), A_GIMME, 0); class_addmethod(pmpd2d_class, (t_method)pmpd2d_setL, gensym("setL"), A_GIMME, 0); + class_addmethod(pmpd2d_class, (t_method)pmpd2d_addL, gensym("addL"), A_GIMME, 0); class_addmethod(pmpd2d_class, (t_method)pmpd2d_setLCurrent, gensym("setLCurrent"), A_GIMME, 0); class_addmethod(pmpd2d_class, (t_method)pmpd2d_setLKTab, gensym("setLKTab"), A_GIMME, 0); class_addmethod(pmpd2d_class, (t_method)pmpd2d_setLDTab, gensym("setLDTab"), A_GIMME, 0); 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; diff --git a/pmpd3d-help.pd b/pmpd3d-help.pd index 3363b75..7e8f312 100644 --- a/pmpd3d-help.pd +++ b/pmpd3d-help.pd @@ -1,4 +1,4 @@ -#N canvas 330 149 570 717 10; +#N canvas 326 159 570 717 10; #X declare -lib Gem; #X obj 4 289 cnv 15 550 15 empty empty empty 20 12 0 14 -158509 -66577 0; @@ -200,7 +200,7 @@ the model. Messages create links and masses or destroy them.; links. They work as general links except their calculation is made following a vector.; #X restore 12 377 pd creation____________; -#N canvas 68 189 1143 866 dynamic 0; +#N canvas 64 189 1143 866 dynamic 0; #X obj 5 3 cnv 15 1050 15 empty empty empty 20 12 0 14 -233017 -66577 0; #X obj 5 84 cnv 15 150 750 empty empty empty 20 12 0 14 -233017 -66577 @@ -224,8 +224,6 @@ following a vector.; #X msg 530 150 setD \$1 \$2; #X text 655 98 Set rigidity of link(s); #X text 655 154 Set damping of link(s); -#X msg 529 211 setL \$1 \$2; -#X text 657 213 Set initial lenght of link(s); #X text 681 116 \$1 : Id (symbol) or No; #X text 681 172 \$1 : Id (symbol) or No; #X text 683 231 \$1 : Id (symbol) or No; @@ -254,18 +252,18 @@ following a vector.; #X text 191 596 \$2 / \$3 : Value; #X text 174 681 \$2 / \$3 : Value; #X msg 19 644 addPos \$1 \$2 \$3; -#X msg 529 359 setLinkId \$1 \$2; -#X text 655 360 Change the Id of a link; -#X text 688 377 \$1 : link (number or Id); -#X text 689 394 \$2 : New Id; -#X msg 527 425 setLKTab \$1 \$2; -#X text 650 425 change the table (K) size of a non linear link; -#X text 691 445 \$1 : link (number or Id); -#X text 692 462 \$2 : New KL; -#X text 691 507 \$1 : link (number or Id); -#X msg 528 487 setLDTab \$1 \$2; -#X text 651 487 change the table (D) size of a non linear link; -#X text 692 524 \$2 : New DL; +#X msg 529 379 setLinkId \$1 \$2; +#X text 655 380 Change the Id of a link; +#X text 688 397 \$1 : link (number or Id); +#X text 689 414 \$2 : New Id; +#X msg 527 445 setLKTab \$1 \$2; +#X text 650 445 change the table (K) size of a non linear link; +#X text 691 465 \$1 : link (number or Id); +#X text 692 482 \$2 : New KL; +#X text 691 527 \$1 : link (number or Id); +#X msg 528 507 setLDTab \$1 \$2; +#X text 651 507 change the table (D) size of a non linear link; +#X text 692 544 \$2 : New DL; #X msg 35 228 forceZ \$1 \$2; #X msg 16 248 min \$1 \$2; #X msg 16 268 max \$1 \$2; @@ -290,23 +288,23 @@ following a vector.; #X msg 36 152 setPosZ \$1 \$2; #X text 171 777 Set environement damping offset (in order to force a specific velocity to masses); -#X text 657 272 Set initial lenght of link(s); -#X text 687 291 \$1 : Id (symbol) or No; -#X msg 529 271 setLCurrent \$1 [\$2]; -#X text 691 610 \$1 : link (number or Id); -#X text 691 566 \$1 : link (number or Id); -#X msg 529 590 setActive \$1 \$2; -#X msg 529 546 setInactive \$1 \$2; -#X text 650 590 compute the link at each bang; -#X text 691 676 \$1 : link (number or Id); -#X msg 529 634 setOverdamp \$1 \$2; -#X text 690 728 \$1 : link (number or Id); -#X msg 528 709 setEnd \$1 \$2 \$3; -#X text 690 744 \$2 : mass number for end 1; -#X text 652 710 Change the masses a link is connected to; -#X text 690 760 \$3 : mass number for end 2; -#X msg 548 732 setEnd1 \$1 \$2; -#X msg 548 754 setEnd2 \$1 \$2; +#X text 657 292 Set initial lenght of link(s); +#X text 687 311 \$1 : Id (symbol) or No; +#X msg 529 291 setLCurrent \$1 [\$2]; +#X text 691 630 \$1 : link (number or Id); +#X text 691 586 \$1 : link (number or Id); +#X msg 529 610 setActive \$1 \$2; +#X msg 529 566 setInactive \$1 \$2; +#X text 650 610 compute the link at each bang; +#X text 691 696 \$1 : link (number or Id); +#X msg 529 654 setOverdamp \$1 \$2; +#X text 690 748 \$1 : link (number or Id); +#X msg 528 729 setEnd \$1 \$2 \$3; +#X text 690 764 \$2 : mass number for end 1; +#X text 652 730 Change the masses a link is connected to; +#X text 690 780 \$3 : mass number for end 2; +#X msg 548 752 setEnd1 \$1 \$2; +#X msg 548 774 setEnd2 \$1 \$2; #X msg 530 99 setK \$1 \$2; #X msg 36 133 setPosY \$1 \$2; #X msg 14 390 grabMass \$1 \$2 \$3 \$4; @@ -314,26 +312,31 @@ a specific velocity to masses); #X text 10 25 Dynamic settings messages allow the user to redefine internal parameters of links and masses.; #X text 166 170 Add force to mass(es); -#X text 686 309 \$2 : mix between link size (0) and current length +#X text 686 329 \$2 : mix between link size (0) and current length (1); -#X text 686 327 if no \$2 arg is provided \, then L is set to current +#X text 686 347 if no \$2 arg is provided \, then L is set to current length; -#X text 651 546 do not compute a link anymore; -#X text 654 635 Change the overdamp of a link. i.e a strange parameter +#X text 651 566 do not compute a link anymore; +#X text 654 655 Change the overdamp of a link. i.e a strange parameter that amplifies forces that oppose to movment. Use at your own risk. ; -#X text 663 793 if only 1 argument is provided \, message generally +#X text 663 813 if only 1 argument is provided \, message generally uses this argument as the value applied to all masses (or links); #X text 166 248 Set minimimum or maximum position of all masses; #X text 681 134 \$2 : New value (float or table); #X text 681 190 \$2 : New value (float or table); #X text 683 249 \$2 : New value (float or table); -#X text 691 690 \$2 : overdamp value (float or table); +#X text 691 710 \$2 : overdamp value (float or table); #X text 193 819 \$2 : damping (float or table); #X text 195 761 \$2 : damping (float or table); #X text 193 467 \$2 : New Id; #X text 189 212 \$2 / \$3 : Value (float or symbol); #X text 189 131 \$2 / \$3 : Value (float or table); +#X msg 529 211 setL \$1 \$2 [\$3]; +#X msg 529 231 addL \$1 \$2 [\$3]; +#X text 683 266 [\$3] : optional multiplicator coef for table; +#X text 657 213 Set initial lenght of link(s) / add value to link length +; #X restore 12 397 pd dynamic settings ___; #X text 158 397 To set the model parameters after creation.; #N canvas 153 264 1157 693 masses_attributes 0; diff --git a/pmpd3d.c b/pmpd3d.c index fd99af2..4a7d97f 100644 --- a/pmpd3d.c +++ b/pmpd3d.c @@ -76,6 +76,7 @@ void pmpd3d_setup(void) class_addmethod(pmpd3d_class, (t_method)pmpd3d_setDEnv, gensym("setDEnv"), A_GIMME, 0); class_addmethod(pmpd3d_class, (t_method)pmpd3d_setDEnvOffset, gensym("setDEnvOffset"), A_GIMME, 0); class_addmethod(pmpd3d_class, (t_method)pmpd3d_setL, gensym("setL"), A_GIMME, 0); + class_addmethod(pmpd3d_class, (t_method)pmpd3d_addL, gensym("addL"), A_GIMME, 0); class_addmethod(pmpd3d_class, (t_method)pmpd3d_setLCurrent, gensym("setLCurrent"), A_GIMME, 0); class_addmethod(pmpd3d_class, (t_method)pmpd3d_setLKTab, gensym("setLKTab"), A_GIMME, 0); class_addmethod(pmpd3d_class, (t_method)pmpd3d_setLDTab, gensym("setLDTab"), A_GIMME, 0); diff --git a/pmpd3d_set.c b/pmpd3d_set.c index 296c94b..b84010f 100644 --- a/pmpd3d_set.c +++ b/pmpd3d_set.c @@ -516,6 +516,70 @@ void pmpd3d_setL(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv) } } +void pmpd3d_addL(t_pmpd3d *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 size + 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 size + 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 ) ) + { // set a link to it's curent size + 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 ) ) + { // set a class of link to there curent size + 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; + } + } + } + } +} + void pmpd3d_setLCurrent(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv) { int tmp, i; 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