MIDIOutput close device

I’m a noob when it comes to c++ so apologies in advance if this question has an obvious answer.

I’ve been able to use a combo box select a MIDI output.

midiOutDev = MidiOutput::openDevice(midiOutputList.getSelectedId() - 1);

But I get a leak error on close. I get that I need to close the device but it’s not obvious to me how to do that.

I was able to get things to work by manipulating the default MIDI output with the audioDeviceManager but it seems like the program should grab an available device without changing the system default.


You need to take ownership of the pointer that’s returned by MidiOutput::openDevice() so instead of using a raw pointer for your midiOutDev member use std::unique_ptr<MidiOutput>. Your code would then look like:

midiOutDev.reset (MidiOutput::openDevice (midiOutputList.getSelectedId() - 1));

That worked!. Thanks so much.