Advice using the AudioDeviceManager and MidiOutput classes correctly


I'm attempting to use an AudioDeviceManager object along with the AudioDeviceSelectorComponent to allow the user to select a device to send MIDI to.

Currently I'm using the following code to send a MIDI message:


 MidiMessage midiMessage = MidiMessage::programChange(1, 10);

//If midi output exists (it won't if the user hasn't chosen an output device...)
if (audioDeviceManager.getDefaultMidiOutput())

All works fine until I try to change the output device using the device selector component, which causes a Thread assertion error complaining that I'm trying to delete the MidiOutput object while it's thread is still running. However as this is handled within the AudioDeviceSelectorComponent, I don't know where I should be stopping the thread to prevent this error.

Where am I going wrong?



On further testing I've found that this is only an issue on OS X - just testing it on Windows and changing output devices seems to be fine. So maybe it is a bug?

Which assertion is it?

JUCE Assertion failure in juce_Thread.cpp:48 - on line 'jassert (! isThreadRunning());'

Ok, try again now..

Thanks Jules, all seems to be working now.

While we're on the subject, it is possible to set the AudioDeviceSelectorComponent to only display the MIDI I/O device components?

No.. don't think I ever had that as a possible use-case. Could be added, I guess..

If that could be added at some point that would be really useful to me.