From f46fa63fdadafe5ee033faf70520bde956b02020 Mon Sep 17 00:00:00 2001 From: Hangman Date: Wed, 4 Jun 2025 21:43:36 +0200 Subject: [PATCH] Use ALC_SOFT_system_events in SmartDeviceRerouter --- .../de/pottgames/tuningfork/ALExtension.java | 1 + .../router/SmartDeviceRerouter.java | 52 ++++++++++++++++--- 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/de/pottgames/tuningfork/ALExtension.java b/core/src/main/java/de/pottgames/tuningfork/ALExtension.java index d49af87a..05571e6c 100644 --- a/core/src/main/java/de/pottgames/tuningfork/ALExtension.java +++ b/core/src/main/java/de/pottgames/tuningfork/ALExtension.java @@ -27,6 +27,7 @@ public enum ALExtension { ALC_SOFT_OUTPUT_MODE("ALC_SOFT_output_mode", true), ALC_SOFT_PAUSE_DEVICE("ALC_SOFT_pause_device", true), ALC_SOFT_REOPEN_DEVICE("ALC_SOFT_reopen_device", true), + ALC_SOFT_SYSTEM_EVENTS("ALC_SOFT_system_events", true), AL_EXT_ALAW("AL_EXT_ALAW", false), AL_EXT_BFORMAT("AL_EXT_BFORMAT", false), AL_EXT_DOUBLE("AL_EXT_DOUBLE", false), diff --git a/core/src/main/java/de/pottgames/tuningfork/router/SmartDeviceRerouter.java b/core/src/main/java/de/pottgames/tuningfork/router/SmartDeviceRerouter.java index 77782403..175fea08 100644 --- a/core/src/main/java/de/pottgames/tuningfork/router/SmartDeviceRerouter.java +++ b/core/src/main/java/de/pottgames/tuningfork/router/SmartDeviceRerouter.java @@ -16,6 +16,8 @@ import org.lwjgl.openal.ALC10; import org.lwjgl.openal.EnumerateAllExt; +import org.lwjgl.openal.SOFTSystemEventProcI; +import org.lwjgl.openal.SOFTSystemEvents; import org.lwjgl.openal.SOFTReopenDevice; import org.lwjgl.system.MemoryUtil; @@ -25,8 +27,9 @@ import de.pottgames.tuningfork.misc.Objects; /** - * The SmartDeviceRerouter checks every 1.5 seconds (configurable) whether the connection to the audio device still exists and whether it is the optimal - * connection. If not, it tries to establish a connection with the following prioritization:
+ * The SmartDeviceRerouter tries to keep the connection to the optimal audio device alive. When the ALC_SOFT_system_events extension is available, + * callbacks are used to react to device changes. Otherwise, a background thread checks every 1.5 seconds (configurable) whether the connection still + * exists and whether it is the optimal connection. If not, it tries to establish a connection with the following prioritization:
*