diff --git a/composeApp/src/commonMain/composeResources/files/config.json b/composeApp/src/commonMain/composeResources/files/config.json index 8c5b2a7..8bfa415 100644 --- a/composeApp/src/commonMain/composeResources/files/config.json +++ b/composeApp/src/commonMain/composeResources/files/config.json @@ -2,6 +2,7 @@ "themeMode": "DARK", "fontSize": 18.5, "playlist": [ + "assets://a.txt", "assets://ffpm-617.txt", "assets://ews-127.txt", "assets://ffpm-521.txt", diff --git a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/Solfa.kt b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/Solfa.kt index 2f21e48..14a810f 100644 --- a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/Solfa.kt +++ b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/Solfa.kt @@ -13,7 +13,7 @@ import mg.dot.feufaro.getConfigDirectoryPath import mg.dot.feufaro.launchFilePicker import mg.dot.feufaro.midi.MidiPitch import mg.dot.feufaro.midi.MidiWriterKotlin -import java.io.File +import kotlin.math.min //@todo: split voices (ffpm19/ews22) ${S:mfs} in N4:, idem ffpm-212 //@todo: ffpm-172-2 ${O:1} non fonctionnel @@ -34,6 +34,8 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository private val O: MutableMap> = mutableMapOf() private val unparsedNote = mutableListOf() private var refrainBeginsAt = -1 + private var refrainEndsAt = -1 + private var refrainMaxStanza = -1 private var smartLyricsType = "L" private val pitches = mutableListOf() @@ -48,7 +50,7 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository val REGEX_TEMPLATE_COMMENT = Regex("(\\$[A-Z]|\\$\\{[^\\}]*\\})") val REGEX_REPETITION = Regex("([zwdrmfslt-](?>[',]*))([1-9][0-9]*)", RegexOption.IGNORE_CASE) val REGEX_PARSE_META = Regex("\\|(?=[a-z]:)") - val REGEX_LYRICS_COMMENT = Regex("\\$\\{([^\\}][^:]*:([^\\}]*))\\}|\\$\\{R!\\}") + val REGEX_LYRICS_COMMENT = Regex("\\$\\{([^\\}][^:]*:([^\\}]*))\\}") val REGEX_LYRICS_REPETITION = Regex("_(\\d+)") val REGEX_VOWELS_STAGE1 = Regex("[aeiouyòàéìỳ](?![,;\\.\\-:!\\?\\}»_\"]*([ aeiouyòàéìỳ/]|_[1-9]))", RegexOption.IGNORE_CASE) @@ -205,6 +207,8 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository } pitches.clear() refrainBeginsAt = -1 + refrainEndsAt = -1 + refrainMaxStanza = -1 unparsedNote.clear() templateString = "" nextTIndex = -1 @@ -264,7 +268,13 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository templateComments.add(matchResult.value) "&" } - val templateCharArray = templateStripped.toCharArray() + fun insertZToCharArray(input: String): CharArray { + val delim = "/:!|" + val reDelim = "[$delim](?=[$delim])".toRegex() + val insertedZ = input.replace(reDelim) { it.value + "z"} + return insertedZ.toCharArray() + } + val templateCharArray = insertZToCharArray(templateStripped) val noteLine = noteLine.replace(REGEX_TEMPLATE_COMMENT, "") .replace(" ", "") val lineRepeated = REGEX_REPETITION.replace(noteLine.substring(1)) { matchResult -> @@ -744,6 +754,7 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository } private fun loadLyrics(stanzaNumber: Int, lyrics: String) { + defineRefrainMaxStanza(99999) val overrideIterator: MutableMap> = mutableMapOf() try { val lyrics = getLyricsComments(lyrics) @@ -795,7 +806,7 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository } addLyricsItem(stanzaNumber, i, originalLyrics) } - if (refrainBeginsAt > 0 && stanzaNumber > 1 && !lyrics.contains($$"${R!}")) { + if (refrainBeginsAt >= 0 && stanzaNumber > 1) { copyRefrainToStanza(stanzaNumber) } @@ -895,10 +906,19 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository private fun defineRefrainFrom(tuoNumber: Int) { refrainBeginsAt = tuoNumber + refrainEndsAt = 99999 + refrainMaxStanza = 99999 + } + private fun defineRefrainTo(tuoNumber: Int) { + refrainEndsAt = tuoNumber + } + private fun defineRefrainMaxStanza(tuoNumber: Int) { + refrainMaxStanza = tuoNumber } private fun copyRefrainToStanza(stanzaNumber: Int) { - for (i in refrainBeginsAt..L.size - 1) { + val refrainMax = min(min(refrainEndsAt - 1, L.size - 1), refrainMaxStanza - 1) + for (i in refrainBeginsAt..refrainMax) { L[i].setLyrics(stanzaNumber, L[i].getLyrics(1)) L[i].copyAlternativeLyrics(1, stanzaNumber) } @@ -914,6 +934,13 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository defineRefrainFrom(i) } lyricsItem.replace($$"${R=}", "") + } else if (lyricsItem.contains($$"${R!}")) { + if (stanzaNumber == 1) { + defineRefrainTo(i) + } else { + defineRefrainMaxStanza(i) + } + lyricsItem.replace($$"${R!}", "") } else { lyricsItem }