From a764a2de7e9adcc24f735fb592fe7264876c39b7 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Tue, 30 Apr 2019 12:32:54 +0200 Subject: [PATCH] Added value for notification volume in sound setting --- src/blackcore/context/contextaudioimpl.cpp | 4 +++- src/blackgui/components/textmessagecomponent.cpp | 2 +- src/blackmisc/audio/audiosettings.cpp | 11 ++++++++++- src/blackmisc/audio/audiosettings.h | 12 ++++++++++-- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/blackcore/context/contextaudioimpl.cpp b/src/blackcore/context/contextaudioimpl.cpp index 66546ede5..2593b49b8 100644 --- a/src/blackcore/context/contextaudioimpl.cpp +++ b/src/blackcore/context/contextaudioimpl.cpp @@ -449,7 +449,9 @@ namespace BlackCore } } - m_notificationPlayer.play(notification, 90); + int volume = 90; + if (considerSettings) { volume = qMax(25, settings.getNotificationVolume()); } + m_notificationPlayer.play(notification, 100); } void CContextAudio::enableAudioLoopback(bool enable) diff --git a/src/blackgui/components/textmessagecomponent.cpp b/src/blackgui/components/textmessagecomponent.cpp index 65fdfba9b..4c6beaa65 100644 --- a/src/blackgui/components/textmessagecomponent.cpp +++ b/src/blackgui/components/textmessagecomponent.cpp @@ -467,7 +467,7 @@ namespace BlackGui // sound const bool playSound = !m_usedAsOverlayWidget && sGui && !sGui->isShuttingDown() && sGui->getIContextAudio(); - if (playSound) + if (sGui && sGui->getIContextAudio() && playSound) { const CSettings settings = m_audioSettings.get(); if (textMessage.isSupervisorMessage() && settings.textMessageSupervisor()) diff --git a/src/blackmisc/audio/audiosettings.cpp b/src/blackmisc/audio/audiosettings.cpp index e088f4617..f1436bbe1 100644 --- a/src/blackmisc/audio/audiosettings.cpp +++ b/src/blackmisc/audio/audiosettings.cpp @@ -55,15 +55,24 @@ namespace BlackMisc m_notificationSoundDir = d; } + void CSettings::setNotificationVolume(int volume) + { + m_notificationVolume = volume; + if (m_notificationVolume < 0) { m_notificationVolume = 0; } + else if (m_notificationVolume > 100) { m_notificationVolume = 100; } + } + QString CSettings::convertToQString(bool i18n) const { Q_UNUSED(i18n); - return u"Notification flags: " % CNotificationSounds::toString(this->getNotification()); + return u"Notification flags: " % CNotificationSounds::toString(this->getNotification()) % + u" volume: " % QString::number(m_notificationVolume); } void CSettings::initDefaultValues() { this->setNotification(CNotificationSounds::AllNotifications); + m_notificationVolume = 90; } } // namespace } // namespace diff --git a/src/blackmisc/audio/audiosettings.h b/src/blackmisc/audio/audiosettings.h index 46d9088b6..37089d4f0 100644 --- a/src/blackmisc/audio/audiosettings.h +++ b/src/blackmisc/audio/audiosettings.h @@ -63,6 +63,12 @@ namespace BlackMisc //! Notification directory const QString &getNotificationSoundDirectory() const { return m_notificationSoundDir; } + //! Set volume + void setNotificationVolume(int volume); + + //! Get volume + int getNotificationVolume() const { return m_notificationVolume; } + //! Init with meaningful default values void initDefaultValues(); @@ -72,12 +78,14 @@ namespace BlackMisc private: QString m_notificationSoundDir; int m_notification = static_cast(CNotificationSounds::DefaultNotifications); //!< play notification for notification x, a little trick to use a string here (streamable, hashable, ..) - void initNotificationFlags(); //!< init flags + int m_notificationVolume = 90; //!< 0-100; + void initNotificationFlags(); //!< init flags BLACK_METACLASS( CSettings, BLACK_METAMEMBER(notificationSoundDir), - BLACK_METAMEMBER(notification) + BLACK_METAMEMBER(notification), + BLACK_METAMEMBER(notificationVolume) ); };