aboutsummaryrefslogtreecommitdiff
path: root/pmpd_tab.c
diff options
context:
space:
mode:
authorCyrille Henry <nusmuk@users.sourceforge.net>2013-05-01 15:03:05 +0000
committerCyrille Henry <nusmuk@users.sourceforge.net>2013-05-01 15:03:05 +0000
commit563967c7bb1b1b4eb0c09b757c4b2595d3aab97c (patch)
treebe443fcebfebe666f6b08b681ae36637b233112b /pmpd_tab.c
parenta81fa35c46071ea95f49056eb159a0dc1fe3ed12 (diff)
pmpd code refactorisation
svn path=/trunk/externals/pmpd/; revision=17105
Diffstat (limited to 'pmpd_tab.c')
-rw-r--r--pmpd_tab.c403
1 files changed, 403 insertions, 0 deletions
diff --git a/pmpd_tab.c b/pmpd_tab.c
new file mode 100644
index 0000000..bc3b4f1
--- /dev/null
+++ b/pmpd_tab.c
@@ -0,0 +1,403 @@
+void pmpd_massesPosT(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int i, j, vecsize;
+ t_garray *a;
+ t_word *vec;
+
+ if ( (argc==1) && (argv[0].a_type == A_SYMBOL) )
+ {
+ t_symbol *tab_name = atom_getsymbolarg(0, argc, argv);
+ if (!(a = (t_garray *)pd_findbyclass(tab_name, garray_class)))
+ pd_error(x, "%s: no such array", tab_name->s_name);
+ else if (!garray_getfloatwords(a, &vecsize, &vec))
+ pd_error(x, "%s: bad template for tabwrite", tab_name->s_name);
+ else
+ {
+ int taille_max = x->nb_mass;
+ taille_max = min(taille_max, vecsize);
+ for (i=0; i < taille_max ; i++)
+ {
+ vec[i].w_float = x->mass[i].posX;
+ }
+ garray_redraw(a);
+ }
+ }
+ else
+ if ( (argc==2) && (argv[0].a_type == A_SYMBOL) && (argv[1].a_type == A_SYMBOL) )
+ {
+ t_symbol *tab_name = atom_getsymbolarg(0, argc, argv);
+ if (!(a = (t_garray *)pd_findbyclass(tab_name, garray_class)))
+ pd_error(x, "%s: no such array", tab_name->s_name);
+ else if (!garray_getfloatwords(a, &vecsize, &vec))
+ pd_error(x, "%s: bad template for tabwrite", tab_name->s_name);
+ else
+ {
+ i = 0;
+ j = 0;
+ while ((i < vecsize) && (j < x->nb_mass))
+ {
+ if (atom_getsymbolarg(1,argc,argv) == x->mass[j].Id)
+ {
+ vec[i].w_float = x->mass[j].posX;
+ i++;
+ }
+ j++;
+ }
+ garray_redraw(a);
+ }
+ }
+}
+
+void pmpd_massesSpeedsT(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int i, j, vecsize;
+ t_garray *a;
+ t_word *vec;
+
+ if ( (argc==1) && (argv[0].a_type == A_SYMBOL) )
+ {
+ t_symbol *tab_name = atom_getsymbolarg(0, argc, argv);
+ if (!(a = (t_garray *)pd_findbyclass(tab_name, garray_class)))
+ pd_error(x, "%s: no such array", tab_name->s_name);
+ else if (!garray_getfloatwords(a, &vecsize, &vec))
+ pd_error(x, "%s: bad template for tabwrite", tab_name->s_name);
+ else
+ {
+ int taille_max = x->nb_mass;
+ taille_max = min(taille_max, vecsize);
+ for (i=0; i < taille_max ; i++)
+ {
+ vec[i].w_float = x->mass[i].speedX;
+ }
+ garray_redraw(a);
+ }
+ }
+ else
+ if ( (argc==2) && (argv[0].a_type == A_SYMBOL) && (argv[1].a_type == A_SYMBOL) )
+ {
+ t_symbol *tab_name = atom_getsymbolarg(0, argc, argv);
+ if (!(a = (t_garray *)pd_findbyclass(tab_name, garray_class)))
+ pd_error(x, "%s: no such array", tab_name->s_name);
+ else if (!garray_getfloatwords(a, &vecsize, &vec))
+ pd_error(x, "%s: bad template for tabwrite", tab_name->s_name);
+ else
+ {
+ i = 0;
+ j = 0;
+ while ((i < vecsize) && (j < x->nb_mass))
+ {
+ if (atom_getsymbolarg(1,argc,argv) == x->mass[j].Id)
+ {
+ vec[i].w_float = x->mass[j].speedX;
+ i++;
+ }
+ j++;
+ }
+ garray_redraw(a);
+ }
+ }
+}
+
+void pmpd_massesForcesT(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int i, j, vecsize;
+ t_garray *a;
+ t_word *vec;
+
+ if ( (argc==1) && (argv[0].a_type == A_SYMBOL) )
+ {
+ t_symbol *tab_name = atom_getsymbolarg(0, argc, argv);
+ if (!(a = (t_garray *)pd_findbyclass(tab_name, garray_class)))
+ pd_error(x, "%s: no such array", tab_name->s_name);
+ else if (!garray_getfloatwords(a, &vecsize, &vec))
+ pd_error(x, "%s: bad template for tabwrite", tab_name->s_name);
+ else
+ {
+ int taille_max = x->nb_mass;
+ taille_max = min(taille_max, vecsize);
+ for (i=0; i < taille_max ; i++)
+ {
+ vec[i].w_float = x->mass[i].forceX;
+ }
+ garray_redraw(a);
+ }
+ }
+ else
+ if ( (argc==2) && (argv[0].a_type == A_SYMBOL) && (argv[1].a_type == A_SYMBOL) )
+ {
+ t_symbol *tab_name = atom_getsymbolarg(0, argc, argv);
+ if (!(a = (t_garray *)pd_findbyclass(tab_name, garray_class)))
+ pd_error(x, "%s: no such array", tab_name->s_name);
+ else if (!garray_getfloatwords(a, &vecsize, &vec))
+ pd_error(x, "%s: bad template for tabwrite", tab_name->s_name);
+ else
+ {
+ i = 0;
+ j = 0;
+ while ((i < vecsize) && (j < x->nb_mass))
+ {
+ if (atom_getsymbolarg(1,argc,argv) == x->mass[j].Id)
+ {
+ vec[i].w_float = x->mass[j].forceX;
+ i++;
+ }
+ j++;
+ }
+ garray_redraw(a);
+ }
+ }
+}
+
+void pmpd_linksPosT(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int i, j, vecsize;
+ t_garray *a;
+ t_word *vec;
+
+ if ( (argc==1) && (argv[0].a_type == A_SYMBOL) )
+ {
+ t_symbol *tab_name = atom_getsymbolarg(0, argc, argv);
+ if (!(a = (t_garray *)pd_findbyclass(tab_name, garray_class)))
+ pd_error(x, "%s: no such array", tab_name->s_name);
+ else if (!garray_getfloatwords(a, &vecsize, &vec))
+ pd_error(x, "%s: bad template for tabwrite", tab_name->s_name);
+ else
+ {
+ int taille_max = x->nb_link;
+ taille_max = min(taille_max, vecsize);
+ for (i=0; i < taille_max ; i++)
+ {
+ vec[i].w_float = (x->link[i].mass1->posX + x->link[i].mass2->posX)/2;
+ }
+ garray_redraw(a);
+ }
+ }
+ else
+ if ( (argc==2) && (argv[0].a_type == A_SYMBOL) && (argv[1].a_type == A_SYMBOL) )
+ {
+ t_symbol *tab_name = atom_getsymbolarg(0, argc, argv);
+ if (!(a = (t_garray *)pd_findbyclass(tab_name, garray_class)))
+ pd_error(x, "%s: no such array", tab_name->s_name);
+ else if (!garray_getfloatwords(a, &vecsize, &vec))
+ pd_error(x, "%s: bad template for tabwrite", tab_name->s_name);
+ else
+ {
+ i = 0;
+ j = 0;
+ while ((i < vecsize) && (j < x->nb_link))
+ {
+ if (atom_getsymbolarg(1,argc,argv) == x->link[j].Id)
+ {
+ vec[i].w_float = (x->link[j].mass1->posX + x->link[j].mass2->posX)/2;
+ i++;
+ }
+ j++;
+ }
+ garray_redraw(a);
+ }
+ }
+}
+
+void pmpd_linksLengthT(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int i, j, vecsize;
+ t_garray *a;
+ t_word *vec;
+
+ if ( (argc==1) && (argv[0].a_type == A_SYMBOL) )
+ {
+ t_symbol *tab_name = atom_getsymbolarg(0, argc, argv);
+ if (!(a = (t_garray *)pd_findbyclass(tab_name, garray_class)))
+ pd_error(x, "%s: no such array", tab_name->s_name);
+ else if (!garray_getfloatwords(a, &vecsize, &vec))
+ pd_error(x, "%s: bad template for tabwrite", tab_name->s_name);
+ else
+ {
+ int taille_max = x->nb_link;
+ taille_max = min(taille_max, vecsize);
+ for (i=0; i < taille_max ; i++)
+ {
+ vec[i].w_float = x->link[i].mass2->posX - x->link[i].mass1->posX;
+ }
+ garray_redraw(a);
+ }
+ }
+ else
+ if ( (argc==2) && (argv[0].a_type == A_SYMBOL) && (argv[1].a_type == A_SYMBOL) )
+ {
+ t_symbol *tab_name = atom_getsymbolarg(0, argc, argv);
+ if (!(a = (t_garray *)pd_findbyclass(tab_name, garray_class)))
+ pd_error(x, "%s: no such array", tab_name->s_name);
+ else if (!garray_getfloatwords(a, &vecsize, &vec))
+ pd_error(x, "%s: bad template for tabwrite", tab_name->s_name);
+ else
+ {
+ i = 0;
+ j = 0;
+ while ((i < vecsize) && (j < x->nb_link))
+ {
+ if (atom_getsymbolarg(1,argc,argv) == x->link[j].Id)
+ {
+ vec[i].w_float = x->link[j].mass2->posX - x->link[j].mass1->posX;
+ i++;
+ }
+ j++;
+ }
+ garray_redraw(a);
+ }
+ }
+}
+
+void pmpd_linksPosSpeedT(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int i, j, vecsize;
+ t_garray *a;
+ t_word *vec;
+
+ if ( (argc==1) && (argv[0].a_type == A_SYMBOL) )
+ {
+ t_symbol *tab_name = atom_getsymbolarg(0, argc, argv);
+ if (!(a = (t_garray *)pd_findbyclass(tab_name, garray_class)))
+ pd_error(x, "%s: no such array", tab_name->s_name);
+ else if (!garray_getfloatwords(a, &vecsize, &vec))
+ pd_error(x, "%s: bad template for tabwrite", tab_name->s_name);
+ else
+ {
+ int taille_max = x->nb_link;
+ taille_max = min(taille_max, vecsize);
+ for (i=0; i < taille_max ; i++)
+ {
+ vec[i].w_float = (x->link[i].mass1->speedX + x->link[i].mass2->speedX)/2;
+ }
+ garray_redraw(a);
+ }
+ }
+ else
+ if ( (argc==2) && (argv[0].a_type == A_SYMBOL) && (argv[1].a_type == A_SYMBOL) )
+ {
+ t_symbol *tab_name = atom_getsymbolarg(0, argc, argv);
+ if (!(a = (t_garray *)pd_findbyclass(tab_name, garray_class)))
+ pd_error(x, "%s: no such array", tab_name->s_name);
+ else if (!garray_getfloatwords(a, &vecsize, &vec))
+ pd_error(x, "%s: bad template for tabwrite", tab_name->s_name);
+ else
+ {
+ i = 0;
+ j = 0;
+ while ((i < vecsize) && (j < x->nb_link))
+ {
+ if (atom_getsymbolarg(1,argc,argv) == x->link[j].Id)
+ {
+ vec[i].w_float = (x->link[j].mass1->speedX + x->link[j].mass2->speedX)/2;
+ i++;
+ }
+ j++;
+ }
+ garray_redraw(a);
+ }
+ }
+}
+
+void pmpd_linksLengthSpeedT(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int i, j, vecsize;
+ t_garray *a;
+ t_word *vec;
+
+ if ( (argc==1) && (argv[0].a_type == A_SYMBOL) )
+ {
+ t_symbol *tab_name = atom_getsymbolarg(0, argc, argv);
+ if (!(a = (t_garray *)pd_findbyclass(tab_name, garray_class)))
+ pd_error(x, "%s: no such array", tab_name->s_name);
+ else if (!garray_getfloatwords(a, &vecsize, &vec))
+ pd_error(x, "%s: bad template for tabwrite", tab_name->s_name);
+ else
+ {
+ int taille_max = x->nb_link;
+ taille_max = min(taille_max, vecsize);
+ for (i=0; i < taille_max ; i++)
+ {
+ vec[i].w_float = x->link[i].mass2->speedX - x->link[i].mass1->speedX;
+ }
+ garray_redraw(a);
+ }
+ }
+ else
+ if ( (argc==2) && (argv[0].a_type == A_SYMBOL) && (argv[1].a_type == A_SYMBOL) )
+ {
+ t_symbol *tab_name = atom_getsymbolarg(0, argc, argv);
+ if (!(a = (t_garray *)pd_findbyclass(tab_name, garray_class)))
+ pd_error(x, "%s: no such array", tab_name->s_name);
+ else if (!garray_getfloatwords(a, &vecsize, &vec))
+ pd_error(x, "%s: bad template for tabwrite", tab_name->s_name);
+ else
+ {
+ i = 0;
+ j = 0;
+ while ((i < vecsize) && (j < x->nb_link))
+ {
+ if (atom_getsymbolarg(1,argc,argv) == x->link[j].Id)
+ {
+ vec[i].w_float = x->link[j].mass2->speedX - x->link[j].mass1->speedX;
+ i++;
+ }
+ j++;
+ }
+ garray_redraw(a);
+ }
+ }
+}
+
+void pmpd_linksEndT(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int i, j, vecsize;
+ t_garray *a;
+ t_word *vec;
+
+ if ( (argc==1) && (argv[0].a_type == A_SYMBOL) )
+ {
+ t_symbol *tab_name = atom_getsymbolarg(0, argc, argv);
+ if (!(a = (t_garray *)pd_findbyclass(tab_name, garray_class)))
+ pd_error(x, "%s: no such array", tab_name->s_name);
+ else if (!garray_getfloatwords(a, &vecsize, &vec))
+ pd_error(x, "%s: bad template for tabwrite", tab_name->s_name);
+ else
+ {
+ int taille_max = x->nb_link;
+ taille_max = min(taille_max, (vecsize-1)/2);
+ for (i=0; i < taille_max ; i++)
+ {
+ vec[2*i ].w_float = x->link[i].mass1->posX;
+ vec[2*i+1].w_float = x->link[i].mass2->posX;
+ }
+ garray_redraw(a);
+ }
+ }
+ else
+ if ( (argc==2) && (argv[0].a_type == A_SYMBOL) && (argv[1].a_type == A_SYMBOL) )
+ {
+ t_symbol *tab_name = atom_getsymbolarg(0, argc, argv);
+ if (!(a = (t_garray *)pd_findbyclass(tab_name, garray_class)))
+ pd_error(x, "%s: no such array", tab_name->s_name);
+ else if (!garray_getfloatwords(a, &vecsize, &vec))
+ pd_error(x, "%s: bad template for tabwrite", tab_name->s_name);
+ else
+ {
+ i = 0;
+ j = 0;
+ while ((i < vecsize-1) && (j < x->nb_link))
+ {
+ if (atom_getsymbolarg(1,argc,argv) == x->link[j].Id)
+ {
+ vec[i].w_float = x->link[j].mass1->posX;
+ i++;
+ vec[i].w_float = x->link[j].mass2->posX;
+ i++;
+ }
+ j++;
+ }
+ garray_redraw(a);
+ }
+ }
+}
+