From 0e03e7baf06c1687cb5e7ba9106a16e5032d384f Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Tue, 5 Mar 2019 23:34:39 +0100 Subject: [PATCH] Ref T558, play notification sound after SELCAL tone * return SELCAL tone duration * play follow up tone --- src/blackcore/context/contextaudioimpl.cpp | 42 +++++++++++----------- src/blacksound/selcalplayer.cpp | 15 ++++---- src/blacksound/selcalplayer.h | 7 ++-- 3 files changed, 33 insertions(+), 31 deletions(-) diff --git a/src/blackcore/context/contextaudioimpl.cpp b/src/blackcore/context/contextaudioimpl.cpp index 3fa7ee11f..0920caac9 100644 --- a/src/blackcore/context/contextaudioimpl.cpp +++ b/src/blackcore/context/contextaudioimpl.cpp @@ -29,16 +29,19 @@ #include "blackmisc/statusmessage.h" #include "blacksound/soundgenerator.h" -#include #include #include +#include + #include +#include using namespace BlackMisc; using namespace BlackMisc::Aviation; using namespace BlackMisc::Audio; using namespace BlackMisc::Input; using namespace BlackMisc::Audio; +using namespace BlackMisc::PhysicalQuantities; using namespace BlackSound; using namespace BlackCore::Vatsim; @@ -114,15 +117,8 @@ namespace BlackCore Q_ASSERT(m_voice); if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << withAudioStatus; } - auto voiceChannel = m_voiceChannelMapping.value(comUnitValue); - if (voiceChannel) - { - return voiceChannel->getVoiceRoom(); - } - else - { - return CVoiceRoom(); - } + const auto voiceChannel = m_voiceChannelMapping.value(comUnitValue); + return voiceChannel ? voiceChannel->getVoiceRoom() : CVoiceRoom(); } CVoiceRoomList CContextAudio::getComVoiceRooms() const @@ -401,15 +397,8 @@ namespace BlackCore Q_ASSERT(m_voice); if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - auto voiceChannel = m_voiceChannelMapping.value(comUnitValue); - if (voiceChannel) - { - return voiceChannel->getVoiceRoomCallsigns(); - } - else - { - return CCallsignSet(); - } + const auto voiceChannel = m_voiceChannelMapping.value(comUnitValue); + return voiceChannel ? voiceChannel->getVoiceRoomCallsigns() : CCallsignSet(); } Network::CUserList CContextAudio::getRoomUsers(BlackMisc::Aviation::CComSystem::ComUnit comUnit) const @@ -426,7 +415,18 @@ namespace BlackCore { Q_ASSERT(m_voice); if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << selcal; } - m_selcalPlayer->play(90, selcal); + const CTime t = m_selcalPlayer->play(90, selcal); + const int ms = t.toMs(); + if (ms > 10) + { + // As of https://dev.swift-project.org/T558 play additional notification + const QPointer myself(const_cast(this)); //! \fixme KB 2019-03 add bit hacky as I need non-const and do not want to change all signatures + QTimer::singleShot(ms, this, [ = ] + { + if (!sApp || sApp->isShuttingDown() || !myself) { return; } + this->playNotification(CNotificationSounds::NotificationTextMessageSupervisor, true); + }); + } } void CContextAudio::playNotification(CNotificationSounds::NotificationFlag notification, bool considerSettings) const @@ -545,7 +545,7 @@ namespace BlackCore case IVoiceChannel::ConnectingFailed: case IVoiceChannel::DisconnectedError: CLogMessage(this).warning(u"Voice channel disconnecting error"); - // intentional fall-through + Q_FALLTHROUGH(); case IVoiceChannel::Disconnected: emit this->changedVoiceRooms(getComVoiceRooms(), false); break; diff --git a/src/blacksound/selcalplayer.cpp b/src/blacksound/selcalplayer.cpp index 334b42cf4..563b74b70 100644 --- a/src/blacksound/selcalplayer.cpp +++ b/src/blacksound/selcalplayer.cpp @@ -27,19 +27,22 @@ namespace BlackSound m_threadedPlayer.quitAndWait(); } - void CSelcalPlayer::play(int volume, const BlackMisc::Aviation::CSelcal &selcal) + CTime CSelcalPlayer::play(int volume, const CSelcal &selcal) { + CTime duration = CTime::null(); if (selcal.isValid()) { - QList frequencies = selcal.getFrequencies(); + const QList frequencies = selcal.getFrequencies(); Q_ASSERT(frequencies.size() == 4); - const BlackMisc::PhysicalQuantities::CTime oneSec(1000.0, BlackMisc::PhysicalQuantities::CTimeUnit::ms()); - CTonePair t1(frequencies.at(0), frequencies.at(1), oneSec); - CTonePair t2({}, {}, oneSec / 5.0); - CTonePair t3(frequencies.at(2), frequencies.at(3), oneSec); + const CTime oneSec(1000.0, CTimeUnit::ms()); + const CTonePair t1(frequencies.at(0), frequencies.at(1), oneSec); + const CTonePair t2({}, {}, oneSec / 5.0); + const CTonePair t3(frequencies.at(2), frequencies.at(3), oneSec); QList tonePairs; tonePairs << t1 << t2 << t3; m_threadedPlayer.play(volume, tonePairs); + duration = oneSec * 2.5; } + return duration; } } diff --git a/src/blacksound/selcalplayer.h b/src/blacksound/selcalplayer.h index d8f27a784..1ea0350b6 100644 --- a/src/blacksound/selcalplayer.h +++ b/src/blacksound/selcalplayer.h @@ -11,16 +11,14 @@ #ifndef BLACKSOUND_SELCALPLAYER_H #define BLACKSOUND_SELCALPLAYER_H -#include "blacksoundexport.h" #include "blacksound/threadedtonepairplayer.h" #include "blacksound/tonepair.h" +#include "blacksoundexport.h" #include "blackmisc/aviation/selcal.h" #include "blackmisc/worker.h" #include -class QTimer; - namespace BlackSound { //! SELCAL player @@ -36,7 +34,8 @@ namespace BlackSound ~CSelcalPlayer(); //! Play selcal - void play(int volume, const BlackMisc::Aviation::CSelcal &selcal); + //! \return Time of the played tone + BlackMisc::PhysicalQuantities::CTime play(int volume, const BlackMisc::Aviation::CSelcal &selcal); private: CThreadedTonePairPlayer m_threadedPlayer;