Skip to content

Commit

Permalink
ソング:プロジェクトファイル読み込みでピッチ編集データもロードする (#2021)
Browse files Browse the repository at this point in the history
プロジェクトファイル読み込みでピッチ編集データもロードする
  • Loading branch information
Hiroshiba authored Apr 26, 2024
1 parent 3eec37d commit cfaed56
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/sing/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,14 @@ export function isValidvolumeRangeAdjustment(volumeRangeAdjustment: number) {
);
}

export function isValidPitchEditData(pitchEditData: number[]) {
return pitchEditData.every(
(value) =>
Number.isFinite(value) &&
(value > 0 || value === VALUE_INDICATING_NO_DATA),
);
}

export const calculateNotesHash = async (notes: Note[]) => {
return await calculateHash({ notes });
};
Expand Down
7 changes: 7 additions & 0 deletions src/store/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ const applySongProjectToStore = async (
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,
startFrame: 0,
});
};

export const projectStore = createPartialStore<ProjectStoreTypes>({
Expand Down Expand Up @@ -168,6 +173,8 @@ export const projectStore = createPartialStore<ProjectStoreTypes>({
notes: tracks[0].notes,
},
});
await context.dispatch("SET_SINGER", {});
await context.dispatch("CLEAR_PITCH_EDIT_DATA");

context.commit("SET_PROJECT_FILEPATH", { filePath: undefined });
context.commit("SET_SAVED_LAST_COMMAND_UNIX_MILLISEC", null);
Expand Down
31 changes: 29 additions & 2 deletions src/store/singing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import {
decibelToLinear,
applyPitchEdit,
VALUE_INDICATING_NO_DATA,
isValidPitchEditData,
} from "@/sing/domain";
import {
DEFAULT_BEATS,
Expand Down Expand Up @@ -535,6 +536,20 @@ export const singingStore = createPartialStore<SingingStoreTypes>({
tempData.splice(startFrame, data.length, ...data);
state.tracks[selectedTrackIndex].pitchEditData = tempData;
},
async action(
{ dispatch, commit },
{ data, startFrame }: { data: number[]; startFrame: number },
) {
if (startFrame < 0) {
throw new Error("startFrame must be greater than or equal to 0.");
}
if (!isValidPitchEditData(data)) {
throw new Error("The pitch edit data is invalid.");
}
commit("SET_PITCH_EDIT_DATA", { data, startFrame });

dispatch("RENDER");
},
},

ERASE_PITCH_EDIT_DATA: {
Expand All @@ -550,6 +565,18 @@ export const singingStore = createPartialStore<SingingStoreTypes>({
},
},

CLEAR_PITCH_EDIT_DATA: {
// ピッチ編集データを失くす。
mutation(state) {
state.tracks[selectedTrackIndex].pitchEditData = [];
},
async action({ dispatch, commit }) {
commit("CLEAR_PITCH_EDIT_DATA");

dispatch("RENDER");
},
},

SET_PHRASES: {
mutation(state, { phrases }: { phrases: Map<string, Phrase> }) {
state.phrases = phrases;
Expand Down Expand Up @@ -2698,8 +2725,8 @@ export const singingCommandStore = transformCommandStore(
if (startFrame < 0) {
throw new Error("startFrame must be greater than or equal to 0.");
}
if (data.some((value) => !Number.isFinite(value) || value <= 0)) {
throw new Error("data is invalid.");
if (!isValidPitchEditData(data)) {
throw new Error("The pitch edit data is invalid.");
}
commit("COMMAND_SET_PITCH_EDIT_DATA", { data, startFrame });

Expand Down
6 changes: 6 additions & 0 deletions src/store/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -913,12 +913,18 @@ export type SingingStoreTypes = {

SET_PITCH_EDIT_DATA: {
mutation: { data: number[]; startFrame: number };
action(payload: { data: number[]; startFrame: number }): void;
};

ERASE_PITCH_EDIT_DATA: {
mutation: { startFrame: number; frameLength: number };
};

CLEAR_PITCH_EDIT_DATA: {
mutation: undefined;
action(): void;
};

SET_PHRASES: {
mutation: { phrases: Map<string, Phrase> };
};
Expand Down

0 comments on commit cfaed56

Please sign in to comment.