I’ve been told by several others that repeatedly polling GetDevices() has worked previously, but for me it does not reflect added or removed MIDI devices.
I’m not interested in proper add/remove callbacks which, although much more convenient, aren’t high priority.
I was beginning to think this was a CoreMIDI bug, but considering how Ableton Live or GarageBand updates their lists on the same platform, I fail to see why GetDevices() isn’t able to achieve the same functionality other than a missing call to something, somewhere. Thoughts?
We saw this once, because of a threading issue.
Mac OS uses a messaging system for updating this list, and so for this to happen someone has to read the messages.
When coding a single threaded utility command line utility where we never called the message pump, we noticed this behavior. If I recalled well, we solved this issue by calling MessageManager::runDispatchLoopUntil() or similar
I was using a TimeSliceThread to monitor for the changes. It looked like the MessageManager was running, but it seems like that thread was being blocked by the TimeSliceThread?
The solution is easy (user a timer), but even with MessageManagerLocks I couldn’t get it to go.
It’d be great if MidiInput had a Listener with insert / remove notifications and all this background thread business was neatly tucked away in a JUCE implementation (that works on all platforms).
Actually I am going to go ahead and put together an implementation in VFLib. I need this feature, and I know that Jules has a bunch of stuff to do. I should have something in relatively short order.
I see a problem. What happens if the device gets disconnected and reconnected before the periodic re-scan of the device list occurs? The MidiInput and MidiOutput objects have to expose some functionality that shows when the operating-system specific connection has been broken (perhaps by detecting an error code).
On Mac OS X, there is the MIDINotifyProc. It tells you that the MIDI setup has changed.
Unfortunately, I don’t think there is a Windows equivalent. Maybe something at the USB level.
[quote=“ke20”]On Mac OS X, there is the MIDINotifyProc. It tells you that the MIDI setup has changed.
Unfortunately, I don’t think there is a Windows equivalent. Maybe something at the USB level.[/quote]
I spent all day trying to figure out a way to do something on Windows but there is nothing. The Windows MIDI API truly sucks. The USB API would probably be the way to go.
Did you look into KS Midi?
Maybe if we are lucky the hardware is given a unique GUID each time it is connected? Or maybe that’s just wishful thinking. Ace17 will probably know the answer to that.
Well I just looked over the code in that repository and it uses RtMidi, which calls midiGetNumDevs() and midiInOpen() both of which refer to devices by index and not a unique ID.
I think you are referring to the MME code in RtMidi.cpp at line 2528.
I was talking about the KS Midi code in RtMidi.cpp at line 3569 which uses the KS Midi code which Ace17 wrote.
[quote=“sonic59”]I think you are referring to the MME code in RtMidi.cpp at line 2528.
I was talking about the KS Midi code in RtMidi.cpp at line 3569 which uses the KS Midi code which Ace17 wrote.[/quote]
All true. Okay, so KS uses the “Direct Kernel Streaming” API. This could be an interesting alternative but it is listed under “legacy interfaces.”
Well one could argue that MME and DirectMusic are legacy interfaces as well.
As I understand it, MME and DirectMusic are user-mode MIDI API’s built on top of the kernel-mode KS API.