diff --git a/src/blackcore/context_audio.h b/src/blackcore/context_audio.h index 8b9ada420..16e58703a 100644 --- a/src/blackcore/context_audio.h +++ b/src/blackcore/context_audio.h @@ -74,6 +74,16 @@ namespace BlackCore //! \details the flag indicates, whether a room got connected or disconnected void changedVoiceRooms(const BlackMisc::Audio::CVoiceRoomList &voiceRooms, bool connected); + //! Volumes changed (COM1, COM2) + //! \sa setVolumes + // KB: Is see some potential changes here, which we should do when we have the new 2.0 vatlib + // 1. volume integrated in voice room? + // 2. Value object for volumes CVolume / CVolumeList? + void changedAudioVolumes(QList volumes); + + //! Mute changed + void changedMute(bool muted); + public slots: //! Get voice rooms for COM1, COM2: virtual BlackMisc::Audio::CVoiceRoomList getComVoiceRoomsWithAudioStatus() const = 0; @@ -135,6 +145,12 @@ namespace BlackCore */ virtual void setVolumes(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2) = 0; + //! Set the volumes (0..100) + virtual void setVolumes(qint32 volumeCom1, qint32 volumeCom2) = 0; + + //! Set mute state + virtual void setMute(bool mute) = 0; + //! Is muted? virtual bool isMuted() const = 0; diff --git a/src/blackcore/context_audio_impl.cpp b/src/blackcore/context_audio_impl.cpp index 38677d673..b99f6e1f9 100644 --- a/src/blackcore/context_audio_impl.cpp +++ b/src/blackcore/context_audio_impl.cpp @@ -30,24 +30,21 @@ namespace BlackCore * Init this context */ CContextAudio::CContextAudio(CRuntimeConfig::ContextMode mode, CRuntime *runtime) : - IContextAudio(mode, runtime), m_voice(nullptr), m_inputManager(nullptr) + IContextAudio(mode, runtime), + m_voice(new CVoiceVatlib()) { // 1. Init by "voice driver" - this->m_voice = new CVoiceVatlib(); m_voice->moveToThread(&m_threadVoice); m_threadVoice.start(); // 2. Register PTT hotkey function + CVoiceVatlib *voice = m_voice.data(); m_inputManager = CInputManager::getInstance(); - m_handlePtt = m_inputManager->registerHotkeyFunc(CHotkeyFunction::Ptt(), m_voice, &CVoiceVatlib::handlePushToTalk); + m_handlePtt = m_inputManager->registerHotkeyFunc(CHotkeyFunction::Ptt(), voice, &CVoiceVatlib::handlePushToTalk); - // 3. own aircraft, if possible - //if (this->getIContextOwnAircraft()) m_voice->setMyAircraftCallsign(this->getIContextOwnAircraft()->getOwnAircraft().getCallsign()); - - // 4. Signal / slots - connect(this->m_voice, &CVoiceVatlib::micTestFinished, this, &CContextAudio::audioTestCompleted); - connect(this->m_voice, &CVoiceVatlib::squelchTestFinished, this, &CContextAudio::audioTestCompleted); - //connect(this->m_voice, &CVoiceVatlib::connectionStatusChanged, this, &CContextAudio::ps_connectionStatusChanged); + // 3. Signal / slots + connect(voice, &CVoiceVatlib::micTestFinished, this, &CContextAudio::audioTestCompleted); + connect(voice, &CVoiceVatlib::squelchTestFinished, this, &CContextAudio::audioTestCompleted); m_channelCom1 = m_voice->getVoiceChannel(0); m_channelCom1->setMyAircraftCallsign(getIContextOwnAircraft()->getOwnAircraft().getCallsign()); @@ -56,7 +53,7 @@ namespace BlackCore m_channelCom2->setMyAircraftCallsign(getIContextOwnAircraft()->getOwnAircraft().getCallsign()); connect(m_channelCom2.data(), &IVoiceChannel::connectionStatusChanged, this, &CContextAudio::ps_com2ConnectionStatusChanged); - // 5. load sounds (init), not possible in own thread + // 4. load sounds (init), not possible in own thread QTimer::singleShot(10 * 1000, this, SLOT(ps_initNotificationSounds())); } @@ -178,14 +175,32 @@ namespace BlackCore // volumes qint32 vol1 = com1.getVolumeOutput(); qint32 vol2 = com2.getVolumeOutput(); - m_channelCom1->setRoomOutputVolume(vol1); - m_channelCom2->setRoomOutputVolume(vol2); + this->setVolumes(vol1, vol2); // enable / disable in the same step m_channelCom1->switchAudioOutput(com1.isEnabled()); m_channelCom2->switchAudioOutput(com2.isEnabled()); } + void CContextAudio::setVolumes(qint32 com1Volume, qint32 com2Volume) + { + if (m_channelCom1->getVolume() == com1Volume && m_channelCom2->getVolume() == com2Volume) { return; } + + m_channelCom1->setRoomOutputVolume(com1Volume); + m_channelCom2->setRoomOutputVolume(com2Volume); + m_channelCom1->switchAudioOutput(com1Volume < 1); + m_channelCom2->switchAudioOutput(com2Volume < 1); + emit changedAudioVolumes(QList({com1Volume, com2Volume})); + } + + void CContextAudio::setMute(bool muted) + { + if (this->isMuted() == muted) { return; } // avoid roundtrips / unnecessary signals + m_channelCom1->switchAudioOutput(!muted); + m_channelCom2->switchAudioOutput(!muted); + emit changedMute(muted); + } + /* * Muted? */ @@ -389,7 +404,7 @@ namespace BlackCore case IVoiceChannel::ConnectingFailed: case IVoiceChannel::DisconnectedError: qWarning() << "Voice room COM1 error"; - // intentional fall-through + // intentional fall-through case IVoiceChannel::Disconnected: if (this->getIContextOwnAircraft()) { @@ -420,7 +435,7 @@ namespace BlackCore case IVoiceChannel::ConnectingFailed: case IVoiceChannel::DisconnectedError: qWarning() << "Voice room COM2 error"; - // intentional fall-through + // intentional fall-through case IVoiceChannel::Disconnected: if (this->getIContextOwnAircraft()) { diff --git a/src/blackcore/context_audio_impl.h b/src/blackcore/context_audio_impl.h index d8599ef4a..de3ae6303 100644 --- a/src/blackcore/context_audio_impl.h +++ b/src/blackcore/context_audio_impl.h @@ -19,6 +19,7 @@ #include #include #include +#include namespace BlackCore { @@ -81,6 +82,12 @@ namespace BlackCore //! \copydoc IContextAudio::setVolumes virtual void setVolumes(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2) override; + //!\copydoc IContext::setVolumes + virtual void setVolumes(qint32 com1Volume, qint32 com2Volume) override; + + //! \copydoc ICOntext::setMute + virtual void setMute(bool muted) override; + //! \copydoc IContextAudio::isMuted() virtual bool isMuted() const override; @@ -134,8 +141,10 @@ namespace BlackCore //! Connection in transition bool inTransitionState() const; - CVoiceVatlib *m_voice; //!< underlying voice lib - CInputManager *m_inputManager; + // TODO: see #339, MS' comment on deletion in another thread + QScopedPointer m_voice; //!< underlying voice lib + + CInputManager *m_inputManager = nullptr; CInputManager::RegistrationHandle m_handlePtt; QThread m_threadVoice; QPointer m_channelCom1; diff --git a/src/blackcore/context_audio_proxy.cpp b/src/blackcore/context_audio_proxy.cpp index 4ad79750f..4cb3880f9 100644 --- a/src/blackcore/context_audio_proxy.cpp +++ b/src/blackcore/context_audio_proxy.cpp @@ -19,13 +19,12 @@ namespace BlackCore CContextAudioProxy::CContextAudioProxy(const QString &serviceName, QDBusConnection &connection, CRuntimeConfig::ContextMode mode, CRuntime *runtime) : IContextAudio(mode, runtime), m_dBusInterface(nullptr) { this->m_dBusInterface = new BlackMisc::CGenericDBusInterface( - serviceName, IContextAudio::ObjectPath(), IContextAudio::InterfaceName(), - connection, this); + serviceName, IContextAudio::ObjectPath(), IContextAudio::InterfaceName(), connection, this); this->relaySignals(serviceName, connection); } /* - * Workaround for signals, not working without, but why? + * Relaying signals */ void CContextAudioProxy::relaySignals(const QString &serviceName, QDBusConnection &connection) { @@ -33,7 +32,13 @@ namespace BlackCore "audioTestCompleted", this, SIGNAL(audioTestCompleted())); Q_ASSERT(s); s = connection.connect(serviceName, IContextAudio::ObjectPath(), IContextAudio::InterfaceName(), - "changedVoiceRooms", this, SIGNAL(changedVoiceRooms(BlackMisc::Audio::CVoiceRoomList, bool))); + "changedVoiceRooms", this, SIGNAL(changedVoiceRooms(BlackMisc::Audio::CVoiceRoomList, bool))); + Q_ASSERT(s); + s = connection.connect(serviceName, IContextAudio::ObjectPath(), IContextAudio::InterfaceName(), + "changedAudioVolumes", this, SIGNAL(changedAudioVolumes(QList))); + Q_ASSERT(s); + s = connection.connect(serviceName, IContextAudio::ObjectPath(), IContextAudio::InterfaceName(), + "changedMute", this, SIGNAL(changedMute(bool))); Q_ASSERT(s); Q_UNUSED(s); } @@ -198,6 +203,22 @@ namespace BlackCore this->m_dBusInterface->callDBus(QLatin1Literal("setVolumes"), com1, com2); } + /* + * Volumes + */ + void CContextAudioProxy::setVolumes(qint32 com1Volume, qint32 com2Volume) + { + this->m_dBusInterface->callDBus(QLatin1Literal("setVolumes"), com1Volume, com2Volume); + } + + /* + * Toggle mute + */ + void CContextAudioProxy::setMute(bool muted) + { + return this->m_dBusInterface->callDBus(QLatin1Literal("setMute"), muted); + } + /* * Muted? */ diff --git a/src/blackcore/context_audio_proxy.h b/src/blackcore/context_audio_proxy.h index 5cdd22d88..290abb700 100644 --- a/src/blackcore/context_audio_proxy.h +++ b/src/blackcore/context_audio_proxy.h @@ -87,6 +87,12 @@ namespace BlackCore //! \copydoc IContextAudio::setVolumes() virtual void setVolumes(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2) override; + //!\copydoc IContextAudio::setVolumes + virtual void setVolumes(qint32 com1Volume, qint32 com2Volume) override; + + //! \copydoc IContextAudio::setMute + virtual void setMute(bool muted) override; + //! \copydoc IContextAudio::isMuted() virtual bool isMuted() const override;