From e31044b6b81c6f41c91f240a335f1889229c3710 Mon Sep 17 00:00:00 2001 From: Michael Deal Date: Fri, 13 Apr 2012 21:59:48 -0700 Subject: [PATCH] updates for flash and safari, tweaks here and there --- LICENSE.txt | 2 +- MIDIPlayer.html | 15 +++++++++++++-- README.html | 1 - js/MIDI.Player.js | 8 ++++---- js/MIDI.Plugin.js | 8 ++++---- js/MIDI.loadPlugin.js | 10 +++++----- js/lib/jasmid/jasmid/replayer.js | 4 +--- js/lib/jasmid/replayer.js | 4 +--- minimal.html | 10 ++++++---- 9 files changed, 35 insertions(+), 27 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index 6c8c604..5ea8157 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -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 diff --git a/MIDIPlayer.html b/MIDIPlayer.html index 712bf76..293818d 100644 --- a/MIDIPlayer.html +++ b/MIDIPlayer.html @@ -135,7 +135,7 @@ MIDI.Player.setAnimation(function(data) {
Coded by mud.
  • - Whitney Music Box
    Beautiful HTML5 simulation of a Whitney Music Box. + Whitney Music Box
    Beautiful HTML5 simulation of a Whitney Music Box.
    Coded by KrazyDad.
  • + \ No newline at end of file diff --git a/README.html b/README.html index c43bd4e..a965e9c 100644 --- a/README.html +++ b/README.html @@ -139,4 +139,3 @@ MIDI.Player.setAnimation(function(data) {
  • Flash package:  SoundManager2 by Scott Schiller
  • jasmid:  Reads MIDI file byte-code, and translats into a Javascript array.
  • base642binary.js:  Cleans up XML base64-requests for Web Audio API.
  • - diff --git a/js/MIDI.Player.js b/js/MIDI.Player.js index 6c940ed..364eb7f 100644 --- a/js/MIDI.Player.js +++ b/js/MIDI.Player.js @@ -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); } }; diff --git a/js/MIDI.Plugin.js b/js/MIDI.Plugin.js index 9d26203..935b318 100644 --- a/js/MIDI.Plugin.js +++ b/js/MIDI.Plugin.js @@ -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); diff --git a/js/MIDI.loadPlugin.js b/js/MIDI.loadPlugin.js index 218df5f..8dc5ec3 100644 --- a/js/MIDI.loadPlugin.js +++ b/js/MIDI.loadPlugin.js @@ -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%
    Processing..."); diff --git a/js/lib/jasmid/jasmid/replayer.js b/js/lib/jasmid/jasmid/replayer.js index 3ab9c1a..3932762 100644 --- a/js/lib/jasmid/jasmid/replayer.js +++ b/js/lib/jasmid/jasmid/replayer.js @@ -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); } }; diff --git a/js/lib/jasmid/replayer.js b/js/lib/jasmid/replayer.js index 3ab9c1a..3932762 100644 --- a/js/lib/jasmid/replayer.js +++ b/js/lib/jasmid/replayer.js @@ -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); } }; diff --git a/minimal.html b/minimal.html index 207e614..67e921a 100644 --- a/minimal.html +++ b/minimal.html @@ -1,5 +1,5 @@ - - + + @@ -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); } }); };