Advice using the AudioDeviceManager and MidiOutput classes correctly


#1

Hey

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())
{
   audioDeviceManager.getDefaultMidiOutput()->startBackgroundThread();
   
   audioDeviceManager.getDefaultMidiOutput()->sendBlockOfMessages(MidiBuffer(midiMessage),
                                                                  Time::getMillisecondCounter(), 
                                                                  44100);
}

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?

Thanks.

 


#2

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?


#3

Which assertion is it?


#4

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


#5

Ok, try again now..


#6

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?


#7

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


#8

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

Thanks.