From b2b240084f9e00a9496e793d38be1c3c99c2c9e7 Mon Sep 17 00:00:00 2001 From: Sig Date: Tue, 18 Oct 2022 22:49:21 +0900 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E6=9C=9F=E5=8C=96=E3=81=A8=E3=82=B7?= =?UTF-8?q?=E3=83=B3=E3=82=AC=E3=83=BC=E3=83=BB=E6=A5=BD=E8=AD=9C=E3=82=92?= =?UTF-8?q?=E8=A8=AD=E5=AE=9A=E3=81=99=E3=82=8Baction/mutation=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/singing.ts | 72 +++++++++++++++++++++++++++++++++++++++- src/store/type.ts | 14 ++++++++ src/views/SingerHome.vue | 24 ++++++++++++-- 3 files changed, 106 insertions(+), 4 deletions(-) diff --git a/src/store/singing.ts b/src/store/singing.ts index e422bcd370..dea9014254 100644 --- a/src/store/singing.ts +++ b/src/store/singing.ts @@ -1,4 +1,4 @@ -import { SingingStoreState, SingingStoreTypes } from "./type"; +import { Score, SingingStoreState, SingingStoreTypes } from "./type"; import { createPartialStore } from "./vuex"; export const singingStoreState: SingingStoreState = { @@ -21,4 +21,74 @@ export const singingStore = createPartialStore({ }); }, }, + + SET_SINGER: { + mutation( + state, + { engineId, styleId }: { engineId: string; styleId: number } + ) { + state.engineId = engineId; + state.styleId = styleId; + }, + async action( + { state, getters, dispatch, commit }, + payload: { engineId?: string; styleId?: number } + ) { + if (state.defaultStyleIds == undefined) + throw new Error("state.defaultStyleIds == undefined"); + if (getters.USER_ORDERED_CHARACTER_INFOS == undefined) + throw new Error("state.characterInfos == undefined"); + const userOrderedCharacterInfos = getters.USER_ORDERED_CHARACTER_INFOS; + + const engineId = payload.engineId ?? state.engineIds[0]; + + // FIXME: engineIdも含めて探査する + const styleId = + payload.styleId ?? + state.defaultStyleIds[ + state.defaultStyleIds.findIndex( + (x) => + x.speakerUuid === userOrderedCharacterInfos[0].metas.speakerUuid // FIXME: defaultStyleIds内にspeakerUuidがない場合がある + ) + ].defaultStyleId; + + try { + // 指定されたstyleIdに対して、エンジン側の初期化を行う + const isInitialized = await dispatch("IS_INITIALIZED_ENGINE_SPEAKER", { + engineId, + styleId, + }); + if (!isInitialized) { + await dispatch("INITIALIZE_ENGINE_SPEAKER", { + engineId, + styleId, + }); + } + } finally { + commit("SET_SINGER", { engineId, styleId }); + } + }, + }, + + GET_DEFAULT_SCORE: { + async action() { + const score: Score = { + resolution: 480, + // テンポの初期値は120で良いでしょうか? + tempos: [{ position: 0, tempo: 120 }], + timeSignatures: [{ position: 0, beats: 4, beatType: 4 }], + notes: [], + }; + return score; + }, + }, + + SET_SCORE: { + mutation(state, { score }: { score: Score }) { + state.score = score; + }, + async action({ commit }, { score }: { score: Score }) { + commit("SET_SCORE", { score }); + }, + }, }); diff --git a/src/store/type.ts b/src/store/type.ts index 15f9f373bc..53d2fa1b48 100644 --- a/src/store/type.ts +++ b/src/store/type.ts @@ -708,6 +708,20 @@ export type SingingStoreTypes = { mutation: { isShowSinger: boolean }; action(payload: { isShowSinger: boolean }): void; }; + + SET_SINGER: { + mutation: { engineId: string; styleId: number }; + action(payload: { engineId?: string; styleId?: number }): void; + }; + + GET_DEFAULT_SCORE: { + action(): Promise; + }; + + SET_SCORE: { + mutation: { score: Score }; + action(payload: { score: Score }): void; + }; }; /* diff --git a/src/views/SingerHome.vue b/src/views/SingerHome.vue index bb8b99ed19..e199e7dd8f 100644 --- a/src/views/SingerHome.vue +++ b/src/views/SingerHome.vue @@ -16,11 +16,11 @@ import { //computed, defineComponent, //onBeforeUpdate, - //onMounted, + onMounted, //ref, //watch, } from "vue"; -// import { useStore } from "@/store"; +import { useStore } from "@/store"; // import { QResizeObserver, useQuasar } from "quasar"; // import path from "path"; @@ -43,8 +43,26 @@ export default defineComponent({ }, setup() { - //const store = useStore(); + const store = useStore(); //const $q = useQuasar(); + + // 歌声合成エディターの初期化 + onMounted(async () => { + await store.dispatch("SET_SINGER", {}); + + const score = await store.dispatch("GET_DEFAULT_SCORE"); + + // 実装時の確認用です TODO: 必要なくなったら削除 + score.notes = [ + { position: 0, duration: 480, midi: 60, lyric: "ら" }, + { position: 480, duration: 480, midi: 62, lyric: "ら" }, + { position: 960, duration: 480, midi: 64, lyric: "ら" }, + { position: 1440, duration: 480, midi: 65, lyric: "ら" }, + { position: 1920, duration: 1920, midi: 67, lyric: "ら" }, + ]; + + await store.dispatch("SET_SCORE", { score }); + }); return null; }, });