From c0c78553e6d5db89e851aa1ac58e0b422cce76c5 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sat, 25 May 2024 01:17:51 +0200 Subject: [PATCH] port MPSettings --- src/frontend/qt_sdl/Config.cpp | 4 +--- src/frontend/qt_sdl/Config.h | 3 --- src/frontend/qt_sdl/EmuInstance.cpp | 2 ++ src/frontend/qt_sdl/EmuInstance.h | 2 ++ src/frontend/qt_sdl/EmuInstanceAudio.cpp | 5 ++--- src/frontend/qt_sdl/MPSettingsDialog.cpp | 15 +++++++++------ src/frontend/qt_sdl/MPSettingsDialog.h | 3 +++ src/frontend/qt_sdl/Window.cpp | 3 ++- 8 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/frontend/qt_sdl/Config.cpp b/src/frontend/qt_sdl/Config.cpp index 7b274ebf..e35f6ef7 100644 --- a/src/frontend/qt_sdl/Config.cpp +++ b/src/frontend/qt_sdl/Config.cpp @@ -62,9 +62,6 @@ int GL_ScaleFactor; bool GL_BetterPolygons; bool GL_HiresCoordinates; -int MPAudioMode; -int MPRecvTimeout; - std::string LANDevice; bool DirectLAN; @@ -124,6 +121,7 @@ RangeList IntRanges = {"Instance*.Window*.ScreenSizing", {0, Frontend::screenSizing_MAX-1}}, {"Instance*.Window*.ScreenAspectTop", {0, AspectRatiosNum-1}}, {"Instance*.Window*.ScreenAspectBot", {0, AspectRatiosNum-1}}, + {"MP.AudioMode", {0, 2}}, }; DefaultList DefaultBools = diff --git a/src/frontend/qt_sdl/Config.h b/src/frontend/qt_sdl/Config.h index bb2374dc..a931fd67 100644 --- a/src/frontend/qt_sdl/Config.h +++ b/src/frontend/qt_sdl/Config.h @@ -176,9 +176,6 @@ extern int GL_ScaleFactor; extern bool GL_BetterPolygons; extern bool GL_HiresCoordinates; -extern int MPAudioMode; -extern int MPRecvTimeout; - extern std::string LANDevice; extern bool DirectLAN; diff --git a/src/frontend/qt_sdl/EmuInstance.cpp b/src/frontend/qt_sdl/EmuInstance.cpp index 00be2b6f..9ed7f37a 100644 --- a/src/frontend/qt_sdl/EmuInstance.cpp +++ b/src/frontend/qt_sdl/EmuInstance.cpp @@ -73,6 +73,8 @@ EmuInstance::EmuInstance(int inst) : instanceID(inst), maxFPS = globalCfg.GetInt("MaxFPS"); doAudioSync = globalCfg.GetBool("AudioSync"); + mpAudioMode = globalCfg.GetInt("MP.AudioMode"); + nds = nullptr; updateConsole(nullptr, nullptr); diff --git a/src/frontend/qt_sdl/EmuInstance.h b/src/frontend/qt_sdl/EmuInstance.h index b505d992..6ef485ba 100644 --- a/src/frontend/qt_sdl/EmuInstance.h +++ b/src/frontend/qt_sdl/EmuInstance.h @@ -247,6 +247,8 @@ private: SDL_cond* audioSyncCond; SDL_mutex* audioSyncLock; + int mpAudioMode; + SDL_AudioDeviceID micDevice; melonDS::s16 micExtBuffer[2048]; melonDS::u32 micExtBufferWritePos; diff --git a/src/frontend/qt_sdl/EmuInstanceAudio.cpp b/src/frontend/qt_sdl/EmuInstanceAudio.cpp index 0dfa01c8..e7bc71dd 100644 --- a/src/frontend/qt_sdl/EmuInstanceAudio.cpp +++ b/src/frontend/qt_sdl/EmuInstanceAudio.cpp @@ -117,13 +117,12 @@ void EmuInstance::micCallback(void* data, Uint8* stream, int len) void EmuInstance::audioMute() { - int inst = Platform::InstanceID(); audioMuted = false; - switch (Config::MPAudioMode) + switch (mpAudioMode) { case 1: // only instance 1 - if (inst > 0) audioMuted = true; + if (instanceID > 0) audioMuted = true; break; case 2: // only currently focused instance diff --git a/src/frontend/qt_sdl/MPSettingsDialog.cpp b/src/frontend/qt_sdl/MPSettingsDialog.cpp index bd64dfa2..957a8019 100644 --- a/src/frontend/qt_sdl/MPSettingsDialog.cpp +++ b/src/frontend/qt_sdl/MPSettingsDialog.cpp @@ -22,6 +22,7 @@ #include "types.h" #include "Platform.h" #include "Config.h" +#include "main.h" #include "LAN_Socket.h" #include "LAN_PCap.h" @@ -41,13 +42,16 @@ MPSettingsDialog::MPSettingsDialog(QWidget* parent) : QDialog(parent), ui(new Ui ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); + emuInstance = ((MainWindow*)parent)->getEmuInstance(); + + auto& cfg = emuInstance->getGlobalConfig(); grpAudioMode = new QButtonGroup(this); grpAudioMode->addButton(ui->rbAudioAll, 0); grpAudioMode->addButton(ui->rbAudioOneOnly, 1); grpAudioMode->addButton(ui->rbAudioActiveOnly, 2); - grpAudioMode->button(Config::MPAudioMode)->setChecked(true); + grpAudioMode->button(cfg.GetInt("MP.AudioMode"))->setChecked(true); - ui->sbReceiveTimeout->setValue(Config::MPRecvTimeout); + ui->sbReceiveTimeout->setValue(cfg.GetInt("MP.RecvTimeout")); } MPSettingsDialog::~MPSettingsDialog() @@ -59,8 +63,9 @@ void MPSettingsDialog::done(int r) { if (r == QDialog::Accepted) { - Config::MPAudioMode = grpAudioMode->checkedId(); - Config::MPRecvTimeout = ui->sbReceiveTimeout->value(); + auto& cfg = emuInstance->getGlobalConfig(); + cfg.SetInt("MP.AudioMode", grpAudioMode->checkedId()); + cfg.SetInt("MP.RecvTimeout", ui->sbReceiveTimeout->value()); Config::Save(); } @@ -69,5 +74,3 @@ void MPSettingsDialog::done(int r) closeDlg(); } - -// diff --git a/src/frontend/qt_sdl/MPSettingsDialog.h b/src/frontend/qt_sdl/MPSettingsDialog.h index 837ac8db..cdd05831 100644 --- a/src/frontend/qt_sdl/MPSettingsDialog.h +++ b/src/frontend/qt_sdl/MPSettingsDialog.h @@ -25,6 +25,8 @@ namespace Ui { class MPSettingsDialog; } class MPSettingsDialog; +class EmuInstance; + class MPSettingsDialog : public QDialog { Q_OBJECT @@ -58,6 +60,7 @@ private slots: private: Ui::MPSettingsDialog* ui; + EmuInstance* emuInstance; QButtonGroup* grpAudioMode; }; diff --git a/src/frontend/qt_sdl/Window.cpp b/src/frontend/qt_sdl/Window.cpp index d97a637b..0476c5ae 100644 --- a/src/frontend/qt_sdl/Window.cpp +++ b/src/frontend/qt_sdl/Window.cpp @@ -1843,8 +1843,9 @@ void MainWindow::onOpenMPSettings() void MainWindow::onMPSettingsFinished(int res) { + emuInstance->mpAudioMode = globalCfg.GetInt("MP.AudioMode"); emuInstance->audioMute(); - LocalMP::SetRecvTimeout(Config::MPRecvTimeout); + LocalMP::SetRecvTimeout(globalCfg.GetInt("MP.RecvTimeout")); emuThread->emuUnpause(); }