[PD] 2d control surface using GOP datastructures

Frank Barknecht fbar at footils.org
Sat Dec 24 00:21:24 CET 2005


Hallo,
Chris McCormick hat gesagt: // Chris McCormick wrote:

> This is a 2 dimensional control surface. The number box adds new
> controllable points. Banging the inlet outputs a sequence of values (n x
> y) where n is the number of the controllable point, x is it's normalised
> x value, and y is it's normalised y value. You can unpack these to assign
> different points to parameters in your patches.

Actually for this kind of surface, you wouldn't need to go through the
metro-banging to set borders anymore. (I'm not sure yet how to do this
with arrays, though, as you ask in your other mail.)

Attached is a version, which uses the scaling of coordinates in
structs to greatly simplify your patch. Note that I also avoided the
constant traversal of the graphing subpatch, because that can be very
expensive CPU-wise. I avoided it by auto-creating a little abstraction
(ctl-parser.pd) that receives the pointer of the newly created
graphical control object and caches this. This way, no traversal at
all is done and you only get a little "spike" in CPU the moment, you
create the new dots. 

The other "trick" out of my bag is, that the struct doesn't have
fields for "float x float y" at all, these two are always 0 here.
Instead I use different fields for the coordinates of the dots: x0 and
y0. These two are scaled with (a:b)(a+?:b+?) to keep the whole
displayed graph inside of an area of 200x200. Note that the output
isn't normalized. You could use for example [list-normalize] out of my
[list]-abs collection for this.

Ciao
-- 
 Frank Barknecht                 _ ______footils.org_ __goto10.org__
-------------- next part --------------
#N canvas 225 584 450 300 10;
#X obj 119 155 pointer;
#X obj 119 99 route \$1;
#X obj 119 262 s \$2-result;
#X text 234 49 args: id \, \$0;
#X obj 119 70 r \$2-pointer;
#X obj 133 134 r \$2-readout;
#X obj 119 183 get \$2-controller id x0 y0;
#X obj 119 228 pack 0 0 0;
#X text 229 133 from metro;
#X connect 0 0 6 0;
#X connect 1 0 0 0;
#X connect 4 0 1 0;
#X connect 5 0 0 0;
#X connect 6 0 7 0;
#X connect 6 1 7 1;
#X connect 6 2 7 2;
#X connect 7 0 2 0;
-------------- next part --------------
#N struct 1010-controller float x0 float y0 float id;
#N canvas 290 167 668 496 10;
#X obj 65 325 print c1;
#X obj 316 327 print c2;
#X text 70 361 Output: Id (color) x \, y;
#X obj 427 374 tgl 15 0 empty empty empty 0 -6 0 8 -1 -262131 -1 0
1;
#X obj 426 429 hradio 15 1 0 6 empty empty empty 0 -6 0 8 -1 -262144
-262144 0;
#X obj 427 404 bng 15 250 50 0 \$0-clear empty clear 0 -6 0 8 -233017
-1 -1;
#X text 311 371 readout on/off:;
#X text 311 398 clear all:;
#X text 311 426 create more:;
#X obj 316 63 control;
#X obj 65 61 control;
#X connect 9 0 1 0;
#X connect 10 0 0 0;
-------------- next part --------------
#N canvas 342 32 786 583 10;
#N canvas 109 550 751 371 controller 0;
#X obj 603 213 makefilename pd-%s;
#X msg 603 240 traverse \$1 \, bang;
#X obj 603 183 symbol \$0-show;
#X obj 603 261 pointer;
#X obj 405 322 outlet;
#X obj 405 146 inlet;
#X obj 23 35 struct \$0-controller float x0 float y0 float id;
#X msg 405 261 100 100 \$1;
#X obj 405 205 t f b b b b;
#X msg 433 171 1;
#X obj 405 286 append \$0-controller x0 y0 id;
#X obj 24 82 filledpolygon id 999 1 x0(0:200)(0:200) y0(0:200)(0:200)
x0(0:200)(10:210) y0(0:200)(0:200) x0(0:200)(10:210) y0(0:200)(10:210)
x0(0:200)(0:200) y0(0:200)(10:210);
#X connect 0 0 1 0;
#X connect 1 0 3 0;
#X connect 2 0 0 0;
#X connect 3 0 10 3;
#X connect 5 0 8 0;
#X connect 7 0 10 0;
#X connect 8 0 7 0;
#X connect 8 4 2 0;
#X connect 9 0 8 0;
#X connect 10 0 4 0;
#X restore 395 114 pd controller;
#X obj 244 102 metro 100;
#X obj 92 42 tgl 15 0 empty empty empty 0 -6 0 8 -1 -262131 -1 0 1
;
#N canvas 0 0 450 300 1007-pointer-pool 0;
#X restore 340 449 pd \$0-pointer-pool;
#X obj 589 284 makefilename pd-%s;
#X obj 589 254 symbol \$0-pointer-pool;
#X msg 654 226 bang;
#X obj 395 62 hradio 15 1 0 8 empty empty make_new 0 -6 0 8 -262144
-1 -1 0;
#X text 561 81 make colorful;
#X obj 395 209 get \$0-controller id;
#X obj 517 311 pack 0 \$0 s;
#X msg 517 334 \; \$3 obj 100 100 ctl-parser \$1 \$2;
#X msg 164 317 clear;
#X obj 395 182 t p p;
#X obj 395 314 s \$0-pointer;
#X obj 395 279 pack 0 p;
#X obj 395 238 t f f;
#X obj 42 401 r \$0-result;
#X obj 244 128 s \$0-readout;
#X obj 589 225 loadbang;
#N canvas 0 0 590 367 clear-all 0;
#X msg 89 155 \; \$1 clear;
#X obj 254 134 makefilename pd-%s;
#X obj 254 104 symbol \$0-show;
#X obj 89 133 makefilename pd-%s;
#X obj 89 103 symbol \$0-pointer-pool;
#X obj 89 72 t b b;
#X obj 89 46 inlet;
#X connect 1 0 0 0;
#X connect 2 0 1 0;
#X connect 3 0 0 0;
#X connect 4 0 3 0;
#X connect 5 0 4 0;
#X connect 5 1 2 0;
#X connect 6 0 5 0;
#X restore 164 361 pd clear-all;
#X obj 170 338 loadbang;
#X text 339 412 cache active pointers to speed up access and avoid
frequent subpatch traversal:;
#X obj 136 42 hradio 15 1 0 6 empty empty empty 0 -6 0 8 -1 -262144
-262144 0;
#X obj 42 487 outlet;
#X obj 115 42 bng 15 250 50 0 \$0-clear empty empty 0 -6 0 8 -233017
-1 -1;
#X obj 235 338 r \$0-clear;
#X obj 395 82 expr 5 * pow(2 \, $f1);
#X obj 16 64 cnv 15 210 210 empty empty empty 20 12 0 14 -1 -66577
0;
#N canvas 0 0 450 300 1007-show 0;
#X coords 0 210 210 0 210 210 1;
#X restore 15 64 pd \$0-show;
#X obj 496 110 loadbang;
#X obj 496 132 del 10;
#X msg 496 155 0;
#X connect 0 0 13 0;
#X connect 1 0 18 0;
#X connect 2 0 1 0;
#X connect 4 0 10 2;
#X connect 5 0 4 0;
#X connect 6 0 5 0;
#X connect 7 0 27 0;
#X connect 9 0 16 0;
#X connect 10 0 11 0;
#X connect 12 0 20 0;
#X connect 13 0 9 0;
#X connect 13 1 15 1;
#X connect 15 0 14 0;
#X connect 16 0 15 0;
#X connect 16 1 10 0;
#X connect 17 0 24 0;
#X connect 19 0 5 0;
#X connect 21 0 20 0;
#X connect 23 0 27 0;
#X connect 26 0 20 0;
#X connect 27 0 0 0;
#X connect 30 0 31 0;
#X connect 31 0 32 0;
#X connect 32 0 0 0;
#X coords 0 -1 1 1 220 250 1 10 30;


More information about the Pd-list mailing list