Published
Edited
Sep 6, 2020
Importers
Insert cell
Insert cell
Insert cell
Insert cell
function playMidiFileAndEmitEvents(jqueryCallback) {
let ac = new AudioContext();
var stopCallback;
SoundFontPlayer.instrument(ac, 'acoustic_grand_piano').then(function(piano) {
// Initialize player and register event handler
var Player = new MidiPlayer.Player(function(event) {
if (event.name == 'Note on') {
piano.play(event.noteName, ac.currentTime, {
gain: event.velocity / 100
});

if (jqueryCallback) {
jqueryCallback(event.noteName);
}
}
});

// Load a MIDI file
Player.loadArrayBuffer(theme);
Player.play();
stopCallback = () => piano.stop();
});
return stopCallback;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more