From 16a1f1a8a9e30aaabb6d3873f6eee9cddafccaa9 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Wed, 25 Sep 2019 17:43:21 +0200 Subject: [PATCH] Ref T731, audio UI * set settings from UI properly * UI improvements --- .../audiodevicevolumesetupcomponent.cpp | 113 ++++++++++++++---- .../audiodevicevolumesetupcomponent.h | 16 ++- 2 files changed, 103 insertions(+), 26 deletions(-) diff --git a/src/blackgui/components/audiodevicevolumesetupcomponent.cpp b/src/blackgui/components/audiodevicevolumesetupcomponent.cpp index ac6e90299..cd53b502f 100644 --- a/src/blackgui/components/audiodevicevolumesetupcomponent.cpp +++ b/src/blackgui/components/audiodevicevolumesetupcomponent.cpp @@ -42,18 +42,36 @@ namespace BlackGui ui(new Ui::CAudioDeviceVolumeSetupComponent) { ui->setupUi(this); - connect(ui->hs_VolumeIn, &QSlider::valueChanged, this, &CAudioDeviceVolumeSetupComponent::onVolumeSliderChanged); - connect(ui->hs_VolumeOut, &QSlider::valueChanged, this, &CAudioDeviceVolumeSetupComponent::onVolumeSliderChanged); + connect(ui->hs_VolumeIn, &QSlider::valueChanged, this, &CAudioDeviceVolumeSetupComponent::onVolumeSliderChanged); + connect(ui->hs_VolumeOut, &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); + + ui->hs_VolumeIn->setMaximum(CSettings::InMax); + ui->hs_VolumeIn->setMinimum(CSettings::InMin); + ui->hs_VolumeOut->setMaximum(CSettings::OutMax); + ui->hs_VolumeOut->setMinimum(CSettings::OutMin); + + const CSettings as(m_audioSettings.getThreadLocal()); + const int i = this->getInValue(); + const int o = this->getOutValue(); + ui->hs_VolumeIn->setValue(i); + ui->hs_VolumeOut->setValue(o); // deferred init, because in a distributed swift system // it takes a moment until the settings are sychronized // this is leading to undesired "save settings" messages and played sounds QPointer myself(this); - QTimer::singleShot(2500, this, [ = ] + QTimer::singleShot(1000, this, [ = ] { if (!myself || !sGui || sGui->isShuttingDown()) { return; } this->init(); }); + + ui->pb_LevelIn->setValue(ui->pb_LevelIn->minimum()); + ui->pb_LevelOut->setValue(ui->pb_LevelOut->minimum()); } void CAudioDeviceVolumeSetupComponent::init() @@ -67,6 +85,8 @@ namespace BlackGui bool c = connect(ui->cb_SetupAudioLoopback, &QCheckBox::toggled, this, &CAudioDeviceVolumeSetupComponent::onLoopbackToggled); Q_ASSERT(c); + c = connect(ui->cb_DisableAudioEffects, &QCheckBox::toggled, this, &CAudioDeviceVolumeSetupComponent::onDisableAudioEffectsToggled); + Q_ASSERT(c); if (audio) { @@ -89,11 +109,11 @@ namespace BlackGui c = connect(sGui->getIContextAudio(), &IContextAudio::changedSelectedAudioDevices, this, &CAudioDeviceVolumeSetupComponent::onCurrentAudioDevicesChanged, Qt::QueuedConnection); Q_ASSERT(c); - if (sGui->getIContextAudio()->isUsingImplementingObject()) + CAfvClient *afvClient = CAudioDeviceVolumeSetupComponent::afvClient(); + if (afvClient) { - CAfvClient &afvClient = sGui->getCoreFacade()->getCContextAudio()->voiceClient(); - connect(&afvClient, &CAfvClient::outputVolumePeakVU, this, &CAudioDeviceVolumeSetupComponent::onOutputVU); - connect(&afvClient, &CAfvClient::inputVolumePeakVU, this, &CAudioDeviceVolumeSetupComponent::onInputVU); + connect(afvClient, &CAfvClient::outputVolumePeakVU, this, &CAudioDeviceVolumeSetupComponent::onOutputVU); + connect(afvClient, &CAfvClient::inputVolumePeakVU, this, &CAudioDeviceVolumeSetupComponent::onInputVU); } } @@ -214,29 +234,56 @@ namespace BlackGui this->setInLevel(qRound(vu * 100.0), 0, 100); } + void CAudioDeviceVolumeSetupComponent::onReloadDevices() + { + if (!hasAudio()) { return; } + this->initAudioDeviceLists(); + const CAudioDeviceInfo i = this->getSelectedInputDevice(); + const CAudioDeviceInfo o = this->getSelectedInputDevice(); + sGui->getIContextAudio()->setCurrentAudioDevices(i, o); + } + + void CAudioDeviceVolumeSetupComponent::onResetVolumeIn() + { + 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); + } + + CAudioDeviceInfo CAudioDeviceVolumeSetupComponent::getSelectedInputDevice() const + { + if (!hasAudio()) { return CAudioDeviceInfo(); } + const CAudioDeviceInfoList devices = sGui->getIContextAudio()->getAudioInputDevices(); + return devices.findByName(ui->cb_SetupAudioInputDevice->currentText()); + } + + CAudioDeviceInfo CAudioDeviceVolumeSetupComponent::getSelectedOutputDevice() const + { + if (!hasAudio()) { return CAudioDeviceInfo(); } + const CAudioDeviceInfoList devices = sGui->getIContextAudio()->getAudioOutputDevices(); + return devices.findByName(ui->cb_SetupAudioOutputDevice->currentText()); + } + + CAfvClient *CAudioDeviceVolumeSetupComponent::afvClient() + { + if (!sGui || sGui->isShuttingDown() || !sGui->getIContextAudio()) { return nullptr; } + if (!sGui->getIContextAudio()->isUsingImplementingObject()) { return nullptr; } + + CAfvClient &afvClient = sGui->getCoreFacade()->getCContextAudio()->voiceClient(); + return &afvClient; + } + void CAudioDeviceVolumeSetupComponent::onAudioDeviceSelected(int index) { if (!sGui || sGui->isShuttingDown() || !sGui->getIContextAudio()) { return; } if (index < 0) { return; } - CAudioDeviceInfoList devices = sGui->getIContextAudio()->getAudioDevices(); - if (devices.isEmpty()) { return; } - CAudioDeviceInfo selectedDevice; - const QObject *sender = QObject::sender(); - if (sender == ui->cb_SetupAudioInputDevice) - { - const CAudioDeviceInfoList inputDevices = devices.getInputDevices(); - if (index >= inputDevices.size()) { return; } - selectedDevice = inputDevices[index]; - sGui->getIContextAudio()->setCurrentAudioDevice(selectedDevice); - } - else if (sender == ui->cb_SetupAudioOutputDevice) - { - const CAudioDeviceInfoList outputDevices = devices.getOutputDevices(); - if (index >= outputDevices.size()) { return; } - selectedDevice = outputDevices[index]; - sGui->getIContextAudio()->setCurrentAudioDevice(selectedDevice); - } + const CAudioDeviceInfo in = this->getSelectedInputDevice(); + const CAudioDeviceInfo out = this->getSelectedOutputDevice(); + sGui->getIContextAudio()->setCurrentAudioDevices(in, out); } void CAudioDeviceVolumeSetupComponent::onCurrentAudioDevicesChanged(const CAudioDeviceInfoList &devices) @@ -259,6 +306,9 @@ namespace BlackGui ui->cb_SetupAudioOutputDevice->clear(); ui->cb_SetupAudioInputDevice->clear(); + const QString i = ui->cb_SetupAudioInputDevice->currentText(); + const QString o = ui->cb_SetupAudioOutputDevice->currentText(); + for (const CAudioDeviceInfo &device : devices) { if (device.getType() == CAudioDeviceInfo::InputDevice) @@ -270,6 +320,9 @@ namespace BlackGui ui->cb_SetupAudioOutputDevice->addItem(device.toQString(true)); } } + + if (!i.isEmpty()) { ui->cb_SetupAudioInputDevice->setCurrentText(i); } + if (!o.isEmpty()) { ui->cb_SetupAudioOutputDevice->setCurrentText(o); } } void CAudioDeviceVolumeSetupComponent::onLoopbackToggled(bool loopback) @@ -278,5 +331,15 @@ namespace BlackGui if (sGui->getIContextAudio()->isAudioLoopbackEnabled() == loopback) { return; } sGui->getIContextAudio()->enableAudioLoopback(loopback); } + + void CAudioDeviceVolumeSetupComponent::onDisableAudioEffectsToggled(bool disabled) + { + if (!sGui || sGui->isShuttingDown() || !sGui->getIContextAudio()) { return; } + CSettings as(m_audioSettings.getThreadLocal()); + const bool enabled = !disabled; + if (as.isAudioEffectsEnabled() == enabled) { return; } + as.setAudioEffectsEnabled(enabled); + m_audioSettings.setAndSave(as); + } } // namespace } // namespace diff --git a/src/blackgui/components/audiodevicevolumesetupcomponent.h b/src/blackgui/components/audiodevicevolumesetupcomponent.h index 72878675f..648734c64 100644 --- a/src/blackgui/components/audiodevicevolumesetupcomponent.h +++ b/src/blackgui/components/audiodevicevolumesetupcomponent.h @@ -23,6 +23,7 @@ #include namespace Ui { class CAudioDeviceVolumeSetupComponent; } +namespace BlackCore { namespace Afv { namespace Clients { class CAfvClient; }}} namespace BlackGui { namespace Components @@ -40,7 +41,7 @@ namespace BlackGui virtual ~CAudioDeviceVolumeSetupComponent() override; //! Get input and output volume values @{ - int getInValue(int from = BlackMisc::Audio::CSettings::InMin, int to = BlackMisc::Audio::CSettings::InMax) const; + int getInValue(int from = BlackMisc::Audio::CSettings::InMin, int to = BlackMisc::Audio::CSettings::InMax) const; int getOutValue(int from = BlackMisc::Audio::CSettings::OutMin, int to = BlackMisc::Audio::CSettings::OutMax) const; //! @} @@ -80,6 +81,9 @@ namespace BlackGui //! Loopback toggled void onLoopbackToggled(bool loopback); + //! Disable audio effects disable + void onDisableAudioEffectsToggled(bool disabled); + //! Audio device lists from settings void initAudioDeviceLists(); @@ -95,6 +99,16 @@ namespace BlackGui void onOutputVU(double vu); void onInputVU(double vu); + void onReloadDevices(); + + void onResetVolumeIn(); + void onResetVolumeOut(); + + BlackMisc::Audio::CAudioDeviceInfo getSelectedInputDevice() const; + BlackMisc::Audio::CAudioDeviceInfo getSelectedOutputDevice() const; + + static BlackCore::Afv::Clients::CAfvClient *afvClient(); + QScopedPointer ui; BlackMisc::CDigestSignal m_volumeSliderChanged { this, &CAudioDeviceVolumeSetupComponent::saveVolumes, 1000, 10 }; BlackMisc::CSetting m_audioSettings { this, &CAudioDeviceVolumeSetupComponent::reloadSettings };