From 7428cb0819cc7b97d309ce8d6319625cdd709919 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Mon, 21 Oct 2019 02:06:09 +0200 Subject: [PATCH] [AFV], Ref T730 play audio "tuned in"/"out" Replaces the former voice room connected sounds --- .../context/contextownaircraftimpl.cpp | 62 +++++++++++++++++-- .../context/contextownaircraftimpl.h | 6 ++ src/blackmisc/aviation/atcstationlist.cpp | 16 +++++ src/blackmisc/aviation/atcstationlist.h | 10 ++- 4 files changed, 88 insertions(+), 6 deletions(-) diff --git a/src/blackcore/context/contextownaircraftimpl.cpp b/src/blackcore/context/contextownaircraftimpl.cpp index 36f623f2a..6213ea140 100644 --- a/src/blackcore/context/contextownaircraftimpl.cpp +++ b/src/blackcore/context/contextownaircraftimpl.cpp @@ -23,10 +23,11 @@ #include "blackmisc/aviation/altitude.h" #include "blackmisc/aviation/callsign.h" #include "blackmisc/aviation/transponder.h" +#include "blackmisc/audio/notificationsounds.h" #include "blackcore/db/databaseutils.h" -#include "blackmisc/pq/physicalquantity.h" #include "blackmisc/geo/latitude.h" #include "blackmisc/geo/longitude.h" +#include "blackmisc/pq/physicalquantity.h" #include "blackmisc/pq/units.h" #include "blackmisc/simplecommandparser.h" #include "blackmisc/compare.h" @@ -245,6 +246,56 @@ namespace BlackCore return true; } + void CContextOwnAircraft::evaluateComStations(bool atcChanged) + { + if (!sApp || sApp->isShuttingDown() || !sApp->getCContextAudioBase() || !sApp->getIContextNetwork()) { return; } + + CComSystem com1; + CComSystem com2; + CComSystem lastCom1; + CComSystem lastCom2; + { + QReadLocker l(&m_lockAircraft); + com1 = m_ownAircraft.getCom1System(); + com2 = m_ownAircraft.getCom2System(); + lastCom1 = m_lastEvaluatedCom1; + lastCom2 = m_lastEvaluatedCom2; + } + + const bool changedCom1Freq = (lastCom1.getFrequencyActive() != com1.getFrequencyActive()); + const bool changedCom2Freq = (lastCom2.getFrequencyActive() != com2.getFrequencyActive()); + + if (!atcChanged && !changedCom1Freq && !changedCom2Freq) { return; } + + const CAtcStationList atcs = sApp->getIContextNetwork()->getAtcStationsOnline(true).findInRange(); + const bool atcCom1 = atcs.hasComUnitTunedInChannelSpacing(com1); + const bool atcCom2 = atcs.hasComUnitTunedInChannelSpacing(com2); + + const bool tunedIn1 = atcCom1 && !lastCom1.isReceiveEnabled(); + const bool tunedIn2 = atcCom2 && !lastCom2.isReceiveEnabled(); + const bool tunedOut1 = !atcCom1 && lastCom1.isReceiveEnabled(); + const bool tunedOut2 = !atcCom2 && lastCom2.isReceiveEnabled(); + + if (sApp && sApp->getCContextAudioBase() && sApp->getIContextNetwork()->isConnected()) + { + if (tunedIn1 || tunedIn2) + { + sApp->getCContextAudioBase()->playNotification(CNotificationSounds::NotificationAtcTunedIn, true); + } + else if (tunedOut1 || tunedOut2) + { + sApp->getCContextAudioBase()->playNotification(CNotificationSounds::NotificationAtcTunedOut, true); + } + } + + // remember if I was tuned in, abusing the flag + lastCom1.setReceiveEnabled(tunedIn1); + lastCom2.setReceiveEnabled(tunedIn2); + QWriteLocker l(&m_lockAircraft); + m_lastEvaluatedCom1 = lastCom1; + m_lastEvaluatedCom2 = lastCom2; + } + bool CContextOwnAircraft::updateOwnSituation(const CAircraftSituation &situation) { QWriteLocker l(&m_lockAircraft); @@ -309,6 +360,7 @@ namespace BlackCore } if (changed) { + this->evaluateComStations(false); emit this->changedAircraftCockpit(m_ownAircraft, originator); } return changed; @@ -349,7 +401,10 @@ namespace BlackCore { com2.setFrequencyActive(frequency); } - return this->updateCockpit(com1, com2, xpdr, originator); + + const bool changed = this->updateCockpit(com1, com2, xpdr, originator); + if (changed) { this->evaluateComStations(false); } + return changed; } bool CContextOwnAircraft::updateOwnAircraftPilot(const CUser &pilot) @@ -424,10 +479,9 @@ namespace BlackCore void CContextOwnAircraft::xCtxChangedAtcStationOnlineConnectionStatus(const CAtcStation &atcStation, bool connected) { - // any of our active frequencies? - // keep this to play notification sounds maybe Q_UNUSED(connected) Q_UNUSED(atcStation) + this->evaluateComStations(true); } void CContextOwnAircraft::xCtxChangedSimulatorModel(const CAircraftModel &model, const CIdentifier &identifier) diff --git a/src/blackcore/context/contextownaircraftimpl.h b/src/blackcore/context/contextownaircraftimpl.h index 5df240fde..f6cf10459 100644 --- a/src/blackcore/context/contextownaircraftimpl.h +++ b/src/blackcore/context/contextownaircraftimpl.h @@ -223,6 +223,9 @@ namespace BlackCore std::atomic_bool m_history { true }; //!< enable history BlackMisc::Aviation::CAircraftSituationList m_situationHistory; //!< history, latest situation first + BlackMisc::Aviation::CComSystem m_lastEvaluatedCom1; + BlackMisc::Aviation::CComSystem m_lastEvaluatedCom2; + BlackMisc::CSetting m_currentNetworkServer { this }; //! Station has been changed, needed to tune in/out voice room @@ -254,6 +257,9 @@ namespace BlackCore //! Update own model and emit signal with identifier bool updateOwnModel(const BlackMisc::Simulation::CAircraftModel &model, const BlackMisc::CIdentifier &identifier); + //! Evaluate COM stations + void evaluateComStations(bool atcChanged); + //! Reverse lookup of the model against DB data static BlackMisc::Simulation::CAircraftModel reverseLookupModel(const BlackMisc::Simulation::CAircraftModel &model); }; diff --git a/src/blackmisc/aviation/atcstationlist.cpp b/src/blackmisc/aviation/atcstationlist.cpp index b55f28ade..3d9266494 100644 --- a/src/blackmisc/aviation/atcstationlist.cpp +++ b/src/blackmisc/aviation/atcstationlist.cpp @@ -47,6 +47,14 @@ namespace BlackMisc }); } + bool CAtcStationList::hasComUnitTunedInChannelSpacing(const CComSystem &comUnit) const + { + return this->containsBy([&](const CAtcStation & atcStation) + { + return atcStation.isComUnitTunedInChannelSpacing(comUnit); + }); + } + CAtcStationList CAtcStationList::findIfFrequencyIsWithinSpacing(const CFrequency &frequency, CComSystem::ChannelSpacing spacing) { if (frequency.isNull()) { return CAtcStationList(); } @@ -110,6 +118,14 @@ namespace BlackMisc return this->removeIf(&CAtcStation::isInRange, false); } + CAtcStationList CAtcStationList::findInRange() const + { + if (this->isEmpty()) { return {}; } + CAtcStationList copy(*this); + copy.removeIfOutsideRange(); + return copy; + } + int CAtcStationList::synchronizeWithBookedStation(CAtcStation &bookedAtcStation) { int c = 0; diff --git a/src/blackmisc/aviation/atcstationlist.h b/src/blackmisc/aviation/atcstationlist.h index 721c53718..161ca6b23 100644 --- a/src/blackmisc/aviation/atcstationlist.h +++ b/src/blackmisc/aviation/atcstationlist.h @@ -46,12 +46,15 @@ namespace BlackMisc //! Construct from a base class object. CAtcStationList(const CSequence &other); - //! Find 0..n stations tune in frequency of COM unit (with 25kHz channel spacing) + //! Find 0..n stations tuned in frequency of COM unit (with 25kHz channel spacing) CAtcStationList findIfComUnitTunedIn25KHz(const CComSystem &comUnit) const; - //! Find 0..n stations tune in frequency of COM unit (with channel spacing) + //! Find 0..n stations tuned in frequency of COM unit (with channel spacing) CAtcStationList findIfComUnitTunedInChannelSpacing(const CComSystem &comUnit) const; + //! Any stations tuned in frequency of COM unit (with channel spacing) + bool hasComUnitTunedInChannelSpacing(const CComSystem &comUnit) const; + //! Find 0..n stations within channel spacing CAtcStationList findIfFrequencyIsWithinSpacing(const PhysicalQuantities::CFrequency &frequency, CComSystem::ChannelSpacing spacing); @@ -71,6 +74,9 @@ namespace BlackMisc //! Remove if marked outside of range int removeIfOutsideRange(); + //! Those in range + CAtcStationList findInRange() const; + //! Synchronize with ATC station representing booking information. //! Both sides (booking, online station) will be updated. //! \pre Can be used only if the stored data in this list are online ATC stations