aboutsummaryrefslogtreecommitdiff
path: root/pmpd~.c
diff options
context:
space:
mode:
authorCyrille Henry <nusmuk@users.sourceforge.net>2011-02-18 19:56:11 +0000
committerCyrille Henry <nusmuk@users.sourceforge.net>2011-02-18 19:56:11 +0000
commited864f40e547f6994ff61135016f40be682d74e2 (patch)
treeb02063db1415cff63998b316fccf5f29ac8ce8df /pmpd~.c
parent45db148cbbebda92ccc34ba8c7cbb0736d63c297 (diff)
1st test version of pmpd / pmpd2d / pmpd3d, as MSD compatible, but without flext
svn path=/trunk/externals/pmpd/; revision=14927
Diffstat (limited to 'pmpd~.c')
-rw-r--r--pmpd~.c117
1 files changed, 59 insertions, 58 deletions
diff --git a/pmpd~.c b/pmpd~.c
index ce8f02d..db5d821 100644
--- a/pmpd~.c
+++ b/pmpd~.c
@@ -11,18 +11,18 @@
#include "m_pd.h"
-#include "stdio.h"
+#include "stdio.h"
#include "math.h"
#define max(a,b) ( ((a) > (b)) ? (a) : (b) )
#define min(a,b) ( ((a) < (b)) ? (a) : (b) )
-
+
#define nb_max_link 10000
#define nb_max_mass 10000
-#define nb_max_in 1000
+#define nb_max_in 1000
#define nb_max_out 1000
#define nb_max_outlet 20
-#define nb_max_inlet 20 // hard-coded on the methods definition
+#define nb_max_inlet 20 // hard-coded on the methods definition
static t_class *pmpd_tilde_class;
@@ -37,13 +37,13 @@ typedef struct _link {
struct _mass *mass1;
struct _mass *mass2;
t_float Ke, K1, D1;
-} foo1 ;
-
+} foo1 ;
+
typedef struct _NLlink {
struct _mass *mass1;
struct _mass *mass2;
t_float Ke, K1, D1,L0,Lmin, Lmax, Pow;
-} foo1b ;
+} foo1b ;
typedef struct _inPos {
// in en position
@@ -51,27 +51,27 @@ typedef struct _inPos {
struct _mass *mass1;
t_float influence;
} foo2;
-
+
typedef struct _inForce {
// in en force
t_int nbr_inlet;
struct _mass *mass1;
t_float influence;
} foo3;
-
+
typedef struct _outPos {
// out en position
t_int nbr_outlet;
struct _mass *mass1;
t_float influence;
-} foo4;
-
+} foo4;
+
typedef struct _outSpeed {
// out en vitesse
t_int nbr_outlet;
struct _mass *mass1;
t_float influence;
-} foo5;
+} foo5;
typedef struct _pmpd_tilde {
t_object x_obj;
@@ -123,7 +123,7 @@ t_int *pmpd_tilde_perform(t_int *w)
t_float F,L;
t_int i;
- struct _mass mass_1, mass_2;
+// struct _mass mass_1, mass_2;
t_sample *out[nb_max_outlet];
t_sample *in[nb_max_inlet];
@@ -135,15 +135,16 @@ t_int *pmpd_tilde_perform(t_int *w)
out[i]= x->outlet_vector[i];
while (n--)
- {
+ {
x->loop = 0;
while (x->loop++ < x->nb_loop)
- {
+ {
for (i=0; i<x->nb_inPos; i++)
- // get inlet value and make it a position to the specified mass x->inPos[i].mass1->posX = x->inPos[i].influence * *in[x->inPos[i].nbr_inlet];
+ // get inlet value and make it a position to the specified mass
+ x->inPos[i].mass1->posX = x->inPos[i].influence * *in[x->inPos[i].nbr_inlet];
for (i=0; i<x->nb_inForce; i++)
- // get inlet value and make it a force to the specified mass
- x->inForce[i].mass1->forceX += x->inForce[i].influence * *in[x->inForce[i].nbr_inlet];
+ // get inlet value and make it a force to the specified mass
+ x->inForce[i].mass1->forceX += x->inForce[i].influence * *in[x->inForce[i].nbr_inlet];
for (i=0; i<x->nb_link; i++)
// compute forces generated by links (spring / dashpot)
@@ -157,14 +158,14 @@ t_int *pmpd_tilde_perform(t_int *w)
x->link[i].mass1->forceX -= F;
x->link[i].mass2->forceX += F;
}
-
+
for (i=0; i<x->nb_NLlink; i++)
// compute forces generated by NLlinks (spring / dashpot)
- {
- L=x->NLlink[i].mass1->posX - x->NLlink[i].mass2->posX - x->NLlink[i].L0;
- if (L<x->NLlink[i].Lmax & L>x->NLlink[i].Lmin)
+ {
+ L=x->NLlink[i].mass1->posX - x->NLlink[i].mass2->posX - x->NLlink[i].L0;
+ if (L<x->NLlink[i].Lmax & L>x->NLlink[i].Lmin)
{
- F = x->NLlink[i].K1 * pow(fabs(L) ,x->NLlink[i].Pow) ;
+ F = x->NLlink[i].K1 * pow(fabs(L) ,x->NLlink[i].Pow) ;
if (L < 0) F *= -1;
// spring
@@ -175,14 +176,14 @@ t_int *pmpd_tilde_perform(t_int *w)
x->NLlink[i].mass2->forceX += F;
}
}
- for (i=1; i<x->nb_mass; i++)
+ for (i=1; i<x->nb_mass; i++)
{
- // compute new masses position
+ // compute new masses position
// a mass does not move if M=0 (i.e : invM = 0)
- x->mass[i].speedX += x->mass[i].forceX * x->mass[i].invM;
+ x->mass[i].speedX += x->mass[i].forceX * x->mass[i].invM;
x->mass[i].forceX = 0;
- x->mass[i].forceX = random_bang_pmpd_tilde(x) * 1e-25;
- // only used for denormal problem
+ x->mass[i].forceX = random_bang_pmpd_tilde(x) * 1e-25;
+ // only used for denormal problem
// -ffast-math -O6 does not solve the problem
x->mass[i].posX += x->mass[i].speedX ;
}
@@ -254,21 +255,21 @@ void pmpd_tilde_posX(t_pmpd_tilde *x, t_float nbr_mass, t_float posX)
void pmpd_tilde_mass(t_pmpd_tilde *x, t_float M, t_float posX)
// add a mass
-//invM speedX posX force
+//invM speedX posX force
{
- if (M<=0)
- {
- M = 0;
+ if (M<=0)
+ {
+ M = 0;
x->mass[x->nb_mass].invM = 0;
- }
- else
+ }
+ else
x->mass[x->nb_mass].invM = 1/M;
-
+
x->mass[x->nb_mass].speedX = 0;
x->mass[x->nb_mass].posX = posX;
x->mass[x->nb_mass].forceX = 0;
- x->nb_mass++ ;
+ x->nb_mass++ ;
if (x->nb_mass == nb_max_mass) error("to many mass");
x->nb_mass = min ( nb_max_mass -1, x->nb_mass );
}
@@ -282,31 +283,31 @@ void pmpd_tilde_link(t_pmpd_tilde *x, t_float mass_1, t_float mass_2, t_float K1
x->link[x->nb_link].K1 = K1;
x->link[x->nb_link].D1 = D1;
- x->nb_link++ ;
+ x->nb_link++ ;
if (x->nb_link == nb_max_link) error("to many link");
x->nb_link = min ( nb_max_link -1, x->nb_link );
-}
-
-void pmpd_tilde_NLlink(t_pmpd_tilde *x, t_symbol *s, int argc, t_atom *argv)
+}
+
+void pmpd_tilde_NLlink(t_pmpd_tilde *x, t_symbol *s, int argc, t_atom *argv)
// t_float mass_1, t_float mass_2, t_float K1, t_float D1, t_float Pow, t_float Lmin, t_float Lmax, t_float L0
// add a NLlink
-{
+{
if (argc == 8)
- {
+ {
x->NLlink[x->nb_NLlink].mass1 = &x->mass[max(0, min ( x->nb_mass, (int)atom_getfloatarg(0, argc, argv)))];
x->NLlink[x->nb_NLlink].mass2 = &x->mass[max(0, min ( x->nb_mass, (int)atom_getfloatarg(1, argc, argv)))];
x->NLlink[x->nb_NLlink].K1 = atom_getfloatarg(2, argc, argv);
x->NLlink[x->nb_NLlink].D1 = atom_getfloatarg(3, argc, argv);
- x->NLlink[x->nb_NLlink].Pow = atom_getfloatarg(4, argc, argv);
+ x->NLlink[x->nb_NLlink].Pow = atom_getfloatarg(4, argc, argv);
x->NLlink[x->nb_NLlink].L0 = atom_getfloatarg(5, argc, argv);
x->NLlink[x->nb_NLlink].Lmin = atom_getfloatarg(6, argc, argv);
x->NLlink[x->nb_NLlink].Lmax = atom_getfloatarg(7, argc, argv);
- x->nb_NLlink++ ;
+ x->nb_NLlink++ ;
if (x->nb_NLlink == nb_max_link) error("to many NLlink");
- x->nb_NLlink = min ( nb_max_link -1, x->nb_NLlink );
- }
- else
+ x->nb_NLlink = min ( nb_max_link -1, x->nb_NLlink );
+ }
+ else
error("wrong argument number for NLlink");
}
@@ -318,10 +319,10 @@ void pmpd_tilde_inPos(t_pmpd_tilde *x, t_float nb_inlet, t_float mass_1, t_float
x->inPos[x->nb_inPos].mass1 = &x->mass[max(0, min ( x->nb_mass, (int)mass_1))];
x->inPos[x->nb_inPos].influence = influence;
- x->nb_inPos++;
+ x->nb_inPos++;
if (x->nb_inPos == nb_max_in) error("to many inPos");
x->nb_inPos = min ( nb_max_in - 1, x->nb_inPos );
-}
+}
void pmpd_tilde_inForce(t_pmpd_tilde *x, t_float nb_inlet, t_float mass_1, t_float influence)
//add an input point
// nbr_inlet, *mass1, influence;
@@ -330,10 +331,10 @@ void pmpd_tilde_inForce(t_pmpd_tilde *x, t_float nb_inlet, t_float mass_1, t_flo
x->inForce[x->nb_inForce].mass1 = &x->mass[max(0, min ( x->nb_mass, (int)mass_1))];
x->inForce[x->nb_inForce].influence = influence;
- x->nb_inForce++;
+ x->nb_inForce++;
if (x->nb_inForce == nb_max_in) error("to many inForce");
x->nb_inForce = min ( nb_max_in - 1, x->nb_inForce );
-}
+}
void pmpd_tilde_outPos(t_pmpd_tilde *x, t_float nb_outlet, t_float mass_1, t_float influence)
// add an output point
@@ -343,7 +344,7 @@ void pmpd_tilde_outPos(t_pmpd_tilde *x, t_float nb_outlet, t_float mass_1, t_flo
x->outPos[x->nb_outPos].mass1 = &x->mass[max(0, min ( x->nb_mass, (int)mass_1))];
x->outPos[x->nb_outPos].influence = influence;
- x->nb_outPos++ ;
+ x->nb_outPos++ ;
if (x->nb_outPos == nb_max_out) error("to many outPos");
x->nb_outPos = min ( nb_max_out - 1, x->nb_outPos );
}
@@ -356,14 +357,14 @@ void pmpd_tilde_outSpeed(t_pmpd_tilde *x, t_float nb_outlet, t_float mass_1, t_f
x->outSpeed[x->nb_outSpeed].mass1 = &x->mass[max(0, min ( x->nb_mass, (int)mass_1))];
x->outSpeed[x->nb_outSpeed].influence = influence;
- x->nb_outSpeed++ ;
+ x->nb_outSpeed++ ;
if (x->nb_outSpeed == nb_max_out) error("to many outSpeed");
x->nb_outSpeed = min ( nb_max_out - 1, x->nb_outSpeed );
}
void pmpd_tilde_reset(t_pmpd_tilde *x)
{
- x->nb_link = 0;
+ x->nb_link = 0;
x->nb_NLlink = 0;
x->nb_mass = 0;
x->nb_inPos= 0;
@@ -391,7 +392,7 @@ void *pmpd_tilde_new(t_symbol *s, int argc, t_atom *argv)
for(i=0; i<x->nb_inlet-1; i++)
inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
- x->nb_loop = max (1, (int)atom_getfloatarg(2, argc, argv) );
+ x->nb_loop = max (1, (int)atom_getfloatarg(2, argc, argv) );
return (void *)x;
}
@@ -404,9 +405,9 @@ void pmpd_tilde_setup(void) {
class_addbang(pmpd_tilde_class, pmpd_tilde_bang);
class_addfloat(pmpd_tilde_class, (t_method)pmpd_tilde_float);
class_addmethod(pmpd_tilde_class, (t_method)pmpd_tilde_mass, gensym("mass"), A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
- class_addmethod(pmpd_tilde_class, (t_method)pmpd_tilde_link, gensym("link"), A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
- class_addmethod(pmpd_tilde_class, (t_method)pmpd_tilde_NLlink, gensym("NLlink"), A_GIMME, 0);
- class_addmethod(pmpd_tilde_class, (t_method)pmpd_tilde_inPos, gensym("inPos"), A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
+ class_addmethod(pmpd_tilde_class, (t_method)pmpd_tilde_link, gensym("link"), A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
+ class_addmethod(pmpd_tilde_class, (t_method)pmpd_tilde_NLlink, gensym("NLlink"), A_GIMME, 0);
+ class_addmethod(pmpd_tilde_class, (t_method)pmpd_tilde_inPos, gensym("inPos"), A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
class_addmethod(pmpd_tilde_class, (t_method)pmpd_tilde_inForce, gensym("inForce"), A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
class_addmethod(pmpd_tilde_class, (t_method)pmpd_tilde_outPos, gensym("outPos"), A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
class_addmethod(pmpd_tilde_class, (t_method)pmpd_tilde_outSpeed, gensym("outSpeed"), A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);