Support "DSFin" marker on MidiPlayer - desktop
This commit is contained in:
parent
3a14870ed3
commit
790ed83ddc
2 changed files with 83 additions and 120 deletions
|
|
@ -487,6 +487,11 @@ class SharedScreenModel(private val fileRepository: FileRepository) : ScreenMode
|
|||
// val timestamps = _tuoTimestamps.value
|
||||
val tuos = _tuoList.value.drop(1)
|
||||
|
||||
val hasDCDS = rawList.any { midiMarker ->
|
||||
midiMarker.marker.any { text ->
|
||||
text.contains(Regex("""D\.?C\.?|D\.?S\.?""", RegexOption.IGNORE_CASE))
|
||||
}
|
||||
}
|
||||
val finalizedList = rawList.map { marker ->
|
||||
val originalMarker = marker.marker
|
||||
var currentMarker = marker
|
||||
|
|
@ -499,94 +504,57 @@ class SharedScreenModel(private val fileRepository: FileRepository) : ScreenMode
|
|||
val isNearEnd = index >= (tuos.size - 2)
|
||||
// println("MARKERS:> $markerText\n")
|
||||
|
||||
val isDC = markerText.contains(Regex("""D\.?C\.?"""))
|
||||
val isDS = markerText.contains(Regex("""D\.?S\.?"""))
|
||||
val isFarany = markerText.trim().contains(Regex("""^(fine|fin|farany|end)$""", RegexOption.IGNORE_CASE))
|
||||
val isDC = markerText.trim().matches(Regex("""D\.?C\.?"""))
|
||||
val isDS = markerText.trim().matches(Regex("""D\.?S\.?"""))
|
||||
val isFarany = markerText.trim().matches(Regex("""^(fine|fin|farany|end)$""", RegexOption.IGNORE_CASE))
|
||||
val isDSFin = markerText.trim().contains(Regex("""D\.?S\.?""", RegexOption.IGNORE_CASE)) && markerText.trim().contains(Regex("""(fine|fin|farany|end)""", RegexOption.IGNORE_CASE))
|
||||
val isRit = Regex("""rit\.?|ritard\.?|ritenuto\.?|ritardando""", RegexOption.IGNORE_CASE)
|
||||
val isRall = Regex("""rall\.?|rallent\.?|rallentando""", RegexOption.IGNORE_CASE)
|
||||
|
||||
if (isFarany) {
|
||||
var forwardIndex = index
|
||||
while (forwardIndex < tuos.size) {
|
||||
if (tuos.getOrNull(forwardIndex)?.sep0 == "/") {
|
||||
newGridIndex = forwardIndex - 1
|
||||
newMarkerList.add("Farany_GROUP_PART")
|
||||
break
|
||||
}
|
||||
forwardIndex++
|
||||
}
|
||||
println("Farany finalisé : grille $index → ${forwardIndex - 1}")
|
||||
} else if (isDC) {
|
||||
var found = false
|
||||
var forwardIndex = index
|
||||
while (forwardIndex < tuos.size) {
|
||||
if (tuos.getOrNull(forwardIndex)?.sep0 == "/") {
|
||||
newGridIndex = forwardIndex - 1
|
||||
newMarkerList.add("${markerText.trim()}_GROUP_PART")
|
||||
println("DC gp finalisé grille $newGridIndex")
|
||||
found = true
|
||||
break
|
||||
}
|
||||
forwardIndex++
|
||||
}
|
||||
if (!found) {
|
||||
newMarkerList.add(markerText)
|
||||
}
|
||||
} else if (isDS && isNearEnd) {
|
||||
val currentNote = tuos.getOrNull(index)?.tuNotes?.getOrNull(1)?.toString() ?: ""
|
||||
val nextNote = tuos.getOrNull(index + 1)?.tuNotes?.getOrNull(1)?.toString() ?: ""
|
||||
var searchIndex = index + 1
|
||||
var lastValidIndex = index
|
||||
|
||||
if (currentNote.isBlank() && nextNote.isBlank()) {
|
||||
var backwardIndex = index - 1
|
||||
while (backwardIndex >= 0) {
|
||||
if (tuos.getOrNull(backwardIndex)?.tuNotes?.getOrNull(1)?.toString()?.isNotBlank() == true) {
|
||||
newGridIndex = backwardIndex
|
||||
newMarkerList.add("${if (markerText.trim() == "DSFin") "DS" else markerText.trim()}_GROUP_PART")
|
||||
println("DS finalisé grille $newGridIndex")
|
||||
break
|
||||
while (searchIndex < tuos.size && tuos.getOrNull(searchIndex)?.tuNotes?.getOrNull(1)?.toString() == "―") {
|
||||
lastValidIndex = searchIndex
|
||||
searchIndex++
|
||||
}
|
||||
backwardIndex--
|
||||
|
||||
val targetIndex = if (lastValidIndex > index) lastValidIndex else index
|
||||
|
||||
when {
|
||||
isDSFin -> {
|
||||
newGridIndex = targetIndex
|
||||
newMarkerList.add("${markerText.trim()}")
|
||||
}
|
||||
isFarany -> {
|
||||
newGridIndex = if(hasDCDS) {
|
||||
targetIndex
|
||||
} else {
|
||||
var forwardIndex = index
|
||||
while (forwardIndex < tuos.size) {
|
||||
if (tuos.getOrNull(forwardIndex)?.sep0 == "/") {
|
||||
newGridIndex = forwardIndex
|
||||
newMarkerList.add("${if (markerText.trim() == "DSFin") "DS" else markerText.trim()}_GROUP_PART")
|
||||
println("DS gp finalisé grille $newGridIndex")
|
||||
break
|
||||
index
|
||||
}
|
||||
forwardIndex++
|
||||
newMarkerList.add("Farany")
|
||||
}
|
||||
isDC -> {
|
||||
newGridIndex = targetIndex
|
||||
newMarkerList.add("${markerText.trim()}")
|
||||
}
|
||||
} else if (isRit.containsMatchIn(markerText)) {
|
||||
var forwardIndex = index + 1
|
||||
while (forwardIndex < tuos.size) {
|
||||
if (tuos.getOrNull(forwardIndex)?.sep0 == "/") {
|
||||
currentMarker = currentMarker.copy(lastCallerMarker = forwardIndex - 1)
|
||||
isDS -> {
|
||||
newGridIndex = targetIndex
|
||||
newMarkerList.add("${markerText.trim()}")
|
||||
}
|
||||
isRit.containsMatchIn(markerText) -> {
|
||||
currentMarker = currentMarker.copy(lastCallerMarker = targetIndex)
|
||||
newMarkerList.add("Ritenuto")
|
||||
break
|
||||
}
|
||||
forwardIndex++
|
||||
}
|
||||
println("Rit finalisé : grille $index → ${forwardIndex - 1}")
|
||||
|
||||
} else if (isRall.containsMatchIn(markerText)) {
|
||||
var forwardIndex = index + 1
|
||||
while (forwardIndex < tuos.size) {
|
||||
if (tuos.getOrNull(forwardIndex)?.sep0 == "/") {
|
||||
currentMarker = currentMarker.copy(lastCallerMarker = forwardIndex - 1)
|
||||
isRall.containsMatchIn(markerText) -> {
|
||||
currentMarker = currentMarker.copy(lastCallerMarker = targetIndex)
|
||||
newMarkerList.add("Rallentando")
|
||||
break
|
||||
}
|
||||
forwardIndex++
|
||||
}
|
||||
println("Rall finalisé : grille $index → ${forwardIndex - 1}")
|
||||
|
||||
} else {
|
||||
else -> {
|
||||
newMarkerList.add(markerText)
|
||||
}
|
||||
}
|
||||
}
|
||||
currentMarker.copy(
|
||||
gridIndex = newGridIndex,
|
||||
marker = newMarkerList
|
||||
|
|
@ -760,7 +728,7 @@ class SharedScreenModel(private val fileRepository: FileRepository) : ScreenMode
|
|||
fun setStanza(theStanza: Int) {
|
||||
try {
|
||||
_stanza.value = theStanza
|
||||
_showMidiCtrl.value = false
|
||||
_mediaPlayer?.syncNavigationMonitor(this)
|
||||
} catch (e: NumberFormatException) {
|
||||
_stanza.value = 0
|
||||
}
|
||||
|
|
|
|||
|
|
@ -267,9 +267,37 @@ actual class FMediaPlayer actual constructor(
|
|||
val dcGPattern = Regex("""D\.?C\.?_GROUP_PART""")
|
||||
val finReg = Regex("""(fine|fin|farany|end)""", RegexOption.IGNORE_CASE)
|
||||
|
||||
markerList.forEach { marker ->
|
||||
var i = 0
|
||||
while(i < markerList.size) {
|
||||
val marker = markerList[i]
|
||||
val mTrim = marker.trim()
|
||||
val nextTrim = markerList.getOrNull(i + 1)?.trim() ?: ""
|
||||
|
||||
val hasDs = dsRegex.containsMatchIn(mTrim)
|
||||
val hasDc = dcRegex.containsMatchIn(mTrim)
|
||||
val hasFin = finReg.containsMatchIn(mTrim)
|
||||
|
||||
val isDsFin = (dsRegex.containsMatchIn(mTrim) && finReg.containsMatchIn(nextTrim))
|
||||
val isDcFin = (dcRegex.containsMatchIn(mTrim) && finReg.containsMatchIn(nextTrim))
|
||||
|
||||
when {
|
||||
//DSFin
|
||||
isDsFin || isDcFin -> {
|
||||
val target = if (lastSegno > 0) lastSegno else 0
|
||||
val combinedMarker = "$mTrim$nextTrim"
|
||||
|
||||
navigationSteps.add(
|
||||
NavigationStep(
|
||||
marker = combinedMarker,
|
||||
gridIndex = currentIndex,
|
||||
targetGrid = target
|
||||
)
|
||||
)
|
||||
println("Lien $combinedMarker créé : Saut à $currentIndex vers Segno $target")
|
||||
|
||||
i += 2
|
||||
continue
|
||||
}
|
||||
// segno
|
||||
marker.contains("$") -> {
|
||||
lastSegno = currentIndex
|
||||
|
|
@ -304,6 +332,7 @@ actual class FMediaPlayer actual constructor(
|
|||
)
|
||||
println("Ritardando mémorisé à grille $currentIndex jusqu'à $endGrid")
|
||||
}
|
||||
//Rall
|
||||
rallRegex.containsMatchIn(marker) -> {
|
||||
val endGrid = last_grid
|
||||
|
||||
|
|
@ -319,23 +348,8 @@ actual class FMediaPlayer actual constructor(
|
|||
)
|
||||
println("Rallentando mémorisé à grille $currentIndex jusqu'à $endGrid")
|
||||
}
|
||||
// DS
|
||||
dsGPattern.matches(mTrim) -> {
|
||||
val target = if (lastSegno > 0) lastSegno else 0
|
||||
var indx = if ((last_grid - currentIndex) <= 0) {
|
||||
currentIndex - 1
|
||||
} else currentIndex
|
||||
navigationSteps.add(
|
||||
NavigationStep(
|
||||
marker,
|
||||
gridIndex = indx,
|
||||
targetGrid = target,
|
||||
)
|
||||
)
|
||||
println("Lien créé : $marker à grille n° $indx vers cible $target ........")
|
||||
}
|
||||
|
||||
dsRegex.matches(mTrim) || marker == "DSFin" -> {
|
||||
//DS
|
||||
dsRegex.matches(mTrim) -> {
|
||||
val target = if (lastSegno > 0) lastSegno else 0
|
||||
|
||||
navigationSteps.add(
|
||||
|
|
@ -347,24 +361,8 @@ actual class FMediaPlayer actual constructor(
|
|||
)
|
||||
println("Lien DS créé : Saut immédiat à ${midiMarker.gridIndex} vers Segno $target")
|
||||
}
|
||||
|
||||
// DC
|
||||
dcGPattern.matches(mTrim) -> {
|
||||
val indx = if ((last_grid - currentIndex) <= 0) {
|
||||
currentIndex - 1
|
||||
} else currentIndex
|
||||
// println("monn index est $indx car dernier est $last_grid et curr $currentIndex")
|
||||
navigationSteps.add(
|
||||
NavigationStep(
|
||||
marker,
|
||||
indx,
|
||||
targetGrid = 0
|
||||
)
|
||||
)
|
||||
println("Lien créé : $marker à $indx vers cible 0 ")
|
||||
}
|
||||
|
||||
(dcRegex.matches(mTrim) && !marker.contains("DC_GROUP_PART")) -> {
|
||||
//DC
|
||||
dcRegex.matches(mTrim) -> {
|
||||
println("dernier grille $last_grid")
|
||||
var indx = if ((last_grid - currentIndex) <= 0) {
|
||||
currentIndex /*- 1*/
|
||||
|
|
@ -378,7 +376,6 @@ actual class FMediaPlayer actual constructor(
|
|||
)
|
||||
println("Lien DC créé : $marker à $indx vers le début")
|
||||
}
|
||||
|
||||
// Farany
|
||||
finReg.containsMatchIn(mTrim) -> {
|
||||
val hasDcAfter = metadataList.any { m ->
|
||||
|
|
@ -389,10 +386,7 @@ actual class FMediaPlayer actual constructor(
|
|||
)
|
||||
|
||||
val hasMarker = m.marker.any { mk ->
|
||||
val value = mk.trim()
|
||||
val ok = dcGPattern.matches(value) || dcRegex.matches(value)
|
||||
println("marker=$value -> $ok")
|
||||
ok
|
||||
dcRegex.matches(mk.trim())
|
||||
}
|
||||
|
||||
println("after=$after, hasMarker=$hasMarker, result=${after && hasMarker}")
|
||||
|
|
@ -505,6 +499,7 @@ actual class FMediaPlayer actual constructor(
|
|||
println("NavigationStep HairPin '$symbol' : $currentIndex→${pair.endGrid} | ${fromFactor})→${toFactor})")
|
||||
}
|
||||
}
|
||||
i++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue