aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--examples/51_string~.pd106
-rw-r--r--pmpd-help.pd388
-rw-r--r--pmpd.c913
4 files changed, 814 insertions, 595 deletions
diff --git a/Makefile b/Makefile
index d5b0df6..fcb9e87 100644
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@ LIBRARY_NAME = pmpd
# add your .c source files, one object per file, to the SOURCES
# variable, help files will be included automatically
-SOURCES = iAmbient2D.c iAmbient3D.c iCircle2D.c iCircle3D.c iCylinder3D.c iLine2D.c iPlane3D.c iSeg2D.c iSphere3D.c link.c link2D.c link3D.c mass.c mass2D.c mass3D.c pmpd~.c tCircle2D.c tCircle3D.c tCube3D.c tCylinder3D.c tLine2D.c tLink2D.c tLink3D.c tPlane3D.c tSeg2D.c tSphere3D.c tSquare2D.c
+SOURCES = iAmbient2D.c iAmbient3D.c iCircle2D.c iCircle3D.c iCylinder3D.c iLine2D.c iPlane3D.c iSeg2D.c iSphere3D.c link.c link2D.c link3D.c mass.c mass2D.c mass3D.c pmpd.c pmpd~.c tCircle2D.c tCircle3D.c tCube3D.c tCylinder3D.c tLine2D.c tLink2D.c tLink3D.c tPlane3D.c tSeg2D.c tSphere3D.c tSquare2D.c
# list all pd objects (i.e. myobject.pd) files here, and their helpfiles will
# be included automatically
diff --git a/examples/51_string~.pd b/examples/51_string~.pd
index 804c7bc..89411f1 100644
--- a/examples/51_string~.pd
+++ b/examples/51_string~.pd
@@ -1,4 +1,4 @@
-#N canvas 423 238 487 445 10;
+#N canvas 421 245 487 445 10;
#X floatatom 32 12 0 0 0 0 - - -;
#N canvas 0 0 454 304 cpu 0;
#X obj 61 159 cputime;
@@ -30,89 +30,67 @@
#X array array99 3000 float 0;
#X coords 0 1 2999 -1 150 100 1;
#X restore 49 257 graph;
-#N canvas 0 0 531 530 corde 0;
+#N canvas 1 82 531 530 corde 0;
#X obj 86 32 t b b b b;
#X msg 143 71 reset;
#X obj 92 4 inlet;
-#X obj 141 409 outlet;
-#X obj 72 270 pack f f;
-#X obj 83 200 t f f;
-#X obj 108 223 + 1;
+#X obj 155 479 outlet;
+#X obj 82 347 pack f f;
+#X obj 93 277 t f f;
+#X obj 118 300 + 1;
#X text 254 75 number of masss on the string;
-#X obj 144 220 + 1;
+#X obj 158 290 + 1;
#X obj 104 112 + 1;
-#N canvas 0 0 454 304 uzi 0;
-#X obj 70 50 inlet;
-#X obj 70 154 f;
-#X obj 95 129 + 1;
-#X msg 67 103 0;
-#X obj 71 199 moses;
-#X obj 69 74 t b f;
-#X obj 71 232 outlet;
-#X connect 0 0 5 0;
-#X connect 1 0 4 0;
-#X connect 2 0 1 0;
-#X connect 3 0 1 0;
-#X connect 4 0 2 0;
-#X connect 4 0 6 0;
-#X connect 5 0 3 0;
-#X connect 5 1 4 1;
-#X restore 83 160 pd uzi;
-#N canvas 0 0 454 304 uzi 0;
-#X obj 70 50 inlet;
-#X obj 70 154 f;
-#X obj 95 129 + 1;
-#X msg 67 103 0;
-#X obj 71 199 moses;
-#X obj 69 74 t b f;
-#X obj 71 232 outlet;
-#X connect 0 0 5 0;
-#X connect 1 0 4 0;
-#X connect 2 0 1 0;
-#X connect 3 0 1 0;
-#X connect 4 0 2 0;
-#X connect 4 0 6 0;
-#X connect 5 0 3 0;
-#X connect 5 1 4 1;
-#X restore 138 156 pd uzi;
#X obj 137 127 20;
#X obj 86 136 21;
-#X obj 109 244 % 21;
+#X obj 119 321 % 21;
#X msg 221 78 50;
#X msg 149 181 mass 20 1;
-#X msg 69 297 link \$1 \$2 0.1 0.03;
-#X msg 204 360 inForce 0 3 1;
-#X msg 206 332 outPos 0 7 1;
-#X connect 0 0 19 0;
-#X connect 0 0 18 0;
-#X connect 0 1 13 0;
-#X connect 0 2 12 0;
+#X msg 83 367 link \$1 \$2 0.1 0.03;
+#X msg 218 430 inForce 0 3 1;
+#X msg 220 402 outPos 0 7 1;
+#X obj 138 156 until;
+#X obj 83 160 t f b;
+#X msg 108 180 0;
+#X obj 82 207 until;
+#X obj 80 233 f;
+#X obj 108 233 + 1;
+#X connect 0 0 17 0;
+#X connect 0 0 16 0;
+#X connect 0 1 11 0;
+#X connect 0 2 10 0;
#X connect 0 3 1 0;
#X connect 1 0 3 0;
#X connect 2 0 0 0;
-#X connect 4 0 17 0;
+#X connect 4 0 15 0;
#X connect 5 0 4 0;
#X connect 5 1 6 0;
-#X connect 6 0 14 0;
-#X connect 8 0 14 1;
-#X connect 9 0 13 1;
-#X connect 10 0 5 0;
-#X connect 11 0 16 0;
-#X connect 12 0 11 0;
-#X connect 13 0 10 0;
-#X connect 14 0 4 1;
-#X connect 15 0 8 0;
-#X connect 15 0 9 0;
-#X connect 15 0 12 1;
+#X connect 6 0 12 0;
+#X connect 8 0 12 1;
+#X connect 9 0 11 1;
+#X connect 10 0 18 0;
+#X connect 11 0 19 0;
+#X connect 12 0 4 1;
+#X connect 13 0 8 0;
+#X connect 13 0 9 0;
+#X connect 13 0 10 1;
+#X connect 14 0 3 0;
+#X connect 15 0 3 0;
#X connect 16 0 3 0;
#X connect 17 0 3 0;
-#X connect 18 0 3 0;
-#X connect 19 0 3 0;
+#X connect 18 0 14 0;
+#X connect 19 0 21 0;
+#X connect 19 1 20 0;
+#X connect 20 0 22 1;
+#X connect 21 0 22 0;
+#X connect 22 0 23 0;
+#X connect 22 0 5 0;
+#X connect 23 0 22 1;
#X restore 28 96 pd corde;
#X obj 28 74 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
-1;
#X obj 89 193 metro 100;
-#X obj 89 167 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 1 1
+#X obj 89 167 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1
;
#X obj 115 170 loadbang;
#X obj 28 122 pmpd~ 1 1;
diff --git a/pmpd-help.pd b/pmpd-help.pd
index 4d0face..a1d0b75 100644
--- a/pmpd-help.pd
+++ b/pmpd-help.pd
@@ -1,255 +1,137 @@
-#N canvas 517 121 498 357 12;
-#X text 52 14 physical modeling for pure data using a collection of
-physical ojects.;
-#N canvas 0 0 623 384 read 0;
-#X text 123 207 cyrille.henry@la-kitchen.fr;
-#X text 412 312 ch20031213;
-#X text 30 25 The aim of this collection of objects is to create physical
-behavior with pure data. It's not audio synthesis. But it can be used
-for the creation of parameters that can be used for driving an audio
-or video synthesis.;
-#X text 30 101 Most of the examples use GEM \, to allow visualization
-of the "physical" geometry \, but you don't need it to use this collection.
+#N canvas 557 109 710 663 10;
+#X obj 90 363 pmpd;
+#X msg 186 32 reset;
+#X text 373 68 Add a mass;
+#X text 396 83 \$1 : Id (symbol);
+#X text 395 103 \$2 : fixed or mobile (0/1);
+#X text 395 121 \$3 : mass;
+#X msg 186 55 mass \$1 \$2 \$3 \$4;
+#X text 395 139 \$4 : initial position;
+#X text 393 195 \$1 : Id (symbol);
+#X text 393 248 \$4 : rigidity;
+#X text 393 195 \$1 : Id (symbol);
+#X text 393 248 \$4 : rigidity;
+#X text 393 213 \$2 : creation No/Id of mass1;
+#X text 393 231 \$3 : creation No/Id of mass2;
+#X text 388 176 Add link(s);
+#X text 393 266 \$5 : damping;
+#X msg 194 87 link \$1 \$2 \$3 \$4 \$5 (\$6 \$7 \$8);
+#X msg 255 216 posX \$1 \$2;
+#X text 383 451 Add force on mass(es);
+#X msg 254 272 forceX \$1 \$2;
+#X text 385 519 \$1 : Value;
+#X text 386 414 \$1 : Id (symbol) or No;
+#X text 386 468 \$1 : Id (symbol) or No;
+#X text 386 396 Set position of fixed mass(es);
+#X text 386 432 \$2 : Value;
+#X text 386 486 \$2 : Value;
+#X text 382 503 Set minimimum and maximum position of all masses;
+#X text 381 551 Set mass to mobile or fixed;
+#X msg 280 714 setD \$1 \$2;
+#X text 377 687 \$2 : New value;
+#X msg 280 663 setK \$1 \$2;
+#X text 377 743 \$2 : New value;
+#X text 377 796 \$2 : New value;
+#X text 371 651 Set rigidity of link(s);
+#X text 371 707 Set damping of link(s);
+#X msg 280 769 setL \$1 \$2;
+#X text 371 760 Set initial lenght of link(s);
+#X text 377 669 \$1 : Id (symbol) or No;
+#X text 377 725 \$1 : Id (symbol) or No;
+#X text 377 778 \$1 : Id (symbol) or No;
+#X text 384 568 \$1 : Id (symbol) or No;
+#X text 214 848 General :;
+#X text 214 911 Lists :;
+#X msg 240 878 infosL;
+#X text 343 878 Get infos on all masses and links on right outlet;
+#X msg 239 944 massesPosL;
+#X msg 239 972 massesForcesL;
+#X text 377 944 Output all masses positions in a list on outlet No
+1;
+#X text 347 1054 Get specific attribute on specific element;
+#X msg 227 1052 get \$1 (\$2);
+#X text 347 1155 The get message return the asked attribute preceded
+by an identifier and the creation No of the element. The identifier
+is made of the asked parameter and the way you asked for it.;
+#X text 348 1231 message;
+#X text 588 1231 response;
+#X text 347 1212 Examples with 3 masses numbered 0 \, 1 and 2 and named
+mas:;
+#X text 353 1321 [get massesPos mas( -----> [massesPosId 0 x0(;
+#X text 542 1336 [massesPosId 2 x2(;
+#X text 542 1351 [massesPosId 1 x1(;
+#X text 381 1250 [get massesPos( -----> [massesPos 0 x0(;
+#X text 542 1264 [massesPos 2 x2(;
+#X text 542 1278 [massesPos 1 x1(;
+#X text 367 1300 [get massesPos 1( -----> [massesPosNo 1 x1(;
+#X text 377 973 Output all forces applied on masses in a list on outlet
+No 1;
+#X text 347 1122 (\$2) : - If not defined all the attributes are send
+for all the elements. - Ids or/and creations No;
+#X text 347 1079 \$1 : Attribute type ( massesPos / massesPosName /
+massesSpeeds / massesSpeedsName / massesForces / massesForces / linksPos
+/ linksPos );
+#X text 353 1370 [get massesPosName( -----> [massesPosName name_0 x0(
;
-#X text 30 161 any comments \, criticism \, suggestions \, help would
-be highly apreciated :;
-#X text 28 240 informations can be find :;
-#X text 122 263 http://drpichon.free.fr/pmpd/;
-#X restore 38 87 pd read me first;
-#N canvas 0 0 663 567 basics 0;
-#X text 34 30 Object in this collection can be mass \, link and interactor
-\, in 1D \, 2D or 3D.;
-#X text 47 69 Masses (mass \, mass2D \, mass3D) are ponctual. They've
-got a weight \, and know their position. They can move when they receive
-a force \, acording to physical rules.;
-#X text 47 126 Link (link \, link2D \, link3D) are the basic interaction
-beetween 2 masses. It is a visco-elastic link. The link object receive
-the position of 2 masses \, compute the force beetween the 2 masses
-and output a force for each mass.;
-#X text 47 202 Interactors are a kind of link \, but influence a group
-of masses at once. They can be used for global interaction. We will
-look further into it later.;
-#X text 32 272 This collection of objects can be interconnected for
-the creation of "physical" structures. Such structures can then move
-\, and distord themselves \, according to forces applied to them.;
-#X text 29 350 The resulting movements are very natural \, due to the
-physical equations used to define the objects.;
-#X restore 38 115 pd basics;
-#N canvas 434 60 645 737 global_description 0;
-#X obj 34 169 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
--1;
-#X obj 34 268 print;
-#X obj 34 217 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
--1;
-#X text 57 165 1;
-#X text 58 216 2;
-#X text 36 452 Here is the basic connection beetween 2 masses :;
-#X text 36 529 You can also create things like this :;
-#X text 32 23 For patching simplification \, objects in this collection
-only have "cold" inlets. The computation speed depends on an external
-metronome. This metronome should bang alternatively all links in the
-model and then masses of the model.;
-#X text 33 103 mass and link have a name corresponding to their class
-name. They will receive everything sent to this name.;
-#X text 159 236 clicking on bang 1 or 2 is equivalent;
-#X text 32 304 As you sould send a bang alternatively to links and
-masses \, you sould give diferent names to the links group and masses
-group.;
-#X text 36 361 Masses output their position when you bang them. This
-position depends on the forces applied to the mass.;
-#X text 36 401 Links output a force according to the position of the
-masses when you bang them. This force sould be applied to the same
-mass.;
-#X text 40 626 The masse1 will never receive forces \, so it will never
-move. It is useful for creating a structure attached to a fixed point.
-;
-#X obj 40 558 mass masse1;
-#X obj 90 591 mass masse2;
-#X obj 34 188 s foo1;
-#X obj 34 237 mass2D foo1;
-#X obj 110 489 mass;
-#X obj 160 490 link;
-#X obj 214 492 mass;
-#X obj 40 591 link;
-#X connect 0 0 16 0;
-#X connect 2 0 17 0;
-#X connect 14 0 21 0;
-#X connect 15 0 21 1;
-#X connect 17 0 1 0;
-#X connect 18 0 19 0;
-#X connect 19 0 18 0;
-#X connect 19 1 20 0;
-#X connect 20 0 19 1;
-#X connect 21 1 15 0;
-#X restore 38 144 pd global_description;
-#N canvas 0 0 762 661 test 0;
-#X msg 108 98 1;
-#X msg 74 98 0;
-#X msg 41 98 -1;
-#X msg 141 98 2;
-#X obj 15 16 loadbang;
-#X floatatom 41 169 5 0 0 0 - - -;
-#X msg 106 390 1;
-#X msg 72 390 0;
-#X msg 39 390 -1;
-#X msg 139 390 2;
-#X floatatom 39 461 5 0 0 0 - - -;
-#X floatatom 37 325 5 0 0 0 - - -;
-#X msg 106 508 1;
-#X msg 72 508 0;
-#X msg 39 508 -1;
-#X msg 139 508 2;
-#X floatatom 39 579 5 0 0 0 - - -;
-#X text 247 61 A force to a masse make it to move at a constant speed.
-You can accelerate it or decelerate it using message box. a nul force
-as no effect.;
-#X floatatom 172 267 5 0 0 0 - - -;
-#X msg 104 264 1;
-#X msg 70 264 0;
-#X msg 37 264 -1;
-#X msg 137 264 2;
-#X text 247 405 Viscosity link : the force is proportinal to the deformation
-speed of the link;
-#X text 249 265 Rigidity link : the force is proportional to the elongation
-of the link. (the right inlet is not used \, so the like take is defauld
-value : 0.) Lengh of the link is null.;
-#X text 238 529 Visco-elasic link : the effect is the somme of the
-2 previus link.;
-#X obj 15 69 s foo2;
-#X obj 41 142 mass foo2 10 0 0;
-#X obj 37 298 link foo2 0 0.1 0;
-#X obj 39 434 link foo2 0 0 0.1;
-#X obj 39 552 link foo2 0 0.1 0.1;
-#X obj 15 43 metro 300;
-#X connect 0 0 27 0;
-#X connect 1 0 27 0;
-#X connect 2 0 27 0;
-#X connect 3 0 27 0;
-#X connect 4 0 31 0;
-#X connect 6 0 29 0;
-#X connect 7 0 29 0;
-#X connect 8 0 29 0;
-#X connect 9 0 29 0;
-#X connect 12 0 30 0;
-#X connect 13 0 30 0;
-#X connect 14 0 30 0;
-#X connect 15 0 30 0;
-#X connect 18 0 28 0;
-#X connect 19 0 28 0;
-#X connect 20 0 28 0;
-#X connect 21 0 28 0;
-#X connect 22 0 28 0;
-#X connect 27 0 5 0;
-#X connect 28 0 11 0;
-#X connect 29 0 10 0;
-#X connect 30 0 16 0;
-#X connect 31 0 26 0;
-#X restore 40 265 pd test;
-#N canvas 394 231 879 595 simple_exemple 0;
-#X obj 356 237 vsl 15 128 0 127 0 0 empty empty empty 0 -8 0 8 -262144
--1 -1 0 0;
-#X obj 74 98 hradio 15 1 0 5 empty empty empty 0 -6 0 8 -262144 -1
--1 0;
-#N canvas 477 25 445 299 preset 0;
-#X msg 36 193 setK 0.05 \, setD 0 \, setD2 30;
-#X msg 55 166 setK 1 \, setD 0 \, setD2 30;
-#X msg 75 138 setK 1 \, setD 0 \, setD2 200;
-#X obj 36 16 inlet;
-#X obj 115 254 outlet;
-#X msg 95 108 setK 300 \, setD 300 \, setD2 5;
-#X obj 36 43 sel 2 1 0 3 4;
-#X msg 115 78 setK 3000 \, setD 1000 \, setD2 5000;
-#X connect 0 0 4 0;
-#X connect 1 0 4 0;
-#X connect 2 0 4 0;
-#X connect 3 0 6 0;
-#X connect 5 0 4 0;
+#X text 543 1400 [massesPosName name_1 x1(;
+#X text 543 1385 [massesPosName name_2 x2(;
+#X msg 179 10 bang;
+#X msg 37 35 mass test1 0 1 0;
+#X msg 246 22 infosL;
+#X msg 40 67 mass test2 1 2 3;
+#X text 391 286 (\$6) : Power of the rigidity distance;
+#X text 390 303 (\$7) : minimum lenght of link;
+#X text 390 320 (\$8) : maximum lenght of link;
+#X msg 69 132 link toto 1 test1 3 4 5;
+#X msg 79 152 link toto test1 2 3 4 5;
+#X msg 89 172 link toto test1 test2 3 4 5;
+#X msg 112 200 forceX test2 1;
+#X msg 127 228 posX test2 3;
+#X msg 179 319 Xmin -1;
+#X msg 179 341 Xmax 11;
+#X msg 180 368 setMobile test1;
+#X msg 178 389 setFixed 1;
+#X msg 56 112 link toto1 1 2 3 4 5;
+#X msg 144 254 setK toto 4;
+#X msg 155 285 setK 1 2;
+#X msg 74 444 get massesPos test1;
+#X msg 84 464 get massesPos 1;
+#X msg 94 484 get massesPos;
+#X obj 92 391 print out1;
+#X msg 74 504 get massesPosName test1;
+#X msg 84 524 get massesPosName 1;
+#X msg 94 544 get massesPosName;
+#X msg 96 599 get linksPos toto;
+#X msg 277 526 massesPosL;
+#X msg 277 546 massesForcesL;
+#X msg 278 148 link a 1 2 11 22;
+#X connect 0 0 89 0;
+#X connect 1 0 0 0;
#X connect 6 0 0 0;
-#X connect 6 1 1 0;
-#X connect 6 2 2 0;
-#X connect 6 3 5 0;
-#X connect 6 4 7 0;
-#X connect 7 0 4 0;
-#X restore 74 119 pd preset;
-#X obj 336 237 vsl 15 128 0 127 0 0 empty empty empty 0 -8 0 8 -262144
--1 -1 0 0;
-#X text 80 415 the masse is link to the cursor with diferents kinf
-of liaison (see the preset);
-#X text 71 18 comportement of a single masse link to a fixed point
-with a visco elastic link.;
-#X text 173 95 <- diferents comportement of the link;
-#N canvas 0 0 268 186 stuff 0;
-#X obj 13 20 loadbang;
-#X obj 48 97 s \$0-lia;
-#X obj 13 72 t b b;
-#X obj 13 123 s \$0-masse;
-#X obj 13 45 metro 5;
-#X obj 89 20 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
--1;
-#X msg 124 92 reset;
-#X msg 89 66 resetL \, resetF;
-#X obj 89 40 t b b;
-#X connect 0 0 4 0;
-#X connect 2 0 3 0;
-#X connect 2 1 1 0;
-#X connect 4 0 2 0;
-#X connect 5 0 8 0;
-#X connect 6 0 3 0;
-#X connect 7 0 1 0;
-#X connect 8 0 7 0;
-#X connect 8 1 6 0;
-#X restore 75 65 pd stuff;
-#X text 98 346 click or move the slider ->;
-#X text 396 346 look at the mouvement of the masse (the right slider)
-;
-#X text 80 481 surch system can be usefull for replacing the line object
-of pd when more natural evolution is neaded...;
-#X obj 168 167 link \$0-lia 0 1 0 200;
-#X obj 356 167 mass \$0-masse 10000 0;
-#X connect 1 0 2 0;
-#X connect 2 0 11 0;
-#X connect 3 0 11 0;
-#X connect 11 1 12 0;
-#X connect 12 0 0 0;
-#X connect 12 0 11 1;
-#X restore 40 292 pd simple_exemple;
-#X text 64 180 look at mass and link help file :;
-#X obj 65 198 mass;
-#X obj 65 228 link;
-#N canvas 108 97 450 614 list 0;
-#X obj 190 135 iAmbient2D;
-#X obj 305 137 iAmbient3D;
-#X obj 190 166 iCircle2D;
-#X obj 306 257 iCylinder3D;
-#X obj 305 227 iCircle3D;
-#X obj 190 196 iLine2D;
-#X obj 305 197 iPlane3D;
-#X obj 190 225 iSeg2D;
-#X obj 305 168 iSphere3D;
-#X obj 79 76 lia;
-#X obj 79 48 mass;
-#X obj 192 48 mass2D;
-#X obj 306 48 mass3D;
-#X text 78 25 1D;
-#X text 191 27 2D;
-#X text 304 28 3D;
-#X text 21 46 basic;
-#X text 19 136 interactors;
-#X text 24 328 test;
-#X obj 192 389 tCircle2D;
-#X obj 192 419 tLine2D;
-#X obj 192 448 tSeg2D;
-#X obj 305 480 tCylinder3D;
-#X obj 306 420 tPlane3D;
-#X obj 306 450 tCircle3D;
-#X obj 306 390 tSphere3D;
-#X obj 192 358 tSquare2D;
-#X obj 307 359 tCube3D;
-#X obj 192 327 tLink2D;
-#X obj 307 327 tLink3D;
-#X obj 306 75 link3D;
-#X obj 192 75 link2D;
-#X text 19 535 other;
-#X obj 192 540 pmpd;
-#X obj 306 544 pmpd~;
-#X restore 40 322 pd list of pmpd's object;
+#X connect 16 0 0 0;
+#X connect 67 0 0 0;
+#X connect 68 0 0 0;
+#X connect 69 0 0 0;
+#X connect 70 0 0 0;
+#X connect 74 0 0 0;
+#X connect 75 0 0 0;
+#X connect 76 0 0 0;
+#X connect 77 0 0 0;
+#X connect 78 0 0 0;
+#X connect 79 0 0 0;
+#X connect 80 0 0 0;
+#X connect 81 0 0 0;
+#X connect 82 0 0 0;
+#X connect 83 0 0 0;
+#X connect 84 0 0 0;
+#X connect 85 0 0 0;
+#X connect 86 0 0 0;
+#X connect 87 0 0 0;
+#X connect 88 0 0 0;
+#X connect 90 0 0 0;
+#X connect 91 0 0 0;
+#X connect 92 0 0 0;
+#X connect 93 0 0 0;
+#X connect 94 0 0 0;
+#X connect 95 0 0 0;
+#X connect 96 0 0 0;
diff --git a/pmpd.c b/pmpd.c
index 78c2f7f..577a3f8 100644
--- a/pmpd.c
+++ b/pmpd.c
@@ -3,9 +3,9 @@
pmpd = physical modeling for pure data
- Written by Cyrille Henry (cyrille.henry@la-kitchen.fr)
+ Written by Cyrille Henry (ch@chnry.net)
- Get sources at http://drpichon.free.fr/pure-data/physical-modeling/
+ Get sources on pd svn on sourceforge.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -28,301 +28,714 @@
*/
#ifndef VERSION
-#define VERSION "0.07"
+#define VERSION "0.10"
#endif
#include "m_pd.h"
-#include "stdio.h"
+#include "stdio.h"
#ifndef __DATE__
#define __DATE__ ""
#endif
-#define nb_max_link 2000
-#define nb_max_mass 2000
-#define nb_max_out 200
-#define nb_max_in 200
-#define nb_max_outlet 20
-#define nb_max_inlet 20 // hard-coded on the methods definition
+#define nb_max_link 1000000
+#define nb_max_mass 100000
#define max(a,b) ( ((a) > (b)) ? (a) : (b) )
#define min(a,b) ( ((a) < (b)) ? (a) : (b) )
-
-/*
-#include "masse.c"
-#include "lia.c"
-#include "masse2D.c"
-#include "lia2D.c"
-#include "masse3D.c"
-#include "lia3D.c"
-
-#include "iAmbient2D.c"
-#include "iLine2D.c"
-#include "iSeg2D.c"
-#include "iCircle2D.c"
-
-#include "tSquare2D.c"
-#include "tLine2D.c"
-#include "tSeg2D.c"
-#include "tCircle2D.c"
-#include "tLia2D.c"
-
-#include "iAmbient3D.c"
-#include "iSphere3D.c"
-#include "iPlane3D.c"
-#include "iCircle3D.c"
-#include "iCylinder3D.c"
-
-
-#include "tCube3D.c"
-#include "tSphere3D.c"
-#include "tPlane3D.c"
-#include "tCircle3D.c"
-#include "tCylinder3D.c"
-#include "tLia3D.c"
-
-#include "pmpd~.c"
-*/
+#define sign(a) ( ((a) < 0) ? -1 : 1 )
static t_class *pmpd_class;
-
+
typedef struct _mass {
- t_int Id;
+ t_symbol *Id;
+ int mobile;
t_float invM;
t_float speedX;
t_float posX;
t_float forceX;
+ int num;
} foo;
typedef struct _link {
- t_int Id;
+ t_symbol *Id;
struct _mass *mass1;
struct _mass *mass2;
- t_float Ke, K1, D1, K2, D2;
+ t_float K;
+ t_float D;
+ t_float L;
+ t_float Pow;
+ t_float Lmin;
+ t_float Lmax;
+ t_float distance;
} foo1 ;
-typedef struct _out {
- // TODO ajouter un type pour diferencier les outlets en forces et celles en position
- t_int Id;
- t_int nbr_outlet;
- struct _mass *mass1;
- t_float influence;
-} foo2;
-
-typedef struct _in {
- // TODO ajouter un type pour diferencier les inlets en forces et celles en position
- t_int Id;
- t_int nbr_inlet;
- struct _mass *mass1;
- t_float influence;
-} foo3;
-
typedef struct _pmpd
{
t_object x_obj;
struct _link link[nb_max_link];
struct _mass mass[nb_max_mass];
- struct _out out[nb_max_out];
- struct _in in[nb_max_in];
- t_float outlet[nb_max_outlet];
- t_outlet *taboutlet[nb_max_outlet];
- t_float inlet[nb_max_inlet];
- int nb_link, nb_mass, nb_outlet, nb_inlet, nb_in, nb_out;
+ t_outlet *main_outlet;
+ t_outlet *info_outlet;
+ int nb_link;
+ int nb_mass;
+ t_float minX, maxX;
} t_pmpd;
void pmpd_bang(t_pmpd *x)
///////////////////////////////////////////////////////////////////////////////////
-// this part is doing all the job!
+// this part is doing all the PM
{
- t_float F;
+ t_float F, L;
t_int i;
- struct _mass mass_1, mass_2;
-
- for (i=0; i<x->nb_in; i++)
- // compute input
- {
- x->in[i].mass1->forceX += x->in[i].influence * x->inlet[x->in[i].nbr_inlet];
- }
-
- for (i=0; i<x->nb_inlet; i++)
- // clear inlet[i]
- {
- x->inlet[i]=0;
- }
-
- for (i=0; i<x->nb_link; i++)
- // comput link forces
- {
- F = x->link[i].K1 * ( x->link[i].mass1->posX - x->link[i].mass2->posX ) ;
- F += x->link[i].D1 * ( x->link[i].mass1->speedX - x->link[i].mass2->speedX) ;
- x->link[i].mass1->forceX -= F;
- x->link[i].mass2->forceX += F;
- }
for (i=1; i<x->nb_mass; i++)
// compute new masses position
- if (x->mass[i].Id >0) // only if Id >0
- {
+ if (x->mass[i].mobile > 0) // only if mobile
+ {
x->mass[i].speedX += x->mass[i].forceX * x->mass[i].invM;
x->mass[i].forceX = 0;
x->mass[i].posX += x->mass[i].speedX ;
- }
+ x->mass[i].posX = min(x->maxX,max(x->minX,x->mass[i].posX));
+ }
- for (i=0; i<x->nb_out; i++)
- // compute output point
- {
- x->outlet[x->out[i].nbr_outlet] += x->out[i].mass1->posX * x->out[i].influence ;
- }
-
-// for (i=0; i<x->nb_outlet; i++)
- for (i=x->nb_outlet-1; i>=0; i--)
- // output everything on the corresponding outlet
+ for (i=0; i<x->nb_link; i++)
+ // comput link forces
{
- outlet_float(x->taboutlet[i], x->outlet[i]);
- x->outlet[i] = 0;
+ L = x->link[i].mass1->posX - x->link[i].mass2->posX;
+ L -= x->link[i].L;
+ if ( (L > x->link[i].Lmin) & (L < x->link[i].Lmax) & (L!=0))
+ {
+ F = x->link[i].D * (L - x->link[i].distance) ;
+ x->link[i].distance=L;
+
+ if (L-x->link[i].L >= 0)
+ L = pow(L, x->link[i].Pow);
+ else
+ L = -pow(-L, x->link[i].Pow);
+
+ F += x->link[i].K * L;
+ x->link[i].mass1->forceX -= F;
+ x->link[i].mass2->forceX += F;
+ }
}
}
-void pmpd_forceX(t_pmpd *x, t_float nbr_mass, t_float force)
+void pmpd_forceX(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
{
// add a force to a specific mass
- nbr_mass = max(0, min( x->nb_mass, (int)nbr_mass));
- x->mass[(int)nbr_mass].forceX += force;
+ 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);
+ }
+ 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].forceX += atom_getfloatarg(1, argc, argv);
+ }
+ }
+ }
}
-void pmpd_posX(t_pmpd *x, t_float nbr_mass, t_float posX)
+void pmpd_posX(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
{
// displace a mass to a certain position
- nbr_mass = max(0, min( x->nb_mass, (int)nbr_mass));
- x->mass[(int)nbr_mass].posX = posX;
+ 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?
+ }
+ 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].posX = atom_getfloatarg(1, argc, argv);
+ x->mass[i].speedX = 0; // ??? TODO : esce la bonne chose a faire?
+ }
+ }
+ }
}
-void pmpd_mass(t_pmpd *x, t_float Id, t_float M, t_float posX)
+void pmpd_mass(t_pmpd *x, t_symbol *Id, t_float mobile, t_float M, t_float posX )
// add a mass
// Id, invM speedX posX forceX
{
- if (M==0) M=1;
- x->mass[x->nb_mass].Id = (int)Id;
+ if (M<=0) M=1;
+ x->mass[x->nb_mass].Id = Id;
+ x->mass[x->nb_mass].mobile = (int)mobile;
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->mass[x->nb_mass].num = x->nb_mass;
x->nb_mass++ ;
x->nb_mass = min ( nb_max_mass -1, x->nb_mass );
}
-void pmpd_link(t_pmpd *x, t_float Id, t_float mass_1, t_float mass_2, t_float K1, t_float D1)
+void pmpd_create_link(t_pmpd *x, t_symbol *Id, int mass1, int mass2, t_float K, t_float D, t_float Pow, t_float Lmin, t_float Lmax)
+{ // create a link based on mass number
+
+ if ((x->nb_mass>0) & (mass1 != mass2) & (mass1 >= 0) & (mass2 >= 0) & (mass1 < x->nb_mass) & (mass2 < x->nb_mass) )
+ {
+ x->link[x->nb_link].Id = Id;
+ x->link[x->nb_link].mass1 = &x->mass[mass1];
+ x->link[x->nb_link].mass2 = &x->mass[mass2];
+ x->link[x->nb_link].K = K;
+ x->link[x->nb_link].D = D;
+ x->link[x->nb_link].L = x->mass[mass1].posX - x->mass[mass2].posX;
+ x->link[x->nb_link].Pow = Pow;
+ x->link[x->nb_link].Lmin = Lmin;
+ x->link[x->nb_link].Lmax = Lmax;
+ x->link[x->nb_link].distance = 0;
+
+ x->nb_link++ ;
+ x->nb_link = min ( nb_max_link -1, x->nb_link );
+ }
+}
+
+void pmpd_link(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
// add a link
-// Id, *mass1, *mass2, Ke, K1, D1, K2, D2;
+// Id, *mass1, *mass2, K, D, Pow, Lmin, Lmax;
+{
+ int i, j;
+
+ t_symbol *Id = atom_getsymbolarg(0,argc,argv);
+ int mass1 = atom_getfloatarg(1, argc, argv);
+ int mass2 = atom_getfloatarg(2, argc, argv);
+ t_float K = atom_getfloatarg(3, argc, argv);
+ t_float D = atom_getfloatarg(4, argc, argv);
+ t_float Pow = 1;
+ if (argc > 5) Pow = atom_getfloatarg(5, argc, argv);
+ t_float Lmin = -1000000;
+ if (argc > 6) Lmin = atom_getfloatarg(6, argc, argv);
+ t_float Lmax = 1000000;
+ if (argc > 7) Lmax = atom_getfloatarg(7, argc, argv);
+// post("%d,%d, %f,%f", mass1, mass2, K, D);
+
+ if ( ( argv[1].a_type == A_FLOAT ) & ( argv[2].a_type == A_FLOAT ) )
+ {
+ pmpd_create_link(x, Id, mass1, mass2, K, D, Pow, Lmin, Lmax);
+ }
+ else
+ if ( ( argv[1].a_type == A_SYMBOL ) & ( argv[2].a_type == A_FLOAT ) )
+ {
+ for (i=0; i< x->nb_mass; i++)
+ {
+ if ( atom_getsymbolarg(1,argc,argv) == x->mass[i].Id)
+ {
+ pmpd_create_link(x, Id, i, mass2, K, D, Pow, Lmin, Lmax);
+ }
+ }
+ }
+ else
+ if ( ( argv[1].a_type == A_FLOAT ) & ( argv[2].a_type == A_SYMBOL ) )
+ {
+ for (i=0; i< x->nb_mass; i++)
+ {
+ if ( atom_getsymbolarg(2,argc,argv) == x->mass[i].Id)
+ {
+ pmpd_create_link(x, Id, mass1, i, K, D, Pow, Lmin, Lmax);
+ }
+ }
+ }
+ else
+ if ( ( argv[1].a_type == A_SYMBOL ) & ( argv[2].a_type == A_SYMBOL ) )
+ {
+ for (i=0; i< x->nb_mass; i++)
+ {
+ for (j=0; j< x->nb_mass; j++)
+ {
+ if ( (atom_getsymbolarg(1,argc,argv) == x->mass[i].Id)&(atom_getsymbolarg(2,argc,argv) == x->mass[j].Id))
+ {
+ pmpd_create_link(x, Id, i, j, K, D, Pow, Lmin, Lmax);
+ }
+ }
+ }
+ }
+}
+
+void pmpd_reset(t_pmpd *x)
{
+ x->nb_link = 0;
+ x->nb_mass = 0;
+ x->minX = -1000000;
+ x->maxX = 1000000;
+}
- x->link[x->nb_link].Id = (int)Id;
- x->link[x->nb_link].mass1 = &x->mass[max(0, min ( x->nb_mass, (int)mass_1))];
- x->link[x->nb_link].mass2 = &x->mass[max(0, min ( x->nb_mass, (int)mass_2))];
- x->link[x->nb_link].K1 = K1;
- x->link[x->nb_link].D1 = D1;
+void pmpd_infosL(t_pmpd *x)
+{
+ int i;
+ post("list of mass");
+ post("number, Id, mobile, mass, position, speed, forces");
+ for(i=0; i < x->nb_mass; i++)
+ {
+ post("masse %i: %s, %d, %f, %f, %f, %f",i, x->mass[i].Id->s_name, x->mass[i].mobile, 1/x->mass[i].invM, x->mass[i].posX, x->mass[i].speedX, x->mass[i].forceX );
+ }
+
+ post("list of link");
+ post("number, Id, mass1, mass2, K, D, Pow, L, Lmin, Lmax");
+ for(i=0; i < x->nb_link; i++)
+ {
+ post("link %i: %s, %i, %i, %f, %f, %f, %f, %f, %f", i, x->link[i].Id->s_name, x->link[i].mass1->num, x->link[i].mass2->num, x->link[i].K, x->link[i].D, x->link[i].Pow, x->link[i].L, x->link[i].Lmin, x->link[i].Lmax);
+ }
+}
- x->nb_link++ ;
- x->nb_link = min ( nb_max_link -1, x->nb_link );
+void pmpd_minX(t_pmpd *x, t_float min)
+{
+ x->minX = min;
}
-void pmpd_out(t_pmpd *x, t_float Id, t_float nb_outlet, t_float mass_1, t_float influence)
-// add an output point
-// Id, nbr_outlet, *mass1, influence;
+void pmpd_maxX(t_pmpd *x, t_float max)
{
- x->out[x->nb_out].Id = (int)Id;
- x->out[x->nb_out].nbr_outlet = max(0, min( x->nb_outlet,(int)nb_outlet));
- x->out[x->nb_out].mass1 = &x->mass[max(0, min ( x->nb_mass, (int)mass_1))];
- x->out[x->nb_out].influence = influence;
+ x->maxX = max;
+}
- x->nb_out++ ;
- x->nb_out = min ( nb_max_out - 1, x->nb_out );
+void pmpd_setFixed(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int tmp, i;
+
+ if ( argv[0].a_type == A_FLOAT )
+ {
+ tmp = atom_getfloatarg(0, argc, argv);
+ tmp = max(0, min( x->nb_mass-1, tmp));
+ x->mass[tmp].mobile = 0;
+ }
+ if ( argv[0].a_type == A_SYMBOL )
+ {
+ for (i=0; i< x->nb_mass; i++)
+ {
+ if ( atom_getsymbolarg(0,argc,argv) == x->mass[i].Id)
+ {
+ x->mass[i].mobile = 0;
+ }
+ }
+ }
}
-void pmpd_in(t_pmpd *x, t_float Id, t_float nb_inlet, t_float mass_1, t_float influence)
-//add an input point
-// Id, nbr_inlet, *mass1, influence;
+void pmpd_setMobile(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
{
- x->in[x->nb_in].Id = (int)Id;
- x->in[x->nb_in].nbr_inlet = max(0, min( x->nb_inlet,(int)nb_inlet));
- x->in[x->nb_in].mass1 = &x->mass[max(0, min ( x->nb_mass, (int)mass_1))];
- x->in[x->nb_in].influence = influence;
+ int tmp, i;
+
+ if ( argv[0].a_type == A_FLOAT )
+ {
+ tmp = atom_getfloatarg(0, argc, argv);
+ tmp = max(0, min( x->nb_mass-1, tmp));
+ x->mass[tmp].mobile = 1;
+ }
+ if ( argv[0].a_type == A_SYMBOL )
+ {
+ for (i=0; i< x->nb_mass; i++)
+ {
+ if ( atom_getsymbolarg(0,argc,argv) == x->mass[i].Id)
+ {
+ x->mass[i].mobile = 1;
+ }
+ }
+ }
+}
- x->nb_in++;
- x->nb_in = min ( nb_max_in - 1, x->nb_in );
+void pmpd_setK(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_link-1, tmp));
+ x->link[tmp].K = atom_getfloatarg(1, argc, argv);
+ }
+ if ( ( 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)
+ {
+ x->link[i].K = atom_getfloatarg(1, argc, argv);
+ }
+ }
+ }
}
-void pmpd_forceX_1(t_pmpd *x, t_float force)
- { x->inlet[0] += force; }
-void pmpd_forceX_2(t_pmpd *x, t_float force)
- { x->inlet[1] += force; }
-void pmpd_forceX_3(t_pmpd *x, t_float force)
- { x->inlet[2] += force; }
-void pmpd_forceX_4(t_pmpd *x, t_float force)
- { x->inlet[3] += force; }
-void pmpd_forceX_5(t_pmpd *x, t_float force)
- { x->inlet[4] += force; }
-void pmpd_forceX_6(t_pmpd *x, t_float force)
- { x->inlet[5] += force; }
-void pmpd_forceX_7(t_pmpd *x, t_float force)
- { x->inlet[6] += force; }
-void pmpd_forceX_8(t_pmpd *x, t_float force)
- { x->inlet[7] += force; }
-void pmpd_forceX_9(t_pmpd *x, t_float force)
- { x->inlet[8] += force; }
-void pmpd_forceX_10(t_pmpd *x, t_float force)
- { x->inlet[9] += force; }
-void pmpd_forceX_11(t_pmpd *x, t_float force)
- { x->inlet[10]+= force; }
-void pmpd_forceX_12(t_pmpd *x, t_float force)
- { x->inlet[11]+= force; }
-void pmpd_forceX_13(t_pmpd *x, t_float force)
- { x->inlet[12]+= force; }
-void pmpd_forceX_14(t_pmpd *x, t_float force)
- { x->inlet[13]+= force; }
-void pmpd_forceX_15(t_pmpd *x, t_float force)
- { x->inlet[14]+= force; }
-void pmpd_forceX_16(t_pmpd *x, t_float force)
- { x->inlet[15]+= force; }
-void pmpd_forceX_17(t_pmpd *x, t_float force)
- { x->inlet[16]+= force; }
-void pmpd_forceX_18(t_pmpd *x, t_float force)
- { x->inlet[17]+= force; }
-void pmpd_forceX_19(t_pmpd *x, t_float force)
- { x->inlet[18]+= force; }
-void pmpd_forceX_20(t_pmpd *x, t_float force)
- { x->inlet[19]+= force; }
+void pmpd_setD(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_link-1, tmp));
+ x->link[tmp].D = atom_getfloatarg(1, argc, argv);
+ }
+ if ( ( 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)
+ {
+ x->link[i].D = atom_getfloatarg(1, argc, argv);
+ }
+ }
+ }
+}
-void pmpd_reset(t_pmpd *x)
+void pmpd_setL(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
{
- x->nb_link = 0;
- x->nb_mass = 1;
- x->nb_out= 0;
- x->nb_in= 0;
+ 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_link-1, tmp));
+ x->link[tmp].L = atom_getfloatarg(1, argc, argv);
+ }
+ if ( ( 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)
+ {
+ x->link[i].L = atom_getfloatarg(1, argc, argv);
+ }
+ }
+ }
}
-void *pmpd_new(t_symbol *s, int argc, t_atom *argv)
+void pmpd_get(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
{
- int i;
- char buffer[10];
+ int tmp, i;
+ t_float X;
+ t_symbol *toget;
+ t_atom toout[2];
+ toget = atom_getsymbolarg(0, argc, argv);
+
+ if ( (toget == gensym("massesPos")) & (argv[1].a_type == A_FLOAT) )
+ {
+ i = atom_getfloatarg(1, argc, argv);
+ if ( (i>=0) & (i<x->nb_mass) )
+ {
+ SETFLOAT(&(toout[0]), i);
+ SETFLOAT(&(toout[1]), x->mass[i].posX);
+ outlet_anything(x->main_outlet, gensym("massesPosNo"), 2, toout);
+ }
+ }
+ else
+ if ( (toget == gensym("massesPos")) & (argv[1].a_type == A_SYMBOL) )
+ {
+ for (i=0; i< x->nb_mass; i++)
+ {
+ if ( atom_getsymbolarg(1,argc,argv) == x->mass[i].Id)
+ {
+ SETFLOAT(&(toout[0]), i);
+ SETFLOAT(&(toout[1]), x->mass[i].posX);
+ outlet_anything(x->main_outlet, gensym("massesPosId"), 2, toout);
+ }
+ }
+ }
+ else
+ if ( (toget == gensym("massesPos")) & (argc == 1) )
+ {
+ for (i=0; i< x->nb_mass; i++)
+ {
+ SETFLOAT(&(toout[0]), i);
+ SETFLOAT(&(toout[1]), x->mass[i].posX);
+ outlet_anything(x->main_outlet, gensym("massesPos"), 2, toout);
+ }
+ }
+ else
+ if ( (toget == gensym("massesPosName")) & (argv[1].a_type == A_FLOAT) )
+ {
+ i = atom_getfloatarg(1, argc, argv);
+ if ( (i>=0) & (i<x->nb_mass) )
+ {
+ SETSYMBOL(&(toout[0]), x->mass[i].Id);
+ SETFLOAT(&(toout[1]), x->mass[i].posX);
+ outlet_anything(x->main_outlet, gensym("massesPosNameNo"), 2, toout);
+ }
+ }
+ else
+ if ( (toget == gensym("massesPosName")) & (argv[1].a_type == A_SYMBOL) )
+ {
+ for (i=0; i< x->nb_mass; i++)
+ {
+ if ( atom_getsymbolarg(1,argc,argv) == x->mass[i].Id)
+ {
+ SETSYMBOL(&(toout[0]), x->mass[i].Id);
+ SETFLOAT(&(toout[1]), x->mass[i].posX);
+ outlet_anything(x->main_outlet, gensym("massesPosNameId"), 2, toout);
+ }
+ }
+ }
+ else
+ if ( (toget == gensym("massesPosName")) & (argc == 1) )
+ {
+ for (i=0; i< x->nb_mass; i++)
+ {
+ SETSYMBOL(&(toout[0]), x->mass[i].Id);
+ SETFLOAT(&(toout[1]), x->mass[i].posX);
+ outlet_anything(x->main_outlet, gensym("massesPosName"), 2, toout);
+ }
+ }
+ else
+ if ( (toget == gensym("massesSpeeds")) & (argv[1].a_type == A_FLOAT) )
+ {
+ i = atom_getfloatarg(1, argc, argv);
+ if ( (i>=0) & (i<x->nb_mass) )
+ {
+ SETFLOAT(&(toout[0]), i);
+ SETFLOAT(&(toout[1]), x->mass[i].speedX);
+ outlet_anything(x->main_outlet, gensym("massesSpeedsNo"), 2, toout);
+ }
+ }
+ else
+ if ( (toget == gensym("massesSpeeds")) & (argv[1].a_type == A_SYMBOL) )
+ {
+ for (i=0; i< x->nb_mass; i++)
+ {
+ if ( atom_getsymbolarg(1,argc,argv) == x->mass[i].Id)
+ {
+ SETFLOAT(&(toout[0]), i);
+ SETFLOAT(&(toout[1]), x->mass[i].speedX);
+ outlet_anything(x->main_outlet, gensym("massesSpeedsId"), 2, toout);
+ }
+ }
+ }
+ else
+ if ( (toget == gensym("massesSpeeds")) & (argc == 1) )
+ {
+ for (i=0; i< x->nb_mass; i++)
+ {
+ SETFLOAT(&(toout[0]), i);
+ SETFLOAT(&(toout[1]), x->mass[i].speedX);
+ outlet_anything(x->main_outlet, gensym("massesSpeeds"), 2, toout);
+ }
+ }
+ else
+ if ( (toget == gensym("massesSpeedsName")) & (argv[1].a_type == A_FLOAT) )
+ {
+ i = atom_getfloatarg(1, argc, argv);
+ if ( (i>=0) & (i<x->nb_mass) )
+ {
+ SETSYMBOL(&(toout[0]), x->mass[i].Id);
+ SETFLOAT(&(toout[1]), x->mass[i].speedX);
+ outlet_anything(x->main_outlet, gensym("massesSpeedsNameNo"), 2, toout);
+ }
+ }
+ else
+ if ( (toget == gensym("massesSpeedsName")) & (argv[1].a_type == A_SYMBOL) )
+ {
+ for (i=0; i< x->nb_mass; i++)
+ {
+ if ( atom_getsymbolarg(1,argc,argv) == x->mass[i].Id)
+ {
+ SETSYMBOL(&(toout[0]), x->mass[i].Id);
+ SETFLOAT(&(toout[1]), x->mass[i].speedX);
+ outlet_anything(x->main_outlet, gensym("massesSpeedsNameId"), 2, toout);
+ }
+ }
+ }
+ else
+ if ( (toget == gensym("massesSpeedsName")) & (argc == 1) )
+ {
+ for (i=0; i< x->nb_mass; i++)
+ {
+ SETSYMBOL(&(toout[0]), x->mass[i].Id);
+ SETFLOAT(&(toout[1]), x->mass[i].speedX);
+ outlet_anything(x->main_outlet, gensym("massesSpeedsName"), 2, toout);
+ }
+ }
+ else
+ if ( (toget == gensym("massesForces")) & (argv[1].a_type == A_FLOAT) )
+ {
+ i = atom_getfloatarg(1, argc, argv);
+ if ( (i>=0) & (i<x->nb_mass) )
+ {
+ SETFLOAT(&(toout[0]), i);
+ SETFLOAT(&(toout[1]), x->mass[i].forceX);
+ outlet_anything(x->main_outlet, gensym("massesForcesNo"), 2, toout);
+ }
+ }
+ else
+ if ( (toget == gensym("massesForces")) & (argv[1].a_type == A_SYMBOL) )
+ {
+ for (i=0; i< x->nb_mass; i++)
+ {
+ if ( atom_getsymbolarg(1,argc,argv) == x->mass[i].Id)
+ {
+ SETFLOAT(&(toout[0]), i);
+ SETFLOAT(&(toout[1]), x->mass[i].forceX);
+ outlet_anything(x->main_outlet, gensym("massesForcesId"), 2, toout);
+ }
+ }
+ }
+ else
+ if ( (toget == gensym("massesForces")) & (argc == 1) )
+ {
+ for (i=0; i< x->nb_mass; i++)
+ {
+ SETFLOAT(&(toout[0]), i);
+ SETFLOAT(&(toout[1]), x->mass[i].forceX);
+ outlet_anything(x->main_outlet, gensym("massesForces"), 2, toout);
+ }
+ }
+ else
+ if ( (toget == gensym("massesForcesName")) & (argv[1].a_type == A_FLOAT) )
+ {
+ i = atom_getfloatarg(1, argc, argv);
+ if ( (i>=0) & (i<x->nb_mass) )
+ {
+ SETSYMBOL(&(toout[0]), x->mass[i].Id);
+ SETFLOAT(&(toout[1]), x->mass[i].forceX);
+ outlet_anything(x->main_outlet, gensym("massesForcesNameNo"), 2, toout);
+ }
+ }
+ else
+ if ( (toget == gensym("massesForcesName")) & (argv[1].a_type == A_SYMBOL) )
+ {
+ for (i=0; i< x->nb_mass; i++)
+ {
+ if ( atom_getsymbolarg(1,argc,argv) == x->mass[i].Id)
+ {
+ SETSYMBOL(&(toout[0]), x->mass[i].Id);
+ SETFLOAT(&(toout[1]), x->mass[i].forceX);
+ outlet_anything(x->main_outlet, gensym("massesForcesNameId"), 2, toout);
+ }
+ }
+ }
+ else
+ if ( (toget == gensym("massesForcesName")) & (argc == 1) )
+ {
+ for (i=0; i< x->nb_mass; i++)
+ {
+ SETSYMBOL(&(toout[0]), x->mass[i].Id);
+ SETFLOAT(&(toout[1]), x->mass[i].forceX);
+ outlet_anything(x->main_outlet, gensym("massesForcesName"), 2, toout);
+ }
+ }
+ else
+ if ( (toget == gensym("linksPos")) & (argv[1].a_type == A_FLOAT) )
+ {
+ i = atom_getfloatarg(1, argc, argv);
+ if ( (i>=0) & (i<x->nb_mass) )
+ {
+ SETFLOAT(&(toout[0]), i);
+ SETFLOAT(&(toout[1]), x->link[i].mass1->posX);
+ SETFLOAT(&(toout[2]), x->link[i].mass2->posX);
+ outlet_anything(x->main_outlet, gensym("linksPosNo"), 3, toout);
+ }
+ }
+ else
+ if ( (toget == gensym("linksPos")) & (argv[1].a_type == A_SYMBOL) )
+ {
+ for (i=0; i< x->nb_link; i++)
+ {
+ if ( atom_getsymbolarg(1,argc,argv) == x->link[i].Id)
+ {
+ SETFLOAT(&(toout[0]), i);
+ SETFLOAT(&(toout[1]), x->link[i].mass1->posX);
+ SETFLOAT(&(toout[2]), x->link[i].mass2->posX);
+ outlet_anything(x->main_outlet, gensym("linksPosId"), 3, toout);
+ }
+ }
+ }
+ else
+ if ( (toget == gensym("linksPos")) & (argc == 1) )
+ {
+ for (i=0; i< x->nb_link; i++)
+ {
+ SETFLOAT(&(toout[0]), i);
+ SETFLOAT(&(toout[1]), x->link[i].mass1->posX);
+ SETFLOAT(&(toout[2]), x->link[i].mass2->posX);
+ outlet_anything(x->main_outlet, gensym("linksPos"), 3, toout);
+ }
+ }
+ else
+ if ( (toget == gensym("linksPosName")) & (argv[1].a_type == A_FLOAT) )
+ {
+ i = atom_getfloatarg(1, argc, argv);
+ if ( (i>=0) & (i<x->nb_mass) )
+ {
+ SETSYMBOL(&(toout[0]), x->link[i].Id);
+ SETFLOAT(&(toout[1]), x->link[i].mass1->posX);
+ SETFLOAT(&(toout[2]), x->link[i].mass2->posX);
+ outlet_anything(x->main_outlet, gensym("linksPosNameNo"), 3, toout);
+ }
+ }
+ else
+ if ( (toget == gensym("linksPosName")) & (argv[1].a_type == A_SYMBOL) )
+ {
+ for (i=0; i< x->nb_link; i++)
+ {
+ if ( atom_getsymbolarg(1,argc,argv) == x->link[i].Id)
+ {
+ SETSYMBOL(&(toout[0]), x->link[i].Id);
+ SETFLOAT(&(toout[1]), x->link[i].mass1->posX);
+ SETFLOAT(&(toout[2]), x->link[i].mass2->posX);
+ outlet_anything(x->main_outlet, gensym("linksPosNameId"), 3, toout);
+ }
+ }
+ }
+ else
+ if ( (toget == gensym("linksPosName")) & (argc == 1) )
+ {
+ for (i=0; i< x->nb_link; i++)
+ {
+ SETSYMBOL(&(toout[0]), x->link[i].Id);
+ SETFLOAT(&(toout[1]), x->link[i].mass1->posX);
+ SETFLOAT(&(toout[2]), x->link[i].mass2->posX);
+ outlet_anything(x->main_outlet, gensym("linksPosName"), 3, toout);
+ }
+ }
+ else
+ error("not get attribute");
+}
+
+void pmpd_massesPosL(t_pmpd *x)
+{
+ int i;
+ t_atom pos_list[nb_max_link];
+
+ for (i=0; i< x->nb_mass; i++)
+ {
+ SETFLOAT(&(pos_list[i]),x->mass[i].posX);
+ }
+ outlet_anything(x->main_outlet, gensym("massesPosL"),x->nb_mass , pos_list);
+}
+
+void pmpd_massesForcesL(t_pmpd *x)
+{
+ int i;
+ t_atom pos_list[nb_max_link];
+
+ for (i=0; i< x->nb_mass; i++)
+ {
+ SETFLOAT(&(pos_list[i]),x->mass[i].forceX);
+ }
+ outlet_anything(x->main_outlet, gensym("massesForcesL"),x->nb_mass , pos_list);
+}
+void *pmpd_new()
+{
t_pmpd *x = (t_pmpd *)pd_new(pmpd_class);
pmpd_reset(x);
- x->nb_outlet= (int)atom_getfloatarg(1, argc, argv);
- x->nb_outlet= max(0, min(nb_max_outlet, x->nb_outlet) );
- for(i=0; i<x->nb_outlet; i++)
- x->taboutlet[i]=outlet_new(&x->x_obj, 0);
-
- x->nb_inlet = (int)atom_getfloatarg(0, argc, argv);
- x->nb_inlet= max(0, min(nb_max_inlet, x->nb_inlet) );
- for(i=0; i<x->nb_inlet; i++)
- {
- sprintf (buffer, "forceX_%i", i+1);
- inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("forceX"), gensym(buffer));
- }
+ x->main_outlet=outlet_new(&x->x_obj, 0);
+ x->info_outlet=outlet_new(&x->x_obj, 0); // TODO
+
return (void *)x;
}
@@ -330,78 +743,24 @@ void pmpd_setup(void)
{
pmpd_class = class_new(gensym("pmpd"),
(t_newmethod)pmpd_new,
- 0, sizeof(t_pmpd),CLASS_DEFAULT, A_GIMME, 0);
+ 0, sizeof(t_pmpd),CLASS_DEFAULT, 0);
class_addbang(pmpd_class, pmpd_bang);
- class_addmethod(pmpd_class, (t_method)pmpd_mass, gensym("mass"), A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_link, gensym("link"), A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_out, gensym("out"), A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_in, gensym("in"), A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_posX, gensym("posX"), A_DEFFLOAT, A_DEFFLOAT, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_forceX, gensym("forceX"), A_DEFFLOAT, A_DEFFLOAT, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_forceX_1, gensym("forceX_1"), A_DEFFLOAT, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_forceX_2, gensym("forceX_2"), A_DEFFLOAT, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_forceX_3, gensym("forceX_3"), A_DEFFLOAT, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_forceX_4, gensym("forceX_4"), A_DEFFLOAT, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_forceX_5, gensym("forceX_5"), A_DEFFLOAT, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_forceX_6, gensym("forceX_6"), A_DEFFLOAT, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_forceX_7, gensym("forceX_7"), A_DEFFLOAT, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_forceX_8, gensym("forceX_8"), A_DEFFLOAT, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_forceX_9, gensym("forceX_9"), A_DEFFLOAT, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_forceX_10, gensym("forceX_10"), A_DEFFLOAT, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_forceX_11, gensym("forceX_11"), A_DEFFLOAT, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_forceX_12, gensym("forceX_12"), A_DEFFLOAT, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_forceX_13, gensym("forceX_13"), A_DEFFLOAT, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_forceX_14, gensym("forceX_14"), A_DEFFLOAT, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_forceX_15, gensym("forceX_15"), A_DEFFLOAT, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_forceX_16, gensym("forceX_16"), A_DEFFLOAT, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_forceX_17, gensym("forceX_17"), A_DEFFLOAT, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_forceX_18, gensym("forceX_18"), A_DEFFLOAT, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_forceX_19, gensym("forceX_19"), A_DEFFLOAT, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_forceX_20, gensym("forceX_20"), A_DEFFLOAT, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_reset, gensym("reset"), 0);
-
-/*
- post("");
- post(" pmpd = Physical Modeling for Pure Data");
- post(" version "VERSION);
- post(" compiled "__DATE__);
- post(" Contact : cyrille.henry@la-kitchen.fr");
- post("");
-
-masse_setup() ;
-lia_setup() ;
-masse2D_setup() ;
-lia2D_setup() ;
-masse3D_setup() ;
-lia3D_setup() ;
-
-iAmbient2D_setup();
-iLine2D_setup();
-iSeg2D_setup();
-iCircle2D_setup();
-
-tSquare2D_setup();
-tCircle2D_setup();
-tLine2D_setup();
-tSeg2D_setup();
-tLia2D_setup();
-
-iAmbient3D_setup();
-iSphere3D_setup();
-iPlane3D_setup();
-iCircle3D_setup();
-iCylinder3D_setup();
-
-tLia3D_setup();
-tCube3D_setup();
-tPlane3D_setup();
-tSphere3D_setup();
-tCylinder3D_setup();
-tCircle3D_setup();
-
-pmpd_tilde_setup();
-
-*/
+ 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_posX, gensym("posX"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_forceX, gensym("forceX"), A_GIMME, 0);
+ 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_minX, gensym("Xmin"), A_DEFFLOAT, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_maxX, gensym("Xmax"), 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_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_setL, gensym("setL"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_get, gensym("get"), A_GIMME, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_massesPosL, gensym("massesPosL"), 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_massesForcesL, gensym("massesForcesL"), 0);
}