Skip to content

Commit

Permalink
トーク画面でハミング・歌のキャラクター・スタイルが表示されないように修正 (#1779)
Browse files Browse the repository at this point in the history
* improve USER_ORDERED_CHARACTER_INFOS getter

* リファクタリング

---------

Co-authored-by: Hiroshiba <[email protected]>
  • Loading branch information
y-chan and Hiroshiba authored Jan 28, 2024
1 parent a164427 commit c50e73b
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 51 deletions.
6 changes: 4 additions & 2 deletions src/components/DictionaryManageDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,13 @@ const surface = ref("");
const yomi = ref("");
const voiceComputed = computed(() => {
if (store.getters.USER_ORDERED_CHARACTER_INFOS == undefined)
const userOrderedCharacterInfos =
store.getters.USER_ORDERED_CHARACTER_INFOS("talk");
if (userOrderedCharacterInfos == undefined)
throw new Error("assert USER_ORDERED_CHARACTER_INFOS");
if (store.state.engineIds.length === 0)
throw new Error("assert engineId.length > 0");
const characterInfo = store.getters.USER_ORDERED_CHARACTER_INFOS[0].metas;
const characterInfo = userOrderedCharacterInfos[0].metas;
const speakerId = characterInfo.speakerUuid;
const { engineId, styleId } = characterInfo.styles[0];
return { engineId, speakerId, styleId };
Expand Down
25 changes: 3 additions & 22 deletions src/components/Sing/CharacterMenuButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@
>
<q-list>
<q-item
v-for="(style, styleIndex) in getSingingStyles(
characterInfo
)"
v-for="(style, styleIndex) in characterInfo.metas.styles"
:key="styleIndex"
v-close-popup
clickable
Expand Down Expand Up @@ -141,7 +139,7 @@ import { defineComponent, computed, ref } from "vue";
import { debounce } from "quasar";
import { useStore } from "@/store";
import { base64ImageToUri } from "@/helpers/imageHelper";
import { CharacterInfo, SpeakerId, StyleId, StyleInfo } from "@/type/preload";
import { SpeakerId, StyleId } from "@/type/preload";
import { getStyleDescription } from "@/sing/viewHelper";
export default defineComponent({
Expand All @@ -150,18 +148,8 @@ export default defineComponent({
setup() {
const store = useStore();
const isSingingStyle = (styleInfo: StyleInfo) => {
return (
styleInfo.styleType === "humming" ||
styleInfo.styleType === "sing_teacher"
);
};
const userOrderedCharacterInfos = computed(() => {
return store.getters.USER_ORDERED_CHARACTER_INFOS?.filter(
(characterInfo) =>
characterInfo.metas.styles.some((value) => isSingingStyle(value))
);
return store.getters.USER_ORDERED_CHARACTER_INFOS("singerLike");
});
const subMenuOpenFlags = ref(
Expand Down Expand Up @@ -214,12 +202,6 @@ export default defineComponent({
return defaultStyle;
};
const getSingingStyles = (characterInfo: CharacterInfo) => {
return characterInfo.metas.styles.filter((value) =>
isSingingStyle(value)
);
};
const selectedCharacterInfo = computed(() => {
if (
userOrderedCharacterInfos.value == undefined ||
Expand Down Expand Up @@ -263,7 +245,6 @@ export default defineComponent({
reassignSubMenuOpen,
changeStyleId,
getDefaultStyle,
getSingingStyles,
getStyleDescription,
selectedCharacterInfo,
selectedSpeakerUuid,
Expand Down
4 changes: 2 additions & 2 deletions src/components/Sing/CharacterPortrait.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export default defineComponent({
const store = useStore();
const isShowSinger = computed(() => store.state.isShowSinger);
const userOrderedCharacterInfos = computed(
() => store.getters.USER_ORDERED_CHARACTER_INFOS
const userOrderedCharacterInfos = computed(() =>
store.getters.USER_ORDERED_CHARACTER_INFOS("all")
);
const characterInfo = computed(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Sing/ToolBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ export default defineComponent({
const uiLocked = computed(() => store.getters.UI_LOCKED);
const userOrderedCharacterInfos = computed(
() => store.getters.USER_ORDERED_CHARACTER_INFOS
const userOrderedCharacterInfos = computed(() =>
store.getters.USER_ORDERED_CHARACTER_INFOS("singerLike")
);
const selectedCharacterInfo = computed(() => {
if (!userOrderedCharacterInfos.value || !store.state.singer) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Talk/AudioCell.vue
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ defineExpose({
const store = useStore();
const userOrderedCharacterInfos = computed(() => {
const infos = store.getters.USER_ORDERED_CHARACTER_INFOS;
const infos = store.getters.USER_ORDERED_CHARACTER_INFOS("talk");
if (infos == undefined)
throw new Error("USER_ORDERED_CHARACTER_INFOS == undefined");
return infos;
Expand Down
12 changes: 7 additions & 5 deletions src/components/Talk/AudioInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ watchEffect(() => {
});
const morphingTargetCharacters = computed<CharacterInfo[]>(() => {
const allCharacterInfos = store.getters.USER_ORDERED_CHARACTER_INFOS;
const allCharacterInfos = store.getters.USER_ORDERED_CHARACTER_INFOS("talk");
if (allCharacterInfos == undefined)
throw new Error("USER_ORDERED_CHARACTER_INFOS == undefined");
Expand Down Expand Up @@ -598,10 +598,12 @@ const morphingTargetVoice = computed({
});
const morphingTargetCharacterInfo = computed(() =>
store.getters.USER_ORDERED_CHARACTER_INFOS?.find(
(character) =>
character.metas.speakerUuid === morphingTargetVoice.value?.speakerId
)
store.getters
.USER_ORDERED_CHARACTER_INFOS("talk")
?.find(
(character) =>
character.metas.speakerUuid === morphingTargetVoice.value?.speakerId
)
);
const morphingTargetStyleInfo = computed(() => {
Expand Down
54 changes: 43 additions & 11 deletions src/store/audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,15 +471,42 @@ export const audioStore = createPartialStore<AudioStoreTypes>({
},

USER_ORDERED_CHARACTER_INFOS: {
getter: (state, getters) => {
/**
* ユーザーが並び替えたキャラクターの順番でキャラクター情報を返す。
* `singerLike`の場合はhummingかsingなスタイルのみを返す。
*/
getter: (state, getters) => (styleType: "all" | "singerLike" | "talk") => {
const isSingingStyle = (styleInfo: StyleInfo) => {
return (
styleInfo.styleType === "humming" || styleInfo.styleType === "sing"
);
};

const allCharacterInfos = getters.GET_ALL_CHARACTER_INFOS;
return allCharacterInfos.size !== 0
? [...allCharacterInfos.values()].sort(
if (allCharacterInfos.size === 0) return undefined;
return (
[...allCharacterInfos.values()]
// スタイルタイプでフィルタリング
.map((info) => {
info.metas.styles = info.metas.styles.filter((style) => {
const isSinging = isSingingStyle(style);
return (
styleType === "all" ||
(styleType === "singerLike" && isSinging) ||
(styleType === "talk" && !isSinging)
);
});
return info;
})
// スタイルがなくなったキャラクターを除外
.filter((info) => info.metas.styles.length !== 0)
// ユーザーが並び替えた順番に並び替え
.sort(
(a, b) =>
state.userCharacterOrder.indexOf(a.metas.speakerUuid) -
state.userCharacterOrder.indexOf(b.metas.speakerUuid)
)
: undefined;
);
},
},

Expand Down Expand Up @@ -588,13 +615,14 @@ export const audioStore = createPartialStore<AudioStoreTypes>({
//baseAudioItemのうち、textとstyleIdは別途与えられるので引き継がない
if (state.defaultStyleIds == undefined)
throw new Error("state.defaultStyleIds == undefined");
if (getters.USER_ORDERED_CHARACTER_INFOS == undefined)
const userOrderedCharacterInfos =
getters.USER_ORDERED_CHARACTER_INFOS("talk");
if (userOrderedCharacterInfos == undefined)
throw new Error("state.characterInfos == undefined");

const text = payload.text ?? "";

const defaultSpeakerId =
getters.USER_ORDERED_CHARACTER_INFOS[0].metas.speakerUuid;
const defaultSpeakerId = userOrderedCharacterInfos[0].metas.speakerUuid;
const defaultStyleId = state.defaultStyleIds.find(
(styleId) => styleId.speakerUuid === defaultSpeakerId
);
Expand Down Expand Up @@ -1697,10 +1725,12 @@ export const audioStore = createPartialStore<AudioStoreTypes>({

const characters = new Map<string, string>();

if (!getters.USER_ORDERED_CHARACTER_INFOS)
const userOrderedCharacterInfos =
getters.USER_ORDERED_CHARACTER_INFOS("talk");
if (!userOrderedCharacterInfos)
throw new Error("USER_ORDERED_CHARACTER_INFOS == undefined");

for (const characterInfo of getters.USER_ORDERED_CHARACTER_INFOS) {
for (const characterInfo of userOrderedCharacterInfos) {
const speakerName = characterInfo.metas.speakerName;
for (const style of characterInfo.metas.styles) {
characters.set(
Expand Down Expand Up @@ -2883,12 +2913,14 @@ export const audioCommandStore = transformCommandStore(
baseAudioItem = state.audioItems[state._activeAudioKey];
}

if (!getters.USER_ORDERED_CHARACTER_INFOS)
const userOrderedCharacterInfos =
getters.USER_ORDERED_CHARACTER_INFOS("talk");
if (!userOrderedCharacterInfos)
throw new Error("USER_ORDERED_CHARACTER_INFOS == undefined");
for (const { text, voice } of parseTextFile(
body,
state.defaultStyleIds,
getters.USER_ORDERED_CHARACTER_INFOS,
userOrderedCharacterInfos,
baseAudioItem?.voice
)) {
audioItems.push(
Expand Down
5 changes: 3 additions & 2 deletions src/store/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,10 @@ export const projectStore = createPartialStore<ProjectStoreTypes>({
if (
semver.satisfies(projectAppVersion, "<0.15", semverSatisfiesOptions)
) {
const characterInfos = context.getters.USER_ORDERED_CHARACTER_INFOS;
const characterInfos =
context.getters.USER_ORDERED_CHARACTER_INFOS("talk");
if (characterInfos == undefined)
throw new Error("USER_ORDERED_CHARACTER_INFOS == undefined");
throw new Error("characterInfos == undefined");
for (const audioItemsKey in projectData.audioItems) {
const audioItem = projectData.audioItems[audioItemsKey];
if (audioItem.voice == undefined) {
Expand Down
7 changes: 4 additions & 3 deletions src/store/singing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,10 @@ export const singingStore = createPartialStore<SingingStoreTypes>({
) {
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 userOrderedCharacterInfos =
getters.USER_ORDERED_CHARACTER_INFOS("singerLike");
if (userOrderedCharacterInfos == undefined)
throw new Error("userOrderedCharacterInfos == undefined");

const engineId = singer?.engineId ?? state.engineIds[0];

Expand Down
2 changes: 1 addition & 1 deletion src/store/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export type AudioStoreTypes = {
};

USER_ORDERED_CHARACTER_INFOS: {
getter: CharacterInfo[] | undefined;
getter(type: "all" | "singerLike" | "talk"): CharacterInfo[] | undefined;
};

SETUP_SPEAKER: {
Expand Down

0 comments on commit c50e73b

Please sign in to comment.