detangle loader, add configuration MIDI.soundfontUrl to set the base-path to your soundfonts
This commit is contained in:
parent
f723a45652
commit
d0cf6085d7
9 changed files with 51 additions and 55 deletions
|
@ -1,11 +1,11 @@
|
|||
/*
|
||||
|
||||
-------------------------------------
|
||||
MIDI.Player : 0.3
|
||||
-------------------------------------
|
||||
https://github.com/mudcube/MIDI.js
|
||||
-------------------------------------
|
||||
requires jasmid
|
||||
|
||||
#jasmid
|
||||
-------------------------------------
|
||||
*/
|
||||
|
||||
if (typeof (MIDI) === "undefined") var MIDI = {};
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
--------------------------------------------
|
||||
MIDI.Plugin : 0.3 : 11/20/2012
|
||||
--------------------------------------------
|
||||
https://github.com/mudx/MIDI.js
|
||||
https://github.com/mudcube/MIDI.js
|
||||
--------------------------------------------
|
||||
MIDI.WebAudioAPI
|
||||
MIDI.Flash
|
||||
|
@ -14,7 +14,7 @@
|
|||
--------------------------------------------
|
||||
setMute?
|
||||
getInstruments?
|
||||
|
||||
-------------------------------------
|
||||
*/
|
||||
|
||||
if (typeof (MIDI) === "undefined") var MIDI = {};
|
||||
|
@ -49,8 +49,8 @@ if (window.AudioContext || window.webkitAudioContext) (function () {
|
|||
ctx.decodeAudioData(buffer, function (buffer) {
|
||||
var msg = url;
|
||||
while (msg.length < 3) msg += " ";
|
||||
if (typeof (loader) !== "undefined") {
|
||||
loader.message(synth.instrument + "<br>Processing: " + (index / 87 * 100 >> 0) + "%<br>" + msg);
|
||||
if (typeof (MIDI.loader) !== "undefined") {
|
||||
MIDI.loader.update(null, synth.instrument + "<br>Processing: " + (index / 87 * 100 >> 0) + "%<br>" + msg);
|
||||
}
|
||||
buffer.id = url;
|
||||
bufferList[index] = buffer;
|
||||
|
@ -330,7 +330,7 @@ if (window.Audio) (function () {
|
|||
var instrumentId = synth.number;
|
||||
notes[instrumentId+""+id] = soundManager.createSound({
|
||||
id: id,
|
||||
url: "./soundfont/"+instrument+"-mp3/" + id + ".mp3",
|
||||
url: MIDI.soundfontUrl + instrument + "-mp3/" + id + ".mp3",
|
||||
multiShot: true,
|
||||
autoLoad: true,
|
||||
onload: onload
|
||||
|
@ -340,8 +340,8 @@ if (window.Audio) (function () {
|
|||
var loaded = [];
|
||||
var onload = function () {
|
||||
loaded.push(this.sID);
|
||||
if (typeof (loader) === "undefined") return;
|
||||
loader.message("Processing: " + this.sID);
|
||||
if (typeof (MIDI.loader) === "undefined") return;
|
||||
MIDI.loader.update(null, "Processing: " + this.sID);
|
||||
};
|
||||
for (var i = 0; i < 88; i++) {
|
||||
var id = noteReverse[i + 21];
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
/*
|
||||
|
||||
-------------------------------------
|
||||
MIDI.audioDetect : 0.3
|
||||
-------------------------------------
|
||||
https://github.com/mudx/MIDI.js
|
||||
https://github.com/mudcube/MIDI.js
|
||||
-------------------------------------
|
||||
Probably, Maybe, No... Absolutely!
|
||||
-------------------------------------
|
||||
Test to see what types of <audio> MIME types are playable by the browser.
|
||||
|
||||
-------------------------------------
|
||||
*/
|
||||
|
||||
if (typeof(MIDI) === "undefined") var MIDI = {};
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
-----------------------------------------------------------
|
||||
MIDI.loadPlugin : 0.1 : 11/20/2012
|
||||
-----------------------------------------------------------
|
||||
https://github.com/mudx/MIDI.js
|
||||
https://github.com/mudcube/MIDI.js
|
||||
-----------------------------------------------------------
|
||||
MIDI.loadPlugin({
|
||||
instrument: "acoustic_grand_piano", // or 1 (default)
|
||||
|
@ -26,6 +26,8 @@ MIDI.loadPlugin = function(conf) {
|
|||
MIDI.Soundfont[data] = true;
|
||||
return data;
|
||||
});
|
||||
///
|
||||
MIDI.soundfontUrl = conf.soundfontUrl || MIDI.soundfontUrl || "./soundfont/";
|
||||
/// Detect the best type of audio to use.
|
||||
MIDI.audioDetect(function(types) {
|
||||
var type = "";
|
||||
|
@ -60,15 +62,13 @@ var connect = {};
|
|||
|
||||
connect.java = function(filetype, instruments, callback) {
|
||||
// works well cross-browser, and fully featured, but has delay when Java machine starts.
|
||||
if (typeof(loader) === "undefined") var loader;
|
||||
if (loader) loader.message("Soundfont (500KB)<br>Java Interface...");
|
||||
if (MIDI.loader) MIDI.loader.message("Java API...");
|
||||
MIDI.Java.connect(callback);
|
||||
};
|
||||
|
||||
connect.flash = function(filetype, instruments, callback) {
|
||||
// fairly quick, but requires loading of individual MP3s (more http requests).
|
||||
if (typeof(loader) === "undefined") var loader;
|
||||
if (loader) loader.message("Soundfont (2MB)<br>Flash Interface...");
|
||||
if (MIDI.loader) MIDI.loader.message("Flash API...");
|
||||
DOMLoader.script.add({
|
||||
src: "./inc/SoundManager2/script/soundmanager2.js",
|
||||
verify: "SoundManager",
|
||||
|
@ -79,21 +79,18 @@ connect.flash = function(filetype, instruments, callback) {
|
|||
};
|
||||
|
||||
connect.audiotag = function(filetype, instruments, callback) {
|
||||
if (MIDI.loader) MIDI.loader.message("HTML5 Audio API...");
|
||||
// works ok, kinda like a drunken tuna fish, across the board.
|
||||
if (typeof(loader) === "undefined") var loader;
|
||||
var queue = createQueue({
|
||||
items: instruments,
|
||||
getNext: function(instrumentId) {
|
||||
DOMLoader.sendRequest({
|
||||
url: "./soundfont/" + instrumentId + "-" + filetype + ".js",
|
||||
url: MIDI.soundfontUrl + instrumentId + "-" + filetype + ".js",
|
||||
onprogress: getPercent,
|
||||
onload: function (response) {
|
||||
MIDI.Soundfont[instrumentId] = JSON.parse(response.responseText);
|
||||
if (loader) loader.message("Downloading", 100);
|
||||
if (MIDI.loader) MIDI.loader.update(null, "Downloading", 100);
|
||||
queue.getNext();
|
||||
},
|
||||
onprogress: function (evt) {
|
||||
var percent = Math.round(evt.loaded / evt.total * 100);
|
||||
if (loader) loader.message("Downloading", percent);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
@ -104,20 +101,18 @@ connect.audiotag = function(filetype, instruments, callback) {
|
|||
};
|
||||
|
||||
connect.webaudio = function(filetype, instruments, callback) {
|
||||
if (MIDI.loader) MIDI.loader.message("Web Audio API...");
|
||||
// works awesome! safari and chrome support
|
||||
var queue = createQueue({
|
||||
items: instruments,
|
||||
getNext: function(instrumentId) {
|
||||
DOMLoader.sendRequest({
|
||||
url: "./soundfont/" + instrumentId + "-" + filetype + ".js",
|
||||
url: MIDI.soundfontUrl + instrumentId + "-" + filetype + ".js",
|
||||
onprogress: getPercent,
|
||||
onload: function(response) {
|
||||
MIDI.Soundfont[instrumentId] = JSON.parse(response.responseText);
|
||||
if (loader) loader.message("Downloading", 100);
|
||||
if (MIDI.loader) MIDI.loader.update(null, "Downloading...", 100);
|
||||
queue.getNext();
|
||||
},
|
||||
onprogress: function (evt) {
|
||||
var percent = Math.round(evt.loaded / evt.total * 100);
|
||||
if (loader) loader.message("Downloading", percent);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
@ -136,6 +131,18 @@ var plugins = {
|
|||
"#flash": true
|
||||
};
|
||||
|
||||
var getPercent = function(event) {
|
||||
if (!this.totalSize) {
|
||||
if (this.getResponseHeader("Content-Length-Raw")) {
|
||||
this.totalSize = parseInt(this.getResponseHeader("Content-Length-Raw"));
|
||||
} else {
|
||||
this.totalSize = event.total;
|
||||
}
|
||||
}
|
||||
var percent = this.totalSize ? Math.round(event.loaded / this.totalSize * 100) : "";
|
||||
if (MIDI.loader) MIDI.loader.update(null, "Downloading...", percent);
|
||||
};
|
||||
|
||||
var createQueue = function(conf) {
|
||||
var self = {};
|
||||
self.queue = [];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue