Change sound backend from Qt to miniaudio (#4334)

Thanks Greenlandicsmiley, Nerixyz, Yoitsu, and helmak for helping debug & test this

* Remove QMediaPlayer includes

* Prefer local path when generating the sound path

* Update changelog entry number

* Disable pitch & spatialization control
This commit is contained in:
pajlada
2023-01-29 10:36:25 +01:00
committed by GitHub
parent adf58d2770
commit 4958d08036
16 changed files with 354 additions and 64 deletions
+21 -48
View File
@@ -6,6 +6,7 @@
#include "controllers/ignores/IgnoreController.hpp"
#include "controllers/ignores/IgnorePhrase.hpp"
#include "controllers/nicknames/Nickname.hpp"
#include "controllers/sound/SoundController.hpp"
#include "messages/Message.hpp"
#include "messages/MessageElement.hpp"
#include "providers/twitch/TwitchBadge.hpp"
@@ -16,34 +17,33 @@
#include "util/StreamerMode.hpp"
#include <QFileInfo>
#include <QMediaPlayer>
namespace chatterino {
namespace {
/**
* Gets the default sound url if the user set one,
* or the chatterino default ping sound if no url is set.
*/
QUrl getFallbackHighlightSound()
{
QString path = getSettings()->pathHighlightSound;
bool fileExists = !path.isEmpty() && QFileInfo::exists(path) &&
QFileInfo(path).isFile();
using namespace chatterino;
if (fileExists)
{
return QUrl::fromLocalFile(path);
}
else
{
return QUrl("qrc:/sounds/ping2.wav");
}
/**
* Gets the default sound url if the user set one,
* or the chatterino default ping sound if no url is set.
*/
QUrl getFallbackHighlightSound()
{
QString path = getSettings()->pathHighlightSound;
bool fileExists =
!path.isEmpty() && QFileInfo::exists(path) && QFileInfo(path).isFile();
if (fileExists)
{
return QUrl::fromLocalFile(path);
}
return QUrl("qrc:/sounds/ping2.wav");
}
} // namespace
namespace chatterino {
SharedMessageBuilder::SharedMessageBuilder(
Channel *_channel, const Communi::IrcPrivateMessage *_ircMessage,
const MessageParseArgs &_args)
@@ -198,23 +198,8 @@ void SharedMessageBuilder::appendChannelName()
->setLink(link);
}
inline QMediaPlayer *getPlayer()
{
if (isGuiThread())
{
static auto player = new QMediaPlayer;
return player;
}
else
{
return nullptr;
}
}
void SharedMessageBuilder::triggerHighlights()
{
static QUrl currentPlayerUrl;
if (isInStreamerMode() && getSettings()->streamerModeMuteMentions)
{
// We are in streamer mode with muting mention sounds enabled. Do nothing.
@@ -232,19 +217,7 @@ void SharedMessageBuilder::triggerHighlights()
if (this->highlightSound_ && resolveFocus)
{
if (auto player = getPlayer())
{
// Set media if the highlight sound url has changed, or if media is buffered
if (currentPlayerUrl != this->highlightSoundUrl_ ||
player->mediaStatus() == QMediaPlayer::BufferedMedia)
{
player->setMedia(this->highlightSoundUrl_);
currentPlayerUrl = this->highlightSoundUrl_;
}
player->play();
}
getApp()->sound->play(this->highlightSoundUrl_);
}
if (this->highlightAlert_)