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() - returns an info object with the following keys:

Currently, implementation can be one of the following:

refresh()

engine.refresh() - refreshes 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() - opens the MIDI-In port. See more details here.

openMidiOut()

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

close()

engine.close() - closes 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) - returns a 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) - adds handler to the watcher.

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

onChange().disconnect()

watcher.diconnect(handler) - removes 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