diff --git a/src/blackcore/context/contextaudioimpl.cpp b/src/blackcore/context/contextaudioimpl.cpp index 11c746641..66546ede5 100644 --- a/src/blackcore/context/contextaudioimpl.cpp +++ b/src/blackcore/context/contextaudioimpl.cpp @@ -601,6 +601,12 @@ namespace BlackCore } } + void CContextAudio::onChangedAudioSettings() + { + const QString dir = m_audioSettings.get().getNotificationSoundDirectory(); + m_notificationPlayer.updateDirectory(dir); + } + QSharedPointer CContextAudio::getVoiceChannelBy(const CVoiceRoom &voiceRoom) { QSharedPointer voiceChannel; diff --git a/src/blackcore/context/contextaudioimpl.h b/src/blackcore/context/contextaudioimpl.h index 98da1f91d..45f315d3f 100644 --- a/src/blackcore/context/contextaudioimpl.h +++ b/src/blackcore/context/contextaudioimpl.h @@ -136,8 +136,12 @@ namespace BlackCore //! Connection in transition bool inTransitionState() const; + //! Change the device settings void changeDeviceSettings(); + //! Changed audio settings + void onChangedAudioSettings(); + //! Voice channel by room QSharedPointer getVoiceChannelBy(const BlackMisc::Audio::CVoiceRoom &voiceRoom); @@ -161,8 +165,8 @@ namespace BlackCore BlackSound::CNotificationPlayer m_notificationPlayer; // settings - BlackMisc::CSetting m_audioSettings { this }; - BlackMisc::CSetting m_inputDeviceSetting { this, &CContextAudio::changeDeviceSettings }; + BlackMisc::CSetting m_audioSettings { this, &CContextAudio::onChangedAudioSettings }; + BlackMisc::CSetting m_inputDeviceSetting { this, &CContextAudio::changeDeviceSettings }; BlackMisc::CSetting m_outputDeviceSetting { this, &CContextAudio::changeDeviceSettings }; }; } // namespace diff --git a/src/blackmisc/audio/audiosettings.cpp b/src/blackmisc/audio/audiosettings.cpp index a999e0a39..e088f4617 100644 --- a/src/blackmisc/audio/audiosettings.cpp +++ b/src/blackmisc/audio/audiosettings.cpp @@ -12,6 +12,8 @@ #include #include +#include "blackmisc/fileutils.h" + using namespace BlackMisc::Audio; namespace BlackMisc @@ -40,6 +42,19 @@ namespace BlackMisc } } + void CSettings::setNotificationSoundDirectory(const QString &dir) + { + QString d = dir.trimmed(); + if (d.isEmpty()) + { + // reset + m_notificationSoundDir.clear(); + return; + } + d = CFileUtils::fixWindowsUncPath(d); + m_notificationSoundDir = d; + } + QString CSettings::convertToQString(bool i18n) const { Q_UNUSED(i18n); diff --git a/src/blackmisc/audio/audiosettings.h b/src/blackmisc/audio/audiosettings.h index b69057bba..46d9088b6 100644 --- a/src/blackmisc/audio/audiosettings.h +++ b/src/blackmisc/audio/audiosettings.h @@ -57,6 +57,12 @@ namespace BlackMisc //! Settings value CStatusMessage value(const QString &path, const QString &command, const CVariant &value, bool &changedFlag); + //! Directory + void setNotificationSoundDirectory(const QString &dir); + + //! Notification directory + const QString &getNotificationSoundDirectory() const { return m_notificationSoundDir; } + //! Init with meaningful default values void initDefaultValues(); @@ -64,11 +70,13 @@ namespace BlackMisc QString convertToQString(bool i18n = false) const; 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 BLACK_METACLASS( CSettings, + BLACK_METAMEMBER(notificationSoundDir), BLACK_METAMEMBER(notification) ); }; diff --git a/src/blackmisc/fileutils.cpp b/src/blackmisc/fileutils.cpp index 54224b9fe..08846f00e 100644 --- a/src/blackmisc/fileutils.cpp +++ b/src/blackmisc/fileutils.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -582,9 +583,15 @@ namespace BlackMisc return CFileUtils::appendFilePaths(CDirectoryUtils::soundFilesDirectory(), name); } - QUrl CFileUtils::soundFileQUrl(const QString &name) + QUrl CFileUtils::soundFileQUrl(const QString &directory, const QString &name) { if (name.isEmpty()) { return {}; } + if (!directory.isEmpty()) + { + const QString f = CFileUtils::appendFilePathsAndFixUnc(directory, name); + const QFileInfo fi(f); + if (fi.exists()) { return QUrl::fromLocalFile(f); } + } return QUrl::fromLocalFile(CFileUtils::soundFilePathAndFileName(name)); } } // ns diff --git a/src/blackmisc/fileutils.h b/src/blackmisc/fileutils.h index f506b625b..906352c15 100644 --- a/src/blackmisc/fileutils.h +++ b/src/blackmisc/fileutils.h @@ -203,7 +203,7 @@ namespace BlackMisc static QString soundFilePathAndFileName(const QString &name); //! QUrl of soundFilePathAndFileName - static QUrl soundFileQUrl(const QString &name); + static QUrl soundFileQUrl(const QString &directory, const QString &name); }; } // ns diff --git a/src/blacksound/notificationplayer.cpp b/src/blacksound/notificationplayer.cpp index f40b94454..2e9959935 100644 --- a/src/blacksound/notificationplayer.cpp +++ b/src/blacksound/notificationplayer.cpp @@ -8,6 +8,7 @@ #include "notificationplayer.h" #include "blackmisc/fileutils.h" +#include using namespace BlackMisc; using namespace BlackMisc::Audio; @@ -17,49 +18,7 @@ namespace BlackSound CNotificationPlayer::CNotificationPlayer(QObject *parent) : QObject(parent) { - QSoundEffect *effect = new QSoundEffect(this); - effect->setSource(CFileUtils::soundFileQUrl("error.wav")); - m_effects[CNotificationSounds::NotificationError] = effect; - - effect = new QSoundEffect(this); - effect->setSource(CFileUtils::soundFileQUrl("login.wav")); - m_effects[CNotificationSounds::NotificationLogin] = effect; - - effect = new QSoundEffect(this); - effect->setSource(CFileUtils::soundFileQUrl("logoff.wav")); - m_effects[CNotificationSounds::NotificationLogoff] = effect; - - effect = new QSoundEffect(this); - effect->setSource(CFileUtils::soundFileQUrl("privatemessage.wav")); - m_effects[CNotificationSounds::NotificationTextMessagePrivate] = effect; - - effect = new QSoundEffect(this); - effect->setSource(CFileUtils::soundFileQUrl("supervisormessage.wav")); - m_effects[CNotificationSounds::NotificationTextMessageSupervisor] = effect; - - effect = new QSoundEffect(this); - effect->setSource(CFileUtils::soundFileQUrl("callsignmentioned.wav")); - m_effects[CNotificationSounds::NotificationTextCallsignMentioned] = effect; - - effect = new QSoundEffect(this); - effect->setSource(CFileUtils::soundFileQUrl("voiceroomjoined.wav")); - m_effects[CNotificationSounds::NotificationVoiceRoomJoined] = effect; - - effect = new QSoundEffect(this); - effect->setSource(CFileUtils::soundFileQUrl("voiceroomleft.wav")); - m_effects[CNotificationSounds::NotificationVoiceRoomLeft] = effect; - - effect = new QSoundEffect(this); - effect->setSource(CFileUtils::soundFileQUrl("noaudiotransmission.wav")); - m_effects[CNotificationSounds::NotificationNoAudioTransmission] = effect; - - effect = new QSoundEffect(this); - effect->setSource(CFileUtils::soundFileQUrl("pttclick.wav")); - m_effects[CNotificationSounds::PTTClickKeyDown] = effect; - - effect = new QSoundEffect(this); - effect->setSource(CFileUtils::soundFileQUrl("pttclick.wav")); - m_effects[CNotificationSounds::PTTClickKeyUp] = effect; + // lazy init at play } void CNotificationPlayer::play(Audio::CNotificationSounds::NotificationFlag notification, int volume) const @@ -71,4 +30,32 @@ namespace BlackSound effect->play(); } } + + void CNotificationPlayer::updateDirectory(const QString &directory) + { + if (directory == m_directory && !m_effects.isEmpty()) { return; } + m_directory = directory; + + this->updateEffect(CNotificationSounds::NotificationError, directory, "error.wav"); + this->updateEffect(CNotificationSounds::NotificationLogin, directory, "login.wav"); + this->updateEffect(CNotificationSounds::NotificationLogoff, directory, "logoff.wav"); + this->updateEffect(CNotificationSounds::NotificationTextMessagePrivate, directory, "privatemessage.wav"); + this->updateEffect(CNotificationSounds::NotificationTextMessageSupervisor, directory, "supervisormessage.wav"); + this->updateEffect(CNotificationSounds::NotificationTextCallsignMentioned, directory, "callsignmentioned.wav"); + this->updateEffect(CNotificationSounds::NotificationVoiceRoomJoined, directory, "voiceroomjoined.wav"); + this->updateEffect(CNotificationSounds::NotificationVoiceRoomLeft, directory, "voiceroomleft.wav"); + this->updateEffect(CNotificationSounds::NotificationNoAudioTransmission, directory, "noaudiotransmission.wav"); + this->updateEffect(CNotificationSounds::PTTClickKeyDown, directory, "pttclick.wav"); + this->updateEffect(CNotificationSounds::PTTClickKeyUp, directory, "pttclick.wav"); + } + + void CNotificationPlayer::updateEffect(CNotificationSounds::NotificationFlag f, const QString &directory, const QString &name) + { + QSoundEffect *e = nullptr; + QSoundEffect *effect = new QSoundEffect(this); + effect->setSource(CFileUtils::soundFileQUrl(directory, name)); + if (m_effects.contains(f)) { e = m_effects[f]; } + m_effects[f] = effect; + if (e) { e->deleteLater(); } + } } // ns diff --git a/src/blacksound/notificationplayer.h b/src/blacksound/notificationplayer.h index 21700239b..5e21e50de 100644 --- a/src/blacksound/notificationplayer.h +++ b/src/blacksound/notificationplayer.h @@ -35,8 +35,15 @@ namespace BlackSound //! Play notification sound void play(BlackMisc::Audio::CNotificationSounds::NotificationFlag notification, int volume = 100) const; + //! Update the directory + void updateDirectory(const QString &directory); + private: QHash m_effects; + QString m_directory; + + //! Update an effect + void updateEffect(BlackMisc::Audio::CNotificationSounds::NotificationFlag f, const QString &directory, const QString &name); }; }