fix: restore SDL volume to MAX after device switch
Remove dead 'currentVolume' variable that was never written to, causing SwitchDevice to always restore volume to 0 after switching audio devices. - Remove currentVolume from package state - SwitchDevice now sets mix.MAX_VOLUME after reopening device - GetVolume128 now queries SDL directly instead of reading stale variable - Fix parseSinkLine not stripping trailing ']' from [vol: X.XX] (caused volume to silently parse as 0 for sinks without MUTED tag) - Fix flake.nix: make wayland/X11 buildInputs Linux-only for macOS compat - Add unit tests for parseSinks, parseSinkLine, and ConvertVolume - Add changelog.txt tracking all audio bug fixes
This commit is contained in:
+7
-10
@@ -23,10 +23,9 @@ var (
|
||||
deviceOpen bool
|
||||
deviceName string
|
||||
|
||||
currentMusic *mix.Music
|
||||
currentPath string
|
||||
currentLoops int // 0 = once, -1 = forever
|
||||
currentVolume int // 0..128, defaults to MAX_VOLUME
|
||||
currentMusic *mix.Music
|
||||
currentPath string
|
||||
currentLoops int // 0 = once, -1 = forever
|
||||
|
||||
// Config knobs (could be made public or read from your config)
|
||||
defaultFreq = 48000
|
||||
@@ -351,6 +350,7 @@ func parseSinkLine(s string) (Sink, bool) {
|
||||
volPart := rest[volStart:]
|
||||
// "[vol: 0.65]" or "[vol: 0.65 MUTED]"
|
||||
volPart = strings.TrimPrefix(volPart, "[vol:")
|
||||
volPart = strings.TrimRight(volPart, "]")
|
||||
volPart = strings.TrimSpace(volPart)
|
||||
fields := strings.Fields(volPart)
|
||||
if len(fields) > 0 {
|
||||
@@ -411,11 +411,8 @@ func SwitchDevice(newName string) error {
|
||||
wasPlaying := mix.PlayingMusic()
|
||||
savedPath := currentPath
|
||||
savedLoops := currentLoops
|
||||
savedVolume := currentVolume
|
||||
|
||||
// Stop and release current music before reopening device
|
||||
if wasPlaying {
|
||||
}
|
||||
mix.HaltMusic()
|
||||
if currentMusic != nil {
|
||||
currentMusic.Free()
|
||||
@@ -441,8 +438,8 @@ func SwitchDevice(newName string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Restore volume
|
||||
mix.VolumeMusic(savedVolume)
|
||||
// Restore volume to MAX after reopening device (matches Play() behavior)
|
||||
mix.VolumeMusic(mix.MAX_VOLUME)
|
||||
|
||||
// Optionally resume previous track if there was one
|
||||
if wasPlaying && savedPath != "" {
|
||||
@@ -471,7 +468,7 @@ func SwitchDevice(newName string) error {
|
||||
func GetVolume128() int {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
return currentVolume
|
||||
return mix.VolumeMusic(-1)
|
||||
}
|
||||
|
||||
// Shutdown fully tears everything down. Call at app exit.
|
||||
|
||||
Reference in New Issue
Block a user