Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
fix(audio): actually disable the audio in/out device in settings, whe…
Browse files Browse the repository at this point in the history
…n selected

As esecially the "Disabled" text is translated, the audio device will change from "disabled" to "default", just by changing the language.

In contrast to video devices, an audio device is either always available, or sound will be disabled. So "Disabled" is the correct term to use here.
  • Loading branch information
antis81 committed Jul 1, 2016
1 parent 81df534 commit 9694d6b
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/audio/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
28 changes: 28 additions & 0 deletions src/persistence/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -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};
Expand Down
10 changes: 9 additions & 1 deletion src/persistence/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,15 @@ public slots:
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);

Expand Down Expand Up @@ -433,8 +439,10 @@ private slots:

// Audio
QString inDev;
QString outDev;
bool audioInDevEnabled;
qreal audioInGainDecibel;
QString outDev;
bool audioOutDevEnabled;
int outVolume;

// Video
Expand Down
32 changes: 20 additions & 12 deletions src/widget/form/settings/avform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down

0 comments on commit 9694d6b

Please sign in to comment.