diff options
-rw-r--r-- | pmpd.c | 249 | ||||
-rw-r--r-- | pmpd.h | 3 | ||||
-rw-r--r-- | pmpd_get.c | 217 | ||||
-rw-r--r-- | pmpd_list.c | 223 | ||||
-rw-r--r-- | pmpd_set.c | 273 | ||||
-rw-r--r-- | pmpd_tab.c | 99 | ||||
-rw-r--r-- | pmpd_various.c | 135 |
7 files changed, 1107 insertions, 92 deletions
@@ -4,7 +4,8 @@ pmpd = physical modeling for pure data
Written by Cyrille Henry (ch@chnry.net)
-
+ with help from Nicolas Mongermont
+
Get sources on pd svn on sourceforge.
This program is free software; you can redistribute it and/or
@@ -32,107 +33,227 @@ #include "m_pd.h"
-
-
-
-
-
-
-
+#include "pmpd.h"
+#include "pmpd_core.c"
+#include "pmpd_set.c"
+#include "pmpd_get.c"
+#include "pmpd_list.c"
+#include "pmpd_tab.c"
+#include "pmpd_test.c"
+#include "pmpd_stat.c"
+#include "pmpd_various.c"
+#include "pmpd_deprecated.c"
void pmpd_setup(void)
{
pmpd_class = class_new(gensym("pmpd"),
(t_newmethod)pmpd_new,
0, sizeof(t_pmpd),CLASS_DEFAULT, 0);
-
+/*
+ pmpd_core
+ --
+ Basic functions for creation of the structure
+*/
class_addbang(pmpd_class, pmpd_bang);
class_addmethod(pmpd_class, (t_method)pmpd_reset, gensym("reset"), 0);
- class_addmethod(pmpd_class, (t_method)pmpd_infosL, gensym("infosL"), 0);
- class_addmethod(pmpd_class, (t_method)pmpd_infosL, gensym("print"), 0);
class_addmethod(pmpd_class, (t_method)pmpd_mass, gensym("mass"), A_DEFSYMBOL, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
class_addmethod(pmpd_class, (t_method)pmpd_link, gensym("link"), A_GIMME, 0);
class_addmethod(pmpd_class, (t_method)pmpd_tabLink, gensym("tabLink"), A_GIMME, 0);
+
+/*
+ pmpd_set
+ --
+ Functions to modify the internal state of the pmpd object
+*/
class_addmethod(pmpd_class, (t_method)pmpd_setK, gensym("setK"), A_GIMME, 0);
class_addmethod(pmpd_class, (t_method)pmpd_setD, gensym("setD"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_setD2, gensym("setDEnv"), A_GIMME, 0);
class_addmethod(pmpd_class, (t_method)pmpd_setL, gensym("setL"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_setLCurrent, gensym("setLCurrent"), A_GIMME, 0);
class_addmethod(pmpd_class, (t_method)pmpd_setLKTab, gensym("setLKTab"), A_GIMME, 0);
class_addmethod(pmpd_class, (t_method)pmpd_setLDTab, gensym("setLDTab"), A_GIMME, 0);
class_addmethod(pmpd_class, (t_method)pmpd_setLinkId, gensym("setLinkId"), A_GIMME, 0);
-
- class_addmethod(pmpd_class, (t_method)pmpd_setMassId, gensym("setMassId"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_setMassId, gensym("setMassId"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_setFixed, gensym("setFixed"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_setMobile, gensym("setMobile"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_setSpeedX, gensym("setSpeed"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_setSpeedX, gensym("setSpeedX"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_setForceX, gensym("setForce"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_setForceX, gensym("setForceX"), A_GIMME, 0);
class_addmethod(pmpd_class, (t_method)pmpd_posX, gensym("pos"), A_GIMME, 0);
class_addmethod(pmpd_class, (t_method)pmpd_posX, gensym("posX"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_posX, gensym("setPos"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_posX, gensym("setPosX"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_overdamp, gensym("setOverdamp"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_setEnd1, gensym("setEnd1"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_setEnd2, gensym("setEnd2"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_setEnd, gensym("setEnd"), A_GIMME, 0);
+
+/*
+ pmpd_get
+ --
+ Basic functions to output internal state of the object
+ Output syntax : 1 line by element (mass/link)
+*/
+ class_addmethod(pmpd_class, (t_method)pmpd_get, gensym("get"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_massPos, gensym("massPos"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_massSpeed, gensym("massSpeed"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_massForce, gensym("massForce"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linkPos, gensym("linkPos"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linkEnd, gensym("linkEnd"), A_GIMME, 0);
+
+/*
+ pmpd_list
+ --
+ Fucntions to output internal state of the object in lists
+ Output Syntax : 1 list with all elements
+*/
+
+ class_addmethod(pmpd_class, (t_method)pmpd_massPosXL, gensym("massPosL"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_massSpeedXL, gensym("massSpeedL"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_massForceXL, gensym("massForceL"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_massPosXL, gensym("massPosXL"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_massSpeedXL, gensym("massSpeedXL"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_massForceXL, gensym("massForceXL"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linkPosXL, gensym("linkPosL"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linkLengthXL, gensym("linkLengthL"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linkPosSpeedXL, gensym("linkPosSpeedL"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linkLengthSpeedXL, gensym("linkLengthSpeedL"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linkPosXL, gensym("linkPosXL"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linkLengthXL, gensym("linkLengthXL"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linkPosSpeedXL, gensym("linkPosSpeedXL"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linkLengthSpeedXL, gensym("linkLengthSpeedXL"), A_GIMME, 0);
+
+/*
+ pmpd_tab
+ --
+ Functions to copy the internal state of the object in arrays
+ Output Syntax : none
+*/
+ class_addmethod(pmpd_class, (t_method)pmpd_massesPosT, gensym("massesPosT"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_massesSpeedsT, gensym("massesSpeedsT"),A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_massesForcesT, gensym("massesForcesT"),A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_massesPosT, gensym("massesPosXT"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_massesSpeedsT, gensym("massesSpeedsXT"),A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_massesForcesT, gensym("massesForcesXT"),A_GIMME, 0);
+
+ class_addmethod(pmpd_class, (t_method)pmpd_massesPosT, gensym("massPosT"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_massesSpeedsT, gensym("massSpeedT"),A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_massesForcesT, gensym("massForceT"),A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_massesPosT, gensym("massPosXT"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_massesSpeedsT, gensym("massSpeedXT"),A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_massesForcesT, gensym("massForceXT"),A_GIMME, 0);
+
+ class_addmethod(pmpd_class, (t_method)pmpd_linksPosT, gensym("linksPosT"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linksLengthT, gensym("linksLengthT"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linksPosSpeedT, gensym("linksPosSpeedT"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linksLengthSpeedT, gensym("linksLengthSpeedT"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linksPosT, gensym("linksPosXT"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linksLengthT, gensym("linksLengthXT"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linksPosSpeedT, gensym("linksPosSpeedXT"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linksLengthSpeedT, gensym("linksLengthSpeedXT"), A_GIMME, 0);
+
+ class_addmethod(pmpd_class, (t_method)pmpd_linksPosT, gensym("linkPosT"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linksLengthT, gensym("linkLengthT"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linksPosSpeedT, gensym("linkPosSpeedT"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linksLengthSpeedT, gensym("linkLengthSpeedT"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linksPosT, gensym("linkPosXT"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linksLengthT, gensym("linkLengthXT"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linksPosSpeedT, gensym("linkPosSpeedXT"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linksLengthSpeedT, gensym("linkLengthSpeedXT"), A_GIMME, 0);
+
+ class_addmethod(pmpd_class, (t_method)pmpd_linksEndT, gensym("linksEndT"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linkEnd1T, gensym("linkEnd1T"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linkEnd2T, gensym("linkEnd2T"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linkEndT, gensym("linkEndXT"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linkEnd1T, gensym("linkEnd1XT"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linkEnd2T, gensym("linkEnd2XT"), A_GIMME, 0);
+
+/*
+ pmpd_test
+ --
+ Functions to list all elements that fit specific conditions
+ Output syntax : depends of the function
+*/
+ class_addmethod(pmpd_class, (t_method)pmpd_testMass, gensym("testMass"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_testLink, gensym("testLink"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_testMassT, gensym("testMassT"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_testLinkT, gensym("testLinkT"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_testMassL, gensym("testMassL"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_testLinkL, gensym("testLinkL"), A_GIMME, 0);
+
+/*
+ pmpd_stat
+ --
+ Functions to get global stats
+*/
+ class_addmethod(pmpd_class, (t_method)pmpd_massPosMean, gensym("massPosMean"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_massPosStd, gensym("massPosStd"),A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_massForceMean, gensym("massForecesMean"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_massForceStd, gensym("massForcesStd"),A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_massSpeedMean, gensym("massSpeedsMean"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_massSpeedStd, gensym("massSpeedsStd"),A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linkPosMean, gensym("linkPosMean"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linkLengthMean, gensym("linkLengthMean"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linkPosSpeedMean, gensym("linkPosSpeedMean"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linkLengthSpeedMean, gensym("linkLengthSpeedMean"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linkPosStd, gensym("linkPosStd"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linkLengthStd, gensym("linkLengthStd"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linkPosSpeedStd, gensym("linkPosSpeedStd"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linkLengthSpeedStd, gensym("linkLengthSpeedStd"), A_GIMME, 0);
+
+
+/*
+ pmpd_various
+ --
+ Others
+*/
+ class_addmethod(pmpd_class, (t_method)pmpd_infosL, gensym("infosL"), 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_infosL, gensym("print"), 0);
class_addmethod(pmpd_class, (t_method)pmpd_forceX, gensym("force"), A_GIMME, 0);
class_addmethod(pmpd_class, (t_method)pmpd_forceX, gensym("forceX"), A_GIMME, 0);
class_addmethod(pmpd_class, (t_method)pmpd_minX, gensym("Xmin"), A_DEFFLOAT, 0);
class_addmethod(pmpd_class, (t_method)pmpd_minX, gensym("min"), A_DEFFLOAT, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_minX, gensym("minX"), A_DEFFLOAT, 0);
class_addmethod(pmpd_class, (t_method)pmpd_maxX, gensym("Xmax"), A_DEFFLOAT, 0);
class_addmethod(pmpd_class, (t_method)pmpd_maxX, gensym("max"), A_DEFFLOAT, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_setFixed, gensym("setFixed"), A_GIMME, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_setMobile, gensym("setMobile"), A_GIMME, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_setD2, gensym("setDEnv"), A_GIMME, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_setSpeedX, gensym("setSpeed"), A_GIMME, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_setSpeedX, gensym("setSpeedX"), A_GIMME, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_setForceX, gensym("setForce"), A_GIMME, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_setForceX, gensym("setForceX"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_maxX, gensym("maxX"), A_DEFFLOAT, 0);
+
class_addmethod(pmpd_class, (t_method)pmpd_addPosX, gensym("addPos"), A_GIMME, 0);
class_addmethod(pmpd_class, (t_method)pmpd_addPosX, gensym("addPosX"), A_GIMME, 0);
-
- class_addmethod(pmpd_class, (t_method)pmpd_get, gensym("get"), A_GIMME, 0);
-
+
+ class_addmethod(pmpd_class, (t_method)pmpd_grabMass, gensym("grabMass"), A_DEFFLOAT, A_DEFFLOAT, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_closestMass, gensym("closestMass"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_massDistances, gensym("massDistance"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_forcesXT, gensym("forceXT"), A_GIMME, 0);
+
+/*
+ pmpd_deprecated
+ --
+ Functions in which the output selector has been modified
+ It is now the same as the input slector : all singular
+*/
class_addmethod(pmpd_class, (t_method)pmpd_massesPosL, gensym("massesPosL"), 0);
class_addmethod(pmpd_class, (t_method)pmpd_massesSpeedsL, gensym("massesSpeedsL"), 0);
class_addmethod(pmpd_class, (t_method)pmpd_massesForcesL, gensym("massesForcesL"), 0);
- class_addmethod(pmpd_class, (t_method)pmpd_massesPosT, gensym("massesPosT"), A_GIMME, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_massesSpeedsT, gensym("massesSpeedsT"),A_GIMME, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_massesForcesT, gensym("massesForcesT"),A_GIMME, 0);
-
class_addmethod(pmpd_class, (t_method)pmpd_massesPosL, gensym("massesPosXL"), 0);
class_addmethod(pmpd_class, (t_method)pmpd_massesSpeedsL, gensym("massesSpeedsXL"), 0);
class_addmethod(pmpd_class, (t_method)pmpd_massesForcesL, gensym("massesForcesXL"), 0);
- class_addmethod(pmpd_class, (t_method)pmpd_massesPosT, gensym("massesPosXT"), A_GIMME, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_massesSpeedsT, gensym("massesSpeedsXT"),A_GIMME, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_massesForcesT, gensym("massesForcesXT"),A_GIMME, 0);
-
+
+ class_addmethod(pmpd_class, (t_method)pmpd_linksPosL, gensym("linksPosL"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linksLengthL, gensym("linksLengthL"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linksPosSpeedL, gensym("linksPosSpeedL"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linksLengthSpeedL, gensym("linksLengthSpeedL"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linksPosL, gensym("linksPosXL"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linksLengthL, gensym("linksLengthXL"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linksPosSpeedL, gensym("linksPosSpeedXL"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_linksLengthSpeedL, gensym("linksLengthSpeedXL"), A_GIMME, 0);
+
class_addmethod(pmpd_class, (t_method)pmpd_massesPosMean, gensym("massesPosMean"), A_GIMME, 0);
class_addmethod(pmpd_class, (t_method)pmpd_massesPosStd, gensym("massesPosStd"),A_GIMME, 0);
class_addmethod(pmpd_class, (t_method)pmpd_massesForcesMean,gensym("massesForcesMean"), A_GIMME, 0);
class_addmethod(pmpd_class, (t_method)pmpd_massesForcesStd, gensym("massesForcesStd"),A_GIMME, 0);
class_addmethod(pmpd_class, (t_method)pmpd_massesSpeedsMean,gensym("massesSpeedsMean"), A_GIMME, 0);
class_addmethod(pmpd_class, (t_method)pmpd_massesSpeedsStd, gensym("massesSpeedsStd"),A_GIMME, 0);
-
- class_addmethod(pmpd_class, (t_method)pmpd_linksPosL, gensym("linksPosXL"), A_GIMME, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_linksLengthL, gensym("linksLengthXL"), A_GIMME, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_linksPosSpeedL, gensym("linksPosSpeedXL"), A_GIMME, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_linksLengthSpeedL, gensym("linksLengthSpeedXL"), A_GIMME, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_linksPosT, gensym("linksPosXT"), A_GIMME, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_linksLengthT, gensym("linksLengthXT"), A_GIMME, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_linksPosSpeedT, gensym("linksPosSpeedXT"), A_GIMME, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_linksLengthSpeedT, gensym("linksLengthSpeedXT"), A_GIMME, 0);
-
- class_addmethod(pmpd_class, (t_method)pmpd_linksPosL, gensym("linksPosL"), A_GIMME, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_linksLengthL, gensym("linksLengthL"), A_GIMME, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_linksPosSpeedL, gensym("linksPosSpeedL"), A_GIMME, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_linksLengthSpeedL, gensym("linksLengthSpeedL"), A_GIMME, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_linksPosT, gensym("linksPosT"), A_GIMME, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_linksLengthT, gensym("linksLengthT"), A_GIMME, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_linksPosSpeedT, gensym("linksPosSpeedT"), A_GIMME, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_linksLengthSpeedT, gensym("linksLengthSpeedT"), A_GIMME, 0);
-
- class_addmethod(pmpd_class, (t_method)pmpd_linksEndT, gensym("linksEndT"), A_GIMME, 0);
-
-/* class_addmethod(pmpd_class, (t_method)pmpd_linksPosMean, gensym("linksPosMean"), A_GIMME, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_linksLengthMean, gensym("linksLengthMean"), A_GIMME, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_linksPosSpeedMean, gensym("linksPosSpeedMean"), A_GIMME, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_linksLengthSpeedMean, gensym("linksLengthSpeedMean"), A_GIMME, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_linksPosStd, gensym("linksPosStd"), A_GIMME, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_linksLengthStd, gensym("linksLengthStd"), A_GIMME, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_linksPosSpeedStd, gensym("linksPosSpeedStd"), A_GIMME, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_linksLengthSpeedStd0, gensym("linksLengthSpeedStd"), A_GIMME, 0);
-*/
-
- class_addmethod(pmpd_class, (t_method)pmpd_grabMass, gensym("grabMass"), A_DEFFLOAT, A_DEFFLOAT, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_closestMass, gensym("closestMass"), A_GIMME, 0);
}
@@ -19,6 +19,7 @@ typedef struct _mass { t_float posX; t_float forceX; t_float D2; + t_float overdamp; int num; } foo; @@ -27,6 +28,7 @@ typedef struct _link { int lType; struct _mass *mass1; struct _mass *mass2; + t_int active; t_float K; t_float D; t_float L; @@ -38,6 +40,7 @@ typedef struct _link { t_symbol *arrayD; t_float K_L; // longeur du tabeau K t_float D_L; // longeur du tabeau D + t_float forceX; } foo1 ; typedef struct _pmpd { @@ -286,3 +286,220 @@ void pmpd_get(t_pmpd *x, t_symbol *s, int argc, t_atom *argv) error("not get attribute"); } +void pmpd_massPos(t_pmpd *x, t_symbol *s, int argc, t_atom *argv) +{ + int i; + t_atom toout[3]; + + if ((argc>0)&&(argv[0].a_type == A_FLOAT)) + { + i = atom_getfloatarg(0, argc, argv); + if ( (i>=0) && (i<x->nb_mass) ) + { + SETSYMBOL(&(toout[0]), x->mass[i].Id); + SETFLOAT(&(toout[1]), i); + SETFLOAT(&(toout[2]), x->mass[i].posX); + outlet_anything(x->main_outlet, gensym("massPos"), 3, toout); + } + } + else + if ((argc>0)&&(argv[0].a_type == A_SYMBOL)) + { + for (i=0; i< x->nb_mass; i++) + { + SETSYMBOL(&(toout[0]), atom_getsymbolarg(0,argc,argv)); + if ( atom_getsymbolarg(0,argc,argv) == x->mass[i].Id) + { + SETFLOAT(&(toout[1]), i); + SETFLOAT(&(toout[2]), x->mass[i].posX); + outlet_anything(x->main_outlet, gensym("massPos"), 3, toout); + } + } + } + else + if (argc == 0) + { + for (i=0; i< x->nb_mass; i++) + { + SETSYMBOL(&(toout[0]), x->mass[i].Id); + SETFLOAT(&(toout[1]), i); + SETFLOAT(&(toout[2]), x->mass[i].posX); + outlet_anything(x->main_outlet, gensym("massPos"), 3, toout); + } + } +} + +void pmpd_massSpeed(t_pmpd *x, t_symbol *s, int argc, t_atom *argv) +{ + int i; + t_atom toout[3]; + + if ((argc>0)&&(argv[0].a_type == A_FLOAT)) + { + i = atom_getfloatarg(0, argc, argv); + if ( (i>=0) && (i<x->nb_mass) ) + { + SETSYMBOL(&(toout[0]), x->mass[i].Id); + SETFLOAT(&(toout[1]), i); + SETFLOAT(&(toout[2]), x->mass[i].speedX); + outlet_anything(x->main_outlet, gensym("massSpeed"), 3, toout); + } + } + else + if ((argc>0)&&(argv[0].a_type == A_SYMBOL)) + { + for (i=0; i< x->nb_mass; i++) + { + SETSYMBOL(&(toout[0]), atom_getsymbolarg(0,argc,argv)); + if ( atom_getsymbolarg(0,argc,argv) == x->mass[i].Id) + { + SETFLOAT(&(toout[1]), i); + SETFLOAT(&(toout[2]), x->mass[i].speedX); + outlet_anything(x->main_outlet, gensym("massSpeed"), 3, toout); + } + } + } + else + if (argc == 0) + { + for (i=0; i< x->nb_mass; i++) + { + SETSYMBOL(&(toout[0]), x->mass[i].Id); + SETFLOAT(&(toout[1]), i); + SETFLOAT(&(toout[2]), x->mass[i].speedX); + outlet_anything(x->main_outlet, gensym("massSpeed"), 3, toout); + } + } +} + +void pmpd_massForce(t_pmpd *x, t_symbol *s, int argc, t_atom *argv) +{ + int i; + t_atom toout[3]; + + if ((argc>0)&&(argv[0].a_type == A_FLOAT)) + { + i = atom_getfloatarg(0, argc, argv); + if ( (i>=0) && (i<x->nb_mass) ) + { + SETSYMBOL(&(toout[0]), x->mass[i].Id); + SETFLOAT(&(toout[1]), i); + SETFLOAT(&(toout[2]), x->mass[i].forceX); + outlet_anything(x->main_outlet, gensym("massForce"), 3, toout); + } + } + else + if ((argc>0)&&(argv[0].a_type == A_SYMBOL)) + { + for (i=0; i< x->nb_mass; i++) + { + SETSYMBOL(&(toout[0]), atom_getsymbolarg(0,argc,argv)); + if ( atom_getsymbolarg(0,argc,argv) == x->mass[i].Id) + { + SETFLOAT(&(toout[1]), i); + SETFLOAT(&(toout[2]), x->mass[i].forceX); + outlet_anything(x->main_outlet, gensym("massForce"), 3, toout); + } + } + } + else + if (argc == 0) + { + for (i=0; i< x->nb_mass; i++) + { + SETSYMBOL(&(toout[0]), x->mass[i].Id); + SETFLOAT(&(toout[1]), i); + SETFLOAT(&(toout[2]), x->mass[i].forceX); + outlet_anything(x->main_outlet, gensym("massForce"), 3, toout); + } + } +} + +void pmpd_linkEnd(t_pmpd *x, t_symbol *s, int argc, t_atom *argv) +{ + int i; + t_atom toout[4]; + + if ((argc>0)&&(argv[0].a_type == A_FLOAT)) + { + i = atom_getfloatarg(0, argc, argv); + if ( (i>=0) && (i<x->nb_link) ) + { + SETSYMBOL(&(toout[0]), x->link[i].Id); + SETFLOAT(&(toout[1]), i); + SETFLOAT(&(toout[2]), x->link[i].mass1->posX); + SETFLOAT(&(toout[3]), x->link[i].mass2->posX); + outlet_anything(x->main_outlet, gensym("linkEnd"), 4, toout); + } + } + else + if ((argc>0)&&(argv[0].a_type == A_SYMBOL)) + { + SETSYMBOL(&(toout[0]), atom_getsymbolarg(0,argc,argv)); + for (i=0; i< x->nb_link; i++) + { + if ( atom_getsymbolarg(0,argc,argv) == x->link[i].Id) + { + SETFLOAT(&(toout[1]), i); + SETFLOAT(&(toout[2]), x->link[i].mass1->posX); + SETFLOAT(&(toout[3]), x->link[i].mass2->posX); + outlet_anything(x->main_outlet, gensym("linkEnd"), 4, toout); + } + } + } + else + if (argc == 0) + { + for (i=0; i< x->nb_link; i++) + { + SETSYMBOL(&(toout[0]), x->link[i].Id); + SETFLOAT(&(toout[1]), i); + SETFLOAT(&(toout[2]), x->link[i].mass1->posX); + SETFLOAT(&(toout[3]), x->link[i].mass2->posX); + outlet_anything(x->main_outlet, gensym("linkEnd"), 4, toout); + } + } +} + +void pmpd_linkPos(t_pmpd *x, t_symbol *s, int argc, t_atom *argv) +{ + int i; + t_atom toout[3]; + + if ((argc>0)&&(argv[0].a_type == A_FLOAT)) + { + i = atom_getfloatarg(0, argc, argv); + if ( (i>=0) && (i<x->nb_link) ) + { + SETSYMBOL(&(toout[0]), x->link[i].Id); + SETFLOAT(&(toout[1]), i); + SETFLOAT(&(toout[2]), (x->link[i].mass1->posX+x->link[i].mass2->posX)/2); + outlet_anything(x->main_outlet, gensym("linkPos"), 3, toout); + } + } + else + if ((argc>0)&&(argv[0].a_type == A_SYMBOL)) + { + SETSYMBOL(&(toout[0]), atom_getsymbolarg(0,argc,argv)); + for (i=0; i< x->nb_link; i++) + { + if ( atom_getsymbolarg(0,argc,argv) == x->link[i].Id) + { + SETFLOAT(&(toout[1]), i); + SETFLOAT(&(toout[2]), (x->link[i].mass1->posX+x->link[i].mass2->posX)/2); + outlet_anything(x->main_outlet, gensym("linkPos"), 3, toout); + } + } + } + else + if (argc == 0) + { + for (i=0; i< x->nb_link; i++) + { + SETSYMBOL(&(toout[0]), x->link[i].Id); + SETFLOAT(&(toout[1]), i); + SETFLOAT(&(toout[2]), (x->link[i].mass1->posX+x->link[i].mass2->posX)/2); + outlet_anything(x->main_outlet, gensym("linkPos"), 3, toout); + } + } +} diff --git a/pmpd_list.c b/pmpd_list.c index e69de29..7ede167 100644 --- a/pmpd_list.c +++ b/pmpd_list.c @@ -0,0 +1,223 @@ +void pmpd_massPosXL(t_pmpd *x, t_symbol *s, int argc, t_atom *argv) +{ + int i,j; + t_atom pos_list[x->nb_mass]; + + if (argc==0) + { + for (i=0; i < x->nb_mass; i++) + { + SETFLOAT(&(pos_list[i]),x->mass[i].posX); + } + outlet_anything(x->main_outlet, gensym("massPosXL"),x->nb_mass , pos_list); + } + else if ((argc==1) && (argv[0].a_type == A_SYMBOL)) + { + i = 0; + j = 0; + while (j < x->nb_mass) + { + if (atom_getsymbolarg(0,argc,argv) == x->mass[j].Id) + { + SETFLOAT(&(pos_list[i]),x->mass[i].posX); + i++; + } + j++; + } + outlet_anything(x->main_outlet, gensym("massPosXL"),i , pos_list); + } + else if ((argc==1) && (argv[0].a_type == A_FLOAT)) + { + SETFLOAT(&(pos_list[0]),x->mass[(int)atom_getfloatarg(0, argc, argv)].posX); + outlet_anything(x->main_outlet, gensym("massPosXL"),1 , pos_list); + } +} + +void pmpd_massForceXL(t_pmpd *x, t_symbol *s, int argc, t_atom *argv) +{ + int i,j; + t_atom pos_list[x->nb_mass]; + + if (argc==0) + { + for (i=0; i< x->nb_mass; i++) + { + SETFLOAT(&(pos_list[i]),x->mass[i].forceX); + } + outlet_anything(x->main_outlet, gensym("massForceXL"),x->nb_mass , pos_list); + } + else if ((argc==1) && (argv[0].a_type == A_SYMBOL)) + { + i = 0; + j = 0; + while (j < x->nb_mass) + { + if (atom_getsymbolarg(0,argc,argv) == x->mass[j].Id) + { + SETFLOAT(&(pos_list[i]),x->mass[j].forceX); + i++; + } + j++; + } + outlet_anything(x->main_outlet, gensym("massForceXL"),i , pos_list); + } + else if ((argc==1) && (argv[0].a_type == A_FLOAT)) + { + SETFLOAT(&(pos_list[0]),x->mass[(int)atom_getfloatarg(0, argc, argv)].forceX); + outlet_anything(x->main_outlet, gensym("massForceXL"),1 , pos_list); + } +} + +void pmpd_massSpeedXL(t_pmpd *x, t_symbol *s, int argc, t_atom *argv) +{ + int i,j; + t_atom pos_list[x->nb_mass]; + + if (argc==0) + { + for (i=0; i< x->nb_mass; i++) + { + SETFLOAT(&(pos_list[i]),x->mass[i].speedX); + } + outlet_anything(x->main_outlet, gensym("massSpeedXL"),x->nb_mass , pos_list); + } + else if ((argc==1) && (argv[0].a_type == A_SYMBOL)) + { + i = 0; + j = 0; + while (j < x->nb_mass) + { + if (atom_getsymbolarg(0,argc,argv) == x->mass[j].Id) + { + SETFLOAT(&(pos_list[i]),x->mass[j].speedX); + i++; + } + j++; + } + outlet_anything(x->main_outlet, gensym("massSpeedXL"),i , pos_list); + } + else if ((argc==1) && (argv[0].a_type == A_FLOAT)) + { + SETFLOAT(&(pos_list[0]),x->mass[(int)atom_getfloatarg(0, argc, argv)].speedX); + outlet_anything(x->main_outlet, gensym("massSpeedXL"),1 , pos_list); + } +} + +// --------------------------------------------------------------------- + +void pmpd_linkPosXL(t_pmpd *x, t_symbol *s, int argc, t_atom *argv) +{ + int i,j; + t_atom pos_list[x->nb_link]; + + if (argc==0) + { + for (i=0; i < x->nb_link; i++) + { + SETFLOAT(&(pos_list[i]),(x->link[i].mass1->posX + x->link[i].mass2->posX)/2); + } + outlet_anything(x->main_outlet, gensym("linkPosXL"),x->nb_link , pos_list); + } + else + if ( (argc==1) && (argv[0].a_type == A_SYMBOL) ) + { + j=0; + for (i=0; i < x->nb_link; i++) + { + if (atom_getsymbolarg(0,argc,argv) == x->link[i].Id) + { + SETFLOAT(&(pos_list[j]),(x->link[i].mass1->posX + x->link[i].mass2->posX)/2); + j++; + } + } + outlet_anything(x->main_outlet, gensym("linkPosXL"),j , pos_list); + } +} + +void pmpd_linkLengthXL(t_pmpd *x, t_symbol *s, int argc, t_atom *argv) +{ + int i,j; + t_atom pos_list[x->nb_link]; + + if (argc==0) + { + for (i=0; i < x->nb_link; i++) + { + SETFLOAT(&(pos_list[i]),x->link[i].mass2->posX - x->link[i].mass1->posX); + } + outlet_anything(x->main_outlet, gensym("linkLengthXL"),x->nb_link , pos_list); + } + else + if ( (argc==1) && (argv[0].a_type == A_SYMBOL) ) + { + j=0; + for (i=0; i < x->nb_link; i++) + { + if (atom_getsymbolarg(0,argc,argv) == x->link[i].Id) + { + SETFLOAT(&(pos_list[j]),x->link[i].mass2->posX - x->link[i].mass1->posX); + j++; + } + } + outlet_anything(x->main_outlet, gensym("linkLengthXL"),j , pos_list); + } +} + +void pmpd_linkPosSpeedXL(t_pmpd *x, t_symbol *s, int argc, t_atom *argv) +{ + int i,j; + t_atom pos_list[x->nb_link]; + + if (argc==0) + { + for (i=0; i < x->nb_link; i++) + { + SETFLOAT(&(pos_list[i]),(x->link[i].mass1->speedX + x->link[i].mass2->speedX)/2); + } + outlet_anything(x->main_outlet, gensym("linkPosSpeedXL"),x->nb_link , pos_list); + } + else + if ( (argc==1) && (argv[0].a_type == A_SYMBOL) ) + { + j=0; + for (i=0; i < x->nb_link; i++) + { + if (atom_getsymbolarg(0,argc,argv) == x->link[i].Id) + { + SETFLOAT(&(pos_list[j]),(x->link[i].mass1->speedX + x->link[i].mass2->speedX)/2); + j++; + } + } + outlet_anything(x->main_outlet, gensym("linkPosSpeedXL"),j , pos_list); + } +} + +void pmpd_linkLengthSpeedXL(t_pmpd *x, t_symbol *s, int argc, t_atom *argv) +{ + int i,j; + t_atom pos_list[x->nb_link]; + + if (argc==0) + { + for (i=0; i < x->nb_link; i++) + { + SETFLOAT(&(pos_list[i]),x->link[i].mass2->speedX - x->link[i].mass1->speedX); + } + outlet_anything(x->main_outlet, gensym("linkLengthSpeedXL"), x->nb_link, pos_list); + } + else + if ( (argc==1) && (argv[0].a_type == A_SYMBOL) ) + { + j=0; + for (i=0; i < x->nb_link; i++) + { + if (atom_getsymbolarg(0,argc,argv) == x->link[i].Id) + { + SETFLOAT(&(pos_list[j]),x->link[i].mass2->speedX - x->link[i].mass1->speedX); + j++; + } + } + outlet_anything(x->main_outlet, gensym("linkLengthSpeedXL"), j, pos_list); + } +} + @@ -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)); + } + } + } +} + @@ -401,3 +401,102 @@ void pmpd_linksEndT(t_pmpd *x, t_symbol *s, int argc, t_atom *argv) } } +void pmpd3d_linkEnd1T(t_pmpd3d *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; + } + 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-2) && (j < x->nb_link)) + { + if (atom_getsymbolarg(1,argc,argv) == x->link[j].Id) + { + vec[i].w_float = x->link[j].mass1->posX; + i++; + } + j++; + } + garray_redraw(a); + } + } +} + +void pmpd3d_linkEnd2T(t_pmpd3d *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; + } + 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-2) && (j < x->nb_link)) + { + if (atom_getsymbolarg(1,argc,argv) == x->link[j].Id) + { + vec[i].w_float = x->link[j].mass2->posX; + i++; + } + j++; + } + garray_redraw(a); + } + } +} diff --git a/pmpd_various.c b/pmpd_various.c index e6b2dfc..c31041a 100644 --- a/pmpd_various.c +++ b/pmpd_various.c @@ -158,3 +158,138 @@ void pmpd_closestMass(t_pmpd *x, t_symbol *s, int argc, t_atom *argv) outlet_anything(x->main_outlet, gensym("closestMass"),2,std_out); } +void pmpd_massDistances_f_f(t_pmpd *x, t_int i, t_int j) +{ + t_float dist, tmp; + t_atom to_out[3]; + + dist = x->mass[i].posX - x->mass[j].posX; + + SETFLOAT(&(to_out[0]), i); + SETFLOAT(&(to_out[1]), j); + SETFLOAT(&(to_out[2]), dist); + outlet_anything(x->main_outlet, gensym("distance"), 3, to_out); +} + +void pmpd_massDistances(t_pmpd *x, t_symbol *s, int argc, t_atom *argv) +{ + t_int i,j; + + if ( (argc == 2) && (argv[0].a_type == A_FLOAT) && (argv[1].a_type == A_FLOAT) ) + { + pmpd_massDistances_f_f(x, atom_getfloatarg(0, argc, argv), atom_getfloatarg(1, argc, argv)); + } + else if ( (argc == 2) && (argv[0].a_type == A_FLOAT) && (argv[1].a_type == A_SYMBOL) ) + { + for (i=0; i < x->nb_mass; i++) + { + if ( atom_getsymbolarg(1,argc,argv) == x->mass[i].Id) + { + pmpd_massDistances_f_f(x, atom_getfloatarg(0, argc, argv), i); + } + } + } + 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) ) + { + pmpd_massDistances_f_f(x, atom_getfloatarg(1, argc, argv), i); + } + } + } + else if ( (argc == 2) && (argv[0].a_type == A_SYMBOL) && (argv[1].a_type == A_SYMBOL) ) + { + for (i=0; i < x->nb_mass; i++) + { + if ( atom_getsymbolarg(0,argc,argv) == x->mass[i].Id) + { + for (j=i+1; j < x->nb_mass; j++) + { + if ( atom_getsymbolarg(1,argc,argv) == x->mass[j].Id) + { + pmpd_massDistances_f_f(x,i, j); + } + } + } + } + } + else if (argc == 0) + { + for (i=0; i < x->nb_mass; i++) + { + for (j=i+1; j < x->nb_mass; j++) + { + pmpd_massDistances_f_f(x,i, j); + } + } + } + else if ((argc == 1) && (argv[0].a_type == A_SYMBOL) ) + { + for (i=0; i < x->nb_mass; i++) + { + if ( atom_getsymbolarg(0,argc,argv) == x->mass[i].Id) + { + for (j=i+1; j < x->nb_mass; j++) + { + pmpd_massDistances_f_f(x,i, j); + } + } + } + } + else if ( (argc == 1) && (argv[0].a_type == A_FLOAT) ) + { + for (i=0; i < x->nb_mass; i++) + { + pmpd_massDistances_f_f(x, atom_getfloatarg(0, argc, argv), i); + } + } +} + + +void pmpd_forcesXT(t_pmpd *x, t_symbol *s, int argc, t_atom *argv) +{ +// add forces to masses. forces comes from a table, masse can be filter on ther Id or not + + t_int i, j; + t_garray *a; + int npoints; + t_word *vec; + t_symbol *array; + + if ( ( argc > 0 ) && (argv[0].a_type == A_SYMBOL )) + { + array = atom_getsymbolarg(0,argc,argv); + if (!(a = (t_garray *)pd_findbyclass(array, garray_class))) + pd_error(x, "%s: no such array", array->s_name); + else if (!garray_getfloatwords(a, &npoints, &vec)) + pd_error(x, "%s: bad template for tabLink", array->s_name); + else + { + if ( argc == 1 ) // apply forces on all masses + { + j = min(x->nb_mass, npoints); + for (i=0; i< j; i++) + { + x->mass[i].forceX += vec[i].w_float; + } + } + else if (( argc > 1 ) && ( argv[1].a_type == A_SYMBOL )) + { + i=0; + j=0; + + while ( (i < x->nb_mass) && (j < npoints) ) + { + if ( atom_getsymbolarg(1,argc,argv) == x->mass[i].Id) + { + x->mass[i].forceX += vec[j].w_float; + j++; + } + i++; + } + } + } + } +} |