Compare commits

..

No commits in common. "94728593088f0264ff5bcce8ea650bde54c6f118" and "22a5ba2c50bd9786b7b8440bf15d5d6c9a5c8725" have entirely different histories.

View file

@ -3,16 +3,13 @@ package mg.dot.feufaro.midi
import SharedScreenModel
import kotlinx.coroutines.*
import mg.dot.feufaro.getConfigDirectoryPath
import mg.dot.feufaro.viewmodel.MidiMarkers
import java.io.File
import java.util.prefs.Preferences
import javax.sound.midi.MetaMessage
import javax.sound.midi.MidiSystem
import javax.sound.midi.Sequence
import javax.sound.midi.Sequencer
import javax.sound.midi.ShortMessage
import javax.sound.midi.Synthesizer
import javax.sound.midi.Track
import javax.sound.sampled.AudioSystem
import javax.sound.sampled.FloatControl
@ -59,6 +56,8 @@ actual class FMediaPlayer actual constructor(
val hairPinEndGrid: Int = -1,
val hairPinFromFactor: Float = 1.0f,
val hairPinToFactor: Float = 1.0f,
val isFin: Boolean = false, // Farany D.C.
var finActive: Boolean =false,
)
private val navigationSteps = mutableListOf<NavigationStep>()
@ -84,9 +83,13 @@ actual class FMediaPlayer actual constructor(
applyVoiceStates()
sequencer?.addMetaEventListener { meta ->
if(meta.type == 47){
val totalGrids = (sequencer!!.sequence.tickLength / sequencer!!.sequence.resolution).toInt()
val currentGrid = (sequencer!!.tickPosition / sequencer!!.sequence.resolution).toInt()
val pendingDc = getPendingDcStep()
if (pendingDc != null) {
val isDcNearEnd = pendingDc != null && (totalGrids - pendingDc.gridIndex) <= 2
if (isDcNearEnd && pendingDc != null) {
println("onFinished : DC pending → saut direct vers ${pendingDc.targetGrid}")
pendingDc.alreadyDone = true
seekToGrid(pendingDc.targetGrid)
@ -281,6 +284,27 @@ actual class FMediaPlayer actual constructor(
println("Lien DC créé : $marker à $indx vers le début")
}
// Farany
marker.trim().equals("Farany_GROUP_PART", ignoreCase = true) -> {
val hasDcAfter = metadataList.any { (_, gi, _, _, mk, _, _, _) ->
(gi ?: 0) > currentIndex &&
(dcGPattern.matches(mk.trim()) ||
dcRegex.matches(mk.trim()))
}
if (hasDcAfter) {
navigationSteps.add(
NavigationStep(
marker = marker,
gridIndex = currentIndex,
targetGrid = last_grid,
isFin = true,
finActive = false
)
)
println("Farany mémorisé à la grille $currentIndex")
}
}
// velocité
extractDynamic(marker) != null && marker.trim() != "=" -> {
val dyn = extractDynamic(marker) ?: return@forEach
@ -362,6 +386,7 @@ actual class FMediaPlayer actual constructor(
step.hairPin == null &&
step.dynamic == null &&
!step.isHold
&& !step.isFin
}
}
private fun startNavigationMonitor(sharedScreenModel: SharedScreenModel) {
@ -389,6 +414,19 @@ actual class FMediaPlayer actual constructor(
if (step != null) {
when {
step.isFin -> {
if(step.finActive) {
step.alreadyDone = true
// println("Farany passage → FIN à grille $currentIndex")
sequencer?.stop()
sequencer?.tempoFactor = 1f
synthetizer?.channels?.forEach {
it?.controlChange(64, 0)
it?.controlChange(123, 0)
}
onFinished()
}
}
// Point d'orgue
step.isHold -> {
val currentBpm = sequencer?.tempoInBPM ?: targetBpm
@ -443,6 +481,14 @@ actual class FMediaPlayer actual constructor(
seekToGrid(step.targetGrid)
synthetizer?.channels?.forEach { it?.controlChange(64, 0) }
sequencer?.tempoFactor = 1f
navigationSteps.filter {
it.isFin
}.forEach {
it.finActive = true
it.alreadyDone = false
}
if (sequencer?.isRunning == false) {
sequencer?.tempoInBPM = targetBpm
sequencer?.start()