From 6cc30fdafc90a29e1082cb1637a4974032e98623 Mon Sep 17 00:00:00 2001 From: Sig Date: Wed, 31 Jul 2024 01:01:44 +0900 Subject: [PATCH] =?UTF-8?q?Fix=EF=BC=9A=E3=83=95=E3=83=AC=E3=83=BC?= =?UTF-8?q?=E3=82=BA=E3=81=AE=E6=9B=B4=E6=96=B0=E3=82=92=E8=A1=8C=E3=81=A3?= =?UTF-8?q?=E3=81=A6=E3=81=84=E3=82=8B=E3=81=A8=E3=81=93=E3=82=8D=E3=81=AE?= =?UTF-8?q?=E5=87=A6=E7=90=86=E3=81=AB=E5=95=8F=E9=A1=8C=E3=81=8C=E3=81=82?= =?UTF-8?q?=E3=81=A3=E3=81=9F=E3=81=AE=E3=81=A7=E4=BF=AE=E6=AD=A3=20(#2188?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * singingGuides、singingVoices、phrases、sequencesの更新を同じタイミングで行うように修正 * 修正 --- src/store/singing.ts | 129 +++++++++++++++++++++++-------------------- 1 file changed, 69 insertions(+), 60 deletions(-) diff --git a/src/store/singing.ts b/src/store/singing.ts index 70f63b2664..5b03695437 100644 --- a/src/store/singing.ts +++ b/src/store/singing.ts @@ -1565,36 +1565,20 @@ export const singingStore = createPartialStore({ } } - for (const [phraseKey, phrase] of state.phrases) { - const notesHash = phraseKey; - if (!foundPhrases.has(notesHash)) { - // 歌い方と歌声を削除する - if (phrase.singingGuideKey != undefined) { - commit("DELETE_SINGING_GUIDE", { - singingGuideKey: phrase.singingGuideKey, - }); - } - if (phrase.singingVoiceKey != undefined) { - singingVoices.delete(phrase.singingVoiceKey); - } + const phrases = new Map(); + const disappearedPhraseKeys = new Set(); - // 音源とシーケンスの接続を解除して削除する - const sequence = sequences.get(phraseKey); - if (sequence) { - getAudioSourceNode(sequence).disconnect(); - transportRef.removeSequence(sequence); - sequences.delete(phraseKey); - } + for (const phraseKey of state.phrases.keys()) { + if (!foundPhrases.has(phraseKey)) { + // 無くなったフレーズの場合 + disappearedPhraseKeys.add(phraseKey); } } - - const newPhrases = new Map(); - for (const [phraseKey, foundPhrase] of foundPhrases) { const existingPhrase = state.phrases.get(phraseKey); if (!existingPhrase) { // 新しいフレーズの場合 - newPhrases.set(phraseKey, foundPhrase); + phrases.set(phraseKey, foundPhrase); continue; } @@ -1608,50 +1592,36 @@ export const singingStore = createPartialStore({ // すでに存在するフレーズの場合 // 再レンダリングする必要があるかどうかをチェックする // シンガーが未設定の場合、とりあえず常に再レンダリングする - // 音声合成を行う必要がある場合、現在フレーズに設定されている歌声を削除する - // 歌い方の推論も行う必要がある場合、現在フレーズに設定されている歌い方を削除する + // 音声合成を行う必要がある場合、singingVoiceKeyをundefinedにする + // 歌い方の推論も行う必要がある場合、singingGuideKeyとsingingVoiceKeyをundefinedにする // TODO: リファクタリングする const phrase = { ...existingPhrase }; if (!singerAndFrameRate || phrase.state === "COULD_NOT_RENDER") { if (phrase.singingGuideKey != undefined) { - commit("DELETE_SINGING_GUIDE", { - singingGuideKey: phrase.singingGuideKey, - }); phrase.singingGuideKey = undefined; } if (phrase.singingVoiceKey != undefined) { - singingVoices.delete(phrase.singingVoiceKey); phrase.singingVoiceKey = undefined; } - } else { - if (phrase.singingGuideKey != undefined) { - const calculatedHash = await calculateSingingGuideSourceHash({ - engineId: singerAndFrameRate.singer.engineId, - tpqn, - tempos, - firstRestDuration: phrase.firstRestDuration, - lastRestDurationSeconds, - notes: phrase.notes, - keyRangeAdjustment: track.keyRangeAdjustment, - volumeRangeAdjustment: track.volumeRangeAdjustment, - frameRate: singerAndFrameRate.frameRate, - }); - const hash = phrase.singingGuideKey; - if (hash !== calculatedHash) { - commit("DELETE_SINGING_GUIDE", { - singingGuideKey: phrase.singingGuideKey, - }); - phrase.singingGuideKey = undefined; - if (phrase.singingVoiceKey != undefined) { - singingVoices.delete(phrase.singingVoiceKey); - phrase.singingVoiceKey = undefined; - } + } else if (phrase.singingGuideKey != undefined) { + const calculatedHash = await calculateSingingGuideSourceHash({ + engineId: singerAndFrameRate.singer.engineId, + tpqn, + tempos, + firstRestDuration: phrase.firstRestDuration, + lastRestDurationSeconds, + notes: phrase.notes, + keyRangeAdjustment: track.keyRangeAdjustment, + volumeRangeAdjustment: track.volumeRangeAdjustment, + frameRate: singerAndFrameRate.frameRate, + }); + const hash = phrase.singingGuideKey; + if (hash !== calculatedHash) { + phrase.singingGuideKey = undefined; + if (phrase.singingVoiceKey != undefined) { + phrase.singingVoiceKey = undefined; } - } - if ( - phrase.singingGuideKey != undefined && - phrase.singingVoiceKey != undefined - ) { + } else if (phrase.singingVoiceKey != undefined) { let singingGuide = getOrThrow( state.singingGuides, phrase.singingGuideKey, @@ -1667,22 +1637,61 @@ export const singingStore = createPartialStore({ }); const hash = phrase.singingVoiceKey; if (hash !== calculatedHash) { - singingVoices.delete(phrase.singingVoiceKey); phrase.singingVoiceKey = undefined; } } } + + phrases.set(phraseKey, phrase); + } + + // フレーズのstateを更新する + for (const phrase of phrases.values()) { if ( phrase.singingGuideKey == undefined || phrase.singingVoiceKey == undefined ) { phrase.state = "WAITING_TO_BE_RENDERED"; } + } + + // 無くなったフレーズの音源とシーケンスの接続を解除して削除する + for (const phraseKey of disappearedPhraseKeys) { + const sequence = sequences.get(phraseKey); + if (sequence) { + getAudioSourceNode(sequence).disconnect(); + transportRef.removeSequence(sequence); + sequences.delete(phraseKey); + } + } - newPhrases.set(phraseKey, phrase); + // 使われていない歌い方と歌声を削除する + const singingGuideKeysInUse = new Set( + [...phrases.values()] + .map((value) => value.singingGuideKey) + .filter((value) => value != undefined), + ); + const singingVoiceKeysInUse = new Set( + [...phrases.values()] + .map((value) => value.singingVoiceKey) + .filter((value) => value != undefined), + ); + const existingSingingGuideKeys = new Set(state.singingGuides.keys()); + const existingSingingVoiceKeys = new Set(singingVoices.keys()); + const singingGuideKeysToDelete = existingSingingGuideKeys.difference( + singingGuideKeysInUse, + ); + const singingVoiceKeysToDelete = existingSingingVoiceKeys.difference( + singingVoiceKeysInUse, + ); + for (const singingGuideKey of singingGuideKeysToDelete) { + commit("DELETE_SINGING_GUIDE", { singingGuideKey }); + } + for (const singingVoiceKey of singingVoiceKeysToDelete) { + singingVoices.delete(singingVoiceKey); } - commit("SET_PHRASES", { phrases: newPhrases }); + commit("SET_PHRASES", { phrases }); logger.info("Phrases updated.");