This commit is contained in:
2024-06-20 18:57:20 +02:00
parent 945f4bb016
commit f4a5d0a75b
9 changed files with 350 additions and 139 deletions

View File

@@ -30,13 +30,20 @@ external class MIDIOutput {
val type: String
val version: String
fun send(message: dynamic)
fun send(message: dynamic, timestamp: dynamic)
fun open()
fun close()
}
object Midi {
var inputChannel: Int = -1
var outputChannel: Int = -1
var inputs = mutableListOf<MIDIInput>()
var outputs = mutableListOf<MIDIInput>()
var outputs = mutableListOf<MIDIOutput>()
var currentInput: MIDIInput? = null
var currentOutput: MIDIOutput? = null
fun start() {
val navigator = window.navigator.asDynamic()
@@ -68,7 +75,7 @@ object Midi {
)
}
fun setInput(input: MIDIInput) {
fun setInput(input: MIDIInput?) {
console.log("Setting input", input)
currentInput?.close()
@@ -94,4 +101,17 @@ object Midi {
currentInput?.open()
}
fun setOutput(output: MIDIOutput?) {
console.log("Setting output", output)
currentOutput?.close()
currentOutput = output
currentOutput?.open()
}
fun send(data: Uint8Array, timestamp: dynamic? = null) {
currentOutput?.send(data, timestamp)
}
}