diff --git a/modules/juce_audio_utils/gui/juce_AudioDeviceSelectorComponent.cpp b/modules/juce_audio_utils/gui/juce_AudioDeviceSelectorComponent.cpp index 2e0f4bc740..131ebe3861 100644 --- a/modules/juce_audio_utils/gui/juce_AudioDeviceSelectorComponent.cpp +++ b/modules/juce_audio_utils/gui/juce_AudioDeviceSelectorComponent.cpp @@ -439,9 +439,8 @@ public: error = setup.manager->setAudioDeviceSetup (config, true); - showCorrectDeviceName (inputDeviceDropDown.get(), true); - showCorrectDeviceName (outputDeviceDropDown.get(), false); - + updateSelectedInput(); + updateSelectedOutput(); updateControlPanelButton(); resized(); } @@ -610,18 +609,34 @@ private: std::unique_ptr inputLevelMeter; std::unique_ptr 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) { - if (box != nullptr) - { - auto* currentDevice = setup.manager->getCurrentAudioDevice(); - auto index = type.getIndexOfDevice (currentDevice, isInput); + if (box == nullptr) + return; - box->setSelectedId (index < 0 ? index : index + 1, dontSendNotification); - - if (testButton != nullptr && ! isInput) - testButton->setEnabled (index >= 0); - } + const auto index = findSelectedDeviceIndex (isInput); + box->setSelectedId (index < 0 ? index : index + 1, dontSendNotification); } void addNamesToDeviceBox (ComboBox& combo, bool isInputs) @@ -711,7 +726,7 @@ private: addNamesToDeviceBox (*outputDeviceDropDown, false); } - showCorrectDeviceName (outputDeviceDropDown.get(), false); + updateSelectedOutput(); } void updateInputsComboBox() @@ -734,7 +749,7 @@ private: addNamesToDeviceBox (*inputDeviceDropDown, true); } - showCorrectDeviceName (inputDeviceDropDown.get(), true); + updateSelectedInput(); } void updateSampleRateComboBox (AudioIODevice* currentDevice)