From d8a78e1cb8b58688275cbc2a1bfb25e138cfbff2 Mon Sep 17 00:00:00 2001 From: Moshe Gordon Radian Date: Fri, 19 Apr 2024 22:13:24 +0300 Subject: [PATCH] fix: type issue in one of the files --- .../src/oddVoiceJSON/index.ts | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/musicxml-singer-with-oddvoices/src/oddVoiceJSON/index.ts b/musicxml-singer-with-oddvoices/src/oddVoiceJSON/index.ts index 375ca76..61fcc46 100644 --- a/musicxml-singer-with-oddvoices/src/oddVoiceJSON/index.ts +++ b/musicxml-singer-with-oddvoices/src/oddVoiceJSON/index.ts @@ -588,25 +588,32 @@ export const musicXMLToEvents = ( } }); + // Chords with no lyrics should have the previous lyrics added to them if (!newLyricText && currChordLvl > 1) { // Find the last lyric event for this part and voice with a lower chord level const lastLyricEvent = findLast( lyricsEvents, - (e) => e.partIdx === partIdx && e.voice === currentVoice + (e) => + e.partIdx === partIdx && + e.voice === currentVoice && + e.time === timeElapsedForPartAndVoice ); if (lastLyricEvent) { const newLyricEvent = cloneDeep(lastLyricEvent); - continuesPreviousLyric = Boolean(newLyricEvent.continuesPrevious); - newLyricText = `${continuesPreviousLyric ? "" : " "}${newLyricEvent.lyric ?? ""}`; newLyricEvent.chordLevel = currChordLvl; - console.log("Adding previous lyric", { - measureChild, - newLyricText, - partChordLyrics: partChordLyricsTexts[`${partIdx}_${currChordLvl}`], - lastLyricEvent, - newLyricEvent, - }); - lyricsEvents.push(newLyricEvent); + // Only add this event if it doesn't exist yet + if (!find(lyricsEvents, newLyricEvent)) { + continuesPreviousLyric = Boolean(newLyricEvent.continuesPrevious); + newLyricText = `${continuesPreviousLyric ? "" : " "}${newLyricEvent.lyric ?? ""}`; + console.log("Adding previous lyric", { + measureChild, + newLyricText, + partChordLyrics: partChordLyricsTexts[`${partIdx}_${currChordLvl}`], + lastLyricEvent, + newLyricEvent, + }); + lyricsEvents.push(newLyricEvent); + } } }