2012-02-16 05:46:03 +01:00
|
|
|
/*
|
|
|
|
|
|
|
|
MIDI.loadPlugin(callback, type);
|
|
|
|
-------------------------------------
|
|
|
|
https://github.com/mudx/MIDI.js
|
|
|
|
-------------------------------------
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (typeof (MIDI) === "undefined") var MIDI = {};
|
|
|
|
if (typeof (MIDI.Soundfont) === "undefined") MIDI.Soundfont = {};
|
|
|
|
|
|
|
|
(function() { "use strict";
|
|
|
|
|
|
|
|
var plugins = { "#webaudio": true, "#html5": true, "#java": true, "#flash": true };
|
|
|
|
|
|
|
|
MIDI.loadPlugin = function(callback, instrument) {
|
2012-04-14 06:59:48 +02:00
|
|
|
var type = "";
|
2012-02-16 05:46:03 +01:00
|
|
|
var instrument = instrument || "";
|
|
|
|
MIDI.audioDetect(function(types) {
|
|
|
|
// use the most appropriate plugin if not specified
|
|
|
|
if (typeof(type) === 'undefined') {
|
|
|
|
if (plugins[window.location.hash]) {
|
|
|
|
type = window.location.hash;
|
|
|
|
} else {
|
|
|
|
type = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (type === "") {
|
|
|
|
if (window.webkitAudioContext) { // Chrome
|
|
|
|
type = "#webaudio";
|
2012-04-14 06:59:48 +02:00
|
|
|
} else if (window.Audio) { // Firefox
|
2012-02-16 05:46:03 +01:00
|
|
|
type = "#html5";
|
2012-04-14 06:59:48 +02:00
|
|
|
} else { // Internet Explorer
|
2012-02-16 05:46:03 +01:00
|
|
|
type = "#flash";
|
|
|
|
}
|
|
|
|
}
|
2012-04-14 06:59:48 +02:00
|
|
|
if (typeof(loader) === "undefined") var loader;
|
2012-02-16 05:46:03 +01:00
|
|
|
// use audio/ogg when supported
|
|
|
|
var filetype = types["audio/ogg"] ? "ogg" : "mp3";
|
|
|
|
// load the specified plugin
|
|
|
|
switch (type) {
|
|
|
|
case "#java":
|
|
|
|
// works well cross-browser, and highly featured, but required Java machine to startup
|
|
|
|
if (loader) loader.message("Soundfont (500KB)<br>Java Interface...");
|
|
|
|
MIDI.Java.connect(callback);
|
|
|
|
break;
|
|
|
|
case "#flash":
|
|
|
|
// fairly quick, but requires loading of individual MP3s
|
|
|
|
if (loader) loader.message("Soundfont (2MB)<br>Flash Interface...");
|
|
|
|
DOMLoader.script.add({
|
|
|
|
src: "./inc/SoundManager2/script/soundmanager2.js",
|
|
|
|
verify: "SoundManager",
|
|
|
|
callback: function () {
|
|
|
|
MIDI.Flash.connect(callback);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case "#html5":
|
|
|
|
// works well in Firefox
|
|
|
|
DOMLoader.sendRequest({
|
2012-04-14 06:59:48 +02:00
|
|
|
url: "./soundfont/soundfont-" + filetype + instrument + ".js",
|
2012-02-16 05:46:03 +01:00
|
|
|
callback: function (response) {
|
|
|
|
MIDI.Soundfont = JSON.parse(response.responseText);
|
|
|
|
if (loader) loader.message("Downloading: 100%<br>Processing...");
|
|
|
|
MIDI.HTML5.connect(callback);
|
|
|
|
},
|
|
|
|
progress: function (evt) {
|
|
|
|
var percent = evt.loaded / 1719931 * 100 >> 0;
|
|
|
|
if (loader) loader.message("Downloading: " + (percent + "%"));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case "#webaudio":
|
|
|
|
// works well in Chrome
|
|
|
|
DOMLoader.sendRequest({
|
|
|
|
url: "./soundfont/soundfont-" + filetype + instrument + ".js",
|
|
|
|
callback: function(response) {
|
|
|
|
MIDI.Soundfont = JSON.parse(response.responseText);
|
|
|
|
if (loader) loader.message("Downloading: 100%<br>Processing...");
|
|
|
|
MIDI.WebAudioAPI.connect(callback);
|
|
|
|
},
|
|
|
|
progress: function (evt) {
|
|
|
|
var percent = evt.loaded / 1719931 * 100 >> 0;
|
|
|
|
if (loader) loader.message("Downloading: " + (percent + "%"));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|