Fundamentals
Export Targets
Code Export
Patcher UI
Special Topics
RNBO Raspberry Pi OSCQuery Runner
Sending and Receiving Messages (Inlets + Outlets)
@rnbo/js exposes the MessageEvent class, which you can use to send messages to your RNBO patcher. This includes support for the inport/outport RNBO objects, as well as RNBO inlets and outlets.
@rnbo/js
exposes the MessageEvent
class, which you can use to send messages to your RNBO patcher. This includes support for the inport/outport RNBO objects, as well as RNBO inlets and outlets.
const { TimeNow, MessageEvent } = require("@rnbo/js")
// Sends the number 74 to the first inlet
// All inlets have a tag with the form "in$", where $ is the index of the inlet (starting at 1)
const event1 = new MessageEvent(TimeNow, "in1", [ 74 ]);
device.scheduleEvent(event1);
// Sends the number 75 to an inport labeled "dest"
const event2 = new MessageEvent(TimeNow, "dest", [ 75 ]);
device.scheduleEvent(event2);
Getting Events from your RNBO Patch
A RNBO Device uses an EventSubject for its emitted events. You can subscribe to the messageEvent
property of a RNBO device to bind a function that will be called whenever the RNBO device produces a message event. Messages sent to an outport will have a tag based on that outport, whereas messages sent to an outlet will have a tag of the form "out$", where $ is the index of the outlet (starting at 1). See the example below on how to subscribe to outgoing events. Visit the JS API Reference for more information about the MessageEvent class.
// ev is of type MessageEvent, which has a tag and a payload
device.messageEvent.subscribe((ev) => {
console.log(`Received message ${ev.tag}: ${ev.payload}`);
if (ev.tag === "out1") console.log("from the first outlet");
});