From 6be7ae51720f74c67f2125b63799754a050f48bb Mon Sep 17 00:00:00 2001 From: rnentjes Date: Thu, 15 May 2025 16:15:56 +0200 Subject: [PATCH] Add MidiMessageHandler for managing MIDI message handlers Introduced `MidiMessageHandler` with support for adding and invoking handlers based on byte inputs. This enables more flexible and organized handling of MIDI messages within the application. --- .../kotlin/nl/astraeus/vst/MidiMessageHandler.kt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/commonMain/kotlin/nl/astraeus/vst/MidiMessageHandler.kt diff --git a/src/commonMain/kotlin/nl/astraeus/vst/MidiMessageHandler.kt b/src/commonMain/kotlin/nl/astraeus/vst/MidiMessageHandler.kt new file mode 100644 index 0000000..d35bef4 --- /dev/null +++ b/src/commonMain/kotlin/nl/astraeus/vst/MidiMessageHandler.kt @@ -0,0 +1,16 @@ +package nl.astraeus.vst + +typealias MidiHandler = (Byte, Byte, Byte) -> Unit + +object MidiMessageHandler { + val handlers = mutableMapOf>() + + fun addHandler(byte1: Byte, byte2: Byte = 0, handler: MidiHandler) { + handlers.getOrPut(byte1) { mutableMapOf() }[byte2] = handler + } + + fun handle(byte1: Byte, byte2: Byte, byte3: Byte) { + handlers[byte1]?.get(byte2)?.invoke(byte1, byte2, byte3) + } + +}