move smartELyrics and smartYLyrics out from loadE and loadY
This commit is contained in:
parent
0941cc674c
commit
16edf13981
1 changed files with 52 additions and 31 deletions
|
|
@ -11,6 +11,7 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
|
|||
private val T: MutableList<PTemplate> = mutableListOf()
|
||||
private val N: MutableList<POneVoiceNote> = mutableListOf()
|
||||
private val L: MutableList<POneStanzaLyrics> = mutableListOf()
|
||||
private val O: MutableMap<Int, MutableList<String>> = mutableMapOf()
|
||||
private val unparsedNote = mutableListOf<String>()
|
||||
private var refrainBeginsAt = -1
|
||||
companion object {
|
||||
|
|
@ -31,6 +32,7 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
|
|||
val REGEX_MALAGASY_MN = Regex("([aeio])_([nm])([tdjkbp])")
|
||||
val REGEX_MALAGASY_MN_STAGE2 = Regex("_([mn])-")
|
||||
val REGEX_PAREN_RECURSIVE = Regex("(\\([^\\(\\)]*)\\(([^\\)]*)\\)")
|
||||
val REGEX_COMMENT = Regex("\\$\\{[^\\}]*\\}")
|
||||
}
|
||||
var nextTIndex: Int = -1
|
||||
var nextNIndex: Int = -1
|
||||
|
|
@ -269,14 +271,15 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
|
|||
value = line.trim().substring(3)
|
||||
}
|
||||
|
||||
if (key != "") {
|
||||
if ((key == "T") && (index == 0)) {
|
||||
when (key) {
|
||||
"T" -> if (index == 0) {
|
||||
loadT(value)
|
||||
} else if (key == "N") {
|
||||
}
|
||||
"N" ->
|
||||
// Les lignes de type N seront parsées à la fin. preloadN() se chargera d'abord de réarranger la ligne
|
||||
// pour bien gérer les parenthèses.
|
||||
unparsedNote.add(index.toString()+value)
|
||||
} else if (key == "M") {
|
||||
"M" -> {
|
||||
val metaChunks: List<String> = value.split(REGEX_PARSE_META)
|
||||
metaChunks.forEach { parseMeta(it) }
|
||||
parseMeta(value)
|
||||
|
|
@ -285,17 +288,18 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
|
|||
sharedScreenModel.setSongAuthor(meta["a"] ?: "")
|
||||
sharedScreenModel.setSongComposer(meta["h"] ?: "")
|
||||
sharedScreenModel.setSongRhythm(meta["r"] ?: "")
|
||||
} else if (key == "L") {
|
||||
loadL(index, value)
|
||||
} else if (key == "Y") {
|
||||
loadY(index, value)
|
||||
} else if (key == "E") {
|
||||
loadE(index, value)
|
||||
} else if (key == "U") {
|
||||
loadU(value)
|
||||
} else {
|
||||
//setData(key, index, value)
|
||||
}
|
||||
"L" ->
|
||||
loadL(index, value)
|
||||
"Y" ->
|
||||
loadY(index, value)
|
||||
"E" ->
|
||||
loadE(index, value)
|
||||
"U" ->
|
||||
loadU(value)
|
||||
"O" ->
|
||||
loadO(index, value)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -374,6 +378,9 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
|
|||
val parsedULine = uObject.parsed()
|
||||
loadT(parsedULine)
|
||||
}
|
||||
fun loadO(index:Int, line:String) {
|
||||
O.getOrPut(index) { mutableListOf() }.add(line)
|
||||
}
|
||||
fun parseMeta(line: String) {
|
||||
/* $_a_keyAbbrev = array(
|
||||
'a' => 'author',
|
||||
|
|
@ -430,16 +437,21 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
|
|||
private fun loadL(stanzaNumber: Int, lyrics: String) {
|
||||
try {
|
||||
getLyricsComments(lyrics)
|
||||
val loadedLyrics = lyrics.replace(REGEX_LYRICS_COMMENT, "")
|
||||
val comments = REGEX_COMMENT.findAll(lyrics)
|
||||
val commentsIterator = comments.iterator()
|
||||
val loadedLyrics = lyrics//.replace(REGEX_LYRICS_COMMENT, "")
|
||||
.replace(REGEX_LYRICS_REPETITION) { matchResult ->
|
||||
val repeating = matchResult.destructured.match.groupValues[1]
|
||||
"_".repeat(repeating.toString().toInt())
|
||||
}
|
||||
//.replace("/", "_")
|
||||
.addHyphens()
|
||||
val arrayLyrics = loadedLyrics.split(Regex("[/_]"))
|
||||
val lyricsFinal = REGEX_COMMENT.replace(loadedLyrics) { matchResult ->
|
||||
commentsIterator.next().value
|
||||
}
|
||||
val arrayLyrics = lyricsFinal.split(Regex("[/_]"))
|
||||
arrayLyrics.forEachIndexed { i, lyricsItem ->
|
||||
addLyricsItem(stanzaNumber, i, lyricsItem)
|
||||
val originalLyrics = REGEX_COMMENT.replace(lyricsItem, "")
|
||||
addLyricsItem(stanzaNumber, i, originalLyrics)
|
||||
}
|
||||
if (refrainBeginsAt > 0 && stanzaNumber > 1 && !lyrics.contains($$"${R!}")) {
|
||||
copyRefrainToStanza(stanzaNumber)
|
||||
|
|
@ -449,6 +461,7 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
|
|||
val lyricsIterator = lyricsComment.iterator()
|
||||
while (lyricsIterator.hasNext()) {
|
||||
val item = lyricsIterator.next()
|
||||
// @todo: if item == ${O:...}
|
||||
// ${D:xxx} lyrics of DC and DSs
|
||||
if (item.substring(0, 4) == $$"${D:") {
|
||||
item.replace(REGEX_LYRICS_COMMENT, "$2")
|
||||
|
|
@ -469,16 +482,14 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
|
|||
}
|
||||
lyricsComment.clear()
|
||||
}
|
||||
// loadY is a smart lyrics parser for Malagasy language
|
||||
private fun loadY(intKey: Int, lyrics: String) {
|
||||
fun smartYLyrics(lyrics: String): String {
|
||||
// Les ${O:1} risquent de changer en ${O:_1}. Sauvegardons-les dans comments.
|
||||
val comments = REGEX_COMMENT.findAll(lyrics)
|
||||
val commentsIterator = comments.iterator()
|
||||
val loadedLyrics = lyrics
|
||||
.also { println(it)}
|
||||
.replace(REGEX_VOWELS_STAGE1, "$0_")
|
||||
.also { println(it)}
|
||||
.replace(REGEX_VOWELS_STAGE2, "$1_")
|
||||
.also { println(it)}
|
||||
.replace(REGEX_VOWELS_STAGE3, "$1_")
|
||||
.also { println(it)}
|
||||
.replace(" ", " _")
|
||||
.replace("_\\ _", " ")
|
||||
.replace("_\\", "")
|
||||
|
|
@ -487,10 +498,18 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
|
|||
.replace(REGEX_MALAGASY_MN, "$1$2_$3")
|
||||
.replace(REGEX_MALAGASY_MN_STAGE2, "$1-_")
|
||||
.replace("_n'", "n'_")
|
||||
loadL(intKey, loadedLyrics)
|
||||
// Et remettons les valeurs originales de ${...}
|
||||
val lyricsFinal = REGEX_COMMENT.replace(loadedLyrics) { matchResult ->
|
||||
commentsIterator.next().value
|
||||
}
|
||||
return lyricsFinal
|
||||
}
|
||||
// loadY is a smart lyrics parser for Malagasy language
|
||||
private fun loadY(intKey: Int, lyrics: String) {
|
||||
val smartLyrics = smartYLyrics(lyrics)
|
||||
loadL(intKey, smartLyrics)
|
||||
}
|
||||
// loadE is a smart Lyrics parser for English language
|
||||
private fun loadE(intKey: Int, lyrics: String) {
|
||||
fun smartELyrics(lyrics: String): String {
|
||||
val loadedLyrics = lyrics
|
||||
.replace(" ", " _")
|
||||
.replace("\\ _", " ")
|
||||
|
|
@ -498,7 +517,12 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
|
|||
.replace("_/", "/")
|
||||
.replace("_0", "")
|
||||
getLyricsComments(loadedLyrics)
|
||||
loadL(intKey, loadedLyrics.replace(REGEX_LYRICS_COMMENT, ""))
|
||||
return loadedLyrics
|
||||
}
|
||||
// loadE is a smart Lyrics parser for English language
|
||||
private fun loadE(intKey: Int, lyrics: String) {
|
||||
val smartLyrics = smartELyrics(lyrics)
|
||||
loadL(intKey, smartLyrics)
|
||||
}
|
||||
private fun getLyricsComments(lyrics: String) {
|
||||
val matchResult = REGEX_LYRICS_COMMENT.findAll(lyrics)
|
||||
|
|
@ -536,6 +560,3 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
|
|||
}
|
||||
}
|
||||
}
|
||||
fun getOpt(x: String) : String {
|
||||
return ""
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue