# midi.js

> A modern JavaScript port of MIDI.js.

Latest version **0.3.1** (published 2016-10-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install midi.js
pnpm add midi.js
yarn add midi.js
bun add midi.js
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.1 |
| Published | 2016-10-03 |
| First published | 2016-09-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 14 |
| Author | SuneBear |
| Maintainers | sunebear |
| Keywords | midi, webaudio |

## Links

- npm: https://www.npmjs.com/package/midi.js
- Repository: https://github.com/SuneBear/midi.js
- Issues: https://github.com/SuneBear/midi.js/issues
- npm.io page: https://npm.io/package/midi.js

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.3.1 (latest) — 2016-10-03
- 0.3.0 — 2016-09-30

## README

# midi.js
A modern JavaScript port of MIDI.js.

## Basic Examples
- [MIDI Player](http://sunebear.github.io/midi.js/MIDIPlayer.html)
- [Whitney Music Box](http://sunebear.github.io/midi.js/WhitneyMusicBox.html)

## Installtion
``` bash
$ npm install midi.js
```

## Import
``` JavaScript
import MIDI from 'midi.js'
```

## Usage & APi
#### [loader.js](./src/loader.js) - Decides which framework is best to use

```javascript
// interface to download soundfont, then execute callback
MIDI.loadPlugin(onsuccess)
// simple example to get started
MIDI.loadPlugin({
  instrument: "acoustic_grand_piano", // or the instrument code 1 (aka the default)
  instruments: [ "acoustic_grand_piano", "acoustic_guitar_nylon" ], // or multiple instruments
  onsuccess: function() { }
});
```

#### [plugins/webaudio.js](./src/plugins/webaudio.js) - Controls MIDI output

```javascript
MIDI.noteOn(channel, note, velocity, delay)
MIDI.noteOff(channel, note, delay)
MIDI.chordOn(channel, [note, note, note], velocity, delay)
MIDI.chordOff(channel, [note, note, note], delay)
MIDI.keyToNote = object // A0 => 21
MIDI.noteToKey = object // 21 => A0
```

#### [player.js](./src/player.js) - Plays MIDI stream

```javascript
MIDI.Player.currentTime = integer // time we are at now within the song.
MIDI.Player.endTime = integer // time when song ends.
MIDI.Player.playing = boolean // are we playing? yes or no.
MIDI.Player.loadFile(file, onsuccess) // load .MIDI from base64 or binary XML request.
MIDI.Player.start() // start the MIDI track (you can put this in the loadFile callback)
MIDI.Player.resume() // resume the MIDI track from pause.
MIDI.Player.pause() // pause the MIDI track.
MIDI.Player.stop() // stops all audio being played, and resets currentTime to 0.
```

#### Listener for when notes are played

```javascript
MIDI.Player.removeListener() // removes current listener.
MIDI.Player.addListener(function(data) { // set it to your own function!
  const now = data.now // where we are now
  const end = data.end // time when song ends
  const channel = data.channel // channel note is playing on
  const message = data.message // 128 is noteOff, 144 is noteOn
  const note = data.note // the note
  const velocity = data.velocity // the velocity of the note
  // then do whatever you want with the information!
})
```

#### Smooth animation interpolating between onMidiEvent calls

```javascript
MIDI.Player.clearAnimation(); // clears current animation.
MIDI.Player.setAnimation(function(data) {
  const now = data.now // where we are now
  const end = data.end // time when song ends
  const events = data.events // all the notes currently being processed
  // then do what you want with the information!
})
```
Refer to https://github.com/mudcube/MIDI.js#api for more details.


## License
[MIT](./LICENSE)

---
_Source: https://npm.io/package/midi.js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
