Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/grimmdude/MidiPlayerJS
♬ MIDI parser & player engine for browser or Node. As a parser converts MIDI events into JSON. Works well with single or multitrack MIDI files.
https://github.com/grimmdude/MidiPlayerJS
audio es6 javascript-library midi midi-player
Last synced: about 2 months ago
JSON representation
♬ MIDI parser & player engine for browser or Node. As a parser converts MIDI events into JSON. Works well with single or multitrack MIDI files.
- Host: GitHub
- URL: https://github.com/grimmdude/MidiPlayerJS
- Owner: grimmdude
- License: mit
- Created: 2016-09-18T02:10:18.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2024-02-21T08:17:41.000Z (10 months ago)
- Last Synced: 2024-04-14T11:56:11.718Z (8 months ago)
- Topics: audio, es6, javascript-library, midi, midi-player
- Language: JavaScript
- Homepage: https://grimmdude.com/MidiPlayerJS/
- Size: 3.79 MB
- Stars: 347
- Watchers: 15
- Forks: 50
- Open Issues: 23
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-javascript-audio - grimmdude/MidiPlayerJS - multi-track MIDI player/parser (Libraries: Web MIDI API / Web MIDI API)
README
# ♬ MidiPlayerJS
[![npm version](https://badge.fury.io/js/midi-player-js.svg)](https://badge.fury.io/js/midi-player-js)
[![Build Status](https://travis-ci.org/grimmdude/MidiPlayerJS.svg?branch=master)](https://travis-ci.org/grimmdude/MidiPlayerJS)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.
## Demos
* [Neopixel Music](https://github.com/robertvorthman/neopixel-music) by robertvorthman @robertvorthman
* [Autocomposer](https://github.com/rjsalvadorr/autocomposer-js) by RJ Salvador @rjsalvadorr
* [Simple Browser Player](http://grimmdude.com/MidiPlayerJS/) by Garrett Grimm @grimmdude
* [Orchestra](https://lexcast.github.io/orchestra/) by Daniel Alejandro Cast @lexcast## 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.```js
import MidiPlayer from 'midi-player-js';// Initialize player and register event handler
const 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:```js
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.
});
```Note that because of a common practice called "running status" many MIDI files may use `Note on` events with `0` velocity in place of `Note off` events.
## Full API Documentation
[http://grimmdude.com/MidiPlayerJS/docs/](http://grimmdude.com/MidiPlayerJS/docs/)