Skip to content

Commit

Permalink
ソング:Score型をなくす (VOICEVOX#2065)
Browse files Browse the repository at this point in the history
SET_SCOREをなくした、リファクタリング
  • Loading branch information
sigprogramming authored May 9, 2024
1 parent 6801519 commit 1087cad
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 205 deletions.
31 changes: 8 additions & 23 deletions src/components/Sing/SingEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ import EngineStartupOverlay from "@/components/EngineStartupOverlay.vue";
import { useStore } from "@/store";
import onetimeWatch from "@/helpers/onetimeWatch";
import {
DEFAULT_BEATS,
DEFAULT_BEAT_TYPE,
DEFAULT_BPM,
DEFAULT_TPQN,
} from "@/sing/storeHelper";
createDefaultTempo,
createDefaultTimeSignature,
} from "@/sing/domain";
const props = defineProps<{
isEnginesReady: boolean;
Expand Down Expand Up @@ -78,26 +77,12 @@ onetimeWatch(
return "continue";
if (!isProjectFileLoaded) {
await store.dispatch("SET_SCORE", {
score: {
tpqn: DEFAULT_TPQN,
tempos: [
{
position: 0,
bpm: DEFAULT_BPM,
},
],
timeSignatures: [
{
measureNumber: 1,
beats: DEFAULT_BEATS,
beatType: DEFAULT_BEAT_TYPE,
},
],
notes: [],
},
await store.dispatch("SET_TPQN", { tpqn: DEFAULT_TPQN });
await store.dispatch("SET_TEMPOS", { tempos: [createDefaultTempo(0)] });
await store.dispatch("SET_TIME_SIGNATURES", {
timeSignatures: [createDefaultTimeSignature(1)],
});
await store.dispatch("SET_NOTES", { notes: [] });
// CI上のe2eテストのNemoエンジンには歌手がいないためエラーになるのでワークアラウンド
// FIXME: 歌手をいると見せかけるmock APIを作り、ここのtry catchを削除する
try {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Sing/ToolBar/ToolBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ import {
isValidBeats,
isValidBpm,
isValidKeyRangeAdjustment,
isValidvolumeRangeAdjustment,
isValidVolumeRangeAdjustment,
} from "@/sing/domain";
import CharacterMenuButton from "@/components/Sing/CharacterMenuButton/MenuButton.vue";
import { useHotkeyManager } from "@/plugins/hotkeyPlugin";
Expand Down Expand Up @@ -296,7 +296,7 @@ const setVolumeRangeAdjustmentInputBuffer = (
volumeRangeAdjustmentStr: string | number | null,
) => {
const volumeRangeAdjustmentValue = Number(volumeRangeAdjustmentStr);
if (!isValidvolumeRangeAdjustment(volumeRangeAdjustmentValue)) {
if (!isValidVolumeRangeAdjustment(volumeRangeAdjustmentValue)) {
return;
}
volumeRangeAdjustmentInputBuffer.value = volumeRangeAdjustmentValue;
Expand Down
45 changes: 34 additions & 11 deletions src/sing/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { convertLongVowel } from "@/store/utility";
import {
Note,
Phrase,
Score,
SingingGuide,
SingingGuideSource,
SingingVoiceSource,
Tempo,
TimeSignature,
Track,
singingGuideSourceHashSchema,
singingVoiceSourceHashSchema,
} from "@/store/type";
Expand Down Expand Up @@ -87,15 +87,6 @@ export const isValidNotes = (notes: Note[]) => {
return notes.every((value) => isValidNote(value));
};

export const isValidScore = (score: Score) => {
return (
isValidTpqn(score.tpqn) &&
isValidTempos(score.tempos) &&
isValidTimeSignatures(score.timeSignatures) &&
isValidNotes(score.notes)
);
};

const tickToSecondForConstantBpm = (
ticks: number,
bpm: number,
Expand Down Expand Up @@ -283,6 +274,14 @@ export function decibelToLinear(decibelValue: number) {
return Math.pow(10, decibelValue / 20);
}

export const DEFAULT_TPQN = 480;
export const DEFAULT_BPM = 120;
export const DEFAULT_BEATS = 4;
export const DEFAULT_BEAT_TYPE = 4;

// マルチエンジン対応のために将来的に廃止予定で、利用は非推奨
export const DEPRECATED_DEFAULT_EDIT_FRAME_RATE = 93.75;

export const VALUE_INDICATING_NO_DATA = -1;

export const UNVOICED_PHONEMES = [
Expand All @@ -299,6 +298,30 @@ export const UNVOICED_PHONEMES = [
"ts",
];

export function createDefaultTempo(position: number): Tempo {
return { position, bpm: DEFAULT_BPM };
}

export function createDefaultTimeSignature(
measureNumber: number,
): TimeSignature {
return {
measureNumber,
beats: DEFAULT_BEATS,
beatType: DEFAULT_BEAT_TYPE,
};
}

export function createDefaultTrack(): Track {
return {
singer: undefined,
keyRangeAdjustment: 0,
volumeRangeAdjustment: 0,
notes: [],
pitchEditData: [],
};
}

export function getSnapTypes(tpqn: number) {
return getRepresentableNoteTypes(tpqn).filter((value) => {
return value <= MAX_SNAP_TYPE;
Expand All @@ -317,7 +340,7 @@ export function isValidKeyRangeAdjustment(keyRangeAdjustment: number) {
);
}

export function isValidvolumeRangeAdjustment(volumeRangeAdjustment: number) {
export function isValidVolumeRangeAdjustment(volumeRangeAdjustment: number) {
return (
Number.isInteger(volumeRangeAdjustment) &&
volumeRangeAdjustment <= 20 &&
Expand Down
8 changes: 0 additions & 8 deletions src/sing/storeHelper.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import { NoteId } from "@/type/preload";
import { Note } from "@/store/type";

export const DEFAULT_TPQN = 480;
export const DEFAULT_BPM = 120;
export const DEFAULT_BEATS = 4;
export const DEFAULT_BEAT_TYPE = 4;

// マルチエンジン対応のために将来的に廃止予定で、利用は非推奨
export const DEPRECATED_DEFAULT_EDIT_FRAME_RATE = 93.75;

/**
* 頻繁に変更される値を保持します。
* 値変更時に実行する関数を登録できます。
Expand Down
36 changes: 15 additions & 21 deletions src/store/project.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import semver from "semver";
import { getBaseName } from "./utility";
import { createPartialStore, Dispatch } from "./vuex";
import { generateSingingStoreInitialScore } from "./singing";
import { createUILockAction } from "@/store/ui";
import {
AllActions,
AudioItem,
ProjectStoreState,
ProjectStoreTypes,
} from "@/store/type";

import { AccentPhrase } from "@/openapi";
import { EngineId } from "@/type/preload";
import { getValueOrThrow, ResultError } from "@/type/result";
import { LatestProjectType, projectSchema } from "@/domain/project/schema";
import {
createDefaultTempo,
createDefaultTimeSignature,
DEFAULT_BEAT_TYPE,
DEFAULT_BEATS,
DEFAULT_BPM,
DEFAULT_TPQN,
} from "@/sing/storeHelper";
import { LatestProjectType, projectSchema } from "@/domain/project/schema";
} from "@/sing/domain";

const DEFAULT_SAMPLING_RATE = 24000;

Expand Down Expand Up @@ -108,14 +108,10 @@ const applySongProjectToStore = async (
await dispatch("SET_VOLUME_RANGE_ADJUSTMENT", {
volumeRangeAdjustment: tracks[0].volumeRangeAdjustment,
});
await dispatch("SET_SCORE", {
score: {
tpqn,
tempos,
timeSignatures,
notes: tracks[0].notes,
},
});
await dispatch("SET_TPQN", { tpqn });
await dispatch("SET_TEMPOS", { tempos });
await dispatch("SET_TIME_SIGNATURES", { timeSignatures });
await dispatch("SET_NOTES", { notes: tracks[0].notes });
await dispatch("CLEAR_PITCH_EDIT_DATA"); // FIXME: SET_PITCH_EDIT_DATAがセッターになれば不要
await dispatch("SET_PITCH_EDIT_DATA", {
data: tracks[0].pitchEditData,
Expand Down Expand Up @@ -163,16 +159,14 @@ export const projectStore = createPartialStore<ProjectStoreTypes>({
});

// ソングプロジェクトの初期化
const { tpqn, tempos, timeSignatures, tracks } =
generateSingingStoreInitialScore();
await context.dispatch("SET_SCORE", {
score: {
tpqn,
tempos,
timeSignatures,
notes: tracks[0].notes,
},
await context.dispatch("SET_TPQN", { tpqn: DEFAULT_TPQN });
await context.dispatch("SET_TEMPOS", {
tempos: [createDefaultTempo(0)],
});
await context.dispatch("SET_TIME_SIGNATURES", {
timeSignatures: [createDefaultTimeSignature(1)],
});
await context.dispatch("SET_NOTES", { notes: [] });
await context.dispatch("SET_SINGER", { withRelated: true });
await context.dispatch("CLEAR_PITCH_EDIT_DATA");

Expand Down
Loading

0 comments on commit 1087cad

Please sign in to comment.