From 194857d6874ec11b089268cef3d57624465982b9 Mon Sep 17 00:00:00 2001 From: rnentjes Date: Sat, 29 Jun 2024 20:01:16 +0200 Subject: [PATCH] Cleanup --- .../nl/astraeus/vst/chip/ChipProcessor.kt | 2 +- settings.common.gradle.kts | 2 +- .../astraeus/vst/chip/audio/VstChipWorklet.kt | 26 ++++++++++--------- .../nl/astraeus/vst/chip/view/MainView.kt | 2 +- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/audio-worklet/src/jsMain/kotlin/nl/astraeus/vst/chip/ChipProcessor.kt b/audio-worklet/src/jsMain/kotlin/nl/astraeus/vst/chip/ChipProcessor.kt index 2e94977..4344262 100644 --- a/audio-worklet/src/jsMain/kotlin/nl/astraeus/vst/chip/ChipProcessor.kt +++ b/audio-worklet/src/jsMain/kotlin/nl/astraeus/vst/chip/ChipProcessor.kt @@ -149,7 +149,7 @@ class VstChipProcessor : AudioWorkletProcessor() { console.log("playMidi", bytes) if (bytes.length > 0) { var cmdByte = bytes[0] - val channelCmd = ((cmdByte shr 4) and 0xf) in 0x8 .. 0xe + val channelCmd = ((cmdByte shr 4) and 0xf) != 0xf0 val channel = cmdByte and 0xf println("Channel cmd: $channelCmd") if (channelCmd && channel != midiChannel) { diff --git a/settings.common.gradle.kts b/settings.common.gradle.kts index 4230eaf..d8820bf 100644 --- a/settings.common.gradle.kts +++ b/settings.common.gradle.kts @@ -1,6 +1,6 @@ pluginManagement { plugins { - kotlin("multiplatform") version "2.0.0" + kotlin("multiplatform") version "2.0.20-Beta1" id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0" } repositories { diff --git a/src/jsMain/kotlin/nl/astraeus/vst/chip/audio/VstChipWorklet.kt b/src/jsMain/kotlin/nl/astraeus/vst/chip/audio/VstChipWorklet.kt index 3611f17..44ebf69 100644 --- a/src/jsMain/kotlin/nl/astraeus/vst/chip/audio/VstChipWorklet.kt +++ b/src/jsMain/kotlin/nl/astraeus/vst/chip/audio/VstChipWorklet.kt @@ -2,6 +2,7 @@ package nl.astraeus.vst.chip.audio import nl.astraeus.vst.chip.view.MainView import nl.astraeus.vst.chip.view.WaveformView +import nl.astraeus.vst.ui.util.uInt8ArrayOf import org.khronos.webgl.Float32Array import org.khronos.webgl.Uint8Array import org.khronos.webgl.get @@ -18,46 +19,53 @@ object VstChipWorklet : AudioNode( postMessage("waveform\n$value") } var midiChannel = 0 + set(value) { + check(value in 0..15) { + "Midi channel must be between 0 and 15." + } + field = value + postMessage("set_channel\n${midiChannel}") + } var volume = 0.75 set(value) { field = value super.postMessage( - Uint8Array(arrayOf(0xb0.toByte(), 0x46.toByte(), (value * 127).toInt().toByte())) + uInt8ArrayOf(0xb0 + midiChannel, 0x46, (value * 127).toInt()) ) } var dutyCycle = 0.5 set(value) { field = value super.postMessage( - Uint8Array(arrayOf(0xb0.toByte(), 0x4a.toByte(), (value * 127).toInt().toByte())) + uInt8ArrayOf(0xb0 + midiChannel, 0x4a, (value * 127).toInt()) ) } var fmModFreq = 0.0 set(value) { field = value super.postMessage( - Uint8Array(arrayOf(0xb0.toByte(), 0x4b.toByte(), (value * 127).toInt().toByte())) + uInt8ArrayOf(0xb0 + midiChannel, 0x4b, (value * 127).toInt()) ) } var fmModAmp = 0.0 set(value) { field = value super.postMessage( - Uint8Array(arrayOf(0xb0.toByte(), 0x4c.toByte(), (value * 127).toInt().toByte())) + uInt8ArrayOf(0xb0 + midiChannel, 0x4c, (value * 127).toInt()) ) } var amModFreq = 0.0 set(value) { field = value super.postMessage( - Uint8Array(arrayOf(0xb0.toByte(), 0x47.toByte(), (value * 127).toInt().toByte())) + uInt8ArrayOf(0xb0 + midiChannel, 0x47, (value * 127).toInt()) ) } var amModAmp = 0.0 set(value) { field = value super.postMessage( - Uint8Array(arrayOf(0xb0.toByte(), 0x48.toByte(), (value * 127).toInt().toByte())) + uInt8ArrayOf(0xb0 + midiChannel, 0x48, (value * 127).toInt()) ) } var recording: Float32Array? = null @@ -125,10 +133,4 @@ object VstChipWorklet : AudioNode( } } - fun setChannel(channel: Int) { - midiChannel = channel - - postMessage("set_channel\n${midiChannel}") - } - } diff --git a/src/jsMain/kotlin/nl/astraeus/vst/chip/view/MainView.kt b/src/jsMain/kotlin/nl/astraeus/vst/chip/view/MainView.kt index d02160c..aa0c96a 100644 --- a/src/jsMain/kotlin/nl/astraeus/vst/chip/view/MainView.kt +++ b/src/jsMain/kotlin/nl/astraeus/vst/chip/view/MainView.kt @@ -166,7 +166,7 @@ object MainView : Komponent(), CssName { onInputFunction = { event -> val target = event.target as HTMLInputElement println("onInput channel: $target") - VstChipWorklet.setChannel(target.value.toInt()) + VstChipWorklet.midiChannel = target.value.toInt() } } }