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 mg.dot.feufaro.FileRepository
|
||||||
import java.io.ByteArrayInputStream
|
import java.io.ByteArrayInputStream
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.util.prefs.Preferences
|
||||||
import javax.sound.midi.MidiSystem
|
import javax.sound.midi.MidiSystem
|
||||||
import javax.sound.midi.Sequencer
|
import javax.sound.midi.Sequencer
|
||||||
import javax.sound.midi.Synthesizer //import javax.sound.midi.ShortMessage
|
import javax.sound.midi.Synthesizer //import javax.sound.midi.ShortMessage
|
||||||
|
|
@ -27,6 +28,7 @@ actual class MediaPlayer actual constructor(
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val prefs = Preferences.userRoot().node("mg.dot.feufaro")
|
||||||
private var synthetizer = MidiSystem.getSynthesizer() as Synthesizer?
|
private var synthetizer = MidiSystem.getSynthesizer() as Synthesizer?
|
||||||
|
|
||||||
private var pointA: Long = -1L
|
private var pointA: Long = -1L
|
||||||
|
|
@ -53,6 +55,7 @@ actual class MediaPlayer actual constructor(
|
||||||
val file = File(filename)
|
val file = File(filename)
|
||||||
if (file.exists()){
|
if (file.exists()){
|
||||||
sequencer?.sequence = MidiSystem.getSequence(file)
|
sequencer?.sequence = MidiSystem.getSequence(file)
|
||||||
|
loadVoiceStates()
|
||||||
applyVoiceStates()
|
applyVoiceStates()
|
||||||
sequencer?.addMetaEventListener { meta ->
|
sequencer?.addMetaEventListener { meta ->
|
||||||
if(meta.type == 47){
|
if(meta.type == 47){
|
||||||
|
|
@ -170,6 +173,7 @@ actual class MediaPlayer actual constructor(
|
||||||
|
|
||||||
actual fun toggleVoice(index: Int) {
|
actual fun toggleVoice(index: Int) {
|
||||||
voiceStates[index] = !voiceStates[index]
|
voiceStates[index] = !voiceStates[index]
|
||||||
|
saveVoiceStates()
|
||||||
applyVoiceStates()
|
applyVoiceStates()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -231,4 +235,20 @@ actual class MediaPlayer actual constructor(
|
||||||
e.printStackTrace()
|
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