Clean up LogitechMicWindow.

This commit is contained in:
Jordan Woyak 2025-11-09 19:04:29 -06:00
parent 6202655339
commit b3af9a1ef9
4 changed files with 35 additions and 77 deletions

View File

@ -19,6 +19,7 @@
#include "Core/Config/MainSettings.h"
#include "Core/Core.h"
#include "Core/System.h"
#include "DolphinQt/Config/ConfigControls/ConfigBool.h"
#include "DolphinQt/Resources.h"
#include "DolphinQt/Settings.h"
@ -39,8 +40,8 @@ LogitechMicWindow::LogitechMicWindow(QWidget* parent) : QWidget(parent)
void LogitechMicWindow::CreateMainWindow()
{
auto* main_layout = new QVBoxLayout();
auto* label = new QLabel();
auto* const main_layout = new QVBoxLayout;
auto* const label = new QLabel;
label->setText(QStringLiteral("<center><i>%1</i></center>")
.arg(tr("Some settings cannot be changed when emulation is running.")));
main_layout->addWidget(label);
@ -58,16 +59,11 @@ void LogitechMicWindow::CreateCheckboxGroup(QVBoxLayout* main_layout)
auto* checkbox_layout = new QHBoxLayout();
checkbox_layout->setAlignment(Qt::AlignHCenter);
for (u8 index = 0; index < 4; index++)
for (std::size_t index = 0; index != Config::EMULATED_LOGITECH_MIC_COUNT; ++index)
{
std::stringstream ss;
ss << "Emulate Logitech USB Mic " << (index + 1);
m_checkbox_mic_enabled[index] = new QCheckBox(tr(ss.str().c_str()), this);
m_checkbox_mic_enabled[index]->setChecked(
Config::Get(Config::MAIN_EMULATE_LOGITECH_MIC[index]));
connect(m_checkbox_mic_enabled[index], &QCheckBox::toggled, this,
[index, this](bool checked) { EmulateLogitechMic(index, checked); });
checkbox_layout->addWidget(m_checkbox_mic_enabled[index]);
m_mic_enabled_checkboxes[index] = new ConfigBool(
tr("Emulate Logitech USB Mic %1").arg(index + 1), Config::MAIN_EMULATE_LOGITECH_MIC[index]);
checkbox_layout->addWidget(m_mic_enabled_checkboxes[index]);
}
checkbox_group->setLayout(checkbox_layout);
@ -79,20 +75,15 @@ void LogitechMicWindow::CreateMicrophoneConfigurationGroup(QVBoxLayout* main_lay
auto* main_config_group = new QGroupBox(tr("Microphone Configuration"));
auto* main_config_layout = new QVBoxLayout();
for (u8 index = 0; index < 4; index++)
for (std::size_t index = 0; index != Config::EMULATED_LOGITECH_MIC_COUNT; ++index)
{
std::stringstream ss;
ss << "Microphone " << (index + 1) << " Configuration";
auto* config_group = new QGroupBox(tr(ss.str().c_str()));
auto* config_layout = new QHBoxLayout();
// i18n: %1 is a number from 1 to 4.
auto* config_group = new QGroupBox(tr("Microphone %1 Configuration").arg(index + 1));
auto* const config_layout = new QHBoxLayout();
m_checkbox_mic_muted[index] = new QCheckBox(tr("Mute"), this);
m_checkbox_mic_muted[index]->setChecked(Settings::Instance().IsLogitechMicMuted(index));
connect(m_checkbox_mic_muted[index], &QCheckBox::toggled, &Settings::Instance(),
[index](bool checked) { Settings::Instance().SetLogitechMicMuted(index, checked); });
m_checkbox_mic_muted[index]->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
config_layout->addWidget(m_checkbox_mic_muted[index]);
auto* const mic_muted = new ConfigBool(tr("Mute"), Config::MAIN_LOGITECH_MIC_MUTED[index]);
mic_muted->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
config_layout->addWidget(mic_muted);
static constexpr int FILTER_MIN = -50;
static constexpr int FILTER_MAX = 50;
@ -100,8 +91,8 @@ void LogitechMicWindow::CreateMicrophoneConfigurationGroup(QVBoxLayout* main_lay
auto* volume_layout = new QGridLayout();
const int volume_modifier = std::clamp<int>(
Config::Get(Config::MAIN_LOGITECH_MIC_VOLUME_MODIFIER[index]), FILTER_MIN, FILTER_MAX);
auto filter_slider = new QSlider(Qt::Horizontal, this);
auto slider_label = new QLabel(tr("Volume modifier (value: %1dB)").arg(volume_modifier));
auto* const filter_slider = new QSlider(Qt::Horizontal, this);
auto* const slider_label = new QLabel(tr("Volume modifier (value: %1dB)").arg(volume_modifier));
connect(filter_slider, &QSlider::valueChanged, this, [slider_label, index](int value) {
Config::SetBaseOrCurrent(Config::MAIN_LOGITECH_MIC_VOLUME_MODIFIER[index], value);
slider_label->setText(tr("Volume modifier (value: %1dB)").arg(value));
@ -121,65 +112,51 @@ void LogitechMicWindow::CreateMicrophoneConfigurationGroup(QVBoxLayout* main_lay
config_layout->addLayout(volume_layout);
config_layout->setStretch(1, 3);
m_combobox_microphone[index] = new QComboBox();
m_mic_device_comboboxes[index] = new QComboBox();
#ifndef HAVE_CUBEB
m_combobox_microphone[index]->addItem(
QLatin1String("(%1)").arg(tr("Audio backend unsupported")), QString{});
#else
m_combobox_microphone[index]->addItem(
m_mic_device_comboboxes[index]->addItem(
QLatin1String("(%1)").arg(tr("Autodetect preferred microphone")), QString{});
for (auto& [device_id, device_name] : CubebUtils::ListInputDevices())
{
const auto user_data = QString::fromStdString(device_id);
m_combobox_microphone[index]->addItem(QString::fromStdString(device_name), user_data);
m_mic_device_comboboxes[index]->addItem(QString::fromStdString(device_name), user_data);
}
#endif
auto current_device_id =
QString::fromStdString(Config::Get(Config::MAIN_LOGITECH_MIC_MICROPHONE[index]));
m_combobox_microphone[index]->setCurrentIndex(
m_combobox_microphone[index]->findData(current_device_id));
connect(m_combobox_microphone[index], &QComboBox::currentIndexChanged, this,
m_mic_device_comboboxes[index]->setCurrentIndex(
m_mic_device_comboboxes[index]->findData(current_device_id));
connect(m_mic_device_comboboxes[index], &QComboBox::currentIndexChanged, this,
[index, this]() { OnInputDeviceChange(index); });
config_layout->addWidget(m_combobox_microphone[index]);
config_layout->addWidget(m_mic_device_comboboxes[index]);
config_group->setLayout(config_layout);
main_config_layout->addWidget(config_group);
}
connect(&Settings::Instance(), &Settings::LogitechMicMuteChanged, this,
&LogitechMicWindow::OnMuteChange);
main_config_group->setLayout(main_config_layout);
main_layout->addWidget(main_config_group);
}
void LogitechMicWindow::EmulateLogitechMic(u8 index, bool emulate)
{
Config::SetBaseOrCurrent(Config::MAIN_EMULATE_LOGITECH_MIC[index], emulate);
}
void LogitechMicWindow::OnEmulationStateChanged(Core::State state)
{
const bool running = state != Core::State::Uninitialized;
for (u8 index = 0; index < 4; index++)
for (std::size_t index = 0; index != Config::EMULATED_LOGITECH_MIC_COUNT; ++index)
{
m_checkbox_mic_enabled[index]->setEnabled(!running);
m_combobox_microphone[index]->setEnabled(!running);
m_mic_enabled_checkboxes[index]->setEnabled(!running);
}
}
void LogitechMicWindow::OnInputDeviceChange(u8 index)
void LogitechMicWindow::OnInputDeviceChange(std::size_t index)
{
auto user_data = m_combobox_microphone[index]->currentData();
auto user_data = m_mic_device_comboboxes[index]->currentData();
if (user_data.isValid())
{
const std::string device_id = user_data.toString().toStdString();
Config::SetBaseOrCurrent(Config::MAIN_LOGITECH_MIC_MICROPHONE[index], device_id);
}
}
void LogitechMicWindow::OnMuteChange(u8 index, bool muted)
{
m_checkbox_mic_muted[index]->setChecked(muted);
}

View File

@ -6,12 +6,13 @@
#include <QVBoxLayout>
#include <QWidget>
#include "Core/Config/MainSettings.h"
#include "Core/Core.h"
class QCheckBox;
class ConfigBool;
class QComboBox;
class LogitechMicWindow : public QWidget
class LogitechMicWindow final : public QWidget
{
Q_OBJECT
public:
@ -21,12 +22,10 @@ private:
void CreateMainWindow();
void CreateCheckboxGroup(QVBoxLayout* main_layout);
void CreateMicrophoneConfigurationGroup(QVBoxLayout* main_layout);
void OnEmulationStateChanged(Core::State state);
void EmulateLogitechMic(u8 index, bool emulate);
void OnInputDeviceChange(u8 index);
void OnMuteChange(u8 index, bool muted);
std::array<QCheckBox*, 4> m_checkbox_mic_enabled;
std::array<QCheckBox*, 4> m_checkbox_mic_muted;
std::array<QComboBox*, 4> m_combobox_microphone;
void OnEmulationStateChanged(Core::State state);
void OnInputDeviceChange(std::size_t index);
std::array<ConfigBool*, Config::EMULATED_LOGITECH_MIC_COUNT> m_mic_enabled_checkboxes;
std::array<QComboBox*, 4> m_mic_device_comboboxes;
};

View File

@ -801,20 +801,6 @@ void Settings::SetWiiSpeakMuted(bool muted)
emit WiiSpeakMuteChanged(muted);
}
bool Settings::IsLogitechMicMuted(u8 index) const
{
return Config::Get(Config::MAIN_LOGITECH_MIC_MUTED[index]);
}
void Settings::SetLogitechMicMuted(u8 index, bool muted)
{
if (IsLogitechMicMuted(index) == muted)
return;
Config::SetBaseOrCurrent(Config::MAIN_LOGITECH_MIC_MUTED[index], muted);
emit LogitechMicMuteChanged(index, muted);
}
void Settings::SetIsContinuouslyFrameStepping(bool is_stepping)
{
m_continuously_frame_stepping = is_stepping;

View File

@ -122,9 +122,6 @@ public:
bool IsWiiSpeakMuted() const;
void SetWiiSpeakMuted(bool muted);
bool IsLogitechMicMuted(u8 index) const;
void SetLogitechMicMuted(u8 index, bool muted);
void SetIsContinuouslyFrameStepping(bool is_stepping);
bool GetIsContinuouslyFrameStepping() const;
@ -227,7 +224,6 @@ signals:
void ReleaseDevices();
void DevicesChanged();
void WiiSpeakMuteChanged(bool muted);
void LogitechMicMuteChanged(u8 index, bool muted);
void EnableGfxModsChanged(bool enabled);
private: