From 6fc3d55d9a8aa2e9b71d43ae8dcf18331bf7e057 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sat, 23 May 2020 01:18:59 +0200 Subject: [PATCH] Fixed mute handling and audio LED * AFV client has own "changedMute" signal * unmute if started/stopped AFC client * in statusbar also check audio start/stop to refresh LEDs * see https://discordapp.com/channels/539048679160676382/539486309882789888/713491666971000872 --- src/blackcore/afv/clients/afvclient.cpp | 12 ++++++ src/blackcore/afv/clients/afvclient.h | 3 ++ src/blackcore/context/contextaudio.cpp | 10 +++-- .../components/infobarstatuscomponent.cpp | 41 +++++++++++++------ .../components/infobarstatuscomponent.h | 7 ++++ 5 files changed, 56 insertions(+), 17 deletions(-) diff --git a/src/blackcore/afv/clients/afvclient.cpp b/src/blackcore/afv/clients/afvclient.cpp index 5415f736f..f952e13cc 100644 --- a/src/blackcore/afv/clients/afvclient.cpp +++ b/src/blackcore/afv/clients/afvclient.cpp @@ -273,7 +273,10 @@ namespace BlackCore void CAfvClient::setMuted(bool mute) { + if (this->isMuted() == mute) { return; } this->setNormalizedOutputVolume(mute ? 0 : 50); + + emit this->changedMute(mute); } void CAfvClient::startAudio() @@ -352,6 +355,13 @@ namespace BlackCore this->onTimerUpdate(); // update values emit this->startedAudio(useInputDevice, useOutputDevice); + + if (this->isMuted()) + { + // un-mute after startup + this->setMuted(false); + } + } void CAfvClient::startAudio(const QString &inputDeviceName, const QString &outputDeviceName) @@ -388,6 +398,8 @@ namespace BlackCore } CLogMessage(this).info(u"AFV Client stopped"); + if (this->isMuted()) { this->setMuted(false); } + emit this->inputVolumePeakVU(0.0); emit this->outputVolumePeakVU(0.0); emit this->stoppedAudio(); diff --git a/src/blackcore/afv/clients/afvclient.h b/src/blackcore/afv/clients/afvclient.h index bca674b42..0234df0bd 100644 --- a/src/blackcore/afv/clients/afvclient.h +++ b/src/blackcore/afv/clients/afvclient.h @@ -313,6 +313,9 @@ namespace BlackCore //! Audio has been stopped void stoppedAudio(); + //! Mute changed + void changedMute(bool muted); + protected: //! \copydoc BlackMisc::CContinuousWorker::initialize virtual void initialize() override; diff --git a/src/blackcore/context/contextaudio.cpp b/src/blackcore/context/contextaudio.cpp index 076da9a47..96d2301b0 100644 --- a/src/blackcore/context/contextaudio.cpp +++ b/src/blackcore/context/contextaudio.cpp @@ -207,6 +207,7 @@ namespace BlackCore connect(m_voiceClient, &CAfvClient::startedAudio, this, &CContextAudioBase::startedAudio, Qt::QueuedConnection); connect(m_voiceClient, &CAfvClient::stoppedAudio, this, &CContextAudioBase::stoppedAudio, Qt::QueuedConnection); connect(m_voiceClient, &CAfvClient::ptt, this, &CContextAudioBase::ptt, Qt::QueuedConnection); + connect(m_voiceClient, &CAfvClient::changedMute, this, &CContextAudioBase::changedMute, Qt::QueuedConnection); connect(m_voiceClient, &CAfvClient::connectionStatusChanged, this, &CContextAudioBase::onAfvConnectionStatusChanged, Qt::QueuedConnection); connect(m_voiceClient, &CAfvClient::afvConnectionFailure, this, &CContextAudioBase::onAfvConnectionFailure, Qt::QueuedConnection); } @@ -429,6 +430,7 @@ namespace BlackCore const bool changedVoiceOutput = (currentVolume != volume); if (changedVoiceOutput) { + // TODO: KB 2020-05 the mute handling should entirely go to AFV client! m_voiceClient->setNormalizedOutputVolume(volume); m_outVolumeBeforeMute = volume; @@ -468,8 +470,8 @@ namespace BlackCore m_voiceClient->setMuted(muted); if (!muted) { m_voiceClient->setNormalizedOutputVolume(m_outVolumeBeforeMute); } - // signal - emit this->changedMute(muted); + // signal no longer need, signaled by m_voiceClient->setMuted + // emit this->changedMute(muted); } bool CContextAudioBase::isMuted() const @@ -503,13 +505,13 @@ namespace BlackCore if (!play) { return; } if (notification == CNotificationSounds::PTTClickKeyDown && (considerSettings && settings.noAudioTransmission())) { - /** + /* if (!this->canTalk()) { // warning sound notification = CNotificationSounds::NotificationNoAudioTransmission; } - **/ + */ } if (volume < 0 || volume > 100) diff --git a/src/blackgui/components/infobarstatuscomponent.cpp b/src/blackgui/components/infobarstatuscomponent.cpp index da27886d7..41296c054 100644 --- a/src/blackgui/components/infobarstatuscomponent.cpp +++ b/src/blackgui/components/infobarstatuscomponent.cpp @@ -53,14 +53,14 @@ namespace BlackGui this->adjustTextSize(); ui->lbl_Audio->setContextMenuPolicy(Qt::CustomContextMenu); - connect(ui->lbl_Audio, &QLabel::customContextMenuRequested, this, &CInfoBarStatusComponent::onCustomAudioContextMenuRequested); + connect(ui->lbl_Audio, &QLabel::customContextMenuRequested, this, &CInfoBarStatusComponent::onCustomAudioContextMenuRequested); connect(ui->comp_XpdrMode, &CTransponderModeComponent::changed, this, &CInfoBarStatusComponent::transponderModeChanged); Q_ASSERT_X(sGui, Q_FUNC_INFO, "Need sGui"); if (sGui->getIContextSimulator()) { connect(sGui->getIContextSimulator(), &IContextSimulator::simulatorStatusChanged, this, &CInfoBarStatusComponent::onSimulatorStatusChanged, Qt::QueuedConnection); - connect(sGui->getIContextSimulator(), &IContextSimulator::modelSetChanged, this, &CInfoBarStatusComponent::onMapperReady); + connect(sGui->getIContextSimulator(), &IContextSimulator::modelSetChanged, this, &CInfoBarStatusComponent::onMapperReady); connect(sGui, &CGuiApplication::changedInternetAccessibility, this, &CInfoBarStatusComponent::onInternetAccessibleChanged); // initial values @@ -70,7 +70,7 @@ namespace BlackGui if (sGui->getIContextNetwork()) { - connect(sGui->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CInfoBarStatusComponent::onNetworkConnectionChanged); + connect(sGui->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CInfoBarStatusComponent::onNetworkConnectionChanged, Qt::QueuedConnection); } if (sGui->getIContextApplication()) @@ -81,7 +81,9 @@ namespace BlackGui ui->led_Audio->setOn(CInfoBarStatusComponent::isAudioAvailableAndNotMuted()); if (sGui->getCContextAudioBase()) { - connect(sGui->getCContextAudioBase(), &CContextAudioBase::changedMute, this, &CInfoBarStatusComponent::onMuteChanged); + connect(sGui->getCContextAudioBase(), &CContextAudioBase::changedMute, this, &CInfoBarStatusComponent::onMuteChanged, Qt::QueuedConnection); + connect(sGui->getCContextAudioBase(), &CContextAudioBase::startedAudio, this, &CInfoBarStatusComponent::onAudioStarted, Qt::QueuedConnection); + connect(sGui->getCContextAudioBase(), &CContextAudioBase::stoppedAudio, this, &CInfoBarStatusComponent::onAudioStopped, Qt::QueuedConnection); // PTT as received on audio // that also would need to be reconnected if audio is disabled/enabled @@ -91,7 +93,7 @@ namespace BlackGui QPointer myself(this); QTimer::singleShot(5000, this, [ = ] { - if (!myself) { return; } + if (!sGui || sGui->isShuttingDown() || !myself) { return; } this->updateValues(); }); } @@ -103,14 +105,14 @@ namespace BlackGui { this->updateSpacing(); CLedWidget::LedShape shape = CLedWidget::Circle; - ui->led_DBus->setValues(CLedWidget::Yellow, CLedWidget::Black, shape, "DBus connected", "DBus disconnected", 14); - ui->led_Network->setValues(CLedWidget::Yellow, CLedWidget::Black, shape, "Network connected", "Network disconnected", 14); - ui->led_Simulator->setValues(CLedWidget::Yellow, CLedWidget::Black, CLedWidget::Blue, shape, "Simulator running", "Simulator disconnected", "Simulator connected", 14); + ui->led_DBus->setValues(CLedWidget::Yellow, CLedWidget::Black, shape, "DBus connected", "DBus disconnected", 14); + ui->led_Network->setValues(CLedWidget::Yellow, CLedWidget::Black, shape, "Network connected", "Network disconnected", 14); + ui->led_Simulator->setValues(CLedWidget::Yellow, CLedWidget::Black, CLedWidget::Blue, shape, "Simulator running", "Simulator disconnected", "Simulator connected", 14); ui->led_MapperReady->setValues(CLedWidget::Yellow, CLedWidget::Black, CLedWidget::Blue, shape, "Mapper ready", "Mappings not yet loaded", "Mappings not yet loaded", 14); shape = CLedWidget::Rounded; - ui->led_Ptt->setValues(CLedWidget::Yellow, CLedWidget::Black, shape, "Ptt", "Silence", 18); - ui->led_Audio->setValues(CLedWidget::Yellow, CLedWidget::Black, shape, "On", "Muted", 18); + ui->led_Ptt->setValues(CLedWidget::Yellow, CLedWidget::Black, shape, "Ptt", "Silence", 18); + ui->led_Audio->setValues(CLedWidget::Yellow, CLedWidget::Black, shape, "On", "Muted", 18); this->onInternetAccessibleChanged(sGui->isInternetAccessible()); } @@ -240,7 +242,20 @@ namespace BlackGui void CInfoBarStatusComponent::onMuteChanged(bool muted) { - ui->led_Audio->setOn(!muted); + const bool on = !muted && isAudioAvailableAndNotMuted(); // make sure audio is started + ui->led_Audio->setOn(on); + } + + void CInfoBarStatusComponent::onAudioStarted(const CAudioDeviceInfo &input, const CAudioDeviceInfo &output) + { + Q_UNUSED(input) + Q_UNUSED(output) + this->updateValues(); + } + + void CInfoBarStatusComponent::onAudioStopped() + { + this->updateValues(); } void CInfoBarStatusComponent::onMapperReady() @@ -276,12 +291,12 @@ namespace BlackGui Q_UNUSED(active) Q_UNUSED(pttcom) - /** + /* if (pttcom == COM1 || pttcom == COM2) { this->onPttChanged(active); } - **/ + */ } void CInfoBarStatusComponent::onInternetAccessibleChanged(bool access) diff --git a/src/blackgui/components/infobarstatuscomponent.h b/src/blackgui/components/infobarstatuscomponent.h index bce3b95ad..4e3122a89 100644 --- a/src/blackgui/components/infobarstatuscomponent.h +++ b/src/blackgui/components/infobarstatuscomponent.h @@ -15,6 +15,7 @@ #include "blackgui/blackguiexport.h" #include "blackmisc/audio/ptt.h" +#include "blackmisc/audio/audiodeviceinfo.h" #include "blackmisc/input/actionhotkeydefs.h" #include "blackmisc/network/connectionstatus.h" @@ -88,6 +89,12 @@ namespace BlackGui //! Mute changed void onMuteChanged(bool muted); + //! Audio started + void onAudioStarted(const BlackMisc::Audio::CAudioDeviceInfo &input, const BlackMisc::Audio::CAudioDeviceInfo &output); + + //! Audio stopped + void onAudioStopped(); + //! Mapper is ready void onMapperReady();