diff options
Diffstat (limited to 'msd')
-rw-r--r-- | msd/02_imsdtest.pd | 16 | ||||
-rw-r--r-- | msd/help-msd.pd | 82 | ||||
-rwxr-xr-x | msd/main.cpp | 212 |
3 files changed, 192 insertions, 118 deletions
diff --git a/msd/02_imsdtest.pd b/msd/02_imsdtest.pd index 9a5ee14..280efc7 100644 --- a/msd/02_imsdtest.pd +++ b/msd/02_imsdtest.pd @@ -31,16 +31,16 @@ #X obj 45 576 cnv 15 300 200 empty empty empty 20 12 0 14 -261689 -66577 0; #X obj 88 590 vsl 15 128 0 100 0 0 empty empty empty 0 -8 0 8 -261689 --1 -1 8228 1; +-1 -1 6249 1; #X obj 111 590 vsl 15 128 0 100 0 0 empty empty empty 0 -8 0 8 -261689 --1 -1 6323 1; +-1 -1 0 1; #X obj 66 590 vsl 15 128 0 100 0 0 empty empty empty 0 -8 0 8 -261689 --1 -1 10160 1; +-1 -1 6860 1; #X msg 52 736 posX fix \$1; #X obj 156 590 vsl 15 128 0 100 0 0 empty empty empty 0 -8 0 8 -261689 --1 -1 2513 1; +-1 -1 0 1; #X obj 134 590 vsl 15 128 0 100 0 0 empty empty empty 0 -8 0 8 -261689 --1 -1 4418 1; +-1 -1 0 1; #X text 199 638 MOVE FIRST SLIDER; #X text 182 662 TO MOVE THE FIXED MASS; #X msg 66 438 forceX mob 300; @@ -50,8 +50,8 @@ #X obj 52 523 route massesPosL; #X msg 52 335 bang \, massesPosL; #X obj 52 545 unpack f f f f f; -#X msg 184 223 iLink inter fix mob 10 2.5 0.5; #X text 490 126 CREATION : 5 MASSES \, 1 iLINK; +#X msg 184 223 iLink inter fix mob 10 2.5 0.5 5 20; #X connect 0 0 35 0; #X connect 2 0 37 0; #X connect 2 1 1 0; @@ -76,7 +76,7 @@ #X connect 35 0 33 0; #X connect 35 0 3 0; #X connect 35 1 23 0; -#X connect 35 1 40 0; +#X connect 35 1 41 0; #X connect 35 2 13 0; #X connect 35 3 15 0; #X connect 35 4 14 0; @@ -89,4 +89,4 @@ #X connect 39 2 26 0; #X connect 39 3 30 0; #X connect 39 4 29 0; -#X connect 40 0 9 0; +#X connect 41 0 9 0; diff --git a/msd/help-msd.pd b/msd/help-msd.pd index e77b750..358df40 100644 --- a/msd/help-msd.pd +++ b/msd/help-msd.pd @@ -1,5 +1,5 @@ #N canvas 367 274 570 449 10; -#N canvas 271 52 742 843 masses 1; +#N canvas 271 52 742 843 masses 0; #X obj 33 821 msd; #X obj 62 154 cnv 15 610 180 empty empty CREATION 20 12 0 14 -262131 -66577 0; @@ -73,17 +73,17 @@ their; #X restore 281 323 pd masses; #N canvas 222 83 808 841 links 0; #X obj 33 821 msd; -#X obj 62 250 cnv 15 610 305 empty empty CREATION 20 12 0 14 -262131 +#X obj 62 192 cnv 15 610 360 empty empty CREATION 20 12 0 14 -262131 -66577 0; -#X msg 79 279 reset; -#X text 338 308 \$1 : Id (symbol); -#X text 250 308 Add a link; -#X text 337 328 \$2 : creation No of mass1; -#X text 337 346 \$3 : creation No of mass2; -#X text 336 364 \$4 : rigidity; -#X text 251 280 Delete all masses and links; -#X text 336 382 \$5 : viscosity; -#X text 336 399 \$6 : damping; +#X msg 79 221 reset; +#X text 402 247 \$1 : Id (symbol); +#X text 314 247 Add a link; +#X text 401 267 \$2 : creation No of mass1; +#X text 401 285 \$3 : creation No of mass2; +#X text 400 303 \$4 : rigidity; +#X text 251 222 Delete all masses and links; +#X text 400 321 \$5 : viscosity; +#X text 400 338 \$6 : damping; #X obj 61 561 cnv 15 610 82 empty empty DYNAMIC_SETTING 20 12 0 14 -262131 -66577 0; #X msg 172 583 setD \$1 \$2; @@ -99,29 +99,27 @@ their; #X text 237 705 \$1 : Attribute type ( massesPos / massesSpeeds / massesForces / linksPos ); #X text 237 742 \$2 : Id (symbol or creations numbers); -#X msg 78 308 link \$1 \$2 \$3 \$4 \$5 \$6; -#X msg 74 532 deleteLink \$1; -#X text 239 534 Delete a link; -#X text 340 534 \$1 : Creation No of link; +#X msg 74 533 deleteLink \$1; +#X text 239 535 Delete a link; +#X text 340 535 \$1 : Creation No of link; #X msg 73 762 infosL; #X text 236 762 Get infos on all masses and links on outlet No 2; -#X msg 73 423 iLink \$1 \$2 \$3 \$4 \$5 \$6; -#X text 338 308 \$1 : Id (symbol); -#X text 250 308 Add a link; -#X text 337 328 \$2 : creation No of mass1; -#X text 337 346 \$3 : creation No of mass2; -#X text 336 364 \$4 : rigidity; -#X text 336 382 \$5 : viscosity; -#X text 336 399 \$6 : damping; -#X text 410 422 \$1 : Id (symbol); -#X text 409 478 \$4 : rigidity; -#X text 409 496 \$5 : viscosity; -#X text 409 513 \$6 : damping; -#X text 410 422 \$1 : Id (symbol); -#X text 409 478 \$4 : rigidity; -#X text 409 496 \$5 : viscosity; -#X text 409 513 \$6 : damping; -#X text 248 423 Add an interactor link; +#X text 402 247 \$1 : Id (symbol); +#X text 314 247 Add a link; +#X text 401 267 \$2 : creation No of mass1; +#X text 401 285 \$3 : creation No of mass2; +#X text 400 303 \$4 : rigidity; +#X text 400 321 \$5 : viscosity; +#X text 400 338 \$6 : damping; +#X text 463 392 \$1 : Id (symbol); +#X text 462 448 \$4 : rigidity; +#X text 462 466 \$5 : viscosity; +#X text 462 483 \$6 : damping; +#X text 463 392 \$1 : Id (symbol); +#X text 462 448 \$4 : rigidity; +#X text 462 466 \$5 : viscosity; +#X text 462 483 \$6 : damping; +#X text 301 393 Add an interactor link; #X text 94 52 LINKS :; #X text 71 91 parameters : length \, rigidity \, viscosity and damping. ; @@ -130,23 +128,29 @@ their; #X text 70 134 the two masses at the creation.; #X text 71 120 message. The lenght is initialised to the distance between ; -#X text 71 106 Rigidity \, viscosity and damping are defined by the +#X text 71 107 Rigidity \, viscosity and damping are defined by the creation; -#X text 409 442 \$2 : Id (symbol) of masses type 1; -#X text 409 460 \$3 : Id (symbol) of masses type 2; #X text 70 148 Interactor links are links between mutiples masses \, instead; #X text 70 161 of creation number \, the masses linked are defined with; #X text 69 175 their Id.; +#X text 397 356 ($7) : minimum lenght of link; +#X text 397 373 ($8) : maximum lenght of link; +#X msg 78 247 link \$1 \$2 \$3 \$4 \$5 \$6 ($7 \$8); +#X text 462 412 \$2 : Id (symbol) of masses 1; +#X text 462 430 \$3 : Id (symbol) of masses 2; +#X msg 73 393 iLink \$1 \$2 \$3 \$4 \$5 \$6 ($7 \$8); +#X text 458 500 ($7) : minimum lenght of links; +#X text 458 517 ($8) : maximum lenght of links; #X connect 2 0 0 0; #X connect 15 0 0 0; #X connect 19 0 0 0; #X connect 23 0 0 0; -#X connect 24 0 0 0; -#X connect 27 0 0 0; -#X connect 29 0 0 0; -#X restore 283 353 pd links; +#X connect 26 0 0 0; +#X connect 55 0 0 0; +#X connect 58 0 0 0; +#X restore 284 353 pd links; #X text 135 323 HELP on masses --->; #X text 134 354 HELP on links --->; #X text 154 34 MSD : mass - spring - damper model; diff --git a/msd/main.cpp b/msd/main.cpp index a9aad8a..aabd8d1 100755 --- a/msd/main.cpp +++ b/msd/main.cpp @@ -30,7 +30,7 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Version 0.02 -- 15.04.2005 + Version 0.03 -- 21.04.2005 */ // include flext header @@ -38,7 +38,7 @@ #include <math.h> // define constants -#define MSD_VERSION 0.02 +#define MSD_VERSION 0.03 #define nb_max_link 4000
#define nb_max_mass 4000
#define Id_length 20 @@ -69,7 +69,7 @@ typedef struct _link { t_mass *mass1;
t_mass *mass2;
t_float K1, D1, D2; - t_float longx, longueur; + t_float longx, longueur, long_min, long_max; t_float distance_old; } t_link; @@ -132,16 +132,23 @@ protected: for (i=0; i<nb_link; i++) {
// compute link forces distance = link[i]->mass1->posX-link[i]->mass2->posX; // L[n] = x1 - x2 - F = link[i]->K1 * (distance - link[i]->longueur) ; // F[n] = k1 (L[n] - L[0]) - F += link[i]->D1 * (distance - link[i]->distance_old) ; // F[n] = F[n] + D1 (L[n] - L[n-1]) - if (distance != 0) { - Fx = F * (link[i]->mass1->posX - link[i]->mass2->posX)/distance; // Fx = F * Lx[n]/L[n] + if (distance < 0) + distance = -distance; // |L[n]| + if (distance < link[i]->long_min || distance > link[i]->long_max) + Fx = 0; + else { // Lmin < L < Lmax + F = link[i]->K1 * (distance - link[i]->longueur) ; // F[n] = k1 (L[n] - L[0]) + F += link[i]->D1 * (distance - link[i]->distance_old) ; // F[n] = F[n] + D1 (L[n] - L[n-1]) + if (distance != 0) + Fx = F * (link[i]->mass1->posX - link[i]->mass2->posX)/distance; // Fx = F * Lx[n]/L[n] }
- link[i]->mass1->forceX -= Fx; // Fx1[n] = -Fx - link[i]->mass1->forceX -= link[i]->D2*link[i]->mass1->speedX; // Fx1[n] = Fx1[n] - D2 * vx1[n-1]
- link[i]->mass2->forceX += Fx; // Fx2[n] = Fx - link[i]->mass2->forceX -= link[i]->D2*link[i]->mass2->speedX; // Fx2[n] = Fx2[n] - D2 * vx2[n-1] - link[i]->distance_old = distance; // L[n-1] = L[n] + link[i]->mass1->forceX -= Fx; // Fx1[n] = -Fx + link[i]->mass1->forceX -= link[i]->D2*link[i]->mass1->speedX; // Fx1[n] = Fx1[n] - D2 * vx1[n-1]
+ link[i]->mass2->forceX += Fx; // Fx2[n] = Fx + link[i]->mass2->forceX -= link[i]->D2*link[i]->mass2->speedX; // Fx2[n] = Fx2[n] - D2 * vx2[n-1] + link[i]->distance_old = distance; // L[n-1] = L[n] + + } for (i=0; i<nb_mass; i++)
@@ -169,6 +176,9 @@ protected: t_atom sortie[5], aux[2]; t_float M; + if (argc != 4) + error("mass : Id mobile mass X"); + mass[nb_mass] = new t_mass; // new mass
mass[nb_mass]->Id = GetSymbol(argv[0]); // ID mass[nb_mass]->mobile = GetInt(argv[1]); // mobile @@ -198,6 +208,9 @@ protected: t_int i; const t_symbol *sym = GetSymbol(argv[0]); + if (argc != 2) + error("forceX : Idmass value"); + for (i=0; i<nb_mass;i++) { if (sym == mass[i]->Id) @@ -211,6 +224,9 @@ protected: t_int i; const t_symbol *sym = GetSymbol(argv[0]); + if (argc != 2) + error("posX : Idmass value"); + if (GetFloat(argv[1]) < Xmax && GetFloat(argv[1]) > Xmin) for (i=0; i<nb_mass;i++) { @@ -223,7 +239,10 @@ protected: {
// set mass No to mobile
t_int i,aux; - + + if (argc != 1) + error("setMobile : Idmass"); + aux = GetInt(argv[0]); for (i=0; i<nb_mass;i++) { @@ -238,6 +257,9 @@ protected: // set mass No to fixed
t_int i,aux; + if (argc != 1) + error("setFixed : Idmass"); + aux = GetInt(argv[0]); for (i=0; i<nb_mass;i++) { @@ -250,49 +272,54 @@ protected: void m_delete_mass(int argc,t_atom *argv) { // Delete mass - t_int i,nb_link_delete=0; - t_atom sortie[5], aux[nb_link]; + t_int i,nb_link_delete=0; + t_atom sortie[5], aux[nb_link]; - - // Delete all associated links - for (i=0; i<nb_link;i++) { - if (link[i]->mass1->nbr == GetAInt(argv[0]) || link[i]->mass2->nbr == GetAInt(argv[0])) { - SetFloat((aux[nb_link_delete]),link[i]->nbr); - nb_link_delete++; + if (argc != 1) + error("deleteMass : Nomass"); + + // Delete all associated links + for (i=0; i<nb_link;i++) { + if (link[i]->mass1->nbr == GetAInt(argv[0]) || link[i]->mass2->nbr == GetAInt(argv[0])) { + SetFloat((aux[nb_link_delete]),link[i]->nbr); + nb_link_delete++; + } } - } - for (i=0; i<nb_link_delete;i++) - m_delete_link(1,&aux[i]); + for (i=0; i<nb_link_delete;i++) + m_delete_link(1,&aux[i]); - // Delete mass - for (i=0; i<nb_mass;i++) - if (mass[i]->nbr == GetAInt(argv[0])) { - SetFloat((sortie[0]),mass[i]->nbr); - SetSymbol((sortie[1]),mass[i]->Id); - SetFloat((sortie[2]),mass[i]->mobile); - SetFloat((sortie[3]),1/mass[i]->invM); - SetFloat((sortie[4]),mass[i]->posX); - delete mass[i]; - mass[i] = mass[nb_mass-1]; // copy last mass instead - nb_mass--; - ToOutAnything(1,S_Mass_deleted,5,sortie); - break; + // Delete mass + for (i=0; i<nb_mass;i++) + if (mass[i]->nbr == GetAInt(argv[0])) { + SetFloat((sortie[0]),mass[i]->nbr); + SetSymbol((sortie[1]),mass[i]->Id); + SetFloat((sortie[2]),mass[i]->mobile); + SetFloat((sortie[3]),1/mass[i]->invM); + SetFloat((sortie[4]),mass[i]->posX); + delete mass[i]; + mass[i] = mass[nb_mass-1]; // copy last mass instead + nb_mass--; + ToOutAnything(1,S_Mass_deleted,5,sortie); + break; } - } void m_Xmax(int argc,t_atom *argv) {
// set X max - Xmax = GetFloat(argv[0]); + if (argc != 1) + error("Xmax : Value"); + Xmax = GetFloat(argv[0]); } void m_Xmin(int argc,t_atom *argv) {
// set X min - Xmin = GetFloat(argv[0]); + if (argc != 1) + error("Xmin : Value"); + Xmin = GetFloat(argv[0]); } // -------------------------------------------------------------- LINKS @@ -300,11 +327,13 @@ protected: void m_link(int argc,t_atom *argv) // add a link
- // Id, nbr, *mass1, *mass2, K1, D1
+ // Id, *mass1, *mass2, K1, D1, D2, (Lmin,Lmax)
{
t_atom sortie[7], aux[2]; t_int i; + if (argc < 6 || argc > 8) + error("link : Id Nomass1 Nomass2 K D1 D2 (Lmin Lmax)"); link[nb_link] = new t_link; // New pointer link[nb_link]->Id = GetSymbol(argv[0]); // ID for (i=0; i<nb_mass;i++) @@ -316,9 +345,26 @@ protected: link[nb_link]->D1 = GetFloat(argv[4]); // D1 link[nb_link]->D2 = GetFloat(argv[5]); // D2 link[nb_link]->longx = link[nb_link]->mass1->posX - link[nb_link]->mass2->posX; // Lx[0] - link[nb_link]->longueur = link[nb_link]->longx ;// L[0] + if (link[nb_link]->longx < 0) + link[nb_link]->longueur = -link[nb_link]->longx; + else + link[nb_link]->longueur = link[nb_link]->longx ;// L[0] link[nb_link]->nbr = id_link; // id number link[nb_link]->distance_old = link[nb_link]->longueur; // L[n-1] + switch (argc) { + case 6 : + link[nb_link]->long_max = 32768; + link[nb_link]->long_min = 0; + break; + case 7 : + link[nb_link]->long_min = GetFloat(argv[6]); + link[nb_link]->long_max = 32768; + break; + case 8 : + link[nb_link]->long_min = GetFloat(argv[6]); + link[nb_link]->long_max = GetFloat(argv[7]); + break; + } nb_link++; id_link++;
nb_link = min ( nb_max_link -1, nb_link ); @@ -334,12 +380,15 @@ protected: void m_ilink(int argc,t_atom *argv) // add interactor link
- // Id, nbr, Id masses1, Id masses2, K1, D1
+ // Id, Id masses1, Id masses2, K1, D1, D2, (Lmin, Lmax)
{
- t_atom aux[2], arglist[6]; + t_atom aux[2], arglist[8]; t_int i,j, imass1[nb_mass], nbmass1=0, imass2[nb_mass], nbmass2=0; t_symbol *Id1, *Id2; + if (argc < 6 || argc > 8) + error("ilink : Id Idmass1 Idmass2 K D1 D2 (Lmin Lmax)"); + Id1 = GetSymbol(argv[1]); Id2 = GetSymbol(argv[2]); ToOutAnything(1,S_iLink,0,aux); @@ -364,7 +413,16 @@ protected: SetFloat((arglist[3]),GetFloat(argv[3])); SetFloat((arglist[4]),GetFloat(argv[4])); SetFloat((arglist[5]),GetFloat(argv[5])); - m_link(6,arglist); + switch (argc) { + case 7 : + SetFloat(arglist[6],GetFloat(argv[6])); + break; + case 8 : + SetFloat(arglist[6],GetFloat(argv[6])); + SetFloat(arglist[7],GetFloat(argv[7])); + break; + } + m_link(argc,arglist); } } @@ -374,6 +432,9 @@ protected: t_int i; const t_symbol *sym = GetSymbol(argv[0]); + if (argc != 2) + error("setK : IdLink Value"); + for (i=0; i<nb_link;i++) { if (sym == link[i]->Id) @@ -387,6 +448,9 @@ protected: t_int i; const t_symbol *sym = GetSymbol(argv[0]); + if (argc != 2) + error("setD : IdLink Value"); + for (i=0; i<nb_link;i++) { if (sym == link[i]->Id) @@ -400,6 +464,9 @@ protected: t_int i; const t_symbol *sym = GetSymbol(argv[0]); + if (argc != 2) + error("setD2 : IdLink Value"); + for (i=0; i<nb_link;i++) { if (sym == link[i]->Id) @@ -410,23 +477,26 @@ protected: void m_delete_link(int argc,t_atom *argv) { // Delete link - t_int i; - t_atom sortie[7]; + t_int i; + t_atom sortie[7]; - for (i=0; i<nb_link;i++) - if (link[i]->nbr == GetInt(argv[0])) { - SetFloat((sortie[0]),link[i]->nbr); - SetSymbol((sortie[1]),link[i]->Id); - SetFloat((sortie[2]),link[i]->mass1->nbr); - SetFloat((sortie[3]),link[i]->mass2->nbr); - SetFloat((sortie[4]),link[i]->K1); - SetFloat((sortie[5]),link[i]->D1); - SetFloat((sortie[6]),link[i]->D2); - delete link[i]; - link[i]=link[nb_link-1]; // copy last link instead - nb_link--; - ToOutAnything(1,S_Link_deleted,7,sortie); - break; + if (argc != 1) + error("deleteLink : NoLink"); + + for (i=0; i<nb_link;i++) + if (link[i]->nbr == GetInt(argv[0])) { + SetFloat((sortie[0]),link[i]->nbr); + SetSymbol((sortie[1]),link[i]->Id); + SetFloat((sortie[2]),link[i]->mass1->nbr); + SetFloat((sortie[3]),link[i]->mass2->nbr); + SetFloat((sortie[4]),link[i]->K1); + SetFloat((sortie[5]),link[i]->D1); + SetFloat((sortie[6]),link[i]->D2); + delete link[i]; + link[i]=link[nb_link-1]; // copy last link instead + nb_link--; + ToOutAnything(1,S_Link_deleted,7,sortie); + break; } } @@ -441,36 +511,36 @@ protected: t_symbol *auxarg,*auxarg2, *auxtype; t_atom sortie[4]; auxtype = GetSymbol(argv[0]); - auxarg = GetASymbol(argv[1]); //auxarg : & symbol, 0 else + auxarg = GetASymbol(argv[1]); //auxarg : & symbol, 0 else if (argc == 1) { - if (auxtype == S_massesPos)// get all masses positions + if (auxtype == S_massesPos) // get all masses positions for (i=0; i<nb_mass; i++) { SetFloat(sortie[0],mass[i]->posX); ToOutAnything(0,S_massesPos,1,sortie); } - else if (auxtype == S_massesForces)// get all masses forces + else if (auxtype == S_massesForces) // get all masses forces for (i=0; i<nb_mass; i++) { SetFloat(sortie[0],mass[i]->out_forceX); ToOutAnything(0,S_massesForces,1,sortie); } - else if (auxtype == S_linksPos)// get all links positions + else if (auxtype == S_linksPos) // get all links positions for (i=0; i<nb_link; i++) { SetFloat(sortie[0],link[i]->mass1->posX); SetFloat(sortie[1],link[i]->mass2->posX); ToOutAnything(0,S_linksPos,2,sortie); } - else // get all masses speeds + else // get all masses speeds for (i=0; i<nb_mass; i++) { SetFloat(sortie[0],mass[i]->speedX); ToOutAnything(0,S_massesSpeeds,1,sortie); } } - else if (auxtype == S_massesPos) // get mass positions + else if (auxtype == S_massesPos) // get mass positions { if (auxarg == 0) // No { @@ -498,7 +568,7 @@ protected: } } } - else if (auxtype == S_massesForces) // get mass forces + else if (auxtype == S_massesForces) // get mass forces { if (auxarg == 0) // No { @@ -526,7 +596,7 @@ protected: } } } - else if (auxtype == S_linksPos) // get links positions + else if (auxtype == S_linksPos) // get links positions { if (auxarg == 0) // No { @@ -556,7 +626,7 @@ protected: } } } - else // get mass speeds + else // get mass speeds { if (auxarg == 0) // No { @@ -613,7 +683,7 @@ protected: } void m_info_dumpl() - // List of masses and links infos on first outlet + // List of masses and links infos on second outlet { t_atom sortie[7]; t_int i; |