2.0.1-tm2 • Published 6 years ago

midi-player-ts v2.0.1-tm2

Weekly downloads
11
License
MIT
Repository
github
Last release
6 years ago

MidiPlayerJS

npm version

MidiPlayerJS is a JavaScript library which reads standard MIDI files and emits JSON events in real time. This player does not generate any audio, but by attaching a handler to the event emitter you can trigger any code you like which could play audio, control visualizations, feed into a MIDI interface, etc.

Forked & modified by Tim Mensch to be easier to include into an ES6 or TypeScript project. Includes TypeScript types.

Additional post-fork improvements include:

  • Older Safari browser compatibility: There were several places where the code would fail on Safari on iOS 9. Fixed/polyfilled.
  • Optimized: Was using Uint8Array.slice previously, which creates a copy of the slice. Changed to subarray which links to the original data.
  • Use a gulpfile to enable building cross-platform. Previously it wouldn't build on Windows.
  • Improved the packaging to use require, and correctly use browserify to package both browser and node versions.
  • Add a yarn.lock file for consistent builds.
  • Fix Program Change message to work as expected

Demos

Getting Started

Using MidiWriterJS is pretty simple. Create a new player by instantiating MidiPlayer.Player with an event handler to be called for every MIDI event. Then you can load and play a MIDI file.

var MidiPlayer = require('midi-player-js');

// Initialize player and register event handler
var Player = new MidiPlayer.Player(function(event) {
	console.log(event);
});

// Load a MIDI file
Player.loadFile('./test.mid');
Player.play();

Player Events

There are a handful of events on the Player object which you can subscribe to using the Player.on() method. Some events pass data as the first argument of the callback as described below:

Player.on('fileLoaded', function() {
    // Do something when file is loaded
});
Player.on('playing', function(currentTick) {
    // Do something while player is playing
    // (this is repeatedly triggered within the play loop)
});
Player.on('midiEvent', function(event) {
    // Do something when a MIDI event is fired.
    // (this is the same as passing a function to MidiPlayer.Player() when instantiating.
});
Player.on('endOfFile', function() {
    // Do something when end of the file has been reached.
});

Full API Documentation

http://grimmdude.com/MidiPlayerJS/docs/

2.0.1-tm2

6 years ago

2.0.1-tm1

6 years ago

1.1.4-tm-7

6 years ago

1.1.4-tm-6

6 years ago

1.1.4-tm-5

6 years ago

1.1.4-tm-4

6 years ago

1.1.4-tm-3

6 years ago

1.1.4-tm-2

6 years ago

1.1.4-tm-1

6 years ago