From 9b46cf64041a4c65155d3db75ed2d08630a673f0 Mon Sep 17 00:00:00 2001 From: Alice Weigt Date: Tue, 27 Sep 2016 20:25:44 -0700 Subject: [PATCH] fix(settings): Play test sound when user enables test sound Fixes #3735 --- src/audio/audio.cpp | 14 ++++++++++++++ src/audio/audio.h | 18 ++++++++++++++++++ src/widget/form/settings/avform.cpp | 6 +++++- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/audio/audio.cpp b/src/audio/audio.cpp index f40b7a5fa..a12dc1a84 100644 --- a/src/audio/audio.cpp +++ b/src/audio/audio.cpp @@ -88,6 +88,20 @@ private: /** * @class Audio * + * @enum Audio::Sound + * @brief Provides the different sounds for use in the getSound function. + * @see getSound + * + * @value NewMessage Returns the new message notification sound. + * @value Test Returns the test sound. + * @value IncomingCall Returns the incoming call sound. + * + * @fn QString Audio::getSound(Sound s) + * @brief Function to get the path of the requested sound. + * + * @param s Name of the sound to get the path of. + * @return The path of the requested sound. + * * @fn void Audio::frameAvailable(const int16_t *pcm, size_t sample_count, uint8_t channels, uint32_t sampling_rate); * * When there are input subscribers, we regularly emit captured audio frames with this signal diff --git a/src/audio/audio.h b/src/audio/audio.h index 4cb747652..f6f3f787b 100644 --- a/src/audio/audio.h +++ b/src/audio/audio.h @@ -28,6 +28,8 @@ #include #include +#include + #if defined(__APPLE__) && defined(__MACH__) #include #include @@ -49,6 +51,22 @@ class Audio : public QObject class Private; public: + + enum class Sound { NewMessage, Test, IncomingCall }; + + inline static QString getSound(Sound s) { + switch (s) + { + case Sound::Test: + return QStringLiteral(":/audio/notification.pcm"); + case Sound::NewMessage: + return QStringLiteral(":/audio/notification.pcm"); + case Sound::IncomingCall: + return QStringLiteral(":/audio/ToxIncomingCall.pcm"); + } + assert(false); + return QString(); + } static Audio& getInstance(); qreal outputVolume() const; diff --git a/src/widget/form/settings/avform.cpp b/src/widget/form/settings/avform.cpp index 33dae7483..4ce76e0f7 100644 --- a/src/widget/form/settings/avform.cpp +++ b/src/widget/form/settings/avform.cpp @@ -528,13 +528,17 @@ void AVForm::on_playbackSlider_valueChanged(int value) audio.setOutputVolume(percentage); if (mPlayTestSound) - audio.playMono16Sound(QStringLiteral(":/audio/notification.pcm")); + audio.playMono16Sound(Audio::getSound(Audio::Sound::Test)); } } void AVForm::on_btnPlayTestSound_clicked(bool checked) { mPlayTestSound = checked; + + Audio& audio = Audio::getInstance(); + if (mPlayTestSound && audio.isOutputReady()) + audio.playMono16Sound(Audio::getSound(Audio::Sound::Test)); } void AVForm::on_microphoneSlider_valueChanged(int value)