#N canvas 459 95 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 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 444 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 msg 52 231 72 \$1;
#X msg 99 231 74 \$1;
#X msg 146 231 77 \$1;
#X msg 194 231 81 \$1;
#N canvas 661 49 444 661 monophonic 0;
#X obj 163 454 output~;
#X obj 171 240 notein;
#X obj 163 354 osc~;
#X obj 163 393 *~;
#X obj 163 318 mtof;
#X obj 209 416 pow~ 4;
#X obj 209 311 / 127;
#X obj 209 377 line~;
#X msg 209 341 \$1 150;
#X obj 137 274 poly 1 1;
#X obj 232 131 tgl 19 0 empty empty empty 17 7 0 10 #dfdfdf #000000 #000000 0 64;
#X obj 90 131 tgl 19 0 empty empty empty 17 7 0 10 #dfdfdf #000000 #000000 0 64;
#X obj 137 131 tgl 19 0 empty empty empty 17 7 0 10 #dfdfdf #000000 #000000 0 64;
#X obj 184 131 tgl 19 0 empty empty empty 17 7 0 10 #dfdfdf #000000 #000000 0 64;
#X msg 90 157 72 \$1;
#X msg 184 157 77 \$1;
#X msg 232 157 81 \$1;
#X listbox 137 207 10 0 0 0 - - - 0;
#X msg 137 157 74 \$1;
#X text 33 19 If you set [poly] to a single voice you can make it manage a monophonic synth control a single polyhonic synth. Without this minimum management you may end up getting undesired note off messages from releasing keys that were previously pressed instead from the currently pressed one., f 50;
#X text 59 542 Note however that some monophonic synths may have a more sophisticated management where it goes back to the previously pressed key (if you're still pressing it) \, but [poly] can only manage this in a much simpler way., f 45;
#X text 228 233 you can also try your MIDI keyboard., f 19;
#X connect 1 0 9 0;
#X connect 1 1 9 1;
#X connect 2 0 3 0;
#X connect 3 0 0 0;
#X connect 4 0 2 0;
#X connect 5 0 3 1;
#X connect 6 0 8 0;
#X connect 7 0 5 0;
#X connect 8 0 7 0;
#X connect 9 1 4 0;
#X connect 9 2 6 0;
#X connect 10 0 16 0;
#X connect 11 0 14 0;
#X connect 12 0 18 0;
#X connect 13 0 15 0;
#X connect 14 0 17 0;
#X connect 15 0 17 0;
#X connect 16 0 17 0;
#X connect 17 0 9 0;
#X connect 18 0 17 0;
#X restore 444 419 pd monophonic;
#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 20 0;
#X connect 8 0 7 0;
#X connect 15 0 40 0;
#X connect 17 0 37 0;
#X connect 18 0 38 0;
#X connect 19 0 39 0;
#X connect 20 0 21 0;
#X connect 20 1 23 0;
#X connect 20 2 24 0;
#X connect 20 3 25 0;
#X connect 21 0 22 0;
#X connect 23 0 26 0;
#X connect 24 0 27 0;
#X connect 25 0 28 0;
#X connect 37 0 3 0;
#X connect 38 0 3 0;
#X connect 39 0 3 0;
#X connect 40 0 3 0;
