Merge pull request #21 from bsstoner/flash

flash api isn't loading any of the mp3 samples
This commit is contained in:
Michael Deal 2013-03-20 16:47:54 -07:00
commit e9c2766858
2 changed files with 11 additions and 7 deletions

View file

@ -75,7 +75,7 @@ connect.flash = function(filetype, instruments, conf) {
src: conf.soundManagerUrl || "./inc/SoundManager2/script/soundmanager2.js", src: conf.soundManagerUrl || "./inc/SoundManager2/script/soundmanager2.js",
verify: "SoundManager", verify: "SoundManager",
callback: function () { callback: function () {
MIDI.Flash.connect(conf); MIDI.Flash.connect(instruments, conf);
} }
}); });
}; };

View file

@ -424,7 +424,7 @@ if (window.Audio) (function () {
}; };
root.connect = function (conf) { root.connect = function (instruments, conf) {
soundManager.flashVersion = 9; soundManager.flashVersion = 9;
soundManager.useHTML5Audio = true; soundManager.useHTML5Audio = true;
soundManager.url = conf.soundManagerSwfUrl || '../inc/SoundManager2/swf/'; soundManager.url = conf.soundManagerSwfUrl || '../inc/SoundManager2/swf/';
@ -444,15 +444,19 @@ if (window.Audio) (function () {
onload: onload onload: onload
}); });
}; };
for (var instrument in MIDI.Soundfont) { var loaded = [];
var loaded = []; var samplesPerInstrument = 88;
var samplesToLoad = instruments.length * samplesPerInstrument;
for (var i = 0; i < instruments.length; i++) {
var instrument = instruments[i];
var onload = function () { var onload = function () {
loaded.push(this.sID); loaded.push(this.sID);
if (typeof (MIDI.loader) === "undefined") return; if (typeof (MIDI.loader) === "undefined") return;
MIDI.loader.update(null, "Processing: " + this.sID); MIDI.loader.update(null, "Processing: " + this.sID);
}; };
for (var i = 0; i < 88; i++) { for (var j = 0; j < samplesPerInstrument; j++) {
var id = noteReverse[i + 21]; var id = noteReverse[j + 21];
createBuffer(instrument, id, onload); createBuffer(instrument, id, onload);
} }
} }
@ -460,7 +464,7 @@ if (window.Audio) (function () {
setPlugin(root); setPlugin(root);
// //
var interval = window.setInterval(function () { var interval = window.setInterval(function () {
if (loaded.length !== 88) return; if (loaded.length < samplesToLoad) return;
window.clearInterval(interval); window.clearInterval(interval);
if (conf.callback) conf.callback(); if (conf.callback) conf.callback();
}, 25); }, 25);