From 2760a67d5f05d016bad579dc99436361b85e9ce4 Mon Sep 17 00:00:00 2001 From: hasina Date: Mon, 19 Jan 2026 14:53:39 +0300 Subject: [PATCH] Remember voice states SATB --- .../kotlin/mg/dot/feufaro/midi/MidiPlayer.kt | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) 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 e3de7f2..2160bf9 100644 --- a/composeApp/src/desktopMain/kotlin/mg/dot/feufaro/midi/MidiPlayer.kt +++ b/composeApp/src/desktopMain/kotlin/mg/dot/feufaro/midi/MidiPlayer.kt @@ -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] + } + } + } \ No newline at end of file