mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-16 18:35:35 +08:00
[AFV] Ref T731, allow to re-init audio in UI
* audio can be started/stopped and disabled/enabled * allow to connect signals if audio was started * allow default devices in combobox
This commit is contained in:
committed by
Mat Sutcliffe
parent
a9a772c929
commit
1d195b87fa
@@ -108,9 +108,9 @@ namespace BlackGui
|
|||||||
ui->cb_SetupAudioLoopback->setChecked(sGui->getCContextAudioBase()->isAudioLoopbackEnabled());
|
ui->cb_SetupAudioLoopback->setChecked(sGui->getCContextAudioBase()->isAudioLoopbackEnabled());
|
||||||
|
|
||||||
// the connects depend on initAudioDeviceLists
|
// the connects depend on initAudioDeviceLists
|
||||||
c = connect(ui->cb_SetupAudioInputDevice, qOverload<int>(&QComboBox::currentIndexChanged), this, &CAudioDeviceVolumeSetupComponent::onAudioDeviceSelected);
|
c = connect(ui->cb_SetupAudioInputDevice, qOverload<int>(&QComboBox::currentIndexChanged), this, &CAudioDeviceVolumeSetupComponent::onAudioDeviceSelected, Qt::QueuedConnection);
|
||||||
Q_ASSERT(c);
|
Q_ASSERT(c);
|
||||||
c = connect(ui->cb_SetupAudioOutputDevice, qOverload<int>(&QComboBox::currentIndexChanged), this, &CAudioDeviceVolumeSetupComponent::onAudioDeviceSelected);
|
c = connect(ui->cb_SetupAudioOutputDevice, qOverload<int>(&QComboBox::currentIndexChanged), this, &CAudioDeviceVolumeSetupComponent::onAudioDeviceSelected, Qt::QueuedConnection);
|
||||||
Q_ASSERT(c);
|
Q_ASSERT(c);
|
||||||
|
|
||||||
// context
|
// context
|
||||||
@@ -121,29 +121,46 @@ namespace BlackGui
|
|||||||
c = connect(sGui->getCContextAudioBase(), &CContextAudioBase::stoppedAudio, this, &CAudioDeviceVolumeSetupComponent::onAudioStopped, Qt::QueuedConnection);
|
c = connect(sGui->getCContextAudioBase(), &CContextAudioBase::stoppedAudio, this, &CAudioDeviceVolumeSetupComponent::onAudioStopped, Qt::QueuedConnection);
|
||||||
Q_ASSERT(c);
|
Q_ASSERT(c);
|
||||||
|
|
||||||
//! \todo Workaround to avoid context signals
|
this->initWithAfvClient();
|
||||||
c = connect(sGui->getCContextAudioBase()->afvClient(), &CAfvClient::outputVolumePeakVU, this, &CAudioDeviceVolumeSetupComponent::onOutputVU, Qt::QueuedConnection);
|
m_init = true;
|
||||||
Q_ASSERT(c);
|
|
||||||
c = connect(sGui->getCContextAudioBase()->afvClient(), &CAfvClient::inputVolumePeakVU, this, &CAudioDeviceVolumeSetupComponent::onInputVU, Qt::QueuedConnection);
|
|
||||||
Q_ASSERT(c);
|
|
||||||
c = connect(sGui->getCContextAudioBase()->afvClient(), &CAfvClient::receivedCallsignsChanged, this, &CAudioDeviceVolumeSetupComponent::onReceivingCallsignsChanged, Qt::QueuedConnection);
|
|
||||||
Q_ASSERT(c);
|
|
||||||
c = connect(sGui->getCContextAudioBase()->afvClient(), &CAfvClient::updatedFromOwnAircraftCockpit, this, &CAudioDeviceVolumeSetupComponent::onUpdatedClientWithCockpitData, Qt::QueuedConnection);
|
|
||||||
Q_ASSERT(c);
|
|
||||||
|
|
||||||
QPointer<CAudioDeviceVolumeSetupComponent> myself(this);
|
|
||||||
c = connect(sGui->getCContextAudioBase()->afvClient(), &CAfvClient::connectionStatusChanged, this, [ = ]
|
|
||||||
{
|
|
||||||
if (!myself || !sGui || sGui->isShuttingDown()) { return; }
|
|
||||||
myself->setTransmitReceiveInUiFromVoiceClient();
|
|
||||||
}, Qt::QueuedConnection);
|
|
||||||
Q_ASSERT(c);
|
|
||||||
|
|
||||||
this->setTransmitReceiveInUiFromVoiceClient();
|
|
||||||
}
|
}
|
||||||
Q_UNUSED(c)
|
Q_UNUSED(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CAudioDeviceVolumeSetupComponent::initWithAfvClient()
|
||||||
|
{
|
||||||
|
if (!afvClient()) { return; }
|
||||||
|
m_afvConnections.disconnectAll();
|
||||||
|
|
||||||
|
//! \todo Workaround to avoid context signals
|
||||||
|
CAfvClient *afv = afvClient();
|
||||||
|
const Qt::ConnectionType ct = Qt::QueuedConnection;
|
||||||
|
QMetaObject::Connection c;
|
||||||
|
c = connect(afv, &CAfvClient::outputVolumePeakVU, this, &CAudioDeviceVolumeSetupComponent::onOutputVU, ct);
|
||||||
|
Q_ASSERT(c);
|
||||||
|
m_afvConnections.append(c);
|
||||||
|
c = connect(afv, &CAfvClient::inputVolumePeakVU, this, &CAudioDeviceVolumeSetupComponent::onInputVU, ct);
|
||||||
|
Q_ASSERT(c);
|
||||||
|
m_afvConnections.append(c);
|
||||||
|
c = connect(afv, &CAfvClient::receivedCallsignsChanged, this, &CAudioDeviceVolumeSetupComponent::onReceivingCallsignsChanged, ct);
|
||||||
|
Q_ASSERT(c);
|
||||||
|
m_afvConnections.append(c);
|
||||||
|
c = connect(afv, &CAfvClient::updatedFromOwnAircraftCockpit, this, &CAudioDeviceVolumeSetupComponent::onUpdatedClientWithCockpitData, ct);
|
||||||
|
Q_ASSERT(c);
|
||||||
|
m_afvConnections.append(c);
|
||||||
|
|
||||||
|
QPointer<CAudioDeviceVolumeSetupComponent> myself(this);
|
||||||
|
c = connect(afv, &CAfvClient::connectionStatusChanged, this, [ = ]
|
||||||
|
{
|
||||||
|
if (!myself || !sGui || sGui->isShuttingDown()) { return; }
|
||||||
|
myself->setTransmitReceiveInUiFromVoiceClient();
|
||||||
|
}, ct);
|
||||||
|
Q_ASSERT(c);
|
||||||
|
m_afvConnections.append(c);
|
||||||
|
|
||||||
|
this->setTransmitReceiveInUiFromVoiceClient();
|
||||||
|
}
|
||||||
|
|
||||||
CAudioDeviceVolumeSetupComponent::~CAudioDeviceVolumeSetupComponent()
|
CAudioDeviceVolumeSetupComponent::~CAudioDeviceVolumeSetupComponent()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
@@ -230,6 +247,12 @@ namespace BlackGui
|
|||||||
this->setTransmitReceiveInUi(com1Tx, com1Rx, com2Tx, com2Rx);
|
this->setTransmitReceiveInUi(com1Tx, com1Rx, com2Tx, com2Rx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CAfvClient *CAudioDeviceVolumeSetupComponent::afvClient()
|
||||||
|
{
|
||||||
|
if (!sGui || sGui->isShuttingDown() || !sGui->getCContextAudioBase()) { return nullptr; }
|
||||||
|
return sGui->getCContextAudioBase()->afvClient();
|
||||||
|
}
|
||||||
|
|
||||||
void CAudioDeviceVolumeSetupComponent::reloadSettings()
|
void CAudioDeviceVolumeSetupComponent::reloadSettings()
|
||||||
{
|
{
|
||||||
const CSettings as(m_audioSettings.getThreadLocal());
|
const CSettings as(m_audioSettings.getThreadLocal());
|
||||||
@@ -241,7 +264,7 @@ namespace BlackGui
|
|||||||
void CAudioDeviceVolumeSetupComponent::initAudioDeviceLists()
|
void CAudioDeviceVolumeSetupComponent::initAudioDeviceLists()
|
||||||
{
|
{
|
||||||
if (!this->hasAudio()) { return; }
|
if (!this->hasAudio()) { return; }
|
||||||
const bool changed = this->onAudioDevicesChanged(sGui->getCContextAudioBase()->getAudioDevices());
|
const bool changed = this->onAudioDevicesChanged(sGui->getCContextAudioBase()->getAudioDevicesPlusDefault());
|
||||||
if (!changed) { return; }
|
if (!changed) { return; }
|
||||||
const CAudioDeviceInfoList currentDevices = sGui->getCContextAudioBase()->getCurrentAudioDevices();
|
const CAudioDeviceInfoList currentDevices = sGui->getCContextAudioBase()->getCurrentAudioDevices();
|
||||||
this->onAudioStarted(currentDevices.getInputDevices().frontOrDefault(), currentDevices.getOutputDevices().frontOrDefault());
|
this->onAudioStarted(currentDevices.getInputDevices().frontOrDefault(), currentDevices.getOutputDevices().frontOrDefault());
|
||||||
@@ -323,14 +346,14 @@ namespace BlackGui
|
|||||||
CAudioDeviceInfo CAudioDeviceVolumeSetupComponent::getSelectedInputDevice() const
|
CAudioDeviceInfo CAudioDeviceVolumeSetupComponent::getSelectedInputDevice() const
|
||||||
{
|
{
|
||||||
if (!hasAudio()) { return CAudioDeviceInfo(); }
|
if (!hasAudio()) { return CAudioDeviceInfo(); }
|
||||||
const CAudioDeviceInfoList devices = sGui->getCContextAudioBase()->getAudioInputDevices();
|
const CAudioDeviceInfoList devices = sGui->getCContextAudioBase()->getAudioInputDevicesPlusDefault();
|
||||||
return devices.findByName(ui->cb_SetupAudioInputDevice->currentText());
|
return devices.findByName(ui->cb_SetupAudioInputDevice->currentText());
|
||||||
}
|
}
|
||||||
|
|
||||||
CAudioDeviceInfo CAudioDeviceVolumeSetupComponent::getSelectedOutputDevice() const
|
CAudioDeviceInfo CAudioDeviceVolumeSetupComponent::getSelectedOutputDevice() const
|
||||||
{
|
{
|
||||||
if (!hasAudio()) { return CAudioDeviceInfo(); }
|
if (!hasAudio()) { return CAudioDeviceInfo(); }
|
||||||
const CAudioDeviceInfoList devices = sGui->getCContextAudioBase()->getAudioOutputDevices();
|
const CAudioDeviceInfoList devices = sGui->getCContextAudioBase()->getAudioOutputDevicesPlusDefault();
|
||||||
return devices.findByName(ui->cb_SetupAudioOutputDevice->currentText());
|
return devices.findByName(ui->cb_SetupAudioOutputDevice->currentText());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -346,6 +369,12 @@ namespace BlackGui
|
|||||||
|
|
||||||
void CAudioDeviceVolumeSetupComponent::onAudioStarted(const CAudioDeviceInfo &input, const CAudioDeviceInfo &output)
|
void CAudioDeviceVolumeSetupComponent::onAudioStarted(const CAudioDeviceInfo &input, const CAudioDeviceInfo &output)
|
||||||
{
|
{
|
||||||
|
if (!afvClient()) { return; }
|
||||||
|
if (m_afvConnections.isEmpty() && m_init)
|
||||||
|
{
|
||||||
|
this->initWithAfvClient();
|
||||||
|
}
|
||||||
|
|
||||||
ui->cb_SetupAudioInputDevice->setCurrentText(input.toQString(true));
|
ui->cb_SetupAudioInputDevice->setCurrentText(input.toQString(true));
|
||||||
ui->cb_SetupAudioOutputDevice->setCurrentText(output.toQString(true));
|
ui->cb_SetupAudioOutputDevice->setCurrentText(output.toQString(true));
|
||||||
this->setAudioRunsWhere();
|
this->setAudioRunsWhere();
|
||||||
@@ -354,6 +383,10 @@ namespace BlackGui
|
|||||||
void CAudioDeviceVolumeSetupComponent::onAudioStopped()
|
void CAudioDeviceVolumeSetupComponent::onAudioStopped()
|
||||||
{
|
{
|
||||||
this->setAudioRunsWhere();
|
this->setAudioRunsWhere();
|
||||||
|
if (!afvClient())
|
||||||
|
{
|
||||||
|
m_afvConnections.disconnectAll();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CAudioDeviceVolumeSetupComponent::onAudioDevicesChanged(const CAudioDeviceInfoList &devices)
|
bool CAudioDeviceVolumeSetupComponent::onAudioDevicesChanged(const CAudioDeviceInfoList &devices)
|
||||||
|
|||||||
@@ -12,9 +12,10 @@
|
|||||||
#define BLACKGUI_COMPONENTS_AUDIODEVICEVOLUMESETUPCOMPONENT_H
|
#define BLACKGUI_COMPONENTS_AUDIODEVICEVOLUMESETUPCOMPONENT_H
|
||||||
|
|
||||||
#include "blackgui/blackguiexport.h"
|
#include "blackgui/blackguiexport.h"
|
||||||
#include "blackcore/afv/audio/receiversampleprovider.h"
|
|
||||||
#include "blackmisc/audio/audiosettings.h"
|
#include "blackmisc/audio/audiosettings.h"
|
||||||
#include "blackmisc/audio/audiodeviceinfolist.h"
|
#include "blackmisc/audio/audiodeviceinfolist.h"
|
||||||
|
#include "blackmisc/aviation/callsignset.h"
|
||||||
|
#include "blackmisc/connectionguard.h"
|
||||||
#include "blackmisc/settingscache.h"
|
#include "blackmisc/settingscache.h"
|
||||||
#include "blackmisc/digestsignal.h"
|
#include "blackmisc/digestsignal.h"
|
||||||
|
|
||||||
@@ -63,6 +64,9 @@ namespace BlackGui
|
|||||||
//! Init
|
//! Init
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
|
//! AFV client related part
|
||||||
|
void initWithAfvClient();
|
||||||
|
|
||||||
//! Reload settings
|
//! Reload settings
|
||||||
void reloadSettings();
|
void reloadSettings();
|
||||||
|
|
||||||
@@ -118,6 +122,10 @@ namespace BlackGui
|
|||||||
void setTransmitReceiveInUiFromVoiceClient();
|
void setTransmitReceiveInUiFromVoiceClient();
|
||||||
//! @}
|
//! @}
|
||||||
|
|
||||||
|
static BlackCore::Afv::Clients::CAfvClient *afvClient();
|
||||||
|
|
||||||
|
bool m_init = false;
|
||||||
|
BlackMisc::CConnectionGuard m_afvConnections;
|
||||||
QScopedPointer<Ui::CAudioDeviceVolumeSetupComponent> ui;
|
QScopedPointer<Ui::CAudioDeviceVolumeSetupComponent> ui;
|
||||||
BlackMisc::Audio::CAudioDeviceInfoList m_cbDevices;
|
BlackMisc::Audio::CAudioDeviceInfoList m_cbDevices;
|
||||||
BlackMisc::CDigestSignal m_volumeSliderChanged { this, &CAudioDeviceVolumeSetupComponent::saveVolumes, 1000, 10 };
|
BlackMisc::CDigestSignal m_volumeSliderChanged { this, &CAudioDeviceVolumeSetupComponent::saveVolumes, 1000, 10 };
|
||||||
|
|||||||
@@ -57,6 +57,9 @@ namespace BlackMisc
|
|||||||
//! Disconnect all
|
//! Disconnect all
|
||||||
int disconnectAll();
|
int disconnectAll();
|
||||||
|
|
||||||
|
//! Empty
|
||||||
|
bool isEmpty() const { return m_connections.isEmpty(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<QMetaObject::Connection> m_connections;
|
QList<QMetaObject::Connection> m_connections;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user