From dce96a426d5a5d5586f5760725562a21e946553e Mon Sep 17 00:00:00 2001 From: Arisotura Date: Mon, 19 Sep 2022 21:56:12 +0200 Subject: [PATCH] actually implement the fun audio settings --- src/frontend/qt_sdl/main.cpp | 35 ++++++++++++++++++++++++++++++++++- src/frontend/qt_sdl/main.h | 3 +++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 6002b445..66481954 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -104,6 +104,7 @@ bool videoSettingsDirty; SDL_AudioDeviceID audioDevice; int audioFreq; +bool audioMuted; SDL_cond* audioSync; SDL_mutex* audioSyncLock; @@ -141,7 +142,7 @@ void audioCallback(void* data, Uint8* stream, int len) SDL_CondSignal(audioSync); SDL_UnlockMutex(audioSyncLock); - if (num_in < 1) + if ((num_in < 1) || audioMuted) { memset(stream, 0, len*sizeof(s16)*2); return; @@ -161,6 +162,23 @@ void audioCallback(void* data, Uint8* stream, int len) Frontend::AudioOut_Resample(buf_in, num_in, (s16*)stream, len, Config::AudioVolume); } +void audioMute() +{ + int inst = Platform::InstanceID(); + audioMuted = false; + + switch (Config::MPAudioMode) + { + case 1: // only instance 1 + if (inst > 0) audioMuted = true; + break; + + case 2: // only currently focused instance + if (!mainWindow->isActiveWindow()) audioMuted = true; + break; + } +} + void micOpen() { @@ -1341,6 +1359,7 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) setWindowTitle("melonDS " MELONDS_VERSION); setAttribute(Qt::WA_DeleteOnClose); setAcceptDrops(true); + setFocusPolicy(Qt::ClickFocus); int inst = Platform::InstanceID(); @@ -1969,6 +1988,16 @@ void MainWindow::dropEvent(QDropEvent* event) } } +void MainWindow::focusInEvent(QFocusEvent* event) +{ + audioMute(); +} + +void MainWindow::focusOutEvent(QFocusEvent* event) +{ + audioMute(); +} + void MainWindow::onAppStateChanged(Qt::ApplicationState state) { if (state == Qt::ApplicationInactive) @@ -2802,6 +2831,7 @@ void MainWindow::onOpenMPSettings() void MainWindow::onMPSettingsFinished(int res) { + audioMute(); LocalMP::SetRecvTimeout(Config::MPRecvTimeout); emuThread->emuUnpause(); @@ -3135,6 +3165,7 @@ int main(int argc, char** argv) format.setSwapInterval(0); QSurfaceFormat::setDefaultFormat(format); + audioMuted = false; audioSync = SDL_CreateCond(); audioSyncLock = SDL_CreateMutex(); @@ -3188,6 +3219,8 @@ int main(int argc, char** argv) emuThread->start(); emuThread->emuPause(); + audioMute(); + QObject::connect(&melon, &QApplication::applicationStateChanged, mainWindow, &MainWindow::onAppStateChanged); if (argc > 1) diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h index 6e108929..a9f0c0cd 100644 --- a/src/frontend/qt_sdl/main.h +++ b/src/frontend/qt_sdl/main.h @@ -226,6 +226,9 @@ protected: void dragEnterEvent(QDragEnterEvent* event) override; void dropEvent(QDropEvent* event) override; + void focusInEvent(QFocusEvent* event) override; + void focusOutEvent(QFocusEvent* event) override; + signals: void screenLayoutChange();