Validate first song key, with support minor key
This commit is contained in:
parent
b935c7d8f0
commit
640be8edb5
1 changed files with 13 additions and 7 deletions
|
|
@ -2361,17 +2361,23 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
|
|||
}
|
||||
if ("c" == subKey) {
|
||||
val validKeys = Transpose.keyToNumber.sortedByDescending { it.length }
|
||||
val keyRegex = Regex("\\b(${validKeys.joinToString("|")})\\b", RegexOption.IGNORE_CASE)
|
||||
val keyRegex = Regex("\\b(${validKeys.joinToString("|")})(m)?\\b", RegexOption.IGNORE_CASE)
|
||||
val rawText = line.substringAfter("c:")
|
||||
val matchedKey = keyRegex.find(rawText)?.value
|
||||
val tonality = Transpose.keyToNumber.firstOrNull { it.equals(matchedKey, ignoreCase = true) }
|
||||
if(tonality != null) {
|
||||
val matchResult = keyRegex.find(rawText)
|
||||
|
||||
if (matchResult != null) {
|
||||
val rawBaseKey = matchResult.groupValues[1]
|
||||
val hasMinor = matchResult.groupValues[2].isNotEmpty()
|
||||
val baseTonality = Transpose.keyToNumber.firstOrNull { it.equals(rawBaseKey, ignoreCase = true) }
|
||||
if (baseTonality != null) {
|
||||
val tonality = if (hasMinor) "${baseTonality}m" else baseTonality
|
||||
meta["C"] = tonality
|
||||
sharedScreenModel.setSongKey(tonality)
|
||||
sharedScreenModel.setTransposeAsIf(tonality)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun String.uppercaseFirstMeta(): String {
|
||||
if (this.length < 2) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue