Also hide latency control on Qt GUI

This commit is contained in:
LAGonauta 2017-11-07 07:55:44 -02:00
parent e7f0279ffc
commit 9e63c65c36
2 changed files with 41 additions and 15 deletions

View File

@ -24,6 +24,7 @@
AudioPane::AudioPane()
{
CheckNeedForLatencyControl();
CreateWidgets();
LoadSettings();
ConnectWidgets();
@ -69,20 +70,24 @@ void AudioPane::CreateWidgets()
backend_box->setLayout(backend_layout);
m_backend_label = new QLabel(tr("Audio Backend:"));
m_backend_combo = new QComboBox();
m_latency_label = new QLabel(tr("Latency:"));
m_dolby_pro_logic = new QCheckBox(tr("Dolby Pro Logic II Decoder"));
m_latency_spin = new QSpinBox();
m_latency_spin->setMinimum(0);
m_latency_spin->setMaximum(30);
m_latency_spin->setToolTip(tr("Sets the latency (in ms). Higher values may reduce audio "
"crackling. Certain backends only."));
if (m_latency_control_supported)
{
m_latency_label = new QLabel(tr("Latency:"));
m_latency_spin = new QSpinBox();
m_latency_spin->setMinimum(0);
m_latency_spin->setMaximum(200);
m_latency_spin->setToolTip(tr("Sets the latency (in ms). Higher values may reduce audio "
"crackling. Certain backends only."));
}
m_dolby_pro_logic->setToolTip(
tr("Enables Dolby Pro Logic II emulation using 5.1 surround. Certain backends only."));
backend_layout->addRow(m_backend_label, m_backend_combo);
backend_layout->addRow(m_latency_label, m_latency_spin);
if (m_latency_control_supported)
backend_layout->addRow(m_latency_label, m_latency_spin);
backend_layout->addRow(m_dolby_pro_logic);
auto* stretching_box = new QGroupBox(tr("Audio Stretching Settings"));
@ -122,8 +127,11 @@ void AudioPane::ConnectWidgets()
connect(m_backend_combo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &AudioPane::SaveSettings);
connect(m_volume_slider, &QSlider::valueChanged, this, &AudioPane::SaveSettings);
connect(m_latency_spin, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
&AudioPane::SaveSettings);
if (m_latency_control_supported)
{
connect(m_latency_spin, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
&AudioPane::SaveSettings);
}
connect(m_stretching_buffer_slider, &QSlider::valueChanged, this, &AudioPane::SaveSettings);
connect(m_dolby_pro_logic, &QCheckBox::toggled, this, &AudioPane::SaveSettings);
connect(m_stretching_enable, &QCheckBox::toggled, this, &AudioPane::SaveSettings);
@ -165,7 +173,8 @@ void AudioPane::LoadSettings()
m_dolby_pro_logic->setChecked(SConfig::GetInstance().bDPL2Decoder);
// Latency
m_latency_spin->setValue(SConfig::GetInstance().iLatency);
if (m_latency_control_supported)
m_latency_spin->setValue(SConfig::GetInstance().iLatency);
// Stretch
m_stretching_enable->setChecked(SConfig::GetInstance().m_audio_stretch);
@ -204,7 +213,8 @@ void AudioPane::SaveSettings()
SConfig::GetInstance().bDPL2Decoder = m_dolby_pro_logic->isChecked();
// Latency
SConfig::GetInstance().iLatency = m_latency_spin->value();
if (m_latency_control_supported)
SConfig::GetInstance().iLatency = m_latency_spin->value();
// Stretch
SConfig::GetInstance().m_audio_stretch = m_stretching_enable->isChecked();
@ -223,8 +233,11 @@ void AudioPane::OnBackendChanged()
const auto backend = SConfig::GetInstance().sBackend;
m_dolby_pro_logic->setEnabled(AudioCommon::SupportsDPL2Decoder(backend));
m_latency_label->setEnabled(AudioCommon::SupportsLatencyControl(backend));
m_latency_spin->setEnabled(AudioCommon::SupportsLatencyControl(backend));
if (m_latency_control_supported)
{
m_latency_label->setEnabled(AudioCommon::SupportsLatencyControl(backend));
m_latency_spin->setEnabled(AudioCommon::SupportsLatencyControl(backend));
}
m_volume_slider->setEnabled(AudioCommon::SupportsVolumeChanges(backend));
m_volume_indicator->setEnabled(AudioCommon::SupportsVolumeChanges(backend));
}
@ -237,8 +250,11 @@ void AudioPane::OnEmulationStateChanged(bool running)
m_dolby_pro_logic->setEnabled(!running);
m_backend_label->setEnabled(!running);
m_backend_combo->setEnabled(!running);
m_latency_label->setEnabled(!running);
m_latency_spin->setEnabled(!running);
if (m_latency_control_supported)
{
m_latency_label->setEnabled(!running);
m_latency_spin->setEnabled(!running);
}
}
void AudioPane::OnVolumeChanged(int volume)
@ -246,3 +262,10 @@ void AudioPane::OnVolumeChanged(int volume)
m_volume_slider->setValue(volume);
m_volume_indicator->setText(tr("%1 %").arg(volume));
}
void AudioPane::CheckNeedForLatencyControl()
{
std::vector<std::string> backends = AudioCommon::GetSoundBackends();
m_latency_control_supported =
std::any_of(backends.cbegin(), backends.cend(), AudioCommon::SupportsLatencyControl);
}

View File

@ -32,6 +32,9 @@ private:
void OnBackendChanged();
void OnVolumeChanged(int volume);
void CheckNeedForLatencyControl();
bool m_latency_control_supported;
QGridLayout* m_main_layout;
// DSP Engine