#N canvas 345 66 982 652 12;
#X declare -stdpath ./;
#X text 35 81 ARGUMENTS FOR NOTES:;
#X text 55 110 pitch in halftones, f 21;
#X text 55 130 amplitude (dB), f 21;
#X text 55 169 sample number, f 21;
#X text 55 149 duration (msec), f 21;
#X text 55 189 start location (msec);
#X text 55 208 rise time (msec), f 21;
#X text 55 228 decay time (msec), f 21;
#X obj 561 17 r note;
#X obj 534 76 t b f;
#X obj 474 109 f;
#X obj 510 109 + 1;
#X obj 482 146 mod 1e+06;
#X obj 474 175 makenote 64;
#X obj 474 203 poly 8 1;
#X obj 474 230 stripnote;
#X text 759 78 record \, etc.;
#X text 294 200 allocate sampler voice;
#X text 315 225 drop note off again;
#X obj 689 512 qlist;
#X obj 546 483 r comment;
#X obj 547 331 output~;
#X text 231 175 supply delayed note-off message;
#X msg 772 104 record 1;
#X msg 787 150 stop;
#X msg 780 127 record 2;
#X msg 793 173 reload;
#X msg 798 196 browse;
#X obj 547 262 pack f f f f f f f f;
#X obj 561 47 unpack f f f f f f f;
#X obj 547 296 clone -s 1 sampvoice 8;
#X text 18 410 The [poly] object essentially repeats pitch and velocity pairs to its output \, but also sending a voice number from its left outlet. To use it \, we unpack the 7 parameters \, calculate the voice number \, repack the message as 8 parameters with voice number first \, and [clone] routes to internal instances of the abstraction., f 61;
#X obj 546 512 print comment;
#X msg 689 555 line 0 \, auto;
#X obj 520 590 text define -k seq;
#A set note 60 90 50 4 50 30 30 \; 15 note 60 \; 15 note 60 \; 15 note 60 \; 15 note 60 \; 15 note 60 \; 15 note 60 \; 15 note 60 \; 15 note 60 \; 15 note 60 \; 15 note 60 \; 15 note 60 \; 15 note 60 \; 15 note 60 \; 15 note 60 \; 15 note 60 \; 15 note 60 \; 15 note 60 \; 100 note 59 90 100 \; comment measure 1 \; 100 note 60 90 150 4 0 \; note 36 90 200 4 50 \; 200 note 48 90 250 4 0 \; note 40 90 200 4 50 \; note 43 90 200 4 50 \; 200 note 48 90 250 4 0 \; note 31 90 200 4 50 \; 200 note 55 90 100 \; note 41 90 200 \; note 43 90 200 \; 100 note 53 90 100 \; 100 note 52 90 100 \; note 36 90 200 \; 100 note 55 90 100 \; 100 note 60 90 100 \; note 40 90 200 \; note 43 90 200 \; 100 note 59 90 100 \; 100 note 60 90 100 \; note 25 90 200 \; 100 note 64 90 100 \; 100 note 62 90 100 \; note 39 90 200 \; note 43 90 200 \; 100 note 61 90 100 \; comment measure 2 \; 100 note 62 90 150 4 0 \; note 26 90 200 \; 200 note 50 90 250 4 50 \; note 41 90 200 \; note 42 90 200 \; 200 note 50 90 250 \; note 29 90 200 \; 200 note 50 90 100 \; note 30 90 200 \; note 44 90 200 \; note 48 90 200 \; 100 note 48 90 100 \; 100 note 47 90 100 \; note 31 90 200 \; note 43 90 200 \; note 47 90 200 \; 100 note 50 90 100 \; 100 note 55 90 100 \; note 34 90 200 \; note 42 90 200 \; note 46 90 200 \; 100 note 54 90 100 \; 100 note 55 90 200 \; note 35 90 200 \; note 42 90 200 \; note 45 90 200 \; 200 note 57 90 100 \; note 41 90 200 \; note 47 90 200 \; 100 note 59 90 100 \; comment measure 3 \; 100 note 60 90 100 \; note 24 90 200 \; note 40 90 200 \; note 48 90 200 4 0 \; 100 note 59 90 100 4 50 \; 100 note 57 90 100 \; 100 note 55 90 100 \; 100 note 57 90 100 \; note 28 90 200 \; note 38 90 200 \; note 46 90 200 \; 100 note 55 90 100 \; 100 note 53 90 100 \; 100 note 52 90 100 \; 100 note 53 90 100 \; note 29 90 100 \; note 36 90 100 \; note 45 90 100 \; 100 note 52 90 100 \; 100 note 50 90 100 \; note 29 90 300 \; note 36 90 300 \; note 45 90 300 \; 100 note 48 90 100 \; 100 note 50 90 100 \; 100 note 48 90 100 \; 100 note 47 90 100 \; note 29 90 300 \; note 38 90 300 \; note 44 90 300 4 0 \; 100 note 45 90 100 4 50 \; comment measure 4 \; 100 note 43 90 100 \; note 31 90 200 \; note 38 90 200 \; 100 note 48 90 100 \; 100 note 47 90 100 \; note 31 90 300 \; note 40 90 300 \; note 43 90 300 4 0 \; 100 note 50 90 100 4 50 \; 100 note 48 90 100 \; 100 note 52 90 100 \; 100 note 50 90 100 \; note 31 90 300 4 0 \; note 41 90 300 \; note 43 90 300 \; 100 note 53 90 100 4 50 \; 100 note 52 90 200 \; note 31 90 300 4 50 \; 200 note 48 90 200 \; note 19 90 200 4 50 \; note 29 90 200 4 50 \; note 36 90 200 4 50 \; 200 note 48 90 100 4 50 0 4000 \; note 12 90 300 \; note 28 90 300 \; note 36 90 300 \;;
#X obj 689 599 text sequence seq -g;
#X text 782 555 <--;
#X text 532 564 click to open:;
#X text 688 333 Lashed to the mast of his boat \, Ulysses hears beautiful singing. He begs his sailors to untie him..., f 35;
#X text 245 110 increment with [mod 1e+06] to make a note tag (acts like a MIDI pitch to identify the note to [poly]), f 29;
#X text 18 276 Here we take the previous patch and make it polyphonic \, with 8 voices. The single voice which we had before has been made into an abstraction \, [sampvoice] \, which we instantiate in 8 copies with the [clone] object. Earlier we used sends and receives to pass messages to "cutoff" \, etc \, but here if we did that the copies of [sampvoice] would be sending messages to each other \, so we combine the control and the audio computation in the [sampvoice] abstraction without using send and receive. Click on [clone] one to see how., f 61;
#X text 18 502 There's some bother because [poly] expects to track note on and note off messages separately as they would come from a MIDI keyboard. So we assign each note a unique fake "pitch" \, use [makenote] to generate the note-off messages \, and run [poly] on the resulting stream. We then discard both pitch and velocity for the note offs with [stripnoe] (using the velocity only to strip note-offs) and rebuild the original message adding the voice number we just scored., f 61;
#X obj 74 24 cnv 5 5 25 empty empty Polyphonic\ Sampler 15 13 0 16 #dfdfdf #202020 0;
#N canvas 446 297 961 453 init-samples 0;
#X obj 218 34 inlet;
#X obj 128 258 adc~ 1;
#X obj 128 286 hip~ 5;
#X obj 197 316 line~;
#X obj 128 315 *~;
#X msg 197 288 1;
#X obj 256 253 del 3990;
#X msg 233 288 0 10;
#X obj 128 366 tabwrite~ sample3;
#X msg 42 220 set \$1 \, bang;
#X msg 300 224 stop;
#X msg 256 224 bang;
#X obj 382 226 loadbang;
#X obj 378 128 openpanel;
#X text 422 265 v-- re-read original samples;
#X obj 218 63 route record stop reload browse;
#X obj 382 347 soundfiler;
#X msg 378 155 read \$1 sample3;
#X obj 378 182 soundfiler;
#X obj 378 99 bng 19 250 50 0 empty empty empty 0 -10 0 12 #dfdfdf #000000 #000000;
#X text 406 99 <-- browse for samples;
#X obj 513 351 declare -stdpath ./;
#X msg 382 288 read ../sound/bell.aiff sample3 \, read ../sound/voice2.wav sample4, f 33;
#N canvas 0 0 450 300 (subpatch) 0;
#X array sample3 176400 float 2;
#X coords 0 1.02 176400 -1.02 200 130 1;
#X restore 708 73 graph;
#N canvas 0 0 450 300 (subpatch) 0;
#X array sample4 176400 float 2;
#X coords 0 1.02 176400 -1.02 200 130 1;
#X restore 707 240 graph;
#X obj 42 191 makefilename sample%d;
#X connect 0 0 15 0;
#X connect 1 0 2 0;
#X connect 2 0 4 0;
#X connect 3 0 4 1;
#X connect 4 0 8 0;
#X connect 5 0 3 0;
#X connect 6 0 7 0;
#X connect 7 0 3 0;
#X connect 9 0 8 0;
#X connect 10 0 6 0;
#X connect 11 0 6 0;
#X connect 12 0 22 0;
#X connect 13 0 17 0;
#X connect 15 0 11 0;
#X connect 15 0 5 0;
#X connect 15 0 25 0;
#X connect 15 1 7 0;
#X connect 15 1 10 0;
#X connect 15 2 22 0;
#X connect 15 3 19 0;
#X connect 17 0 18 0;
#X connect 19 0 13 0;
#X connect 22 0 16 0;
#X connect 25 0 9 0;
#X restore 780 231 pd init-samples;
#X text 514 412 You can use the [qlist] to read a text file or the more modern [text sequence] object that can save its contents with the patch.;
#X msg 689 469 read qlist-sampler.txt \, rewind \, bang, f 23;
#X text 868 465 <- read \, rewind & start, f 8;
#X text 811 551 rewind and start (automatically), f 16;
#X connect 8 0 29 0;
#X connect 9 0 10 0;
#X connect 9 1 28 1;
#X connect 10 0 11 0;
#X connect 10 0 13 0;
#X connect 11 0 12 0;
#X connect 12 0 10 1;
#X connect 13 0 14 0;
#X connect 13 1 14 1;
#X connect 14 0 15 0;
#X connect 14 2 15 1;
#X connect 15 0 28 0;
#X connect 20 0 32 0;
#X connect 23 0 43 0;
#X connect 24 0 43 0;
#X connect 25 0 43 0;
#X connect 26 0 43 0;
#X connect 27 0 43 0;
#X connect 28 0 30 0;
#X connect 29 0 9 0;
#X connect 29 1 28 2;
#X connect 29 2 13 2;
#X connect 29 2 28 3;
#X connect 29 3 28 4;
#X connect 29 4 28 5;
#X connect 29 5 28 6;
#X connect 29 6 28 7;
#X connect 30 0 21 0;
#X connect 33 0 35 0;
#X connect 45 0 19 0;
