MidiKeyboard - holding a key triggers multiple note-ons

UPDATE: It might be appropriate to move this to the Linux section. I compiled the same code under WinXP and the problem was gone. So it is a Linux specific problem with the keyboard handling. I checked out juce_linux_Windowing.cpp file, in an attempt to figure out the problem, but it has 2500 lines of code and is way over my head as of now… :frowning:


I am trying to use the MidiKeyboardComponent together with MidiKeyboardState. I added handleNoteOn and handleNoteOff functions to my class which derives from MidiKeyboardStateListener. In those functions I (obviously) send out midi note on/off messages.

My problem is that when I hold a key on the computer keyboard, it triggers multiple note on/off messages (strangely, note offs are also triggered). I.e. handleNoteOn and handleNoteOff both are triggered multiple times (same as repeating letters when you hold down a key). I expected that when I hold down a key, only handleNoteOn is called, and when I release the key, handleNoteOff will be called.

Any ideas? What am I doing wrong? I thought the MidiKeyboardState class could handle stuff like this … Otherwise I will use a map or set to keep track of which keys are down to avoid triggering multiple noteon/offs. The whole code is here, if you want to take a look: http://virtual-midi-keyboard.googlecode.com/svn/trunk/main.cpp

I’m using Juce 1.40 under Linux.



(wish I had some answers to offer, but I’ve not done anything with JUCE’s MIDI classes).

i’m having exactly the same problem. at the moment i haven’t time to focus on this, but sure i have to address the problem later on before i publish my project.
i think on linux (but maybe i’m wrong), the KeyPress event is sent repeatedly when the key is pressed. You should look in juce_linux_Windowing.cpp when in the LinuxComponentPeer::handleMessage it handle the keypress, make a trace there, and see what happens if you keep the key pressed for a while…