From 3cef52b72dc4bae8045f1fb5a7974164ea7e2eb8 Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Thu, 30 Mar 2023 00:22:54 +0000 Subject: [PATCH] Fix pause/next-frame Pause only sound on menu open on Windows, and resume on menu close if emulator is not paused. This is to avoid DirectSound looping on menu open. Fix #788 Fix #1077 Signed-off-by: Rafael Kitover --- src/wx/dsound.cpp | 2 +- src/wx/wxvbam.cpp | 30 ++++++++---------------------- 2 files changed, 9 insertions(+), 23 deletions(-) diff --git a/src/wx/dsound.cpp b/src/wx/dsound.cpp index a38c6227..3038f07a 100644 --- a/src/wx/dsound.cpp +++ b/src/wx/dsound.cpp @@ -104,7 +104,7 @@ bool DirectSound::init(long sampleRate) return false; } - if (FAILED(hr = pDirectSound->SetCooperativeLevel((HWND)wxGetApp().frame->GetHandle(), DSSCL_EXCLUSIVE))) { + if (FAILED(hr = pDirectSound->SetCooperativeLevel((HWND)wxGetApp().frame->GetHandle(), DSSCL_PRIORITY))) { wxLogError(_("Cannot SetCooperativeLevel %08x"), hr); return false; } diff --git a/src/wx/wxvbam.cpp b/src/wx/wxvbam.cpp index 76770552..9a4d27dc 100644 --- a/src/wx/wxvbam.cpp +++ b/src/wx/wxvbam.cpp @@ -1143,32 +1143,18 @@ void MainFrame::MenuPopped(wxMenuEvent& evt) evt.Skip(); } -// Pause game if menu pops up. -// -// This is a feature most people don't like, and it causes problems with -// keyboard game keys on mac, so we will disable it for now. -// -// On Windows, there will still be a pause because of how the windows event -// model works, in addition the audio will loop with SDL, so we still pause on -// Windows. -// -// TODO: This needs to be fixed properly. -// +// On Windows, opening the menubar will stop the app, but DirectSound will +// loop, so we pause audio here. void MainFrame::SetMenusOpened(bool state) { - if ((menus_opened = state)) { + menus_opened = state; + #ifdef __WXMSW__ - paused = true; - panel->Pause(); + if (menus_opened) + soundPause(); + else if (!paused) + soundResume(); #endif - } - else { -#ifdef __WXMSW__ - paused = false; - pause_next = false; - panel->Resume(); -#endif - } } // ShowModal that also disables emulator loop