All MIDI nodes, including Widgets, MIDI-In and MIDI-Out share the same API.
They can stand on either side of the connect() and disconnect() functions, and/or receive MIDI messages via the send() and various helpers.
NOTE: Nodes connected after the MIDI-Out port, will most likely receive nothing, since, by default, MIDI-Out will consume the messages sent to it;
Messages sent to the MIDI-In port will appear unchanged on its other end.
However, this default behavior can be changed by redefining the object's _receive() function.
JZZ.Widget(arg) - create a new MIDI node (widget).
Works with or without the new keyword.
If arg is a not empty object, its properties will be copied to the new node.
Possible properties:
var logger = JZZ.Widget(); logger._receive = function(msg) { console.log(msg.toString()); }; // or var logger = JZZ.Widget({ _receive: function(msg) { console.log(msg.toString()); }}); // ... JZZ().openMidiIn().connect(logger);
_emit(msg), emit(msg) - send MIDI event to the descendant nodes; _emit(msg) is synchronous, emit(msg) - asynchronous.
These functions are most often used by gadgets emulating MIDI-In devices.
var delay = JZZ.Widget(); delay._receive = function(msg) { this.wait(500).emit(msg); };
JZZ.addMidiIn(name, widget) - register widget as MIDI-In port.
name must be a unique name for the new MIDI port.
JZZ.addMidiOut(name, widget) - register widget as MIDI-Out port.
name must be a unique name for the new MIDI port.
var logger = JZZ.Widget({ _receive: function(msg) { console.log(msg.toString()); }}); JZZ.addMidiOut('Console Logger', logger); // now it can be used as a port: var port = JZZ().openMidiOut('Console Logger'); // ... // if required, substitute the native MIDIAccess // to make virtual ports visible to the Web MIDI API code: navigator.requestMIDIAccess = JZZ.requestMIDIAccess;