Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

project-s: 初期化とシンガー・楽譜を設定するaction/mutationを追加 #988

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 71 additions & 1 deletion src/store/singing.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SingingStoreState, SingingStoreTypes } from "./type";
import { Score, SingingStoreState, SingingStoreTypes } from "./type";
import { createPartialStore } from "./vuex";

export const singingStoreState: SingingStoreState = {
Expand All @@ -21,4 +21,74 @@ export const singingStore = createPartialStore<SingingStoreTypes>({
});
},
},

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で良いでしょうか?
sigprogramming marked this conversation as resolved.
Show resolved Hide resolved
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 });
},
},
});
14 changes: 14 additions & 0 deletions src/store/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Score>;
};

SET_SCORE: {
mutation: { score: Score };
action(payload: { score: Score }): void;
};
};

/*
Expand Down
24 changes: 21 additions & 3 deletions src/views/SingerHome.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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 = [
sigprogramming marked this conversation as resolved.
Show resolved Hide resolved
{ 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;
},
});
Expand Down