JSFiddle - React, Tailwind, and code Playground
by nimrodsarda
JavaScript
//injecting the script
var addSoundfont = function(text) {
var script = document.createElement("script");
script.language = "javascript";
script.type = "text/javascript";
script.text = text;
document.body.appendChild(script);
};
// calling addSoundFont
connect.webaudio = function(filetype, instruments, conf) {
if (MIDI.loader) MIDI.loader.message("Web Audio API...");
// works awesome! safari, chrome and firefox support.
var queue = createQueue({
items: instruments,
getNext: function(instrumentId) {
DOMLoader.sendRequest({
url: MIDI.soundfontUrl + instrumentId + "-" + filetype + ".js",
onprogress: getPercent,
onload: function(response) {
addSoundfont(response.responseText);
if (MIDI.loader) MIDI.loader.update(null, "Downloading...", 100);
queue.getNext();
}
});
},
onComplete: function() {
MIDI.WebAudio.connect(conf);
}
});
};