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

AudioDeviceSelector: Fix a bug with the input and output device selectors

The bug presented when selecting none for either input or output, when
the opposite input or output was a device that had the same name for
both the input and output
This commit is contained in:
Anthony Nicholls 2024-04-26 17:15:22 +01:00
parent bce68c2b11
commit 2fc532ccac

View file

@ -439,9 +439,8 @@ public:
error = setup.manager->setAudioDeviceSetup (config, true); error = setup.manager->setAudioDeviceSetup (config, true);
showCorrectDeviceName (inputDeviceDropDown.get(), true); updateSelectedInput();
showCorrectDeviceName (outputDeviceDropDown.get(), false); updateSelectedOutput();
updateControlPanelButton(); updateControlPanelButton();
resized(); resized();
} }
@ -610,18 +609,34 @@ private:
std::unique_ptr<Component> inputLevelMeter; std::unique_ptr<Component> inputLevelMeter;
std::unique_ptr<TextButton> showUIButton, showAdvancedSettingsButton, resetDeviceButton; std::unique_ptr<TextButton> showUIButton, showAdvancedSettingsButton, resetDeviceButton;
int findSelectedDeviceIndex (bool isInput) const
{
const auto device = setup.manager->getAudioDeviceSetup();
const auto deviceName = isInput ? device.inputDeviceName : device.outputDeviceName;
return type.getDeviceNames (isInput).indexOf (deviceName);
}
void updateSelectedInput()
{
showCorrectDeviceName (inputDeviceDropDown.get(), true);
}
void updateSelectedOutput()
{
constexpr auto isInput = false;
showCorrectDeviceName (outputDeviceDropDown.get(), isInput);
if (testButton != nullptr)
testButton->setEnabled (findSelectedDeviceIndex (isInput) >= 0);
}
void showCorrectDeviceName (ComboBox* box, bool isInput) void showCorrectDeviceName (ComboBox* box, bool isInput)
{ {
if (box != nullptr) if (box == nullptr)
{ return;
auto* currentDevice = setup.manager->getCurrentAudioDevice();
auto index = type.getIndexOfDevice (currentDevice, isInput);
box->setSelectedId (index < 0 ? index : index + 1, dontSendNotification); const auto index = findSelectedDeviceIndex (isInput);
box->setSelectedId (index < 0 ? index : index + 1, dontSendNotification);
if (testButton != nullptr && ! isInput)
testButton->setEnabled (index >= 0);
}
} }
void addNamesToDeviceBox (ComboBox& combo, bool isInputs) void addNamesToDeviceBox (ComboBox& combo, bool isInputs)
@ -711,7 +726,7 @@ private:
addNamesToDeviceBox (*outputDeviceDropDown, false); addNamesToDeviceBox (*outputDeviceDropDown, false);
} }
showCorrectDeviceName (outputDeviceDropDown.get(), false); updateSelectedOutput();
} }
void updateInputsComboBox() void updateInputsComboBox()
@ -734,7 +749,7 @@ private:
addNamesToDeviceBox (*inputDeviceDropDown, true); addNamesToDeviceBox (*inputDeviceDropDown, true);
} }
showCorrectDeviceName (inputDeviceDropDown.get(), true); updateSelectedInput();
} }
void updateSampleRateComboBox (AudioIODevice* currentDevice) void updateSampleRateComboBox (AudioIODevice* currentDevice)