I use this MIDI.js library: https://github.com/mudcube/MIDI.js
To download the plugin and play the midi file, I do this:
window.onload = function () {
MIDI.loadPlugin({
soundfontUrl: "./soundfont/",
instruments: [ "acoustic_grand_piano" ],
callback: function() {
MIDI.programChange(0, 0);
_player = MIDI.Player;
}
});
};
function playSong(){
_player.timeWarp = 1;
_player.loadFile(song[songid], _player.start);
_player.addListener(function(data) {
var now = data.now;
var end = data.end;
var channel = data.channel;
var message = data.message;
var note = data.note;
var velocity = data.velocity;
});
}
var songid = 0;
var song = ['data:audio/mid;base64,TVRoZAAAAA...
My question is, is there any transposition of this MIDI file before the game? Basically I want to parse a midi file (either a .mid file, or base64 format), change all notes to +1 and then send it to the player. Any way to do this in javascript?
source
share