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 c93c1e8..20174ac 100644 --- a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/Solfa.kt +++ b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/Solfa.kt @@ -1877,6 +1877,35 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository var anchorNote = ' ' lineRepeated.toCharArray().forEach { if (it == '§') { + val rawSplit = splitBlocks.removeAt(0) + val anchorSuffix = anchor.replace(Regex("^[drmfslt]"), "") + val processedSplit = rawSplit.replace(Regex("\\{([^\\}]+)\\}")) { match -> + val innerContent = match.groupValues[1] + val updatedInner = innerContent.replace(Regex("([drmfsltDRFSTz])([,']*)")) { noteMatch -> + val n = noteMatch.groupValues[1] + val oct = noteMatch.groupValues[2] + var res = n + res += anchorSuffix + if (oct.isEmpty()) { + val noteChar = n[0] + if ( + (anchorNote == 'r' && noteChar in listOf('d', 'D')) + || (anchorNote == 'm' && noteChar in listOf('d', 'D', 'r', 'R')) + || (anchorNote == 'f' && noteChar in listOf('d', 'D', 'r', 'R', 'm', 'M')) + || (anchorNote == 's' && noteChar !in listOf('s', 'S', 'l', 'L', 't', 'T')) + || (anchorNote == 'l' && noteChar !in listOf('l', 'L', 't', 'T')) + || (anchorNote == 't' && noteChar !in listOf('t', 'T')) + ) { + res += '\'' + } + } else { + res += oct + } + res.replace(",'", "").replace("',", "").replace(",'", "").replace("',", "") + } + "{$updatedInner}" + } + splitBlocks.add(processedSplit) noteChar2 += "§" return@forEach }