diff --git a/src/audio/audio.cpp b/src/audio/audio.cpp index 3d517af9b..9757fa647 100644 --- a/src/audio/audio.cpp +++ b/src/audio/audio.cpp @@ -320,7 +320,7 @@ bool Audio::autoInitOutput() bool Audio::initInput(const QString& deviceName) { - if (deviceName.toLower() == QStringLiteral("none")) + if (!Settings::getInstance().getAudioInDevEnabled()) return false; qDebug() << "Opening audio input" << deviceName; @@ -363,7 +363,7 @@ bool Audio::initOutput(const QString& deviceName) outSources.clear(); outputInitialized = false; - if (deviceName.toLower() == QStringLiteral("none")) + if (!Settings::getInstance().getAudioOutDevEnabled()) return false; qDebug() << "Opening audio output" << deviceName; diff --git a/src/persistence/settings.cpp b/src/persistence/settings.cpp index efa86342f..8c7ff971b 100644 --- a/src/persistence/settings.cpp +++ b/src/persistence/settings.cpp @@ -242,7 +242,9 @@ void Settings::loadGlobal() s.beginGroup("Audio"); inDev = s.value("inDev", "").toString(); + audioInDevEnabled = s.value("audioInDevEnabled", true).toBool(); outDev = s.value("outDev", "").toString(); + audioOutDevEnabled = s.value("audioOutDevEnabled", true).toBool(); audioInGainDecibel = s.value("inGain", 0).toReal(); outVolume = s.value("outVolume", 100).toInt(); s.endGroup(); @@ -478,7 +480,9 @@ void Settings::saveGlobal() s.beginGroup("Audio"); s.setValue("inDev", inDev); + s.setValue("audioInDevEnabled", audioInDevEnabled); s.setValue("outDev", outDev); + s.setValue("audioOutDevEnabled", audioOutDevEnabled); s.setValue("inGain", audioInGainDecibel); s.setValue("outVolume", outVolume); s.endGroup(); @@ -1389,6 +1393,18 @@ void Settings::setInDev(const QString& deviceSpecifier) inDev = deviceSpecifier; } +bool Settings::getAudioInDevEnabled() const +{ + QMutexLocker locker(&bigLock); + return audioInDevEnabled; +} + +void Settings::setAudioInDevEnabled(bool enabled) +{ + QMutexLocker locker(&bigLock); + audioInDevEnabled = enabled; +} + qreal Settings::getAudioInGain() const { QMutexLocker locker{&bigLock}; @@ -1425,6 +1441,18 @@ void Settings::setOutDev(const QString& deviceSpecifier) outDev = deviceSpecifier; } +bool Settings::getAudioOutDevEnabled() const +{ + QMutexLocker locker(&bigLock); + return audioOutDevEnabled; +} + +void Settings::setAudioOutDevEnabled(bool enabled) +{ + QMutexLocker locker(&bigLock); + audioOutDevEnabled = enabled; +} + int Settings::getOutVolume() const { QMutexLocker locker{&bigLock}; diff --git a/src/persistence/settings.h b/src/persistence/settings.h index 6a3fd429a..412e058ad 100644 --- a/src/persistence/settings.h +++ b/src/persistence/settings.h @@ -179,9 +179,15 @@ public: QString getInDev() const; void setInDev(const QString& deviceSpecifier); + bool getAudioInDevEnabled() const; + void setAudioInDevEnabled(bool enabled); + QString getOutDev() const; void setOutDev(const QString& deviceSpecifier); + bool getAudioOutDevEnabled() const; + void setAudioOutDevEnabled(bool enabled); + qreal getAudioInGain() const; void setAudioInGain(qreal dB); @@ -433,8 +439,10 @@ private: // Audio QString inDev; - QString outDev; + bool audioInDevEnabled; qreal audioInGainDecibel; + QString outDev; + bool audioOutDevEnabled; int outVolume; // Video diff --git a/src/widget/form/settings/avform.cpp b/src/widget/form/settings/avform.cpp index 0a04d7c7b..cbd720f2d 100644 --- a/src/widget/form/settings/avform.cpp +++ b/src/widget/form/settings/avform.cpp @@ -345,36 +345,42 @@ void AVForm::getVideoDevices() void AVForm::getAudioInDevices() { QStringList deviceNames; - deviceNames << tr("None") << Audio::inDeviceNames(); + deviceNames << tr("Disabled") << Audio::inDeviceNames(); bodyUI->inDevCombobox->blockSignals(true); bodyUI->inDevCombobox->clear(); bodyUI->inDevCombobox->addItems(deviceNames); bodyUI->inDevCombobox->blockSignals(false); - int idx = deviceNames.indexOf(Settings::getInstance().getInDev()); - bodyUI->inDevCombobox->setCurrentIndex(idx > 0 ? idx : 0); + int idx = Settings::getInstance().getAudioInDevEnabled() + ? deviceNames.indexOf(Settings::getInstance().getInDev()) + : 0; + bodyUI->inDevCombobox->setCurrentIndex(idx < 0 ? 1 : idx); } void AVForm::getAudioOutDevices() { QStringList deviceNames; - deviceNames << tr("None") << Audio::outDeviceNames(); + deviceNames << tr("Disabled") << Audio::outDeviceNames(); bodyUI->outDevCombobox->blockSignals(true); bodyUI->outDevCombobox->clear(); bodyUI->outDevCombobox->addItems(deviceNames); bodyUI->outDevCombobox->blockSignals(false); - int idx = deviceNames.indexOf(Settings::getInstance().getOutDev()); - bodyUI->outDevCombobox->setCurrentIndex(idx > 0 ? idx : 0); + int idx = Settings::getInstance().getAudioOutDevEnabled() + ? deviceNames.indexOf(Settings::getInstance().getOutDev()) + : 0; + bodyUI->outDevCombobox->setCurrentIndex(idx < 0 ? 1 : idx); } void AVForm::onAudioInDevChanged(int deviceIndex) { - QString deviceName = deviceIndex > 0 - ? bodyUI->inDevCombobox->itemText(deviceIndex) - : QStringLiteral("none"); + Settings::getInstance().setAudioInDevEnabled(deviceIndex != 0); + + QString deviceName; + if (deviceIndex > 0) + deviceName = bodyUI->inDevCombobox->itemText(deviceIndex); Settings::getInstance().setInDev(deviceName); @@ -386,9 +392,11 @@ void AVForm::onAudioInDevChanged(int deviceIndex) void AVForm::onAudioOutDevChanged(int deviceIndex) { - QString deviceName = deviceIndex > 0 - ? bodyUI->outDevCombobox->itemText(deviceIndex) - : QStringLiteral("none"); + Settings::getInstance().setAudioOutDevEnabled(deviceIndex != 0); + + QString deviceName; + if (deviceIndex > 0) + deviceName = bodyUI->outDevCombobox->itemText(deviceIndex); Settings::getInstance().setOutDev(deviceName);