#N canvas 153 58 1094 665 12;
#X declare -stdpath ./;
#N canvas 642 163 417 426 samples 0;
#N canvas 0 0 450 300 (subpatch) 0;
#X array sample5 176403 float 0;
#X coords 0 1.02 176403 -1.02 200 130 1;
#X restore 116 45 graph;
#X text 125 352 ------ 4 seconds ------;
#N canvas 0 0 450 300 (subpatch) 0;
#X array sample6 176403 float 0;
#X coords 0 1.02 176403 -1.02 200 130 1;
#X restore 116 210 graph;
#X restore 481 531 pd samples;
#X text 745 463 sample number;
#X obj 542 118 poly 8 1;
#X obj 611 351 output~;
#X obj 542 143 swap;
#X obj 542 190 route 0;
#X obj 542 167 pack;
#X text 896 416 amplitude;
#X text 895 440 pitch;
#X text 814 349 ARGUMENTS FOR:;
#X text 747 391 pitch;
#X text 747 415 amplitude;
#X text 747 439 duration;
#X text 41 9 POLY SAMPLER \, VERSION 2 FOR SEPARATE NOTE-ON/OFF MESSAGES;
#X obj 597 56 r onoff;
#X text 895 373 ON/OFF TRANSITIONS:;
#X text 748 372 ENTIRE NOTES:;
#X text 895 395 tag;
#X text 745 490 sample onset;
#X text 745 516 rise time;
#X text 746 540 decay time;
#X text 892 465 (same other 4);
#X obj 773 154 f;
#X obj 809 154 + 1;
#X obj 783 180 mod 1e+06;
#X obj 854 60 r note;
#X obj 827 123 t b f;
#X obj 868 291 s onoff;
#X obj 822 236 pipe;
#X obj 822 259 pack;
#X msg 313 513 \; onoff 1 0;
#X msg 314 555 \; onoff 2 0;
#X text 29 146 Messages to "onoff" require a tag \, which is a number shared between the note-on and note-off message so that we can track down the voice to turn it off. If you're using MIDI input \, you can just re-use the pitch as a tag., f 67;
#X text 91 593 single messages to do both as before:;
#X obj 597 81 unpack f f f f f f f;
#X obj 611 250 pack f f f f f f f;
#X obj 854 86 unpack f f f f f f f;
#X obj 868 236 pack f f f f f f f;
#N canvas 333 157 708 551 recorder 0;
#X obj 152 363 adc~ 1;
#X obj 152 391 hip~ 5;
#X obj 221 421 line~;
#X obj 152 420 *~;
#X msg 221 393 1;
#X obj 280 358 del 3990;
#X msg 257 393 0 10;
#X obj 152 471 tabwrite~ sample5;
#X obj 66 296 makefilename sample%1;
#X msg 66 325 set \$1 \, bang;
#X msg 324 329 stop;
#X msg 280 329 bang;
#X obj 406 331 loadbang;
#X obj 402 233 openpanel;
#X msg 402 205 bang;
#X text 446 370 v-- re-read original samples;
#X obj 242 168 route record stop reload browse;
#X obj 406 452 soundfiler;
#X msg 406 394 read ../sound/bell.aiff sample5 \, read ../sound/voice2.wav sample6, f 33;
#X msg 402 260 read \$1 sample5;
#X obj 402 287 soundfiler;
#X text 440 205 <= browse for samples;
#X text 228 21 record \, etc.;
#X msg 242 48 record 1;
#X msg 256 92 stop;
#X msg 249 70 record 2;
#X msg 262 114 reload;
#X msg 267 136 browse;
#X connect 0 0 1 0;
#X connect 1 0 3 0;
#X connect 2 0 3 1;
#X connect 3 0 7 0;
#X connect 4 0 2 0;
#X connect 5 0 6 0;
#X connect 6 0 2 0;
#X connect 8 0 9 0;
#X connect 9 0 7 0;
#X connect 10 0 5 0;
#X connect 11 0 5 0;
#X connect 12 0 18 0;
#X connect 13 0 19 0;
#X connect 14 0 13 0;
#X connect 16 0 8 0;
#X connect 16 0 11 0;
#X connect 16 0 4 0;
#X connect 16 1 6 0;
#X connect 16 1 10 0;
#X connect 16 2 18 0;
#X connect 16 3 14 0;
#X connect 18 0 17 0;
#X connect 19 0 20 0;
#X connect 23 0 16 0;
#X connect 24 0 16 0;
#X connect 25 0 16 0;
#X connect 26 0 16 0;
#X connect 27 0 16 0;
#X restore 481 555 pd recorder;
#X obj 481 595 declare -stdpath ./;
#X obj 611 296 clone -s 1 sampvoice2 8;
#X msg 542 217 \$1 0;
#X msg 588 218 \$2;
#X text 822 606 updated for Pd version 0.52;
#X msg 93 513 \; onoff 1 90 60 5 0 0 100;
#X msg 94 555 \; onoff 2 90 48 5 0 0 100;
#X msg 94 612 \; note 51 90 1000 5 0 0 100;
#X text 92 493 separate messages for note on and off:;
#X text 30 39 Here is a variation on the polyphonic sampler \, which can take separate messages to start and stop notes (so that you can attach it to a MIDI keyboard \, for example.) "Note" messages act as before \, but in an intermediate step they are split onto note-on and note-off messages \, sent to "onoff". You can alternatively send messages straight to "onoff" if you don't know the duration in advance., f 67;
#X text 29 215 Messages to "onoff" whose amplitude is zero are note-off messages (the other parameters of note-off messages are ignored). The [sampvoice2] abstraction is a modification of [sampvoice] which looks at the amplitude field to decide whether to begin or end a note., f 67;
#X text 29 295 To convert "note" messages to pairs of "onoff" messages \, first a counter generates a tag. The [pipe] object delays a copy of the tag \, which the following [pack] object converts into a note-off message (a pair of numbers \, the tag and a zero.), f 67;
#X text 29 361 Under [r onoff] \, the [poly] object allocates a voice number \, putting it out paired with velocity. After swapping the two and packing them into a single message \, the amplitude is checked against zero by the [route 0] object. If zero \, the "\$1 0" message outputs a list with "voice number" and "0". Otherwise \, the "\$2" retrieves the voice number from [poly] which gets packed in with the note data and routed to the appropriate sampvoice2 [clone]., f 67;
#X connect 2 0 4 0;
#X connect 2 2 4 1;
#X connect 4 0 6 0;
#X connect 4 1 6 1;
#X connect 5 0 41 0;
#X connect 5 1 42 0;
#X connect 6 0 5 0;
#X connect 14 0 34 0;
#X connect 22 0 23 0;
#X connect 23 0 24 0;
#X connect 24 0 22 1;
#X connect 24 0 28 0;
#X connect 24 0 37 0;
#X connect 25 0 36 0;
#X connect 26 0 22 0;
#X connect 26 1 37 2;
#X connect 28 0 29 0;
#X connect 29 0 27 0;
#X connect 34 0 2 0;
#X connect 34 1 2 1;
#X connect 34 1 35 1;
#X connect 34 2 35 2;
#X connect 34 3 35 3;
#X connect 34 4 35 4;
#X connect 34 5 35 5;
#X connect 34 6 35 6;
#X connect 35 0 40 0;
#X connect 36 0 26 0;
#X connect 36 1 37 1;
#X connect 36 2 28 1;
#X connect 36 3 37 3;
#X connect 36 4 37 4;
#X connect 36 5 37 5;
#X connect 36 6 37 6;
#X connect 37 0 27 0;
#X connect 40 0 3 0;
#X connect 41 0 40 0;
#X connect 42 0 35 0;
