From c53e46b4b4dbf88d82acfaa8bce338a58b91b778 Mon Sep 17 00:00:00 2001 From: "hasinarak3@gmail.com" Date: Tue, 10 Mar 2026 09:33:21 +0300 Subject: [PATCH] Fix tempoInFactor to tempoInBpm --- .../kotlin/mg/dot/feufaro/midi/MidiPlayer.kt | 9 ++---- .../mg/dot/feufaro/ui/MidiControlPanel.kt | 30 +++++++------------ .../kotlin/mg/dot/feufaro/midi/MidiPlayer.kt | 15 ++++++---- 3 files changed, 22 insertions(+), 32 deletions(-) diff --git a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/midi/MidiPlayer.kt b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/midi/MidiPlayer.kt index 0c2fb72..41872c5 100644 --- a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/midi/MidiPlayer.kt +++ b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/midi/MidiPlayer.kt @@ -19,15 +19,10 @@ expect class FMediaPlayer(filename: String, onFinished: () -> Unit) { fun setPointA() fun setPointB() fun clearLoop() - fun setTempo(factor: Float) + fun setTempo(bpm: Float) fun getCurrentBPM(): Float fun updateVoiceVolume(voiceIndex: Int, newVolume: Float) fun requestSync(sharedScreenModel: SharedScreenModel) fun syncNavigationMonitor(sharedScreenModel: SharedScreenModel) fun release() -} - -/* -expect fun MidiPlayer(filename: String, onFinished: () -> Unit) - -expect fun StopMidi()*/ +} \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/ui/MidiControlPanel.kt b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/ui/MidiControlPanel.kt index dc486cc..180bd6e 100644 --- a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/ui/MidiControlPanel.kt +++ b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/ui/MidiControlPanel.kt @@ -70,9 +70,8 @@ fun MidiControlPanel( val labels = listOf("S", "A", "T", "B") listOf("Soprano", "Alto", "Ténor", "Basse") - var tempo by remember { mutableStateOf(1.0f) } + var tempo by remember { mutableStateOf(120.toFloat()) } var currentBpm by remember { mutableStateOf(mediaPlayer.getCurrentBPM()) } - val basseBpm = 120f var isPianoSelected by remember { mutableStateOf(true) } @@ -101,23 +100,16 @@ fun MidiControlPanel( LaunchedEffect(tempo) { currentBpm = mediaPlayer.getCurrentBPM() } + fun updateTempoToBpm(newBpm: Int) { + tempo = newBpm.toFloat() + mediaPlayer?.setTempo(tempo) + } fun updateTempoByBpmStep(step: Int) { - val currentBpm = (basseBpm * tempo).toInt() - val newBpm = (currentBpm + step).coerceIn((basseBpm * 0.25f).toInt(), (basseBpm * 1.5f).toInt()) - val newFactor = newBpm.toFloat() / basseBpm - - tempo = newFactor - mediaPlayer?.setTempo(newFactor) + val currentBpm = mediaPlayer!!.getCurrentBPM() + val nextBpm = currentBpm.toInt() + step + updateTempoToBpm(nextBpm) } - fun updateTempoToBpm(targetBpm: Int) { - val clampedBpm = targetBpm.coerceIn((basseBpm * 0.25f).toInt(), (basseBpm * 1.5f).toInt()) - val newFactor = clampedBpm.toFloat() / basseBpm - - tempo = newFactor - mediaPlayer?.setTempo(newFactor) -// println("tempo : $tempo") - } Column( modifier = Modifier.fillMaxWidth() ) { @@ -252,7 +244,7 @@ fun MidiControlPanel( .padding(vertical = 6.dp), verticalAlignment = Alignment.CenterVertically ) { - if (tempo >= 0.3) { // limite 40BPM + if (tempo >= 40.0) { // limite 40BPM IconButton( modifier = Modifier.background(Color(0XFF2C3130)), onClick = { updateTempoByBpmStep(-10) }) { @@ -265,7 +257,7 @@ fun MidiControlPanel( } } - val currentBpmInt = (basseBpm * tempo).toInt() + val currentBpmInt = (tempo).toInt() Row( modifier = Modifier.padding(horizontal = 2.dp), @@ -300,7 +292,7 @@ fun MidiControlPanel( } } - if (tempo <= 1.3) { // limite 156BPM + if (tempo <= 160) { // limite 160BPM IconButton( modifier = Modifier.background(Color(0XFF2C3130)), onClick = { updateTempoByBpmStep(10) }) { diff --git a/composeApp/src/desktopMain/kotlin/mg/dot/feufaro/midi/MidiPlayer.kt b/composeApp/src/desktopMain/kotlin/mg/dot/feufaro/midi/MidiPlayer.kt index 30bd452..b5da82e 100644 --- a/composeApp/src/desktopMain/kotlin/mg/dot/feufaro/midi/MidiPlayer.kt +++ b/composeApp/src/desktopMain/kotlin/mg/dot/feufaro/midi/MidiPlayer.kt @@ -39,6 +39,7 @@ actual class FMediaPlayer actual constructor( private var currentGlobalVolume: Float = 0.8f private var currentTempo: Float = 1.0f + private var targetBpm: Float = 120f private val playerScope = CoroutineScope(Dispatchers.Default + SupervisorJob()) private var abJob: Job? = null @@ -393,14 +394,16 @@ actual class FMediaPlayer actual constructor( } } actual fun getCurrentBPM(): Float { - val currentFactor = sequencer?.tempoFactor ?: 1.0f - val currentBPM = (120f * currentFactor) - return currentBPM + return targetBpm } - actual fun setTempo(factor: Float){ - currentTempo = factor - sequencer?.tempoFactor = factor + actual fun setTempo(bpm: Float){ + this.targetBpm = bpm + sequencer?.tempoInBPM = bpm + boundModel?.let { modele -> + prepareNavigation(modele) + } + println("Tempo réglé à : $bpm BPM") } fun getTempo(): Float = currentTempo private val MS8PER_NOTE = 500L