#N canvas 409 63 554 643 12;
#X msg 123 274 60 0;
#X msg 221 274 62 0;
#X text 196 549 Output is in the printout window., f 17;
#X obj 123 555 print bag;
#X text 17 608 see also:;
#X obj 138 609 makenote;
#X obj 33 11 bag;
#X obj 94 609 poly;
#N canvas 606 95 571 508 reference 0;
#X obj 8 42 cnv 5 550 5 empty empty INLETS: 8 18 0 13 #202020 #000000 0;
#X obj 8 75 cnv 1 550 1 empty empty 1st: 8 12 0 13 #9f9f9f #000000 0;
#X obj 8 260 cnv 2 550 2 empty empty OUTLETS: 8 12 0 13 #202020 #000000 0;
#X obj 8 384 cnv 2 550 2 empty empty ARGUMENTS: 8 12 0 13 #202020 #000000 0;
#X obj 7 480 cnv 5 550 5 empty empty empty 8 18 0 13 #202020 #000000 0;
#X obj 8 219 cnv 1 550 1 empty empty 2nd: 8 12 0 13 #7c7c7c #000000 0;
#X text 116 83 float -;
#X obj 28 12 bag;
#X text 60 11 - collection of numbers;
#X text 116 103 flush -;
#X text 116 122 clear -;
#X text 173 122 clear stored values from the bag (no output)., f 47;
#X text 173 103 output stored values and clear the bag., f 47;
#X text 173 83 value to store or delete depending on the flag.;
#X text 123 141 bang -;
#X obj 8 324 cnv 1 550 1 empty empty 2nd: 8 12 0 13 #7c7c7c #000000 0;
#X obj 8 290 cnv 1 550 1 empty empty 1st: 8 12 0 13 #9f9f9f #000000 0;
#X text 110 297 float - the stored values on bang or flush message.;
#X text 53 161 unique <float> -;
#X text 173 141 output stored values but don't clear them., f 47;
#X text 173 160 set <1> or clear <0> "unique" flag., f 47;
#X text 117 230 float - store flag: true (nonzero) or false (zero)., f 57;
#X text 60 180 count <float> -;
#X text 173 179 count the number of stored values that correspond to the given float (output is on the 2nd outlet)., f 49;
#X text 111 332 float -;
#X text 174 333 output count value on "count" message.;
#X text 118 351 bang -;
#X text 174 352 reports duplicate in "unique" mode.;
#X obj 8 412 cnv 1 550 1 empty empty flags: 8 12 0 13 #9f9f9f #000000 0;
#X obj 8 444 cnv 1 550 1 empty empty args: 8 12 0 13 #7c7c7c #000000 0;
#X text 121 418 '-u': flag to prevent multiple copies of same value.;
#X text 208 452 none, f 7;
#X restore 348 11 pd reference;
#X text 446 10 <= click;
#X obj 9 44 cnv 1 535 1 empty empty empty 8 12 0 13 #000000 #000000 0;
#X text 259 274 <-- add or delete elements;
#X text 66 11 - collection of numbers;
#X obj 141 525 print bag-outlet2;
#X obj 123 495 bag;
#X obj 75 381 bng 20 250 50 0 empty empty empty 0 -10 0 12 #dfdfdf #000000 #000000;
#X listbox 123 328 7 0 0 0 - - - 0;
#X obj 10 599 cnv 1 535 1 empty empty empty 8 12 0 13 #000000 #000000 0;
#X msg 69 274 60 127;
#X msg 165 274 62 127;
#X text 63 358 output;
#X msg 204 311 clear;
#X msg 212 339 flush;
#X msg 221 370 count 60;
#X msg 222 438 unique \$1;
#X obj 222 414 tgl 19 0 empty empty empty 17 7 0 10 #dfdfdf #000000 #000000 0 64;
#X text 249 312 <-- clear;
#X text 260 338 <-- clear and output;
#X text 29 103 The first inlet is a number to add or delete. If the second inlet is nonzero \, the number is added to the collection \, otherwise it is removed. A list can also be given \, which distributes the values into the inlets as usual in Pd., f 69;
#X text 29 169 By default \, the collection may have many copies of the same number \, but if set to unique mode (via the "unique" message or "-u" flag) \, duplicates are dropped and a "bang" is sent out the second outlet., f 69;
#X text 29 219 You can output the collection with a bang \, output and empty it with a "flush" message \, or just empty it with "clear"., f 69;
#X text 299 424 set or clear "unique" flag. A bang is set to the right outlet when there's a repeated input., f 31;
#X text 29 55 The [bag] object maintains a variable-length collection of numbers \, for instance to implement a MIDI-style sustain pedal or an arpeggiator., f 69;
#N canvas 275 116 567 592 sustain 0;
#X obj 183 295 stripnote;
#X obj 153 266 route 0 1;
#X obj 328 278 sel 0;
#X obj 218 325 pack;
#X msg 328 306 flush;
#X obj 297 424 f;
#X obj 218 351 t l l f;
#X msg 241 473 \$1 0;
#X obj 153 236 list prepend 0;
#X obj 153 205 pack f f;
#X obj 327 196 tgl 23 0 empty empty empty 0 -10 0 12 #dfdfdf #000000 #000000 0 1;
#X obj 327 166 loadbang;
#X text 356 201 Sustain;
#X obj 241 419 bag -u;
#X obj 97 160 makenote 127 250;
#X msg 97 96 60;
#X floatatom 97 127 5 0 0 0 - - - 0;
#X obj 46 93 + 60;
#X obj 46 66 random 12;
#X obj 46 24 bng 21 250 50 0 empty empty empty 0 -10 0 12 #dfdfdf #000000 #000000;
#X text 151 94 send a repeated note, f 8;
#X listbox 216 505 10 0 0 0 - - - 0;
#X text 78 17 generate random notes, f 12;
#X msg 328 343 unique 0;
#X msg 332 378 unique 1;
#X text 126 94 <--;
#X text 35 292 use [stripnote] to filter note offs \, which are flushed when the sustain toggle is set to off., f 15;
#X text 250 24 This is a way to implement a sustain pedal. The unique flag is set here by default to manage repeated notes \, where it sends a note off before repeating the note. If you set it to "unique 0" \, then the note offs are stacked and all of them are sent when the sustain pedal is turned off., f 39;
#X text 396 342 stack note offs;
#X text 400 367 retrigger by sending a note off before repeating the note, f 20;
#X obj 216 542 print Sustain;
#X connect 0 0 3 0;
#X connect 0 1 3 1;
#X connect 1 0 21 0;
#X connect 1 1 0 0;
#X connect 2 0 4 0;
#X connect 3 0 6 0;
#X connect 4 0 13 0;
#X connect 5 0 7 0;
#X connect 6 0 21 0;
#X connect 6 1 13 0;
#X connect 6 2 5 1;
#X connect 7 0 21 0;
#X connect 8 0 1 0;
#X connect 9 0 8 0;
#X connect 10 0 2 0;
#X connect 10 0 8 1;
#X connect 11 0 10 0;
#X connect 13 0 7 0;
#X connect 13 1 5 0;
#X connect 14 0 9 0;
#X connect 14 1 9 1;
#X connect 15 0 16 0;
#X connect 16 0 14 0;
#X connect 17 0 16 0;
#X connect 18 0 17 0;
#X connect 19 0 18 0;
#X connect 21 0 30 0;
#X connect 23 0 13 0;
#X connect 24 0 13 0;
#X restore 435 515 pd sustain;
#N canvas 495 128 736 651 arpeggiator 0;
#X obj 549 190 text define notes;
#X msg 549 150 clear;
#X obj 437 100 t b b l b;
#X obj 487 222 text insert notes;
#X msg 447 150 sort;
#X obj 58 360 text get notes;
#X obj 58 302 f;
#X obj 439 258 text size notes;
#X obj 100 324 mod;
#X obj 100 299 + 1;
#X obj 439 292 > 0;
#X obj 439 322 change;
#X obj 58 139 tgl 19 0 empty metro empty 0 -10 0 12 #dfdfdf #000000 #000000 0 1;
#X obj 133 526 line~;
#X msg 133 498 \$1 10;
#X obj 58 460 mtof;
#X obj 58 532 *~;
#X msg 115 161 tempo \$1 permin;
#X floatatom 255 108 5 0 0 0 - bpm - 0;
#X obj 177 224 expr 1/$f1;
#X floatatom 177 198 4 0 0 0 - mul - 0;
#X obj 58 206 metro;
#X obj 255 258 expr 60000/$f1;
#X obj 191 374 *;
#X obj 177 252 t b f;
#X obj 241 366 hsl 162 19 0.25 1 0 0 empty dur empty -2 -10 0 12 #dfdfdf #000000 #000000 0 1;
#X obj 238 413 t b f;
#X obj 58 426 makenote 1;
#X obj 191 451 *;
#X obj 58 562 output~;
#X obj 58 488 tabosc4~ wave, f 8;
#X obj 58 392 route float;
#X obj 487 150 bag -u;
#X msg 437 36 40 127 \, 45 127 \, 49 127 \, 52 127;
#X msg 460 67 40 0 \, 45 0 \, 49 0 \, 52 0;
#X text 458 13 play and hold a chord;
#X text 629 67 release it;
#N canvas 281 271 450 300 init 0;
#X obj 129 65 loadbang;
#X obj 138 222 array define wave 2051;
#X msg 129 95 \; bpm 120 \; mul 4 \; dur 0.75 \; wave sinesum 2048 1 0.5 0.33333 0.25 0.2 0.166667 \, normalize, f 26;
#X connect 0 0 2 0;
#X restore 238 557 pd init;
#X floatatom 58 332 3 0 0 0 - - - 0;
#X text 219 106 BPM;
#X text 146 198 mul;
#X obj 439 350 s metro;
#X floatatom 238 390 5 0 0 0 - - - 0;
#X text 55 19 Below we have a way to sequence through notes stored in a [text] object with a [metro] object. The notes are stored to the right with the help of [bag]., f 40;
#X msg 83 258 -1;
#X msg 118 258 1;
#X text 79 238 down;
#X text 121 238 up;
#X text 358 444 Above \, we clear the [text] contents every time we play a new note and use [bag] to output all of its contents with a bang message. Then the contents of the sequence are sorted and the size of the sequence is queried to use as the module of the sequence counter., f 46;
#X floatatom 255 323 5 0 0 0 - - - 0;
#X text 296 323 ms;
#X floatatom 191 404 4 0 0 0 - - - 0;
#X floatatom 191 478 7 0 0 0 - - - 0;
#X text 247 478 duration;
#X text 282 390 relative duration;
#X connect 1 0 0 0;
#X connect 2 0 4 0;
#X connect 2 0 7 0;
#X connect 2 1 32 0;
#X connect 2 2 32 0;
#X connect 2 3 1 0;
#X connect 4 0 0 0;
#X connect 5 0 31 0;
#X connect 6 0 9 0;
#X connect 6 0 38 0;
#X connect 7 0 10 0;
#X connect 7 0 8 1;
#X connect 8 0 6 1;
#X connect 9 0 8 0;
#X connect 10 0 11 0;
#X connect 11 0 41 0;
#X connect 12 0 21 0;
#X connect 13 0 16 1;
#X connect 14 0 13 0;
#X connect 15 0 30 0;
#X connect 16 0 29 0;
#X connect 17 0 21 0;
#X connect 18 0 17 0;
#X connect 18 0 22 0;
#X connect 19 0 21 1;
#X connect 19 0 24 0;
#X connect 20 0 19 0;
#X connect 21 0 6 0;
#X connect 22 0 49 0;
#X connect 23 0 51 0;
#X connect 24 0 23 0;
#X connect 24 1 23 1;
#X connect 25 0 42 0;
#X connect 26 0 28 0;
#X connect 26 1 28 1;
#X connect 27 0 15 0;
#X connect 27 1 14 0;
#X connect 28 0 27 2;
#X connect 28 0 52 0;
#X connect 30 0 16 0;
#X connect 31 0 27 0;
#X connect 32 0 3 0;
#X connect 33 0 2 0;
#X connect 34 0 2 0;
#X connect 38 0 5 0;
#X connect 42 0 26 0;
#X connect 44 0 9 1;
#X connect 45 0 9 1;
#X connect 49 0 23 0;
#X connect 51 0 28 0;
#X restore 408 565 pd arpeggiator;
#N canvas 720 261 466 441 active-voices 0;
#X obj 163 269 bag;
#X obj 123 230 t b b a b;
#X msg 202 279 0;
#X obj 163 296 b;
#X floatatom 123 376 5 0 0 0 - - - 0;
#X obj 239 301 + 1;
#X obj 202 331 v n;
#X obj 123 342 v n;
#X listbox 123 195 10 0 0 0 - - - 0;
#X obj 218 121 tgl 19 0 empty empty empty 17 7 0 10 #dfdfdf #000000 #000000 0 64;
#X obj 76 121 tgl 19 0 empty empty empty 17 7 0 10 #dfdfdf #000000 #000000 0 64;
#X obj 123 121 tgl 19 0 empty empty empty 17 7 0 10 #dfdfdf #000000 #000000 0 64;
#X obj 170 121 tgl 19 0 empty empty empty 17 7 0 10 #dfdfdf #000000 #000000 0 64;
#X msg 76 147 72 \$1;
#X msg 123 147 74 \$1;
#X msg 170 147 77 \$1;
#X msg 218 147 81 \$1;
#X text 268 120 <-- emulate note on/off messages, f 20;
#X text 67 45 This example shows how to use [bag] to tell us the number of active voices in it., f 43;
#X text 175 376 Number of currently on voices;
#X connect 0 0 3 0;
#X connect 1 0 7 0;
#X connect 1 1 0 0;
#X connect 1 2 0 0;
#X connect 1 3 2 0;
#X connect 2 0 6 0;
#X connect 3 0 6 0;
#X connect 5 0 6 0;
#X connect 6 0 5 0;
#X connect 7 0 4 0;
#X connect 8 0 1 0;
#X connect 9 0 16 0;
#X connect 10 0 13 0;
#X connect 11 0 14 0;
#X connect 12 0 15 0;
#X connect 13 0 8 0;
#X connect 14 0 8 0;
#X connect 15 0 8 0;
#X connect 16 0 8 0;
#X restore 394 539 pd active-voices;
#X text 325 607 updated for Pd version 0.56;
#X text 405 487 Examples:;
#X text 287 369 <-- query how many 60s are in the collection (the count is sent to the second output), f 30;
#X connect 0 0 16 0;
#X connect 1 0 16 0;
#X connect 14 0 3 0;
#X connect 14 1 13 0;
#X connect 15 0 14 0;
#X connect 16 0 14 0;
#X connect 18 0 16 0;
#X connect 19 0 16 0;
#X connect 21 0 14 0;
#X connect 22 0 14 0;
#X connect 23 0 14 0;
#X connect 24 0 14 0;
#X connect 25 0 24 0;
