Broadcast

This commit is contained in:
2024-06-21 21:32:08 +02:00
parent f4a5d0a75b
commit d22fa8b367
3 changed files with 12 additions and 6 deletions

View File

@@ -3,8 +3,8 @@ package nl.astraeus.vst.chip
import kotlinx.browser.document
import kotlinx.browser.window
import nl.astraeus.komp.Komponent
import nl.astraeus.vst.chip.channel.Broadcaster
import nl.astraeus.vst.chip.channel.MidiMessage
import nl.astraeus.vst.chip.midi.Broadcaster
import nl.astraeus.vst.chip.midi.MidiMessage
import nl.astraeus.vst.chip.midi.Midi
import nl.astraeus.vst.chip.view.MainView
import org.khronos.webgl.Uint8Array

View File

@@ -1,6 +1,6 @@
@file:OptIn(ExperimentalJsExport::class)
package nl.astraeus.vst.chip.channel
package nl.astraeus.vst.chip.midi
import kotlinx.browser.window
import org.khronos.webgl.Uint8Array
@@ -63,6 +63,7 @@ object Broadcaster {
val channels = mutableMapOf<Int, BroadcastChannel>()
fun getChannel(channel: Int): BroadcastChannel = channels.getOrPut(channel) {
println("Opening broadcast channel $channel")
val bcChannel = BroadcastChannel("audio-worklet-$channel")
bcChannel.onmessage = { event ->
@@ -75,6 +76,10 @@ object Broadcaster {
private fun onMessage(channel: Int, event: MessageEvent) {
val data: dynamic = event.data.asDynamic()
console.log(
"Received broadcast message on channel $channel",
event
)
if (data.type == MessageType.SYNC.name) {
val syncMessage = SyncMessage(
data.timeOrigin,
@@ -92,6 +97,7 @@ object Broadcaster {
}
fun send(channel: Int, message: Any) {
console.log("Sending broadcast message on channel $channel:", message)
getChannel(channel).postMessage(message)
}

View File

@@ -33,8 +33,8 @@ import nl.astraeus.komp.Komponent
import nl.astraeus.vst.chip.audio.VstChipWorklet
import nl.astraeus.vst.chip.midi.Midi
import org.khronos.webgl.Uint8Array
import org.w3c.dom.HTMLInputElement
import org.w3c.dom.HTMLSelectElement
import org.w3c.performance.Performance
object MainView : Komponent() {
private var messages: MutableList<String> = ArrayList()
@@ -112,7 +112,7 @@ object MainView : Komponent() {
type = InputType.number
value = Midi.inputChannel.toString()
onChangeFunction = { event ->
val target = event.target as HTMLSelectElement
val target = event.target as HTMLInputElement
Midi.inputChannel = target.value.toInt()
}
}
@@ -156,7 +156,7 @@ object MainView : Komponent() {
type = InputType.number
value = Midi.outputChannel.toString()
onChangeFunction = { event ->
val target = event.target as HTMLSelectElement
val target = event.target as HTMLInputElement
Midi.outputChannel = target.value.toInt()
}
}