From 277a7e04aafe214fc8ed085b2aef624eecbcab68 Mon Sep 17 00:00:00 2001 From: Brian Stoner Date: Tue, 12 Mar 2013 15:54:04 -0400 Subject: [PATCH] Pass instruments into flash.connect(), so that it can load all the sample .mp3 files --- js/MIDI/LoadPlugin.js | 2 +- js/MIDI/Plugin.js | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/js/MIDI/LoadPlugin.js b/js/MIDI/LoadPlugin.js index 3e1bff2..9df1802 100644 --- a/js/MIDI/LoadPlugin.js +++ b/js/MIDI/LoadPlugin.js @@ -75,7 +75,7 @@ connect.flash = function(filetype, instruments, conf) { src: "./inc/SoundManager2/script/soundmanager2.js", verify: "SoundManager", callback: function () { - MIDI.Flash.connect(conf); + MIDI.Flash.connect(instruments, conf); } }); }; diff --git a/js/MIDI/Plugin.js b/js/MIDI/Plugin.js index e391e1e..a6880f1 100644 --- a/js/MIDI/Plugin.js +++ b/js/MIDI/Plugin.js @@ -424,7 +424,7 @@ if (window.Audio) (function () { }; - root.connect = function (conf) { + root.connect = function (instruments, conf) { soundManager.flashVersion = 9; soundManager.useHTML5Audio = true; soundManager.url = '../inc/SoundManager2/swf/'; @@ -444,15 +444,19 @@ if (window.Audio) (function () { 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 () { loaded.push(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]; + for (var j = 0; j < samplesPerInstrument; j++) { + var id = noteReverse[j + 21]; createBuffer(instrument, id, onload); } } @@ -460,7 +464,7 @@ if (window.Audio) (function () { setPlugin(root); // var interval = window.setInterval(function () { - if (loaded.length !== 88) return; + if (loaded.length < samplesToLoad) return; window.clearInterval(interval); if (conf.callback) conf.callback(); }, 25);