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,14 +2361,20 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
|
||||||
}
|
}
|
||||||
if ("c" == subKey) {
|
if ("c" == subKey) {
|
||||||
val validKeys = Transpose.keyToNumber.sortedByDescending { it.length }
|
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 rawText = line.substringAfter("c:")
|
||||||
val matchedKey = keyRegex.find(rawText)?.value
|
val matchResult = keyRegex.find(rawText)
|
||||||
val tonality = Transpose.keyToNumber.firstOrNull { it.equals(matchedKey, ignoreCase = true) }
|
|
||||||
if(tonality != null) {
|
if (matchResult != null) {
|
||||||
meta["C"] = tonality
|
val rawBaseKey = matchResult.groupValues[1]
|
||||||
sharedScreenModel.setSongKey(tonality)
|
val hasMinor = matchResult.groupValues[2].isNotEmpty()
|
||||||
sharedScreenModel.setTransposeAsIf(tonality)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue