updates for flash and safari, tweaks here and there

This commit is contained in:
Michael Deal 2012-04-13 21:59:48 -07:00
parent 214d1917b0
commit e31044b6b8
9 changed files with 35 additions and 27 deletions

View file

@ -1,6 +1,6 @@
The MIT License
Copyright (c) 2011-2012 MIDI.js Authors. All rights reserved.
Copyright (c) 2010-2012 MIDI.js Authors. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View file

@ -135,7 +135,7 @@ MIDI.Player.setAnimation(function(data) {
<br>Coded by <a href="http://mudcu.be/">mud</a>.</li>
<hr size=1 style="opacity: 0.25;">
<li class="indent square">
<a href="http://mudcu.be/midi.js/WhitneyMusicBox.html">Whitney Music Box</a><br>Beautiful HTML5 simulation of a Whitney Music Box.
<a href="http://mudcu.be/midi-js/WhitneyMusicBox.html">Whitney Music Box</a><br>Beautiful HTML5 simulation of a Whitney Music Box.
<br>Coded by <a href="http://www.krazydad.com/">KrazyDad</a>.</li>
</div>
<script type="text/javascript">
@ -144,7 +144,7 @@ if (typeof(console) === "undefined") var console = { log: function() { } };
// Begin loading indication.
var loader = new widgets.Loader({
message: "&lt;loading&gt;<br>MIDI.js..."
message: "loading: Soundfont..."
});
// Tchaikovsky via Disklavier World.
@ -357,6 +357,17 @@ var ColorSphereBackground = function() {
ctx.drawImage(theSphere = sphere(percent), 0, 0)
};
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-420768-7']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</body>
</html>

View file

@ -139,4 +139,3 @@ MIDI.Player.setAnimation(function(data) {
<li>Flash package: &nbsp;<a href="http://www.schillmania.com/projects/soundmanager2/">SoundManager2</a> by <a href="http://schillmania.com">Scott Schiller</a></li>
<li><a href="https://github.com/gasman/jasmid">jasmid</a>: &nbsp;Reads MIDI file byte-code, and translats into a Javascript array.</li>
<li><a href="http://blog.danguer.com/2011/10/24/base64-binary-decoding-in-javascript/">base642binary.js</a>: &nbsp;Cleans up XML base64-requests for Web Audio API.</li>

View file

@ -56,7 +56,7 @@ root.clearAnimation = function() {
root.setAnimation = function(config) {
var callback = (typeof(config) === "function") ? config : config.callback;
var delay = config.delay || 100;
var delay = config.delay || 24;
var currentTime = 0;
var tOurTime = 0;
var tTheirTime = 0;
@ -96,7 +96,7 @@ root.setAnimation = function(config) {
// helpers
var loadMidiFile = function() { // reads midi into javascript array of events
root.loadMidiFile = function() { // reads midi into javascript array of events
root.replayer = new Replayer(MidiFile(root.currentData), root.timeWarp);
root.data = root.replayer.getData();
root.endTime = getLength();
@ -107,7 +107,7 @@ root.loadFile = function (file, callback) {
if (file.indexOf("base64,") !== -1) {
var data = window.atob(file.split(",")[1]);
root.currentData = data;
loadMidiFile();
root.loadMidiFile();
if (callback) callback(data);
return;
}
@ -125,7 +125,7 @@ root.loadFile = function (file, callback) {
}
var data = window.atob(ff.join(""));
root.currentData = data;
loadMidiFile();
root.loadMidiFile();
if (callback) callback(data);
}
};

View file

@ -280,7 +280,7 @@ if (window.Audio) (function () {
root.connect = function (callback) {
soundManager.flashVersion = 9;
soundManager.useHTML5Audio = true;
soundManager.url = '../../swf/';
soundManager.url = '../inc/SoundManager2/swf/';
soundManager.useHighPerformance = true;
soundManager.wmode = 'transparent';
soundManager.flashPollingInterval = 1;
@ -292,8 +292,8 @@ if (window.Audio) (function () {
if (typeof (loader) === "undefined") return;
loader.message("Processing: " + this.sID);
};
for (var i = 10; i < 65 + 10; i++) {
var id = noteReverse[i + 26];
for (var i = 0; i < 88; i++) {
var id = noteReverse[i + 21];
notes[id] = soundManager.createSound({
id: id,
url: './soundfont/mp3/' + id + '.mp3',
@ -311,7 +311,7 @@ if (window.Audio) (function () {
MIDI.chordOff = root.chordOff;
//
var interval = window.setInterval(function () {
if (loaded.length !== 65) return;
if (loaded.length !== 88) return;
window.clearInterval(interval);
if (callback) callback();
}, 25);

View file

@ -15,7 +15,7 @@ if (typeof (MIDI.Soundfont) === "undefined") MIDI.Soundfont = {};
var plugins = { "#webaudio": true, "#html5": true, "#java": true, "#flash": true };
MIDI.loadPlugin = function(callback, instrument) {
var type, loader;
var type = "";
var instrument = instrument || "";
MIDI.audioDetect(function(types) {
// use the most appropriate plugin if not specified
@ -27,15 +27,15 @@ MIDI.loadPlugin = function(callback, instrument) {
}
}
if (type === "") {
var isSafari = navigator.userAgent.toLowerCase().indexOf("safari") !== -1;
if (window.webkitAudioContext) { // Chrome
type = "#webaudio";
} else if (window.Audio && isSafari === false) { // Firefox
} else if (window.Audio) { // Firefox
type = "#html5";
} else { // Safari and Internet Explorer
} else { // Internet Explorer
type = "#flash";
}
}
if (typeof(loader) === "undefined") var loader;
// use audio/ogg when supported
var filetype = types["audio/ogg"] ? "ogg" : "mp3";
// load the specified plugin
@ -59,7 +59,7 @@ MIDI.loadPlugin = function(callback, instrument) {
case "#html5":
// works well in Firefox
DOMLoader.sendRequest({
url: "./soundfont/soundfont-" + filetype + ".js",
url: "./soundfont/soundfont-" + filetype + instrument + ".js",
callback: function (response) {
MIDI.Soundfont = JSON.parse(response.responseText);
if (loader) loader.message("Downloading: 100%<br>Processing...");

View file

@ -7,7 +7,6 @@ var clone = function (o) {
};
function Replayer(midiFile, timeWarp, eventProcessor) {
//console.log(midiFile)
var trackStates = [];
var beatsPerMinute = 120;
var ticksPerBeat = midiFile.header.ticksPerBeat;
@ -64,7 +63,7 @@ function Replayer(midiFile, timeWarp, eventProcessor) {
var beatsToGenerate = midiEvent.ticksToEvent / ticksPerBeat;
var secondsToGenerate = beatsToGenerate / (beatsPerMinute / 60);
}
var time = secondsToGenerate * 1000 * timeWarp || 0;
var time = (secondsToGenerate * 1000 * timeWarp) || 0;
temporal.push([ midiEvent, time]);
midiEvent = getNextEvent();
};
@ -76,7 +75,6 @@ function Replayer(midiFile, timeWarp, eventProcessor) {
processEvents();
return {
"getData": function() {
// console.log(temporal)
return clone(temporal);
}
};

View file

@ -7,7 +7,6 @@ var clone = function (o) {
};
function Replayer(midiFile, timeWarp, eventProcessor) {
//console.log(midiFile)
var trackStates = [];
var beatsPerMinute = 120;
var ticksPerBeat = midiFile.header.ticksPerBeat;
@ -64,7 +63,7 @@ function Replayer(midiFile, timeWarp, eventProcessor) {
var beatsToGenerate = midiEvent.ticksToEvent / ticksPerBeat;
var secondsToGenerate = beatsToGenerate / (beatsPerMinute / 60);
}
var time = secondsToGenerate * 1000 * timeWarp || 0;
var time = (secondsToGenerate * 1000 * timeWarp) || 0;
temporal.push([ midiEvent, time]);
midiEvent = getNextEvent();
};
@ -76,7 +75,6 @@ function Replayer(midiFile, timeWarp, eventProcessor) {
processEvents();
return {
"getData": function() {
// console.log(temporal)
return clone(temporal);
}
};

View file

@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<script src="./js/DOMLoader.XMLHttp.js" type="text/javascript"></script>
<script src="./js/DOMLoader.script.js" type="text/javascript"></script>
@ -16,12 +16,14 @@
window.onload = function () {
MIDI.loadPlugin(function() {
for (var n = 50; n < 100; n ++) {
var delay = (n - 50) / 4; // play one note every quarter second
for (var n = 0; n < 100; n ++) {
var delay = n / 4; // play one note every quarter second
var note = MIDI.pianoKeyOffset + n; // the MIDI note
var velocity = 127; // how hard the note hits
// play the note
MIDI.noteOn(0, note, velocity, delay);
// play the some note 3-steps up
MIDI.noteOn(0, note + 3, velocity, delay);
}
});
};