Speech settings updated, no large decimals for settings. Also changing with quick settings keys now applies across window changes.
This commit is contained in:
1 parent
7ae2801e53
commit
6ee0454fbe
17 files changed
+406
-15
No files matched your search
@@ -11,6 +11,7 @@ package preferences
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"math"
|
||||
"sort"
|
||||
"strings"
|
||||
"unsafe"
|
||||
@@ -142,7 +143,7 @@ func (session *uiSession) getEchoVoice() (config.Voice, string) {
|
||||
{"echoRateScale", &voice.Rate}, {"echoPitchScale", &voice.AveragePitch}, {"echoVolumeScale", &voice.Gain},
|
||||
} {
|
||||
id := C.CString(item.id)
|
||||
value := float64(C.prefs_number_value(id))
|
||||
value := math.Round(float64(C.prefs_number_value(id))*10) / 10
|
||||
C.free(unsafe.Pointer(id))
|
||||
*item.target = &value
|
||||
}
|
||||
|
||||
@@ -5,12 +5,45 @@
|
||||
package preferences
|
||||
|
||||
import (
|
||||
"math"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"git.stormux.org/storm/cthulhu/internal/config"
|
||||
)
|
||||
|
||||
func TestSpeechValuesMergeRoundsNumbersAndPreservesInheritance(t *testing.T) {
|
||||
settings := config.DefaultSettings()
|
||||
values := FromSettings(settings)
|
||||
rate, pitch, gain := 61.29999999999999, 4.499999999999998, 4.999999999999999
|
||||
values.Rate, values.Pitch, values.Volume = &rate, &pitch, &gain
|
||||
values.UppercaseVoice.AveragePitch = &pitch
|
||||
values.HyperlinkVoice.Rate = &rate
|
||||
values.SystemVoice.Gain = &gain
|
||||
values.EchoVoice = config.Voice{Rate: &rate, AveragePitch: &pitch, Gain: &gain}
|
||||
merged, err := values.Merge(settings)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if *merged.DefaultVoice.Rate != 61.3 || *merged.DefaultVoice.AveragePitch != 4.5 || *merged.DefaultVoice.Gain != 5 ||
|
||||
*merged.UppercaseVoice.AveragePitch != 4.5 || *merged.HyperlinkVoice.Rate != 61.3 || *merged.SystemVoice.Gain != 5 ||
|
||||
*merged.EchoVoice.Rate != 61.3 || *merged.EchoVoice.AveragePitch != 4.5 || *merged.EchoVoice.Gain != 5 {
|
||||
t.Fatal("speech values retained floating-point noise")
|
||||
}
|
||||
if merged.UppercaseVoice.Rate != nil || merged.HyperlinkVoice.Gain != nil || merged.SystemVoice.AveragePitch != nil {
|
||||
t.Fatal("rounding turned inheritance into explicit settings")
|
||||
}
|
||||
if pitch != 4.499999999999998 {
|
||||
t.Fatal("merging mutated caller's values")
|
||||
}
|
||||
for _, invalid := range []float64{9.01, -0.01, math.NaN(), math.Inf(1)} {
|
||||
values.Pitch = &invalid
|
||||
if _, err := values.Merge(settings); err == nil {
|
||||
t.Fatalf("rounding hid invalid pitch %g", invalid)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSoundValuesDefaultAndMerge(t *testing.T) {
|
||||
settings := config.DefaultSettings()
|
||||
values := FromSettings(settings)
|
||||
|
||||
@@ -419,7 +419,7 @@ func (session *uiSession) read_voice_editor() (config.Voice, error) {
|
||||
} {
|
||||
id := C.CString(item.id)
|
||||
edited := C.prefs_number_edited(id) != 0
|
||||
value := float64(C.prefs_number_value(id))
|
||||
value := math.Round(float64(C.prefs_number_value(id))*10) / 10
|
||||
C.free(unsafe.Pointer(id))
|
||||
if !edited {
|
||||
continue
|
||||
|
||||
@@ -139,5 +139,8 @@ func (values Values) Merge(settings config.Settings) (config.Settings, error) {
|
||||
settings.SayCapForCapitals = values.SayCapForCapitals
|
||||
settings.Reading = values.Reading
|
||||
settings.SpeakDescription = values.SpeakDescription
|
||||
return settings, config.Validate(settings)
|
||||
if err := config.Validate(settings); err != nil {
|
||||
return settings, err
|
||||
}
|
||||
return config.RoundSpeechValues(settings), nil
|
||||
}
|
||||
Reference in new issue
Block a user