MIDI Input stops working after sleep

If I create a basic setup of either MIDIInput or AudioDeviceManager, I can receive MIDI callbacks.

However, once I send my computer to sleep manually (using the Apple menu→sleep), I stop receiving the callbacks. Recreating the class instance fixes it.

A simplified example you can try in any JUCE GUI app:

juce::String getMidiDeviceByName(const juce::String& name)
{
    auto inputs = juce::MidiInput::getAvailableDevices();

    for (auto& input: inputs)
    {
        if (input.name.containsIgnoreCase(name))
            return input.identifier;
    }

    jassertfalse;
    return inputs[0].identifier;
}

struct MIDITestApp : juce::MidiInputCallback
{
    MIDITestApp()
    {
        auto device = getMidiDeviceByName("Hammer 88");

        dm.setMidiInputDeviceEnabled(device, true);
        dm.addMidiInputDeviceCallback(device, this);
    }

    void handleIncomingMidiMessage(juce::MidiInput*,
                                   const juce::MidiMessage&) override
    { DBG("MIDI Callback"); }

    juce::AudioDeviceManager dm;
};

This was only tested with MacOS 26.2.

Is there any way to resolve this?
I’d also be happy with a solution that notifies me on wakeup/sleep so I can fix it locally in my project.

Does the root JUCE app instance call suspend/resume when sleep/resume occurs?

Good question!

I added some logging and none of those are called.

However - I was able to get a Mac notification about it by writing some native code using NSWorkspaceDidWakeNotification.

Update: I was able to fix this (for my use case) by switching to use RTMIDI within my JUCE app. RTMIDI doesn’t show that behavior and can handle continuing the connection after sleep without any kind of listening to wake up events, at least from the ‘user’ side.

It would be nice if JUCE could also handle this situation.