diff options
author | N.N. <nimon@users.sourceforge.net> | 2005-04-26 16:10:08 +0000 |
---|---|---|
committer | N.N. <nimon@users.sourceforge.net> | 2005-04-26 16:10:08 +0000 |
commit | 2d390319a45282ffa6fcc5da41bbac81eb26fb3c (patch) | |
tree | 52905a8f94ff4ee05ed30ae6412f13944c7deacd /msd | |
parent | 3d7f8e6f9f4c708c6130ea0a63c2eb139f34327a (diff) |
MSD Version 0.04
svn path=/trunk/externals/nusmuk/; revision=2826
Diffstat (limited to 'msd')
-rw-r--r-- | msd/02_imsdtest.pd | 73 | ||||
-rw-r--r-- | msd/03_msdwave.pd | 124 | ||||
-rwxr-xr-x | msd/main.cpp | 188 |
3 files changed, 206 insertions, 179 deletions
diff --git a/msd/02_imsdtest.pd b/msd/02_imsdtest.pd index 280efc7..901b7a2 100644 --- a/msd/02_imsdtest.pd +++ b/msd/02_imsdtest.pd @@ -21,26 +21,22 @@ #X msg 218 129 100 65 \, 100 50 \, 100 35 \, 100 20; #X obj 46 380 cnv 15 700 90 empty empty empty 20 12 0 14 -262131 -66577 0; -#X msg 176 385 setD souple 0.01; -#X msg 66 384 setK souple 1; -#X msg 176 407 setD souple 1; -#X msg 66 406 setK souple 2; #X text 455 399 SET RIGIDITY AND VISCOSITY OF LINKS; #X text 455 438 ADD FORCE ON ALL MOBILE MASSES; #X msg 184 153 0; #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 6249 1; +-1 -1 12166 1; #X obj 111 590 vsl 15 128 0 100 0 0 empty empty empty 0 -8 0 8 -261689 --1 -1 0 1; +-1 -1 7166 1; #X obj 66 590 vsl 15 128 0 100 0 0 empty empty empty 0 -8 0 8 -261689 --1 -1 6860 1; +-1 -1 9960 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 0 1; +-1 -1 2370 1; #X obj 134 590 vsl 15 128 0 100 0 0 empty empty empty 0 -8 0 8 -261689 --1 -1 0 1; +-1 -1 12700 1; #X text 199 638 MOVE FIRST SLIDER; #X text 182 662 TO MOVE THE FIXED MASS; #X msg 66 438 forceX mob 300; @@ -51,42 +47,45 @@ #X msg 52 335 bang \, massesPosL; #X obj 52 545 unpack f f f f f; #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 msg 66 384 setK inter 1; +#X msg 66 406 setK inter 2; +#X msg 176 385 setD inter 0.01; +#X msg 176 407 setD inter 1; +#X msg 184 223 iLink inter fix mob 10 2.5 0.5 5; +#X connect 0 0 31 0; +#X connect 2 0 33 0; #X connect 2 1 1 0; #X connect 3 0 6 0; -#X connect 6 0 38 0; +#X connect 6 0 34 0; #X connect 9 0 2 0; -#X connect 10 0 35 0; +#X connect 10 0 31 0; #X connect 11 0 9 0; #X connect 12 0 9 0; #X connect 13 0 9 0; #X connect 14 0 9 0; #X connect 15 0 12 0; -#X connect 17 0 2 0; -#X connect 18 0 2 0; -#X connect 19 0 2 0; -#X connect 20 0 2 0; -#X connect 23 0 3 0; -#X connect 27 0 28 0; -#X connect 28 0 2 0; -#X connect 33 0 2 0; +#X connect 19 0 3 0; +#X connect 23 0 24 0; +#X connect 24 0 2 0; +#X connect 29 0 2 0; +#X connect 30 0 2 0; +#X connect 31 0 3 0; +#X connect 31 1 19 0; +#X connect 31 1 41 0; +#X connect 31 2 13 0; +#X connect 31 3 15 0; +#X connect 31 4 14 0; +#X connect 31 5 11 0; +#X connect 33 0 35 0; +#X connect 33 1 1 0; #X connect 34 0 2 0; -#X connect 35 0 33 0; -#X connect 35 0 3 0; -#X connect 35 1 23 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; -#X connect 35 5 11 0; -#X connect 37 0 39 0; -#X connect 37 1 1 0; +#X connect 35 0 23 0; +#X connect 35 1 21 0; +#X connect 35 2 22 0; +#X connect 35 3 26 0; +#X connect 35 4 25 0; +#X connect 37 0 2 0; #X connect 38 0 2 0; -#X connect 39 0 27 0; -#X connect 39 1 25 0; -#X connect 39 2 26 0; -#X connect 39 3 30 0; -#X connect 39 4 29 0; +#X connect 39 0 2 0; +#X connect 40 0 2 0; #X connect 41 0 9 0; diff --git a/msd/03_msdwave.pd b/msd/03_msdwave.pd index e09102f..e69ae1b 100644 --- a/msd/03_msdwave.pd +++ b/msd/03_msdwave.pd @@ -17,7 +17,7 @@ #X obj 48 153 any; #X obj 127 136 t b f; #X obj 127 57 unpack f f f; -#X obj 45 283 cuboid 0.065 0.065 0.07; +#X obj 48 283 cuboid 0.065 0.065 0.07; #X connect 0 0 6 0; #X connect 1 0 7 0; #X connect 2 0 4 1; @@ -34,19 +34,15 @@ #X obj 145 38 t b b b b; #X text 418 114 Filet abstraction : x0 y0 stepx stepy ny nx; #X obj 454 464 msd -------------; -#X obj 568 488 print msd; #X obj 33 497 msd2D --------------------------------; -#X obj 294 522 print msd2D; #X obj 305 254 route mass; #X msg 305 275 mass msd1 \$1 \$2 \$5; #X obj 145 253 route mass; #X msg 145 274 mass msd2 \$1 \$2 \$3 \$4; -#X obj 33 539 route massesPos; +#X obj 33 517 route massesPos; #X msg 33 343 bang \, get massesPos; #X obj 33 321 t b b; #X obj 265 600 pack f f f; -#X obj 33 561 unpack f f; -#X obj 33 583 t f b; #N canvas 0 0 450 300 getmasses 0; #X obj 84 33 inlet; #X obj 91 71 t b b b; @@ -66,8 +62,8 @@ #X connect 5 0 6 0; #X connect 6 0 2 1; #X connect 8 0 2 1; -#X restore 63 698 pd getmasses; -#X obj 454 507 route massesPosNo; +#X restore 72 657 pd getmasses; +#X obj 454 488 route massesPosNo; #X msg 63 718 get massesPos \$1; #X obj 602 334 rotateXYZ; #X obj 651 450 vsl 15 128 0 4 0 0 empty empty empty 0 -8 0 8 -262131 @@ -94,7 +90,7 @@ #X msg 603 204 view 0 5 0 0 0 0 0 0 1; #X msg 670 605 posX 39 \$1; #X msg 689 625 posX 799 \$1; -#X msg 708 645 posX 760 \$1; +#X msg 707 645 posX 760 \$1; #X text 734 508 Move corners to send a wave!; #X text 194 703 Each time a mass2D position is send \, the corresponding z is asked to the 1D model.; @@ -106,64 +102,68 @@ z is asked to the 1D model.; #X text 304 228 800 masses / 1540 links for each model; #X text 31 455 The 2D model is just here to help display masses and test synchronization between msd objects; +#X obj 33 537 unpack f f f; +#X obj 443 546 unpack f f; +#X obj 173 598 f; +#X obj 33 574 t b f; #X connect 0 0 12 0; #X connect 2 0 1 0; -#X connect 3 0 31 0; +#X connect 3 0 27 0; +#X connect 5 0 16 0; #X connect 5 0 18 0; -#X connect 5 0 20 0; #X connect 6 0 12 0; #X connect 7 0 5 0; -#X connect 8 0 24 0; -#X connect 10 0 28 1; -#X connect 10 0 45 1; -#X connect 12 0 42 0; -#X connect 12 0 43 0; -#X connect 12 1 46 0; -#X connect 12 2 45 0; +#X connect 8 0 22 0; +#X connect 10 0 24 1; +#X connect 10 0 41 1; +#X connect 12 0 38 0; +#X connect 12 0 39 0; +#X connect 12 1 42 0; +#X connect 12 2 41 0; #X connect 12 3 7 0; #X connect 12 3 10 0; -#X connect 14 0 29 0; -#X connect 14 1 15 0; -#X connect 16 0 22 0; -#X connect 16 1 17 0; +#X connect 14 0 25 0; +#X connect 15 0 20 0; +#X connect 16 0 17 0; +#X connect 16 1 14 0; +#X connect 17 0 14 0; #X connect 18 0 19 0; -#X connect 18 1 14 0; -#X connect 19 0 14 0; -#X connect 20 0 21 0; -#X connect 20 1 16 0; -#X connect 21 0 16 0; -#X connect 22 0 26 0; -#X connect 23 0 16 0; -#X connect 24 0 23 0; -#X connect 24 1 14 0; -#X connect 25 0 9 0; -#X connect 26 0 27 0; -#X connect 26 1 25 1; -#X connect 27 0 25 0; -#X connect 27 1 28 0; -#X connect 28 0 30 0; -#X connect 29 0 25 2; -#X connect 30 0 14 0; -#X connect 31 0 4 0; -#X connect 32 0 36 0; -#X connect 33 0 48 0; -#X connect 34 0 49 0; -#X connect 35 0 50 0; -#X connect 36 0 14 0; -#X connect 37 0 31 1; -#X connect 38 0 1 0; -#X connect 39 0 1 0; -#X connect 40 0 31 2; -#X connect 41 0 1 0; -#X connect 41 0 44 0; -#X connect 42 0 16 0; -#X connect 43 0 14 0; -#X connect 44 0 39 0; -#X connect 44 0 40 0; -#X connect 44 0 37 0; -#X connect 45 0 5 0; -#X connect 46 0 5 0; -#X connect 47 0 1 0; -#X connect 48 0 14 0; -#X connect 49 0 14 0; -#X connect 50 0 14 0; +#X connect 18 1 15 0; +#X connect 19 0 15 0; +#X connect 20 0 55 0; +#X connect 21 0 15 0; +#X connect 22 0 21 0; +#X connect 22 1 14 0; +#X connect 23 0 9 0; +#X connect 25 0 56 0; +#X connect 26 0 14 0; +#X connect 27 0 4 0; +#X connect 28 0 32 0; +#X connect 29 0 44 0; +#X connect 30 0 45 0; +#X connect 31 0 46 0; +#X connect 32 0 14 0; +#X connect 33 0 27 1; +#X connect 34 0 1 0; +#X connect 35 0 1 0; +#X connect 36 0 27 2; +#X connect 37 0 1 0; +#X connect 37 0 40 0; +#X connect 38 0 15 0; +#X connect 39 0 14 0; +#X connect 40 0 35 0; +#X connect 40 0 36 0; +#X connect 40 0 33 0; +#X connect 41 0 5 0; +#X connect 42 0 5 0; +#X connect 43 0 1 0; +#X connect 44 0 14 0; +#X connect 45 0 14 0; +#X connect 46 0 14 0; +#X connect 55 0 58 0; +#X connect 55 1 57 1; +#X connect 55 2 23 1; +#X connect 56 1 23 2; +#X connect 57 0 23 0; +#X connect 58 0 57 0; +#X connect 58 1 26 0; diff --git a/msd/main.cpp b/msd/main.cpp index 69dfbd5..f74ba3d 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.03 -- 21.04.2005 + Version 0.04 -- 26.04.2005 */ // include flext header @@ -38,7 +38,7 @@ #include <math.h> // define constants -#define MSD_VERSION 0.03 +#define MSD_VERSION 0.04 #define nb_max_link 4000 #define nb_max_mass 4000 #define Id_length 20 @@ -135,7 +135,9 @@ protected: t_float F=0,Fx=0,distance,vitesse, X_new; t_int i; struct _mass mass_1, mass_2; - + + + for (i=0; i<nb_link; i++) { // compute link forces distance = link[i]->mass1->posX-link[i]->mass2->posX; // L[n] = x1 - x2 @@ -154,10 +156,10 @@ protected: 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++) // compute new masses position only if mobile = 1 if (mass[i]->mobile == 1) { @@ -198,7 +200,7 @@ protected: mass[nb_mass]->posX2 = GetFloat(argv[3]); // x[n-1] mass[nb_mass]->forceX = 0; // Fx[n] mass[nb_mass]->nbr = id_mass; // id number - nb_mass++ ; + nb_mass++; id_mass++; nb_mass = min ( nb_max_mass -1, nb_mass ); SetFloat((sortie[0]),id_mass-1); @@ -350,51 +352,65 @@ protected: { 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++) - if (mass[i]->nbr==GetAInt(argv[1])) // pointer to mass1 - link[nb_link]->mass1 = mass[i]; - else if(mass[i]->nbr==GetAInt(argv[2])) // pointer to mass2 - link[nb_link]->mass2 = mass[i]; - link[nb_link]->K1 = GetFloat(argv[3]); // K1 - 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] - 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 ); - SetFloat((sortie[0]),id_link-1); - SetSymbol((sortie[1]),link[nb_link-1]->Id); - SetFloat((sortie[2]),GetInt(argv[1])); - SetFloat((sortie[3]),GetInt(argv[2])); - SetFloat((sortie[4]),link[nb_link-1]->K1); - SetFloat((sortie[5]),link[nb_link-1]->D1); - SetFloat((sortie[6]),link[nb_link-1]->D2); - ToOutAnything(1,S_Link,7,sortie); + t_mass *mass1 = NULL; + t_mass *mass2 = NULL; + + if (argc < 6 || argc > 8) + error("link : Id Nomass1 Nomass2 K D1 D2 (Lmin Lmax)"); + + // check for existence of link masses: + for (i=0; i<nb_mass;i++) + if (mass[i]->nbr==GetInt(argv[1])) // pointer to mass1 + // we found mass1 + mass1 = mass[i]; + else if (mass[i]->nbr==GetInt(argv[2])) // pointer to mass2 + // ... and mass2 + mass2 = mass[i]; + + if (mass1 and mass2) + { + link[nb_link] = new t_link; // New pointer + link[nb_link]->Id = GetSymbol(argv[0]); // ID + link[nb_link]->mass1 = mass1; // pointer to mass1 + link[nb_link]->mass2 = mass2; // pointer to mass2 + link[nb_link]->K1 = GetFloat(argv[3]); // K1 + 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] + 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 ); + SetFloat((sortie[0]),id_link-1); + SetSymbol((sortie[1]),link[nb_link-1]->Id); + SetFloat((sortie[2]),GetInt(argv[1])); + SetFloat((sortie[3]),GetInt(argv[2])); + SetFloat((sortie[4]),link[nb_link-1]->K1); + SetFloat((sortie[5]),link[nb_link-1]->D1); + SetFloat((sortie[6]),link[nb_link-1]->D2); + ToOutAnything(1,S_Link,7,sortie); + } + else + error("link : Cannot create link: Not all masses for this link have been created yet."); } void m_ilink(int argc,t_atom *argv) @@ -533,35 +549,39 @@ protected: { t_int i,j; t_symbol *auxarg,*auxarg2, *auxtype; - t_atom sortie[4]; + t_atom sortie[3]; auxtype = GetSymbol(argv[0]); auxarg = GetASymbol(argv[1]); //auxarg : & symbol, 0 else if (argc == 1) { 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); + { + SetFloat(sortie[0],mass[i]->nbr); + SetFloat(sortie[1],mass[i]->posX); + ToOutAnything(0,S_massesPos,2,sortie); } 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); + SetFloat(sortie[0],mass[i]->nbr); + SetFloat(sortie[1],mass[i]->out_forceX); + ToOutAnything(0,S_massesForces,2,sortie); } 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); + SetFloat(sortie[0],link[i]->nbr); + SetFloat(sortie[1],link[i]->mass1->posX); + SetFloat(sortie[2],link[i]->mass2->posX); + ToOutAnything(0,S_linksPos,3,sortie); } else // get all masses speeds for (i=0; i<nb_mass; i++) { - SetFloat(sortie[0],mass[i]->speedX); - ToOutAnything(0,S_massesSpeeds,1,sortie); + SetFloat(sortie[0],mass[i]->nbr); + SetFloat(sortie[1],mass[i]->speedX); + ToOutAnything(0,S_massesSpeeds,2,sortie); } } else if (auxtype == S_massesPos) // get mass positions @@ -572,8 +592,9 @@ protected: for (i=0;i<nb_mass;i++) if (mass[i]->nbr==GetInt(argv[j])) { - SetFloat(sortie[0],mass[i]->posX); - ToOutAnything(0,S_massesPosNo,1,sortie); + SetFloat(sortie[0],mass[i]->nbr); + SetFloat(sortie[1],mass[i]->posX); + ToOutAnything(0,S_massesPosNo,2,sortie); } } else //symbol @@ -585,8 +606,9 @@ protected: { if (auxarg2==mass[i]->Id) { - SetFloat(sortie[0],mass[i]->posX); - ToOutAnything(0,S_massesPosId,1,sortie); + SetSymbol(sortie[0],mass[i]->Id); + SetFloat(sortie[1],mass[i]->posX); + ToOutAnything(0,S_massesPosId,2,sortie); } } } @@ -600,8 +622,9 @@ protected: for (i=0;i<nb_mass;i++) if (mass[i]->nbr==GetInt(argv[j])) { - SetFloat(sortie[0],mass[i]->out_forceX); - ToOutAnything(0,S_massesForcesNo,1,sortie); + SetFloat(sortie[0],mass[i]->nbr); + SetFloat(sortie[1],mass[i]->out_forceX); + ToOutAnything(0,S_massesForcesNo,2,sortie); } } else //string @@ -613,8 +636,9 @@ protected: { if (auxarg2==mass[i]->Id) { - SetFloat(sortie[0],mass[i]->out_forceX); - ToOutAnything(0,S_massesForcesId,1,sortie); + SetSymbol(sortie[0],mass[i]->Id); + SetFloat(sortie[1],mass[i]->out_forceX); + ToOutAnything(0,S_massesForcesId,2,sortie); } } } @@ -628,9 +652,10 @@ protected: for (i=0;i<nb_link;i++) if (link[i]->nbr==GetInt(argv[j])) { - SetFloat(sortie[0],link[i]->mass1->posX); - SetFloat(sortie[1],link[i]->mass2->posX); - ToOutAnything(0,S_linksPosNo,2,sortie); + SetFloat(sortie[0],link[i]->nbr); + SetFloat(sortie[1],link[i]->mass1->posX); + SetFloat(sortie[2],link[i]->mass2->posX); + ToOutAnything(0,S_linksPosNo,3,sortie); } } else //symbol @@ -642,9 +667,10 @@ protected: { if (auxarg2==link[i]->Id) { - SetFloat(sortie[0],link[i]->mass1->posX); - SetFloat(sortie[1],link[i]->mass2->posX); - ToOutAnything(0,S_linksPosId,2,sortie); + SetSymbol(sortie[0],link[i]->Id); + SetFloat(sortie[1],link[i]->mass1->posX); + SetFloat(sortie[2],link[i]->mass2->posX); + ToOutAnything(0,S_linksPosId,3,sortie); } } } @@ -658,8 +684,9 @@ protected: for (i=0;i<nb_mass;i++) if (mass[i]->nbr==GetInt(argv[j])) { - SetFloat(sortie[0],mass[i]->speedX); - ToOutAnything(0,S_massesSpeedsNo,1,sortie); + SetFloat(sortie[0],mass[i]->nbr); + SetFloat(sortie[1],mass[i]->speedX); + ToOutAnything(0,S_massesSpeedsNo,2,sortie); } } else //symbol @@ -671,8 +698,9 @@ protected: { if (auxarg2==mass[i]->Id) { - SetFloat(sortie[0],mass[i]->speedX); - ToOutAnything(0,S_massesSpeedsId,1,sortie); + SetSymbol(sortie[0],mass[i]->Id); + SetFloat(sortie[1],mass[i]->speedX); + ToOutAnything(0,S_massesSpeedsId,2,sortie); } } } |