Issue #100 Add slider for master output volume

This commit is contained in:
Lars Toenning
2021-09-05 11:24:32 +02:00
parent 2a69f10ce2
commit 4b37c5ca30
10 changed files with 246 additions and 84 deletions

View File

@@ -48,11 +48,13 @@ namespace BlackGui
{
ui->setupUi(this);
connect(ui->hs_VolumeIn, &QSlider::valueChanged, this, &CAudioDeviceVolumeSetupComponent::onVolumeSliderChanged);
connect(ui->hs_VolumeOut, &QSlider::valueChanged, this, &CAudioDeviceVolumeSetupComponent::onVolumeSliderChanged);
connect(ui->hs_VolumeOutCom1, &QSlider::valueChanged, this, &CAudioDeviceVolumeSetupComponent::onVolumeSliderChanged);
connect(ui->hs_VolumeOutCom2, &QSlider::valueChanged, this, &CAudioDeviceVolumeSetupComponent::onVolumeSliderChanged);
connect(ui->tb_RefreshInDevice, &QToolButton::released, this, &CAudioDeviceVolumeSetupComponent::onReloadDevices, Qt::QueuedConnection);
connect(ui->tb_RefreshOutDevice, &QToolButton::released, this, &CAudioDeviceVolumeSetupComponent::onReloadDevices, Qt::QueuedConnection);
connect(ui->tb_ResetInVolume, &QToolButton::released, this, &CAudioDeviceVolumeSetupComponent::onResetVolumeIn, Qt::QueuedConnection);
connect(ui->tb_ResetOutVolume, &QToolButton::released, this, &CAudioDeviceVolumeSetupComponent::onResetVolumeOut, Qt::QueuedConnection);
connect(ui->tb_ResetOutVolumeCom1, &QToolButton::released, this, &CAudioDeviceVolumeSetupComponent::onResetVolumeOutCom1, Qt::QueuedConnection);
connect(ui->tb_ResetOutVolumeCom2, &QToolButton::released, this, &CAudioDeviceVolumeSetupComponent::onResetVolumeOutCom2, Qt::QueuedConnection);
@@ -64,6 +66,8 @@ namespace BlackGui
ui->hs_VolumeIn->setMaximum(CSettings::InMax);
ui->hs_VolumeIn->setMinimum(CSettings::InMin);
ui->hs_VolumeOut->setMaximum(CSettings::OutMax);
ui->hs_VolumeOut->setMinimum(CSettings::OutMin);
ui->hs_VolumeOutCom1->setMaximum(CSettings::OutMax);
ui->hs_VolumeOutCom1->setMinimum(CSettings::OutMin);
ui->hs_VolumeOutCom2->setMaximum(CSettings::OutMax);
@@ -71,9 +75,11 @@ namespace BlackGui
const CSettings as(m_audioSettings.getThreadLocal());
const int i = this->getInValue();
const int o = this->getOutValue();
const int o1 = this->getOutValueCom1();
const int o2 = this->getOutValueCom2();
ui->hs_VolumeIn->setValue(i);
ui->hs_VolumeOut->setValue(o);
ui->hs_VolumeOutCom1->setValue(o1);
ui->hs_VolumeOutCom2->setValue(o2);
ui->cb_SetupAudioLoopback->setChecked(false);
@@ -97,6 +103,7 @@ namespace BlackGui
});
this->setCheckBoxesReadOnly(this->isComIntegrated());
this->setVolumeSlidersReadOnly(this->isComIntegrated());
}
void CAudioDeviceVolumeSetupComponent::init()
@@ -189,6 +196,13 @@ namespace BlackGui
return qRound(ui->hs_VolumeIn->value() / r * tr);
}
int CAudioDeviceVolumeSetupComponent::getOutValue(int from, int to) const
{
const double r = ui->hs_VolumeOut->maximum() - ui->hs_VolumeOut->minimum();
const double tr = to - from;
return qRound(ui->hs_VolumeOut->value() / r * tr);
}
int CAudioDeviceVolumeSetupComponent::getOutValueCom1(int from, int to) const
{
const double r = ui->hs_VolumeOutCom1->maximum() - ui->hs_VolumeOutCom1->minimum();
@@ -212,6 +226,15 @@ namespace BlackGui
ui->hs_VolumeIn->setValue(qRound(value / tr * r));
}
void CAudioDeviceVolumeSetupComponent::setOutValue(int value, int from, int to)
{
if (value > to) { value = to; }
else if (value < from) { value = from; }
const double r = ui->hs_VolumeOut->maximum() - ui->hs_VolumeOut->minimum();
const double tr = to - from;
ui->hs_VolumeOut->setValue(qRound(value / tr * r));
}
void CAudioDeviceVolumeSetupComponent::setOutValueCom1(int value, int from, int to)
{
if (value > to) { value = to; }
@@ -255,6 +278,7 @@ namespace BlackGui
this->setRxTxCheckboxes(rec1, tx1, rec2, tx2);
ui->cb_IntegratedWithCom->setChecked(integrated);
this->setCheckBoxesReadOnly(integrated);
this->setVolumeSlidersReadOnly(integrated);
}
void CAudioDeviceVolumeSetupComponent::setTransmitReceiveInUiFromVoiceClient()
@@ -282,10 +306,13 @@ namespace BlackGui
this->setTransmitReceiveInUi(com1Tx, com1Rx, com2Tx, com2Rx, integrated);
// Set transmit volume in GUI
const int vol1 = sGui->getCContextAudioBase()->getVoiceOutputVolume(CComSystem::Com1);
const int vol2 = sGui->getCContextAudioBase()->getVoiceOutputVolume(CComSystem::Com2);
ui->hs_VolumeOutCom1->setValue(vol1);
ui->hs_VolumeOutCom2->setValue(vol2);
if (integrated)
{
const int vol1 = sGui->getCContextAudioBase()->getComOutputVolume(CComSystem::Com1);
const int vol2 = sGui->getCContextAudioBase()->getComOutputVolume(CComSystem::Com2);
ui->hs_VolumeOutCom1->setValue(vol1);
ui->hs_VolumeOutCom2->setValue(vol2);
}
}
void CAudioDeviceVolumeSetupComponent::setCheckBoxesReadOnly(bool readonly)
@@ -297,6 +324,23 @@ namespace BlackGui
CGuiUtility::checkBoxReadOnly(ui->cb_2Rec, readonly);
}
void CAudioDeviceVolumeSetupComponent::setVolumeSlidersReadOnly(bool readonly)
{
ui->hs_VolumeOutCom1->setDisabled(readonly);
ui->hs_VolumeOutCom2->setDisabled(readonly);
if (readonly)
{
// \fixme hardcoded stylesheet setting, should come from stylesheet")
ui->hs_VolumeOutCom1->setStyleSheet("background: rgb(40,40,40)");
ui->hs_VolumeOutCom2->setStyleSheet("background: rgb(40,40,40)");
}
else
{
ui->hs_VolumeOutCom1->setStyleSheet("");
ui->hs_VolumeOutCom2->setStyleSheet("");
}
}
CAfvClient *CAudioDeviceVolumeSetupComponent::afvClient()
{
if (!sGui || sGui->isShuttingDown() || !sGui->getCContextAudioBase()) { return nullptr; }
@@ -308,6 +352,7 @@ namespace BlackGui
const CSettings as(m_audioSettings.getThreadLocal());
ui->cb_DisableAudioEffects->setChecked(!as.isAudioEffectsEnabled());
this->setInValue(as.getInVolume());
this->setOutValue(as.getOutVolume());
this->setOutValueCom1(as.getOutVolumeCom1());
this->setOutValueCom2(as.getOutVolumeCom2());
}
@@ -341,10 +386,13 @@ namespace BlackGui
{
CSettings as(m_audioSettings.getThreadLocal());
const int i = this->getInValue();
const int o = this->getOutValue();
const int o1 = this->getOutValueCom1();
const int o2 = this->getOutValueCom2();
if (as.getInVolume() == i && as.getOutVolumeCom1() == o1 && as.getOutVolumeCom2() == o2) { return; }
if (as.getInVolume() == i && o == as.getOutVolume() &&
as.getOutVolumeCom1() == o1 && as.getOutVolumeCom2() == o2) { return; }
as.setInVolume(i);
as.setOutVolume(o);
as.setOutVolumeCom1(o1);
as.setOutVolumeCom2(o2);
m_audioSettings.setAndSave(as);
@@ -374,14 +422,19 @@ namespace BlackGui
ui->hs_VolumeIn->setValue((ui->hs_VolumeIn->maximum() - ui->hs_VolumeIn->minimum()) / 2);
}
void CAudioDeviceVolumeSetupComponent::onResetVolumeOut()
{
ui->hs_VolumeOut->setValue((ui->hs_VolumeOut->maximum() - ui->hs_VolumeOut->minimum()) / 2);
}
void CAudioDeviceVolumeSetupComponent::onResetVolumeOutCom1()
{
ui->hs_VolumeOutCom1->setValue((ui->hs_VolumeOutCom1->maximum() - ui->hs_VolumeOutCom1->minimum()) / 2);
ui->hs_VolumeOutCom1->setValue(ui->hs_VolumeOutCom1->maximum());
}
void CAudioDeviceVolumeSetupComponent::onResetVolumeOutCom2()
{
ui->hs_VolumeOutCom2->setValue((ui->hs_VolumeOutCom2->maximum() - ui->hs_VolumeOutCom2->minimum()) / 2);
ui->hs_VolumeOutCom2->setValue(ui->hs_VolumeOutCom2->maximum());
}
void CAudioDeviceVolumeSetupComponent::setAudioRunsWhere()
@@ -397,6 +450,7 @@ namespace BlackGui
if (ui->cb_IntegratedWithCom->isChecked() == integrate) { return integrate; }
ui->cb_IntegratedWithCom->setChecked(integrate);
this->setCheckBoxesReadOnly(integrate);
this->setVolumeSlidersReadOnly(integrate);
return integrate;
}
@@ -441,6 +495,7 @@ namespace BlackGui
{
if (!this->hasAudio()) { return; }
this->setCheckBoxesReadOnly(checked);
this->setVolumeSlidersReadOnly(checked);
if (!this->hasSimulator()) { return; }
if (!sGui->getIContextSimulator()->isSimulatorAvailable()) { return; }