Hey guys. awesome to see the new ID-based MIDI device API in JUCE 5.4.4. I have a quick suggestion for improvements in the WinRT MIDI implementation.
In the current form, the getAvailableDevices
function includes all BLE MIDI devices that have been paired with the system even if they’re not currently connected. If you try to open a device that’s not connected, the operation will block the calling thread for a few seconds, and then return a nullptr.
Since we have access to the connection status of BLE MIDI devices, this can easily be avoided. It takes a slight modification to the MidiIODeviceWatcher
class. Namely:
- Keep a
const BLEDeviceWatcher&
member. - Replace the for-loop body in
getAvailableDevices()
with:
for (auto info : lastQueriedConnectedDevices.get())
{
bool available = true;
HashMap<String, BLEDeviceWatcher::DeviceInfo>::Iterator iter(bleDeviceWatcher.devices);
while (iter.next())
{
if (iter.getValue().containerID == info.containerID && !iter.getValue().isConnected)
{
available = false;
break;
}
}
if (available)
{
deviceNames.add(info.name);
deviceIDs.add(info.containerID);
}
}
Let me know what you guys think about this. There may well be cleaner solutions, but this is an easy starting point.