We make it sound!
Home » Documentation » JZZ.js » MIDI-In


Opening MIDI-In port

engine.openMidiIn(arg) - try to open MIDI-In port.


port = JZZ().openMidiIn(0);
port = JZZ().openMidiIn('Roland RD');
port = JZZ().openMidiIn(function(){ return [2, 1, 0]; });
port = JZZ().openMidiIn(/Yamaha/);
port = JZZ().openMidiIn();


port.info() - get an info object with the following keys:


port.name() - a shortcut for the port.info().name.


port.connect(out) - add MIDI event handler or connect to MIDI-Out port.

out is either a MIDI-Out port object, or a function that will execute in the context of the current MIDI-In port object and receive a JZZ.MIDI object as an argument.

Both MIDI-In and MIDI-Out ports can have multiple connections.


port.disconnect(out) - remove MIDI event handler or disconnect MIDI-Out port.

out - a handler function to remove or a MIDI-Out port to disconnect.

If called without arguments, removes all handlers and disconnects all MIDI-Out ports. This is the only way to remuve anonymous handlers.


port.close() - close the port.

No other calls except the common calls can be chained to the closed port.

This call is optional in HTML, but in Node.js all open MIDI-In ports must be closed before the application can exit.


JZZ().or('Cannot start MIDI engine!')
     .openMidiIn().or('MIDI-In: Cannot open!')
     .and(function(){ console.log('MIDI-In:', this.name()); })
     .connect(JZZ().openMidiOut())                            // redirect to the default MIDI-Out port
     .connect(function(msg){ console.log(msg.toString()); })  // and log to the console
     .wait(10000).close().and('Thank you!');

Other calls

port.or(), port.and(), port.wait()

See also