Refactor MIDI handling and update dependencies.
Streamlined MIDI message handling by introducing `MidiMessageHandler` and removed redundant code. Added better handler support for specific message types and parameters. Also upgraded Kotlin to version 2.1.0 and adjusted build configurations.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
package nl.astraeus.vst.chip.audio
|
||||
|
||||
import nl.astraeus.midi.message.TimedMidiMessage
|
||||
import nl.astraeus.vst.chip.PatchDTO
|
||||
import nl.astraeus.vst.chip.view.MainView
|
||||
import nl.astraeus.vst.chip.view.WaveformView
|
||||
@@ -134,7 +135,20 @@ object VstChipWorklet : AudioNode(
|
||||
super.postMessage(msg)
|
||||
}
|
||||
|
||||
override fun postMessage(msg: Any) {
|
||||
if (msg is ByteArray) {
|
||||
val tmm = TimedMidiMessage(msg)
|
||||
val byte1 = tmm.midi[0]
|
||||
|
||||
if (byte1.toInt() and 0xf0 == 0xb0) {
|
||||
handleIncomingMidi(tmm.midi[1], tmm.midi[2])
|
||||
}
|
||||
}
|
||||
super.postMessage(msg)
|
||||
}
|
||||
|
||||
override fun postMessage(vararg msg: Int) {
|
||||
println("postMessage ${msg.size} bytes")
|
||||
if (
|
||||
msg.size == 3
|
||||
&& (msg[0] and 0xf == midiChannel)
|
||||
@@ -144,12 +158,13 @@ object VstChipWorklet : AudioNode(
|
||||
val value = msg[2]
|
||||
|
||||
handleIncomingMidi(knob.toByte(), value.toByte())
|
||||
} else {
|
||||
super.postMessage(msg)
|
||||
}
|
||||
|
||||
super.postMessage(msg)
|
||||
}
|
||||
|
||||
private fun handleIncomingMidi(knob: Byte, value: Byte) {
|
||||
println("Incoming knob: $knob, value: $value")
|
||||
when (knob) {
|
||||
0x46.toByte() -> {
|
||||
volume = value / 127.0
|
||||
|
||||
@@ -35,6 +35,8 @@ import nl.astraeus.css.style.cls
|
||||
import nl.astraeus.komp.HtmlBuilder
|
||||
import nl.astraeus.komp.Komponent
|
||||
import nl.astraeus.komp.currentElement
|
||||
import nl.astraeus.midi.message.TimedMidiMessage
|
||||
import nl.astraeus.midi.message.getCurrentTime
|
||||
import nl.astraeus.vst.chip.audio.VstChipWorklet
|
||||
import nl.astraeus.vst.chip.audio.VstChipWorklet.midiChannel
|
||||
import nl.astraeus.vst.chip.midi.Midi
|
||||
@@ -46,7 +48,6 @@ import nl.astraeus.vst.ui.css.Css.defineCss
|
||||
import nl.astraeus.vst.ui.css.Css.noTextSelect
|
||||
import nl.astraeus.vst.ui.css.CssName
|
||||
import nl.astraeus.vst.ui.css.hover
|
||||
import nl.astraeus.vst.ui.util.uInt8ArrayOf
|
||||
import org.khronos.webgl.get
|
||||
import org.w3c.dom.CanvasRenderingContext2D
|
||||
import org.w3c.dom.HTMLCanvasElement
|
||||
@@ -114,6 +115,11 @@ object MainView : Komponent(), CssName {
|
||||
requestUpdate()
|
||||
}
|
||||
|
||||
override fun renderUpdate() {
|
||||
println("Rendering MainView")
|
||||
super.renderUpdate()
|
||||
}
|
||||
|
||||
override fun HtmlBuilder.render() {
|
||||
div(MainDivCss.name) {
|
||||
if (!started) {
|
||||
@@ -190,7 +196,8 @@ object MainView : Komponent(), CssName {
|
||||
+"STOP"
|
||||
onClickFunction = {
|
||||
VstChipWorklet.postDirectlyToWorklet(
|
||||
uInt8ArrayOf(0xb0 + midiChannel, 123, 0)
|
||||
TimedMidiMessage(getCurrentTime(), (0xb0 + midiChannel).toByte(), 123, 0)
|
||||
.data.buffer.data
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user