mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 17:35:34 +08:00
[AFV] Ref T739, audio can now be disabled from UI
This commit is contained in:
committed by
Mat Sutcliffe
parent
c8097cc899
commit
9447db00bc
@@ -11,6 +11,7 @@
|
||||
|
||||
#include "blackgui/guiapplication.h"
|
||||
#include "blackcore/context/contextaudio.h"
|
||||
#include "blackcore/context/contextnetwork.h"
|
||||
#include "blackcore/afv/clients/afvclient.h"
|
||||
|
||||
using namespace BlackMisc::Audio;
|
||||
@@ -28,9 +29,10 @@ namespace BlackGui
|
||||
|
||||
connect(sGui->getCContextAudioBase(), &CContextAudioBase::startedAudio, this, &CAudioAdvancedDistributedComponent::onAudioStarted, Qt::QueuedConnection);
|
||||
connect(sGui->getCContextAudioBase(), &CContextAudioBase::stoppedAudio, this, &CAudioAdvancedDistributedComponent::onAudioStoppend, Qt::QueuedConnection);
|
||||
connect(ui->pb_StartStop, &QPushButton::released, this, &CAudioAdvancedDistributedComponent::toggleAudioStartStop, Qt::QueuedConnection);
|
||||
connect(ui->pb_EnableDisable, &QPushButton::pressed, this, &CAudioAdvancedDistributedComponent::toggleAudioEnableDisable, Qt::QueuedConnection);
|
||||
connect(ui->pb_StartStop, &QPushButton::pressed, this, &CAudioAdvancedDistributedComponent::toggleAudioStartStop, Qt::QueuedConnection);
|
||||
|
||||
this->setStartButton();
|
||||
this->setButtons();
|
||||
}
|
||||
|
||||
CAudioAdvancedDistributedComponent::~CAudioAdvancedDistributedComponent()
|
||||
@@ -42,37 +44,73 @@ namespace BlackGui
|
||||
const bool started = sGui->getCContextAudioBase()->isAudioStarted();
|
||||
if (started)
|
||||
{
|
||||
sGui->getCContextAudioBase()->afvClient()->stopAudio();
|
||||
sGui->getCContextAudioBase()->afvClient()->disconnectFromAndStop();
|
||||
}
|
||||
else
|
||||
{
|
||||
sGui->getCContextAudioBase()->afvClient()->startAudio();
|
||||
if (sGui->getIContextNetwork()->isConnected())
|
||||
{
|
||||
sGui->getCContextAudioBase()->connectAudioWithNetworkCredentials();
|
||||
}
|
||||
}
|
||||
|
||||
this->setButtons(2000);
|
||||
}
|
||||
|
||||
void CAudioAdvancedDistributedComponent::setStartButton()
|
||||
void CAudioAdvancedDistributedComponent::toggleAudioEnableDisable()
|
||||
{
|
||||
if (!hasContexts()) { return; }
|
||||
const bool enabled = sGui->getCContextAudioBase()->isAudioEnabled();
|
||||
if (enabled)
|
||||
{
|
||||
sGui->getCContextAudioBase()->disableVoiceClient();
|
||||
}
|
||||
else
|
||||
{
|
||||
sGui->getCContextAudioBase()->enableVoiceClientAndStart();
|
||||
}
|
||||
|
||||
this->setButtons(2000);
|
||||
}
|
||||
|
||||
void CAudioAdvancedDistributedComponent::setButtons()
|
||||
{
|
||||
if (!hasContexts()) { return; }
|
||||
const bool started = sGui->getCContextAudioBase()->isAudioStarted();
|
||||
const bool enabled = sGui->getCContextAudioBase()->isAudioEnabled();
|
||||
ui->pb_StartStop->setText(started ? "stop" : "start");
|
||||
ui->pb_StartStop->setEnabled(enabled);
|
||||
ui->pb_EnableDisable->setText(enabled ? "disable" : "enable");
|
||||
}
|
||||
|
||||
void CAudioAdvancedDistributedComponent::setButtons(int delayMs)
|
||||
{
|
||||
if (!hasContexts()) { return; }
|
||||
QPointer<CAudioAdvancedDistributedComponent> myself(this);
|
||||
QTimer::singleShot(delayMs, this, [ = ]
|
||||
{
|
||||
if (!sGui || !myself || sGui->isShuttingDown()) { return; }
|
||||
this->setButtons();
|
||||
});
|
||||
}
|
||||
|
||||
void CAudioAdvancedDistributedComponent::onAudioStarted(const CAudioDeviceInfo &inputDevice, const CAudioDeviceInfo &outputDevice)
|
||||
{
|
||||
Q_UNUSED(inputDevice)
|
||||
Q_UNUSED(outputDevice)
|
||||
this->setStartButton();
|
||||
this->setButtons();
|
||||
}
|
||||
|
||||
void CAudioAdvancedDistributedComponent::onAudioStoppend()
|
||||
{
|
||||
this->setStartButton();
|
||||
this->setButtons();
|
||||
}
|
||||
|
||||
bool CAudioAdvancedDistributedComponent::hasContexts()
|
||||
{
|
||||
if (!sGui || sGui->isShuttingDown() || !sGui->getCContextAudioBase()) { return false; }
|
||||
if (!sGui->getCContextAudioBase()->afvClient()) { return false; }
|
||||
if (!sGui->getIContextNetwork()) { return false; }
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,8 +39,13 @@ namespace BlackGui
|
||||
//! Audio start/stop
|
||||
void toggleAudioStartStop();
|
||||
|
||||
//! Start/stop button
|
||||
void setStartButton();
|
||||
//! Audio enable/disable
|
||||
void toggleAudioEnableDisable();
|
||||
|
||||
//! Start/stop button @{
|
||||
void setButtons();
|
||||
void setButtons(int delayMs);
|
||||
//! @}
|
||||
|
||||
void onAudioStarted(const BlackMisc::Audio::CAudioDeviceInfo &inputDevice, const BlackMisc::Audio::CAudioDeviceInfo &outputDevice);
|
||||
void onAudioStoppend();
|
||||
|
||||
@@ -7,29 +7,46 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>166</width>
|
||||
<height>32</height>
|
||||
<height>55</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Frame</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="lbl_StartStop">
|
||||
<item row="0" column="1">
|
||||
<widget class="QPushButton" name="pb_EnableDisable">
|
||||
<property name="text">
|
||||
<string>Start/stop audio:</string>
|
||||
<string>enable</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<item row="1" column="1">
|
||||
<widget class="QPushButton" name="pb_StartStop">
|
||||
<property name="text">
|
||||
<string>stop</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="lbl_EnableDisable">
|
||||
<property name="text">
|
||||
<string>Enable/disable:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="lbl_StartStop">
|
||||
<property name="text">
|
||||
<string>Start/stop audio:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>pb_StartStop</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
||||
@@ -101,10 +101,7 @@ namespace BlackGui
|
||||
|
||||
if (audio)
|
||||
{
|
||||
const QString ai = sGui->getCContextAudioBase()->audioRunsWhereInfo();
|
||||
ui->le_Info->setText(ai);
|
||||
ui->le_Info->setPlaceholderText(ai);
|
||||
|
||||
this->setAudioRunsWhere();
|
||||
this->initAudioDeviceLists();
|
||||
|
||||
// default
|
||||
@@ -121,18 +118,16 @@ namespace BlackGui
|
||||
Q_ASSERT(c);
|
||||
c = connect(sGui->getCContextAudioBase(), &CContextAudioBase::startedAudio, this, &CAudioDeviceVolumeSetupComponent::onAudioStarted, Qt::QueuedConnection);
|
||||
Q_ASSERT(c);
|
||||
c = connect(sGui->getCContextAudioBase(), &CContextAudioBase::stoppedAudio, this, &CAudioDeviceVolumeSetupComponent::onAudioStopped, Qt::QueuedConnection);
|
||||
Q_ASSERT(c);
|
||||
|
||||
//! \todo Workaround to avoid context signals
|
||||
|
||||
c = connect(sGui->getCContextAudioBase()->afvClient(), &CAfvClient::outputVolumePeakVU, this, &CAudioDeviceVolumeSetupComponent::onOutputVU, Qt::QueuedConnection);
|
||||
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);
|
||||
|
||||
@@ -303,6 +298,12 @@ namespace BlackGui
|
||||
ui->hs_VolumeOut->setValue((ui->hs_VolumeOut->maximum() - ui->hs_VolumeOut->minimum()) / 2);
|
||||
}
|
||||
|
||||
void CAudioDeviceVolumeSetupComponent::setAudioRunsWhere()
|
||||
{
|
||||
const QString ai = sGui->getCContextAudioBase()->audioRunsWhereInfo();
|
||||
ui->le_Info->setPlaceholderText(ai);
|
||||
}
|
||||
|
||||
void CAudioDeviceVolumeSetupComponent::onReceivingCallsignsChanged(const CCallsignSet &com1Callsigns, const CCallsignSet &com2Callsigns)
|
||||
{
|
||||
const QString info = (com1Callsigns.isEmpty() ? QString() : QStringLiteral("COM1: ") % com1Callsigns.getCallsignsAsString()) %
|
||||
@@ -347,6 +348,12 @@ namespace BlackGui
|
||||
{
|
||||
ui->cb_SetupAudioInputDevice->setCurrentText(input.toQString(true));
|
||||
ui->cb_SetupAudioOutputDevice->setCurrentText(output.toQString(true));
|
||||
this->setAudioRunsWhere();
|
||||
}
|
||||
|
||||
void CAudioDeviceVolumeSetupComponent::onAudioStopped()
|
||||
{
|
||||
this->setAudioRunsWhere();
|
||||
}
|
||||
|
||||
bool CAudioDeviceVolumeSetupComponent::onAudioDevicesChanged(const CAudioDeviceInfoList &devices)
|
||||
@@ -354,6 +361,7 @@ namespace BlackGui
|
||||
if (m_cbDevices.hasSameDevices(devices)) { return false; } // avoid numerous follow up actions
|
||||
m_cbDevices = devices;
|
||||
|
||||
this->setAudioRunsWhere();
|
||||
ui->cb_SetupAudioOutputDevice->clear();
|
||||
ui->cb_SetupAudioInputDevice->clear();
|
||||
|
||||
@@ -374,6 +382,7 @@ namespace BlackGui
|
||||
|
||||
if (!i.isEmpty()) { ui->cb_SetupAudioInputDevice->setCurrentText(i); }
|
||||
if (!o.isEmpty()) { ui->cb_SetupAudioOutputDevice->setCurrentText(o); }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -73,6 +73,9 @@ namespace BlackGui
|
||||
//! Current audio devices changed
|
||||
void onAudioStarted(const BlackMisc::Audio::CAudioDeviceInfo &input, const BlackMisc::Audio::CAudioDeviceInfo &output);
|
||||
|
||||
//! Audio has been stopped
|
||||
void onAudioStopped();
|
||||
|
||||
//! Audio devices changed
|
||||
bool onAudioDevicesChanged(const BlackMisc::Audio::CAudioDeviceInfoList &devices);
|
||||
|
||||
@@ -101,6 +104,8 @@ namespace BlackGui
|
||||
void onResetVolumeIn();
|
||||
void onResetVolumeOut();
|
||||
|
||||
void setAudioRunsWhere();
|
||||
|
||||
// TODO: Move TransceiverReceivingCallsignsChangedArgs to Blackmisc
|
||||
void onReceivingCallsignsChanged(const BlackMisc::Aviation::CCallsignSet &com1Callsigns, const BlackMisc::Aviation::CCallsignSet &com2Callsigns);
|
||||
void onUpdatedClientWithCockpitData();
|
||||
|
||||
Reference in New Issue
Block a user