Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MIDI.js - Unable to change instruments

I am trying to initialize MIDI.js with a glockenspiel instead of the default acoustic piano. But I am getting no sounds

I have glockenspiel-ogg.js and glockenspiel-mp3.js (downloaded from https://github.com/gleitz/midi-js-soundfonts ) in a directory called soundfont.

I am running the following code on window.onload. Where am I going wrong?

MIDI.loadPlugin({
soundfontUrl: "soundfont/",
instrument: "glockenspiel",
callback: function() {
MIDI.programChange(0, 10); 
MIDI.noteOn(0, 35, 127, 0);
}
});
like image 779
wolffmart Avatar asked Dec 17 '13 20:12

wolffmart


2 Answers

Sorry for answer an old question, but I found a better solution:

put this after the plugin load:

MIDI.programChange(0, MIDI.GeneralMIDI.byName["instrument_name"].number);
like image 100
Intronaut Avatar answered Sep 17 '22 11:09

Intronaut


Apparently, I was looking at a bad list for MIDI instrument codes. The Wikipedia page here has correct codes: https://en.wikipedia.org/wiki/General_MIDI I was trying to use number 10, but glockenspiel is number 9. So, this line should be:

MIDI.programChange(0, 9); 
like image 23
wolffmart Avatar answered Sep 17 '22 11:09

wolffmart