diff --git a/src/blackcore/context/contextaudio.h b/src/blackcore/context/contextaudio.h index e7e459d26..4193d2ef6 100644 --- a/src/blackcore/context/contextaudio.h +++ b/src/blackcore/context/contextaudio.h @@ -142,13 +142,13 @@ namespace BlackCore virtual bool isMuted() const = 0; //! Play SELCAL tone - virtual void playSelcalTone(const BlackMisc::Aviation::CSelcal &selcal) const = 0; + virtual void playSelcalTone(const BlackMisc::Aviation::CSelcal &selcal) = 0; //! Play notification sound //! \param notification CSoundGenerator::Notification //! \param considerSettings consider settings (notification on/off), false means settings ignored //! \param volume 0..100 - virtual void playNotification(BlackMisc::Audio::CNotificationSounds::NotificationFlag notification, bool considerSettings, int volume = -1) const = 0; + virtual void playNotification(BlackMisc::Audio::CNotificationSounds::NotificationFlag notification, bool considerSettings, int volume = -1) = 0; //! Enable audio loopback virtual void enableAudioLoopback(bool enable = true) = 0; diff --git a/src/blackcore/context/contextaudioempty.h b/src/blackcore/context/contextaudioempty.h index 0a49172ed..57119a874 100644 --- a/src/blackcore/context/contextaudioempty.h +++ b/src/blackcore/context/contextaudioempty.h @@ -111,14 +111,14 @@ namespace BlackCore } //! \copydoc IContextAudio::playSelcalTone() - virtual void playSelcalTone(const BlackMisc::Aviation::CSelcal &selcal) const override + virtual void playSelcalTone(const BlackMisc::Aviation::CSelcal &selcal) override { Q_UNUSED(selcal); logEmptyContextWarning(Q_FUNC_INFO); } //! \copydoc IContextAudio::playNotification() - virtual void playNotification(BlackMisc::Audio::CNotificationSounds::NotificationFlag notification, bool considerSettings, int volume = -1) const override + virtual void playNotification(BlackMisc::Audio::CNotificationSounds::NotificationFlag notification, bool considerSettings, int volume = -1) override { Q_UNUSED(volume); Q_UNUSED(notification); diff --git a/src/blackcore/context/contextaudioimpl.cpp b/src/blackcore/context/contextaudioimpl.cpp index e2e05e07e..e23ba08dd 100644 --- a/src/blackcore/context/contextaudioimpl.cpp +++ b/src/blackcore/context/contextaudioimpl.cpp @@ -478,7 +478,7 @@ namespace BlackCore return this->getIContextNetwork()->getUsersForCallsigns(this->getRoomCallsigns(comUnit)); } - void CContextAudio::playSelcalTone(const CSelcal &selcal) const + void CContextAudio::playSelcalTone(const CSelcal &selcal) { Q_ASSERT(m_voice); if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << selcal; } @@ -496,7 +496,7 @@ namespace BlackCore } } - void CContextAudio::playNotification(CNotificationSounds::NotificationFlag notification, bool considerSettings, int volume) const + void CContextAudio::playNotification(CNotificationSounds::NotificationFlag notification, bool considerSettings, int volume) { Q_ASSERT(m_voice); if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << notification; } diff --git a/src/blackcore/context/contextaudioimpl.h b/src/blackcore/context/contextaudioimpl.h index b397c6310..8738041d0 100644 --- a/src/blackcore/context/contextaudioimpl.h +++ b/src/blackcore/context/contextaudioimpl.h @@ -94,8 +94,8 @@ namespace BlackCore virtual int getVoiceOutputVolume() const override; virtual void setMute(bool muted) override; virtual bool isMuted() const override; - virtual void playSelcalTone(const BlackMisc::Aviation::CSelcal &selcal) const override; - virtual void playNotification(BlackMisc::Audio::CNotificationSounds::NotificationFlag notification, bool considerSettings, int volume = -1) const override; + virtual void playSelcalTone(const BlackMisc::Aviation::CSelcal &selcal) override; + virtual void playNotification(BlackMisc::Audio::CNotificationSounds::NotificationFlag notification, bool considerSettings, int volume = -1) override; virtual void enableAudioLoopback(bool enable = true) override; virtual bool isAudioLoopbackEnabled() const override; virtual BlackMisc::Audio::CVoiceSetup getVoiceSetup() const override; diff --git a/src/blackcore/context/contextaudioproxy.cpp b/src/blackcore/context/contextaudioproxy.cpp index 65359f750..9f2fb817a 100644 --- a/src/blackcore/context/contextaudioproxy.cpp +++ b/src/blackcore/context/contextaudioproxy.cpp @@ -100,12 +100,12 @@ namespace BlackCore this->m_dBusInterface->callDBus(QLatin1String("setComVoiceRooms"), voiceRooms); } - void CContextAudioProxy::playSelcalTone(const CSelcal &selcal) const + void CContextAudioProxy::playSelcalTone(const CSelcal &selcal) { this->m_dBusInterface->callDBus(QLatin1String("playSelcalTone"), selcal); } - void CContextAudioProxy::playNotification(CNotificationSounds::NotificationFlag notification, bool considerSettings, int volume) const + void CContextAudioProxy::playNotification(CNotificationSounds::NotificationFlag notification, bool considerSettings, int volume) { this->m_dBusInterface->callDBus(QLatin1String("playNotification"), notification, considerSettings, volume); } diff --git a/src/blackcore/context/contextaudioproxy.h b/src/blackcore/context/contextaudioproxy.h index b198fff69..033d1adf1 100644 --- a/src/blackcore/context/contextaudioproxy.h +++ b/src/blackcore/context/contextaudioproxy.h @@ -74,8 +74,8 @@ namespace BlackCore virtual int getVoiceOutputVolume() const override; virtual void setMute(bool muted) override; virtual bool isMuted() const override; - virtual void playSelcalTone(const BlackMisc::Aviation::CSelcal &selcal) const override; - virtual void playNotification(BlackMisc::Audio::CNotificationSounds::NotificationFlag notification, bool considerSettings, int volume = -1) const override; + virtual void playSelcalTone(const BlackMisc::Aviation::CSelcal &selcal) override; + virtual void playNotification(BlackMisc::Audio::CNotificationSounds::NotificationFlag notification, bool considerSettings, int volume = -1) override; virtual void enableAudioLoopback(bool enable = true) override; virtual bool isAudioLoopbackEnabled() const override; virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) override; diff --git a/src/blacksound/notificationplayer.cpp b/src/blacksound/notificationplayer.cpp index 5a8e1149c..615965762 100644 --- a/src/blacksound/notificationplayer.cpp +++ b/src/blacksound/notificationplayer.cpp @@ -21,13 +21,27 @@ namespace BlackSound // lazy init at play } - void CNotificationPlayer::play(CNotificationSounds::NotificationFlag notification, int volume) const + void CNotificationPlayer::play(CNotificationSounds::NotificationFlag notification, int volume) { QSoundEffect *effect = m_effects.value(notification, nullptr); if (effect) { - effect->setVolume(volume / 100.0); - effect->play(); + if (!m_playingEffect && effect->isLoaded() && !effect->isPlaying()) + { + const qreal v = volume / 100.0f; + m_playingEffect = effect; + effect->setVolume(v); + effect->play(); + + /** could be used for too long or hanging sounds + QPointer myself(this); + QTimer::singleShot(2000, effect, [ = ] + { + if (!myself || !m_playingEffect) { return; } + m_playingEffect->stop(); + }); + **/ + } } } @@ -36,6 +50,8 @@ namespace BlackSound if (directory == m_directory && !m_effects.isEmpty()) { return; } m_directory = directory; + QStringList types = QSoundEffect::supportedMimeTypes(); + this->updateEffect(CNotificationSounds::NotificationError, directory, "error.wav"); this->updateEffect(CNotificationSounds::NotificationLogin, directory, "login.wav"); this->updateEffect(CNotificationSounds::NotificationLogoff, directory, "logoff.wav"); @@ -49,6 +65,13 @@ namespace BlackSound this->updateEffect(CNotificationSounds::PTTClickKeyUp, directory, "pttclick.wav"); } + void CNotificationPlayer::onPlayingChanged() + { + if (!m_playingEffect) { return; } + if (m_playingEffect->isPlaying()) { return; } + m_playingEffect.clear(); + } + void CNotificationPlayer::updateEffect(CNotificationSounds::NotificationFlag f, const QString &directory, const QString &name) { QSoundEffect *e = nullptr; @@ -56,6 +79,8 @@ namespace BlackSound effect->setSource(CFileUtils::soundFileQUrl(directory, name)); if (m_effects.contains(f)) { e = m_effects[f]; } m_effects[f] = effect; + effect->setLoopCount(0); + connect(effect, &QSoundEffect::playingChanged, this, &CNotificationPlayer::onPlayingChanged, Qt::QueuedConnection); if (e) { e->deleteLater(); } } } // ns diff --git a/src/blacksound/notificationplayer.h b/src/blacksound/notificationplayer.h index 5e21e50de..683971209 100644 --- a/src/blacksound/notificationplayer.h +++ b/src/blacksound/notificationplayer.h @@ -17,6 +17,7 @@ #include #include #include +#include namespace BlackSound { @@ -33,7 +34,7 @@ namespace BlackSound virtual ~CNotificationPlayer() override {} //! Play notification sound - void play(BlackMisc::Audio::CNotificationSounds::NotificationFlag notification, int volume = 100) const; + void play(BlackMisc::Audio::CNotificationSounds::NotificationFlag notification, int volume = 100); //! Update the directory void updateDirectory(const QString &directory); @@ -41,6 +42,10 @@ namespace BlackSound private: QHash m_effects; QString m_directory; + QPointer m_playingEffect; + + //! Playing of effect has been changed + void onPlayingChanged(); //! Update an effect void updateEffect(BlackMisc::Audio::CNotificationSounds::NotificationFlag f, const QString &directory, const QString &name);