Jazz-Soft.net

We make it sound!

Home » Documentation » JZZ.js » JZZ.MIDI

JZZ.MIDI

All midi messages are internally handled as JZZ.MIDI objects. This type inherits from the JavaScript Array, and therefore allows all array operations on it.

Construction

JZZ.MIDI() works with or without the new keyword.

It accepts an array or a comma-separated list of the message bytes or another JZZ.MIDI object.

String names for the notes are allowed where appropriate (in the note on / note off / aftertouch messages).

Note name consists of the pitch class (from A to G), accidentals (#, ##, b, bb, or none), and the octave (from 0 to 10), and is case-insensitive.

German notation fans can use H and Bb for Si and Si-flat.

e.g. C#5, c#5, Db5, db5, DB5, dB5, B##4, b##4, H##4, h##4 will all have value of 61.

MIDI note range spans from C0 (0) to G10 (127), and the Middle-C is C5 (60).

Example

All following statements will produce the same result:

msg = new JZZ.MIDI([0x90, 63, 127]);
msg = new JZZ.MIDI(0x90, 63, 127);
msg = JZZ.MIDI(0x90, 63, 127);
msg = JZZ.MIDI([0x90, 'Eb5', 127]);
msg = JZZ.MIDI.noteOn(0, 'D#5', 127);                    // see below...

Timestamp

Timestamps will be available in the future releases.

toString

toString() converts MIDI message to the human-readable string.

NOTE: in most JavaScript realizations, console.log() does not automatically call this function.

Example

console.log(JZZ.MIDI.noteOn(0, 'D#5', 127).toString());  // or
console.log('Playing note: ' + JZZ.MIDI.noteOn(0, 'D#5', 127));

Helpers

It is not uncommon for JavaScript developer to forget which MIDI message stands for Dumper piano pedal off.

Therefore, some helper functions might be helpful.

In the following list c will stand for the channel, nn - for the note, vv - for velocity, mm - for the most significant byte (MSB), ll - for the least significant byte (LSB), b - for the boolean On/Off, xx and yy for other paraneters.

noteOn(c, nn, vv) - note on; returns 9c nn vv.

noteOff(c, nn) - note off; returns 8c nn 00.

aftertouch(c, nn, xx) - aftertouch; returns Ac nn xx.

program(c, xx) - program change; returns Cc xx.

pressure(c, xx) - pressure (channel aftertouch); returns Dc xx.

pitchBend(c, xx) - pitch bender; returns Ec ll mm.

control(c, xx, yy) - other control; returns Bc xx yy; some controls have their own dedicated helpers below.

bankMSB(c, mm) - bank select, MSB; returns Bc 00 mm.

bankLSB(c, ll) - bank select, LSB; returns Bc 20 ll.

modMSB(c, mm) - modulation wheel, MSB; returns Bc 01 mm.

modLSB(c, ll) - modulation wheel, LSB; returns Bc 21 ll.

breathMSB(c, mm) - breath controller, MSB; returns Bc 02 mm.

breathLSB(c, ll) - breath controller, LSB; returns Bc 22 ll.

footMSB(c, mm) - foot controller, MSB; returns Bc 04 mm.

footLSB(c, ll) - foot controller, LSB; returns Bc 24 ll.

portamentoMSB(c, mm) - portamento time, MSB; returns Bc 05 mm.

portamentoLSB(c, ll) - portamento time, LSB; returns Bc 25 ll.

volumeMSB(c, mm) - channel volume, MSB; returns Bc 07 mm.

volumeLSB(c, ll) - channel volume, LSB; returns Bc 27 ll.

balanceMSB(c, mm) - stereo balance, MSB; returns Bc 08 mm.

balanceLSB(c, ll) - stereo balance, LSB; returns Bc 28 ll.

panMSB(c, mm) - stereo pan, MSB; returns Bc 0A mm.

panLSB(c, ll) - stereo pan, LSB; returns Bc 2A mm.

expressionMSB(c, mm) - expression controller, MSB; returns Bc 0B mm.

expressionLSB(c, ll) - expression controller, LSB; returns Bc 2B mm.

damper(c, b) - damper pedal on/off; returns Bc 40 7f/00.

portamento(c, b) - portamento on/off; returns Bc 41 7f/00.

sostenuto(c, b) - sostenuto pedal on/off; returns Bc 42 7f/00.

soft(c, b) - soft pedal on/off; returns Bc 43 7f/00.

allSoundOff(c) - all sound off; returns Bc 78 00.

allNotesOff(c) - all notes off; returns Bc 7B 00.

mtc(smpte) - MIDI time code (SMPTE quarter-frame); returns F1 xx.

songPosition(xx) - song position pointer; returns F2 ll mm.

songSelect(xx) - song select; returns F3 xx.

tune() - tune request; returns F6.

clock() - timing clock; returns F8.

start() - start; returns FA.

continue() - continue; returns FB.

stop() - stop; returns FC.

active() - active sensing; returns FE.

reset() - reset; returns FF.

Some common SysEx messages:

sxIdRequest() - device ID request; returns F0 7E 7F 06 01 F7. (see also: gearInfo())

sxFullFrame(smpte) - SMPTE full-frame; returns F0 7F 7F 01 01 xx xx xx xx F7.

All helpers above (and some more) can be directly used with the MIDI-Out port object.

Data access

isNoteOn() - returns true for the Note On message (9x nn vv; vv > 0), or false otherwise.

isNoteOff() - returns true for the Note Off message (8x nn vv or 9x nn 00), or false otherwise.

isSysEx() - returns true if the message starts with F0, or false otherwise.

isFullSysEx() - returns true if the message starts with F0 and ends with F7, or false otherwise.

isSysEx() - returns true if the first byte of the message is F0, or false otherwise.

getChannel() - returns the channel number if the message is channel-related, or undefined otherwise.

setChannel(cc) - sets the channel number to cc where it makes sense.

getNote() - returns the note number for Note On / Note Off / Aftertouch messages, or undefined for others.

setNote(nn) - sets the note to nn where it makes sense; nn can be a number or a note name.

getVelocity() - returns the velocity for the Note On message, or undefined for others.

setVelocity(vv) - sets the velocity in the Note On message.

getSysExChannel() - returns the SysEx channel if the message is a SysEx, or undefined otherwise.

setSysExChannel(cc) - sets the SysEx channel in the SysEx message.

Example

// transpose msg an octave up:
var note = msg.getNote();
if (note !== undefined) msg.setNote(note + 12);

See also