MIDI on Linux - Has anyone ever got it to work?


I’m extremely annoyed trying to get JUCE’s MidiOutput to work. This is now the second time I’ve tried it, on a completely different distro of Linux and I have exactly the same result, which makes me wonder if anyone have ever managed to get it to work.

I put a pair of printf() statements inside the sendMessageNow function to see if it was by any chance sending to the wrong MIDI port, and it seems that is the case:

Source Port: 0:0
Destination Port: 254:253

That port does not exist on my system, yet it’s “apparently” working. No sound though, not on my USB MIDI keyboard, not through TiMidity, nothing.

Here is the code I’m using to test:

midiOutput = MidiOutput::openDevice(2);
midiOutput->sendMessageNow(MidiMessage::noteOn(1, 64, 1.0f));

This opens the device with index #2, which on my system is listed as “USB Midi” by MidiOuput::getDevices(), so by opening that I can only assume it’s opening the USB MIDI device. The cable works, and is connected to my keyboard, which is turned on. So it’s certainly not human error.

sendMessageNow() should, as it’s name suggest, Send a Message Now. As in, when that is called, the little green light on my cable that says “I’m transmitting something to the keyboard” should flash, and the keyboard should turn on MIDI Note #64 at full velocity on channel 1.

But this simply isn’t happening. My printf() way of debugging shows that sendMessageNow in juce_amalgamated.cpp is getting called, and the last function that should perform the magic (snd_seq_drain_output()) is returning 0, which according to the ALSA documentation means it’s sent all the data and there is no more data to send, and because it’s not negative, it succeeded. So this seems to suggest that somewhere between my call to sendMessageNow() and that function, something isn’t right. But I can’t figure it out…

Further investigation reveals that JUCE seems to be creating it’s own ALSA device and sending to that instead?

Can someone please provide some sample code that works, or some kind of fix???

I found the “problem”!

JUCE does not automatically connect its ALSA output to the device. Which I’m pretty sure is a bug, since that means choosing which output device to open is completely redundant.

I’m going to take a look at the JUCE source and see if I can fix this myself…

Are you using the latest git version ?