13 using namespace swift::misc::audio;
14 using namespace swift::sound::sample_provider;
16 namespace swift::sound
18 CNotificationPlayer::CNotificationPlayer(QObject *parent) : QObject(parent)
25 QSoundEffect *effect = m_effects.value(notification,
nullptr);
28 if (!m_playingEffect && effect->isLoaded() && !effect->isPlaying())
30 const int currentEffect = ++m_playingEffectCounter;
31 const qreal v = volume / 100.0f;
32 m_playingEffect = effect;
37 QPointer<CNotificationPlayer> myself(
this);
39 if (!myself || !m_playingEffect) {
return; }
40 if (currentEffect != m_playingEffectCounter) {
return; }
41 m_playingEffect->stop();
49 if (directory == m_directory && !m_effects.isEmpty()) {
return; }
50 m_directory = directory;
52 const QStringList types = QSoundEffect::supportedMimeTypes();
53 CLogMessage(
this).
info(u
"Notification mime types: %1") << types.join(
", ");
55 this->updateEffect(CNotificationSounds::NotificationLogin, directory,
"login.wav");
56 this->updateEffect(CNotificationSounds::NotificationLogoff, directory,
"logoff.wav");
57 this->updateEffect(CNotificationSounds::NotificationTextMessageFrequency, directory,
"frequencymessage.wav");
58 this->updateEffect(CNotificationSounds::NotificationTextMessagePrivate, directory,
"privatemessage.wav");
59 this->updateEffect(CNotificationSounds::NotificationTextMessageSupervisor, directory,
"supervisormessage.wav");
60 this->updateEffect(CNotificationSounds::NotificationTextMessageUnicom, directory,
"unicommessage.wav");
61 this->updateEffect(CNotificationSounds::NotificationTextCallsignMentioned, directory,
"callsignmentioned.wav");
62 this->updateEffect(CNotificationSounds::PTTClickKeyDown, directory,
"pttclick.wav");
63 this->updateEffect(CNotificationSounds::PTTClickKeyUp, directory,
"pttclick.wav");
66 this->updateEffect(CNotificationSounds::AFVClicked, directory, Samples::fnClick());
69 void CNotificationPlayer::onPlayingChanged()
71 if (!m_playingEffect) {
return; }
72 if (m_playingEffect->isPlaying()) {
return; }
73 m_playingEffect.clear();
79 QSoundEffect *e =
nullptr;
80 if (m_effects.contains(f)) { e = m_effects[f]; }
81 if (e) { e->deleteLater(); }
84 const QUrl url = QUrl::fromLocalFile(CSwiftDirectories::soundFilePathOrDefaultPath(directory, name));
85 if (url.isEmpty() || !url.isLocalFile())
94 QSoundEffect *effect =
new QSoundEffect(
this);
95 effect->setSource(url);
96 effect->setLoopCount(1);
97 effect->setMuted(
false);
98 m_effects[f] = effect;
99 connect(effect, &QSoundEffect::playingChanged,
this, &CNotificationPlayer::onPlayingChanged,
100 Qt::QueuedConnection);
Class for emitting a log message.
Derived & info(const char16_t(&format)[N])
Set the severity to info, providing a format string.
void updateDirectory(const QString &directory)
Update the directory.
void play(swift::misc::audio::CNotificationSounds::NotificationFlag notification, int volume=100)
Play notification sound.
Free functions in swift::misc.
auto singleShot(int msec, QObject *target, F &&task)
Starts a single-shot timer which will call a task in the thread of the given object when it times out...
NotificationFlag
Play notification.