From 36e88fafb6df5507848b0371eb685130477b82d2 Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Thu, 13 Apr 2023 13:47:17 +0000 Subject: [PATCH] Fix dsound looping when moving/resizing window Add MOVE_START/MOVE_END events to detect when the window is moved or resized and pause sound on Windows to prevent the DirectSound driver from looping. Signed-off-by: Rafael Kitover --- src/wx/wxvbam.cpp | 16 ++++++++++++++++ src/wx/wxvbam.h | 2 ++ 2 files changed, 18 insertions(+) diff --git a/src/wx/wxvbam.cpp b/src/wx/wxvbam.cpp index 504d1ba0..c58990be 100644 --- a/src/wx/wxvbam.cpp +++ b/src/wx/wxvbam.cpp @@ -824,6 +824,8 @@ EVT_DROP_FILES(MainFrame::OnDropFile) // for window geometry EVT_MOVE(MainFrame::OnMove) +EVT_MOVE_START(MainFrame::OnMoveStart) +EVT_MOVE_END(MainFrame::OnMoveEnd) EVT_SIZE(MainFrame::OnSize) // For tracking menubar state. @@ -879,6 +881,20 @@ void MainFrame::OnMove(wxMoveEvent&) { } } +// On Windows pause sound when moving and resizing the window to prevent dsound +// from looping. +void MainFrame::OnMoveStart(wxMoveEvent&) { +#ifdef __WXMSW__ + soundPause(); +#endif +} + +void MainFrame::OnMoveEnd(wxMoveEvent&) { +#ifdef __WXMSW__ + soundResume(); +#endif +} + void MainFrame::OnSize(wxSizeEvent& event) { wxFrame::OnSize(event); diff --git a/src/wx/wxvbam.h b/src/wx/wxvbam.h index dfe7b2b3..ea0659b8 100644 --- a/src/wx/wxvbam.h +++ b/src/wx/wxvbam.h @@ -382,6 +382,8 @@ private: void OnMenu(wxContextMenuEvent&); // window geometry void OnMove(wxMoveEvent& event); + void OnMoveStart(wxMoveEvent& event); + void OnMoveEnd(wxMoveEvent& event); void OnSize(wxSizeEvent& event); // Load a named wxDialog from the XRC file wxDialog* LoadXRCDialog(const char* name);