The latency setting now appears only if there is at least one backend

that supports it.
This commit is contained in:
LAGonauta 2017-06-28 07:56:12 -03:00
parent 9e251206b2
commit e7f0279ffc
2 changed files with 46 additions and 15 deletions

View File

@ -24,6 +24,7 @@
AudioConfigPane::AudioConfigPane(wxWindow* parent, wxWindowID id) : wxPanel(parent, id) AudioConfigPane::AudioConfigPane(wxWindow* parent, wxWindowID id) : wxPanel(parent, id)
{ {
CheckNeedForLatencyControl();
InitializeGUI(); InitializeGUI();
LoadGUIValues(); LoadGUIValues();
BindEvents(); BindEvents();
@ -44,9 +45,12 @@ void AudioConfigPane::InitializeGUI()
m_volume_text = new wxStaticText(this, wxID_ANY, ""); m_volume_text = new wxStaticText(this, wxID_ANY, "");
m_audio_backend_choice = m_audio_backend_choice =
new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_audio_backend_strings); new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_audio_backend_strings);
m_audio_latency_spinctrl = if (m_latency_control_supported)
new wxSpinCtrl(this, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 0, 200); {
m_audio_latency_spinctrl = new wxSpinCtrl(this, wxID_ANY, "", wxDefaultPosition, wxDefaultSize,
wxSP_ARROW_KEYS, 0, 200);
m_audio_latency_label = new wxStaticText(this, wxID_ANY, _("Latency (ms):")); m_audio_latency_label = new wxStaticText(this, wxID_ANY, _("Latency (ms):"));
}
m_stretch_checkbox = new wxCheckBox(this, wxID_ANY, _("Enable Audio Stretching")); m_stretch_checkbox = new wxCheckBox(this, wxID_ANY, _("Enable Audio Stretching"));
m_stretch_label = new wxStaticText(this, wxID_ANY, _("Buffer Size:")); m_stretch_label = new wxStaticText(this, wxID_ANY, _("Buffer Size:"));
@ -54,8 +58,12 @@ void AudioConfigPane::InitializeGUI()
new DolphinSlider(this, wxID_ANY, 80, 5, 300, wxDefaultPosition, wxDefaultSize); new DolphinSlider(this, wxID_ANY, 80, 5, 300, wxDefaultPosition, wxDefaultSize);
m_stretch_text = new wxStaticText(this, wxID_ANY, ""); m_stretch_text = new wxStaticText(this, wxID_ANY, "");
m_audio_latency_spinctrl->SetToolTip(_("Sets the latency (in ms). Higher values may reduce audio " if (m_latency_control_supported)
{
m_audio_latency_spinctrl->SetToolTip(
_("Sets the latency (in ms). Higher values may reduce audio "
"crackling. Certain backends only.")); "crackling. Certain backends only."));
}
m_dpl2_decoder_checkbox->SetToolTip( m_dpl2_decoder_checkbox->SetToolTip(
_("Enables Dolby Pro Logic II emulation using 5.1 surround. Certain backends only.")); _("Enables Dolby Pro Logic II emulation using 5.1 surround. Certain backends only."));
m_stretch_checkbox->SetToolTip(_("Enables stretching of the audio to match emulation speed.")); m_stretch_checkbox->SetToolTip(_("Enables stretching of the audio to match emulation speed."));
@ -76,10 +84,13 @@ void AudioConfigPane::InitializeGUI()
wxALIGN_CENTER_VERTICAL); wxALIGN_CENTER_VERTICAL);
backend_grid_sizer->Add(m_dpl2_decoder_checkbox, wxGBPosition(1, 0), wxGBSpan(1, 2), backend_grid_sizer->Add(m_dpl2_decoder_checkbox, wxGBPosition(1, 0), wxGBSpan(1, 2),
wxALIGN_CENTER_VERTICAL); wxALIGN_CENTER_VERTICAL);
if (m_latency_control_supported)
{
backend_grid_sizer->Add(m_audio_latency_label, wxGBPosition(2, 0), wxDefaultSpan, backend_grid_sizer->Add(m_audio_latency_label, wxGBPosition(2, 0), wxDefaultSpan,
wxALIGN_CENTER_VERTICAL); wxALIGN_CENTER_VERTICAL);
backend_grid_sizer->Add(m_audio_latency_spinctrl, wxGBPosition(2, 1), wxDefaultSpan, backend_grid_sizer->Add(m_audio_latency_spinctrl, wxGBPosition(2, 1), wxDefaultSpan,
wxALIGN_CENTER_VERTICAL); wxALIGN_CENTER_VERTICAL);
}
wxStaticBoxSizer* const backend_static_box_sizer = wxStaticBoxSizer* const backend_static_box_sizer =
new wxStaticBoxSizer(wxVERTICAL, this, _("Backend Settings")); new wxStaticBoxSizer(wxVERTICAL, this, _("Backend Settings"));
@ -139,7 +150,10 @@ void AudioConfigPane::LoadGUIValues()
m_volume_slider->SetValue(SConfig::GetInstance().m_Volume); m_volume_slider->SetValue(SConfig::GetInstance().m_Volume);
m_volume_text->SetLabel(wxString::Format("%d %%", SConfig::GetInstance().m_Volume)); m_volume_text->SetLabel(wxString::Format("%d %%", SConfig::GetInstance().m_Volume));
m_dpl2_decoder_checkbox->SetValue(startup_params.bDPL2Decoder); m_dpl2_decoder_checkbox->SetValue(startup_params.bDPL2Decoder);
if (m_latency_control_supported)
{
m_audio_latency_spinctrl->SetValue(startup_params.iLatency); m_audio_latency_spinctrl->SetValue(startup_params.iLatency);
}
m_stretch_checkbox->SetValue(startup_params.m_audio_stretch); m_stretch_checkbox->SetValue(startup_params.m_audio_stretch);
m_stretch_slider->Enable(startup_params.m_audio_stretch); m_stretch_slider->Enable(startup_params.m_audio_stretch);
m_stretch_slider->SetValue(startup_params.m_audio_stretch_max_latency); m_stretch_slider->SetValue(startup_params.m_audio_stretch_max_latency);
@ -152,9 +166,12 @@ void AudioConfigPane::ToggleBackendSpecificControls(const std::string& backend)
{ {
m_dpl2_decoder_checkbox->Enable(AudioCommon::SupportsDPL2Decoder(backend)); m_dpl2_decoder_checkbox->Enable(AudioCommon::SupportsDPL2Decoder(backend));
if (m_latency_control_supported)
{
bool supports_latency_control = AudioCommon::SupportsLatencyControl(backend); bool supports_latency_control = AudioCommon::SupportsLatencyControl(backend);
m_audio_latency_spinctrl->Enable(supports_latency_control); m_audio_latency_spinctrl->Enable(supports_latency_control);
m_audio_latency_label->Enable(supports_latency_control); m_audio_latency_label->Enable(supports_latency_control);
}
bool supports_volume_changes = AudioCommon::SupportsVolumeChanges(backend); bool supports_volume_changes = AudioCommon::SupportsVolumeChanges(backend);
m_volume_slider->Enable(supports_volume_changes); m_volume_slider->Enable(supports_volume_changes);
@ -175,8 +192,12 @@ void AudioConfigPane::BindEvents()
m_audio_backend_choice->Bind(wxEVT_CHOICE, &AudioConfigPane::OnAudioBackendChanged, this); m_audio_backend_choice->Bind(wxEVT_CHOICE, &AudioConfigPane::OnAudioBackendChanged, this);
m_audio_backend_choice->Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCoreNotRunning); m_audio_backend_choice->Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCoreNotRunning);
m_audio_latency_spinctrl->Bind(wxEVT_SPINCTRL, &AudioConfigPane::OnLatencySpinCtrlChanged, this); if (m_latency_control_supported)
{
m_audio_latency_spinctrl->Bind(wxEVT_SPINCTRL, &AudioConfigPane::OnLatencySpinCtrlChanged,
this);
m_audio_latency_spinctrl->Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCoreNotRunning); m_audio_latency_spinctrl->Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCoreNotRunning);
}
m_stretch_checkbox->Bind(wxEVT_CHECKBOX, &AudioConfigPane::OnStretchCheckBoxChanged, this); m_stretch_checkbox->Bind(wxEVT_CHECKBOX, &AudioConfigPane::OnStretchCheckBoxChanged, this);
m_stretch_slider->Bind(wxEVT_SLIDER, &AudioConfigPane::OnStretchSliderChanged, this); m_stretch_slider->Bind(wxEVT_SLIDER, &AudioConfigPane::OnStretchSliderChanged, this);
@ -241,3 +262,10 @@ void AudioConfigPane::PopulateBackendChoiceBox()
int num = m_audio_backend_choice->FindString(StrToWxStr(SConfig::GetInstance().sBackend)); int num = m_audio_backend_choice->FindString(StrToWxStr(SConfig::GetInstance().sBackend));
m_audio_backend_choice->SetSelection(num); m_audio_backend_choice->SetSelection(num);
} }
void AudioConfigPane::CheckNeedForLatencyControl()
{
std::vector<std::string> backends = AudioCommon::GetSoundBackends();
m_latency_control_supported =
std::any_of(backends.cbegin(), backends.cend(), AudioCommon::SupportsLatencyControl);
}

View File

@ -26,6 +26,7 @@ private:
void BindEvents(); void BindEvents();
void PopulateBackendChoiceBox(); void PopulateBackendChoiceBox();
void CheckNeedForLatencyControl();
void ToggleBackendSpecificControls(const std::string& backend); void ToggleBackendSpecificControls(const std::string& backend);
void OnDSPEngineRadioBoxChanged(wxCommandEvent&); void OnDSPEngineRadioBoxChanged(wxCommandEvent&);
@ -50,4 +51,6 @@ private:
wxStaticText* m_stretch_label; wxStaticText* m_stretch_label;
DolphinSlider* m_stretch_slider; DolphinSlider* m_stretch_slider;
wxStaticText* m_stretch_text; wxStaticText* m_stretch_text;
bool m_latency_control_supported;
}; };