Ref T644, allow to fetch notifications sounds from an arbitrary directory

* added settings
* utility functions
This commit is contained in:
Klaus Basan
2019-04-29 02:14:47 +02:00
parent ecc203cf2e
commit e4b0655129
8 changed files with 81 additions and 47 deletions

View File

@@ -8,6 +8,7 @@
#include "notificationplayer.h"
#include "blackmisc/fileutils.h"
#include <QTimer>
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

View File

@@ -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<BlackMisc::Audio::CNotificationSounds::NotificationFlag, QSoundEffect *> m_effects;
QString m_directory;
//! Update an effect
void updateEffect(BlackMisc::Audio::CNotificationSounds::NotificationFlag f, const QString &directory, const QString &name);
};
}