diff --git a/src/blackcore/context/contextaudioimpl.cpp b/src/blackcore/context/contextaudioimpl.cpp index c4f0370b8..4f6443673 100644 --- a/src/blackcore/context/contextaudioimpl.cpp +++ b/src/blackcore/context/contextaudioimpl.cpp @@ -44,6 +44,7 @@ using namespace BlackMisc::Audio; using namespace BlackMisc::Input; using namespace BlackMisc::Audio; using namespace BlackMisc::PhysicalQuantities; +using namespace BlackMisc::Simulation; using namespace BlackSound; using namespace BlackCore::Vatsim; @@ -53,6 +54,7 @@ namespace BlackCore { CContextAudio::CContextAudio(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : IContextAudio(mode, runtime), + CIdentifiable(this), m_voice(new CVoiceVatlib()) { initVoiceChannels(); @@ -140,12 +142,12 @@ namespace BlackCore } m_voice->connectVoice(m_channel1.data(), m_audioMixer.get(), IAudioMixer::InputVoiceChannel1); m_voice->connectVoice(m_channel2.data(), m_audioMixer.get(), IAudioMixer::InputVoiceChannel2); - m_voice->connectVoice(m_audioMixer.get(), IAudioMixer::OutputOutputDevice1, m_voiceOutputDevice.get()); + m_voice->connectVoice(m_audioMixer.get(), IAudioMixer::OutputDevice1, m_voiceOutputDevice.get()); m_voice->connectVoice(m_audioMixer.get(), IAudioMixer::OutputVoiceChannel1, m_channel1.data()); m_voice->connectVoice(m_audioMixer.get(), IAudioMixer::OutputVoiceChannel2, m_channel2.data()); - m_audioMixer->makeMixerConnection(IAudioMixer::InputVoiceChannel1, IAudioMixer::OutputOutputDevice1); - m_audioMixer->makeMixerConnection(IAudioMixer::InputVoiceChannel2, IAudioMixer::OutputOutputDevice2); + m_audioMixer->makeMixerConnection(IAudioMixer::InputVoiceChannel1, IAudioMixer::OutputDevice1); + m_audioMixer->makeMixerConnection(IAudioMixer::InputVoiceChannel2, IAudioMixer::OutputDevice1); } CContextAudio::~CContextAudio() @@ -531,11 +533,11 @@ namespace BlackCore if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } if (enable) { - m_audioMixer->makeMixerConnection(IAudioMixer::InputMicrophone, IAudioMixer::OutputOutputDevice1); + m_audioMixer->makeMixerConnection(IAudioMixer::InputMicrophone, IAudioMixer::OutputDevice1); } else { - m_audioMixer->removeMixerConnection(IAudioMixer::InputMicrophone, IAudioMixer::OutputOutputDevice1); + m_audioMixer->removeMixerConnection(IAudioMixer::InputMicrophone, IAudioMixer::OutputDevice1); } } @@ -543,7 +545,7 @@ namespace BlackCore { Q_ASSERT(m_audioMixer); if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - return m_audioMixer->hasMixerConnection(IAudioMixer::InputMicrophone, IAudioMixer::OutputOutputDevice1); + return m_audioMixer->hasMixerConnection(IAudioMixer::InputMicrophone, IAudioMixer::OutputDevice1); } void CContextAudio::setVoiceSetup(const CVoiceSetup &setup) @@ -595,9 +597,34 @@ namespace BlackCore void CContextAudio::setVoiceTransmission(bool enable, COM com) { - // FIXME: Use the 'active' channel instead of hardcoded COM1 - // FIXME: Use com - Q_UNUSED(com); + // first apporach of T609 multiple COM + QSharedPointer voiceChannelCom = nullptr; + CComSystem::ComUnit usedUnit = CComSystem::Com1; + + if (com == COM1 && m_voiceChannelMapping.contains(CComSystem::Com1)) { usedUnit = CComSystem::Com1; voiceChannelCom = m_voiceChannelMapping.value(usedUnit); } + else if (com == COM2 && m_voiceChannelMapping.contains(CComSystem::Com2)) { usedUnit = CComSystem::Com2; voiceChannelCom = m_voiceChannelMapping.value(usedUnit); } + else if (com == COMActive && m_voiceChannelMapping.contains(CComSystem::Com1)) { usedUnit = CComSystem::Com1; voiceChannelCom = m_voiceChannelMapping.value(usedUnit); } + else if (com == COMActive && m_voiceChannelMapping.contains(CComSystem::Com2)) { usedUnit = CComSystem::Com2; voiceChannelCom = m_voiceChannelMapping.value(usedUnit); } + if (!voiceChannelCom) { return; } + IAudioMixer::OutputPort mixerOutputPort = m_voiceChannelOutputPortMapping.value(voiceChannelCom); + + // use values from simulator? + if (enable && this->isComIntegratedWithSimulator()) + { + const CComSystem comSystem = this->getOwnComSystem(usedUnit); + enable = comSystem.isTransmitEnabled(); // consider muted + } + + if (enable) + { + m_audioMixer->makeMixerConnection(IAudioMixer::InputMicrophone, mixerOutputPort); + } + else + { + m_audioMixer->removeMixerConnection(IAudioMixer::InputMicrophone, mixerOutputPort); + } + + /** fixme KB 201908 to be removed if the above works if (!m_voiceChannelMapping.contains(CComSystem::Com1)) { return; } QSharedPointer voiceChannelCom1 = m_voiceChannelMapping.value(CComSystem::Com1); IAudioMixer::OutputPort mixerOutputPort = m_voiceChannelOutputPortMapping.value(voiceChannelCom1); @@ -611,6 +638,7 @@ namespace BlackCore m_audioMixer->removeMixerConnection(IAudioMixer::InputMicrophone, IAudioMixer::OutputVoiceChannel1); m_audioMixer->removeMixerConnection(IAudioMixer::InputMicrophone, IAudioMixer::OutputVoiceChannel2); } + **/ } void CContextAudio::setVoiceTransmissionCom1(bool enabled) @@ -689,7 +717,7 @@ namespace BlackCore break; } } - } + } // device name } void CContextAudio::onChangedAudioSettings() @@ -719,13 +747,14 @@ namespace BlackCore if (!this->getIContextOwnAircraft()) { // context not available + const double defFreq = 122.8; switch (unit) { - case CComSystem::Com1: return CComSystem::getCom1System(122.800, 122.800); - case CComSystem::Com2: return CComSystem::getCom2System(122.800, 122.800); + case CComSystem::Com1: return CComSystem::getCom1System(defFreq, defFreq); + case CComSystem::Com2: return CComSystem::getCom2System(defFreq, defFreq); default: break; } - return CComSystem::getCom1System(122.800, 122.800); + return CComSystem::getCom1System(defFreq, defFreq); } return this->getIContextOwnAircraft()->getOwnComSystem(unit); } @@ -736,6 +765,27 @@ namespace BlackCore return this->getIContextSimulator()->getSimulatorSettings().isComIntegrated(); } + void CContextAudio::xCtxChangedAircraftCockpit(const CSimulatedAircraft &aircraft, const CIdentifier &originator) + { + if (CIdentifiable::isMyIdentifier(originator)) { return; } + const bool integrated = this->isComIntegratedWithSimulator(); + + if (integrated) + { + // set as in cockpit + const bool com1Rec = aircraft.getCom1System().isReceiveEnabled(); + const bool com2Rec = aircraft.getCom2System().isReceiveEnabled(); + m_audioMixer->makeOrRemoveConnection(IAudioMixer::InputVoiceChannel1, IAudioMixer::OutputDevice1, com1Rec); + m_audioMixer->makeOrRemoveConnection(IAudioMixer::InputVoiceChannel2, IAudioMixer::OutputDevice1, com2Rec); + } + else + { + // reset + m_audioMixer->makeMixerConnectionIfNotExisting(IAudioMixer::InputVoiceChannel1, IAudioMixer::OutputDevice1); + m_audioMixer->makeMixerConnectionIfNotExisting(IAudioMixer::InputVoiceChannel2, IAudioMixer::OutputDevice1); + } + } + QSharedPointer CContextAudio::getVoiceChannelBy(const CVoiceRoom &voiceRoom) { QSharedPointer voiceChannel; diff --git a/src/blackcore/context/contextaudioimpl.h b/src/blackcore/context/contextaudioimpl.h index b78b36970..a3a1aa66a 100644 --- a/src/blackcore/context/contextaudioimpl.h +++ b/src/blackcore/context/contextaudioimpl.h @@ -27,6 +27,7 @@ #include "blackmisc/aviation/comsystem.h" #include "blackmisc/aviation/selcal.h" #include "blackmisc/macos/microphoneaccess.h" +#include "blackmisc/identifiable.h" #include "blackmisc/identifier.h" #include "blackmisc/network/userlist.h" #include "blackmisc/settingscache.h" @@ -62,7 +63,9 @@ namespace BlackCore namespace Context { //! Audio context implementation - class BLACKCORE_EXPORT CContextAudio : public IContextAudio + class BLACKCORE_EXPORT CContextAudio : + public IContextAudio, + public BlackMisc::CIdentifiable { Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTAUDIO_INTERFACENAME) Q_OBJECT @@ -91,7 +94,7 @@ namespace BlackCore virtual BlackMisc::Audio::CAudioDeviceInfoList getCurrentAudioDevices() const override; virtual void setCurrentAudioDevice(const BlackMisc::Audio::CAudioDeviceInfo &audioDevice) override; virtual void setVoiceOutputVolume(int volume) override; - virtual int getVoiceOutputVolume() const override; + virtual int getVoiceOutputVolume() const override; virtual void setMute(bool muted) override; virtual bool isMuted() const override; virtual void playSelcalTone(const BlackMisc::Aviation::CSelcal &selcal) const override; @@ -174,6 +177,10 @@ namespace BlackCore bool isComIntegratedWithSimulator() const; //! @} + //! Changed cockpit + //! \remark cross context + void xCtxChangedAircraftCockpit(const BlackMisc::Simulation::CSimulatedAircraft &aircraft, const BlackMisc::CIdentifier &originator); + //! Voice channel by room QSharedPointer getVoiceChannelBy(const BlackMisc::Audio::CVoiceRoom &voiceRoom); diff --git a/src/blackcore/corefacade.cpp b/src/blackcore/corefacade.cpp index ded27eeae..32fbe8897 100644 --- a/src/blackcore/corefacade.cpp +++ b/src/blackcore/corefacade.cpp @@ -259,6 +259,14 @@ namespace BlackCore c = connect(this->getCContextOwnAircraft(), &CContextOwnAircraft::ps_changedModel, this->getCContextSimulator(), &CContextSimulator::xCtxChangedOwnAircraftModel); Q_ASSERT(c); + + + // hook up with audio + if (this->getIContextAudio()) + { + c = connect(m_contextOwnAircraft, &IContextOwnAircraft::changedAircraftCockpit, this->getCContextAudio(), &CContextAudio::xCtxChangedAircraftCockpit, Qt::QueuedConnection); + Q_ASSERT(c); + } } // times @@ -279,8 +287,7 @@ namespace BlackCore if (m_contextAudio && m_contextAudio->isUsingImplementingObject()) { Q_ASSERT(m_contextApplication); - Q_ASSERT(m_contextOwnAircraft); - c = connect(m_contextApplication, &IContextApplication::fakedSetComVoiceRoom, this->getCContextAudio(), &CContextAudio::setComVoiceRooms); + c = connect(m_contextApplication, &IContextApplication::fakedSetComVoiceRoom, this->getCContextAudio(), &CContextAudio::setComVoiceRooms, Qt::QueuedConnection); Q_ASSERT(c); times.insert("Post setup, connects audio", time.restart()); }