简体   繁体   English

使用基于javascript浏览器的midi.js创建鼓声?

[英]Use javascript browser based midi.js to create a drum sound?

I have been trying to use midi.js http://mudcu.be/midi-js/ 我一直在尝试使用midi.js http://mudcu.be/midi-js/

I have tried looking for a place to post questions about using it but having found none so I am going to try here.. 我一直在寻找一个地方发布关于使用它的问题,但没有找到,所以我将在这里尝试..

1st off the library works great. 图书馆的第一个工作很棒。

I'm trying to get a just a drum sound to trigger but it is not working. 我试图让一个鼓声只能触发,但它无法正常工作。 I can get other notes to trigger from "acoustic_grand_piano" but not from just "synth_drum". 我可以从“acoustic_grand_piano”中获取其他音符,而不是仅仅从“synth_drum”触发。

I think midi note 35 should relate to the "Acoustic Bass Drum". 我认为midi音符35应该与“Acoustic Bass Drum”有关。

Using the sample from the demo-Basic.html 使用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);
        }
    });
};

Before playing the "synth_drum" sounds you must load that instrument into a channel. 在播放“synth_drum”声音之前,您必须将该乐器加载到通道中。 This is done with the programChange function. 这是通过programChange函数完成的。 The correct method is the following. 正确的方法如下。

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 (or General MIDI) assigns a specific name and number to each instrument. MIDI标准化规范 (或通用MIDI)为每个乐器指定一个特定的名称和编号。 Looking up "Synth Drum" in the MIDI specification gives an instrument number of 118 and thus the need to load 118 into channel 0. 在MIDI规范中查找“Synth Drum”会给出一个118的乐器编号,因此需要将118加载到通道0中。

You can find a list of instrument mappings in the MIDI.js source . 您可以在MIDI.js源中找到乐器映射列表。 There are also handy functions in MIDI.GeneralMIDI that will fetch instrument information byName, byId, and byCategory. MIDI.GeneralMIDI中还有一些方便的功能,可以通过Name,byId和byCategory获取乐器信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM