I think there is a bug in the MidiOutput on Linux.
If I have more than one MidiOutput device open and i send a message to output_a and a message to output_b, then both messages are physically received by the device 1 and not one at dev 1 and one at dev 2.
If i change the device for output_a to device 2, than both messages received by dev 2! (the commented out block)
Is my code wrong or is this a bug?
Cheers
EDIT: I have tested the same code on Windows: works.
EDIT: The correct connections will be create ("openDevice(1)" creates a connection to dev 1 and "openDevice(2)" creates a connection to dev 2, but only dev 1 receive the events)
EDIT: If i create new devices instead open it and connect the created dev 1 and 2 manually via QJackCtl or what ever: every thing works fine. Something with the openDevice handling is may be wrong.
EDIT NOTE in file juce_linux_Midi.cpp : >> static_cast <MidiOutputDevice*> (internal) << are different pointers for output_a and _b.
There are some global ALSA midi objects on linux, but TBH I didn't write the linux midi support myself, and don't have a suitable linux machine for testing it, so am not 100% sure what's going on there..
I am experiencing the same problem under Linux when trying to open two individual MIDI output devices. My code is similar to your test code, removing static works as a quickfix. Could you give me a hint on what you were doing wrong?
Here’s another fix. When calling createNewDevice, the alsa midi code created a whole new alsa client instead of just adding a new port to the existing client.
Without this patch, juce will call setName() every time you call openDevice, overriding the value you might have previously set calling setName().
In addition, the default client name was never set, unless you called openDevice at some point, causing the default name to be initially autocreated by ALSA.
A third thing the patch does is to name ports created by openDevice the same as the port names they are connected to, making it simpler to remember where ports where connected initially in case you connect ports manually afterwards. (this is a minor issue)
No, I was confusing the local AlsaClient::setName function with the MidiInput::setName / MidiOutput::setName functions. It seems like the author of the juce alsa midi code might have been confused about the same thing.
So the only change from the previous patch is to remove the AlsaClient::setName function, since it is only called from the constructor.
The last post was perhaps a bit confusing. Those two patches comes in addition to the first one. Totally in this thread, there’s three patches for alsa midi:
This patch includes the alsa port name into the juce device name. A “device” in JUCE is the combination
of “client” and “port” in Alsa, so it is necessary to include the port name into the device name. If not,
the user has to guess which device to use if a client has several ports.
This patch lets the alsa midi input thread run SCHED_RR/0. If not the messages are likely be delayed xx milliseconds before reaching the program.
BTW, I looked at the juce::Thread::setPriority function, to see if I could use that one instead of using pthread_setschedparam directly, but Thread::setPriority seems semi-broken for posix. In windows, setting priority to 5 would cause the thread to run at normal priority (which seems correct when reading the documentation), while on osx (I presume) and linux, priority 5 will cause the thread to run at SCHED_RR/50, which is a very high realtime priority.