Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including jzz-midi-smf with all npm packages installed. Try it out:

var jzzMidiSmf = require("jzz-midi-smf")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

jzz-midi-smf v1.2.4

Standard MIDI Files: read / write / play


Standard MIDI Files: read / write / play

Node.js Firefox Chrome Opera Safari Internet Explorer Edge
npm npm Build Status Coverage Status


npm install jzz-midi-smf --save
or bower install jzz-midi-smf
or yarn add jzz-midi-smf
or get the full development version and minified scripts from GitHub


Plain HTML
<script src="JZZ.js"></script>
<script src="JZZ.midi.SMF.js"></script>
CDN (always the latest version!)
<script src=""></script>
<script src=""></script>
CommonJS (Browserify and Node.js command line applications)
var JZZ = require('jzz');
require(['JZZ', 'JZZ.midi.SMF'], function(JZZ, dummy) {
  // ...

MIDI files

Supported file formats: .mid, .kar, .rmi

Please check the API Reference !

Playing MIDI file
var midiout = JZZ().openMidiOut();
var data = require('fs').readFileSync('file.mid', 'binary');
var smf = new JZZ.MIDI.SMF(data);
var player = smf.player();
Creating MIDI file from scratch
var smf = new JZZ.MIDI.SMF(0, 96); // type 0, 96 ticks per quarter note
var trk = new JZZ.MIDI.SMF.MTrk();
// add contents:
trk.add(0, JZZ.MIDI.smfSeqName('This is a sequence name'))
   .add(0, JZZ.MIDI.smfBPM(90)) // tempo 90 bpm
   .add(96, JZZ.MIDI.noteOn(0, 'C6', 127))
   .add(96, JZZ.MIDI.noteOn(0, 'Eb6', 127))
   .add(96, JZZ.MIDI.noteOn(0, 'G6', 127))
   .add(192, JZZ.MIDI.noteOff(0, 'C6'))
   .add(192, JZZ.MIDI.noteOff(0, 'Eb6'))
   .add(192, JZZ.MIDI.noteOff(0, 'G6'))
   .add(288, JZZ.MIDI.smfEndOfTrack());
// or an alternative way:
trk.smfSeqName('This is a sequence name').smfBPM(90).tick(96)
   .noteOn(0, 'C6', 127).noteOn(0, 'Eb6', 127).noteOn(0, 'G6', 127)
   .tick(96).noteOff(0, 'C6').noteOff(0, 'Eb6').noteOff(0, 'G6')
// or even shorter:
trk.smfSeqName('This is a sequence name').smfBPM(90).tick(96)
   .ch(0).note('C6', 127, 96).note('Eb6', 127, 96).note('G6', 127, 96)
Transposing MIDI file
for (var i = 0; i < smf.length; i++) {
  if (smf[i] instanceof JZZ.MIDI.SMF.MTrk) {
    for (var j = 0; j < smf[i].length; j++) {
      var note = smf[i][j].getNote();
      if (typeof note != 'undefined') {
        if (smf[i][j].getChannel() != 9) { // skip the percussion channel
          smf[i][j].setNote(note + 12);    // transpose one octave up
Getting the info
var player = smf.player();
var dump = smf.dump();
console.log('Type:', player.type());
console.log('Number of tracks:', player.tracks());
console.log('Size:', dump.length, 'bytes');
console.log('Duration:', player.duration(), 'ticks');
console.log('Total time:', player.durationMS(), 'milliseconds');
Saving MIDI file
require('fs').writeFileSync('out.mid', smf.dump(), 'binary');

More information

Please visit for more information.
Your questions and comments are welcome here.

We would really appreciate your support!

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free