- Notifications
You must be signed in to change notification settings - Fork28
MIDI library for Node.js and web-browsers
License
jazz-soft/JZZ
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
JZZ.js allows sending, receiving and playing MIDI messagesinNode.js andall major browsersinLinux,MacOS andWindows.Some features are available oniOS andAndroid devices.
JZZ.js enablesWeb MIDI APIinNode.js and those browsers that don't support it,and provides additional functionality to make developer's life easier.
For the best user experience, it'shighly RECOMMENDED (though not required)to install the latest version ofJazz-Pluginand browser extensions fromChrome Web StoreorMozilla Add-onsorApple App Store.
- MIDI In/Out
- User-defined MIDI nodes
- MIDI files
- MPE
- SMPTE
- UMP (MIDI 2.0)
- Additional modules
npm install jzz --save
oryarn add jzz
or get the full development version and minified scripts fromGithub
Note: in the (unlikely) case you get into trouble installing themidi-test module,that requires special system configuration,you can safely remove it from thedevDependenciesby runningnpm remove midi-test --save-dev
.
<scriptsrc="JZZ.js"></script>//...
<scriptsrc="https://cdn.jsdelivr.net/npm/jzz"></script> // the latest version, or<scriptsrc="https://cdn.jsdelivr.net/npm/jzz@1.9.1"></script> // any particular version//...
<scriptsrc="https://unpkg.com/jzz"></script> // the latest version, or<scriptsrc="https://unpkg.com/jzz@1.9.1"></script> // any particular version//...
varJZZ=require('jzz');//...
import{JZZ}from'jzz';//...
require(['JZZ'],function(JZZ){//...});
varnavigator=require('jzz');navigator.requestMIDIAccess().then(onSuccess,onFail);// ...navigator.close();// This will close MIDI inputs,// otherwise Node.js will wait for MIDI input forever.// In browsers the funcion is neither defined nor required.
JZZ().or('Cannot start MIDI engine!').openMidiOut().or('Cannot open MIDI Out port!').wait(500).send([0x90,60,127])// note on.wait(500).send([0x80,60,0]);// note offJZZ().openMidiIn().or('Cannot open MIDI In port!').and(function(){console.log('MIDI-In: ',this.name());}).connect(function(msg){console.log(msg.toString());}).wait(10000).close();
varinput=JZZ().openMidiIn();varoutput=JZZ().openMidiOut();vardelay=JZZ.Widget({_receive:function(msg){this.wait(500).emit(msg);}});input.connect(delay);delay.connect(output);
// All calls below will do the same job:port.send([0x90,61,127]).wait(500).send([0x80,61,0]);// arraysport.send(0x90,61,127).wait(500).send(0x80,61,0);// comma-separatedport.send(0x90,'C#5',127).wait(500).send(0x80,'Db5',0);// note namesport.noteOn(0,'C#5',127).wait(500).noteOff(0,'B##4');// helper functionsport.note(0,'C#5',127,500);// another shortcutport.ch(0).noteOn('C#5').wait(500).noteOff('C#5');// using channelsport.ch(0).note('C#5',127,500);// using channels
// in the environments that support async/await:asyncfunctionplayNote(){varmidi=awaitJZZ();varport=awaitmidi.openMidiOut();awaitport.noteOn(0,'C5',127);awaitport.wait(500);awaitport.noteOff(0,'C5');awaitport.close();console.log('done!');}// or:asyncfunctionplayAnotherNote(){varport=awaitJZZ().openMidiOut();awaitport.noteOn(0,'C5',127).wait(500).noteOff(0,'C5').close();console.log('done!');}
varlogger=JZZ.Widget({_receive:function(msg){console.log(msg.toString());}});JZZ.addMidiOut('Console Logger',logger);// now it can be used as a port:varport=JZZ().openMidiOut('Console Logger');// ...// substitute the native MIDIAccess// to make virtual ports visible to the Web MIDI API code:navigator.requestMIDIAccess=JZZ.requestMIDIAccess;
JZZ.MIDI.freq('A5');// => 440JZZ.MIDI.freq(69);// => 440JZZ.MIDI.freq(69.5);// => 452.8929841231365// from frequency:JZZ.MIDI.midi(440);// => 69JZZ.MIDI.midi(450);// => 69.38905773230853// or from name:JZZ.MIDI.midi('A5');// => 69
MIDI2()
is an adapter that enables MIDI 2.0 in all subsequent chained calls.MIDI1()
returns the operation back to MIDI 1.0.
Note that the downstream MIDI nodes don't require any special actions to receive and transfer MIDI 2.0 messages:
varfirst=JZZ.Widget();varsecond=JZZ.Widget();varthird=JZZ.Widget();first.connect(second);second.connect(third);third.connect(function(msg){console.log(msg.toString());});first.send([0x90,0x3c,0x7f])// 90 3c 7f -- Note On.MIDI2()// enable MIDI 2.0.send([0x20,0x90,0x3c,0x7f])// 20903c7f -- Note On.MIDI1()// reset to MIDI 1.0.send([0x90,0x3c,0x7f])// 90 3c 7f -- Note On
When used with MIDI 2.0, most of MIDI 1.0 helpers requiregroup
as an additional first parameter
and produce MIDI 1.0 messages wrapped into UMP packages.
Most of the new MIDI 2.0 helpers don't have corresponding MIDI 1.0 messages.
Usegr()
,ch()
andsxId()
calls to set defaultgroup
,channel
andSysEx ID
for the subsequent calls.MIDI2()
andMIDI1()
clear off defaultgroup
,channel
,SysEx ID
andMPE
settings:
first.noteOn(5,'C5',127)// 95 3c 7f -- Note On.ch(5).noteOn('C5',127)// 95 3c 7f -- Note On.MIDI2().noteOn(2,5,'C5',127)// 22953c7f -- Note On.gr(2).noteOn(5,'C5',127)// 22953c7f -- Note On.ch(5).noteOn('C5',127)// 22953c7f -- Note On.MIDI2().noteOn(2,5,'C5',127)// 22953c7f -- Note On.ch(5).noteOn(2,'C5',127)// 22953c7f -- Note On.MIDI2().umpNoteOn(2,5,'C5',127)// 42953c00 007f0000 -- Note On.gr(2).umpNoteOn(5,'C5',127)// 42953c00 007f0000 -- Note On.ch(5).umpNoteOn('C5',127)// 42953c00 007f0000 -- Note On
More onMIDI 2.0 support...
- JZZ-midi-SMF - Standard MIDI files: read / write / play
- JZZ-midi-WS - MIDI via WebSockets
- JZZ-midi-GM - General MIDI instrument names: MIDI to string / string to MIDI
- JZZ-midi-Gear - Retrieve your MIDI device model and manufacturer
- JZZ-input-Kbd - Virtual piano controls for your MIDI projects
- JZZ-synth-Tiny - A tiny General MIDI synth implemented with the Web Audio API
- JZZ-gui-Select - MIDI Input/Output pickers
- JZZ-gui-Player - MIDI Player - ready for your page
- JZZ-gui-Karaoke - Karaoke :)
- etc... - Import third-party solutions into the JZZ framework
- midi-test - Virtual MIDI ports for testing MIDI applications
- web-midi-test - Fake Web MIDI API for testing Web MIDI applications
- jazz-midi-headless - MIDI for headless testing
- test-midi-files - A framework for producing test MIDI files
Check theGetting Started pageand theAPI referencefor more information...
About
MIDI library for Node.js and web-browsers