Fix tempoInFactor to tempoInBpm
This commit is contained in:
parent
fa603dc71e
commit
c53e46b4b4
3 changed files with 22 additions and 32 deletions
|
|
@ -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()*/
|
||||
|
|
|
|||
|
|
@ -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) }) {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue