Frank Barknecht wrote:
Attached is another way to get at keyboard data in Pd that is suited to be used to built a midi-keyboard from a standard PC keyboard. It involves an abstraction "keytrans.pd" which should be used with two argument as [keytrans <keyname> <midi note>] and will output a list of "<frequency> <keypress state as 0 or 1>" if the respective key passed as <keyname> is pressed or released. It's a good example for when an abstraction can save a lot of typing and connecting work.
Ciao
hi, nice work! i altered your keytrans.pd a little bit and added a retrigger-filter to it, in order to make it independent from changing the keyboard retrigger rate on the system and make it work out of the box. release-events for keys are only let through if no trigger-event for the same key occurs within 50 ms. this of course implies a 50 ms latency on releases, but on synths with a percussive envelope, this won't be too audible. the 50 ms delay work fine for me, but YMMV.
while experimenting with chords on the keyboard, i added 4 more voices to my local copy of the help/test-patch. i found that it is possible to play some 7-voice chords like 'asdfzhk' (interesting chord name ;) but some other keys would not combine as well, for example the only other key i could play in addition to 'fg' was 'z', other 3-voice chords based on 'fg' did not work. operating system weirdness? hardware weirdness? i don't know, but it renders a "polyphonic" pc-keyboard kinda useless for musical use if certain combinations of 3 notes aren't possible.
charlie
#N canvas 311 204 782 431 10; #X obj 195 55 keyname; #X obj 195 127 route $1; #X obj 274 287 f $2; #X obj 58 357 outlet; #X text 292 68 swap output of [keyname] to be a list: <keyname> <state> ; #X obj 195 106 list trim; #X text 294 102 trim the "list" selector; #X obj 58 61 inlet; #X text 28 34 pass-through trick to make connecting easier; #X obj 274 309 mtof; #X text 38 386 list <freq> <0|1>; #X obj 195 78 list prepend; #X obj 274 267 loadbang; #X obj 195 332 list prepend; #X text 308 322 prepend the desired frequency from a midi note passed as argument 2; #X text 294 118 wait for the key passed as first argument. Output after this stage is: 1 (down) or 0 (up) for the selected keyname.; #X obj 195 156 moses 1; #X msg 195 231 0; #X msg 232 185 stop; #X obj 195 186 b; #X obj 195 251 change; #X obj 195 210 delay 50; #X text 296 203 add latency to release events which are stopped again when a trigger event comes. the delay used here depends on your keyboard repeat rate , 50 ms works for me; #X connect 0 0 11 0; #X connect 0 1 11 1; #X connect 1 0 16 0; #X connect 2 0 9 0; #X connect 5 0 1 0; #X connect 7 0 3 0; #X connect 9 0 13 1; #X connect 11 0 5 0; #X connect 12 0 2 0; #X connect 13 0 3 0; #X connect 16 0 19 0; #X connect 16 1 18 0; #X connect 16 1 20 0; #X connect 17 0 20 0; #X connect 18 0 21 0; #X connect 19 0 21 0; #X connect 20 0 13 0; #X connect 21 0 17 0;