[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] Re: Pygame not handling keyboard tracking correctly



Dear Pygame experts/enthusiasts around the world,

Having looked at some possible solutions on stackoverflow I optimized the code to this

#------------------- play keyboard via computer keyboard -------------------

if event.type is KEYDOWN:
x = event.unicode

if x in KEYLIST:
v.keyMIDInn = KEY_TO_MIDI_NN[x] + v.octave
player.note_on(v.keyMIDInn, 100,1) Â# play the note

for key in keyboard_full:
if v.keyMIDInn == key.midi_note_no:
key.key_select = True

if event.type is KEYUP:
x = event.unicode

if x in KEYLIST:
v.keyMIDInn = KEY_TO_MIDI_NN[x] + v.octave
player.note_off(v.keyMIDInn, 0,1)

for key in keyboard_full:
if v.keyMIDInn == key.midi_note_no:
key.key_select = False

Still, if I play the keyboard really fast there are stuck MIDI notes and stuck animations.
What could be the reason?
Any help is much appreciated.



On Sun, Jun 22, 2014 at 12:59 PM, diliup gabadamudalige <diliupg@xxxxxxxxx> wrote:
Below is my code
the indention is wrong here but in the program it is correct

            if event.type is KEYDOWN:
              Âx = check_chr_key(event.key) if x in KEYLIST: if x in KEY_TO_MIDI_NN: # if key in midi note dict v.keyMIDInn = KEY_TO_MIDI_NN[x] + v.octave player.note_on(v.keyMIDInn, 100,1) # play the note
for key in keyboard_full: if v.keyMIDInn == key.midi_note_no: key.key_select = True if event.type is KEYUP: x = check_chr_key(event.key) if x in KEYLIST: v.keyMIDInn = KEY_TO_MIDI_NN[x] + v.octave player.note_off(v.keyMIDInn, 0,1) for key in keyboard_full: if v.keyMIDInn == key.midi_note_no: key.key_select = False If I play the keyboard leisurely this works fine. But If I play the keyboard really fast
sometimes the MIDI notes get stuck and so does the Animation ( the stuck MIDI note shows the keyboard note as down)
I can't see anything wrong in the code. Is it that Pygame is not scanning the keyboard fast enough? What is the work around to this?

--
Diliup Gabadamudalige

http://www.diliupg.com
http://soft.diliupg.com/

**********************************************************************************************
This e-mail is confidential. It may also be legally privileged. If you are not the intended recipient or have received it in error, please delete it and all copies from your system and notify the sender immediately by return e-mail. Any unauthorized reading, reproducing, printing or further dissemination of this e-mail or its contents is strictly prohibited and may be unlawful. Internet communications cannot be guaranteed to be timely, secure, error or virus-free. The sender does not accept liability for any errors or omissions.
**********************************************************************************************




--
Diliup Gabadamudalige

http://www.diliupg.com
http://soft.diliupg.com/

**********************************************************************************************
This e-mail is confidential. It may also be legally privileged. If you are not the intended recipient or have received it in error, please delete it and all copies from your system and notify the sender immediately by return e-mail. Any unauthorized reading, reproducing, printing or further dissemination of this e-mail or its contents is strictly prohibited and may be unlawful. Internet communications cannot be guaranteed to be timely, secure, error or virus-free. The sender does not accept liability for any errors or omissions.
**********************************************************************************************