Remember voice states SATB
This commit is contained in:
parent
4e8866a4e7
commit
2760a67d5f
1 changed files with 20 additions and 0 deletions
|
|
@ -6,6 +6,7 @@ import kotlinx.coroutines.launch
|
|||
import mg.dot.feufaro.FileRepository
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.File
|
||||
import java.util.prefs.Preferences
|
||||
import javax.sound.midi.MidiSystem
|
||||
import javax.sound.midi.Sequencer
|
||||
import javax.sound.midi.Synthesizer //import javax.sound.midi.ShortMessage
|
||||
|
|
@ -27,6 +28,7 @@ actual class MediaPlayer actual constructor(
|
|||
null
|
||||
}
|
||||
|
||||
private val prefs = Preferences.userRoot().node("mg.dot.feufaro")
|
||||
private var synthetizer = MidiSystem.getSynthesizer() as Synthesizer?
|
||||
|
||||
private var pointA: Long = -1L
|
||||
|
|
@ -53,6 +55,7 @@ actual class MediaPlayer actual constructor(
|
|||
val file = File(filename)
|
||||
if (file.exists()){
|
||||
sequencer?.sequence = MidiSystem.getSequence(file)
|
||||
loadVoiceStates()
|
||||
applyVoiceStates()
|
||||
sequencer?.addMetaEventListener { meta ->
|
||||
if(meta.type == 47){
|
||||
|
|
@ -170,6 +173,7 @@ actual class MediaPlayer actual constructor(
|
|||
|
||||
actual fun toggleVoice(index: Int) {
|
||||
voiceStates[index] = !voiceStates[index]
|
||||
saveVoiceStates()
|
||||
applyVoiceStates()
|
||||
}
|
||||
|
||||
|
|
@ -231,4 +235,20 @@ actual class MediaPlayer actual constructor(
|
|||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
private fun saveVoiceStates() {
|
||||
val data = voiceStates.joinToString(",")
|
||||
prefs.put("voice_states", data)
|
||||
}
|
||||
|
||||
private fun loadVoiceStates() {
|
||||
val defaultValue = "true,true,true,true"
|
||||
val savedData = prefs.get("voice_states", defaultValue)
|
||||
|
||||
val states = savedData.split(",").map { it.toBoolean() }
|
||||
for (i in 0 until 4) {
|
||||
if (i < states.size) voiceStates[i] = states[i]
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue