From 0b9c64c7c9c6ef13c29850ca3455e2cadbd2d779 Mon Sep 17 00:00:00 2001 From: Hiroshiba Date: Mon, 20 Feb 2023 02:16:48 +0900 Subject: [PATCH 1/4] =?UTF-8?q?WIP:=20PresetKey=E3=81=AB=E5=9E=8B=E3=82=92?= =?UTF-8?q?=E4=BB=98=E3=81=91=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/audio.ts | 15 ++++++++------- src/store/preset.ts | 19 +++++++++++-------- src/store/type.ts | 32 +++++++++++++++++--------------- src/type/preload.ts | 8 ++++++-- src/views/EditorHome.vue | 2 +- 5 files changed, 43 insertions(+), 33 deletions(-) diff --git a/src/store/audio.ts b/src/store/audio.ts index 9af3cf9227..92ea1ae480 100644 --- a/src/store/audio.ts +++ b/src/store/audio.ts @@ -21,6 +21,7 @@ import { EngineId, MoraDataType, MorphingInfo, + PresetKey, SpeakerId, StyleInfo, Voice, @@ -478,7 +479,7 @@ export const audioStore = createPartialStore({ payload: { text?: string; voice?: Voice; - presetKey?: string; + presetKey?: PresetKey; baseAudioItem?: AudioItem; } ) { @@ -1783,7 +1784,7 @@ export const audioStore = createPartialStore({ { audioKey, presetKey, - }: { audioKey: AudioKey; presetKey: string | undefined } + }: { audioKey: AudioKey; presetKey: PresetKey | undefined } ) { if (presetKey === undefined) { delete state.audioItems[audioKey].presetKey; @@ -2627,7 +2628,7 @@ export const audioCommandStore = transformCommandStore( { audioKey, presetKey, - }: { audioKey: AudioKey; presetKey: string | undefined } + }: { audioKey: AudioKey; presetKey: PresetKey | undefined } ) { audioStore.mutations.SET_AUDIO_PRESET_KEY(draft, { audioKey, @@ -2640,7 +2641,7 @@ export const audioCommandStore = transformCommandStore( { audioKey, presetKey, - }: { audioKey: AudioKey; presetKey: string | undefined } + }: { audioKey: AudioKey; presetKey: PresetKey | undefined } ) { commit("COMMAND_SET_AUDIO_PRESET", { audioKey, presetKey }); }, @@ -2656,7 +2657,7 @@ export const audioCommandStore = transformCommandStore( }, COMMAND_FULLY_APPLY_AUDIO_PRESET: { - mutation(draft, { presetKey }: { presetKey: string }) { + mutation(draft, { presetKey }: { presetKey: PresetKey }) { const targetAudioKeys = draft.audioKeys.filter( (audioKey) => draft.audioItems[audioKey].presetKey === presetKey ); @@ -2664,7 +2665,7 @@ export const audioCommandStore = transformCommandStore( audioStore.mutations.APPLY_AUDIO_PRESET(draft, { audioKey }); } }, - action({ commit }, payload: { presetKey: string }) { + action({ commit }, payload: { presetKey: PresetKey }) { commit("COMMAND_FULLY_APPLY_AUDIO_PRESET", payload); }, }, @@ -2775,7 +2776,7 @@ export const audioCommandStore = transformCommandStore( audioItem: AudioItem; }[] = []; let baseAudioItem: AudioItem | undefined = undefined; - let basePresetKey: string | undefined = undefined; + let basePresetKey: PresetKey | undefined = undefined; if (state.inheritAudioInfo && state._activeAudioKey) { baseAudioItem = state.audioItems[state._activeAudioKey]; basePresetKey = baseAudioItem.presetKey; diff --git a/src/store/preset.ts b/src/store/preset.ts index 1b6f854d53..7df7f97f57 100644 --- a/src/store/preset.ts +++ b/src/store/preset.ts @@ -1,5 +1,5 @@ import { PresetStoreState, PresetStoreTypes } from "@/store/type"; -import { Preset } from "@/type/preload"; +import { Preset, PresetKey } from "@/type/preload"; import { createPartialStore } from "./vuex"; import { v4 as uuidv4 } from "uuid"; @@ -11,13 +11,16 @@ export const presetStoreState: PresetStoreState = { export const presetStore = createPartialStore({ SET_PRESET_ITEMS: { - mutation(state, { presetItems }: { presetItems: Record }) { + mutation( + state, + { presetItems }: { presetItems: Record } + ) { state.presetItems = presetItems; }, }, SET_PRESET_KEYS: { - mutation(state, { presetKeys }: { presetKeys: string[] }) { + mutation(state, { presetKeys }: { presetKeys: PresetKey[] }) { state.presetKeys = presetKeys; }, }, @@ -41,7 +44,7 @@ export const presetStore = createPartialStore({ }, SAVE_PRESET_ORDER: { - action({ state, dispatch }, { presetKeys }: { presetKeys: string[] }) { + action({ state, dispatch }, { presetKeys }: { presetKeys: PresetKey[] }) { return dispatch("SAVE_PRESET_CONFIG", { presetItems: state.presetItems, presetKeys, @@ -55,7 +58,7 @@ export const presetStore = createPartialStore({ { presetItems, presetKeys, - }: { presetItems: Record; presetKeys: string[] } + }: { presetItems: Record; presetKeys: PresetKey[] } ) { const result = await window.electron.setSetting("presets", { items: JSON.parse(JSON.stringify(presetItems)), @@ -68,7 +71,7 @@ export const presetStore = createPartialStore({ ADD_PRESET: { async action(context, { presetData }: { presetData: Preset }) { - const newKey = uuidv4(); + const newKey = PresetKey(uuidv4()); const newPresetItems = { ...context.state.presetItems, [newKey]: presetData, @@ -87,7 +90,7 @@ export const presetStore = createPartialStore({ UPDATE_PRESET: { async action( context, - { presetKey, presetData }: { presetData: Preset; presetKey: string } + { presetKey, presetData }: { presetData: Preset; presetKey: PresetKey } ) { const newPresetItems = { ...context.state.presetItems, @@ -105,7 +108,7 @@ export const presetStore = createPartialStore({ }, DELETE_PRESET: { - async action(context, { presetKey }: { presetKey: string }) { + async action(context, { presetKey }: { presetKey: PresetKey }) { const newPresetKeys = context.state.presetKeys.filter( (key) => key != presetKey ); diff --git a/src/store/type.ts b/src/store/type.ts index aafe4c75f2..f74b0df516 100644 --- a/src/store/type.ts +++ b/src/store/type.ts @@ -46,6 +46,8 @@ import { EngineId, SpeakerId, AudioKey, + PresetKey, + presetKeySchema, } from "@/type/preload"; import { IEngineConnectorFactory } from "@/infrastructures/EngineConnector"; import { QVueGlobals } from "quasar"; @@ -61,7 +63,7 @@ export type AudioItem = { text: string; voice: Voice; query?: EditorAudioQuery; - presetKey?: string; + presetKey?: PresetKey; morphingInfo?: MorphingInfo; }; @@ -199,7 +201,7 @@ export type AudioStoreTypes = { action(payload: { text?: string; voice?: Voice; - presetKey?: string; + presetKey?: PresetKey; baseAudioItem?: AudioItem; }): Promise; }; @@ -446,7 +448,7 @@ export type AudioStoreTypes = { SET_AUDIO_PRESET_KEY: { mutation: { audioKey: AudioKey; - presetKey: string | undefined; + presetKey: PresetKey | undefined; }; }; @@ -633,11 +635,11 @@ export type AudioCommandStoreTypes = { COMMAND_SET_AUDIO_PRESET: { mutation: { audioKey: AudioKey; - presetKey: string | undefined; + presetKey: PresetKey | undefined; }; action(payload: { audioKey: AudioKey; - presetKey: string | undefined; + presetKey: PresetKey | undefined; }): void; }; @@ -647,8 +649,8 @@ export type AudioCommandStoreTypes = { }; COMMAND_FULLY_APPLY_AUDIO_PRESET: { - mutation: { presetKey: string }; - action(payload: { presetKey: string }): void; + mutation: { presetKey: PresetKey }; + action(payload: { presetKey: PresetKey }): void; }; COMMAND_IMPORT_FROM_FILE: { @@ -1231,41 +1233,41 @@ export type UiStoreTypes = { */ export type PresetStoreState = { - presetKeys: string[]; - presetItems: Record; + presetKeys: PresetKey[]; + presetItems: Record; }; export type PresetStoreTypes = { SET_PRESET_ITEMS: { mutation: { - presetItems: Record; + presetItems: Record; }; }; SET_PRESET_KEYS: { mutation: { - presetKeys: string[]; + presetKeys: PresetKey[]; }; }; HYDRATE_PRESET_STORE: { action(): void; }; SAVE_PRESET_ORDER: { - action(payload: { presetKeys: string[] }): void; + action(payload: { presetKeys: PresetKey[] }): void; }; SAVE_PRESET_CONFIG: { action(payload: { presetItems: Record; - presetKeys: string[]; + presetKeys: PresetKey[]; }): void; }; ADD_PRESET: { action(payload: { presetData: Preset }): Promise; }; UPDATE_PRESET: { - action(payload: { presetData: Preset; presetKey: string }): void; + action(payload: { presetData: Preset; presetKey: PresetKey }): void; }; DELETE_PRESET: { - action(payload: { presetKey: string }): void; + action(payload: { presetKey: PresetKey }): void; }; }; diff --git a/src/type/preload.ts b/src/type/preload.ts index 97b135951c..a4c2774f24 100644 --- a/src/type/preload.ts +++ b/src/type/preload.ts @@ -16,6 +16,10 @@ export const audioKeySchema = z.string().uuid().brand<"AudioKey">(); export type AudioKey = z.infer; export const AudioKey = (id: string): AudioKey => audioKeySchema.parse(id); +export const presetKeySchema = z.string().uuid().brand<"PresetKey">(); +export type PresetKey = z.infer; +export const PresetKey = (id: string): PresetKey => presetKeySchema.parse(id); + // ホットキーを追加したときは設定のマイグレーションが必要 export const defaultHotkeySettings: HotkeySetting[] = [ { @@ -517,7 +521,7 @@ export const electronStoreSchema = z .object({ items: z .record( - z.string().uuid(), + presetKeySchema, z .object({ name: z.string(), @@ -540,7 +544,7 @@ export const electronStoreSchema = z .passthrough() ) .default({}), - keys: z.string().uuid().array().default([]), + keys: presetKeySchema.array().default([]), }) .passthrough() .default({}), diff --git a/src/views/EditorHome.vue b/src/views/EditorHome.vue index a0f13d013e..f9427cacee 100644 --- a/src/views/EditorHome.vue +++ b/src/views/EditorHome.vue @@ -378,7 +378,7 @@ const activeAudioKey = computed( const addAudioItem = async () => { const prevAudioKey = activeAudioKey.value; let voice: Voice | undefined = undefined; - let presetKey: string | undefined = undefined; + let presetKey: PresetKey | undefined = undefined; if (prevAudioKey !== undefined) { voice = store.state.audioItems[prevAudioKey].voice; presetKey = store.state.audioItems[prevAudioKey].presetKey; From c95b24caa51924c2b2a692eaad7ef59ecc70cbde Mon Sep 17 00:00:00 2001 From: Hiroshiba Date: Fri, 24 Feb 2023 02:35:35 +0900 Subject: [PATCH 2/4] =?UTF-8?q?as=E4=BB=98=E3=81=91=E3=81=9F=E3=82=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/AudioInfo.vue | 17 ++++++----------- src/components/PresetManageDialog.vue | 8 +++++--- src/store/preset.ts | 8 ++++++-- src/store/type.ts | 2 +- src/views/EditorHome.vue | 1 + 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/components/AudioInfo.vue b/src/components/AudioInfo.vue index 62b44c5e64..6a91c96b73 100644 --- a/src/components/AudioInfo.vue +++ b/src/components/AudioInfo.vue @@ -491,6 +491,7 @@ import { CharacterInfo, MorphingInfo, Preset, + PresetKey, Voice, } from "@/type/preload"; import { previewSliderHelper } from "@/helpers/previewSliderHelper"; @@ -821,24 +822,18 @@ const isChangedPreset = computed(() => { type PresetSelectModelType = { label: string; - key: string | undefined; + key: PresetKey | undefined; }; // プリセットの変更 -const changePreset = ( - presetOrPresetKey: PresetSelectModelType | string -): void => { - const presetKey = - typeof presetOrPresetKey === "string" - ? presetOrPresetKey - : presetOrPresetKey.key; +const changePreset = (presetKey: PresetKey | undefined): void => { store.dispatch("COMMAND_SET_AUDIO_PRESET", { audioKey: props.activeAudioKey, presetKey, }); }; -const presetList = computed<{ label: string; key: string }[]>(() => +const presetList = computed<{ label: string; key: PresetKey }[]>(() => presetKeys.value .filter((key) => presetItems.value[key] != undefined) .map((key) => ({ @@ -875,7 +870,7 @@ const presetSelectModel = computed({ }; }, set: (newVal) => { - changePreset(newVal); + changePreset(newVal.key); }, }); @@ -895,7 +890,7 @@ const setPresetByScroll = (event: WheelEvent) => { if (selectablePresetList.value[newIndex] === undefined) return; - changePreset(selectablePresetList.value[newIndex]); + changePreset(selectablePresetList.value[newIndex].key); }; // プリセットの登録・再登録 diff --git a/src/components/PresetManageDialog.vue b/src/components/PresetManageDialog.vue index 32e88d7ee9..d8f4dcef66 100644 --- a/src/components/PresetManageDialog.vue +++ b/src/components/PresetManageDialog.vue @@ -45,7 +45,7 @@ import { useQuasar } from "quasar"; import { useStore } from "@/store"; import draggable from "vuedraggable"; -import { Preset } from "@/type/preload"; +import { Preset, PresetKey } from "@/type/preload"; export default defineComponent({ name: "PresetManageDialog", @@ -92,7 +92,9 @@ export default defineComponent({ : presetList.value ); - const reorderPreset = (featurePresetList: (Preset & { key: string })[]) => { + const reorderPreset = ( + featurePresetList: (Preset & { key: PresetKey })[] + ) => { const newPresetKeys = featurePresetList.map((item) => item.key); previewPresetKeys.value = newPresetKeys; isPreview.value = true; @@ -103,7 +105,7 @@ export default defineComponent({ .finally(() => (isPreview.value = false)); }; - const deletePreset = (key: string) => { + const deletePreset = (key: PresetKey) => { $q.dialog({ title: "プリセット削除の確認", message: `プリセット "${presetItems.value[key].name}" を削除してもよろしいですか?`, diff --git a/src/store/preset.ts b/src/store/preset.ts index 7df7f97f57..ad64a004d5 100644 --- a/src/store/preset.ts +++ b/src/store/preset.ts @@ -35,7 +35,8 @@ export const presetStore = createPartialStore({ ) return; commit("SET_PRESET_ITEMS", { - presetItems: presetConfig.items, + // z.BRAND型のRecordはPartialになる仕様なのでasで型を変換 + presetItems: presetConfig.items as Record, }); commit("SET_PRESET_KEYS", { presetKeys: presetConfig.keys, @@ -64,7 +65,10 @@ export const presetStore = createPartialStore({ items: JSON.parse(JSON.stringify(presetItems)), keys: JSON.parse(JSON.stringify(presetKeys)), }); - context.commit("SET_PRESET_ITEMS", { presetItems: result.items }); + context.commit("SET_PRESET_ITEMS", { + // z.BRAND型のRecordはPartialになる仕様なのでasで型を変換 + presetItems: result.items as Record, + }); context.commit("SET_PRESET_KEYS", { presetKeys: result.keys }); }, }, diff --git a/src/store/type.ts b/src/store/type.ts index cea7d31334..16fbd2d25b 100644 --- a/src/store/type.ts +++ b/src/store/type.ts @@ -1262,7 +1262,7 @@ export type PresetStoreTypes = { }): void; }; ADD_PRESET: { - action(payload: { presetData: Preset }): Promise; + action(payload: { presetData: Preset }): Promise; }; UPDATE_PRESET: { action(payload: { presetData: Preset; presetKey: PresetKey }): void; diff --git a/src/views/EditorHome.vue b/src/views/EditorHome.vue index 997ab80832..f063ec60d6 100644 --- a/src/views/EditorHome.vue +++ b/src/views/EditorHome.vue @@ -193,6 +193,7 @@ import { EngineId, HotkeyAction, HotkeyReturnType, + PresetKey, SplitterPosition, Voice, } from "@/type/preload"; From 245bce59094e352fd846af54f52e7e623bbd37c3 Mon Sep 17 00:00:00 2001 From: Hiroshiba Date: Fri, 24 Feb 2023 07:30:44 +0900 Subject: [PATCH 3/4] n --- src/store/type.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/store/type.ts b/src/store/type.ts index 16fbd2d25b..21c56ff3b3 100644 --- a/src/store/type.ts +++ b/src/store/type.ts @@ -48,7 +48,6 @@ import { StyleId, AudioKey, PresetKey, - presetKeySchema, } from "@/type/preload"; import { IEngineConnectorFactory } from "@/infrastructures/EngineConnector"; import { QVueGlobals } from "quasar"; From f3dc6b4ece211c0817f822773e31dff46f65ff00 Mon Sep 17 00:00:00 2001 From: Hiroshiba Date: Wed, 1 Mar 2023 18:43:38 +0900 Subject: [PATCH 4/4] =?UTF-8?q?https://github.com/VOICEVOX/voicevox/pull/1?= =?UTF-8?q?217#issuecomment-1449659117=20=E3=82=92=E5=8F=8D=E6=98=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/preset.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/store/preset.ts b/src/store/preset.ts index d3fcd54255..d62203447b 100644 --- a/src/store/preset.ts +++ b/src/store/preset.ts @@ -35,6 +35,7 @@ export const presetStore = createPartialStore({ return; commit("SET_PRESET_ITEMS", { // z.BRAND型のRecordはPartialになる仕様なのでasで型を変換 + // TODO: 将来的にzodのバージョンを上げてasを消す https://github.com/colinhacks/zod/pull/2097 presetItems: presetConfig.items as Record, }); commit("SET_PRESET_KEYS", { @@ -66,6 +67,7 @@ export const presetStore = createPartialStore({ }); context.commit("SET_PRESET_ITEMS", { // z.BRAND型のRecordはPartialになる仕様なのでasで型を変換 + // TODO: 将来的にzodのバージョンを上げてasを消す https://github.com/colinhacks/zod/pull/2097 presetItems: result.items as Record, }); context.commit("SET_PRESET_KEYS", { presetKeys: result.keys });