Skip to content

Instantly share code, notes, and snippets.

@blackrobot
Created November 29, 2011 06:34
Show Gist options
  • Save blackrobot/1403712 to your computer and use it in GitHub Desktop.
Save blackrobot/1403712 to your computer and use it in GitHub Desktop.
var suite = {};
var UPDATE_INTERVAL = 33;
var LOAD_UPDATE_INTERVAL = 80;
var TOTAL_NOTES = 38;
var BPM_NORM = 145;
var MOUSE_SPEED_MIN = 70;
var MOUSE_SPEED_MAX = 1500;
var MOUSE_SPEED_RATIO_GRAB = 0.4;
var MOUSE_AVERAGE_COUNT = 5;
var TOTAL_THREADS = 8;
var TOTAL_NOTES_IN_SONG = SONG_DATA_ARRAY.length;
var NOTE_UNIT = 2;
var HALF_STEP_MULTIPLIER = 0.94921875;
var MAX_LENGTH = 590;
var MIN_LENGTH = MAX_LENGTH * Math.pow(HALF_STEP_MULTIPLIER, TOTAL_NOTES - 1);
var MATH_PI = Math.PI;
var SHOW_FRAMERATE = false;
var mouseX = 0,
mouseY = 0;
var MIDI_MAP = {
"36": 0,
"37": 1,
"38": 2,
"39": 3,
"40": 4,
"41": 5,
"42": 6,
"43": 7,
"44": 8,
"45": 9,
"46": 10,
"47": 11,
"48": 12,
"49": 13,
"50": 14,
"51": 15,
"52": 16,
"53": 17,
"54": 18,
"55": 19,
"56": 20,
"57": 21,
"58": 22,
"59": 23,
"60": 24,
"61": 25,
"62": 26,
"63": 27,
"64": 28,
"65": 29,
"66": 30,
"67": 31,
"68": 32,
"69": 33,
"70": 34,
"71": 35,
"72": 36
};
soundManager.url = "swf/sm2/";
soundManager.flashVersion = 9;
soundManager.useFastPolling = false;
soundManager.useHighPerformance = true;
soundManager.useFlashBlock = true;
soundManager.debugMode = true;
soundManager.wmode = "transparent";
soundManager.onready(function () {
suite.indNoteLd = 0;
suite.smLoadSnd(0);
});
suite.everythingIsReady = function () {
if (suite.ready) {
return;
}
suite.ready = true;
suite.machine.doneLoading();
};
suite.init = function () {
suite.ready = false;
suite.initMidiMap();
suite.urlVersion = parseInt(getQueryVariable("v"));
window.addEventListener("resize", rsize, false);
document.addEventListener("mousemove", function (a) {
mouseX = a.pageX;
mouseY = a.pageY;
}, false);
document.addEventListener("mousedown", function (a) {
mousePressed = true;
if (suite.machine.mouseDown != undefined) {
suite.machine.mouseDown(a);
}
a.preventDefault();
}, false);
document.addEventListener("mouseup", function (a) {
mousePressed = false;
if (suite.machine.mouseUp != undefined) {
suite.machine.mouseUp(a);
}
}, false);
suite.canvasEl = document.getElementById("main-canvas");
suite.canvasObj = suite.canvasEl.getContext("2d");
suite.machine = new Machine(suite.canvasObj);
suite.indNoteLd = 0;
rsize();
suite.machine.build();
suite.machine.beginLoading();
setInterval(updateLoop, UPDATE_INTERVAL);
};
suite.initMidiMap = function () {
suite.arrMidiMap = new Array();
var a;
for (key in MIDI_MAP) {
a = parseInt(key);
suite.arrMidiMap[a] = MIDI_MAP[key];
}
};
var updateLoop = function () {
suite.machine.upd();
};
init = function () {
suite.init();
};
suite.smLoadSnd = function (b) {
var c = b < 10 ? "0" : "";
var a = soundManager.createSound({
id: "note" + b,
url: "audio/harp_" + c + b + ".mp3",
autoLoad: true,
multiShot: true,
multiShotEvents: false,
onload: function () {
suite.smLoadedSnd(this["ahcInd"]);
}
});
a.ahcInd = b;
};
suite.smLoadedSnd = function (a) {
suite.indNoteLd = a;
if (suite.indNoteLd >= TOTAL_NOTES - 1) {
suite.smLoadedAll();
} else {
suite.indNoteLd++;
suite.smLoadSnd(suite.indNoteLd);
}
};
suite.smPlayNote = function (d, c, b) {
var a = soundManager.getSoundById("note" + d);
if (a == null) {
return;
}
a.play({
volume: 100 * c,
pan: 100 * b
});
};
suite.smLoadedAll = function () {
suite.soundAvailable = true;
suite.soundReady = true;
suite.everythingIsReady();
};
var rsize = function () {
width = window.innerWidth;
height = window.innerHeight;
if (suite.machine != null) {
suite.machine.rsize();
}
};
function getQueryVariable(a) {
var c = window.location.search.substring(1);
var d = c.split("&");
for (var b = 0; b < d.length; b++) {
var e = d[b].split("=");
if (e[0] == a) {
return e[1];
}
}
return null;
}
if (!window.console) {
console = {};
}
console.log = console.log ||
function () {};
console.warn = console.warn ||
function () {};
console.error = console.error ||
function () {};
console.info = console.info ||
function () {};
var runGoogleAnalytics = function () {
var b = document.createElement("script");
b.type = "text/javascript";
b.async = true;
b.src = ("https:" == document.location.protocol ? "https://ssl" : "http://www") + ".google-analytics.com/ga.js";
var a = document.getElementsByTagName("script")[0];
a.parentNode.insertBefore(b, a);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment