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

音域補正用のパラメーターを増やしつつ、開発時のみの機能に #1902

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
53 changes: 31 additions & 22 deletions src/components/Sing/ToolBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
<!-- configs for entire song -->
<div class="sing-configs">
<CharacterMenuButton />
<QInput
type="number"
:model-value="keyShiftInputBuffer"
label="トランスポーズ"
dense
hide-bottom-space
class="key-shift"
@update:model-value="setKeyShiftInputBuffer"
@change="setKeyShift"
/>
<!-- 開発時のみ機能 -->
<template v-if="!isProduction">
<QInput
type="number"
:model-value="keyRangeAdjustmentInputBuffer"
label="音域調整"
dense
hide-bottom-space
class="key-shift"
@update:model-value="setKeyRangeAdjustmentInputBuffer"
@change="setKeyRangeAdjustment"
/>
</template>
<QInput
type="number"
:model-value="bpmInputBuffer"
Expand Down Expand Up @@ -124,13 +127,15 @@
<script setup lang="ts">
import { computed, watch, ref, onMounted, onUnmounted } from "vue";
import { useStore } from "@/store";
import { isProduction } from "@/type/preload";

import {
getSnapTypes,
isTriplet,
isValidBeatType,
isValidBeats,
isValidBpm,
isValidVoiceKeyShift,
isValidKeyRangeAdjustment,
} from "@/sing/domain";
import CharacterMenuButton from "@/components/Sing/CharacterMenuButton/MenuButton.vue";
import { useHotkeyManager } from "@/plugins/hotkeyPlugin";
Expand Down Expand Up @@ -183,12 +188,14 @@ const redo = () => {

const tempos = computed(() => store.state.tempos);
const timeSignatures = computed(() => store.state.timeSignatures);
const keyShift = computed(() => store.getters.SELECTED_TRACK.voiceKeyShift);
const keyRangeAdjustment = computed(
() => store.getters.SELECTED_TRACK.keyRangeAdjustment
);

const bpmInputBuffer = ref(120);
const beatsInputBuffer = ref(4);
const beatTypeInputBuffer = ref(4);
const keyShiftInputBuffer = ref(0);
const keyRangeAdjustmentInputBuffer = ref(0);

watch(
tempos,
Expand All @@ -207,8 +214,8 @@ watch(
{ deep: true }
);

watch(keyShift, () => {
keyShiftInputBuffer.value = keyShift.value;
watch(keyRangeAdjustment, () => {
keyRangeAdjustmentInputBuffer.value = keyRangeAdjustment.value;
});

const setBpmInputBuffer = (bpmStr: string | number | null) => {
Expand All @@ -235,12 +242,14 @@ const setBeatTypeInputBuffer = (beatTypeStr: string | number | null) => {
beatTypeInputBuffer.value = beatTypeValue;
};

const setKeyShiftInputBuffer = (keyShiftStr: string | number | null) => {
const keyShiftValue = Number(keyShiftStr);
if (!isValidVoiceKeyShift(keyShiftValue)) {
const setKeyRangeAdjustmentInputBuffer = (
KeyRangeAdjustmentStr: string | number | null
) => {
const KeyRangeAdjustmentValue = Number(KeyRangeAdjustmentStr);
if (!isValidKeyRangeAdjustment(KeyRangeAdjustmentValue)) {
return;
}
keyShiftInputBuffer.value = keyShiftValue;
keyRangeAdjustmentInputBuffer.value = KeyRangeAdjustmentValue;
};

const setTempo = () => {
Expand All @@ -265,9 +274,9 @@ const setTimeSignature = () => {
});
};

const setKeyShift = () => {
const voiceKeyShift = keyShiftInputBuffer.value;
store.dispatch("COMMAND_SET_VOICE_KEY_SHIFT", { voiceKeyShift });
const setKeyRangeAdjustment = () => {
const keyRangeAdjustment = keyRangeAdjustmentInputBuffer.value;
store.dispatch("COMMAND_SET_KEY_RANGE_ADJUSTMENT", { keyRangeAdjustment });
};

const playheadTicks = ref(0);
Expand Down
8 changes: 4 additions & 4 deletions src/sing/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,10 @@ export function isValidSnapType(snapType: number, tpqn: number) {
return getSnapTypes(tpqn).some((value) => value === snapType);
}

export function isValidVoiceKeyShift(voiceKeyShift: number) {
export function isValidKeyRangeAdjustment(keyRangeAdjustment: number) {
return (
Number.isInteger(voiceKeyShift) &&
voiceKeyShift <= 24 &&
voiceKeyShift >= -24
Number.isInteger(keyRangeAdjustment) &&
keyRangeAdjustment <= 24 &&
keyRangeAdjustment >= -24
);
}
3 changes: 1 addition & 2 deletions src/sing/storeHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ export const DEFAULT_BEAT_TYPE = 4;

export const generatePhraseHash = async (obj: {
singer: Singer | undefined;
notesKeyShift: number;
voiceKeyShift: number;
keyRangeAdjustment: number;
tpqn: number;
tempos: Tempo[];
notes: Note[];
Expand Down
7 changes: 3 additions & 4 deletions src/store/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ const applySongProjectToStore = async (
await dispatch("SET_SINGER", {
singer: tracks[0].singer,
});
await dispatch("SET_VOICE_KEY_SHIFT", {
voiceKeyShift: tracks[0].voiceKeyShift,
await dispatch("SET_KEY_RANGE_ADJUSTMENT", {
keyRangeAdjustment: tracks[0].keyRangeAdjustment,
});
await dispatch("SET_SCORE", {
score: {
Expand Down Expand Up @@ -431,8 +431,7 @@ export const projectStore = createPartialStore<ProjectStoreTypes>({
tracks: [
{
singer: undefined,
notesKeyShift: 0,
voiceKeyShift: 0,
keyRangeAdjustment: 0,
notes: [],
},
],
Expand Down
66 changes: 32 additions & 34 deletions src/store/singing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import {
isValidSnapType,
isValidTempo,
isValidTimeSignature,
isValidVoiceKeyShift,
isValidKeyRangeAdjustment,
secondToTick,
tickToSecond,
} from "@/sing/domain";
Expand Down Expand Up @@ -144,8 +144,7 @@ export const generateSingingStoreInitialScore = () => {
tracks: [
{
singer: undefined,
notesKeyShift: 0,
voiceKeyShift: 0,
keyRangeAdjustment: 0,
notes: [],
},
],
Expand Down Expand Up @@ -230,18 +229,18 @@ export const singingStore = createPartialStore<SingingStoreTypes>({
},
},

SET_VOICE_KEY_SHIFT: {
mutation(state, { voiceKeyShift }: { voiceKeyShift: number }) {
state.tracks[selectedTrackIndex].voiceKeyShift = voiceKeyShift;
SET_KEY_RANGE_ADJUSTMENT: {
mutation(state, { keyRangeAdjustment }: { keyRangeAdjustment: number }) {
state.tracks[selectedTrackIndex].keyRangeAdjustment = keyRangeAdjustment;
},
async action(
{ dispatch, commit },
{ voiceKeyShift }: { voiceKeyShift: number }
{ keyRangeAdjustment }: { keyRangeAdjustment: number }
) {
if (!isValidVoiceKeyShift(voiceKeyShift)) {
throw new Error("The voiceKeyShift is invalid.");
if (!isValidKeyRangeAdjustment(keyRangeAdjustment)) {
throw new Error("The keyRangeAdjustment is invalid.");
}
commit("SET_VOICE_KEY_SHIFT", { voiceKeyShift });
commit("SET_KEY_RANGE_ADJUSTMENT", { keyRangeAdjustment });

dispatch("RENDER");
},
Expand Down Expand Up @@ -746,8 +745,7 @@ export const singingStore = createPartialStore<SingingStoreTypes>({
async action({ state, getters, commit, dispatch }) {
const searchPhrases = async (
singer: Singer | undefined,
notesKeyShift: number,
voiceKeyShift: number,
keyRangeAdjustment: number,
tpqn: number,
tempos: Tempo[],
notes: Note[]
Expand All @@ -767,16 +765,14 @@ export const singingStore = createPartialStore<SingingStoreTypes>({
const phraseLastNote = phraseNotes[phraseNotes.length - 1];
const hash = await generatePhraseHash({
singer,
notesKeyShift,
voiceKeyShift,
keyRangeAdjustment,
tpqn,
tempos,
notes: phraseNotes,
});
foundPhrases.set(hash, {
singer,
notesKeyShift,
voiceKeyShift,
keyRangeAdjustment,
tpqn,
tempos,
notes: phraseNotes,
Expand All @@ -802,7 +798,7 @@ export const singingStore = createPartialStore<SingingStoreTypes>({
notes: Note[],
tempos: Tempo[],
tpqn: number,
notesKeyShift: number,
keyRangeAdjustment: number,
frameRate: number,
restDurationSeconds: number
) => {
Expand Down Expand Up @@ -834,8 +830,10 @@ export const singingStore = createPartialStore<SingingStoreTypes>({
.replace("うぉ", "ウォ")
.replace("は", "ハ")
.replace("へ", "ヘ");
// トランスポーズする
const key = note.noteNumber - keyRangeAdjustment;
notesForRequestToEngine.push({
key: note.noteNumber + notesKeyShift,
key,
frameLength: noteFrameLength,
lyric,
});
Expand Down Expand Up @@ -877,12 +875,12 @@ export const singingStore = createPartialStore<SingingStoreTypes>({
return frameAudioQuery.phonemes.map((value) => value.phoneme).join(" ");
};

const shiftVoiceKey = (
voiceKeyShift: number,
const shiftGuidePitch = (
pitchShift: number,
frameAudioQuery: FrameAudioQuery
) => {
frameAudioQuery.f0 = frameAudioQuery.f0.map((value) => {
return value * Math.pow(2, voiceKeyShift / 12);
return value * Math.pow(2, pitchShift / 12);
});
};

Expand Down Expand Up @@ -942,17 +940,15 @@ export const singingStore = createPartialStore<SingingStoreTypes>({
const tempos = state.tempos.map((value) => ({ ...value }));
const track = getters.SELECTED_TRACK;
const singer = track.singer ? { ...track.singer } : undefined;
const notesKeyShift = track.notesKeyShift;
const voiceKeyShift = track.voiceKeyShift;
const keyRangeAdjustment = track.keyRangeAdjustment;
const notes = track.notes
.map((value) => ({ ...value }))
.filter((value) => !state.overlappingNoteIds.has(value.id));

// フレーズを更新する
const foundPhrases = await searchPhrases(
singer,
notesKeyShift,
voiceKeyShift,
keyRangeAdjustment,
tpqn,
tempos,
notes
Expand Down Expand Up @@ -1036,7 +1032,7 @@ export const singingStore = createPartialStore<SingingStoreTypes>({
phrase.notes,
phrase.tempos,
phrase.tpqn,
phrase.notesKeyShift,
phrase.keyRangeAdjustment,
frameRate,
restDurationSeconds
).catch((error) => {
Expand All @@ -1052,7 +1048,7 @@ export const singingStore = createPartialStore<SingingStoreTypes>({
`Fetched frame audio query. Phonemes are "${phonemes}".`
);

shiftVoiceKey(phrase.voiceKeyShift, frameAudioQuery);
shiftGuidePitch(phrase.keyRangeAdjustment, frameAudioQuery);

const startTime = calcStartTime(
phrase.notes,
Expand Down Expand Up @@ -1977,18 +1973,20 @@ export const singingCommandStore = transformCommandStore(
dispatch("RENDER");
},
},
COMMAND_SET_VOICE_KEY_SHIFT: {
mutation(draft, { voiceKeyShift }) {
singingStore.mutations.SET_VOICE_KEY_SHIFT(draft, { voiceKeyShift });
COMMAND_SET_KEY_RANGE_ADJUSTMENT: {
mutation(draft, { keyRangeAdjustment }) {
singingStore.mutations.SET_KEY_RANGE_ADJUSTMENT(draft, {
keyRangeAdjustment,
});
},
async action(
{ dispatch, commit },
{ voiceKeyShift }: { voiceKeyShift: number }
{ keyRangeAdjustment }: { keyRangeAdjustment: number }
) {
if (!isValidVoiceKeyShift(voiceKeyShift)) {
throw new Error("The voiceKeyShift is invalid.");
if (!isValidKeyRangeAdjustment(keyRangeAdjustment)) {
throw new Error("The keyRangeAdjustment is invalid.");
}
commit("COMMAND_SET_VOICE_KEY_SHIFT", { voiceKeyShift });
commit("COMMAND_SET_KEY_RANGE_ADJUSTMENT", { keyRangeAdjustment });

dispatch("RENDER");
},
Expand Down
18 changes: 8 additions & 10 deletions src/store/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -751,8 +751,7 @@ export type Singer = z.infer<typeof singerSchema>;

export const trackSchema = z.object({
singer: singerSchema.optional(),
notesKeyShift: z.number(),
voiceKeyShift: z.number(),
keyRangeAdjustment: z.number(), // 音域調整量
notes: z.array(noteSchema),
});
export type Track = z.infer<typeof trackSchema>;
Expand All @@ -765,8 +764,7 @@ export type PhraseState =

export type Phrase = {
singer?: Singer;
notesKeyShift: number;
voiceKeyShift: number;
keyRangeAdjustment: number;
tpqn: number;
tempos: Tempo[];
notes: Note[];
Expand Down Expand Up @@ -818,9 +816,9 @@ export type SingingStoreTypes = {
action(payload: { singer?: Singer }): void;
};

SET_VOICE_KEY_SHIFT: {
mutation: { voiceKeyShift: number };
action(payload: { voiceKeyShift: number }): void;
SET_KEY_RANGE_ADJUSTMENT: {
mutation: { keyRangeAdjustment: number };
action(payload: { keyRangeAdjustment: number }): void;
};

SET_SCORE: {
Expand Down Expand Up @@ -1033,9 +1031,9 @@ export type SingingCommandStoreTypes = {
action(payload: { singer: Singer }): void;
};

COMMAND_SET_VOICE_KEY_SHIFT: {
mutation: { voiceKeyShift: number };
action(payload: { voiceKeyShift: number }): void;
COMMAND_SET_KEY_RANGE_ADJUSTMENT: {
mutation: { keyRangeAdjustment: number };
action(payload: { keyRangeAdjustment: number }): void;
};

COMMAND_SET_TEMPO: {
Expand Down
Loading