Bug in AudioDeviceManager::setDefaultMidiOutput


#1

Here’s the first few lines of the method:

if (defaultMidiOutputName != deviceName) { if (currentAudioDevice != 0) for (int i = callbacks.size(); --i >= 0;) callbacks.getUnchecked(i)->audioDeviceStopped();

Note that audioDeviceStopped has been called but the device is still open and hence issuing callbacks. This leads to audioIODeviceCallback with a zero sampleRate and a zero blockSize. It can be repro’d by changing the midi output device separately from the audio device.

Here’s a fix:

[code]void AudioDeviceManager::setDefaultMidiOutput (const String& deviceName)
{
if (defaultMidiOutputName != deviceName)
{

    closeAudioDevice();          // <---- add this line

    if (currentAudioDevice != 0)
        for (int i = callbacks.size(); --i >= 0;)
            callbacks.getUnchecked(i)->audioDeviceStopped();

    deleteAndZero (defaultMidiOutput);
    defaultMidiOutputName = deviceName;

    if (deviceName.isNotEmpty())
        defaultMidiOutput = MidiOutput::openDevice (MidiOutput::getDevices().indexOf (deviceName));

    if (currentAudioDevice != 0)
        for (int i = callbacks.size(); --i >= 0;)
            callbacks.getUnchecked(i)->audioDeviceAboutToStart (currentAudioDevice);

    restartLastAudioDevice();  // <---- add this line

    updateXml();
    sendChangeMessage (this);
}

}[/code]


#2

I actually just checked in a (slightly neater) fix for this a few days ago!