#N canvas 252 70 1075 759 12;
#X declare -stdpath ./;
#X text 55 617 sample number;
#X obj 548 133 poly 8 1;
#X obj 617 356 output~;
#X obj 548 158 swap;
#X obj 548 205 route 0;
#X obj 548 182 pack;
#X text 186 581 amplitude, f 16;
#X text 186 599 pitch, f 16;
#X text 109 516 ARGUMENTS FOR:;
#X text 55 563 pitch, f 13;
#X text 55 581 amplitude, f 13;
#X text 55 599 duration, f 13;
#X obj 603 71 r onoff;
#X text 165 545 ON/OFF TRANSITIONS:;
#X text 41 545 ENTIRE NOTES:, f 15;
#X text 186 563 tag, f 16;
#X text 55 635 sample onset, f 13;
#X text 55 653 rise time, f 13;
#X text 55 671 decay time, f 13;
#X text 186 617 (same other 4), f 16;
#X obj 789 169 f;
#X obj 825 169 + 1;
#X obj 799 195 mod 1e+06;
#X obj 870 75 r note;
#X obj 843 138 t b f;
#X obj 884 306 s onoff;
#X obj 838 251 pipe;
#X obj 838 274 pack;
#X msg 522 565 \; onoff 1 0;
#X msg 523 607 \; onoff 2 0;
#X text 35 161 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 reuse the pitch as a tag., f 67;
#X text 265 660 single messages to do both as before:, f 18;
#X obj 603 96 unpack f f f f f f f;
#X obj 617 265 pack f f f f f f f;
#X obj 870 101 unpack f f f f f f f;
#X obj 884 251 pack f f f f f f f;
#N canvas 659 253 685 450 recorder 0;
#X obj 146 273 adc~ 1;
#X obj 146 301 hip~ 5;
#X obj 215 331 line~;
#X obj 146 330 *~;
#X msg 215 303 1;
#X obj 274 268 del 3990;
#X msg 251 303 0 10;
#X obj 146 381 tabwrite~ sample5;
#X obj 60 206 makefilename sample%1;
#X msg 60 235 set \$1 \, bang;
#X msg 318 239 stop;
#X msg 274 239 bang;
#X obj 400 241 loadbang;
#X obj 396 143 openpanel;
#X text 440 280 v-- re-read original samples;
#X obj 236 78 route record stop reload browse;
#X obj 400 362 soundfiler;
#X msg 396 170 read \$1 sample5;
#X obj 396 197 soundfiler;
#X obj 396 111 bng 19 250 50 0 empty empty empty 0 -10 0 12 #dfdfdf #000000 #000000;
#X text 423 111 <-- browse for samples;
#X obj 236 43 inlet;
#X msg 400 304 read ../sound/bell.aiff sample5 \, read ../sound/voice2.wav sample6, f 32;
#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 22 0;
#X connect 13 0 17 0;
#X connect 15 0 8 0;
#X connect 15 0 11 0;
#X connect 15 0 4 0;
#X connect 15 1 6 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 21 0 15 0;
#X connect 22 0 16 0;
#X restore 871 510 pd recorder;
#X obj 594 457 declare -stdpath ./;
#X obj 617 311 clone -s 1 sampvoice2 8;
#X msg 548 232 \$1 0;
#X msg 594 233 \$2;
#X msg 322 565 \; onoff 1 90 60 5 0 0 100;
#X msg 323 607 \; onoff 2 90 48 5 0 0 100;
#X msg 403 660 \; note 51 90 1000 5 0 0 100;
#X text 329 540 separate messages for note on and off:;
#X text 35 54 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 35 230 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 35 310 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 35 376 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] copy inside [clone]., f 67;
#X obj 20 11 cnv 5 5 25 empty empty Polyphonic\ Sampler\ with\ Separate\ Note-On/Off\ Messages 15 13 0 16 #dfdfdf #202020 0;
#X text 857 361 record \, etc.;
#X msg 871 388 record 1;
#X msg 885 432 stop;
#X msg 878 410 record 2;
#X msg 891 454 reload;
#X msg 896 476 browse;
#N canvas 0 0 450 300 (subpatch) 0;
#X array sample5 192000 float 2;
#A color 0;
#A width 2;
#X coords 0 1.02 192000 -1.02 200 130 1;
#X restore 635 577 graph;
#N canvas 0 0 450 300 (subpatch) 0;
#X array sample6 192000 float 2;
#A color 0;
#A width 2;
#X coords 0 1.02 192000 -1.02 200 130 1;
#X restore 842 579 graph;
#X connect 1 0 3 0;
#X connect 1 2 3 1;
#X connect 3 0 5 0;
#X connect 3 1 5 1;
#X connect 4 0 39 0;
#X connect 4 1 40 0;
#X connect 5 0 4 0;
#X connect 12 0 32 0;
#X connect 20 0 21 0;
#X connect 21 0 22 0;
#X connect 22 0 20 1;
#X connect 22 0 26 0;
#X connect 22 0 35 0;
#X connect 23 0 34 0;
#X connect 24 0 20 0;
#X connect 24 1 35 2;
#X connect 26 0 27 0;
#X connect 27 0 25 0;
#X connect 32 0 1 0;
#X connect 32 1 1 1;
#X connect 32 1 33 1;
#X connect 32 2 33 2;
#X connect 32 3 33 3;
#X connect 32 4 33 4;
#X connect 32 5 33 5;
#X connect 32 6 33 6;
#X connect 33 0 38 0;
#X connect 34 0 24 0;
#X connect 34 1 35 1;
#X connect 34 2 26 1;
#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 25 0;
#X connect 38 0 2 0;
#X connect 39 0 38 0;
#X connect 40 0 33 0;
#X connect 51 0 36 0;
#X connect 52 0 36 0;
#X connect 53 0 36 0;
#X connect 54 0 36 0;
#X connect 55 0 36 0;
