我一直在尝试使用midi.js http://mudcu.be/midi-js/
我试着寻找一个地方来发布关于使用它的问题,但没有找到,所以我将在这里尝试。
great这个库工作得很好。
我正试着让一个鼓声来触发,但它不工作。我可以让其他音符从"acoustic_grand_piano“触发,但不仅仅是从"synth_drum”。
我认为midi音符35应该与“声学低音鼓”有关。
使用demo-Basic.html中的示例
window.onload = function () {
MIDI.loadPlugin({
soundfontUrl: "./soundfont/",
instrument: "synth_drum",
callback: function() {
var delay = 0; // play one note every quarter second
var note = 35; // the MIDI note
var velocity = 127; // how hard the note hits
// play the note
MIDI.setVolume(0, 127);
MIDI.noteOn(0, note, velocity, delay);
MIDI.noteOff(0, note, delay + 0.75);
}
});
};发布于 2013-10-03 12:09:07
在播放"synth_drum“声音之前,您必须将该乐器加载到通道中。这是通过programChange函数完成的。正确的方法如下。
MIDI.loadPlugin({
soundfontUrl: "/apps/spaceharp/static/soundfont/",
instrument: "synth_drum",
callback: function() {
var delay = 0; // play one note every quarter second
var note = 35; // the MIDI note
var velocity = 127; // how hard the note hits
// play the note
MIDI.programChange(0, 118); // Load "synth_drum" (118) into channel 0
MIDI.setVolume(0, 127);
MIDI.noteOn(0, note, velocity, delay); // Play note on channel 0
MIDI.noteOff(0, note, delay + 0.75); // Stop note on channel 0
}
});MIDI standardized specification (或通用MIDI)为每种乐器指定一个特定的名称和编号。在MIDI规范中查找"Synth Drum“可以得到乐器编号为118,因此需要将118加载到通道0中。
您可以找到仪器映射in the MIDI.js source的列表。MIDI.GeneralMIDI中还有一些方便的函数,可以获取仪器信息byName、byId和byCategory。
https://stackoverflow.com/questions/17767387
复制相似问题