From 4834a90e63c3b173784f1e93ff6d21a065499047 Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Sun, 9 Oct 2016 19:10:16 -0700 Subject: [PATCH 1/5] AudioConfigPane: dedupe code into ToggleBackendSpecificControls --- .../Core/DolphinWX/Config/AudioConfigPane.cpp | 42 +++++++------------ .../Core/DolphinWX/Config/AudioConfigPane.h | 2 +- 2 files changed, 16 insertions(+), 28 deletions(-) diff --git a/Source/Core/DolphinWX/Config/AudioConfigPane.cpp b/Source/Core/DolphinWX/Config/AudioConfigPane.cpp index f1125700fc..bd626e437c 100644 --- a/Source/Core/DolphinWX/Config/AudioConfigPane.cpp +++ b/Source/Core/DolphinWX/Config/AudioConfigPane.cpp @@ -115,9 +115,9 @@ void AudioConfigPane::InitializeGUI() void AudioConfigPane::LoadGUIValues() { - PopulateBackendChoiceBox(); - const SConfig& startup_params = SConfig::GetInstance(); + PopulateBackendChoiceBox(); + ToggleBackendSpecificControls(SConfig::GetInstance().sBackend); // Audio DSP Engine if (startup_params.bDSPHLE) @@ -125,20 +125,24 @@ void AudioConfigPane::LoadGUIValues() else m_dsp_engine_radiobox->SetSelection(SConfig::GetInstance().m_DSPEnableJIT ? 1 : 2); - m_volume_slider->Enable(SupportsVolumeChanges(SConfig::GetInstance().sBackend)); m_volume_slider->SetValue(SConfig::GetInstance().m_Volume); - m_volume_text->SetLabel(wxString::Format("%d %%", SConfig::GetInstance().m_Volume)); - - m_dpl2_decoder_checkbox->Enable(std::string(SConfig::GetInstance().sBackend) == BACKEND_OPENAL || - std::string(SConfig::GetInstance().sBackend) == - BACKEND_PULSEAUDIO); m_dpl2_decoder_checkbox->SetValue(startup_params.bDPL2Decoder); - - m_audio_latency_spinctrl->Enable(std::string(SConfig::GetInstance().sBackend) == BACKEND_OPENAL); m_audio_latency_spinctrl->SetValue(startup_params.iLatency); } +void AudioConfigPane::ToggleBackendSpecificControls(const std::string& backend) +{ + m_dpl2_decoder_checkbox->Enable(backend == BACKEND_OPENAL || backend == BACKEND_PULSEAUDIO); + m_audio_latency_spinctrl->Enable(backend == BACKEND_OPENAL); + + // FIXME: this one should ask the backend whether it supports it. + // but getting the backend from string etc. is probably + // too much just to enable/disable a stupid slider... + m_volume_slider->Enable(backend == BACKEND_COREAUDIO || backend == BACKEND_OPENAL || + backend == BACKEND_XAUDIO2); +} + void AudioConfigPane::RefreshGUI() { if (Core::IsRunning()) @@ -171,19 +175,11 @@ void AudioConfigPane::OnVolumeSliderChanged(wxCommandEvent& event) void AudioConfigPane::OnAudioBackendChanged(wxCommandEvent& event) { - m_volume_slider->Enable( - SupportsVolumeChanges(WxStrToStr(m_audio_backend_choice->GetStringSelection()))); - m_audio_latency_spinctrl->Enable(WxStrToStr(m_audio_backend_choice->GetStringSelection()) == - BACKEND_OPENAL); - m_dpl2_decoder_checkbox->Enable( - WxStrToStr(m_audio_backend_choice->GetStringSelection()) == BACKEND_OPENAL || - WxStrToStr(m_audio_backend_choice->GetStringSelection()) == BACKEND_PULSEAUDIO); - // Don't save the translated BACKEND_NULLSOUND string SConfig::GetInstance().sBackend = m_audio_backend_choice->GetSelection() ? WxStrToStr(m_audio_backend_choice->GetStringSelection()) : BACKEND_NULLSOUND; - + ToggleBackendSpecificControls(WxStrToStr(m_audio_backend_choice->GetStringSelection())); AudioCommon::UpdateSoundStream(); } @@ -202,11 +198,3 @@ void AudioConfigPane::PopulateBackendChoiceBox() int num = m_audio_backend_choice->FindString(StrToWxStr(SConfig::GetInstance().sBackend)); m_audio_backend_choice->SetSelection(num); } - -bool AudioConfigPane::SupportsVolumeChanges(const std::string& backend) -{ - // FIXME: this one should ask the backend whether it supports it. - // but getting the backend from string etc. is probably - // too much just to enable/disable a stupid slider... - return (backend == BACKEND_COREAUDIO || backend == BACKEND_OPENAL || backend == BACKEND_XAUDIO2); -} diff --git a/Source/Core/DolphinWX/Config/AudioConfigPane.h b/Source/Core/DolphinWX/Config/AudioConfigPane.h index 877be31da5..eccb24ccc9 100644 --- a/Source/Core/DolphinWX/Config/AudioConfigPane.h +++ b/Source/Core/DolphinWX/Config/AudioConfigPane.h @@ -26,7 +26,7 @@ private: void RefreshGUI(); void PopulateBackendChoiceBox(); - static bool SupportsVolumeChanges(const std::string&); + void ToggleBackendSpecificControls(const std::string& backend); void OnDSPEngineRadioBoxChanged(wxCommandEvent&); void OnDPL2DecoderCheckBoxChanged(wxCommandEvent&); From 45903b7b4de4a0e6f64eebde0fdedd648b1be87a Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Sun, 9 Oct 2016 19:18:16 -0700 Subject: [PATCH 2/5] AudioCommon: SupportsDPL2Decoder, SupportsLatencyControl, SupportsVolumeChanges --- Source/Core/AudioCommon/AudioCommon.cpp | 24 +++++++++++++++++++ Source/Core/AudioCommon/AudioCommon.h | 3 +++ .../Core/DolphinWX/Config/AudioConfigPane.cpp | 20 ++++------------ 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/Source/Core/AudioCommon/AudioCommon.cpp b/Source/Core/AudioCommon/AudioCommon.cpp index dd0b31b916..642051f166 100644 --- a/Source/Core/AudioCommon/AudioCommon.cpp +++ b/Source/Core/AudioCommon/AudioCommon.cpp @@ -117,6 +117,30 @@ std::vector GetSoundBackends() return backends; } +bool SupportsDPL2Decoder(const std::string& backend) +{ +#ifndef __APPLE__ + if (backend == BACKEND_OPENAL) + return true; +#endif + if (backend == BACKEND_PULSEAUDIO) + return true; + return false; +} + +bool SupportsLatencyControl(const std::string& backend) +{ + return backend == BACKEND_OPENAL; +} + +bool SupportsVolumeChanges(const std::string& backend) +{ + // FIXME: this one should ask the backend whether it supports it. + // but getting the backend from string etc. is probably + // too much just to enable/disable a stupid slider... + return backend == BACKEND_COREAUDIO || backend == BACKEND_OPENAL || backend == BACKEND_XAUDIO2; +} + void UpdateSoundStream() { if (g_sound_stream) diff --git a/Source/Core/AudioCommon/AudioCommon.h b/Source/Core/AudioCommon/AudioCommon.h index 9b70a3ce4b..1d6bf5fc56 100644 --- a/Source/Core/AudioCommon/AudioCommon.h +++ b/Source/Core/AudioCommon/AudioCommon.h @@ -18,6 +18,9 @@ namespace AudioCommon void InitSoundStream(); void ShutdownSoundStream(); std::vector GetSoundBackends(); +bool SupportsDPL2Decoder(const std::string& backend); +bool SupportsLatencyControl(const std::string& backend); +bool SupportsVolumeChanges(const std::string& backend); void UpdateSoundStream(); void ClearAudioBuffer(bool mute); void SendAIBuffer(const short* samples, unsigned int num_samples); diff --git a/Source/Core/DolphinWX/Config/AudioConfigPane.cpp b/Source/Core/DolphinWX/Config/AudioConfigPane.cpp index bd626e437c..ceb344cf0c 100644 --- a/Source/Core/DolphinWX/Config/AudioConfigPane.cpp +++ b/Source/Core/DolphinWX/Config/AudioConfigPane.cpp @@ -55,14 +55,9 @@ void AudioConfigPane::InitializeGUI() m_audio_backend_choice->SetToolTip( _("Changing this will have no effect while the emulator is running.")); m_audio_latency_spinctrl->SetToolTip(_( - "Sets the latency (in ms). Higher values may reduce audio crackling. OpenAL backend only.")); -#if defined(__APPLE__) + "Sets the latency (in ms). Higher values may reduce audio crackling. Certain backends only.")); m_dpl2_decoder_checkbox->SetToolTip( - _("Enables Dolby Pro Logic II emulation using 5.1 surround. Not available on OS X.")); -#else - m_dpl2_decoder_checkbox->SetToolTip( - _("Enables Dolby Pro Logic II emulation using 5.1 surround. OpenAL or Pulse backends only.")); -#endif + _("Enables Dolby Pro Logic II emulation using 5.1 surround. Certain backends only.")); const int space5 = FromDIP(5); @@ -133,14 +128,9 @@ void AudioConfigPane::LoadGUIValues() void AudioConfigPane::ToggleBackendSpecificControls(const std::string& backend) { - m_dpl2_decoder_checkbox->Enable(backend == BACKEND_OPENAL || backend == BACKEND_PULSEAUDIO); - m_audio_latency_spinctrl->Enable(backend == BACKEND_OPENAL); - - // FIXME: this one should ask the backend whether it supports it. - // but getting the backend from string etc. is probably - // too much just to enable/disable a stupid slider... - m_volume_slider->Enable(backend == BACKEND_COREAUDIO || backend == BACKEND_OPENAL || - backend == BACKEND_XAUDIO2); + m_dpl2_decoder_checkbox->Enable(AudioCommon::SupportsDPL2Decoder(backend)); + m_audio_latency_spinctrl->Enable(AudioCommon::SupportsLatencyControl(backend)); + m_volume_slider->Enable(AudioCommon::SupportsVolumeChanges(backend)); } void AudioConfigPane::RefreshGUI() From a0ebafe9a9b3d5397bc6c62dbd4a223e5b37992e Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Sun, 9 Oct 2016 19:22:18 -0700 Subject: [PATCH 3/5] AudioConfigPane: move DPL2 decoding into 'Backend Settings' --- Source/Core/DolphinWX/Config/AudioConfigPane.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Source/Core/DolphinWX/Config/AudioConfigPane.cpp b/Source/Core/DolphinWX/Config/AudioConfigPane.cpp index ceb344cf0c..5efcde252b 100644 --- a/Source/Core/DolphinWX/Config/AudioConfigPane.cpp +++ b/Source/Core/DolphinWX/Config/AudioConfigPane.cpp @@ -66,9 +66,6 @@ void AudioConfigPane::InitializeGUI() dsp_engine_sizer->Add(m_dsp_engine_radiobox, 0, wxEXPAND | wxLEFT | wxRIGHT, space5); dsp_engine_sizer->AddSpacer(space5); dsp_engine_sizer->AddStretchSpacer(); - dsp_engine_sizer->Add(m_dpl2_decoder_checkbox, 0, wxLEFT | wxRIGHT, space5); - dsp_engine_sizer->AddStretchSpacer(); - dsp_engine_sizer->AddSpacer(space5); wxStaticBoxSizer* const volume_sizer = new wxStaticBoxSizer(wxVERTICAL, this, _("Volume")); volume_sizer->Add(m_volume_slider, 1, wxALIGN_CENTER_HORIZONTAL); @@ -80,9 +77,10 @@ void AudioConfigPane::InitializeGUI() wxDefaultSpan, wxALIGN_CENTER_VERTICAL); backend_grid_sizer->Add(m_audio_backend_choice, wxGBPosition(0, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL); - backend_grid_sizer->Add(new wxStaticText(this, wxID_ANY, _("Latency:")), wxGBPosition(1, 0), + backend_grid_sizer->Add(m_dpl2_decoder_checkbox, wxGBPosition(1, 0), wxGBSpan(1, 2), wxALIGN_CENTER_VERTICAL); + backend_grid_sizer->Add(new wxStaticText(this, wxID_ANY, _("Latency:")), wxGBPosition(2, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL); - backend_grid_sizer->Add(m_audio_latency_spinctrl, wxGBPosition(1, 1), wxDefaultSpan, + backend_grid_sizer->Add(m_audio_latency_spinctrl, wxGBPosition(2, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL); wxStaticBoxSizer* const backend_static_box_sizer = From 78655e5fed749db380c2cad36058cdd2aaeb5c0d Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Sun, 9 Oct 2016 19:28:50 -0700 Subject: [PATCH 4/5] AudioConfigPane: gray-out extra text for disabled controls --- Source/Core/DolphinWX/Config/AudioConfigPane.cpp | 6 ++++-- Source/Core/DolphinWX/Config/AudioConfigPane.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Source/Core/DolphinWX/Config/AudioConfigPane.cpp b/Source/Core/DolphinWX/Config/AudioConfigPane.cpp index 5efcde252b..5df149e8fb 100644 --- a/Source/Core/DolphinWX/Config/AudioConfigPane.cpp +++ b/Source/Core/DolphinWX/Config/AudioConfigPane.cpp @@ -44,6 +44,7 @@ void AudioConfigPane::InitializeGUI() new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_audio_backend_strings); m_audio_latency_spinctrl = new wxSpinCtrl(this, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 0, 30); + m_audio_latency_label = new wxStaticText(this, wxID_ANY, _("Latency:")); m_dsp_engine_radiobox->Bind(wxEVT_RADIOBOX, &AudioConfigPane::OnDSPEngineRadioBoxChanged, this); m_dpl2_decoder_checkbox->Bind(wxEVT_CHECKBOX, &AudioConfigPane::OnDPL2DecoderCheckBoxChanged, @@ -78,8 +79,7 @@ void AudioConfigPane::InitializeGUI() backend_grid_sizer->Add(m_audio_backend_choice, wxGBPosition(0, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL); backend_grid_sizer->Add(m_dpl2_decoder_checkbox, wxGBPosition(1, 0), wxGBSpan(1, 2), wxALIGN_CENTER_VERTICAL); - backend_grid_sizer->Add(new wxStaticText(this, wxID_ANY, _("Latency:")), wxGBPosition(2, 0), - wxDefaultSpan, wxALIGN_CENTER_VERTICAL); + backend_grid_sizer->Add(m_audio_latency_label, wxGBPosition(2, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL); backend_grid_sizer->Add(m_audio_latency_spinctrl, wxGBPosition(2, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL); @@ -128,7 +128,9 @@ void AudioConfigPane::ToggleBackendSpecificControls(const std::string& backend) { m_dpl2_decoder_checkbox->Enable(AudioCommon::SupportsDPL2Decoder(backend)); m_audio_latency_spinctrl->Enable(AudioCommon::SupportsLatencyControl(backend)); + m_audio_latency_label->Enable(AudioCommon::SupportsLatencyControl(backend)); m_volume_slider->Enable(AudioCommon::SupportsVolumeChanges(backend)); + m_volume_text->Enable(AudioCommon::SupportsVolumeChanges(backend)); } void AudioConfigPane::RefreshGUI() diff --git a/Source/Core/DolphinWX/Config/AudioConfigPane.h b/Source/Core/DolphinWX/Config/AudioConfigPane.h index eccb24ccc9..cb5415d577 100644 --- a/Source/Core/DolphinWX/Config/AudioConfigPane.h +++ b/Source/Core/DolphinWX/Config/AudioConfigPane.h @@ -43,4 +43,5 @@ private: wxStaticText* m_volume_text; wxChoice* m_audio_backend_choice; wxSpinCtrl* m_audio_latency_spinctrl; + wxStaticText* m_audio_latency_label; }; From c253076564013a23f9335350f19204b4feb8e1ce Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Sun, 9 Oct 2016 19:34:11 -0700 Subject: [PATCH 5/5] AudioConfigPane: clang-format --- .../Core/DolphinWX/Config/AudioConfigPane.cpp | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/Source/Core/DolphinWX/Config/AudioConfigPane.cpp b/Source/Core/DolphinWX/Config/AudioConfigPane.cpp index 5df149e8fb..84d1b86360 100644 --- a/Source/Core/DolphinWX/Config/AudioConfigPane.cpp +++ b/Source/Core/DolphinWX/Config/AudioConfigPane.cpp @@ -55,8 +55,8 @@ void AudioConfigPane::InitializeGUI() m_audio_backend_choice->SetToolTip( _("Changing this will have no effect while the emulator is running.")); - m_audio_latency_spinctrl->SetToolTip(_( - "Sets the latency (in ms). Higher values may reduce audio crackling. Certain backends only.")); + m_audio_latency_spinctrl->SetToolTip(_("Sets the latency (in ms). Higher values may reduce audio " + "crackling. Certain backends only.")); m_dpl2_decoder_checkbox->SetToolTip( _("Enables Dolby Pro Logic II emulation using 5.1 surround. Certain backends only.")); @@ -78,8 +78,10 @@ void AudioConfigPane::InitializeGUI() wxDefaultSpan, wxALIGN_CENTER_VERTICAL); backend_grid_sizer->Add(m_audio_backend_choice, wxGBPosition(0, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL); - backend_grid_sizer->Add(m_dpl2_decoder_checkbox, wxGBPosition(1, 0), wxGBSpan(1, 2), wxALIGN_CENTER_VERTICAL); - backend_grid_sizer->Add(m_audio_latency_label, wxGBPosition(2, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL); + backend_grid_sizer->Add(m_dpl2_decoder_checkbox, wxGBPosition(1, 0), wxGBSpan(1, 2), + wxALIGN_CENTER_VERTICAL); + backend_grid_sizer->Add(m_audio_latency_label, wxGBPosition(2, 0), wxDefaultSpan, + wxALIGN_CENTER_VERTICAL); backend_grid_sizer->Add(m_audio_latency_spinctrl, wxGBPosition(2, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL); @@ -127,10 +129,14 @@ void AudioConfigPane::LoadGUIValues() void AudioConfigPane::ToggleBackendSpecificControls(const std::string& backend) { m_dpl2_decoder_checkbox->Enable(AudioCommon::SupportsDPL2Decoder(backend)); - m_audio_latency_spinctrl->Enable(AudioCommon::SupportsLatencyControl(backend)); - m_audio_latency_label->Enable(AudioCommon::SupportsLatencyControl(backend)); - m_volume_slider->Enable(AudioCommon::SupportsVolumeChanges(backend)); - m_volume_text->Enable(AudioCommon::SupportsVolumeChanges(backend)); + + bool supports_latency_control = AudioCommon::SupportsLatencyControl(backend); + m_audio_latency_spinctrl->Enable(supports_latency_control); + m_audio_latency_label->Enable(supports_latency_control); + + bool supports_volume_changes = AudioCommon::SupportsVolumeChanges(backend); + m_volume_slider->Enable(supports_volume_changes); + m_volume_text->Enable(supports_volume_changes); } void AudioConfigPane::RefreshGUI()