WinRT - Don't report BLE MIDI devices if they're not connected

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 (
        if (iter.getValue().containerID == info.containerID && !iter.getValue().isConnected)
            available = false;

    if (available)

Let me know what you guys think about this. There may well be cleaner solutions, but this is an easy starting point.

1 Like

Thanks for the code! I don’t think the IsConnected property of the device info is reliable enough to do this though. From some brief testing I’ve found that even though a BLE device can be paired and connected, the property is still false. @t0m is the expert on the WinRT MIDI stuff though and he’s on holiday until next week so I’d like to wait for him to confirm.

Totally! I’m sure you guys have more insight on the intricacies of the WinRT stuff.

Do you have that approach working with a BLE MIDI device? My experience was as Ed describes and the property either stays constant or mirrors the pairing state (which isn’t any more useful).

Things might have improved in the latest Windows update though…