[PD] More data structures: x-spacing in arrays

Frank Barknecht fbar at footils.org
Sat Aug 28 16:57:26 CEST 2004


Hallo,

another one of those data structures question not many people could
answer. ;)

I'm having difficulties in understanding x-spacing in [plot]ted arrays
correctly, if the elements of the array contain the x-fields.

To me it's not clear if x is taken relative to the template's (0,0)
point or relative to the previous array element or taken as a
mysterious combination of both. 

In the attached example I'm trying to make a graphical ADSR example
which can be edited both graphically by using the mouse as well as
numerically through sliders. The sliders should stay in sync with the
graphical representation. 

For that I poll the graphics window and read out the x-coordiantes.
This is done in the subpatch "getter". The subpatch "calculations"
translates slider positions to "set"-commands to the graphics. 

Now the problem is to compute the Release's x-value. 

If I only use "set" - that is, if the "getter" subpatch is off, all is
fine: The slider values correspond to the graphical appearance. If
however I use get as well ("getter" turned on) then a change to the
"A" slider will also change the "R" slider. Now the actually strange
this is, that it does not change the "D" slider which also has a
position dependent on "A". 

It might well be that I have a silly "order of execution" error myself
here, but somehow I don't see it (probably being blinded by colors
now)

I'd love it if someone has an idea on where my error is ...

Ciao
-- 
 Frank Barknecht                               _ ______footils.org__
-------------- next part --------------
#N struct grob-lib-w float x float y array numbers num-w;
#N struct num-w float y float x float w;
#N canvas 377 95 789 633 12;
#N canvas 0 0 450 300 paint 0;
#X scalar grob-lib-w 7 150 \; 0 0 0 \; 0 0 100 \; 0 0 0 \; 0 0 0 \;
\;;
#X coords 0 0 450 300 450 300 1;
#X restore 319 191 pd paint;
#X text 26 17 Graphical ADSR;
#X obj 150 396 vsl 15 128 0 100 0 0 empty empty A 0 -8 0 8 -262144
-1 -1 0 1;
#X obj 174 396 vsl 15 128 0 100 0 0 empty empty D 0 -8 0 8 -262144
-1 -1 0 1;
#X obj 198 396 vsl 15 128 0 100 0 0 empty empty S 0 -8 0 8 -262144
-1 -1 0 1;
#X obj 220 396 vsl 15 128 0 200 0 0 empty empty R 0 -8 0 8 -262144
-1 -1 0 1;
#X obj 135 548 s A;
#X obj 240 548 s R;
#X obj 203 548 s S;
#X obj 171 548 s D;
#X obj 106 398 vsl 15 128 0 100 0 0 empty empty Level 0 -8 0 8 -262144
-1 -1 0 1;
#X obj 91 546 s L;
#N canvas 0 0 959 676 calculations 0;
#X obj 46 44 r A;
#X msg 45 123 x \$1;
#X obj 45 67 t f b;
#X msg 92 95 1;
#X obj 239 122 r \$0-point;
#X msg 148 285 1;
#X obj 36 221 r L;
#X msg 35 277 w \$1;
#X obj 36 251 t f b;
#X obj 234 282 r \$0-point;
#X obj 657 99 r R;
#X obj 701 272 r \$0-point;
#X obj 656 124 t b f b;
#X msg 704 168 3;
#X obj 638 183 +;
#X msg 625 213 x \$1;
#X obj 557 134 t f b;
#X obj 557 94 r A+D;
#X obj 115 400 r D;
#X obj 344 432 r S;
#X msg 61 544 x \$1;
#X obj 65 474 +;
#X obj 115 423 t b f b;
#X msg 190 539 w \$1;
#X msg 231 534 2;
#X obj 343 453 t f b;
#X obj 64 402 r A;
#X obj 64 424 t f b;
#X obj 108 544 s A+D;
#X obj 291 529 r \$0-point;
#X text 31 24 read Attack value \, set point 1 x;
#X text 8 202 read Level value \, set point 1 w;
#X text 21 374 Read attack and delay \, add both and set point 2 x
;
#X text 400 445 read Sustain value \, set w of point 2;
#X text 420 66 read sum of A and D \, add to Release \, set last point's
x;
#X text 454 561 Note: Points are counted starting at 0 We have these
points: 0 \, 1 \, 2 \, 3;
#X obj 45 156 wxy-set grob-lib-w numbers num-w;
#X obj 35 309 wxy-set grob-lib-w numbers num-w;
#X obj 512 304 wxy-set grob-lib-w numbers num-w;
#X obj 56 587 wxy-set grob-lib-w numbers num-w;
#X connect 0 0 2 0;
#X connect 1 0 36 0;
#X connect 2 0 1 0;
#X connect 2 1 3 0;
#X connect 3 0 36 1;
#X connect 4 0 36 2;
#X connect 5 0 37 1;
#X connect 6 0 8 0;
#X connect 7 0 37 0;
#X connect 8 0 7 0;
#X connect 8 1 5 0;
#X connect 9 0 37 2;
#X connect 10 0 12 0;
#X connect 11 0 38 2;
#X connect 12 0 14 0;
#X connect 12 1 14 1;
#X connect 12 2 13 0;
#X connect 13 0 38 1;
#X connect 14 0 15 0;
#X connect 15 0 38 0;
#X connect 16 0 14 0;
#X connect 16 1 13 0;
#X connect 17 0 16 0;
#X connect 18 0 22 0;
#X connect 19 0 25 0;
#X connect 20 0 39 0;
#X connect 21 0 20 0;
#X connect 21 0 28 0;
#X connect 22 0 21 0;
#X connect 22 1 21 1;
#X connect 22 2 24 0;
#X connect 23 0 39 0;
#X connect 24 0 39 1;
#X connect 25 0 23 0;
#X connect 25 1 24 0;
#X connect 26 0 27 0;
#X connect 27 0 21 0;
#X connect 27 1 24 0;
#X connect 29 0 39 2;
#X restore 450 134 pd calculations;
#X obj 81 261 pointer;
#X obj 81 295 s \$0-point;
#X obj 81 201 bng 24 250 50 0 empty empty select_graphic_first 0 -6
0 10 -262144 -1 -1;
#X msg 81 234 traverse pd-paint \, next;
#N canvas 0 0 926 432 build 0;
#X msg 537 149 bang;
#X msg 629 150 clear;
#X obj 629 181 s pd-paint;
#X text 123 149 <----------------;
#X text 358 147 <----------------;
#X text 583 148 <--;
#X msg 308 149 100;
#X floatatom 99 201 5 0 8 0 - - -;
#X obj 308 184 x-append pd-paint grob-lib-w;
#X obj 79 226 setsize grob-lib-w numbers;
#X msg 79 149 4;
#X obj 335 227 s \$0-point;
#X text 204 34 To completely rebuild the ADSR-graphics \, click here
from right to left.;
#X obj 227 107 t b b b b;
#X obj 226 88 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
-1;
#X connect 0 0 8 1;
#X connect 1 0 2 0;
#X connect 6 0 8 0;
#X connect 7 0 9 0;
#X connect 8 0 9 1;
#X connect 8 0 11 0;
#X connect 10 0 9 0;
#X connect 13 0 10 0;
#X connect 13 1 6 0;
#X connect 13 2 0 0;
#X connect 13 3 1 0;
#X connect 14 0 13 0;
#X restore 688 581 pd build;
#X text 461 166 This is graph-on-parent! Tricky.;
#X text 328 552 Don't forget to have grob-library.pd open!!;
#X text 66 60 In order to also let mouse edits flow back to the sliders
\, we now added a "getter" subpatch \, which can be switched on or
off.;
#N canvas 154 117 978 681 getter 0;
#X obj 556 123 wxy-get grob-lib-w numbers num-w;
#X obj 12 9 inlet;
#X obj 229 263 s A-in;
#X obj 223 647 s R-in;
#X obj 88 358 s S-in;
#X obj 229 441 s D-in;
#X floatatom 556 148 5 0 0 0 w - -;
#X floatatom 697 151 5 0 0 0 x - -;
#X floatatom 838 150 5 0 0 0 y - -;
#X obj 104 19 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1
;
#X msg 556 67 0;
#X obj 839 91 r \$0-point;
#X msg 593 68 1;
#X msg 633 67 2;
#X msg 673 67 3;
#X text 552 37 This is how our observer works:;
#X text 176 61 A: p1.x (x of point p1);
#X text 176 111 S: p2.w (x of point p1);
#X text 154 18 How to get ADS and R:;
#X obj 88 211 wxy-get grob-lib-w numbers num-w;
#X floatatom 229 239 5 0 0 0 x - -;
#X obj 371 179 r \$0-point;
#X msg 88 176 1;
#X obj 88 323 wxy-get grob-lib-w numbers num-w;
#X floatatom 179 370 5 0 0 0 x - -;
#X obj 371 291 r \$0-point;
#X msg 62 290 2;
#X text 284 352 comment;
#X obj 82 504 wxy-get grob-lib-w numbers num-w;
#X floatatom 168 544 5 0 0 0 x - -;
#X obj 365 472 r \$0-point;
#X msg 8 472 3;
#X obj 293 347 r A-in;
#X obj 229 404 -;
#X obj 12 44 metro 100;
#X text 176 85 D: p2.x - p1.x;
#X obj 300 405 +;
#X obj 300 441 s AD-in;
#X obj 223 606 -;
#X text 178 137 R: p3.x - p2.x - p1.x;
#X obj 12 93 t b b b;
#X obj 267 550 r D-in;
#X connect 0 0 6 0;
#X connect 0 1 7 0;
#X connect 0 2 8 0;
#X connect 1 0 34 0;
#X connect 9 0 34 0;
#X connect 10 0 0 0;
#X connect 11 0 0 1;
#X connect 12 0 0 0;
#X connect 13 0 0 0;
#X connect 14 0 0 0;
#X connect 19 1 20 0;
#X connect 19 1 2 0;
#X connect 21 0 19 1;
#X connect 22 0 19 0;
#X connect 23 0 4 0;
#X connect 23 1 24 0;
#X connect 23 1 33 0;
#X connect 23 1 36 0;
#X connect 25 0 23 1;
#X connect 26 0 23 0;
#X connect 28 1 29 0;
#X connect 28 1 38 0;
#X connect 30 0 28 1;
#X connect 31 0 28 0;
#X connect 32 0 33 1;
#X connect 32 0 36 1;
#X connect 33 0 5 0;
#X connect 34 0 40 0;
#X connect 36 0 37 0;
#X connect 38 0 3 0;
#X connect 40 0 31 0;
#X connect 40 1 26 0;
#X connect 40 2 22 0;
#X connect 41 0 38 1;
#X restore 175 137 pd getter;
#X obj 64 323 r A-in;
#X obj 195 320 r S-in;
#X obj 256 320 r R-in;
#X obj 175 110 tgl 24 0 empty empty get_on/off 0 -6 0 8 -262144 -1
-1 0 1;
#X msg 64 349 set \$1;
#X msg 134 349 set \$1;
#X msg 198 351 set \$1;
#X msg 258 348 set \$1;
#X obj 131 324 r D-in;
#X text 174 586 This is tricky \, too: How is R reading it's X var?
;
#X obj 58 164 loadbang;
#X connect 2 0 6 0;
#X connect 3 0 9 0;
#X connect 4 0 8 0;
#X connect 5 0 7 0;
#X connect 10 0 11 0;
#X connect 13 0 14 0;
#X connect 15 0 16 0;
#X connect 16 0 13 0;
#X connect 22 0 26 0;
#X connect 23 0 28 0;
#X connect 24 0 29 0;
#X connect 25 0 21 0;
#X connect 26 0 2 0;
#X connect 27 0 3 0;
#X connect 28 0 4 0;
#X connect 29 0 5 0;
#X connect 30 0 27 0;
#X connect 32 0 15 0;
-------------- next part --------------
#N canvas 767 228 454 444 12;
#X text 39 20 A library of graphical objects;
#N canvas 686 559 581 359 num 0;
#X obj 91 184 filledpolygon 900 900 1 0 -5 10 -5 10 5 0 5;
#X text 80 32 The float value can only be moved on the y-axis;
#X text 112 154 A red box visualizes the float value:;
#X obj 193 66 struct num float y;
#X restore 95 69 pd num;
#N canvas 445 540 648 345 grob-lib 0;
#X text 42 137 Arrays are painted using "plot" drawing instructions:
;
#X text 44 21 This declares an array named "numbers" whose elements
are described by the template "num". Note that array declarations take
three arguments: the word "array" \, the name of the array and the
name of the elements.;
#X obj 57 166 plot numbers 90 5 15 0 15;
#X obj 65 100 struct grob-lib float x float y array numbers num;
#X restore 96 93 pd grob-lib;
#X text 180 65 float as red-box;
#X text 218 92 num plotted as numbers;
#N canvas 686 559 581 359 num-x 0;
#X obj 91 184 filledpolygon 900 900 1 0 -5 10 -5 10 5 0 5;
#X obj 135 95 struct num-x float y float x;
#X text 80 32 The num-x float has an and an x field.;
#X text 112 154 A red box visualizes the float values:;
#X restore 91 193 pd num-x;
#N canvas 445 540 648 345 grob-lib-x 0;
#X text 42 137 Arrays are painted using "plot" drawing instructions:
;
#X text 44 21 This declares an array named "numbers" whose elements
are described by the template "num". Note that array declarations take
three arguments: the word "array" \, the name of the array and the
name of the elements.;
#X obj 57 166 plot numbers 90 5 15 0 15;
#X obj 65 100 struct grob-lib-x float x float y array numbers num-x
;
#X restore 92 221 pd grob-lib-x;
#X text 228 221 num-x plotted;
#X text 194 191 float with x and y fields;
#X text 194 289 float with x \, y and w fields;
#X text 228 319 num-w plotted;
#N canvas 445 540 648 345 grob-lib-w 0;
#X text 42 137 Arrays are painted using "plot" drawing instructions:
;
#X text 44 21 This declares an array named "numbers" whose elements
are described by the template "num". Note that array declarations take
three arguments: the word "array" \, the name of the array and the
name of the elements.;
#X obj 65 98 struct grob-lib-w float x float y array numbers num-w
;
#X obj 57 166 plot numbers 90 5 15 0 15;
#X restore 92 319 pd grob-lib-w;
#N canvas 686 559 581 359 num-w 0;
#X obj 91 184 filledpolygon 900 900 1 0 -5 10 -5 10 5 0 5;
#X text 112 154 A red box visualizes the float values:;
#X obj 135 95 struct num-w float y float x float w;
#X text 80 32 The num-w float has a w and an x field added.;
#X restore 91 291 pd num-w;


More information about the Pd-list mailing list