diff --git a/composeApp/src/androidMain/kotlin/mg/dot/feufaro/midi/MidiPlayer.kt b/composeApp/src/androidMain/kotlin/mg/dot/feufaro/midi/MidiPlayer.kt index 3151d9b..718060c 100644 --- a/composeApp/src/androidMain/kotlin/mg/dot/feufaro/midi/MidiPlayer.kt +++ b/composeApp/src/androidMain/kotlin/mg/dot/feufaro/midi/MidiPlayer.kt @@ -424,11 +424,11 @@ actual class FMediaPlayer actual constructor( } } } - val currentGrid = (currentTickPos / resolution).toLong() if (boundModel?.activeIndex?.value != currentGrid.toInt()) { - boundModel?.updateActiveIndex(currentGrid) + boundModel?.updateActiveIndexByIndex(currentGrid.toInt()) } + //println("C= ${currentGrid.toInt()} et shrd ${boundModel?.activeIndex?.value}") idx++ } } @@ -802,13 +802,18 @@ actual class FMediaPlayer actual constructor( private fun startSyncLoop(sharedScreenModel: SharedScreenModel) { syncJob?.cancel() syncJob = playerScope.launch(Dispatchers.Default) { + var lastSentGrid = -1 while (isActive) { if (isRunning && !isHolding) { val elapsedNano = System.nanoTime() - lastEventNano val extraTicks = (elapsedNano / (usPerTick * 1000)).toLong().coerceAtLeast(0L) val interpolated = (currentTickPos + extraTicks) / resolution val rawGrid = interpolated.toInt().coerceAtLeast(0) - sharedScreenModel.updateActiveIndexByIndex(rawGrid) + //sharedScreenModel.updateActiveIndexByIndex(rawGrid) + if (interpolated.toInt() >= lastSentGrid) { + lastSentGrid = interpolated.toInt() + sharedScreenModel.updateActiveIndexByIndex(interpolated.toInt()) + } } delay(16) }