Skip to content

Commit

Permalink
reimplement MP audio mode 2 (active instance only)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arisotura committed Nov 1, 2024
1 parent 58ee191 commit 7740634
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
15 changes: 11 additions & 4 deletions src/frontend/qt_sdl/EmuInstanceAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ void EmuInstance::micCallback(void* data, Uint8* stream, int len)
void EmuInstance::audioMute()
{
audioMuted = false;
if (numEmuInstances() < 2) return;

switch (mpAudioMode)
{
Expand All @@ -141,10 +142,16 @@ void EmuInstance::audioMute()
break;

case 2: // only currently focused instance
//if (mainWindow != nullptr)
// audioMuted = !mainWindow->isActiveWindow();
// TODO!!
printf("TODO!! audioMute mode 2\n");
audioMuted = true;
for (int i = 0; i < kMaxWindows; i++)
{
if (!windowList[i]) continue;
if (windowList[i]->isFocused())
{
audioMuted = false;
break;
}
}
break;
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/frontend/qt_sdl/Screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,10 @@ bool ScreenPanel::event(QEvent* event)
touchEvent((QTouchEvent*)event);
return true;
}
else if (event->type() == QEvent::FocusIn)
mainWindow->onFocusIn();
else if (event->type() == QEvent::FocusOut)
mainWindow->onFocusOut();

return QWidget::event(event);
}
Expand Down
18 changes: 16 additions & 2 deletions src/frontend/qt_sdl/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ MainWindow::MainWindow(int id, EmuInstance* inst, QWidget* parent) :
localCfg(inst->localCfg),
windowCfg(localCfg.GetTable("Window"+std::to_string(id), "Window0")),
emuThread(inst->getEmuThread()),
enabledSaved(false)
enabledSaved(false),
focused(true)
{
#ifndef _WIN32
if (!parent)
Expand Down Expand Up @@ -1015,13 +1016,26 @@ void MainWindow::dropEvent(QDropEvent* event)

void MainWindow::focusInEvent(QFocusEvent* event)
{
emuInstance->audioMute();
onFocusIn();
}

void MainWindow::focusOutEvent(QFocusEvent* event)
{
onFocusOut();
}

void MainWindow::onFocusIn()
{
focused = true;
if (emuInstance)
emuInstance->audioMute();
}

void MainWindow::onFocusOut()
{
// focusOutEvent is called through the window close event handler
// prevent use after free
focused = false;
if (emuInstance)
emuInstance->audioMute();
}
Expand Down
6 changes: 6 additions & 0 deletions src/frontend/qt_sdl/Window.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ class MainWindow : public QMainWindow

void onAppStateChanged(Qt::ApplicationState state);

void onFocusIn();
void onFocusOut();
bool isFocused() { return focused; }

void osdAddMessage(unsigned int color, const char* msg);

// called when the MP interface is changed
Expand Down Expand Up @@ -264,6 +268,8 @@ private slots:
int windowID;
bool enabledSaved;

bool focused;

EmuInstance* emuInstance;
EmuThread* emuThread;

Expand Down

0 comments on commit 7740634

Please sign in to comment.