Play different instruments in a flexible way
I'd like to play several midi-files after one another, like sort of a playlist. According to the midi-file I'd like to get all its instruments to play. Sofar I only achieve that like this:
var player;
var instruments;
window.onload = function () {
MIDI.loadPlugin({
soundfontUrl: './soundfont/',
onsuccess: function () {
player = MIDI.Player;
player.timeWrap = 1;
player.loadFile('test.mid', function () {
instruments = player.getFileInstruments();
for (var i = 0; i < instruments.length; i++) {
MIDI.programChange(i, MIDI.GM.byName[instruments[i]].number);
}
player.start();
});
}
});
};
However they either seem to play on the wrong channel or somehow the wrong soundfont is assigned. So for example, the clarinet plays the piano's melody. I couldn't figure out how to solve that problem.
I'd be really happy about some advice or ideas :)
On 26/11/17 21:37, Owwwl9 wrote:
instruments = player.getFileInstruments(); for (var i = 0; i < instruments.length; i++) { MIDI.programChange(i, MIDI.GM.byName[instruments[i]].number); }
Don't do this, it's completely wrong. getFileInstruments just gives you a list of instruments that are used in the file, so that you can load the appropriate sound fonts.
The MIDI file itself will set the program (instrument) on the appropriate channel. There is no need for you to make any calls to MIDI.programChange yourself.
Thanks, you are right about that, I didn't feel comfortable with that solution as well.
Without it however, the soundfonts aren't loaded, except from "acoustic_grand_piano". I've got all the soundfonts needed in my soundfont-folder, but it doesn't work. Somehow midi.getFileInstruments fails to assign the right instruments, I guess.
The only way it works sofar really is by using programChange as discussed in this previous issue https://github.com/mudcube/MIDI.js/issues/158
What do I miss?
@Owwwl9 I'm currently having the exact same problem... did you finally find a solution for this issue?
Same Problem, happens every year I guess ^^
Same. We skipped a few years.
@embryCODE Maybe it's related to this line being commented out? https://github.com/mudcube/MIDI.js/blob/a8a84257afa70721ae462448048a87301fc1554a/js/midi/player.js#L116
Same problem. Has anyone found a solution? Or any example of MIDI.js playing MIDI files with the correct instruments apart from piano?
The commented-out line is probably not the only bug, as discussed in issue #268