From e02afb3580a17cb48dac2bcd1c79cf6eab12dd84 Mon Sep 17 00:00:00 2001 From: "hasinarak3@gmail.com" Date: Tue, 17 Feb 2026 10:58:03 +0300 Subject: [PATCH] Wait user to clic play btn to allow upd position on partition --- .../dot/feufaro/viewmodel/SharedScreenModel.kt | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/viewmodel/SharedScreenModel.kt b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/viewmodel/SharedScreenModel.kt index bf785d8..946ca5b 100644 --- a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/viewmodel/SharedScreenModel.kt +++ b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/viewmodel/SharedScreenModel.kt @@ -119,6 +119,9 @@ class SharedScreenModel(private val fileRepository: FileRepository) : ScreenMode private val _isPlayMid = MutableStateFlow(false) val isPlayMid = _isPlayMid.asStateFlow() + private val _canUpdPositionFromPartition = MutableStateFlow(false) + val canUpdPositionFromPartition = _canUpdPositionFromPartition.asStateFlow() + fun loadNewSong(newMidiFile: String) { _mediaPlayer?.stop() @@ -143,6 +146,7 @@ class SharedScreenModel(private val fileRepository: FileRepository) : ScreenMode } fun togglePlayPause() { + _canUpdPositionFromPartition.value=true _mediaPlayer?.let { player -> if (_isPlay.value) { _isPlay.value = false @@ -196,12 +200,14 @@ class SharedScreenModel(private val fileRepository: FileRepository) : ScreenMode var currentNoteIndex by mutableStateOf(0f) fun updatePositionFromPartition(index: Int, totalRow: Int) { - val duration = _duration.value - if(totalRow > 0) { - currentNoteIndex = index.toFloat() - val newPos = (currentNoteIndex / totalRow.toFloat()) * duration - seekTo(newPos) - println("Shared:196 currentNoteIndex $currentNoteIndex, Index $index et curret = ${_currentPos.value}") + if(_canUpdPositionFromPartition.value) { /*upd pos part only if midi on playing*/ + val duration = _duration.value + if(totalRow > 0) { + currentNoteIndex = index.toFloat() + val newPos = (currentNoteIndex / totalRow.toFloat()) * duration + seekTo(newPos) + println("Shared:196 currentNoteIndex $currentNoteIndex, Index $index et curret = ${_currentPos.value}") + } } }