From 7d1e02078f50bdbc1bea05593c03d4a55cf3d385 Mon Sep 17 00:00:00 2001 From: Hasinjato Date: Thu, 5 Nov 2026 14:59:30 +0300 Subject: [PATCH] Implements litanies visual partition for ${L} marker --- .../kotlin/mg/dot/feufaro/solfa/PTemplate.kt | 1 + .../kotlin/mg/dot/feufaro/solfa/Solfa.kt | 16 +++++++-- .../mg/dot/feufaro/solfa/SolfaLabels.kt | 34 +++++++++++++++++++ .../mg/dot/feufaro/solfa/TimeUnitObject.kt | 24 +++++++++---- 4 files changed, 66 insertions(+), 9 deletions(-) create mode 100644 composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/SolfaLabels.kt diff --git a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/PTemplate.kt b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/PTemplate.kt index 77ebd25..1a7701a 100644 --- a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/PTemplate.kt +++ b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/PTemplate.kt @@ -32,6 +32,7 @@ class PTemplate (val template: String, val separatorAfter: String, private val m prefix + it.code.replace(Regex("^\\$\\{([abd-z]:)?(.*)\\}"), "$2") .replace("\$Q", "\uD834\uDD10") .replace(Regex("^[<=>]$"), "") + .replace(Regex("^L$"), "") .replace($$"$T", "") .replace(Regex("^c:(.*)"), "Do dia $1") } 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 c40fd8e..469c21f 100644 --- a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/Solfa.kt +++ b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/Solfa.kt @@ -63,6 +63,7 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository val REGEX_NOTE_TODROP = Regex("([drmfsltz][ia]?|[―])([₄₃₂₁¹²³⁴',]*)<") val REGEX_NOTE_SPLIT = Regex("\\$\\{[Ss]:([^\\}]+)\\}([drmfsltDRFSTz][,']*)") val REGEX_DC_REFRAIN = Regex("""\$\{R=\}\$\{D:(.*?)\}""") + val KEEP_MARKERS = listOf("\${L}", "\$T") } fun parseNoteSplit(input: String): String { @@ -1166,7 +1167,11 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository /* On ne ré-insere pas la même marker*/ val markerRegex = Regex("""\$\{.*?\}|\$.""") - val blockWithoutOldMarkers = rawBlockText.replace(markerRegex, "") + val blockWithoutOldMarkers = if (anyNoteModified) { + rawBlockText.replace(markerRegex, "") + } else { + rawBlockText.replace(markerRegex) { if (it.value in KEEP_MARKERS) it.value else "" } + } val leadingCloseParentheses = blockWithoutOldMarkers.takeWhile { it == ')' } val oldCleaned = blockWithoutOldMarkers.substring(leadingCloseParentheses.length) @@ -1192,7 +1197,14 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository } else { oldCleaned } - val rawProcessed = separat + leadingCloseParentheses + newMarkerValue + bodyContent + + val keepMarkers = if (anyNoteModified) { + KEEP_MARKERS + .filter { rawBlockText.contains(it) && !newMarkerValue.contains(it) && !bodyContent.contains(it) } + .joinToString("") + } else "" + + val rawProcessed = separat + leadingCloseParentheses + newMarkerValue + keepMarkers + bodyContent var cleanedProcessed = rawProcessed while (cleanedProcessed.contains("((") || cleanedProcessed.contains("))")) { diff --git a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/SolfaLabels.kt b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/SolfaLabels.kt new file mode 100644 index 0000000..2ed763e --- /dev/null +++ b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/SolfaLabels.kt @@ -0,0 +1,34 @@ +package mg.dot.feufaro.solfa + + +object SolfaLabels { + private val LABELS: Map = mapOf( + "d" to "DÔ", + "di" to "DI", + "r" to "RÉ", + "ri" to "RI", + "m" to "MI", + "f" to "FA", + "fi" to "FI", + "s" to "SÔ", + "si" to "SI", + "l" to "LA", + "ta" to "TA", + "t" to "TI", + ) + fun toLabels(text: String): String { + return LABELS.entries + .sortedByDescending { it.key.length } + .fold(text) { result, (key, value) -> + result.replace(key, value) + } + } + + fun extraChars(text: String, endExclusive: Int): Int { + val prefix = text.take(endExclusive.coerceAtLeast(0)) + + return LABELS.keys.sumOf { key -> + prefix.windowed(key.length).count { it == key } * (key.length - 1) + } + } +} \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/TimeUnitObject.kt b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/TimeUnitObject.kt index d630900..57e1605 100644 --- a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/TimeUnitObject.kt +++ b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/TimeUnitObject.kt @@ -141,6 +141,8 @@ class TimeUnitObject (val pTemplate: PTemplate, val prevTUO: TimeUnitObject?, co fun isTriolet(): Boolean { return pTemplate.hasMarker($$"$T") } + fun isLitany(): Boolean = pTemplate.hasMarker($$"${L}") + fun addLyrics(lyricsIn: POneStanzaLyrics) { lyrics.add(lyricsIn) } @@ -311,11 +313,15 @@ fun TimeUnitComposable( ) val focusRequesters = remember { List(4) { FocusRequester() } } + val isLitany = tuo.isLitany() // Mettre en cache les annotations et les chaînes transposées - val multiLineText = remember(tuo, transpositionInterval) { - val notes = tuo.noteAsMultiString() - Transpose.transposeText(text = notes, interval = transpositionInterval) + val rawText = remember(tuo, transpositionInterval) { + Transpose.transposeText(text = tuo.noteAsMultiString(), interval = transpositionInterval) + } + val rawLines = remember(rawText) { rawText.lines() } + val multiLineText = remember(rawText, isLitany) { + if (isLitany) SolfaLabels.toLabels(rawText) else rawText } val annotationsCache = remember(tuo, transpositionInterval) { @@ -368,9 +374,11 @@ fun TimeUnitComposable( val leftMarginUnderline = with(currentDensity) { leftMarginUnderlineDp.toPx() } + val rawLine = rawLines.getOrNull(ta.voiceNumber - 1).orEmpty() + fun shifted(idx: Int) = if (isLitany) idx + SolfaLabels.extraChars(rawLine, idx) else idx if (us.x > -1) { val lineGlobalStartOffset = textLayoutResult?.getLineStart(ta.voiceNumber - 1) ?: 0 - val globalStartIndex = lineGlobalStartOffset + us.x + val globalStartIndex = lineGlobalStartOffset + shifted(us.x) xStart = textLayoutResult?.getCursorRect(globalStartIndex)?.left ?: 0f if (us.isNewParen) { xStart += leftMarginUnderline @@ -380,7 +388,7 @@ fun TimeUnitComposable( if (us.y > -1 ) { val lineGlobalStartOffset = textLayoutResult?.getLineStart(ta.voiceNumber - 1) ?: 0 // don't ask me why + 1 here makes it work, but it works. - val globalEndIndex = min(lineGlobalStartOffset + us.y + separatorLength + 1, multiLineText.length) + val globalEndIndex = min(lineGlobalStartOffset + shifted(us.y + separatorLength + 1), multiLineText.length) xEnd = textLayoutResult?.getCursorRect(globalEndIndex)?.right ?: size.width } @@ -470,8 +478,10 @@ fun bestTUOWidth( // println("=== [DEBUG TUO] Début mesure de ${items.size} blocs TUO ===") items.forEach { tuo -> - val rawNotes = tuo.noteAsMultiString() - val transposedNotes = Transpose.transposeText(text = rawNotes, interval = transpositionInterval) + val rawNotes = Transpose.transposeText( + text = tuo.noteAsMultiString(), interval = transpositionInterval + ) + val transposedNotes = if (tuo.isLitany()) SolfaLabels.toLabels(rawNotes) else rawNotes val noteLines = transposedNotes.lines() var maxNoteWidthPx = 0