Implements litanies visual partition for ${L} marker
This commit is contained in:
parent
c846552574
commit
7d1e02078f
4 changed files with 66 additions and 9 deletions
|
|
@ -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")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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("))")) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
package mg.dot.feufaro.solfa
|
||||
|
||||
|
||||
object SolfaLabels {
|
||||
private val LABELS: Map<String, String> = 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue