Validate first song key
This commit is contained in:
parent
df72c0b755
commit
b935c7d8f0
1 changed files with 10 additions and 4 deletions
|
|
@ -2360,10 +2360,16 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
|
|||
meta[subKey] = line.substring(2)
|
||||
}
|
||||
if ("c" == subKey) {
|
||||
val tonality = line.uppercaseFirstMeta()
|
||||
meta["C"] = tonality
|
||||
sharedScreenModel.setSongKey(tonality)
|
||||
sharedScreenModel.setTransposeAsIf(tonality)
|
||||
val validKeys = Transpose.keyToNumber.sortedByDescending { it.length }
|
||||
val keyRegex = Regex("\\b(${validKeys.joinToString("|")})\\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) {
|
||||
meta["C"] = tonality
|
||||
sharedScreenModel.setSongKey(tonality)
|
||||
sharedScreenModel.setTransposeAsIf(tonality)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue