#N canvas 459 83 575 630 12;
#X declare -stdpath ./;
#X text 17 593 see also:;
#X obj 29 16 poly;
#X obj 95 594 makenote;
#X obj 111 402 poly 4 1;
#X msg 210 304 stop;
#X msg 204 275 clear;
#X text 68 16 - MIDI-style polyphonic voice allocator;
#X listbox 104 460 13 0 0 0 - - - 0;
#X obj 104 430 pack f f f;
#X text 249 276 clear memory;
#X text 248 305 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 699 162 467 445 reference 0;
#X obj 8 52 cnv 5 450 5 empty empty INLETS: 8 18 0 13 #202020 #000000 0;
#X obj 8 236 cnv 2 450 2 empty empty OUTLET: 8 12 0 13 #202020 #000000 0;
#X obj 8 357 cnv 2 450 2 empty empty ARGUMENTS: 8 12 0 13 #202020 #000000 0;
#X obj 7 424 cnv 5 450 5 empty empty empty 8 18 0 13 #202020 #000000 0;
#X obj 7 199 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 206 float - set velocity value., f 40;
#X obj 7 290 cnv 1 450 1 empty empty 2nd: 8 12 0 13 #7c7c7c #000000 0;
#X obj 7 260 cnv 1 450 1 empty empty 1st: 8 12 0 13 #7c7c7c #000000 0;
#X text 132 268 float - the voice number., f 40;
#X obj 7 320 cnv 1 450 1 empty empty 3rd: 8 12 0 13 #7c7c7c #000000 0;
#X text 62 379 1) float - number of voices (default 1)., f 43;
#X text 131 328 float - note velocity., f 40;
#X text 131 298 float - note pitch., f 40;
#X text 75 150 steal <float> -;
#X text 68 170 resize <float> -;
#X text 188 170 set number of voices., f 32;
#X text 187 150 turn voice stealing on/off., f 32;
#X text 62 397 2) float - non-zero sets to voice stealing (default 0).;
#X restore 383 17 pd reference;
#X text 477 17 <= click;
#X obj 10 577 cnv 1 550 1 empty empty empty 8 12 0 13 #000000 #000000 0;
#X text 248 227 <-- emulating note on/off messages;
#X obj 104 489 route 1 2 3 4, f 39;
#X listbox 104 517 7 0 0 0 - - - 0;
#X obj 104 544 print v1;
#X listbox 171 517 7 0 0 0 - - - 0;
#X listbox 239 517 7 0 0 0 - - - 0;
#X listbox 306 517 7 0 0 0 - - - 0;
#X obj 171 544 print v2;
#X obj 239 544 print v3;
#X obj 306 544 print v4;
#N canvas 707 76 425 614 clone 0;
#X listbox 191 378 13 0 0 0 - - - 0;
#X obj 191 348 pack f f f;
#X obj 191 448 output~;
#X obj 60 436 declare -stdpath ./, f 11;
#X obj 191 412 clone -s 1 clone-abs-c 4;
#X obj 191 314 poly 4 1;
#X obj 191 255 makenote 55 1500;
#X msg 158 189 60;
#X msg 191 189 62;
#X msg 228 189 65;
#X msg 269 189 69;
#X floatatom 191 227 5 0 0 0 - - - 0;
#X obj 203 283 notein;
#X text 33 102 An approach that is more useful in this case is to use [clone] to load copies of an abstraction \, see below. Here we use [makenote] but you can also try your MIDI keyboard input with [notein]., f 50;
#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 from 1)., f 43;
#X text 33 19 You'll usually want [poly] to control many copies (or multiple voices) of the same polyphonic synth patch. 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 50;
#X msg 109 260 resize \$1;
#X floatatom 109 237 5 1 100 0 - - - 0;
#X text 24 238 set number of voices, f 10;
#X connect 0 0 4 0;
#X connect 1 0 0 0;
#X connect 4 0 2 0;
#X connect 5 0 1 0;
#X connect 5 1 1 1;
#X connect 5 2 1 2;
#X connect 6 0 5 0;
#X connect 6 1 5 1;
#X connect 7 0 11 0;
#X connect 8 0 11 0;
#X connect 9 0 11 0;
#X connect 10 0 11 0;
#X connect 11 0 6 0;
#X connect 12 0 5 0;
#X connect 12 1 5 1;
#X connect 16 0 4 0;
#X connect 16 0 5 0;
#X connect 17 0 16 0;
#X restore 445 533 pd clone;
#X text 207 418 argument selects voice stealing;
#X obj 222 594 clone;
#X obj 164 594 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;
#N canvas 661 49 444 661 monophonic 0;
#X obj 163 472 output~;
#X obj 171 258 notein;
#X obj 163 372 osc~;
#X obj 163 411 *~;
#X obj 163 336 mtof;
#X obj 209 434 pow~ 4;
#X obj 209 329 / 127;
#X obj 209 395 line~;
#X msg 209 359 \$1 150;
#X obj 137 292 poly 1 1;
#X obj 232 149 tgl 19 0 empty empty empty 17 7 0 10 #dfdfdf #000000 #000000 0 64;
#X obj 90 149 tgl 19 0 empty empty empty 17 7 0 10 #dfdfdf #000000 #000000 0 64;
#X obj 137 149 tgl 19 0 empty empty empty 17 7 0 10 #dfdfdf #000000 #000000 0 64;
#X obj 184 149 tgl 19 0 empty empty empty 17 7 0 10 #dfdfdf #000000 #000000 0 64;
#X msg 90 175 72 \$1;
#X msg 184 175 77 \$1;
#X msg 232 175 81 \$1;
#X listbox 137 225 10 0 0 0 - - - 0;
#X msg 137 175 74 \$1;
#X text 59 560 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 251 you can also try your MIDI keyboard., f 19;
#X text 33 19 If you set [poly] to a single voice and voice stealing you can make it manage a monophonic synth. Without this minimum management you may end up getting undesired note off messages from releasing keys that were previously pressed instead of the note offs from the currently sounding key pressed for last., f 51;
#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 445 503 pd monophonic;
#X text 178 402 <-- first argument \, number of voices. Second;
#X msg 223 360 steal \$1;
#X obj 223 336 tgl 19 0 empty empty empty 17 7 0 10 #dfdfdf #000000 #000000 0 64;
#X text 290 361 voice stealing on/off;
#X msg 33 352 resize \$1;
#X floatatom 33 329 5 1 100 0 - - - 0;
#X text 23 294 set number of voices, f 10;
#X listbox 373 517 7 0 0 0 - - - 0;
#X text 340 593 updated for Pd version 0.56-0;
#X listbox 110 276 10 0 0 0 - - - 0;
#X obj 205 202 tgl 19 0 empty empty empty 17 7 0 10 #dfdfdf #000000 #000000 0 64;
#X obj 63 202 tgl 19 0 empty empty empty 17 7 0 10 #dfdfdf #000000 #000000 0 64;
#X obj 110 202 tgl 19 0 empty empty empty 17 7 0 10 #dfdfdf #000000 #000000 0 64;
#X obj 157 202 tgl 19 0 empty empty empty 17 7 0 10 #dfdfdf #000000 #000000 0 64;
#X msg 63 228 72 \$1;
#X msg 110 228 74 \$1;
#X msg 157 228 77 \$1;
#X msg 205 228 81 \$1;
#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 16 0;
#X connect 8 0 7 0;
#X connect 16 0 17 0;
#X connect 16 1 19 0;
#X connect 16 2 20 0;
#X connect 16 3 21 0;
#X connect 16 4 39 0;
#X connect 17 0 18 0;
#X connect 19 0 22 0;
#X connect 20 0 23 0;
#X connect 21 0 24 0;
#X connect 33 0 3 0;
#X connect 34 0 33 0;
#X connect 36 0 3 0;
#X connect 37 0 36 0;
#X connect 41 0 3 0;
#X connect 42 0 49 0;
#X connect 43 0 46 0;
#X connect 44 0 47 0;
#X connect 45 0 48 0;
#X connect 46 0 41 0;
#X connect 47 0 41 0;
#X connect 48 0 41 0;
#X connect 49 0 41 0;
