Skip to content

Commit

Permalink
プロパティ名を変更
Browse files Browse the repository at this point in the history
  • Loading branch information
sigprogramming committed Nov 16, 2024
1 parent dc4177b commit 6cb1cd4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
24 changes: 15 additions & 9 deletions src/sing/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,8 @@ type PhonemeTiming = {
};

export type PhonemeTimingEdit = {
phonemeIndex: number; // ノート内での音素の順番
offset: number; // 単位は秒
phonemeIndexInNote: number;
offsetSeconds: number;
};

export type PhonemeTimingEditData = Map<NoteId, PhonemeTimingEdit[]>;
Expand Down Expand Up @@ -667,7 +667,7 @@ function applyPhonemeTimingEditToPhonemeTimings(
phonemeTimingEditData: PhonemeTimingEditData,
frameRate: number,
) {
let phonemeIndex = 0;
let phonemeIndexInNote = 0;
for (let i = 0; i < phonemeTimings.length; i++) {
const phonemeTiming = phonemeTimings[i];
const prevPhonemeTiming = getPrev(phonemeTimings, i);
Expand All @@ -677,9 +677,9 @@ function applyPhonemeTimingEditToPhonemeTimings(
prevPhonemeTiming == undefined ||
phonemeTiming.noteId !== prevPhonemeTiming.noteId
) {
phonemeIndex = 0;
phonemeIndexInNote = 0;
} else {
phonemeIndex++;
phonemeIndexInNote++;
}

if (phonemeTiming.phoneme === "pau") {
Expand All @@ -693,20 +693,26 @@ function applyPhonemeTimingEditToPhonemeTimings(
continue;
}
for (const phonemeTimingEdit of phonemeTimingEdits) {
if (phonemeTimingEdit.phonemeIndex === phonemeIndex) {
const offsetFrame = secondToFrame(phonemeTimingEdit.offset, frameRate);
if (phonemeTimingEdit.phonemeIndexInNote === phonemeIndexInNote) {
const offsetFrame = secondToFrame(
phonemeTimingEdit.offsetSeconds,
frameRate,
);
const roundedOffsetFrame = Math.round(offsetFrame);

phonemeTiming.startFrame += roundedOffsetFrame;
if (prevPhonemeTiming != undefined) {
prevPhonemeTiming.endFrame = phonemeTiming.startFrame;
}
} else if (
phonemeTimingEdit.phonemeIndex === phonemeIndex + 1 &&
phonemeTimingEdit.phonemeIndexInNote === phonemeIndexInNote + 1 &&
nextPhonemeTiming?.phoneme === "pau"
) {
// NOTE: 休符のpauseは休符の直前のノートに含まれる音素として扱う
const offsetFrame = secondToFrame(phonemeTimingEdit.offset, frameRate);
const offsetFrame = secondToFrame(
phonemeTimingEdit.offsetSeconds,
frameRate,
);
const roundedOffsetFrame = Math.round(offsetFrame);

phonemeTiming.endFrame += roundedOffsetFrame;
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/domain/sing/applyPhonemeTimingEdit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ describe("applyPhonemeTimingEditAndAdjust", () => {

it("音素タイミング編集が適用される", () => {
const phonemeTimingEditData = new Map<NoteId, PhonemeTimingEdit[]>([
[noteIds[1], [{ phonemeIndex: 0, offset: -3 / frameRate }]],
[noteIds[4], [{ phonemeIndex: 1, offset: 6 / frameRate }]],
[noteIds[1], [{ phonemeIndexInNote: 0, offsetSeconds: -3 / frameRate }]],
[noteIds[4], [{ phonemeIndexInNote: 1, offsetSeconds: 6 / frameRate }]],
]);
const expectedPhraseQueries = structuredClone(phraseQueries);
expectedPhraseQueries[0].phonemes[2].frameLength -= 3;
Expand All @@ -146,8 +146,8 @@ describe("applyPhonemeTimingEditAndAdjust", () => {

it("音素が重ならないように音素タイミングが調整される", () => {
const phonemeTimingEditData = new Map<NoteId, PhonemeTimingEdit[]>([
[noteIds[1], [{ phonemeIndex: 1, offset: -12 / frameRate }]],
[noteIds[2], [{ phonemeIndex: 2, offset: 60 / frameRate }]],
[noteIds[1], [{ phonemeIndexInNote: 1, offsetSeconds: -12 / frameRate }]],
[noteIds[2], [{ phonemeIndexInNote: 2, offsetSeconds: 60 / frameRate }]],
]);
const expectedPhraseQueries = structuredClone(phraseQueries);
expectedPhraseQueries[0].phonemes[2].frameLength -= 6;
Expand All @@ -167,8 +167,8 @@ describe("applyPhonemeTimingEditAndAdjust", () => {

it("pauseのフレーム長が1以上になるように音素タイミングが調整される", () => {
const phonemeTimingEditData = new Map<NoteId, PhonemeTimingEdit[]>([
[noteIds[3], [{ phonemeIndex: 1, offset: -60 / frameRate }]],
[noteIds[5], [{ phonemeIndex: 2, offset: 60 / frameRate }]],
[noteIds[3], [{ phonemeIndexInNote: 1, offsetSeconds: -60 / frameRate }]],
[noteIds[5], [{ phonemeIndexInNote: 2, offsetSeconds: 60 / frameRate }]],
]);
const expectedPhraseQueries = structuredClone(phraseQueries);
expectedPhraseQueries[1].phonemes[0].frameLength -= 39;
Expand Down

0 comments on commit 6cb1cd4

Please sign in to comment.