Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 71 additions & 1 deletion pcsx2-qt/Settings/AudioSettingsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,33 @@ AudioSettingsWidget::AudioSettingsWidget(SettingsWindow* settings_dialog, QWidge
m_ui.standardVolume->setValue(dialog()->getEffectiveIntValue("SPU2/Output", "StandardVolume", 100));
m_ui.fastForwardVolume->setValue(dialog()->getEffectiveIntValue("SPU2/Output", "FastForwardVolume", 100));
m_ui.muted->setChecked(dialog()->getEffectiveBoolValue("SPU2/Output", "OutputMuted", false));
m_ui.syncVolume->setChecked(dialog()->getEffectiveBoolValue("SPU2/Output", "SyncVolume", true));
connect(m_ui.standardVolume, &QSlider::valueChanged, this, &AudioSettingsWidget::onStandardVolumeChanged);
connect(m_ui.fastForwardVolume, &QSlider::valueChanged, this, &AudioSettingsWidget::onFastForwardVolumeChanged);
connect(m_ui.muted, &QCheckBox::checkStateChanged, this, &AudioSettingsWidget::onOutputMutedChanged);
connect(m_ui.syncVolume, &QCheckBox::checkStateChanged, this, &AudioSettingsWidget::onVolumeSyncChanged);
updateVolumeLabel();
}
else
{
SettingWidgetBinder::BindWidgetAndLabelToIntSetting(sif, m_ui.standardVolume, m_ui.standardVolumeLabel, tr("%"), "SPU2/Output", "StandardVolume", 100);
SettingWidgetBinder::BindWidgetAndLabelToIntSetting(sif, m_ui.fastForwardVolume, m_ui.fastForwardVolumeLabel, tr("%"), "SPU2/Output", "FastForwardVolume", 100);
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.muted, "SPU2/Output", "OutputMuted", false);
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.syncVolume, "SPU2/Output", "SyncVolume", true);
connect(m_ui.standardVolume, &QSlider::valueChanged, this, [this](const int new_value) {
// only synchronize the standard and fast-forward volume is the sync volume checkboxed is ticked
if (dialog()->getEffectiveBoolValue("SPU2/Output", "SyncVolume", true))
m_ui.fastForwardVolume->setValue(new_value);
});
connect(m_ui.syncVolume, &QCheckBox::checkStateChanged, this, [this]() {
// re-sync the fast-forward volume when volume sync is enabled
if (dialog()->getEffectiveBoolValue("SPU2/Output", "SyncVolume", true))
m_ui.fastForwardVolume->setValue(m_ui.standardVolume->value());

updateVolumeSyncState();
});
}
updateVolumeSyncState();
connect(m_ui.resetStandardVolume, &QToolButton::clicked, this, [this]() { resetVolume(false); });
connect(m_ui.resetFastForwardVolume, &QToolButton::clicked, this, [this]() { resetVolume(true); });

Expand All @@ -109,6 +125,8 @@ AudioSettingsWidget::AudioSettingsWidget(SettingsWindow* settings_dialog, QWidge
tr("Controls the volume of the audio played on the host when fast forwarding."));
dialog()->registerWidgetHelp(m_ui.muted, tr("Mute All Sound"), tr("Unchecked"),
tr("Prevents the emulator from producing any audible sound."));
dialog()->registerWidgetHelp(m_ui.syncVolume, tr("Sync Volume"), tr("Checked"),
tr("Synchronizes the fast-forward volume of the audio to the standard volume."));
dialog()->registerWidgetHelp(m_ui.expansionMode, tr("Expansion Mode"), tr("Disabled (Stereo)"),
tr("Determines how audio is expanded from stereo to surround for supported games. This "
"includes games that support Dolby Pro Logic/Pro Logic II."));
Expand Down Expand Up @@ -308,6 +326,15 @@ void AudioSettingsWidget::onStandardVolumeChanged(const int new_value)
// only called for base settings
pxAssert(!dialog()->isPerGameSettings());
Host::SetBaseIntSettingValue("SPU2/Output", "StandardVolume", new_value);

// only synchronize the standard and fast-forward volume is the sync volume checkboxed is ticked
const bool syncVolume = dialog()->getEffectiveBoolValue("SPU2/Output", "SyncVolume", true);
if (syncVolume) {
QSignalBlocker sb(m_ui.fastForwardVolume);
m_ui.fastForwardVolume->setValue(new_value);
Host::SetBaseIntSettingValue("SPU2/Output", "FastForwardVolume", new_value);
}

Host::CommitBaseSettingChanges();
g_emu_thread->applySettings();

Expand Down Expand Up @@ -336,6 +363,38 @@ void AudioSettingsWidget::onOutputMutedChanged(const int new_state)
g_emu_thread->applySettings();
}

void AudioSettingsWidget::onVolumeSyncChanged(const int new_state)
{
// only called for base settings
pxAssert(!dialog()->isPerGameSettings());

const bool syncVolume = (new_state != 0);
Host::SetBaseBoolSettingValue("SPU2/Output", "SyncVolume", syncVolume);

// re-sync the fast-forward volume when volume sync is enabled
if (syncVolume)
{
const int standard_volume = m_ui.standardVolume->value();
QSignalBlocker sb(m_ui.fastForwardVolume);
m_ui.fastForwardVolume->setValue(standard_volume);
Host::SetBaseIntSettingValue("SPU2/Output", "FastForwardVolume", standard_volume);
updateVolumeLabel();
}

Host::CommitBaseSettingChanges();
updateVolumeSyncState();
g_emu_thread->applySettings();
}

void AudioSettingsWidget::updateVolumeSyncState()
{
// disables the fast forward volume slider and reset button if volume synchronization is enabled
// re-enables it when the synchronization is deactivated
const bool syncVolume = dialog()->getEffectiveBoolValue("SPU2/Output", "SyncVolume", true);
m_ui.fastForwardVolume->setEnabled(!syncVolume);
m_ui.resetFastForwardVolume->setEnabled(!syncVolume);
}

void AudioSettingsWidget::onExpansionSettingsClicked()
{
QDialog dlg(QtUtils::GetRootWidget(this));
Expand Down Expand Up @@ -484,7 +543,18 @@ void AudioSettingsWidget::resetVolume(const bool fast_forward)
QSlider* const slider = fast_forward ? m_ui.fastForwardVolume : m_ui.standardVolume;
QLabel* const label = fast_forward ? m_ui.fastForwardVolumeLabel : m_ui.standardVolumeLabel;

if (dialog()->isPerGameSettings())
const bool syncVolume = dialog()->getEffectiveBoolValue("SPU2/Output", "SyncVolume", true);
const bool perGame = dialog()->isPerGameSettings();

resetVolumeAction(perGame, key, slider, label);

if (syncVolume && !fast_forward) {
resetVolumeAction(perGame, "FastForwardVolume", m_ui.fastForwardVolume, m_ui.fastForwardVolumeLabel);
}
}

void AudioSettingsWidget::resetVolumeAction(bool per_game, const char* key, QSlider* slider, QLabel* label) {
if (per_game)
{
dialog()->removeSettingValue("SPU2/Output", key);

Expand Down
3 changes: 3 additions & 0 deletions pcsx2-qt/Settings/AudioSettingsWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ private Q_SLOTS:
void onStandardVolumeChanged(const int new_value);
void onFastForwardVolumeChanged(const int new_value);
void onOutputMutedChanged(const int new_state);
void onVolumeSyncChanged(const int new_state);
void updateVolumeSyncState();
void resetVolumeAction(bool per_game, const char* key, QSlider* slider, QLabel* label);

void onExpansionSettingsClicked();
void onStretchSettingsClicked();
Expand Down
7 changes: 7 additions & 0 deletions pcsx2-qt/Settings/AudioSettingsWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,13 @@
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="syncVolume">
<property name="text">
<string>Sync Volume</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down
Loading