aboutsummaryrefslogtreecommitdiff
path: root/pmpd_set.c
diff options
context:
space:
mode:
authorCyrille Henry <nusmuk@users.sourceforge.net>2013-05-01 16:45:34 +0000
committerCyrille Henry <nusmuk@users.sourceforge.net>2013-05-01 16:45:34 +0000
commit7d2a7d2cb03f9a238babc6d17949cb89d64d02ec (patch)
tree713d40c9c68d0bc1a44c4a01f1bf15235057f63a /pmpd_set.c
parent515722a58656d57343b78eedb6a74e1e87830058 (diff)
add all pmpd3d new functionality to pmpd
svn path=/trunk/externals/pmpd/; revision=17107
Diffstat (limited to 'pmpd_set.c')
-rw-r--r--pmpd_set.c273
1 files changed, 245 insertions, 28 deletions
diff --git a/pmpd_set.c b/pmpd_set.c
index f17ed6e..bb91ca0 100644
--- a/pmpd_set.c
+++ b/pmpd_set.c
@@ -42,6 +42,36 @@ void pmpd_setD(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
}
}
+void pmpd_setD2(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int tmp, i;
+
+ if ( ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) )
+ {
+ tmp = atom_getfloatarg(0, argc, argv);
+ tmp = max(0, min( x->nb_mass-1, tmp));
+ x->mass[tmp].D2 = atom_getfloatarg(1, argc, argv);
+ }
+ if ( ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) )
+ {
+ for (i=0; i< x->nb_mass; i++)
+ {
+ if ( atom_getsymbolarg(0,argc,argv) == x->mass[i].Id)
+ {
+ x->mass[i].D2 = atom_getfloatarg(1, argc, argv);
+ }
+ }
+ }
+ if ( ( argv[0].a_type == A_FLOAT ) && ( argc == 1 ) )
+ {
+ for (i=0; i< x->nb_mass; i++)
+ {
+ x->mass[i].D2 = atom_getfloatarg(0, argc, argv);
+ }
+ }
+
+}
+
void pmpd_setL(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
{
int tmp, i;
@@ -80,6 +110,44 @@ void pmpd_setL(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
}
}
+void pmpd_setLCurrent(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int tmp, i;
+
+ if ( ( argc == 1 ) && ( argv[0].a_type == A_FLOAT ) )
+ { // 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[i].distance;
+ }
+ else if ( ( argc == 1 ) && ( argv[0].a_type == A_SYMBOL ) )
+ { // 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_FLOAT ) && ( argv[1].a_type == A_FLOAT ) )
+ { // set a link to a mix between it's curent length and it's size
+ i = atom_getfloatarg(0, argc, argv);
+ i = max(0, min( x->nb_link-1, i));
+ x->link[i].L = mix(x->link[i].L,x->link[i].distance,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 mix between it's curent length and it's size
+ for (i=0; i< x->nb_link; i++)
+ {
+ if ( atom_getsymbolarg(0,argc,argv) == x->link[i].Id)
+ {
+ x->link[i].L = mix(x->link[i].L,x->link[i].distance,atom_getfloatarg(1, argc, argv));
+ }
+ }
+ }
+}
+
void pmpd_setLKTab(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
{
int tmp, i;
@@ -213,19 +281,15 @@ void pmpd_setMobile(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
}
}
-void pmpd_posX(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+void pmpd_setSpeedX(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
{
-// displace a mass to a certain position
int tmp, i;
if ( ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) )
{
tmp = atom_getfloatarg(0, argc, argv);
tmp = max(0, min( x->nb_mass-1, tmp));
- x->mass[tmp].posX = atom_getfloatarg(1, argc, argv);
- x->mass[tmp].speedX = 0; // ??? TODO : esce la bonne chose a faire?
- x->mass[tmp].forceX = 0; // ??? TODO : esce la bonne chose a faire?
-
+ x->mass[tmp].speedX = atom_getfloatarg(1, argc, argv);
}
if ( ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) )
{
@@ -233,16 +297,12 @@ void pmpd_posX(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
{
if ( atom_getsymbolarg(0,argc,argv) == x->mass[i].Id)
{
- x->mass[i].posX = atom_getfloatarg(1, argc, argv);
- x->mass[i].speedX = 0; // ??? TODO : esce la bonne chose a faire?
- x->mass[i].forceX = 0; // ??? TODO : esce la bonne chose a faire?
-
+ x->mass[i].speedX = atom_getfloatarg(1, argc, argv);
}
}
}
}
-
-void pmpd_setD2(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+void pmpd_setForceX(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
{
int tmp, i;
@@ -250,7 +310,7 @@ void pmpd_setD2(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
{
tmp = atom_getfloatarg(0, argc, argv);
tmp = max(0, min( x->nb_mass-1, tmp));
- x->mass[tmp].D2 = atom_getfloatarg(1, argc, argv);
+ x->mass[tmp].forceX = atom_getfloatarg(1, argc, argv);
}
if ( ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) )
{
@@ -258,49 +318,91 @@ void pmpd_setD2(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
{
if ( atom_getsymbolarg(0,argc,argv) == x->mass[i].Id)
{
- x->mass[i].D2 = atom_getfloatarg(1, argc, argv);
+ x->mass[i].forceX = atom_getfloatarg(1, argc, argv);
}
}
}
- if ( ( argv[0].a_type == A_FLOAT ) && ( argc == 1 ) )
+}
+
+void pmpd_setActivei(t_pmpd *x, int i)
+{
+ float L;
+ L = x->link[i].mass1->posX - x->link[i].mass2->posX;
+ x->link[i].distance = L;
+ x->link[i].active = 1;
+}
+
+void pmpd_setActive(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int tmp, i;
+
+ if ( (argc == 1) && ( argv[0].a_type == A_FLOAT ) )
{
- for (i=0; i< x->nb_mass; i++)
+ tmp = atom_getfloatarg(0, argc, argv);
+ tmp = max(0, min( x->nb_link-1, tmp));
+ pmpd_setActivei(x,tmp);
+ }
+ else if ( (argc == 1) && ( argv[0].a_type == A_SYMBOL ) )
+ {
+ for (i=0; i< x->nb_link; i++)
{
- x->mass[i].D2 = atom_getfloatarg(0, argc, argv);
+ if ( atom_getsymbolarg(0,argc,argv) == x->link[i].Id )
+ {
+ pmpd_setActivei(x,i);
+ }
+ }
+ }
+ else if ( argc == 0 )
+ {
+ for (i=0; i< x->nb_link; i++)
+ {
+ pmpd_setActivei(x,i);
}
}
}
-void pmpd_setSpeedX(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+void pmpd_setInactive(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
{
int tmp, i;
- if ( ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) )
+ if ( (argc == 1) && ( argv[0].a_type == A_FLOAT ) )
{
tmp = atom_getfloatarg(0, argc, argv);
- tmp = max(0, min( x->nb_mass-1, tmp));
- x->mass[tmp].speedX = atom_getfloatarg(1, argc, argv);
+ tmp = max(0, min( x->nb_link-1, tmp));
+ x->link[tmp].active = 0;
}
- if ( ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) )
+ else if ( (argc == 1) && ( argv[0].a_type == A_SYMBOL ) )
{
- for (i=0; i< x->nb_mass; i++)
+ for (i=0; i< x->nb_link; i++)
{
- if ( atom_getsymbolarg(0,argc,argv) == x->mass[i].Id)
+ if ( atom_getsymbolarg(0,argc,argv) == x->link[i].Id)
{
- x->mass[i].speedX = atom_getfloatarg(1, argc, argv);
+ x->link[i].active = 0;
}
}
}
+ else if ( argc == 0 )
+ {
+ for (i=0; i< x->nb_link; i++)
+ {
+ x->link[i].active = 0;
+ }
+ }
}
-void pmpd_setForceX(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+
+void pmpd_posX(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
{
+// displace a mass to a certain position
int tmp, i;
if ( ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) )
{
tmp = atom_getfloatarg(0, argc, argv);
tmp = max(0, min( x->nb_mass-1, tmp));
- x->mass[tmp].forceX = atom_getfloatarg(1, argc, argv);
+ x->mass[tmp].posX = atom_getfloatarg(1, argc, argv);
+ x->mass[tmp].speedX = 0; // ??? TODO : esce la bonne chose a faire?
+ x->mass[tmp].forceX = 0; // ??? TODO : esce la bonne chose a faire?
+
}
if ( ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) )
{
@@ -308,8 +410,123 @@ void pmpd_setForceX(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
{
if ( atom_getsymbolarg(0,argc,argv) == x->mass[i].Id)
{
- x->mass[i].forceX = atom_getfloatarg(1, argc, argv);
+ x->mass[i].posX = atom_getfloatarg(1, argc, argv);
+ x->mass[i].speedX = 0; // ??? TODO : esce la bonne chose a faire?
+ x->mass[i].forceX = 0; // ??? TODO : esce la bonne chose a faire?
+
+ }
+ }
+ }
+}
+
+void pmpd_overdamp(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+{
+// set the overdamped factor to a mass
+ t_int tmp, i;
+
+ 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_mass-1, tmp));
+ x->mass[tmp].overdamp = 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_mass; i++)
+ {
+ if ( atom_getsymbolarg(0,argc,argv) == x->mass[i].Id)
+ {
+ x->mass[i].overdamp = atom_getfloatarg(1, argc, argv);
+ }
+ }
+ }
+}
+
+void pmpd_setConnection1i(t_pmpd *x, int i, int j)
+{
+ x->link[i].mass1=&x->mass[max(0, min( x->nb_mass-1, j))];
+ x->link[i].distance = x->link[i].mass1->posX - x->link[i].mass2->posX;
+}
+
+void pmpd_setEnd1(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int tmp, i;
+
+ 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));
+ pmpd_setConnection1i(x,tmp,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 )
+ {
+ pmpd_setConnection1i(x,i,atom_getfloatarg(1, argc, argv));
+ }
+ }
+ }
+}
+
+void pmpd_setConnection2i(t_pmpd *x, int i, int j)
+{
+ x->link[i].mass2=&x->mass[max(0, min( x->nb_mass-1, j))];
+ x->link[i].distance = x->link[i].mass1->posX - x->link[i].mass2->posX;
+}
+
+void pmpd_setEnd2(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int tmp, i;
+
+ 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));
+ pmpd_setConnection2i(x,tmp,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 )
+ {
+ pmpd_setConnection2i(x,i,atom_getfloatarg(1, argc, argv));
}
}
}
}
+
+void pmpd_setConnectioni(t_pmpd *x, int i, int j, int k)
+{
+ x->link[i].mass1=&x->mass[max(0, min( x->nb_mass-1, j))];
+ x->link[i].mass2=&x->mass[max(0, min( x->nb_mass-1, k))];
+ x->link[i].distance = x->link[i].mass1->posX - x->link[i].mass2->posX;
+}
+
+void pmpd_setEnd(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int tmp, i;
+
+ if ( (argc == 3) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) && ( argv[2].a_type == A_FLOAT ) )
+ {
+ tmp = atom_getfloatarg(0, argc, argv);
+ tmp = max(0, min( x->nb_link-1, tmp));
+ pmpd_setConnectioni(x,tmp,atom_getfloatarg(1, argc, argv),atom_getfloatarg(2, argc, argv));
+
+ }
+ else if ( (argc == 3) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) && ( argv[2].a_type == A_FLOAT ) )
+ {
+ for (i=0; i< x->nb_link; i++)
+ {
+ if ( atom_getsymbolarg(0,argc,argv) == x->link[i].Id )
+ {
+ pmpd_setConnectioni(x,i,atom_getfloatarg(1, argc, argv),atom_getfloatarg(2, argc, argv));
+ }
+ }
+ }
+}
+