Jazz-Soft.net
We make it sound!
Home » Documentation » JZZ.js » JZZ engine

JZZ engine

JZZ()

JZZ() is the first function you are going to call in your MIDI application.

On the first call, the function checks it's arguments, creates the singleton engine object and tries to initialize it.

On all successive calls, it returns the same object and ignores the arguments.

Engine is considered successfully initialized if there is at least one MIDI-Out or MIDI-In port that can be opened.

If the engine fails to initialize, it will execute its first or call (if there is one), and ignore all further calls.

Argument can be either empty or an object(map) with the following keys:

info()

engine.info() - return an info object with the following keys:

Currently, implementation can be one of the following:

refresh()

engine.refresh() - refresh the list of available input/output ports.

For the case if a device was disconnected or a new device connected during the session.

openMidiIn()

engine.openMidiIn() - open MIDI-In port. See more details here.

openMidiOut()

engine.openMidiOut() - open MIDI-Out port. See more details here.

close()

engine.close() - close all ports.

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

This call is optional in HTML, but may be required in Node.js if there are any MIDI-In ports remaining open.

Other calls

engine.or(), engine.and(), engine.wait()

Example

JZZ({sysex:true}).or('Cannot start MIDI engine!')
    .and(function(){ console.log(this.info()); })
    .wait(10000).refresh()
    .and(function(){ console.log(this.info()); })
    .and('Thank you!');

onChange()

engine.onChange(handler) - get the watcher object.

An optional handler parameter is a handler function that will be called each time when an external MIDI device is connected or disconnected.

The function will be given an argument in the form:

{ inputs: { added: [...], removed: [...] }, outputs: { added: [...], removed: [...] } },

where the arrays are filled with the info objects for each connected/disconnected device.

onChange().connect()

watcher.connect(handler) - add handler to the watcher.

handler - same as above. There can be any number of handlers chained to the watcher.

onChange().disconnect()

watcher.diconnect(handler) - remove handler from the watcher.

handler - a handler to remove.

If called without arguments, removes all handlers. This is the only way to remuve anonymous handlers.

onChange().*

Other engine functions can be chained after the watcher. They will execute on the engine object, rather than on the watcher.

See also