最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - MIDI.js - Unable to change instruments - Stack Overflow

programmeradmin2浏览0评论

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 ) 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);
}
});

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./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);
}
});
Share Improve this question asked Dec 17, 2013 at 20:08 wolffmartwolffmart 811 silver badge7 bronze badges 1
  • 2 currently there is no more 'programChange' in midi.js. how else can i do so? – tjvg1991 Commented Jan 19, 2016 at 15:51
Add a ment  | 

2 Answers 2

Reset to default 8

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);

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

MIDI.programChange(0, 9); 
发布评论

评论列表(0)

  1. 暂无评论