diff --git a/src/blackcore/context/contextaudioimpl.cpp b/src/blackcore/context/contextaudioimpl.cpp index 84602e9ca..83440576a 100644 --- a/src/blackcore/context/contextaudioimpl.cpp +++ b/src/blackcore/context/contextaudioimpl.cpp @@ -290,6 +290,8 @@ namespace BlackCore if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << volume; } bool wasMuted = isMuted(); + volume = qMin(CSettings::MaxAudioVolume, volume); + bool changedVoiceOutput = m_voiceOutputDevice->getOutputVolume() != volume; if (changedVoiceOutput) { @@ -588,9 +590,11 @@ namespace BlackCore return false; } - void CContextAudio::setVoiceTransmission(bool enable) + void CContextAudio::setVoiceTransmission(bool enable, COM com) { // FIXME: Use the 'active' channel instead of hardcoded COM1 + // FIXME: Use com + Q_UNUSED(com); if (!m_voiceChannelMapping.contains(CComSystem::Com1)) { return; } QSharedPointer voiceChannelCom1 = m_voiceChannelMapping.value(CComSystem::Com1); IAudioMixer::OutputPort mixerOutputPort = m_voiceChannelOutputPortMapping.value(voiceChannelCom1); @@ -606,6 +610,21 @@ namespace BlackCore } } + void CContextAudio::setVoiceTransmissionCom1(bool enabled) + { + this->setVoiceTransmission(enabled, COM1); + } + + void CContextAudio::setVoiceTransmissionCom2(bool enabled) + { + this->setVoiceTransmission(enabled, COM2); + } + + void CContextAudio::setVoiceTransmissionComActive(bool enabled) + { + this->setVoiceTransmission(enabled, COMActive); + } + void CContextAudio::onConnectionStatusChanged(BlackCore::IVoiceChannel::ConnectionStatus oldStatus, BlackCore::IVoiceChannel::ConnectionStatus newStatus) { @@ -677,6 +696,20 @@ namespace BlackCore this->setVoiceOutputVolume(s.getAudioVolume()); } + void CContextAudio::audioIncreaseVolume(bool enabled) + { + if (!enabled) { return; } + const int v = qRound(this->getVoiceOutputVolume() * 1.2); + this->setVoiceOutputVolume(v); + } + + void CContextAudio::audioDecreaseVolume(bool enabled) + { + if (!enabled) { return; } + const int v = qRound(this->getVoiceOutputVolume() / 1.2); + this->setVoiceOutputVolume(v); + } + QSharedPointer CContextAudio::getVoiceChannelBy(const CVoiceRoom &voiceRoom) { QSharedPointer voiceChannel; diff --git a/src/blackcore/context/contextaudioimpl.h b/src/blackcore/context/contextaudioimpl.h index 8a1b9b3e0..c788a7775 100644 --- a/src/blackcore/context/contextaudioimpl.h +++ b/src/blackcore/context/contextaudioimpl.h @@ -46,7 +46,7 @@ namespace BlackMisc { class CDBusServer; - namespace Audio { class CAudioDeviceInfo; } + namespace Audio { class CAudioDeviceInfo; } namespace Aviation { class CCallsign; } } @@ -121,6 +121,15 @@ namespace BlackCore CContextAudio *registerWithDBus(BlackMisc::CDBusServer *server); private: + // Voice COM channel + enum COM + { + COM1, + COM2, + COMActive, + COMUnspecified + }; + void initVoiceChannels(); void initInputDevice(); void initOutputDevice(); @@ -131,8 +140,12 @@ namespace BlackCore //! \sa IContextAudio::changedVoiceRooms void onConnectionStatusChanged(IVoiceChannel::ConnectionStatus oldStatus, IVoiceChannel::ConnectionStatus newStatus); - //! Enable/disable voice transmission - void setVoiceTransmission(bool enable); + //! Enable/disable voice transmission @{ + void setVoiceTransmission(bool enable, COM com); + void setVoiceTransmissionCom1(bool enabled); + void setVoiceTransmissionCom2(bool enabled); + void setVoiceTransmissionComActive(bool enabled); + //! @} //! User joined the room void onUserJoinedRoom(const BlackMisc::Aviation::CCallsign &callsign); @@ -149,20 +162,29 @@ namespace BlackCore //! Changed audio settings void onChangedAudioSettings(); + //! Audio increase/decrease @{ + void audioIncreaseVolume(bool enabled); + void audioDecreaseVolume(bool enabled); + //! @} + //! Voice channel by room QSharedPointer getVoiceChannelBy(const BlackMisc::Audio::CVoiceRoom &voiceRoom); - CActionBind m_actionPtt { BlackMisc::Input::pttHotkeyAction(), BlackMisc::Input::pttHotkeyIcon(), this, &CContextAudio::setVoiceTransmission }; + CActionBind m_actionPtt { BlackMisc::Input::pttHotkeyAction(), BlackMisc::Input::pttHotkeyIcon(), this, &CContextAudio::setVoiceTransmissionComActive }; + CActionBind m_actionPttCom1 { BlackMisc::Input::pttCom1HotkeyAction(), BlackMisc::Input::pttHotkeyIcon(), this, &CContextAudio::setVoiceTransmissionCom1 }; + CActionBind m_actionPttCom2 { BlackMisc::Input::pttCom2HotkeyAction(), BlackMisc::Input::pttHotkeyIcon(), this, &CContextAudio::setVoiceTransmissionCom2 }; + CActionBind m_actionAudioVolumeIncrease { BlackMisc::Input::audioVolumeIncreaseHotkeyAction(), BlackMisc::Input::audioVolumeIncreaseHotkeyIcon(), this, &CContextAudio::audioIncreaseVolume }; + CActionBind m_actionAudioVolumeDecrease { BlackMisc::Input::audioVolumeDecreaseHotkeyAction(), BlackMisc::Input::audioVolumeDecreaseHotkeyIcon(), this, &CContextAudio::audioDecreaseVolume }; std::unique_ptr m_voice; //!< underlying voice lib std::unique_ptr m_audioMixer; - const int MinUnmuteVolume = 20; //!< minimum volume when unmuted int m_outVolumeBeforeMute = 90; + static constexpr int MinUnmuteVolume = 20; //!< minimum volume when unmuted - #ifdef Q_OS_MAC +#ifdef Q_OS_MAC BlackMisc::CMacOSMicrophoneAccess m_micAccess; void delayedInitMicrophone(); - #endif +#endif // For easy access. QSharedPointer m_channel1; diff --git a/src/blackcore/inputmanager.cpp b/src/blackcore/inputmanager.cpp index 9d6bf9422..63bc61fea 100644 --- a/src/blackcore/inputmanager.cpp +++ b/src/blackcore/inputmanager.cpp @@ -35,7 +35,7 @@ namespace BlackCore if (!m_availableActions.contains(action)) { m_availableActions.insert(action, icon); - emit hotkeyActionRegistered({ action }); + emit this->hotkeyActionRegistered({ action }); } } @@ -46,7 +46,7 @@ namespace BlackCore if (!m_availableActions.contains(action)) { m_availableActions.insert(action, {}); - emit hotkeyActionRegistered({ action }); + emit this->hotkeyActionRegistered({ action }); } } } diff --git a/src/blackgui/components/settingshotkeycomponent.cpp b/src/blackgui/components/settingshotkeycomponent.cpp index f7d5d74fe..e0482e011 100644 --- a/src/blackgui/components/settingshotkeycomponent.cpp +++ b/src/blackgui/components/settingshotkeycomponent.cpp @@ -176,7 +176,7 @@ namespace BlackGui CIdentifierList CSettingsHotkeyComponent::getAllIdentifiers() const { CIdentifierList identifiers; - if (!sGui) { return identifiers; } + if (!sGui || !sGui->getIContextApplication()) { return identifiers; } if (sGui->getIContextApplication()) { identifiers = sGui->getIContextApplication()->getRegisteredApplications(); } // add local application @@ -188,7 +188,7 @@ namespace BlackGui { if (keyDown) { - QMessageBox* msgBox = new QMessageBox(this); + QMessageBox *msgBox = new QMessageBox(this); msgBox->setAttribute(Qt::WA_DeleteOnClose); msgBox->setStandardButtons(QMessageBox::Ok); msgBox->setWindowTitle("Test"); diff --git a/src/blackmisc/input/actionhotkeydefs.cpp b/src/blackmisc/input/actionhotkeydefs.cpp index eb3ebeac6..dc2694e2f 100644 --- a/src/blackmisc/input/actionhotkeydefs.cpp +++ b/src/blackmisc/input/actionhotkeydefs.cpp @@ -22,5 +22,39 @@ namespace BlackMisc { return CIcons::radio16(); } + + const QString &pttCom1HotkeyAction() + { + static const QString s("/Voice/Activate push-to-talk COM1"); + return s; + } + + const QString &pttCom2HotkeyAction() + { + static const QString s("/Voice/Activate push-to-talk COM2"); + return s; + } + + const QPixmap &audioVolumeDecreaseHotkeyIcon() + { + return CIcons::volumeLow16(); + } + + const QPixmap &audioVolumeIncreaseHotkeyIcon() + { + return CIcons::volumeHigh16(); + } + + const QString &audioVolumeDecreaseHotkeyAction() + { + static const QString s("/Audio/Volume decrease"); + return s; + } + + const QString &audioVolumeIncreaseHotkeyAction() + { + static const QString s("/Audio/Volume increase"); + return s; + } } // ns } // ns diff --git a/src/blackmisc/input/actionhotkeydefs.h b/src/blackmisc/input/actionhotkeydefs.h index 399020d9b..747646234 100644 --- a/src/blackmisc/input/actionhotkeydefs.h +++ b/src/blackmisc/input/actionhotkeydefs.h @@ -23,8 +23,27 @@ namespace BlackMisc //! PTT key BLACKMISC_EXPORT const QString &pttHotkeyAction(); + //! PTT key COM1 only + BLACKMISC_EXPORT const QString &pttCom1HotkeyAction(); + + //! PTT key COM2 only + BLACKMISC_EXPORT const QString &pttCom2HotkeyAction(); + //! PTT key BLACKMISC_EXPORT const QPixmap &pttHotkeyIcon(); + + //! Audio volume + key + BLACKMISC_EXPORT const QString &audioVolumeIncreaseHotkeyAction(); + + //! Audio volume - key + BLACKMISC_EXPORT const QString &audioVolumeDecreaseHotkeyAction(); + + //! Audio icon volume + + BLACKMISC_EXPORT const QPixmap &audioVolumeIncreaseHotkeyIcon(); + + //! Audio icon volume - + BLACKMISC_EXPORT const QPixmap &audioVolumeDecreaseHotkeyIcon(); + } // ns } // ns