#N canvas 420 23 567 557 12;
#X declare -stdpath ./;
#X text 16 519 see also:;
#X obj 29 16 poly;
#X obj 94 519 makenote;
#X obj 99 319 poly 4 1;
#X msg 211 285 stop;
#X msg 203 259 clear;
#X text 68 16 - MIDI-style polyphonic voice allocator;
#X listbox 92 379 13 0 0 0 - - - 0;
#X obj 92 349 pack f f f;
#X msg 52 231 60 \$1;
#X msg 99 231 62 \$1;
#X msg 146 231 65 \$1;
#X msg 194 231 69 \$1;
#X text 248 260 clear memory;
#X text 249 286 flush hanging note on messages;
#X obj 9 50 cnv 1 550 1 empty empty empty 8 12 0 13 #000000 #000000 0;
#N canvas 800 147 484 391 reference 0;
#X obj 8 52 cnv 5 450 5 empty empty INLETS: 8 18 0 13 #202020 #000000 0;
#X obj 8 192 cnv 2 450 2 empty empty OUTLET: 8 12 0 13 #202020 #000000 0;
#X obj 8 313 cnv 2 450 2 empty empty ARGUMENTS: 8 12 0 13 #202020 #000000 0;
#X obj 7 370 cnv 5 450 5 empty empty empty 8 18 0 13 #202020 #000000 0;
#X obj 7 155 cnv 1 450 1 empty empty 2nd: 8 12 0 13 #7c7c7c #000000 0;
#X obj 7 85 cnv 1 450 1 empty empty 1st: 8 12 0 13 #7c7c7c #000000 0;
#X obj 27 18 poly;
#X text 66 18 - MIDI-style polyphonic voice allocator.;
#X text 131 93 float - MIDI pitch value., f 40;
#X text 131 111 clear -;
#X text 187 111 clear memory., f 32;
#X text 138 129 stop -;
#X text 187 129 flush hanging note on messages., f 32;
#X text 132 162 float - set velocity value., f 40;
#X obj 7 246 cnv 1 450 1 empty empty 2nd: 8 12 0 13 #7c7c7c #000000 0;
#X obj 7 216 cnv 1 450 1 empty empty 1st: 8 12 0 13 #7c7c7c #000000 0;
#X text 132 224 float - the voice number., f 40;
#X obj 7 276 cnv 1 450 1 empty empty 3rd: 8 12 0 13 #7c7c7c #000000 0;
#X text 111 323 1) float - number of voices (default 1)., f 43;
#X text 111 341 2) float - non-zero sets to voice stealing.;
#X text 131 284 float - note velocity., f 40;
#X text 131 254 float - note pitch., f 40;
#X restore 383 17 pd reference;
#X text 477 17 <= click;
#X obj 9 506 cnv 1 550 1 empty empty empty 8 12 0 13 #000000 #000000 0;
#X obj 194 205 tgl 19 0 empty empty empty 17 7 0 10 #dfdfdf #000000 #000000 0 64;
#X text 237 230 <-- emulating note on/off messages;
#X obj 52 205 tgl 19 0 empty empty empty 17 7 0 10 #dfdfdf #000000 #000000 0 64;
#X obj 99 205 tgl 19 0 empty empty empty 17 7 0 10 #dfdfdf #000000 #000000 0 64;
#X obj 146 205 tgl 19 0 empty empty empty 17 7 0 10 #dfdfdf #000000 #000000 0 64;
#X obj 92 408 route 1 2 3 4, f 39;
#X listbox 92 436 7 0 0 0 - - - 0;
#X obj 92 463 print v1;
#X listbox 159 436 7 0 0 0 - - - 0;
#X listbox 227 436 7 0 0 0 - - - 0;
#X listbox 294 436 7 0 0 0 - - - 0;
#X obj 159 463 print v2;
#X obj 227 463 print v3;
#X obj 294 463 print v4;
#N canvas 662 49 425 614 clone 0;
#X text 33 19 You'll usually want [poly] to control a single polyhonic synth. The "route" method shown in the parent patch would then imply that you'd have the same subpatch or abstraction taking the note message., f 48;
#X listbox 181 370 13 0 0 0 - - - 0;
#X obj 181 338 pack f f f;
#X obj 181 438 output~;
#X obj 60 436 declare -stdpath ./, f 11;
#X obj 181 402 clone -s 1 clone-abs-c 4;
#X obj 181 304 poly 4 1;
#X text 65 532 In [clone] \, we use the "-s" flag to set the starting copy number to 1 \, so it matches the voice numbers from [poly] \, which is indexed by 1 as well., f 43;
#X obj 181 256 makenote 55 1500;
#X msg 111 188 60;
#X msg 144 188 62;
#X msg 181 188 65;
#X msg 222 188 69;
#X floatatom 181 226 5 0 0 0 - - - 0;
#X obj 119 256 notein;
#X text 33 102 An approach that is more useful in this case is using [clone] to load an abstraction \, see below. Here we use [makenote] but you can also try your MIDI keyboard input with [notein]., f 48;
#X connect 1 0 5 0;
#X connect 2 0 1 0;
#X connect 5 0 3 0;
#X connect 6 0 2 0;
#X connect 6 1 2 1;
#X connect 6 2 2 2;
#X connect 8 0 6 0;
#X connect 8 1 6 1;
#X connect 9 0 13 0;
#X connect 10 0 13 0;
#X connect 11 0 13 0;
#X connect 12 0 13 0;
#X connect 13 0 8 0;
#X connect 14 0 6 0;
#X connect 14 1 6 1;
#X restore 464 449 pd clone;
#X text 166 319 <-- first argument \, number of voices second;
#X text 195 335 argument selects voice stealing;
#X text 339 521 updated for Pd version 0.54-1;
#X obj 221 519 clone;
#X obj 163 518 notein;
#X text 40 62 The [poly] object takes pitch in the left inlet and velocity in the right inlet \, but the example here takes a list input \, which gets spread at inlets (as is common in Pd). The output is voice number (left outlet) \, pitch (mid outlet) and velocity (right outlet)., f 68;
#X text 39 125 You can pack the output and use the [route] object to route messages to different voices (as below) or feed it [clone] (see example in [pd clone]). The [poly] object can be configured to do voice stealing with the 2nd argument (the default is 'no stealing')., f 68;
#X connect 3 0 8 0;
#X connect 3 1 8 1;
#X connect 3 2 8 2;
#X connect 4 0 3 0;
#X connect 5 0 3 0;
#X connect 7 0 24 0;
#X connect 8 0 7 0;
#X connect 9 0 3 0;
#X connect 10 0 3 0;
#X connect 11 0 3 0;
#X connect 12 0 3 0;
#X connect 19 0 12 0;
#X connect 21 0 9 0;
#X connect 22 0 10 0;
#X connect 23 0 11 0;
#X connect 24 0 25 0;
#X connect 24 1 27 0;
#X connect 24 2 28 0;
#X connect 24 3 29 0;
#X connect 25 0 26 0;
#X connect 27 0 30 0;
#X connect 28 0 31 0;
#X connect 29 0 32 0;
