79 lines
2.5 KiB
Go
79 lines
2.5 KiB
Go
// Copyright (c) 2026 Storm Dragon
|
|
// Authors: Storm Dragon, Angus Kola
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package preferences
|
|
|
|
import (
|
|
"errors"
|
|
)
|
|
|
|
func soundChecks(values *Values) []struct {
|
|
id string
|
|
value *bool
|
|
} {
|
|
return []struct {
|
|
id string
|
|
value *bool
|
|
}{
|
|
{"enableSoundCheckButton", &values.EnableSound},
|
|
{"playSoundForRoleCheckButton", &values.PlaySoundForRole},
|
|
{"playSoundForStateCheckButton", &values.PlaySoundForState},
|
|
{"playSoundForPositionInSetCheckButton", &values.PlaySoundForPositionInSet},
|
|
{"spatializeObjectSoundsCheckButton", &values.SpatializeObjectSounds},
|
|
}
|
|
}
|
|
|
|
func (session *uiSession) setSoundTheme(theme string) {
|
|
session.soundThemes = []string{"default", "none"}
|
|
selected := 0
|
|
if theme == "none" {
|
|
selected = 1
|
|
} else if theme != "" && theme != "default" {
|
|
selected = len(session.soundThemes)
|
|
session.soundThemes = append(session.soundThemes, theme)
|
|
}
|
|
labels := make([]string, len(session.soundThemes))
|
|
for i, value := range session.soundThemes {
|
|
if value == "default" {
|
|
labels[i] = "Default"
|
|
} else if value == "none" {
|
|
labels[i] = "None"
|
|
} else {
|
|
labels[i] = value
|
|
}
|
|
}
|
|
comboItems("soundThemeCombo", labels, selected)
|
|
}
|
|
|
|
func set_sound_checks(values Values) {
|
|
for _, check := range soundChecks(&values) {
|
|
setCheck(check.id, *check.value)
|
|
}
|
|
}
|
|
|
|
func (session *uiSession) set_sound_values(values Values) {
|
|
setRange("soundVolumeScale", values.SoundVolume)
|
|
setCombo("soundSinkCombo", map[string]int{"auto": 0, "pipewire": 1, "pulse": 2, "alsa": 3}[values.SoundSink])
|
|
session.setSoundTheme(values.SoundTheme)
|
|
setCombo("roleSoundPresentationCombo", map[string]int{"sound_and_speech": 0, "speech_only": 1, "sound_only": 2}[values.RoleSoundPresentation])
|
|
}
|
|
|
|
func get_sound_checks(values *Values) {
|
|
for _, check := range soundChecks(values) {
|
|
*check.value = getCheck(check.id)
|
|
}
|
|
}
|
|
|
|
func (session *uiSession) get_sound_values(values *Values) error {
|
|
values.SoundVolume = getRange("soundVolumeScale")
|
|
sink, theme, presentation := getCombo("soundSinkCombo"), getCombo("soundThemeCombo"), getCombo("roleSoundPresentationCombo")
|
|
if sink < 0 || sink > 3 || theme < 0 || theme >= len(session.soundThemes) || presentation < 0 || presentation > 2 {
|
|
return errors.New("Choose valid sound output settings.")
|
|
}
|
|
values.SoundSink = []string{"auto", "pipewire", "pulse", "alsa"}[sink]
|
|
values.SoundTheme = session.soundThemes[theme]
|
|
values.RoleSoundPresentation = []string{"sound_and_speech", "speech_only", "sound_only"}[presentation]
|
|
return nil
|
|
}
|