Skip to content

Commit

Permalink
randi~
Browse files Browse the repository at this point in the history
  • Loading branch information
porres committed Aug 3, 2023
1 parent c3fd236 commit 9c90376
Show file tree
Hide file tree
Showing 2 changed files with 181 additions and 125 deletions.
14 changes: 1 addition & 13 deletions Code_source/Compiled/signal/rand.i~.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ typedef struct _randi{
t_random_state x_rstate;
t_int *x_randi;
t_float *x_lastin;
t_int x_trig_bang;
t_inlet *x_low_let;
t_inlet *x_high_let;
int x_id;
Expand All @@ -22,10 +21,6 @@ static void randi_seed(t_randi *x, t_symbol *s, int ac, t_atom *av){
random_init(&x->x_rstate, get_seed(s, ac, av, x->x_id));
}

static void randi_bang(t_randi *x){
x->x_trig_bang = 1;
}

static t_int *randi_perform(t_int *w){
t_randi *x = (t_randi *)(w[1]);
int n = (t_int)(w[2]);
Expand All @@ -48,13 +43,7 @@ static t_int *randi_perform(t_int *w){
if(range == 0)
x->x_randi[j] = out_low;
else{
t_int trigger = 0;
if(x->x_trig_bang){
trigger = 1;
x->x_trig_bang = 0;
}
else
trigger = (trig > 0 && lastin[j] <= 0) || (trig < 0 && lastin[j] >= 0);
t_int trigger = (trig > 0 && lastin[j] <= 0) || (trig < 0 && lastin[j] >= 0);
if(trigger){ // update
uint32_t *s1 = &x->x_rstate.s1;
uint32_t *s2 = &x->x_rstate.s2;
Expand Down Expand Up @@ -138,5 +127,4 @@ void setup_rand0x2ei_tilde(void){
class_addmethod(randi_class, nullfn, gensym("signal"), 0);
class_addmethod(randi_class, (t_method)randi_dsp, gensym("dsp"), A_CANT, 0);
class_addmethod(randi_class, (t_method)randi_seed, gensym("seed"), A_GIMME, 0);
class_addbang(randi_class, (t_method)randi_bang);
}
292 changes: 180 additions & 112 deletions Documentation/Help-files/rand.i~-help.pd
Original file line number Diff line number Diff line change
@@ -1,35 +1,24 @@
#N canvas 423 25 563 531 10;
#X obj 2 3 cnv 15 301 42 empty empty rand.i~ 20 20 2 37 #e0e0e0 #000000
0;
#N canvas 423 25 563 519 10;
#X obj 2 3 cnv 15 301 42 empty empty rand.i~ 20 20 2 37 #e0e0e0 #000000 0;
#N canvas 0 22 450 278 (subpatch) 0;
#X coords 0 1 100 -1 302 42 1 0 0;
#X restore 2 3 graph;
#X obj 23 40 cnv 4 4 4 empty empty Random 0 28 2 18 #e0e0e0 #000000
0;
#X obj 155 40 cnv 4 4 4 empty empty number 0 28 2 18 #e0e0e0 #000000
0;
#X obj 223 39 cnv 4 4 4 empty empty generator 0 28 2 18 #e0e0e0 #000000
0;
#X obj 3 501 cnv 15 552 21 empty empty empty 20 12 0 14 #e0e0e0 #202020
0;
#X obj 4 384 cnv 3 550 3 empty empty outlets 8 12 0 13 #dcdcdc #000000
0;
#X obj 4 452 cnv 3 550 3 empty empty arguments 8 12 0 13 #dcdcdc #000000
0;
#X obj 111 394 cnv 17 3 17 empty empty 0 5 9 0 16 #dcdcdc #9c9c9c 0
;
#X text 181 395 signal;
#X obj 23 40 cnv 4 4 4 empty empty Random 0 28 2 18 #e0e0e0 #000000 0;
#X obj 155 40 cnv 4 4 4 empty empty number 0 28 2 18 #e0e0e0 #000000 0;
#X obj 223 39 cnv 4 4 4 empty empty generator 0 28 2 18 #e0e0e0 #000000 0;
#X obj 3 490 cnv 15 552 21 empty empty empty 20 12 0 14 #e0e0e0 #202020 0;
#X obj 4 373 cnv 3 550 3 empty empty outlets 8 12 0 13 #dcdcdc #000000 0;
#X obj 4 441 cnv 3 550 3 empty empty arguments 8 12 0 13 #dcdcdc #000000 0;
#X obj 95 383 cnv 17 3 17 empty empty 0 5 9 0 16 #dcdcdc #9c9c9c 0;
#X msg 111 179 seed \$1;
#X obj 111 160 nbx 5 14 -1e+37 1e+37 0 0 empty empty empty 0 -8 0 10
#dcdcdc #000000 #000000 0 256;
#X text 237 395 - random values;
#X obj 111 160 nbx 5 14 -1e+37 1e+37 0 0 empty empty empty 0 -8 0 10 #dcdcdc #000000 #000000 0 256;
#X text 215 384 - random values;
#N canvas 764 106 378 447 example 0;
#X obj 122 354 else/out~;
#X text 41 23 Generating random resonant frequencies on impulse;
#X obj 183 280 mtof~;
#X obj 122 311 else/resonant~ 0 3000;
#X obj 122 98 bng 20 250 50 0 empty empty empty 17 7 0 10 #dcdcdc #000000
#000000;
#X obj 122 98 bng 20 250 50 0 empty empty empty 17 7 0 10 #dcdcdc #000000 #000000;
#X obj 122 188 else/impulse~;
#X obj 122 66 loadbang;
#X obj 122 132 else/rand.i~ 1 15;
Expand All @@ -46,10 +35,9 @@
#X connect 8 0 9 0;
#X connect 9 0 2 0;
#X connect 10 0 5 0;
#X restore 462 242 pd example;
#X restore 464 222 pd example;
#N canvas 207 34 366 264 (subpatch) 0;
#X obj 51 101 tgl 42 0 \$0-tgl-s \$0-tgl-r empty 1 8 1 9 #dcdcdc #7c7c7c
#fcfcfc 0 1;
#X obj 51 101 tgl 42 0 \$0-tgl-s \$0-tgl-r empty 1 8 1 9 #4a4f51 #cde5c3 #fcfcfc 0 1;
#X obj 215 68 route dsp;
#X obj 215 37 receive pd;
#N canvas 977 77 379 291 set_color 0;
Expand Down Expand Up @@ -118,8 +106,7 @@
#X restore 215 165 pd set_color;
#X obj 135 122 r \$0-tgl-s;
#N canvas 121 482 450 300 (subpatch) 0;
#X obj 101 101 cnv 25 40 25 empty \$0-cnv DSP 3 13 0 20 #dcdcdc #7c7c7c
0;
#X obj 101 101 cnv 25 40 25 empty \$0-cnv DSP 3 13 0 20 #4a4f51 #cde5c3 0;
#X coords 0 -1 1 1 42 27 1 100 100;
#X restore 51 144 pd;
#X obj 226 139 s \$0-tgl-r;
Expand All @@ -131,8 +118,7 @@
#X obj 136 86 snapshot~;
#X obj 91 52 del 5;
#X obj 136 151 outlet;
#X obj 74 103 tgl 15 0 empty empty empty 17 7 0 10 #fcfcfc #000000
#000000 0 1;
#X obj 74 103 tgl 15 0 empty empty empty 17 7 0 10 #fcfcfc #000000 #000000 0 1;
#X obj 74 126 switch~;
#X connect 0 0 2 0;
#X connect 1 0 3 0;
Expand All @@ -151,101 +137,183 @@
#X connect 9 0 0 0;
#X coords 0 -1 1 1 44 72 2 50 100;
#X restore 505 61 pd;
#X obj 278 174 nbx 5 14 -1e+37 1e+37 0 0 empty empty empty 0 -8 0 10
#dcdcdc #000000 #000000 0 256;
#X obj 370 175 nbx 5 14 -1e+37 1e+37 0 0 empty empty empty 0 -8 0 10
#dcdcdc #000000 #000000 0 256;
#X obj 278 174 nbx 5 14 -1e+37 1e+37 0 0 empty empty empty 0 -8 0 10 #dcdcdc #000000 #000000 0 256;
#X obj 370 175 nbx 5 14 -1e+37 1e+37 0 0 empty empty empty 0 -8 0 10 #dcdcdc #000000 #000000 0 256;
#X text 286 153 low;
#X text 381 155 high;
#X obj 187 164 else/imp~ 5;
#X obj 93 40 cnv 4 4 4 empty empty integer 0 28 2 18 #e0e0e0 #000000
0;
#X obj 306 4 cnv 15 250 40 empty empty empty 12 13 0 18 #7c7c7c #e0e4dc
0;
#X obj 93 40 cnv 4 4 4 empty empty integer 0 28 2 18 #e0e0e0 #000000 0;
#X obj 306 4 cnv 15 250 40 empty empty empty 12 13 0 18 #7c7c7c #e0e4dc 0;
#N canvas 382 141 749 319 (subpatch) 0;
#X coords 0 -1 1 1 252 42 2 100 100;
#X restore 305 3 pd;
#X obj 345 11 cnv 10 10 10 empty empty ELSE 0 15 2 30 #7c7c7c #e0e4dc
0;
#X obj 458 11 cnv 10 10 10 empty empty EL 0 6 2 13 #7c7c7c #e0e4dc
0;
#X obj 478 11 cnv 10 10 10 empty empty Locus 0 6 2 13 #7c7c7c #e0e4dc
0;
#X obj 515 11 cnv 10 10 10 empty empty Solus' 0 6 2 13 #7c7c7c #e0e4dc
0;
#X obj 464 26 cnv 10 10 10 empty empty ELSE 0 6 2 13 #7c7c7c #e0e4dc
0;
#X obj 502 26 cnv 10 10 10 empty empty library 0 6 2 13 #7c7c7c #e0e4dc
0;
#X obj 345 11 cnv 10 10 10 empty empty ELSE 0 15 2 30 #7c7c7c #e0e4dc 0;
#X obj 458 11 cnv 10 10 10 empty empty EL 0 6 2 13 #7c7c7c #e0e4dc 0;
#X obj 478 11 cnv 10 10 10 empty empty Locus 0 6 2 13 #7c7c7c #e0e4dc 0;
#X obj 515 11 cnv 10 10 10 empty empty Solus' 0 6 2 13 #7c7c7c #e0e4dc 0;
#X obj 464 26 cnv 10 10 10 empty empty ELSE 0 6 2 13 #7c7c7c #e0e4dc 0;
#X obj 502 26 cnv 10 10 10 empty empty library 0 6 2 13 #7c7c7c #e0e4dc 0;
#X obj 187 206 else/rand.i~ 0 1, f 31;
#X text 165 283 signal;
#X obj 97 283 cnv 17 3 47 empty empty 0 5 9 0 16 #dcdcdc #9c9c9c 0
;
#X obj 4 273 cnv 3 550 3 empty empty inlets 8 12 0 13 #dcdcdc #000000
0;
#X text 129 315 seed <float>;
#X text 221 282 - trigger signal;
#X obj 95 336 cnv 17 3 17 empty empty 1 5 9 0 16 #dcdcdc #9c9c9c 0
;
#X obj 95 357 cnv 17 3 17 empty empty 2 5 9 0 16 #dcdcdc #9c9c9c 0
;
#X text 128 337 float/signal;
#X text 128 358 float/signal;
#X text 221 337 - lowest random value;
#X text 220 358 - highest random value;
#X text 177 298 bang;
#X text 221 297 - control rate trigger;
#X text 61 91 [rand.i~] generates random integer values for a given
range when triggered. A trigger happens at positive to negative or
negative to positive transitions. Use the seed message if you want
a reproducible output.;
#X obj 97 283 cnv 17 3 35 empty empty 0 5 9 0 16 #dcdcdc #9c9c9c 0;
#X obj 4 273 cnv 3 550 3 empty empty inlets 8 12 0 13 #dcdcdc #000000 0;
#X text 129 300 seed <float>;
#X obj 95 325 cnv 17 3 17 empty empty 1 5 9 0 16 #dcdcdc #9c9c9c 0;
#X obj 95 346 cnv 17 3 17 empty empty 2 5 9 0 16 #dcdcdc #9c9c9c 0;
#X text 216 326 - lowest random value;
#X text 215 347 - highest random value;
#X obj 187 237 else/numbox~ 6 12 100 #c0c0c4 #440008 10 0 0 0;
#N canvas 529 124 603 329 seed 0;
#X text 26 21 Pseudo random number generators aren't true random number
generators. Instead \, an algorithm is used to provide a sequence of
numbers that seems random. The same sequence can be reproduced if you
set a "seed" value \, which can be any integer number., f 52;
#X text 370 24 You can set a seed with the '-seed' flag. If you don't
supply it \, each object gets its own seed internal seed. If you send
a 'seed' message without float \, the object also gets a unique seed
value., f 27;
#X text 26 21 Pseudo random number generators aren't true random number generators. Instead \, an algorithm is used to provide a sequence of numbers that seems random. The same sequence can be reproduced if you set a "seed" value \, which can be any integer number., f 52;
#X text 370 24 You can set a seed with the '-seed' flag. If you don't supply it \, each object gets its own seed internal seed. If you send a 'seed' message without float \, the object also gets a unique seed value., f 27;
#X msg 466 194 seed;
#X msg 456 165 seed 123;
#X obj 481 221 bng 19 250 50 0 empty empty empty 17 7 0 10 #dfdfdf
#000000 #000000;
#X obj 33 258 else/numbox~ 6 14 100 #c0c0c4 #440008 10 0 0 0;
#X obj 243 258 else/numbox~ 6 14 100 #c0c0c4 #440008 10 0 0 0;
#X obj 33 187 r \$0-rand.i~;
#X obj 33 221 else/rand.i~ -seed 1234 0 100;
#X obj 243 221 else/rand.i~ -seed 1234 0 100;
#X obj 33 278 else/numbox~ 6 14 100 #c0c0c4 #440008 10 0 0 0;
#X obj 243 278 else/numbox~ 6 14 100 #c0c0c4 #440008 10 0 0 0;
#X obj 33 241 else/rand.i~ -seed 1234 0 100;
#X obj 243 241 else/rand.i~ -seed 1234 0 100;
#X obj 243 187 r \$0-rand.i~;
#X obj 456 257 s \$0-rand.i~;
#X text 26 100 Seeds are kept locally \, which means that if two [rand.i~]
objects are seeded the same they will have the same output. Conversely
\, you can seed the same [rand.i~] object twice with the same seed
to repeat the output., f 52;
#X connect 2 0 11 0;
#X connect 3 0 11 0;
#X connect 4 0 11 0;
#X connect 7 0 8 0;
#X connect 8 0 5 0;
#X connect 9 0 6 0;
#X connect 10 0 9 0;
#X restore 477 220 pd seed;
#X obj 6 421 cnv 3 550 3 empty empty flags 8 12 0 13 #dcdcdc #000000
0;
#X text 135 430 -seed <float>: seed value (default: unique internal)
;
#X text 221 314 - a float sets seed \, no float sets a unique internal
;
#X text 26 100 Seeds are kept locally \, which means that if two [rand.i~] objects are seeded the same they will have the same output. Conversely \, you can seed the same [rand.i~] object twice with the same seed to repeat the output., f 52;
#X obj 33 168 bng 19 250 50 0 empty empty empty 17 7 0 10 #dfdfdf #000000 #000000;
#X obj 33 196 else/impseq~;
#N canvas 207 34 366 264 (subpatch) 0;
#X obj 51 101 tgl 42 0 \$0-tgl-s \$0-tgl-r empty 1 8 1 9 #4a4f51 #cde5c3 #fcfcfc 0 1;
#X obj 215 68 route dsp;
#X obj 215 37 receive pd;
#N canvas 977 77 379 291 set_color 0;
#X obj 47 30 inlet;
#X obj 147 200 s \$0-cnv;
#X obj 47 83 select 0 1;
#X obj 47 220 s \$0-tgl-r;
#N canvas 0 22 712 637 off 0;
#X obj 490 220 * -1;
#X obj 424 300 +;
#X obj 409 325 +;
#X obj 347 219 * -65536;
#X obj 424 220 * -256;
#X obj 409 356 - 1;
#X obj 390 189 unpack f f f;
#X obj 225 295 +;
#X obj 210 320 +;
#X obj 148 214 * -65536;
#X obj 225 215 * -256;
#X obj 291 215 * -1;
#X obj 210 351 - 1;
#X obj 191 184 unpack f f f;
#X obj 379 423 pack;
#X msg 395 152 124 124 124;
#X msg 203 154 220 220 220;
#X obj 238 121 t b b;
#X obj 238 81 inlet;
#X obj 378 485 outlet;
#X connect 0 0 1 1;
#X connect 1 0 2 1;
#X connect 2 0 5 0;
#X connect 3 0 2 0;
#X connect 4 0 1 0;
#X connect 5 0 14 1;
#X connect 6 0 3 0;
#X connect 6 1 4 0;
#X connect 6 2 0 0;
#X connect 7 0 8 1;
#X connect 8 0 12 0;
#X connect 9 0 8 0;
#X connect 10 0 7 0;
#X connect 11 0 7 1;
#X connect 12 0 14 0;
#X connect 13 0 9 0;
#X connect 13 1 10 0;
#X connect 13 2 11 0;
#X connect 14 0 19 0;
#X connect 15 0 6 0;
#X connect 16 0 13 0;
#X connect 17 0 16 0;
#X connect 17 1 15 0;
#X connect 18 0 17 0;
#X restore 47 113 pd off;
#X msg 47 180 color \$1 \$2 0;
#X msg 147 131 -4.86997e+06 -1.34937e+07;
#X msg 147 171 color \$1 0 \$2;
#X connect 0 0 2 0;
#X connect 2 0 4 0;
#X connect 2 1 6 0;
#X connect 4 0 5 0;
#X connect 4 0 7 0;
#X connect 5 0 3 0;
#X connect 6 0 7 0;
#X connect 6 0 5 0;
#X connect 7 0 1 0;
#X restore 215 165 pd set_color;
#X obj 135 122 r \$0-tgl-s;
#N canvas 121 482 450 300 (subpatch) 0;
#X obj 101 101 cnv 25 40 25 empty \$0-cnv DSP 3 13 0 20 #4a4f51 #cde5c3 0;
#X coords 0 -1 1 1 42 27 1 100 100;
#X restore 51 144 pd;
#X obj 226 139 s \$0-tgl-r;
#X msg 226 115 set \$1;
#X msg 135 177 \; pd dsp \$1;
#N canvas 256 32 278 194 load_check 0;
#X obj 136 53 sig~ 1;
#X obj 74 24 loadbang;
#X obj 136 86 snapshot~;
#X obj 91 52 del 5;
#X obj 136 151 outlet;
#X obj 74 103 tgl 15 0 empty empty empty 17 7 0 10 #fcfcfc #000000 #000000 0 1;
#X obj 74 126 switch~;
#X connect 0 0 2 0;
#X connect 1 0 3 0;
#X connect 1 0 5 0;
#X connect 2 0 4 0;
#X connect 3 0 2 0;
#X connect 3 0 5 0;
#X connect 5 0 6 0;
#X restore 51 72 pd load_check;
#X connect 1 0 3 0;
#X connect 1 0 7 0;
#X connect 2 0 1 0;
#X connect 4 0 8 0;
#X connect 4 0 3 0;
#X connect 7 0 6 0;
#X connect 9 0 0 0;
#X coords 0 -1 1 1 44 72 2 50 100;
#X restore 380 137 pd;
#X connect 2 0 9 0;
#X connect 3 0 9 0;
#X connect 6 0 4 0;
#X connect 7 0 5 0;
#X connect 8 0 7 0;
#X connect 8 0 6 0;
#X connect 11 0 12 0;
#X connect 12 0 6 0;
#X connect 12 0 7 0;
#X restore 479 200 pd seed;
#X obj 6 410 cnv 3 550 3 empty empty flags 8 12 0 13 #dcdcdc #000000 0;
#X text 135 419 -seed <float>: seed value (default: unique internal);
#X text 216 299 - a float sets seed \, no float sets a unique internal;
#X text 14 193 see also:;
#X obj 14 240 else/rand.i;
#X obj 14 215 else/rand.f~;
#X text 180 461 1) float - minimum (default 0);
#X text 180 478 2) float - maximum (default 1);
#X connect 10 0 29 0;
#X connect 11 0 10 0;
#X connect 15 0 29 1;
#X connect 16 0 29 2;
#X connect 19 0 29 0;
#X connect 29 0 44 0;
#X text 180 450 1) float - minimum (default 0);
#X text 180 467 2) float - maximum (default 1);
#X text 164 326 signal;
#X text 164 347 signal;
#N canvas 746 138 370 332 multichannel 0;
#X listbox 106 241 19 0 0 0 - - - 12;
#X obj 106 172 else/rand.i~ 0 1000;
#X obj 106 207 else/s2f~;
#X obj 106 133 else/imp.mc~ 0.25 0.5 1 2;
#X text 60 52 If you have a multichannel connection in the trigger inlet \, [rand.i~] generates a signal with the same number of channels., f 44;
#X connect 1 0 2 0;
#X connect 2 0 0 0;
#X connect 3 0 1 0;
#X restore 435 245 pd multichannel;
#X text 51 87 [rand.i~] generates random integer values for a given range when triggered. A trigger happens at positive to negative or negative to positive transitions. Use the seed message if you want a reproducible output. There's support for multichannels., f 70;
#X text 147 283 signal(s);
#X text 216 282 - trigger signal(s);
#X text 146 384 signal(s);
#X connect 9 0 28 0;
#X connect 10 0 9 0;
#X connect 14 0 28 1;
#X connect 15 0 28 2;
#X connect 18 0 28 0;
#X connect 28 0 36 0;

0 comments on commit 9c90376

Please sign in to comment.