How to use midi-player-js - 1 common examples

To help you get started, we’ve selected a few midi-player-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github xeoneux / pianoforte / src / audio / player.js View on Github external
const AudioContext = window.AudioContext || window.webkitAudioContext;
const audioContext = new AudioContext();

SoundFontPlayer.instrument(new AudioContext(), 'acoustic_grand_piano').then(
  instrument => {
    piano = instrument;
    window.navigator.requestMIDIAccess().then(midiAccess => {
      midiAccess.inputs.forEach(midiInput => {
        piano.listenToMidi(midiInput);
      });
    });
  }
);

export const midiPlayer = new MidiPlayer.Player(event => {
  if (event.name === 'Note on') {
    piano.play(event.noteNumber, audioContext.currentTime, {
      gain: (event.velocity + 1) / 128
    });
    pianoContainer.toggle(event.noteNumber, true);
  }
  if (event.name === 'Note off' || event.velocity === 0) {
    // piano.stop(event.noteNumber);
    pianoContainer.toggle(event.noteNumber, false);
  }
});

midi-player-js

Midi parser & player engine for browser or Node. Works well with single or multitrack MIDI files.

MIT
Latest version published 3 years ago

Package Health Score

45 / 100
Full package analysis

Popular midi-player-js functions