Add support for sound backends & some miniaudio changes (#4978)
Miniaudio now runs everything in a separate audio thread - this uses boost::asio's io_context. Our miniaudio implementation is now also much simplified - it does not use its own resource manager or device. This might end up being stupid if sounds don't work after changing output device or locking or w/e I've made the sound controller into an interface, meaning we can support multiple sound backends in Chatterino. I've added a Null sound backend that disables all sound. A QMediaPlayer or QSoundEffect or Qt backend could be added. Miniaudio might idle & disable the device now too, not sure I've added some unrelated changes in the form of a new setting type, and a new setting page helper function for it, which will hopefully make adding new enum settings easier in the future. This setting stores its value as a string instead of an int, and uses magic_enum to convert between that string value and its enum value.
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include "common/Version.hpp"
|
||||
#include "controllers/hotkeys/HotkeyCategory.hpp"
|
||||
#include "controllers/hotkeys/HotkeyController.hpp"
|
||||
#include "controllers/sound/ISoundController.hpp"
|
||||
#include "providers/twitch/TwitchChannel.hpp"
|
||||
#include "providers/twitch/TwitchIrcServer.hpp"
|
||||
#include "singletons/Fonts.hpp"
|
||||
@@ -20,6 +21,7 @@
|
||||
#include "widgets/settingspages/GeneralPageView.hpp"
|
||||
#include "widgets/splits/SplitInput.hpp"
|
||||
|
||||
#include <magic_enum.hpp>
|
||||
#include <QDesktopServices>
|
||||
#include <QFileDialog>
|
||||
#include <QFontDialog>
|
||||
@@ -1134,6 +1136,14 @@ void GeneralPage::initLayout(GeneralPageView &layout)
|
||||
"Show a Send button next to each split input that can be "
|
||||
"clicked to send the message");
|
||||
|
||||
auto *soundBackend = layout.addDropdownEnumClass<SoundBackend>(
|
||||
"Sound backend (requires restart)",
|
||||
magic_enum::enum_names<SoundBackend>(), s.soundBackend,
|
||||
"Change this only if you're noticing issues with sound playback on "
|
||||
"your system",
|
||||
{});
|
||||
soundBackend->setMinimumWidth(soundBackend->minimumSizeHint().width());
|
||||
|
||||
layout.addStretch();
|
||||
|
||||
// invisible element for width
|
||||
|
||||
@@ -247,6 +247,51 @@ public:
|
||||
return combo;
|
||||
}
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
ComboBox *addDropdownEnumClass(const QString &text,
|
||||
const std::array<std::string_view, N> &items,
|
||||
EnumStringSetting<T> &setting,
|
||||
QString toolTipText,
|
||||
const QString &defaultValueText)
|
||||
{
|
||||
auto *combo = this->addDropdown(text, {}, std::move(toolTipText));
|
||||
|
||||
for (const auto &text : items)
|
||||
{
|
||||
combo->addItem(QString::fromStdString(std::string(text)));
|
||||
}
|
||||
|
||||
if (!defaultValueText.isEmpty())
|
||||
{
|
||||
combo->setCurrentText(defaultValueText);
|
||||
}
|
||||
|
||||
setting.connect(
|
||||
[&setting, combo](const QString &value) {
|
||||
auto enumValue =
|
||||
magic_enum::enum_cast<T>(value.toStdString(),
|
||||
magic_enum::case_insensitive)
|
||||
.value_or(setting.defaultValue);
|
||||
|
||||
auto i = magic_enum::enum_integer(enumValue);
|
||||
|
||||
combo->setCurrentIndex(i);
|
||||
},
|
||||
this->managedConnections_);
|
||||
|
||||
QObject::connect(
|
||||
combo, &QComboBox::currentTextChanged,
|
||||
[&setting](const auto &newText) {
|
||||
// The setter for EnumStringSetting does not check that this value is valid
|
||||
// Instead, it's up to the getters to make sure that the setting is legic - see the enum_cast above
|
||||
// You could also use the settings `getEnum` function
|
||||
setting = newText;
|
||||
getApp()->windows->forceLayoutChannelViews();
|
||||
});
|
||||
|
||||
return combo;
|
||||
}
|
||||
|
||||
DescriptionLabel *addDescription(const QString &text);
|
||||
|
||||
void addSeperator();
|
||||
|
||||
Reference in New Issue
Block a user