Preview voice profile edits and restore parent speech

This commit is contained in:
Storm Dragon committed 2026-11-15 18:29:24 -05:00
1 parent 1b42dde756
commit b21fceb311
7 files changed
+175 -11

No files matched your search

+3
View File
@@ -20,6 +20,9 @@ type uiSession struct {
profileEditor *voiceprofiles.Editor
profileIndex int
profileControls []ui.Control
profileBase Values
profileVoice *voiceprofiles.Profile
profilePreview *Values
extensionPages []ExtensionPage
progressBar config.ProgressBarSettings
wine config.WineSettings
+17 -2
View File
@@ -108,7 +108,13 @@ func Run(ctx context.Context, input io.Reader, output io.Writer) error {
if response.Preview {
previewPending = false
if !response.Accepted {
status(response.Message, true)
if session.profileEditor != nil {
message := C.CString(response.Message)
C.prefs_profile_status(message)
C.free(unsafe.Pointer(message))
} else {
status(response.Message, true)
}
}
continue
}
@@ -145,7 +151,15 @@ func Run(ctx context.Context, input io.Reader, output io.Writer) error {
status(response.Message, !response.Accepted)
case <-ticker.C:
C.prefs_iterate()
if session.profile_tick() {
profileActive := session.profile_tick()
if session.profilePreview != nil && !previewPending && !busy {
if err := encoder.Encode(Request{Values: *session.profilePreview, Preview: true}); err != nil {
return err
}
session.profilePreview = nil
previewPending = true
}
if profileActive {
continue
}
session.refreshEchoVoices()
@@ -224,6 +238,7 @@ func Run(ctx context.Context, input io.Reader, output io.Writer) error {
}
busy = true
previewDirty = false
session.profilePreview = nil
C.prefs_busy(1, boolean(canSave))
continue
}
+37
View File
@@ -53,6 +53,8 @@ func (session *uiSession) profile_action(action int) {
}
session.activeVoiceType = 0
session.setSpeechVoice(FromSettings(next))
preview := profile_preview_values(values, next)
session.profilePreview = &preview
return
}
values, err := session.getValues()
@@ -84,6 +86,8 @@ func (session *uiSession) profile_action(action int) {
}
}
session.profileEditor = voiceprofiles.New_editor(p, drivers, session.catalog)
session.profileBase = values
session.profileVoice = nil
session.profileIndex = index
session.profileControls = session.profileEditor.Form().Tabs[0].Controls
C.prefs_profile_begin()
@@ -170,6 +174,7 @@ func (session *uiSession) profile_tick() bool {
}
}
}
session.preview_profile(values)
response := int(C.prefs_profile_response())
if response == 0 {
return true
@@ -191,10 +196,42 @@ func (session *uiSession) profile_tick() bool {
}
C.prefs_profile_close()
session.profileEditor = nil
session.profileVoice = nil
// Both Save and Cancel return to the unchanged parent speech draft.
preview := session.profileBase
session.profilePreview = &preview
session.populate_profiles(max(0, session.profileIndex))
return true
}
func (session *uiSession) preview_profile(values map[string]ui.Control) {
profile, err := session.profileEditor.Read(values)
if err != nil || session.profileVoice != nil && voiceprofiles.Same_voice(*session.profileVoice, profile) {
return
}
next, err := config.Apply_primary_voice(primary_settings(session.profileBase), profile)
if err != nil {
return // Incomplete or unsupported edits retain the working voice.
}
preview := profile_preview_values(session.profileBase, next)
session.profileVoice = &profile
session.profilePreview = &preview
}
// Profile previews change only primary speech. The parent form and its other
// voice drafts remain intact and are restored when the child editor closes.
func profile_preview_values(base Values, settings config.Settings) Values {
voice := FromSettings(settings)
base.Rate, base.Pitch, base.Volume = voice.Rate, voice.Pitch, voice.Volume
base.SpeechServerFactory = voice.SpeechServerFactory
base.SpeechOutputModule = voice.SpeechOutputModule
base.HardwareSpeechDevice = voice.HardwareSpeechDevice
base.HardwareSpeechBaudRate = voice.HardwareSpeechBaudRate
base.SpeechVoiceFamily = voice.SpeechVoiceFamily
base.VoiceType = "default"
return base
}
func primary_settings(values Values) config.Settings {
settings := config.DefaultSettings()
settings.SpeechServerFactory = values.SpeechServerFactory