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 T: MutableList<PTemplate> = mutableListOf()
|
||||||
private val N: MutableList<POneVoiceNote> = mutableListOf()
|
private val N: MutableList<POneVoiceNote> = mutableListOf()
|
||||||
private val L: MutableList<POneStanzaLyrics> = mutableListOf()
|
private val L: MutableList<POneStanzaLyrics> = mutableListOf()
|
||||||
|
private val O: MutableMap<Int, MutableList<String>> = mutableMapOf()
|
||||||
private val unparsedNote = mutableListOf<String>()
|
private val unparsedNote = mutableListOf<String>()
|
||||||
private var refrainBeginsAt = -1
|
private var refrainBeginsAt = -1
|
||||||
companion object {
|
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 = Regex("([aeio])_([nm])([tdjkbp])")
|
||||||
val REGEX_MALAGASY_MN_STAGE2 = Regex("_([mn])-")
|
val REGEX_MALAGASY_MN_STAGE2 = Regex("_([mn])-")
|
||||||
val REGEX_PAREN_RECURSIVE = Regex("(\\([^\\(\\)]*)\\(([^\\)]*)\\)")
|
val REGEX_PAREN_RECURSIVE = Regex("(\\([^\\(\\)]*)\\(([^\\)]*)\\)")
|
||||||
|
val REGEX_COMMENT = Regex("\\$\\{[^\\}]*\\}")
|
||||||
}
|
}
|
||||||
var nextTIndex: Int = -1
|
var nextTIndex: Int = -1
|
||||||
var nextNIndex: Int = -1
|
var nextNIndex: Int = -1
|
||||||
|
|
@ -269,14 +271,15 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
|
||||||
value = line.trim().substring(3)
|
value = line.trim().substring(3)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key != "") {
|
when (key) {
|
||||||
if ((key == "T") && (index == 0)) {
|
"T" -> if (index == 0) {
|
||||||
loadT(value)
|
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
|
// 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.
|
// pour bien gérer les parenthèses.
|
||||||
unparsedNote.add(index.toString()+value)
|
unparsedNote.add(index.toString()+value)
|
||||||
} else if (key == "M") {
|
"M" -> {
|
||||||
val metaChunks: List<String> = value.split(REGEX_PARSE_META)
|
val metaChunks: List<String> = value.split(REGEX_PARSE_META)
|
||||||
metaChunks.forEach { parseMeta(it) }
|
metaChunks.forEach { parseMeta(it) }
|
||||||
parseMeta(value)
|
parseMeta(value)
|
||||||
|
|
@ -285,17 +288,18 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
|
||||||
sharedScreenModel.setSongAuthor(meta["a"] ?: "")
|
sharedScreenModel.setSongAuthor(meta["a"] ?: "")
|
||||||
sharedScreenModel.setSongComposer(meta["h"] ?: "")
|
sharedScreenModel.setSongComposer(meta["h"] ?: "")
|
||||||
sharedScreenModel.setSongRhythm(meta["r"] ?: "")
|
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()
|
val parsedULine = uObject.parsed()
|
||||||
loadT(parsedULine)
|
loadT(parsedULine)
|
||||||
}
|
}
|
||||||
|
fun loadO(index:Int, line:String) {
|
||||||
|
O.getOrPut(index) { mutableListOf() }.add(line)
|
||||||
|
}
|
||||||
fun parseMeta(line: String) {
|
fun parseMeta(line: String) {
|
||||||
/* $_a_keyAbbrev = array(
|
/* $_a_keyAbbrev = array(
|
||||||
'a' => 'author',
|
'a' => 'author',
|
||||||
|
|
@ -430,16 +437,21 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
|
||||||
private fun loadL(stanzaNumber: Int, lyrics: String) {
|
private fun loadL(stanzaNumber: Int, lyrics: String) {
|
||||||
try {
|
try {
|
||||||
getLyricsComments(lyrics)
|
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 ->
|
.replace(REGEX_LYRICS_REPETITION) { matchResult ->
|
||||||
val repeating = matchResult.destructured.match.groupValues[1]
|
val repeating = matchResult.destructured.match.groupValues[1]
|
||||||
"_".repeat(repeating.toString().toInt())
|
"_".repeat(repeating.toString().toInt())
|
||||||
}
|
}
|
||||||
//.replace("/", "_")
|
|
||||||
.addHyphens()
|
.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 ->
|
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!}")) {
|
if (refrainBeginsAt > 0 && stanzaNumber > 1 && !lyrics.contains($$"${R!}")) {
|
||||||
copyRefrainToStanza(stanzaNumber)
|
copyRefrainToStanza(stanzaNumber)
|
||||||
|
|
@ -449,6 +461,7 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
|
||||||
val lyricsIterator = lyricsComment.iterator()
|
val lyricsIterator = lyricsComment.iterator()
|
||||||
while (lyricsIterator.hasNext()) {
|
while (lyricsIterator.hasNext()) {
|
||||||
val item = lyricsIterator.next()
|
val item = lyricsIterator.next()
|
||||||
|
// @todo: if item == ${O:...}
|
||||||
// ${D:xxx} lyrics of DC and DSs
|
// ${D:xxx} lyrics of DC and DSs
|
||||||
if (item.substring(0, 4) == $$"${D:") {
|
if (item.substring(0, 4) == $$"${D:") {
|
||||||
item.replace(REGEX_LYRICS_COMMENT, "$2")
|
item.replace(REGEX_LYRICS_COMMENT, "$2")
|
||||||
|
|
@ -469,16 +482,14 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
|
||||||
}
|
}
|
||||||
lyricsComment.clear()
|
lyricsComment.clear()
|
||||||
}
|
}
|
||||||
// loadY is a smart lyrics parser for Malagasy language
|
fun smartYLyrics(lyrics: String): String {
|
||||||
private fun loadY(intKey: Int, lyrics: 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
|
val loadedLyrics = lyrics
|
||||||
.also { println(it)}
|
|
||||||
.replace(REGEX_VOWELS_STAGE1, "$0_")
|
.replace(REGEX_VOWELS_STAGE1, "$0_")
|
||||||
.also { println(it)}
|
|
||||||
.replace(REGEX_VOWELS_STAGE2, "$1_")
|
.replace(REGEX_VOWELS_STAGE2, "$1_")
|
||||||
.also { println(it)}
|
|
||||||
.replace(REGEX_VOWELS_STAGE3, "$1_")
|
.replace(REGEX_VOWELS_STAGE3, "$1_")
|
||||||
.also { println(it)}
|
|
||||||
.replace(" ", " _")
|
.replace(" ", " _")
|
||||||
.replace("_\\ _", " ")
|
.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, "$1$2_$3")
|
||||||
.replace(REGEX_MALAGASY_MN_STAGE2, "$1-_")
|
.replace(REGEX_MALAGASY_MN_STAGE2, "$1-_")
|
||||||
.replace("_n'", "n'_")
|
.replace("_n'", "n'_")
|
||||||
loadL(intKey, loadedLyrics)
|
// Et remettons les valeurs originales de ${...}
|
||||||
|
val lyricsFinal = REGEX_COMMENT.replace(loadedLyrics) { matchResult ->
|
||||||
|
commentsIterator.next().value
|
||||||
}
|
}
|
||||||
// loadE is a smart Lyrics parser for English language
|
return lyricsFinal
|
||||||
private fun loadE(intKey: Int, lyrics: String) {
|
}
|
||||||
|
// loadY is a smart lyrics parser for Malagasy language
|
||||||
|
private fun loadY(intKey: Int, lyrics: String) {
|
||||||
|
val smartLyrics = smartYLyrics(lyrics)
|
||||||
|
loadL(intKey, smartLyrics)
|
||||||
|
}
|
||||||
|
fun smartELyrics(lyrics: String): String {
|
||||||
val loadedLyrics = lyrics
|
val loadedLyrics = lyrics
|
||||||
.replace(" ", " _")
|
.replace(" ", " _")
|
||||||
.replace("\\ _", " ")
|
.replace("\\ _", " ")
|
||||||
|
|
@ -498,7 +517,12 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
|
||||||
.replace("_/", "/")
|
.replace("_/", "/")
|
||||||
.replace("_0", "")
|
.replace("_0", "")
|
||||||
getLyricsComments(loadedLyrics)
|
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) {
|
private fun getLyricsComments(lyrics: String) {
|
||||||
val matchResult = REGEX_LYRICS_COMMENT.findAll(lyrics)
|
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