1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

AudioDeviceManager: Avoid overwriting user-specified devices in initialise unless absolutely necessary

This fixes an issue where specifying an audio device type before calling
initialise could cause a different device to become active, even if the
requested device type had usable devices.

With this change in place, a new device type will only be selected if
the current device type has no devices.
This commit is contained in:
reuk 2021-11-04 11:29:39 +00:00
parent 6bf969dab9
commit 2fc254b72e
No known key found for this signature in database
GPG key ID: FCB43929F012EE5C

View file

@ -144,6 +144,10 @@ void AudioDeviceManager::pickCurrentDeviceTypeWithDevices()
|| ! ptr->getDeviceNames (false).isEmpty();
};
if (auto* type = findType (currentDeviceType))
if (deviceTypeHasDevices (type))
return;
const auto iter = std::find_if (availableDeviceTypes.begin(),
availableDeviceTypes.end(),
deviceTypeHasDevices);
@ -1399,6 +1403,32 @@ public:
expectEquals (newSetup.inputChannels.countNumberOfSetBits(), 2);
}
beginTest ("If a device type has been explicitly set to a type with devices, "
"initialisation should respect this choice");
{
AudioDeviceManager manager;
initialiseManagerWithEmptyDeviceType (manager);
manager.setCurrentAudioDeviceType (mockBName, true);
AudioDeviceManager::AudioDeviceSetup setup;
expect (manager.initialise (2, 2, nullptr, true, {}, &setup).isEmpty());
expectEquals (manager.getCurrentAudioDeviceType(), mockBName);
}
beginTest ("If a device type has been explicitly set to a type without devices, "
"initialisation should pick a type with devices instead");
{
AudioDeviceManager manager;
initialiseManagerWithEmptyDeviceType (manager);
manager.setCurrentAudioDeviceType (emptyName, true);
AudioDeviceManager::AudioDeviceSetup setup;
expect (manager.initialise (2, 2, nullptr, true, {}, &setup).isEmpty());
expectEquals (manager.getCurrentAudioDeviceType(), mockAName);
}
beginTest ("Carry out a long sequence of configuration changes");
{
AudioDeviceManager manager;