Adopt common v0.8.0 and preserve canceled hardware settings
This commit is contained in:
1 parent
b21fceb311
commit
5dfa038706
410 files changed
+5353
-4803
No files matched your search
@@ -18,22 +18,22 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"git.stormux.org/storm/cthulhu/internal/datetime"
|
||||
"git.stormux.org/storm/screenreader-common/datetime"
|
||||
)
|
||||
|
||||
func apply(settings *Settings, values rawSettings) {
|
||||
// Keep the established patch order; absent fields leave prior values intact.
|
||||
apply_legacy_sound(settings, values)
|
||||
apply_legacy_output(settings, values)
|
||||
apply_legacy_speech_service(settings, values)
|
||||
apply_legacy_reading(settings, values)
|
||||
apply_legacy_speech_formats(settings, values)
|
||||
apply_legacy_keyboard(settings, values)
|
||||
apply_legacy_echo(settings, values)
|
||||
apply_legacy_default_voice(settings, values)
|
||||
applyLegacySound(settings, values)
|
||||
applyLegacyOutput(settings, values)
|
||||
applyLegacySpeechService(settings, values)
|
||||
applyLegacyReading(settings, values)
|
||||
applyLegacySpeechFormats(settings, values)
|
||||
applyLegacyKeyboard(settings, values)
|
||||
applyLegacyEcho(settings, values)
|
||||
applyLegacyDefaultVoice(settings, values)
|
||||
}
|
||||
|
||||
func apply_legacy_sound(settings *Settings, values rawSettings) {
|
||||
func applyLegacySound(settings *Settings, values rawSettings) {
|
||||
if values.EnableSound != nil {
|
||||
settings.EnableSound = *values.EnableSound
|
||||
}
|
||||
@@ -63,7 +63,7 @@ func apply_legacy_sound(settings *Settings, values rawSettings) {
|
||||
}
|
||||
}
|
||||
|
||||
func apply_legacy_output(settings *Settings, values rawSettings) {
|
||||
func applyLegacyOutput(settings *Settings, values rawSettings) {
|
||||
if values.EnableSpeech != nil {
|
||||
settings.EnableSpeech = *values.EnableSpeech
|
||||
}
|
||||
@@ -108,7 +108,7 @@ func apply_legacy_output(settings *Settings, values rawSettings) {
|
||||
}
|
||||
}
|
||||
|
||||
func apply_legacy_speech_service(settings *Settings, values rawSettings) {
|
||||
func applyLegacySpeechService(settings *Settings, values rawSettings) {
|
||||
if values.HardwareSpeechDevice != nil {
|
||||
settings.HardwareSpeechDevice = *values.HardwareSpeechDevice
|
||||
}
|
||||
@@ -132,7 +132,7 @@ func apply_legacy_speech_service(settings *Settings, values rawSettings) {
|
||||
}
|
||||
}
|
||||
|
||||
func apply_legacy_reading(settings *Settings, values rawSettings) {
|
||||
func applyLegacyReading(settings *Settings, values rawSettings) {
|
||||
if values.Reading.OnlySpeakDisplayedText != nil {
|
||||
settings.Reading.OnlySpeakDisplayedText = *values.Reading.OnlySpeakDisplayedText
|
||||
}
|
||||
@@ -222,7 +222,7 @@ func apply_legacy_reading(settings *Settings, values rawSettings) {
|
||||
}
|
||||
}
|
||||
|
||||
func apply_legacy_speech_formats(settings *Settings, values rawSettings) {
|
||||
func applyLegacySpeechFormats(settings *Settings, values rawSettings) {
|
||||
if values.VerbalizePunctuationStyle != nil {
|
||||
settings.VerbalizePunctuationStyle = *values.VerbalizePunctuationStyle
|
||||
}
|
||||
@@ -237,7 +237,7 @@ func apply_legacy_speech_formats(settings *Settings, values rawSettings) {
|
||||
}
|
||||
}
|
||||
|
||||
func apply_legacy_keyboard(settings *Settings, values rawSettings) {
|
||||
func applyLegacyKeyboard(settings *Settings, values rawSettings) {
|
||||
if values.KeyboardLayout != nil {
|
||||
settings.KeyboardLayout = *values.KeyboardLayout
|
||||
}
|
||||
@@ -246,7 +246,7 @@ func apply_legacy_keyboard(settings *Settings, values rawSettings) {
|
||||
}
|
||||
}
|
||||
|
||||
func apply_legacy_echo(settings *Settings, values rawSettings) {
|
||||
func applyLegacyEcho(settings *Settings, values rawSettings) {
|
||||
if values.UseCustomEchoVoice != nil {
|
||||
settings.UseCustomEchoVoice = *values.UseCustomEchoVoice
|
||||
}
|
||||
@@ -312,7 +312,7 @@ func apply_legacy_echo(settings *Settings, values rawSettings) {
|
||||
}
|
||||
}
|
||||
|
||||
func apply_legacy_default_voice(settings *Settings, values rawSettings) {
|
||||
func applyLegacyDefaultVoice(settings *Settings, values rawSettings) {
|
||||
if voice, exists := values.Voices["default"]; exists {
|
||||
converted := voiceFromLegacy(voice)
|
||||
if settings.SpeechServerFactory == "hardwarefactory" {
|
||||
|
||||
@@ -37,11 +37,11 @@ func TestOCRAutoReadAllDefaultsAndExplicitFalse(t *testing.T) {
|
||||
t.Fatal("automatic OCR reading must default off")
|
||||
}
|
||||
settings.OCR.AutoReadAll = true
|
||||
apply_profile_ocr(&settings.OCR, writableOCR{})
|
||||
applyProfileOcr(&settings.OCR, writableOCR{})
|
||||
if !settings.OCR.AutoReadAll {
|
||||
t.Fatal("omitted setting changed inherited value")
|
||||
}
|
||||
apply_profile_ocr(&settings.OCR, writableOCR{AutoReadAll: boolPointer(false)})
|
||||
applyProfileOcr(&settings.OCR, writableOCR{AutoReadAll: boolPointer(false)})
|
||||
if settings.OCR.AutoReadAll {
|
||||
t.Fatal("explicit false did not override inherited value")
|
||||
}
|
||||
|
||||
@@ -20,8 +20,8 @@ package config
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
"git.stormux.org/storm/cthulhu/internal/datetime"
|
||||
"git.stormux.org/storm/cthulhu/internal/input"
|
||||
"git.stormux.org/storm/screenreader-common/datetime"
|
||||
)
|
||||
|
||||
// Application profiles store only values that differ from the global profile.
|
||||
@@ -117,7 +117,7 @@ func profileFromSettings(settings Settings) writableProfile {
|
||||
},
|
||||
},
|
||||
Speech: writableSpeech{
|
||||
Interruption: interruption_pointer(settings.SpeechInterruption),
|
||||
Interruption: interruptionPointer(settings.SpeechInterruption),
|
||||
HardwareDevice: stringPointer(settings.HardwareSpeechDevice),
|
||||
HardwareBaudRate: intPointer(settings.HardwareSpeechBaudRate),
|
||||
Enabled: boolPointer(settings.EnableSpeech), ServerFactory: stringPointer(settings.SpeechServerFactory),
|
||||
@@ -182,14 +182,14 @@ func applyProfile(settings *Settings, profile writableProfile) {
|
||||
if profile.Wine.ExcludedPrograms != nil {
|
||||
settings.Wine.ExcludedPrograms = append([]string(nil), (*profile.Wine.ExcludedPrograms)...)
|
||||
}
|
||||
apply_profile_ocr(&settings.OCR, profile.OCR)
|
||||
applyProfileOcr(&settings.OCR, profile.OCR)
|
||||
// Keep the established patch order; absent fields leave prior values intact.
|
||||
apply_profile_formats(settings, profile)
|
||||
apply_profile_echo_voice(settings, profile)
|
||||
apply_profile_reading(settings, profile)
|
||||
apply_profile_output(settings, profile)
|
||||
apply_profile_speech(settings, profile)
|
||||
apply_profile_sound(settings, profile)
|
||||
applyProfileFormats(settings, profile)
|
||||
applyProfileEchoVoice(settings, profile)
|
||||
applyProfileReading(settings, profile)
|
||||
applyProfileOutput(settings, profile)
|
||||
applyProfileSpeech(settings, profile)
|
||||
applyProfileSound(settings, profile)
|
||||
if value := profile.ProgressBar.OutputMode; value != nil {
|
||||
settings.ProgressBar.OutputMode = *value
|
||||
}
|
||||
@@ -202,11 +202,11 @@ func applyProfile(settings *Settings, profile writableProfile) {
|
||||
if value := profile.ProgressBar.SpeechPercentageInterval; value != nil {
|
||||
settings.ProgressBar.SpeechPercentageInterval = *value
|
||||
}
|
||||
apply_profile_keyboard(settings, profile)
|
||||
apply_profile_echo_keys(settings, profile)
|
||||
applyProfileKeyboard(settings, profile)
|
||||
applyProfileEchoKeys(settings, profile)
|
||||
}
|
||||
|
||||
func apply_profile_ocr(settings *OCRSettings, patch writableOCR) {
|
||||
func applyProfileOcr(settings *OCRSettings, patch writableOCR) {
|
||||
if patch.Language != nil {
|
||||
settings.Language = *patch.Language
|
||||
}
|
||||
@@ -245,7 +245,7 @@ func apply_profile_ocr(settings *OCRSettings, patch writableOCR) {
|
||||
}
|
||||
}
|
||||
|
||||
func apply_profile_formats(settings *Settings, profile writableProfile) {
|
||||
func applyProfileFormats(settings *Settings, profile writableProfile) {
|
||||
if v := profile.Presentation.TimeFormat; v != nil {
|
||||
settings.TimeFormat = *v
|
||||
}
|
||||
@@ -254,7 +254,7 @@ func apply_profile_formats(settings *Settings, profile writableProfile) {
|
||||
}
|
||||
}
|
||||
|
||||
func apply_profile_echo_voice(settings *Settings, profile writableProfile) {
|
||||
func applyProfileEchoVoice(settings *Settings, profile writableProfile) {
|
||||
if v := profile.KeyEcho.UseCustomEchoVoice; v != nil {
|
||||
settings.UseCustomEchoVoice = *v
|
||||
}
|
||||
@@ -281,7 +281,7 @@ func apply_profile_echo_voice(settings *Settings, profile writableProfile) {
|
||||
}
|
||||
}
|
||||
|
||||
func apply_profile_reading(settings *Settings, profile writableProfile) {
|
||||
func applyProfileReading(settings *Settings, profile writableProfile) {
|
||||
if value := profile.Presentation.Pronunciations; value != nil {
|
||||
settings.Pronunciations = append([]PronunciationEntry(nil), (*value)...)
|
||||
}
|
||||
@@ -422,9 +422,9 @@ func apply_profile_reading(settings *Settings, profile writableProfile) {
|
||||
}
|
||||
}
|
||||
|
||||
func apply_profile_output(settings *Settings, profile writableProfile) {
|
||||
func applyProfileOutput(settings *Settings, profile writableProfile) {
|
||||
if value := profile.Speech.Interruption; value != nil {
|
||||
settings.SpeechInterruption = *interruption_pointer(*value)
|
||||
settings.SpeechInterruption = *interruptionPointer(*value)
|
||||
}
|
||||
if value := profile.Speech.Enabled; value != nil {
|
||||
settings.EnableSpeech = *value
|
||||
@@ -473,12 +473,12 @@ func apply_profile_output(settings *Settings, profile writableProfile) {
|
||||
}
|
||||
}
|
||||
|
||||
func interruption_pointer(settings input.InterruptionSettings) *input.InterruptionSettings {
|
||||
func interruptionPointer(settings input.InterruptionSettings) *input.InterruptionSettings {
|
||||
settings.Keys = append([]string(nil), settings.Keys...)
|
||||
return &settings
|
||||
}
|
||||
|
||||
func apply_profile_speech(settings *Settings, profile writableProfile) {
|
||||
func applyProfileSpeech(settings *Settings, profile writableProfile) {
|
||||
if value := profile.Speech.HardwareDevice; value != nil {
|
||||
settings.HardwareSpeechDevice = *value
|
||||
}
|
||||
@@ -520,7 +520,7 @@ func apply_profile_speech(settings *Settings, profile writableProfile) {
|
||||
}
|
||||
}
|
||||
|
||||
func apply_profile_sound(settings *Settings, profile writableProfile) {
|
||||
func applyProfileSound(settings *Settings, profile writableProfile) {
|
||||
if value := profile.Sound.Enabled; value != nil {
|
||||
settings.EnableSound = *value
|
||||
}
|
||||
@@ -550,7 +550,7 @@ func apply_profile_sound(settings *Settings, profile writableProfile) {
|
||||
}
|
||||
}
|
||||
|
||||
func apply_profile_keyboard(settings *Settings, profile writableProfile) {
|
||||
func applyProfileKeyboard(settings *Settings, profile writableProfile) {
|
||||
if value := profile.Keyboard.Bindings; value != nil {
|
||||
settings.KeyBindings = input.CloneBindingOverrides(*value)
|
||||
}
|
||||
@@ -562,7 +562,7 @@ func apply_profile_keyboard(settings *Settings, profile writableProfile) {
|
||||
}
|
||||
}
|
||||
|
||||
func apply_profile_echo_keys(settings *Settings, profile writableProfile) {
|
||||
func applyProfileEchoKeys(settings *Settings, profile writableProfile) {
|
||||
if value := profile.KeyEcho.Enabled; value != nil {
|
||||
settings.EnableKeyEcho = *value
|
||||
}
|
||||
|
||||
@@ -26,8 +26,8 @@ import (
|
||||
"unicode"
|
||||
"unicode/utf16"
|
||||
|
||||
"git.stormux.org/storm/cthulhu/internal/datetime"
|
||||
"git.stormux.org/storm/cthulhu/internal/input"
|
||||
"git.stormux.org/storm/screenreader-common/datetime"
|
||||
)
|
||||
|
||||
// Validate checks the complete configuration without touching the filesystem.
|
||||
@@ -169,11 +169,12 @@ func validate(settings Settings) error {
|
||||
return errors.New("a separate echo synthesizer requires Speech Dispatcher; disable custom echo voice for hardware speech")
|
||||
}
|
||||
switch settings.SpeechOutputModule {
|
||||
case "litetalk", "doubletalk", "tripletalk", "dectalk":
|
||||
case "litetalk", "doubletalk", "tripletalk", "dectalk", "dectalk-usb":
|
||||
default:
|
||||
return errors.New("choose a hardware speech synthesizer")
|
||||
}
|
||||
if !filepath.IsAbs(settings.HardwareSpeechDevice) {
|
||||
// DECtalk USB finds its device itself; serial synthesizers need a path.
|
||||
if settings.SpeechOutputModule != "dectalk-usb" && !filepath.IsAbs(settings.HardwareSpeechDevice) {
|
||||
return errors.New("choose an explicit serial device path for hardware speech")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,13 +4,12 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.stormux.org/storm/screenreader-common/voiceprofiles"
|
||||
"math"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func Primary_voice(settings Settings) voiceprofiles.Profile {
|
||||
func PrimaryVoice(settings Settings) voiceprofiles.Profile {
|
||||
p := voiceprofiles.Profile{Driver: "speech-dispatcher", Module: settings.SpeechOutputModule, Volume: 100}
|
||||
number := func(v *float64, fallback int) int {
|
||||
if v != nil {
|
||||
@@ -38,7 +37,7 @@ func Primary_voice(settings Settings) voiceprofiles.Profile {
|
||||
return p
|
||||
}
|
||||
|
||||
func Apply_primary_voice(settings Settings, p voiceprofiles.Profile) (Settings, error) {
|
||||
func ApplyPrimaryVoice(settings Settings, p voiceprofiles.Profile) (Settings, error) {
|
||||
if err := p.Normalize().Validate(); err != nil {
|
||||
return settings, err
|
||||
}
|
||||
@@ -51,13 +50,14 @@ func Apply_primary_voice(settings Settings, p voiceprofiles.Profile) (Settings,
|
||||
voice.AveragePitch = &pitch
|
||||
voice.Gain = &volume
|
||||
if p.Driver != "speech-dispatcher" {
|
||||
if p.Driver == "dectalk-usb" {
|
||||
return settings, fmt.Errorf("DECtalk USB is not supported by Cthulhu")
|
||||
}
|
||||
next.SpeechServerFactory = "hardwarefactory"
|
||||
next.SpeechOutputModule = p.Driver
|
||||
next.HardwareSpeechDevice = p.Device
|
||||
next.HardwareSpeechBaudRate = p.BaudRate
|
||||
// DECtalk USB has no device path or baud rate; keep the saved serial
|
||||
// settings for when a serial synthesizer is chosen again.
|
||||
if p.Driver != "dectalk-usb" {
|
||||
next.HardwareSpeechDevice = p.Device
|
||||
next.HardwareSpeechBaudRate = p.BaudRate
|
||||
}
|
||||
} else if p.Voice != "" || p.Language != "" {
|
||||
voice.Family = &VoiceFamily{Name: p.Voice, Lang: p.Language, Variant: p.Variant}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ func TestVoiceProfilesPersistencePrimaryScopeAndApplicationSave(t *testing.T) {
|
||||
if err != nil || !reflect.DeepEqual(loaded.VoiceProfiles, settings.VoiceProfiles) {
|
||||
t.Fatal(loaded.VoiceProfiles, err)
|
||||
}
|
||||
loaded, err = Apply_primary_voice(loaded, p)
|
||||
loaded, err = ApplyPrimaryVoice(loaded, p)
|
||||
if err != nil || loaded.DefaultVoice.Family.Name != "Reader" || *loaded.DefaultVoice.Rate != 30 {
|
||||
t.Fatal(loaded, err)
|
||||
}
|
||||
@@ -58,3 +58,25 @@ func TestVoiceProfilesPersistencePrimaryScopeAndApplicationSave(t *testing.T) {
|
||||
t.Fatal(global.VoiceProfiles, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDECtalkUSBProfileNeedsNoSerialDevice(t *testing.T) {
|
||||
settings := DefaultSettings()
|
||||
settings.UseCustomEchoSpeechServer = false
|
||||
p := voiceprofiles.Profile{Name: "Desk", Driver: "dectalk-usb", Rate: 10}
|
||||
next, err := ApplyPrimaryVoice(settings, p)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if next.SpeechServerFactory != "hardwarefactory" || next.SpeechOutputModule != "dectalk-usb" {
|
||||
t.Fatal(next.SpeechServerFactory, next.SpeechOutputModule)
|
||||
}
|
||||
if got := PrimaryVoice(next); got.Driver != "dectalk-usb" {
|
||||
t.Fatal("round trip", got)
|
||||
}
|
||||
serial := next
|
||||
serial.SpeechOutputModule = "dectalk"
|
||||
serial.HardwareSpeechDevice = ""
|
||||
if err := Validate(serial); err == nil {
|
||||
t.Fatal("serial DECtalk accepted without a device path")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user