History

fix no audio device from previously removed audio device

ZappoMan committed 9 years ago

Commit d3521631 parent 035a9e83 files · +27 −4Browse files

Showing the changes to interface/src/scripting/AudioDeviceScriptingInterface.cpp (1 of 3 files). Show all

Unified · Split

interface/src/scripting/AudioDeviceScriptingInterface.cpp+20−4
@@ -48,15 +48,31 @@ AudioDeviceScriptingInterface::AudioDeviceScriptingInterface(): QAbstractListMod · 47 unmodified lines
4848 SettingsScriptingInterface* settings = SettingsScriptingInterface::getInstance();
4949 const QString inDevice = settings->getValue("audio_input_device", _currentInputDevice).toString();
5050 if (inDevice != _currentInputDevice) {
51− qCDebug(audioclient) << __FUNCTION__ << "about to call setInputDeviceAsync() device: [" << inDevice << "] _currentInputDevice:" << _currentInputDevice;
52− setInputDeviceAsync(inDevice);
51+ // before using the old setting, check to make sure the device still exists....
52+ bool inDeviceExists = DependencyManager::get<AudioClient>()->getNamedAudioDeviceForModeExists(QAudio::AudioInput, inDevice);
53+
54+ if (inDeviceExists) {
55+ qCDebug(audioclient) << __FUNCTION__ << "about to call setInputDeviceAsync() device: [" << inDevice << "] _currentInputDevice:" << _currentInputDevice;
56+ setInputDeviceAsync(inDevice);
57+ } else {
58+ qCDebug(audioclient) << __FUNCTION__ << "previously selected device no longer exists inDevice: [" << inDevice << "] keeping device _currentInputDevice:" << _currentInputDevice;
59+ }
5360 }
5461
5562 // If the audio_output_device setting is not available, use the _currentOutputDevice
5663 auto outDevice = settings->getValue("audio_output_device", _currentOutputDevice).toString();
64+
5765 if (outDevice != _currentOutputDevice) {
58− qCDebug(audioclient) << __FUNCTION__ << "about to call setOutputDeviceAsync() outDevice: [" << outDevice << "] _currentOutputDevice:" << _currentOutputDevice;
59− setOutputDeviceAsync(outDevice);
66+ // before using the old setting, check to make sure the device still exists....
67+ bool outDeviceExists = DependencyManager::get<AudioClient>()->getNamedAudioDeviceForModeExists(QAudio::AudioOutput, outDevice);
68+
69+ if (outDeviceExists) {
70+ qCDebug(audioclient) << __FUNCTION__ << "about to call setOutputDeviceAsync() outDevice: [" << outDevice << "] _currentOutputDevice:" << _currentOutputDevice;
71+ setOutputDeviceAsync(outDevice);
72+ } else {
73+ qCDebug(audioclient) << __FUNCTION__ << "previously selected device no longer exists outDevice: [" << outDevice << "] keeping device _currentOutputDevice:" << _currentOutputDevice;
74+ }
75+
6076 }
6177 }
6278