mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-12 15:25:34 +08:00
refs #240, moved notification sounds in project blackmisc
Notification sounds are used in BlackGui components. They require the whole Qt multimedia library. However, GUI only triggers playing the sound. As a workaround the notification sounds enumeration has been moved in an own class, and moved to the subproject BlackMisc. Hence it is possible to compile BlackGui without dependency to BlackSound.
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include "context_network.h"
|
||||
|
||||
#include "blacksound/soundgenerator.h"
|
||||
#include "blackmisc/notificationsounds.h"
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
@@ -263,7 +264,7 @@ namespace BlackCore
|
||||
{
|
||||
Q_ASSERT(this->m_voice);
|
||||
if (this->getRuntime()->isSlotLogForAudioEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO, QString::number(notification));
|
||||
BlackSound::CSoundGenerator::playNotificationSound(90, static_cast<BlackSound::CSoundGenerator::Notification>(notification));
|
||||
BlackSound::CSoundGenerator::playNotificationSound(90, static_cast<BlackSound::CNotificationSounds::Notification>(notification));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
32
src/blackmisc/notificationsounds.h
Normal file
32
src/blackmisc/notificationsounds.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef BLACKMISC_NOTIFICATIONSOUNDS_H
|
||||
#define BLACKMISC_NOTIFICATIONSOUNDS_H
|
||||
|
||||
namespace BlackSound
|
||||
{
|
||||
|
||||
/*!
|
||||
* Simplified enums to play sound. Outside BlackSound as this allows
|
||||
* to trigger sounds without using Multimedia libraries.
|
||||
*/
|
||||
struct CNotificationSounds
|
||||
{
|
||||
//! How to play?
|
||||
enum PlayMode
|
||||
{
|
||||
Single,
|
||||
SingleWithAutomaticDeletion,
|
||||
EndlessLoop
|
||||
};
|
||||
|
||||
//! Play notification
|
||||
enum Notification
|
||||
{
|
||||
NotificationError = 0,
|
||||
NotificationLogin,
|
||||
NotificationLogoff,
|
||||
NotificationTextMessage,
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
#endif // guard
|
||||
@@ -21,7 +21,7 @@ namespace BlackSound
|
||||
{
|
||||
QDateTime CSoundGenerator::s_selcalStarted = QDateTime::currentDateTimeUtc();
|
||||
|
||||
CSoundGenerator::CSoundGenerator(const QAudioDeviceInfo &device, const QAudioFormat &format, const QList<Tone> &tones, PlayMode mode, QObject *parent)
|
||||
CSoundGenerator::CSoundGenerator(const QAudioDeviceInfo &device, const QAudioFormat &format, const QList<Tone> &tones, CNotificationSounds::PlayMode mode, QObject *parent)
|
||||
: QIODevice(parent),
|
||||
m_tones(tones), m_position(0), m_playMode(mode), m_endReached(false), m_oneCycleDurationMs(calculateDurationMs(tones)),
|
||||
m_device(device), m_audioFormat(format), m_audioOutput(new QAudioOutput(format)),
|
||||
@@ -30,7 +30,7 @@ namespace BlackSound
|
||||
Q_ASSERT(tones.size() > 0);
|
||||
}
|
||||
|
||||
CSoundGenerator::CSoundGenerator(const QList<Tone> &tones, PlayMode mode, QObject *parent)
|
||||
CSoundGenerator::CSoundGenerator(const QList<Tone> &tones, CNotificationSounds::PlayMode mode, QObject *parent)
|
||||
: QIODevice(parent),
|
||||
m_tones(tones), m_position(0), m_playMode(mode), m_endReached(false), m_oneCycleDurationMs(calculateDurationMs(tones)),
|
||||
m_device(QAudioDeviceInfo::defaultOutputDevice()), m_audioFormat(CSoundGenerator::defaultAudioFormat()),
|
||||
@@ -84,7 +84,7 @@ namespace BlackSound
|
||||
connect(this, &CSoundGenerator::stopping, this->m_ownThread, &QThread::quit);
|
||||
|
||||
// in auto delete mode force deleteLater when thread is finished
|
||||
if (this->m_playMode == SingleWithAutomaticDeletion)
|
||||
if (this->m_playMode == CNotificationSounds::SingleWithAutomaticDeletion)
|
||||
connect(this->m_ownThread, &QThread::finished, this, &CSoundGenerator::deleteLater);
|
||||
|
||||
// start thread and begin processing by calling start via signal startThread
|
||||
@@ -107,7 +107,7 @@ namespace BlackSound
|
||||
if (destructor) return;
|
||||
|
||||
// trigger own termination
|
||||
if (this->m_playMode == SingleWithAutomaticDeletion)
|
||||
if (this->m_playMode == CNotificationSounds::SingleWithAutomaticDeletion)
|
||||
{
|
||||
emit this->stopping();
|
||||
if (!this->m_ownThread) this->deleteLater(); // with own thread, thread signal will call deleteLater
|
||||
@@ -134,7 +134,7 @@ namespace BlackSound
|
||||
{
|
||||
if (this->m_pushTimer) this->m_pushTimer->stop();
|
||||
this->m_pushTimer->disconnect(this);
|
||||
if (this->m_playMode == SingleWithAutomaticDeletion) this->stop();
|
||||
if (this->m_playMode == CNotificationSounds::SingleWithAutomaticDeletion) this->stop();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -326,7 +326,7 @@ namespace BlackSound
|
||||
this->m_position = (m_position + chunkSize) % m_buffer.size();
|
||||
total += chunkSize;
|
||||
if (m_position == 0 &&
|
||||
(m_playMode == Single || m_playMode == SingleWithAutomaticDeletion))
|
||||
(m_playMode == CNotificationSounds::Single || m_playMode == CNotificationSounds::SingleWithAutomaticDeletion))
|
||||
{
|
||||
this->m_endReached = true;
|
||||
break;
|
||||
@@ -396,7 +396,7 @@ namespace BlackSound
|
||||
|
||||
CSoundGenerator *CSoundGenerator::playSignal(qint32 volume, const QList<CSoundGenerator::Tone> &tones, QAudioDeviceInfo device)
|
||||
{
|
||||
CSoundGenerator *generator = new CSoundGenerator(device, CSoundGenerator::defaultAudioFormat(), tones, CSoundGenerator::SingleWithAutomaticDeletion);
|
||||
CSoundGenerator *generator = new CSoundGenerator(device, CSoundGenerator::defaultAudioFormat(), tones, CNotificationSounds::SingleWithAutomaticDeletion);
|
||||
if (tones.isEmpty()) return generator; // that was easy
|
||||
if (volume < 1) return generator;
|
||||
if (generator->singleCyleDurationMs() < 10) return generator; // unable to hear
|
||||
@@ -408,7 +408,7 @@ namespace BlackSound
|
||||
|
||||
CSoundGenerator *CSoundGenerator::playSignalInBackground(qint32 volume, const QList<CSoundGenerator::Tone> &tones, QAudioDeviceInfo device)
|
||||
{
|
||||
CSoundGenerator *generator = new CSoundGenerator(device, CSoundGenerator::defaultAudioFormat(), tones, CSoundGenerator::SingleWithAutomaticDeletion);
|
||||
CSoundGenerator *generator = new CSoundGenerator(device, CSoundGenerator::defaultAudioFormat(), tones, CNotificationSounds::SingleWithAutomaticDeletion);
|
||||
if (tones.isEmpty()) return generator; // that was easy
|
||||
if (volume < 1) return generator;
|
||||
if (generator->singleCyleDurationMs() < 10) return generator; // unable to hear
|
||||
@@ -423,7 +423,7 @@ namespace BlackSound
|
||||
if (tones.isEmpty()) return; // that was easy
|
||||
if (volume < 1) return;
|
||||
|
||||
CSoundGenerator *generator = new CSoundGenerator(device, CSoundGenerator::defaultAudioFormat(), tones, CSoundGenerator::SingleWithAutomaticDeletion);
|
||||
CSoundGenerator *generator = new CSoundGenerator(device, CSoundGenerator::defaultAudioFormat(), tones, CNotificationSounds::SingleWithAutomaticDeletion);
|
||||
if (generator->singleCyleDurationMs() > 10)
|
||||
{
|
||||
// play, and maybe clean up when done
|
||||
@@ -460,7 +460,7 @@ namespace BlackSound
|
||||
CSoundGenerator::playSelcal(volume, selcal, CSoundGenerator::findClosestOutputDevice(audioDevice));
|
||||
}
|
||||
|
||||
void CSoundGenerator::playNotificationSound(qint32 volume, CSoundGenerator::Notification notification)
|
||||
void CSoundGenerator::playNotificationSound(qint32 volume, CNotificationSounds::Notification notification)
|
||||
{
|
||||
QMediaPlayer *mediaPlayer = CSoundGenerator::mediaPlayer();
|
||||
if (mediaPlayer->state() == QMediaPlayer::PlayingState) return;
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "blackmisc/avselcal.h"
|
||||
#include "blackmisc/audiodevice.h"
|
||||
#include "blackmisc/pqtime.h"
|
||||
#include "blackmisc/notificationsounds.h"
|
||||
#include <QIODevice>
|
||||
#include <QThread>
|
||||
#include <QDateTime>
|
||||
@@ -27,27 +28,6 @@ namespace BlackSound
|
||||
|
||||
public:
|
||||
|
||||
/*!
|
||||
* \brief How to play
|
||||
*/
|
||||
enum PlayMode
|
||||
{
|
||||
Single,
|
||||
SingleWithAutomaticDeletion,
|
||||
EndlessLoop
|
||||
};
|
||||
|
||||
/*!
|
||||
* \brief Play notification
|
||||
*/
|
||||
enum Notification
|
||||
{
|
||||
NotificationError = 0,
|
||||
NotificationLogin,
|
||||
NotificationLogoff,
|
||||
NotificationTextMessage,
|
||||
};
|
||||
|
||||
//! Tone to be played
|
||||
struct Tone
|
||||
{
|
||||
@@ -81,7 +61,7 @@ namespace BlackSound
|
||||
* \param parent
|
||||
* \see PlayMode
|
||||
*/
|
||||
CSoundGenerator(const QAudioDeviceInfo &device, const QAudioFormat &format, const QList<Tone> &tones, PlayMode mode, QObject *parent = nullptr);
|
||||
CSoundGenerator(const QAudioDeviceInfo &device, const QAudioFormat &format, const QList<Tone> &tones, CNotificationSounds::PlayMode mode, QObject *parent = nullptr);
|
||||
|
||||
/*!
|
||||
* \brief Constructor
|
||||
@@ -90,7 +70,7 @@ namespace BlackSound
|
||||
* \param parent
|
||||
* \see PlayMode
|
||||
*/
|
||||
CSoundGenerator(const QList<Tone> &tones, PlayMode mode, QObject *parent = nullptr);
|
||||
CSoundGenerator(const QList<Tone> &tones, CNotificationSounds::PlayMode mode, QObject *parent = nullptr);
|
||||
|
||||
//! Destructor
|
||||
~CSoundGenerator();
|
||||
@@ -193,7 +173,7 @@ namespace BlackSound
|
||||
* \param volume 0-100
|
||||
* \param notification
|
||||
*/
|
||||
static void playNotificationSound(qint32 volume, Notification notification);
|
||||
static void playNotificationSound(qint32 volume, CNotificationSounds::Notification notification);
|
||||
|
||||
//! One cycle of tones takes t milliseconds
|
||||
BlackMisc::PhysicalQuantities::CTime oneCycleDurationMs() const
|
||||
@@ -246,7 +226,7 @@ namespace BlackSound
|
||||
private:
|
||||
QList<Tone> m_tones; /*! tones to be played */
|
||||
qint64 m_position; /*!< position in buffer */
|
||||
PlayMode m_playMode; /*!< end data provisioning after playing all tones, play endless loop */
|
||||
CNotificationSounds::PlayMode m_playMode; /*!< end data provisioning after playing all tones, play endless loop */
|
||||
bool m_endReached; /*!< indicates end in combination with single play */
|
||||
qint64 m_oneCycleDurationMs; /*!< how long is one cycle of tones */
|
||||
QByteArray m_buffer; /*!< generated buffer for data */
|
||||
|
||||
Reference in New Issue
Block a user