[PD] List with variable number of floats

Frank Barknecht fbar at footils.org
Tue Aug 17 18:28:06 CEST 2010


Hi João,

On Tue, Aug 17, 2010 at 04:30:00PM +0100, João de Brito Rocha Reis Vidigal wrote:
> Here's what I wanna do:
> 
> I have 18 slot for audio and video to play. There can be one playing, none or even um to the 18.
> These slots are to be triggered randomly.
> Is there a possibility of storing the ID of the slots already triggered? Like a list? The thing is that if it is a list it would have to have a variable number of floats (wouldn't it?).
> Why do I need this? Because after triggering a random slot ON I want to trigger a random slot OFF. So, I have to know what are the slots triggered on in order to trigger one of these OFF and not one 18. Otherwise I could end up triggering off a slot that was never on!
> As well I need to know witch ones are OFF to randomly select and turn one on.

A brute-force approach to your problem is attached: It uses [select] to
re-trigger the random selection if you get a slot-value that already is off.
If instead you get a usable slot-value, it stores this in a [f] object
by using the cold, right inlet, so it can be switched off later, then
also updates the [select] via its right inlet to watch for the new "ON"
slot.

There is a small risk to get a lot of the same values from [random] but
this is very, very unlikely. 

You should remember the 

 [t f b]
  \/
  /\
 [f ]

idiom to delay the output of a float value by one execution step. It's
often useful, and also the use of [select] to filter out unwanted
values.

You can also do all this without storing the OFF value by transferring
the logic of switching off or on into your "slot" abstractions. The
c_tgl.pd abstractions shows how to do that. It compares an incoming
slot-number with [== $1] where $1 is the slot-id passed as argument. It
has a global receiver in it to simplify patching a bit.

Ciao 
-- 
Frank
-------------- next part --------------
#N canvas 84 0 1114 648 10;
#X obj 180 170 select 0;
#X obj 210 141 random 18;
#X floatatom 293 288 5 0 0 0 ON - -;
#X floatatom 231 288 5 0 0 0 OFF - -;
#X floatatom 252 166 5 0 0 0 - - -;
#X obj 293 315 hradio 15 1 0 18 empty empty empty 0 -8 0 10 -262144
-1 -1 13;
#X obj 294 339 hradio 15 1 0 18 empty empty empty 0 -8 0 10 -262144
-1 -1 5;
#X msg 210 112 bang;
#X obj 151 215 bng 15 250 50 0 empty empty duplicate 17 7 0 10 -262144
-1 -1;
#X floatatom 270 112 5 0 0 0 - - -;
#X obj 231 240 f;
#X obj 233 202 t f b f f;
#X obj 783 47 tgl 15 0 0 0 empty 17 7 0 10 -262144 -1 -1 0 1;
#X obj 683 47 r 1003-in1-0;
#X obj 783 77 tgl 15 0 0 0 empty 17 7 0 10 -262144 -1 -1 0 1;
#X obj 683 77 r 1003-in1-1;
#X obj 783 107 tgl 15 0 0 0 empty 17 7 0 10 -262144 -1 -1 0 1;
#X obj 683 107 r 1003-in1-2;
#X obj 783 137 tgl 15 0 0 0 empty 17 7 0 10 -262144 -1 -1 0 1;
#X obj 683 137 r 1003-in1-3;
#X obj 783 167 tgl 15 0 0 0 empty 17 7 0 10 -262144 -1 -1 0 1;
#X obj 683 167 r 1003-in1-4;
#X obj 783 197 tgl 15 0 0 0 empty 17 7 0 10 -262144 -1 -1 0 1;
#X obj 683 197 r 1003-in1-5;
#X obj 783 227 tgl 15 0 0 0 empty 17 7 0 10 -262144 -1 -1 0 1;
#X obj 683 227 r 1003-in1-6;
#X obj 783 257 tgl 15 0 0 0 empty 17 7 0 10 -262144 -1 -1 0 1;
#X obj 683 257 r 1003-in1-7;
#X obj 783 287 tgl 15 0 0 0 empty 17 7 0 10 -262144 -1 -1 0 1;
#X obj 683 287 r 1003-in1-8;
#X obj 783 317 tgl 15 0 0 0 empty 17 7 0 10 -262144 -1 -1 0 1;
#X obj 683 317 r 1003-in1-9;
#X obj 783 347 tgl 15 0 0 0 empty 17 7 0 10 -262144 -1 -1 0 1;
#X obj 683 347 r 1003-in1-10;
#X obj 783 377 tgl 15 0 0 0 empty 17 7 0 10 -262144 -1 -1 0 1;
#X obj 683 377 r 1003-in1-11;
#X obj 783 407 tgl 15 0 0 0 empty 17 7 0 10 -262144 -1 -1 0 1;
#X obj 683 407 r 1003-in1-12;
#X obj 783 437 tgl 15 0 0 0 empty 17 7 0 10 -262144 -1 -1 1 1;
#X obj 683 437 r 1003-in1-13;
#X obj 783 467 tgl 15 0 0 0 empty 17 7 0 10 -262144 -1 -1 0 1;
#X obj 683 467 r 1003-in1-14;
#X obj 783 497 tgl 15 0 0 0 empty 17 7 0 10 -262144 -1 -1 0 1;
#X obj 683 497 r 1003-in1-15;
#X obj 783 527 tgl 15 0 0 0 empty 17 7 0 10 -262144 -1 -1 0 1;
#X obj 683 527 r 1003-in1-16;
#X obj 783 557 tgl 15 0 0 0 empty 17 7 0 10 -262144 -1 -1 0 1;
#X obj 683 557 r 1003-in1-17;
#X msg 231 394 0 1003-in1-\$1;
#X msg 340 391 1 1003-in1-\$1;
#X obj 231 429 unpack 0 s;
#X obj 231 455 send;
#X obj 376 107 u_robinpoly 18 c_tgl;
#X obj 888 45 c_tgl 0;
#X obj 888 75 c_tgl 1;
#X obj 888 105 c_tgl 2;
#X obj 888 135 c_tgl 3;
#X obj 888 165 c_tgl 4;
#X obj 888 195 c_tgl 5;
#X obj 888 225 c_tgl 6;
#X obj 888 255 c_tgl 7;
#X obj 888 285 c_tgl 8;
#X obj 888 315 c_tgl 9;
#X obj 888 345 c_tgl 10;
#X obj 888 375 c_tgl 11;
#X obj 888 405 c_tgl 12;
#X obj 888 435 c_tgl 13;
#X obj 888 465 c_tgl 14;
#X obj 888 495 c_tgl 15;
#X obj 888 525 c_tgl 16;
#X obj 888 555 c_tgl 17;
#X obj 363 286 send TOGGLE;
#X text 447 288 in c_tgl!!;
#X connect 0 0 1 0;
#X connect 0 0 8 0;
#X connect 0 1 11 0;
#X connect 1 0 0 0;
#X connect 1 0 4 0;
#X connect 2 0 5 0;
#X connect 2 0 49 0;
#X connect 2 0 71 0;
#X connect 3 0 6 0;
#X connect 3 0 48 0;
#X connect 7 0 1 0;
#X connect 9 0 1 1;
#X connect 10 0 3 0;
#X connect 11 0 10 1;
#X connect 11 1 10 0;
#X connect 11 2 0 1;
#X connect 11 3 2 0;
#X connect 13 0 12 0;
#X connect 15 0 14 0;
#X connect 17 0 16 0;
#X connect 19 0 18 0;
#X connect 21 0 20 0;
#X connect 23 0 22 0;
#X connect 25 0 24 0;
#X connect 27 0 26 0;
#X connect 29 0 28 0;
#X connect 31 0 30 0;
#X connect 33 0 32 0;
#X connect 35 0 34 0;
#X connect 37 0 36 0;
#X connect 39 0 38 0;
#X connect 41 0 40 0;
#X connect 43 0 42 0;
#X connect 45 0 44 0;
#X connect 47 0 46 0;
#X connect 48 0 50 0;
#X connect 49 0 50 0;
#X connect 50 0 51 0;
#X connect 50 1 51 1;
-------------- next part --------------
#N canvas 0 0 453 340 10;
#X obj 130 113 tgl 15 0 0 0 empty 17 7 0 10 -262144 -1 -1 0 1;
#X obj 130 45 r TOGGLE;
#X obj 130 72 == \$1;
#X connect 1 0 2 0;
#X connect 2 0 0 0;
#X coords 0 -1 1 1 85 30 1 100 100;


More information about the Pd-list mailing list