mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-03 15:59:30 +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:
@@ -310,13 +310,13 @@ void MainWindow::connectionStatusChanged(uint /** from **/, uint to, const QStri
|
|||||||
switch (newStatus)
|
switch (newStatus)
|
||||||
{
|
{
|
||||||
case INetwork::Connected:
|
case INetwork::Connected:
|
||||||
this->playNotifcationSound(BlackSound::CSoundGenerator::NotificationLogin);
|
this->playNotifcationSound(BlackSound::CNotificationSounds::NotificationLogin);
|
||||||
break;
|
break;
|
||||||
case INetwork::Disconnected:
|
case INetwork::Disconnected:
|
||||||
this->playNotifcationSound(BlackSound::CSoundGenerator::NotificationLogoff);
|
this->playNotifcationSound(BlackSound::CNotificationSounds::NotificationLogoff);
|
||||||
break;
|
break;
|
||||||
case INetwork::DisconnectedError:
|
case INetwork::DisconnectedError:
|
||||||
this->playNotifcationSound(BlackSound::CSoundGenerator::NotificationError);
|
this->playNotifcationSound(BlackSound::CNotificationSounds::NotificationError);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -234,10 +234,10 @@ void MainWindow::audioTestUpdate()
|
|||||||
/*
|
/*
|
||||||
* Notification
|
* Notification
|
||||||
*/
|
*/
|
||||||
void MainWindow::playNotifcationSound(CSoundGenerator::Notification notification) const
|
void MainWindow::playNotifcationSound(CNotificationSounds::Notification notification) const
|
||||||
{
|
{
|
||||||
if (!this->m_contextAudioAvailable) return;
|
if (!this->m_contextAudioAvailable) return;
|
||||||
if (!this->ui->cb_SettingsAudioPlayNotificationSounds->isChecked()) return;
|
if (!this->ui->cb_SettingsAudioPlayNotificationSounds->isChecked()) return;
|
||||||
if (notification == CSoundGenerator::NotificationTextMessage && !this->ui->cb_SettingsAudioNotificationTextMessage->isChecked()) return;
|
if (notification == CNotificationSounds::NotificationTextMessage && !this->ui->cb_SettingsAudioNotificationTextMessage->isChecked()) return;
|
||||||
this->getIContextAudio()->playNotification(static_cast<uint>(notification));
|
this->getIContextAudio()->playNotification(static_cast<uint>(notification));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "context_network.h"
|
#include "context_network.h"
|
||||||
|
|
||||||
#include "blacksound/soundgenerator.h"
|
#include "blacksound/soundgenerator.h"
|
||||||
|
#include "blackmisc/notificationsounds.h"
|
||||||
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
@@ -263,7 +264,7 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
Q_ASSERT(this->m_voice);
|
Q_ASSERT(this->m_voice);
|
||||||
if (this->getRuntime()->isSlotLogForAudioEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO, QString::number(notification));
|
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();
|
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),
|
: QIODevice(parent),
|
||||||
m_tones(tones), m_position(0), m_playMode(mode), m_endReached(false), m_oneCycleDurationMs(calculateDurationMs(tones)),
|
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)),
|
m_device(device), m_audioFormat(format), m_audioOutput(new QAudioOutput(format)),
|
||||||
@@ -30,7 +30,7 @@ namespace BlackSound
|
|||||||
Q_ASSERT(tones.size() > 0);
|
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),
|
: QIODevice(parent),
|
||||||
m_tones(tones), m_position(0), m_playMode(mode), m_endReached(false), m_oneCycleDurationMs(calculateDurationMs(tones)),
|
m_tones(tones), m_position(0), m_playMode(mode), m_endReached(false), m_oneCycleDurationMs(calculateDurationMs(tones)),
|
||||||
m_device(QAudioDeviceInfo::defaultOutputDevice()), m_audioFormat(CSoundGenerator::defaultAudioFormat()),
|
m_device(QAudioDeviceInfo::defaultOutputDevice()), m_audioFormat(CSoundGenerator::defaultAudioFormat()),
|
||||||
@@ -84,7 +84,7 @@ namespace BlackSound
|
|||||||
connect(this, &CSoundGenerator::stopping, this->m_ownThread, &QThread::quit);
|
connect(this, &CSoundGenerator::stopping, this->m_ownThread, &QThread::quit);
|
||||||
|
|
||||||
// in auto delete mode force deleteLater when thread is finished
|
// 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);
|
connect(this->m_ownThread, &QThread::finished, this, &CSoundGenerator::deleteLater);
|
||||||
|
|
||||||
// start thread and begin processing by calling start via signal startThread
|
// start thread and begin processing by calling start via signal startThread
|
||||||
@@ -107,7 +107,7 @@ namespace BlackSound
|
|||||||
if (destructor) return;
|
if (destructor) return;
|
||||||
|
|
||||||
// trigger own termination
|
// trigger own termination
|
||||||
if (this->m_playMode == SingleWithAutomaticDeletion)
|
if (this->m_playMode == CNotificationSounds::SingleWithAutomaticDeletion)
|
||||||
{
|
{
|
||||||
emit this->stopping();
|
emit this->stopping();
|
||||||
if (!this->m_ownThread) this->deleteLater(); // with own thread, thread signal will call deleteLater
|
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();
|
if (this->m_pushTimer) this->m_pushTimer->stop();
|
||||||
this->m_pushTimer->disconnect(this);
|
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();
|
this->m_position = (m_position + chunkSize) % m_buffer.size();
|
||||||
total += chunkSize;
|
total += chunkSize;
|
||||||
if (m_position == 0 &&
|
if (m_position == 0 &&
|
||||||
(m_playMode == Single || m_playMode == SingleWithAutomaticDeletion))
|
(m_playMode == CNotificationSounds::Single || m_playMode == CNotificationSounds::SingleWithAutomaticDeletion))
|
||||||
{
|
{
|
||||||
this->m_endReached = true;
|
this->m_endReached = true;
|
||||||
break;
|
break;
|
||||||
@@ -396,7 +396,7 @@ namespace BlackSound
|
|||||||
|
|
||||||
CSoundGenerator *CSoundGenerator::playSignal(qint32 volume, const QList<CSoundGenerator::Tone> &tones, QAudioDeviceInfo device)
|
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 (tones.isEmpty()) return generator; // that was easy
|
||||||
if (volume < 1) return generator;
|
if (volume < 1) return generator;
|
||||||
if (generator->singleCyleDurationMs() < 10) return generator; // unable to hear
|
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 *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 (tones.isEmpty()) return generator; // that was easy
|
||||||
if (volume < 1) return generator;
|
if (volume < 1) return generator;
|
||||||
if (generator->singleCyleDurationMs() < 10) return generator; // unable to hear
|
if (generator->singleCyleDurationMs() < 10) return generator; // unable to hear
|
||||||
@@ -423,7 +423,7 @@ namespace BlackSound
|
|||||||
if (tones.isEmpty()) return; // that was easy
|
if (tones.isEmpty()) return; // that was easy
|
||||||
if (volume < 1) return;
|
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)
|
if (generator->singleCyleDurationMs() > 10)
|
||||||
{
|
{
|
||||||
// play, and maybe clean up when done
|
// play, and maybe clean up when done
|
||||||
@@ -460,7 +460,7 @@ namespace BlackSound
|
|||||||
CSoundGenerator::playSelcal(volume, selcal, CSoundGenerator::findClosestOutputDevice(audioDevice));
|
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();
|
QMediaPlayer *mediaPlayer = CSoundGenerator::mediaPlayer();
|
||||||
if (mediaPlayer->state() == QMediaPlayer::PlayingState) return;
|
if (mediaPlayer->state() == QMediaPlayer::PlayingState) return;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include "blackmisc/avselcal.h"
|
#include "blackmisc/avselcal.h"
|
||||||
#include "blackmisc/audiodevice.h"
|
#include "blackmisc/audiodevice.h"
|
||||||
#include "blackmisc/pqtime.h"
|
#include "blackmisc/pqtime.h"
|
||||||
|
#include "blackmisc/notificationsounds.h"
|
||||||
#include <QIODevice>
|
#include <QIODevice>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
@@ -27,27 +28,6 @@ namespace BlackSound
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief How to play
|
|
||||||
*/
|
|
||||||
enum PlayMode
|
|
||||||
{
|
|
||||||
Single,
|
|
||||||
SingleWithAutomaticDeletion,
|
|
||||||
EndlessLoop
|
|
||||||
};
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief Play notification
|
|
||||||
*/
|
|
||||||
enum Notification
|
|
||||||
{
|
|
||||||
NotificationError = 0,
|
|
||||||
NotificationLogin,
|
|
||||||
NotificationLogoff,
|
|
||||||
NotificationTextMessage,
|
|
||||||
};
|
|
||||||
|
|
||||||
//! Tone to be played
|
//! Tone to be played
|
||||||
struct Tone
|
struct Tone
|
||||||
{
|
{
|
||||||
@@ -81,7 +61,7 @@ namespace BlackSound
|
|||||||
* \param parent
|
* \param parent
|
||||||
* \see PlayMode
|
* \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
|
* \brief Constructor
|
||||||
@@ -90,7 +70,7 @@ namespace BlackSound
|
|||||||
* \param parent
|
* \param parent
|
||||||
* \see PlayMode
|
* \see PlayMode
|
||||||
*/
|
*/
|
||||||
CSoundGenerator(const QList<Tone> &tones, PlayMode mode, QObject *parent = nullptr);
|
CSoundGenerator(const QList<Tone> &tones, CNotificationSounds::PlayMode mode, QObject *parent = nullptr);
|
||||||
|
|
||||||
//! Destructor
|
//! Destructor
|
||||||
~CSoundGenerator();
|
~CSoundGenerator();
|
||||||
@@ -193,7 +173,7 @@ namespace BlackSound
|
|||||||
* \param volume 0-100
|
* \param volume 0-100
|
||||||
* \param notification
|
* \param notification
|
||||||
*/
|
*/
|
||||||
static void playNotificationSound(qint32 volume, Notification notification);
|
static void playNotificationSound(qint32 volume, CNotificationSounds::Notification notification);
|
||||||
|
|
||||||
//! One cycle of tones takes t milliseconds
|
//! One cycle of tones takes t milliseconds
|
||||||
BlackMisc::PhysicalQuantities::CTime oneCycleDurationMs() const
|
BlackMisc::PhysicalQuantities::CTime oneCycleDurationMs() const
|
||||||
@@ -246,7 +226,7 @@ namespace BlackSound
|
|||||||
private:
|
private:
|
||||||
QList<Tone> m_tones; /*! tones to be played */
|
QList<Tone> m_tones; /*! tones to be played */
|
||||||
qint64 m_position; /*!< position in buffer */
|
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 */
|
bool m_endReached; /*!< indicates end in combination with single play */
|
||||||
qint64 m_oneCycleDurationMs; /*!< how long is one cycle of tones */
|
qint64 m_oneCycleDurationMs; /*!< how long is one cycle of tones */
|
||||||
QByteArray m_buffer; /*!< generated buffer for data */
|
QByteArray m_buffer; /*!< generated buffer for data */
|
||||||
|
|||||||
Reference in New Issue
Block a user