mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 11:55:35 +08:00
Ref T731, audio UI
* set settings from UI properly * UI improvements
This commit is contained in:
committed by
Mat Sutcliffe
parent
ced0004234
commit
16a1f1a8a9
@@ -42,18 +42,36 @@ namespace BlackGui
|
|||||||
ui(new Ui::CAudioDeviceVolumeSetupComponent)
|
ui(new Ui::CAudioDeviceVolumeSetupComponent)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
connect(ui->hs_VolumeIn, &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->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
|
// deferred init, because in a distributed swift system
|
||||||
// it takes a moment until the settings are sychronized
|
// it takes a moment until the settings are sychronized
|
||||||
// this is leading to undesired "save settings" messages and played sounds
|
// this is leading to undesired "save settings" messages and played sounds
|
||||||
QPointer<CAudioDeviceVolumeSetupComponent> myself(this);
|
QPointer<CAudioDeviceVolumeSetupComponent> myself(this);
|
||||||
QTimer::singleShot(2500, this, [ = ]
|
QTimer::singleShot(1000, this, [ = ]
|
||||||
{
|
{
|
||||||
if (!myself || !sGui || sGui->isShuttingDown()) { return; }
|
if (!myself || !sGui || sGui->isShuttingDown()) { return; }
|
||||||
this->init();
|
this->init();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ui->pb_LevelIn->setValue(ui->pb_LevelIn->minimum());
|
||||||
|
ui->pb_LevelOut->setValue(ui->pb_LevelOut->minimum());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAudioDeviceVolumeSetupComponent::init()
|
void CAudioDeviceVolumeSetupComponent::init()
|
||||||
@@ -67,6 +85,8 @@ namespace BlackGui
|
|||||||
|
|
||||||
bool c = connect(ui->cb_SetupAudioLoopback, &QCheckBox::toggled, this, &CAudioDeviceVolumeSetupComponent::onLoopbackToggled);
|
bool c = connect(ui->cb_SetupAudioLoopback, &QCheckBox::toggled, this, &CAudioDeviceVolumeSetupComponent::onLoopbackToggled);
|
||||||
Q_ASSERT(c);
|
Q_ASSERT(c);
|
||||||
|
c = connect(ui->cb_DisableAudioEffects, &QCheckBox::toggled, this, &CAudioDeviceVolumeSetupComponent::onDisableAudioEffectsToggled);
|
||||||
|
Q_ASSERT(c);
|
||||||
|
|
||||||
if (audio)
|
if (audio)
|
||||||
{
|
{
|
||||||
@@ -89,11 +109,11 @@ namespace BlackGui
|
|||||||
c = connect(sGui->getIContextAudio(), &IContextAudio::changedSelectedAudioDevices, this, &CAudioDeviceVolumeSetupComponent::onCurrentAudioDevicesChanged, Qt::QueuedConnection);
|
c = connect(sGui->getIContextAudio(), &IContextAudio::changedSelectedAudioDevices, this, &CAudioDeviceVolumeSetupComponent::onCurrentAudioDevicesChanged, Qt::QueuedConnection);
|
||||||
Q_ASSERT(c);
|
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::outputVolumePeakVU, this, &CAudioDeviceVolumeSetupComponent::onOutputVU);
|
connect(afvClient, &CAfvClient::inputVolumePeakVU, this, &CAudioDeviceVolumeSetupComponent::onInputVU);
|
||||||
connect(&afvClient, &CAfvClient::inputVolumePeakVU, this, &CAudioDeviceVolumeSetupComponent::onInputVU);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -214,29 +234,56 @@ namespace BlackGui
|
|||||||
this->setInLevel(qRound(vu * 100.0), 0, 100);
|
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)
|
void CAudioDeviceVolumeSetupComponent::onAudioDeviceSelected(int index)
|
||||||
{
|
{
|
||||||
if (!sGui || sGui->isShuttingDown() || !sGui->getIContextAudio()) { return; }
|
if (!sGui || sGui->isShuttingDown() || !sGui->getIContextAudio()) { return; }
|
||||||
if (index < 0) { return; }
|
if (index < 0) { return; }
|
||||||
|
|
||||||
CAudioDeviceInfoList devices = sGui->getIContextAudio()->getAudioDevices();
|
const CAudioDeviceInfo in = this->getSelectedInputDevice();
|
||||||
if (devices.isEmpty()) { return; }
|
const CAudioDeviceInfo out = this->getSelectedOutputDevice();
|
||||||
CAudioDeviceInfo selectedDevice;
|
sGui->getIContextAudio()->setCurrentAudioDevices(in, out);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAudioDeviceVolumeSetupComponent::onCurrentAudioDevicesChanged(const CAudioDeviceInfoList &devices)
|
void CAudioDeviceVolumeSetupComponent::onCurrentAudioDevicesChanged(const CAudioDeviceInfoList &devices)
|
||||||
@@ -259,6 +306,9 @@ namespace BlackGui
|
|||||||
ui->cb_SetupAudioOutputDevice->clear();
|
ui->cb_SetupAudioOutputDevice->clear();
|
||||||
ui->cb_SetupAudioInputDevice->clear();
|
ui->cb_SetupAudioInputDevice->clear();
|
||||||
|
|
||||||
|
const QString i = ui->cb_SetupAudioInputDevice->currentText();
|
||||||
|
const QString o = ui->cb_SetupAudioOutputDevice->currentText();
|
||||||
|
|
||||||
for (const CAudioDeviceInfo &device : devices)
|
for (const CAudioDeviceInfo &device : devices)
|
||||||
{
|
{
|
||||||
if (device.getType() == CAudioDeviceInfo::InputDevice)
|
if (device.getType() == CAudioDeviceInfo::InputDevice)
|
||||||
@@ -270,6 +320,9 @@ namespace BlackGui
|
|||||||
ui->cb_SetupAudioOutputDevice->addItem(device.toQString(true));
|
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)
|
void CAudioDeviceVolumeSetupComponent::onLoopbackToggled(bool loopback)
|
||||||
@@ -278,5 +331,15 @@ namespace BlackGui
|
|||||||
if (sGui->getIContextAudio()->isAudioLoopbackEnabled() == loopback) { return; }
|
if (sGui->getIContextAudio()->isAudioLoopbackEnabled() == loopback) { return; }
|
||||||
sGui->getIContextAudio()->enableAudioLoopback(loopback);
|
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
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
#include <QScopedPointer>
|
#include <QScopedPointer>
|
||||||
|
|
||||||
namespace Ui { class CAudioDeviceVolumeSetupComponent; }
|
namespace Ui { class CAudioDeviceVolumeSetupComponent; }
|
||||||
|
namespace BlackCore { namespace Afv { namespace Clients { class CAfvClient; }}}
|
||||||
namespace BlackGui
|
namespace BlackGui
|
||||||
{
|
{
|
||||||
namespace Components
|
namespace Components
|
||||||
@@ -40,7 +41,7 @@ namespace BlackGui
|
|||||||
virtual ~CAudioDeviceVolumeSetupComponent() override;
|
virtual ~CAudioDeviceVolumeSetupComponent() override;
|
||||||
|
|
||||||
//! Get input and output volume values @{
|
//! 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;
|
int getOutValue(int from = BlackMisc::Audio::CSettings::OutMin, int to = BlackMisc::Audio::CSettings::OutMax) const;
|
||||||
//! @}
|
//! @}
|
||||||
|
|
||||||
@@ -80,6 +81,9 @@ namespace BlackGui
|
|||||||
//! Loopback toggled
|
//! Loopback toggled
|
||||||
void onLoopbackToggled(bool loopback);
|
void onLoopbackToggled(bool loopback);
|
||||||
|
|
||||||
|
//! Disable audio effects disable
|
||||||
|
void onDisableAudioEffectsToggled(bool disabled);
|
||||||
|
|
||||||
//! Audio device lists from settings
|
//! Audio device lists from settings
|
||||||
void initAudioDeviceLists();
|
void initAudioDeviceLists();
|
||||||
|
|
||||||
@@ -95,6 +99,16 @@ namespace BlackGui
|
|||||||
void onOutputVU(double vu);
|
void onOutputVU(double vu);
|
||||||
void onInputVU(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::CAudioDeviceVolumeSetupComponent> ui;
|
QScopedPointer<Ui::CAudioDeviceVolumeSetupComponent> ui;
|
||||||
BlackMisc::CDigestSignal m_volumeSliderChanged { this, &CAudioDeviceVolumeSetupComponent::saveVolumes, 1000, 10 };
|
BlackMisc::CDigestSignal m_volumeSliderChanged { this, &CAudioDeviceVolumeSetupComponent::saveVolumes, 1000, 10 };
|
||||||
BlackMisc::CSetting<BlackMisc::Audio::TSettings> m_audioSettings { this, &CAudioDeviceVolumeSetupComponent::reloadSettings };
|
BlackMisc::CSetting<BlackMisc::Audio::TSettings> m_audioSettings { this, &CAudioDeviceVolumeSetupComponent::reloadSettings };
|
||||||
|
|||||||
Reference in New Issue
Block a user