mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-23 06:15:38 +00:00
Qt: Fix volume slider slowing down emulation
This commit is contained in:
parent
2fb00faa67
commit
b2595a3b3b
|
@ -1,7 +1,9 @@
|
|||
#include "audiosettingswidget.h"
|
||||
#include "common/audio_stream.h"
|
||||
#include "common/log.h"
|
||||
#include "settingsdialog.h"
|
||||
#include "settingwidgetbinder.h"
|
||||
Log_SetChannel(AudioSettingsWidget);
|
||||
|
||||
AudioSettingsWidget::AudioSettingsWidget(QtHostInterface* host_interface, QWidget* parent, SettingsDialog* dialog)
|
||||
: QWidget(parent), m_host_interface(host_interface)
|
||||
|
@ -16,12 +18,14 @@ AudioSettingsWidget::AudioSettingsWidget(QtHostInterface* host_interface, QWidge
|
|||
Settings::DEFAULT_AUDIO_BACKEND);
|
||||
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.syncToOutput, "Audio", "Sync");
|
||||
SettingWidgetBinder::BindWidgetToIntSetting(m_host_interface, m_ui.bufferSize, "Audio", "BufferSize");
|
||||
SettingWidgetBinder::BindWidgetToIntSetting(m_host_interface, m_ui.volume, "Audio", "OutputVolume");
|
||||
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.muted, "Audio", "OutputMuted");
|
||||
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.startDumpingOnBoot, "Audio", "DumpOnBoot");
|
||||
|
||||
m_ui.volume->setValue(m_host_interface->GetIntSettingValue("Audio", "OutputVolume"));
|
||||
m_ui.muted->setChecked(m_host_interface->GetBoolSettingValue("Audio", "OutputMuted"));
|
||||
|
||||
connect(m_ui.bufferSize, &QSlider::valueChanged, this, &AudioSettingsWidget::updateBufferingLabel);
|
||||
connect(m_ui.volume, &QSlider::valueChanged, this, &AudioSettingsWidget::updateVolumeLabel);
|
||||
connect(m_ui.volume, &QSlider::valueChanged, this, &AudioSettingsWidget::onOutputVolumeChanged);
|
||||
connect(m_ui.muted, &QCheckBox::stateChanged, this, &AudioSettingsWidget::onOutputMutedChanged);
|
||||
|
||||
updateBufferingLabel();
|
||||
updateVolumeLabel();
|
||||
|
@ -61,3 +65,19 @@ void AudioSettingsWidget::updateVolumeLabel()
|
|||
{
|
||||
m_ui.volumeLabel->setText(tr("%1%").arg(m_ui.volume->value()));
|
||||
}
|
||||
|
||||
void AudioSettingsWidget::onOutputVolumeChanged(int new_value)
|
||||
{
|
||||
m_host_interface->SetIntSettingValue("Audio", "OutputVolume", new_value);
|
||||
if (!m_ui.muted->isChecked())
|
||||
m_host_interface->setAudioOutputVolume(new_value);
|
||||
|
||||
updateVolumeLabel();
|
||||
}
|
||||
|
||||
void AudioSettingsWidget::onOutputMutedChanged(int new_state)
|
||||
{
|
||||
const bool muted = (new_state != 0);
|
||||
m_host_interface->SetBoolSettingValue("Audio", "OutputMuted", muted);
|
||||
m_host_interface->setAudioOutputVolume(muted ? 0 : m_ui.volume->value());
|
||||
}
|
|
@ -18,6 +18,8 @@ public:
|
|||
private Q_SLOTS:
|
||||
void updateBufferingLabel();
|
||||
void updateVolumeLabel();
|
||||
void onOutputVolumeChanged(int new_value);
|
||||
void onOutputMutedChanged(int new_state);
|
||||
|
||||
private:
|
||||
Ui::AudioSettingsWidget m_ui;
|
||||
|
|
|
@ -884,6 +884,18 @@ void QtHostInterface::saveState(bool global, qint32 slot, bool block_until_done
|
|||
SaveState(global, slot);
|
||||
}
|
||||
|
||||
void QtHostInterface::setAudioOutputVolume(int value)
|
||||
{
|
||||
if (!isOnWorkerThread())
|
||||
{
|
||||
QMetaObject::invokeMethod(this, "setAudioOutputVolume", Q_ARG(int, value));
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_audio_stream)
|
||||
m_audio_stream->SetOutputVolume(value);
|
||||
}
|
||||
|
||||
void QtHostInterface::startDumpingAudio()
|
||||
{
|
||||
if (!isOnWorkerThread())
|
||||
|
|
|
@ -135,6 +135,7 @@ public Q_SLOTS:
|
|||
void loadState(const QString& filename);
|
||||
void loadState(bool global, qint32 slot);
|
||||
void saveState(bool global, qint32 slot, bool block_until_done = false);
|
||||
void setAudioOutputVolume(int value);
|
||||
void startDumpingAudio();
|
||||
void stopDumpingAudio();
|
||||
void saveScreenshot();
|
||||
|
|
Loading…
Reference in a new issue