Update of /cvsroot/pure-data/externals/nusmuk/msd In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7919/nusmuk/msd
Modified Files: main.cpp Log Message: some small changes for Windows compilation
Index: main.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/nusmuk/msd/main.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** main.cpp 25 Apr 2005 16:18:38 -0000 1.5 --- main.cpp 26 Apr 2005 11:39:49 -0000 1.6 *************** *** 40,45 **** // define constants #define MSD_VERSION 0.03 ! #define nb_max_link 4000 ! #define nb_max_mass 4000 #define Id_length 20
--- 40,45 ---- // define constants #define MSD_VERSION 0.03 ! #define nb_max_link 4000 ! #define nb_max_mass 4000 #define Id_length 20
*************** *** 49,72 **** #endif
! #define max(a,b) ( ((a) > (b)) ? (a) : (b) ) #define min(a,b) ( ((a) < (b)) ? (a) : (b) )
! typedef struct _mass { t_symbol *Id; t_int nbr; ! t_int mobile; ! t_float invM; ! t_float speedX; t_float posX; ! t_float posX2; t_float forceX; t_float out_forceX; ! } t_mass; ! ! typedef struct _link { t_symbol *Id; ! t_int nbr; ! t_mass *mass1; ! t_mass *mass2; t_float K1, D1, D2; t_float longx, longueur, long_min, long_max; --- 49,80 ---- #endif
! #define max(a,b) ( ((a) > (b)) ? (a) : (b) ) #define min(a,b) ( ((a) < (b)) ? (a) : (b) )
! #ifdef _MSC_VER ! #define NEWARR(type,var,size) type *var = new type[size] ! #define DELARR(var) delete[] var ! #else ! #define NEWARR(type,var,size) type var[size] ! #define DELARR(var) ((void)0) ! #endif ! ! typedef struct _mass { t_symbol *Id; t_int nbr; ! t_int mobile; ! t_float invM; ! t_float speedX; t_float posX; ! t_float posX2; t_float forceX; t_float out_forceX; ! } t_mass; ! ! typedef struct _link { t_symbol *Id; ! t_int nbr; ! t_mass *mass1; ! t_mass *mass2; t_float K1, D1, D2; t_float longx, longueur, long_min, long_max; *************** *** 75,79 ****
- class msd: public flext_base --- 83,86 ---- *************** *** 106,110 **** { t_int i; ! t_atom sortie[0];
for (i=0; i<nb_mass; i++) { --- 113,117 ---- { t_int i; ! // t_atom sortie;
for (i=0; i<nb_mass; i++) { *************** *** 114,119 **** delete link[i]; } ! ToOutAnything(1,S_Reset,0,sortie); ! nb_link = 0; nb_mass = 0; id_mass = 0; --- 121,126 ---- delete link[i]; } ! ToOutAnything(1,S_Reset,0,NULL); ! nb_link = 0; nb_mass = 0; id_mass = 0; *************** *** 126,134 **** void m_bang() { ! 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 --- 133,141 ---- void m_bang() { ! 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 *************** *** 142,148 **** 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] --- 149,155 ---- 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] *************** *** 151,158 **** } ! ! for (i=0; i<nb_mass; i++) ! // compute new masses position only if mobile = 1 ! if (mass[i]->mobile == 1) { X_new = mass[i]->forceX * mass[i]->invM + 2*mass[i]->posX - mass[i]->posX2; // x[n] =Fx[n]/M+2x[n]-x[n-1] mass[i]->posX2 = mass[i]->posX; // x[n-2] = x[n-1] --- 158,165 ---- } ! ! for (i=0; i<nb_mass; i++) ! // compute new masses position only if mobile = 1 ! if (mass[i]->mobile == 1) { X_new = mass[i]->forceX * mass[i]->invM + 2*mass[i]->posX - mass[i]->posX2; // x[n] =Fx[n]/M+2x[n]-x[n-1] mass[i]->posX2 = mass[i]->posX; // x[n-2] = x[n-1] *************** *** 161,176 **** }
! for (i=0; i<nb_mass; i++) { // clear forces ! mass[i]->out_forceX = mass[i]->forceX; mass[i]->forceX = 0; // Fx[n] = 0 ! } }
// -------------------------------------------------------------- MASSES // ---------------------------------------------------------------------- ! void m_mass(int argc,t_atom *argv) ! // add a mass ! // Id, nbr, mobile, invM, speedX, posX, forceX { t_atom sortie[5], aux[2]; --- 168,183 ---- }
! for (i=0; i<nb_mass; i++) { // clear forces ! mass[i]->out_forceX = mass[i]->forceX; mass[i]->forceX = 0; // Fx[n] = 0 ! } }
// -------------------------------------------------------------- MASSES // ---------------------------------------------------------------------- ! void m_mass(int argc,t_atom *argv) ! // add a mass ! // Id, nbr, mobile, invM, speedX, posX, forceX { t_atom sortie[5], aux[2]; *************** *** 180,184 **** 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 --- 187,191 ---- 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 *************** *** 187,197 **** else M = GetFloat(argv[2]); mass[nb_mass]->invM = 1/(M); // 1/M ! mass[nb_mass]->speedX = 0; // vx[n] mass[nb_mass]->posX = GetFloat(argv[3]); // x[n] ! 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++ ; ! id_mass++; nb_mass = min ( nb_max_mass -1, nb_mass ); SetFloat((sortie[0]),id_mass-1); --- 194,204 ---- else M = GetFloat(argv[2]); mass[nb_mass]->invM = 1/(M); // 1/M ! mass[nb_mass]->speedX = 0; // vx[n] mass[nb_mass]->posX = GetFloat(argv[3]); // x[n] ! 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++ ; ! id_mass++; nb_mass = min ( nb_max_mass -1, nb_mass ); SetFloat((sortie[0]),id_mass-1); *************** *** 203,208 **** }
! void m_forceX(int argc,t_atom *argv) ! { // add a force to mass(es) named Id t_int i; --- 210,215 ---- }
! void m_forceX(int argc,t_atom *argv) ! { // add a force to mass(es) named Id t_int i; *************** *** 220,225 ****
void m_posX(int argc,t_atom *argv) ! { ! // displace mass(es) named Id to a certain position t_int i; const t_symbol *sym = GetASymbol(argv[0]); --- 227,232 ----
void m_posX(int argc,t_atom *argv) ! { ! // displace mass(es) named Id to a certain position t_int i; const t_symbol *sym = GetASymbol(argv[0]); *************** *** 246,251 ****
void m_set_mobile(int argc,t_atom *argv) ! { ! // set mass No to mobile t_int i,aux; --- 253,258 ----
void m_set_mobile(int argc,t_atom *argv) ! { ! // set mass No to mobile t_int i,aux; *************** *** 263,268 ****
void m_set_fixe(int argc,t_atom *argv) ! { ! // set mass No to fixed t_int i,aux; --- 270,275 ----
void m_set_fixe(int argc,t_atom *argv) ! { ! // set mass No to fixed t_int i,aux; *************** *** 283,287 **** // Delete mass t_int i,nb_link_delete=0; ! t_atom sortie[5], aux[nb_link]; if (argc != 1) --- 290,295 ---- // Delete mass t_int i,nb_link_delete=0; ! t_atom sortie[5]; ! NEWARR(t_atom,aux,nb_link); if (argc != 1) *************** *** 313,321 **** break; } }
void m_Xmax(int argc,t_atom *argv) ! { // set X max if (argc != 1) --- 321,331 ---- break; } + + DELARR(aux); }
void m_Xmax(int argc,t_atom *argv) ! { // set X max if (argc != 1) *************** *** 325,329 ****
void m_Xmin(int argc,t_atom *argv) ! { // set X min if (argc != 1) --- 335,339 ----
void m_Xmin(int argc,t_atom *argv) ! { // set X min if (argc != 1) *************** *** 336,342 ****
void m_link(int argc,t_atom *argv) ! // add a link ! // Id, *mass1, *mass2, K1, D1, D2, (Lmin,Lmax) ! { t_atom sortie[7], aux[2]; t_int i; --- 346,352 ----
void m_link(int argc,t_atom *argv) ! // add a link ! // Id, *mass1, *mass2, K1, D1, D2, (Lmin,Lmax) ! { t_atom sortie[7], aux[2]; t_int i; *************** *** 351,355 **** 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 --- 361,365 ---- 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 *************** *** 376,380 **** } nb_link++; ! id_link++; nb_link = min ( nb_max_link -1, nb_link ); SetFloat((sortie[0]),id_link-1); --- 386,390 ---- } nb_link++; ! id_link++; nb_link = min ( nb_max_link -1, nb_link ); SetFloat((sortie[0]),id_link-1); *************** *** 385,397 **** SetFloat((sortie[5]),link[nb_link-1]->D1); SetFloat((sortie[6]),link[nb_link-1]->D2); ! ToOutAnything(1,S_Link,7,sortie); }
void m_ilink(int argc,t_atom *argv) ! // add interactor link ! // Id, Id masses1, Id masses2, K1, D1, D2, (Lmin, Lmax) ! { t_atom aux[2], arglist[8]; ! t_int i,j, imass1[nb_mass], nbmass1=0, imass2[nb_mass], nbmass2=0; t_symbol *Id1, *Id2;
--- 395,409 ---- SetFloat((sortie[5]),link[nb_link-1]->D1); SetFloat((sortie[6]),link[nb_link-1]->D2); ! ToOutAnything(1,S_Link,7,sortie); }
void m_ilink(int argc,t_atom *argv) ! // add interactor link ! // Id, Id masses1, Id masses2, K1, D1, D2, (Lmin, Lmax) ! { t_atom aux[2], arglist[8]; ! t_int i,j,nbmass1=0,nbmass2=0; ! NEWARR(t_int,imass1,nb_mass); ! NEWARR(t_int,imass2,nb_mass); t_symbol *Id1, *Id2;
*************** *** 434,441 **** m_link(argc,arglist); } }
void m_setK(int argc,t_atom *argv) ! { // set rigidity of link(s) named Id t_int i; --- 446,456 ---- m_link(argc,arglist); } + + DELARR(imass1); + DELARR(imass2); }
void m_setK(int argc,t_atom *argv) ! { // set rigidity of link(s) named Id t_int i; *************** *** 453,457 ****
void m_setD(int argc,t_atom *argv) ! { // set damping of link(s) named Id t_int i; --- 468,472 ----
void m_setD(int argc,t_atom *argv) ! { // set damping of link(s) named Id t_int i; *************** *** 469,473 ****
void m_setD2(int argc,t_atom *argv) ! { // set damping of link(s) named Id t_int i; --- 484,488 ----
void m_setD2(int argc,t_atom *argv) ! { // set damping of link(s) named Id t_int i; *************** *** 657,661 **** if (auxarg2==mass[i]->Id) { ! SETFLOAT(&sortie[0],mass[i]->speedX); ToOutAnything(0,S_massesSpeedsId,1,sortie); } --- 672,676 ---- if (auxarg2==mass[i]->Id) { ! SetFloat(sortie[0],mass[i]->speedX); ToOutAnything(0,S_massesSpeedsId,1,sortie); } *************** *** 671,675 **** // List of masses positions on first outlet { ! t_atom sortie[nb_mass]; t_int i; --- 686,690 ---- // List of masses positions on first outlet { ! NEWARR(t_atom,sortie,nb_mass); t_int i; *************** *** 678,681 **** --- 693,697 ---- } ToOutAnything(0, S_massesPosL, nb_mass, sortie); + DELARR(sortie); }
*************** *** 683,687 **** // List of masses forces on first outlet { ! t_atom sortie[nb_mass]; t_int i; --- 699,703 ---- // List of masses forces on first outlet { ! NEWARR(t_atom,sortie,nb_mass); t_int i; *************** *** 690,693 **** --- 706,710 ---- } ToOutAnything(0, S_massesForcesL, nb_mass, sortie); + DELARR(sortie); }
*************** *** 724,728 **** // -----------------------------------------------------------------------------------
! t_link * link[nb_max_link]; // Pointer table on links t_mass * mass[nb_max_mass]; // Pointer table on masses t_float Xmin, Xmax; // Limit values --- 741,745 ---- // -----------------------------------------------------------------------------------
! t_link * link[nb_max_link]; // Pointer table on links t_mass * mass[nb_max_mass]; // Pointer table on masses t_float Xmin, Xmax; // Limit values