Skip to content

Instantly share code, notes, and snippets.

@ROBOKiTTY
Created September 19, 2012 03:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ROBOKiTTY/3747539 to your computer and use it in GitHub Desktop.
Save ROBOKiTTY/3747539 to your computer and use it in GitHub Desktop.
Project for a summer course years ago
function synthInit() {
//##### initialization script adapted from auxlib demo #####//
var synth = new aux.synth.Synth(1.0, aux.synth.RATE_FAST, aux.synth.BITS_SAMPLE_16, true); //length, sample rate, bits per sample, stereo
synth.setVibratoWarp(0.0);
synth.addFunc(aux.synth.sinFunc,"Sin",aux.synth.getNoteFreq('a',4),0.5,0.0); //sinwave; func, id, freq, vol, pan
//##### end init for auxlib synth demo #####//
notes = ["C3", "C#3", "D3","D#3", "E3", "F3", "F#3", "G3", "G#3", "A4", "A#4", "B4",
"C4", "C#4", "D4","D#4", "E4", "F4", "F#4", "G4", "G#4", "A5", "A#5", "B5",
"C5", "C#5", "D5","D#5", "E5", "F5", "F#5", "G5", "G#5", "A6", "A#6", "B6", "C7"]; //notes arrayed in keyboard order
var A4 = 440;
//A4 frequency for frequency formula: 440 * 2^(n/12) where n is number of semitones from A4
//http://tomscarff.110mb.com/midi_analyser/midi_note_frequency.htm
//remembers frequencies for later
freqAll = new Array();
var nCount = 0;
for(var nFloor = -21; nFloor < 16; ++nFloor) {
freqAll[nCount] = A4 * Math.pow(2, (nFloor / 12));
nCount++;
}
var A4n = -9; //start with C3
soundContainer = new Array(); //this variable will hold sound data
for(var i = 0, l = notes.length; i < l; ++i) { //caches three octaves
var noteFreq = A4 * Math.pow(2, (A4n / 12));
//document.writeln(noteFreq); //debug
A4n++;
synth.setFreq("Sin", noteFreq);
synth.render();
var note = new aux.ui.Sound(synth.getDataUri(), true);
soundContainer[i] = note;
}
}
function init() { //initializes page
//onkeydown="keyDown(event);" onkeyup="keyUp(event);" onmousedown="playSound(event);"
//event handlers
window.addEventListener("keydown", keyDown, false);
window.addEventListener("keyup", keyUp, false);
window.addEventListener("mousedown", playSound, false);
window.addEventListener("mouseup", mouseUp, false);
soundManager.url = "soundmanager2.swf";
soundManager.debugMode = false;
soundManager.autoLoad = true;
//soundManager.onready(function() {});
bugMeNot = 0; //whether animal is busy; 0 = at home, 1 = making music, 2 = in transit to keyboard, 3 = in transit back home
mozartBusy = 0;
effectSequence = new Array(); //serves as queue for thingEffect
restoreSequence = new Array(); //serves as queue for thingRestore
shifted = 0;
movesRemaining = 4;
moveUp = 1;
rotateCurrVal = 0;
eyePos = [20, 25]; //in px; width, height
pupilPos = [3, 6, 15]; //in px; width, height, bottom
tail = document.getElementById("tail")
tail.style.transform = "rotate(0 deg)";
tailTopLeft = new Array(150, -280);
backgroundColour = "#00FFFF";
leftearStartPos = new Array(25,300); //stores animal's positioning in px; top, left
sunStartPos = new Array(70, 175); //stores sun positioning in px; top, left
//var animalPosLimits = new Array(0, 55, 250, 700); //delimits the high and low ends of random positioning in px: topL, topH, leftL, leftH
// leftearStartPos[0] = Math.floor(Math.random() * 56 ); //randomizes animal's starting location
// leftearStartPos[1] = Math.floor(Math.random() * 451 + 250 );
document.getElementById("leftear").style.top = leftearStartPos[0] + "px";
document.getElementById("leftear").style.left = leftearStartPos[1] + "px";
document.getElementById("speechbubble").style.background = backgroundColour; //speech bubble invisible; momentary flash allows subliminal messages
document.getElementById("speechbubble").style.borderColor = backgroundColour;
document.getElementById("sub-msg").style.color = backgroundColour;
keyboard1 = document.getElementById("keyboard");
keyboard2 = keyboard1.cloneNode(true);
keyboard1.appendChild(keyboard2); //clone octave
keyboard2.id = "keyboard2"; //give it a new id
keyboard2 = document.getElementById("keyboard2");
keyboard2.style.position = "absolute"; //position second octave
keyboard2.style.left = "255px";
keyboard2.style.top = "0px";
keyboard3 = keyboard2.cloneNode(true);
keyboard1.appendChild(keyboard3); //clone again for a full keyboard
keyboard3.id = "keyboard3";
keyboard3 = document.getElementById("keyboard3");
keyboard3.style.position = "absolute"; //hang onto keyboard1, so hopefully won't have to revisit this too often
keyboard3.style.left = "510px";
keyboard3.style.top = "0px";
synthInit();
setTimeout("timeEvents()", 1000);
}
function timeEvents() { //different things happen over time
doRotate(tail, 5);
}
function doRotate(thing, val) { //object to be rotated, value to be added in degrees
//todo: make code less terribad
if(movesRemaining > 0) {
if(moveUp == 1) {
rotateCurrVal += val;
tailTopLeft[0] -= 4;
thing.style.top = tailTopLeft[0] + "px";
}
else {
rotateCurrVal -= val;
tailTopLeft[0] += 4;
thing.style.top = tailTopLeft[0] + "px";
}
movesRemaining--;
}
else {
if(moveUp == 1) {
moveUp = 0;
movesRemaining = 8;
}
else {
moveUp = 1;
movesRemaining = 8;
}
setTimeout(function() {doRotate(tail, val)}, 125);
return;
}
thing.style.transform = "rotate(" + rotateCurrVal + "deg)";
thing.style.webkitTransform = "rotate(" + rotateCurrVal + "deg)"; //for different browsers
thing.style.msTransform = "rotate(" + rotateCurrVal + "deg)";
thing.style.MozTransform = "rotate(" + rotateCurrVal + "deg)";
thing.style.OTransform = "rotate(" + rotateCurrVal + "deg)";
setTimeout(function() {doRotate(tail, val)}, 125);
}
function thingRestore() { //restore first element in restoreSequence and then remove from queue
if(restoreSequence[0].id.match(/(key[a-g]$)|(key[a-g]sharp$)/)) {
try {
restoreSequence[0].style.boxShadow = "0px 3px 5px 2px #aaaaaa";
}
catch(e) {
//doNothing();
}
finally {
restoreSequence[0].style.mozBoxShadow = "0px 3px 5px 2px #aaaaaa";
restoreSequence[0].style.webkitBoxShadow = "0px 3px 5px 2px #aaaaaa";
}
}
if(restoreSequence[0].id.match(/key[a-g]$/)) {
restoreSequence[0].style.background = "#FFFFFF";
}
restoreSequence.shift();
}
function thingEffect() {
if(effectSequence[0].id.match(/(key[a-g]$)|(key[a-g]sharp$)/)) {
try {
effectSequence[0].style.boxShadow = "0px 0px #FFFFFF";
}
catch(e) {
//doNothing();
}
finally {
effectSequence[0].style.mozBoxShadow = "0px 0px #FFFFFF";
effectSequence[0].style.webkitBoxShadow = "0px 0px #FFFFFF";
}
}
if(effectSequence[0].id.match(/key[a-g]$/)) {
effectSequence[0].style.background = "#D8D8D8";
}
effectSequence.shift();
}
function animalMigrate() {
var animalStatus;
if(bugMeNot == 2) {
//migrate to keyboard
bugMeNot = 1;
}
if(bugMeNot == 3) {
//migrate back home
bugMeNot = 0;
}
}
function randomAnimal() {
if (bugMeNot != 0) {
//hurtUser();
}
else {
bugMeNot = 2;
animalMigrate();
var randomAnimalLength = Math.floor(Math.random() * 81 + 25);
randomAnimalContainer = new Array(); //this variable will hold random sound data
for(var i = 0; i < randomAnimalLength; i++) {
if(i == 0) {
var randomNum = Math.floor(Math.random() * 7 + 15);
randomAnimalContainer[i] = notes[randomNum];
//var prevFreq = freqAll[notes.indexOf(randomAnimalContainer[i])]; //freqAll and notes ordered in parallel
var prevNote = randomAnimalContainer[i];
continue;
}
var randomFactor = Math.floor(Math.random() * 100 + 1);
//todo: figure out random music algorithm for below
if(randomFactor > 20) {
var currentNote;
try {
if(randomFactor < 41) {
var currentNote = notes[notes.indexOf(prevNote) + 4];
}
if(randomFactor > 40 && randomFactor < 61) {
var currentNote = notes[notes.indexOf(prevNote) - 4];
}
if(randomFactor > 60 && randomFactor < 81) {
var currentNote = notes[notes.indexOf(prevNote) + 3];
}
if(randomFactor > 80) {
var currentNote = notes[notes.indexOf(prevNote) - 3];
}
}
catch(e) {
//doNothing();
}
randomAnimalContainer[i] = currentNote;
var prevNote = currentNote;
}
else {
var randomNum = Math.floor(Math.random() * 7 + 15);
randomAnimalContainer[i] = notes[randomNum];
var prevNote = randomAnimalContainer[i];
}
}
playPos = 0;
randomAnimalPlay(playPos, randomAnimalContainer.length);
bugMeNot = 3;
animalMigrate();
bugMeNot = 0;
}
}
function randomAnimalPlay(pos, length) {
var randomFactor = Math.floor(Math.random() * 100 + 1);
if (typeof(window.blinkTime) == 'undefined') blinkTime = 0;
if(blinkTime < 2) {
document.getElementById("lefteye").style.width = eyePos[0] + 2 + "px";
document.getElementById("righteye").style.width = eyePos[0] + 2 + "px";
document.getElementById("lefteye").style.height = eyePos[1] - 2 + "px";
document.getElementById("righteye").style.height = eyePos[1] - 2 + "px";
document.getElementById("leftpupil").style.bottom = pupilPos[2] - 2 + "px";
document.getElementById("rightpupil").style.bottom = pupilPos[2] - 2 + "px";
document.getElementById("leftpupil").style.height = pupilPos[1] - 0.25 + "px";
document.getElementById("rightpupil").style.height = pupilPos[1] - 0.25 + "px";
document.getElementById("leftpupil").style.width = pupilPos[0] + 0.25 + "px";
document.getElementById("rightpupil").style.width = pupilPos[0] + 0.25 + "px";
pupilPos[0] += 0.25;
pupilPos[1] -= 0.25;
pupilPos[2] -= 2;
eyePos[0] += 2;
eyePos[1] -= 2;
blinkTime++;
}
else {
document.getElementById("lefteye").style.width = eyePos[0] - 2 + "px";
document.getElementById("righteye").style.width = eyePos[0] - 2 + "px";
document.getElementById("lefteye").style.height = eyePos[1] + 2 + "px";
document.getElementById("righteye").style.height = eyePos[1] + 2 + "px";
document.getElementById("leftpupil").style.bottom = pupilPos[2] + 2 + "px";
document.getElementById("rightpupil").style.bottom = pupilPos[2] + 2 + "px";
document.getElementById("leftpupil").style.height = pupilPos[1] + 0.25 + "px";
document.getElementById("rightpupil").style.height = pupilPos[1] + 0.25 + "px";
document.getElementById("leftpupil").style.width = pupilPos[0] - 0.25 + "px";
document.getElementById("rightpupil").style.width = pupilPos[0] - 0.25 + "px";
pupilPos[0] -= 0.25;
pupilPos[1] += 0.25;
pupilPos[2] += 2;
eyePos[0] -= 2;
eyePos[1] += 2;
blinkTime++;
if(blinkTime == 4) {
blinkTime = 0;
}
}
setTimeout(function () {
if(randomFactor >= 5) {
try {
soundContainer[notes.indexOf(randomAnimalContainer[playPos])].play();
if(randomFactor >= 30 && length - playPos > 0) {
soundContainer[notes.indexOf(randomAnimalContainer[++playPos])].play();
if(randomFactor >= 55 && length - playPos > 1) {
soundContainer[notes.indexOf(randomAnimalContainer[++playPos])].play();
if(randomFactor >= 75 && length - playPos > 2) {
soundContainer[notes.indexOf(randomAnimalContainer[++playPos])].play();
}
}
}
}
catch(e) {
//doNothing();
}
finally {
playPos++;
}
}
if(playPos < length) {
randomAnimalPlay(playPos, length);
}
}, Math.floor(Math.random() * 500 + 250));
}
function randomMozart() {
if(mozartBusy != 0) {
return;
}
mozartBusy = 1;
var minuetTable = [ //[x][y]; x (2-12) is random number, y (1-16) is sequence
[96,22,141,41,105,122,11,30,70,121,26,9,112,49,109,14],
[32,6,128,63,146,46,134,81,117,39,126,56,174,18,116,83],
[69,95,158,13,153,55,110,24,66,139,15,132,73,58,145,79],
[40,17,113,85,161,2,159,100,90,176,7,34,67,160,52,170],
[148,74,163,45,80,97,36,107,25,143,64,125,76,136,1,93],
[104,157,27,167,154,68,118,91,138,71,150,29,101,162,23,151],
[152,60,171,53,99,133,21,127,16,155,57,175,43,168,89,172],
[119,84,114,50,140,86,169,94,120,88,48,166,51,115,72,111],
[98,142,42,156,75,129,62,123,65,77,19,82,137,38,149,8],
[3,87,165,61,135,47,147,33,102,4,31,164,144,59,173,78],
[54,130,10,103,28,37,106,5,35,20,108,92,12,124,44,131]
];
var trioTable = [ //[x][y]; x (1-6) is random number, y (1-16) is sequence
[72,6,59,25,81,41,89,13,36,5,46,79,30,95,19,66],
[56,82,42,74,14,7,26,71,76,20,64,84,8,35,47,88],
[75,39,54,1,65,43,15,80,9,34,93,48,69,58,90,21],
[40,73,16,68,29,55,2,61,22,67,49,77,57,87,33,10],
[83,3,28,53,37,17,44,70,63,85,32,96,12,23,50,91],
[18,45,62,38,4,27,52,94,11,92,24,86,51,60,78,31]
];
var mozartMinuet = new Array();
var mozartTrio = new Array();
var mozartMinuetInstance = new Array();
var mozartTrioInstance = new Array();
for(var i = 1; i < 17; i++) { //i refers to y above
var minuetDiceTrow = Math.floor(Math.random() * 11); //claws you for 0-10 damage
var trioDiceTrow = Math.floor(Math.random() * 6); //You continue to bleed for 0-5 damage
mozartMinuet[i] = minuetTable[minuetDiceTrow][i-1];
mozartTrio[i] = trioTable[trioDiceTrow][i-1];
} //todo: figure out a less silly way to do this
mozartMinuetInstance[1] = soundManager.createSound({
id:'MozartMinuet1',
url:('mozart/M' + mozartMinuet[1] + '.mp3'),
onfinish:function() {
this.destruct();
},
onbeforefinish:function() {
soundManager.play('MozartMinuet2');
},
onbeforefinishtime:250
});
mozartTrioInstance[1] = soundManager.createSound({
id:('MozartTrio1'),
url:('mozart/T' + mozartTrio[1] + '.mp3'),
onfinish:function() {
this.destruct();
},
onbeforefinish:function() {
soundManager.play('MozartTrio2');
},
onbeforefinishtime:250
});
mozartMinuetInstance[2] = soundManager.createSound({
id:'MozartMinuet2',
url:('mozart/M' + mozartMinuet[2] + '.mp3'),
onfinish:function() {
this.destruct();
},
onbeforefinish:function() {
soundManager.play('MozartMinuet3');
},
onbeforefinishtime:250
});
mozartTrioInstance[2] = soundManager.createSound({
id:('MozartTrio2'),
url:('mozart/T' + mozartTrio[2] + '.mp3'),
onfinish:function() {
this.destruct();
},
onbeforefinish:function() {
soundManager.play('MozartTrio3');
},
onbeforefinishtime:250
});
mozartMinuetInstance[3] = soundManager.createSound({
id:'MozartMinuet3',
url:('mozart/M' + mozartMinuet[3] + '.mp3'),
onfinish:function() {
this.destruct();
},
onbeforefinish:function() {
soundManager.play('MozartMinuet4');
},
onbeforefinishtime:250
});
mozartTrioInstance[3] = soundManager.createSound({
id:('MozartTrio3'),
url:('mozart/T' + mozartTrio[3] + '.mp3'),
onfinish:function() {
this.destruct();
},
onbeforefinish:function() {
soundManager.play('MozartTrio4');
},
onbeforefinishtime:250
});
mozartMinuetInstance[4] = soundManager.createSound({
id:'MozartMinuet4',
url:('mozart/M' + mozartMinuet[4] + '.mp3'),
onfinish:function() {
this.destruct();
},
onbeforefinish:function() {
soundManager.play('MozartMinuet5');
},
onbeforefinishtime:250
});
mozartTrioInstance[4] = soundManager.createSound({
id:('MozartTrio4'),
url:('mozart/T' + mozartTrio[4] + '.mp3'),
onfinish:function() {
this.destruct();
},
onbeforefinish:function() {
soundManager.play('MozartTrio5');
},
onbeforefinishtime:250
});
mozartMinuetInstance[5] = soundManager.createSound({
id:'MozartMinuet5',
url:('mozart/M' + mozartMinuet[5] + '.mp3'),
onfinish:function() {
this.destruct();
},
onbeforefinish:function() {
soundManager.play('MozartMinuet6');
},
onbeforefinishtime:250
});
mozartTrioInstance[5] = soundManager.createSound({
id:('MozartTrio5'),
url:('mozart/T' + mozartTrio[5] + '.mp3'),
onfinish:function() {
this.destruct();
},
onbeforefinish:function() {
soundManager.play('MozartTrio6');
},
onbeforefinishtime:250
});
mozartMinuetInstance[6] = soundManager.createSound({
id:'MozartMinuet6',
url:('mozart/M' + mozartMinuet[6] + '.mp3'),
onfinish:function() {
this.destruct();
},
onbeforefinish:function() {
soundManager.play('MozartMinuet7');
},
onbeforefinishtime:250
});
mozartTrioInstance[6] = soundManager.createSound({
id:('MozartTrio6'),
url:('mozart/T' + mozartTrio[6] + '.mp3'),
onfinish:function() {
this.destruct();
},
onbeforefinish:function() {
soundManager.play('MozartTrio7');
},
onbeforefinishtime:250
});
mozartMinuetInstance[7] = soundManager.createSound({
id:'MozartMinuet7',
url:('mozart/M' + mozartMinuet[7] + '.mp3'),
onfinish:function() {
this.destruct();
},
onbeforefinish:function() {
soundManager.play('MozartMinuet8');
},
onbeforefinishtime:250
});
mozartTrioInstance[7] = soundManager.createSound({
id:('MozartTrio7'),
url:('mozart/T' + mozartTrio[7] + '.mp3'),
onfinish:function() {
this.destruct();
},
onbeforefinish:function() {
soundManager.play('MozartTrio8');
},
onbeforefinishtime:250
});
mozartMinuetInstance[8] = soundManager.createSound({
id:'MozartMinuet8',
url:('mozart/M' + mozartMinuet[8] + '.mp3'),
onfinish:function() {
this.destruct();
},
onbeforefinish:function() {
soundManager.play('MozartMinuet9');
},
onbeforefinishtime:250
});
mozartTrioInstance[8] = soundManager.createSound({
id:('MozartTrio8'),
url:('mozart/T' + mozartTrio[8] + '.mp3'),
onfinish:function() {
this.destruct();
},
onbeforefinish:function() {
soundManager.play('MozartTrio9');
},
onbeforefinishtime:250
});
mozartMinuetInstance[9] = soundManager.createSound({
id:'MozartMinuet9',
url:('mozart/M' + mozartMinuet[9] + '.mp3'),
onfinish:function() {
this.destruct();
},
onbeforefinish:function() {
soundManager.play('MozartMinuet10');
},
onbeforefinishtime:250
});
mozartTrioInstance[9] = soundManager.createSound({
id:('MozartTrio9'),
url:('mozart/T' + mozartTrio[9] + '.mp3'),
onfinish:function() {
this.destruct();
},
onbeforefinish:function() {
soundManager.play('MozartTrio10');
},
onbeforefinishtime:250
});
mozartMinuetInstance[10] = soundManager.createSound({
id:'MozartMinuet10',
url:('mozart/M' + mozartMinuet[10] + '.mp3'),
onfinish:function() {
this.destruct();
},
onbeforefinish:function() {
soundManager.play('MozartMinuet11');
},
onbeforefinishtime:250
});
mozartTrioInstance[10] = soundManager.createSound({
id:('MozartTrio10'),
url:('mozart/T' + mozartTrio[10] + '.mp3'),
onfinish:function() {
this.destruct();
},
onbeforefinish:function() {
soundManager.play('MozartTrio11');
},
onbeforefinishtime:250
});
mozartMinuetInstance[11] = soundManager.createSound({
id:'MozartMinuet11',
url:('mozart/M' + mozartMinuet[11] + '.mp3'),
onfinish:function() {
this.destruct();
},
onbeforefinish:function() {
soundManager.play('MozartMinuet12');
},
onbeforefinishtime:250
});
mozartTrioInstance[11] = soundManager.createSound({
id:('MozartTrio11'),
url:('mozart/T' + mozartTrio[11] + '.mp3'),
onfinish:function() {
this.destruct();
},
onbeforefinish:function() {
soundManager.play('MozartTrio12');
},
onbeforefinishtime:250
});
mozartMinuetInstance[12] = soundManager.createSound({
id:'MozartMinuet12',
url:('mozart/M' + mozartMinuet[12] + '.mp3'),
onfinish:function() {
this.destruct();
},
onbeforefinish:function() {
soundManager.play('MozartMinuet13');
},
onbeforefinishtime:250
});
mozartTrioInstance[12] = soundManager.createSound({
id:('MozartTrio12'),
url:('mozart/T' + mozartTrio[12] + '.mp3'),
onfinish:function() {
this.destruct();
},
onbeforefinish:function() {
soundManager.play('MozartTrio13');
},
onbeforefinishtime:250
});
mozartMinuetInstance[13] = soundManager.createSound({
id:'MozartMinuet13',
url:('mozart/M' + mozartMinuet[13] + '.mp3'),
onfinish:function() {
this.destruct();
},
onbeforefinish:function() {
soundManager.play('MozartMinuet14');
},
onbeforefinishtime:250
});
mozartTrioInstance[13] = soundManager.createSound({
id:('MozartTrio13'),
url:('mozart/T' + mozartTrio[13] + '.mp3'),
onfinish:function() {
this.destruct();
},
onbeforefinish:function() {
soundManager.play('MozartTrio14');
},
onbeforefinishtime:250
});
mozartMinuetInstance[14] = soundManager.createSound({
id:'MozartMinuet14',
url:('mozart/M' + mozartMinuet[14] + '.mp3'),
onfinish:function() {
this.destruct();
},
onbeforefinish:function() {
soundManager.play('MozartMinuet15');
},
onbeforefinishtime:250
});
mozartTrioInstance[14] = soundManager.createSound({
id:('MozartTrio14'),
url:('mozart/T' + mozartTrio[14] + '.mp3'),
onfinish:function() {
this.destruct();
},
onbeforefinish:function() {
soundManager.play('MozartTrio15');
},
onbeforefinishtime:250
});
mozartMinuetInstance[15] = soundManager.createSound({
id:'MozartMinuet15',
url:('mozart/M' + mozartMinuet[15] + '.mp3'),
onfinish:function() {
this.destruct();
},
onbeforefinish:function() {
soundManager.play('MozartMinuet16');
},
onbeforefinishtime:250
});
mozartTrioInstance[15] = soundManager.createSound({
id:('MozartTrio15'),
url:('mozart/T' + mozartTrio[15] + '.mp3'),
onfinish:function() {
this.destruct();
},
onbeforefinish:function() {
soundManager.play('MozartTrio16');
},
onbeforefinishtime:250
});
mozartMinuetInstance[16] = soundManager.createSound({
id:'MozartMinuet16',
url:('mozart/M' + mozartMinuet[16] + '.mp3'),
onfinish:function() {
this.destruct();
}
});
mozartTrioInstance[16] = soundManager.createSound({
id:('MozartTrio16'),
url:('mozart/T' + mozartTrio[16] + '.mp3'),
onfinish:function() {
this.destruct();
}
});
//todo: figure out a better way to do the above
setTimeout(function() {
mozartMinuetInstance[1].play();
mozartTrioInstance[1].play();
},1000);
mozartBusy = 0;
}
function playSound(event) { //event handler for mousedown
evt = event.target || event.srcElement; //cleanup later
parent = evt.parentNode;
//if(parent.id != "keyboard" && parent.id != "keyboard2" && parent.id != "keyboard3") {
// return;
//}
if(evt.className == "animal") {
//randomAnimal();
randomMozart();
return;
}
if(!evt.id.match(/(key[a-g]$)|(key[a-g]sharp$)/)) { //regex filtering
return;
}
//if(evt.id.match(/key[a-g]$/)) {
// evt.style.boxShadow = "0px 0px #FFFFFF";
// evt.style.mozBoxShadow = "0px 0px #FFFFFF";
// evt.style.webkitBoxShadow = "0px 0px #FFFFFF";
// evt.style.background = "#D8D8D8";
//}
//if(evt.id.match(/key[a-g]sharp$/)) {
// evt.style.boxShadow = "0px 0px #FFFFFF";
// evt.style.mozBoxShadow = "0px 0px #FFFFFF";
// evt.style.webkitBoxShadow = "0px 0px #FFFFFF";
//}
if(evt.id == "keyc") { //TERRIBLE UGLY CODE FOLLOWS
if(parent.id == "keyboard") { //UGLY DETECTOR WAILING
effectSequence.push(keyboard1.children.keyc);
thingEffect();
soundContainer[0].play();
restoreSequence.push(keyboard1.children.keyc); //pushes key to tracker array
setTimeout(function() {thingRestore()}, 500);
return;
}
else if(parent.id == "keyboard2") {
effectSequence.push(keyboard2.children.keyc);
thingEffect();
soundContainer[12].play();
restoreSequence.push(keyboard2.children.keyc);
setTimeout(function() {thingRestore()}, 500);
return;
}
soundContainer[24].play();
effectSequence.push(keyboard3.children.keyc);
thingEffect();
restoreSequence.push(keyboard3.children.keyc);
setTimeout(function() {thingRestore()}, 500);
return;
}
if(evt.id == "keycsharp") {
if(parent.id == "keyboard") {
effectSequence.push(keyboard1.children.keycsharp);
thingEffect();
soundContainer[1].play();
restoreSequence.push(keyboard1.children.keycsharp);
setTimeout(function() {thingRestore()}, 500);
return;
}
else if(parent.id == "keyboard2") {
effectSequence.push(keyboard2.children.keycsharp);
thingEffect();
soundContainer[13].play();
restoreSequence.push(keyboard2.children.keycsharp);
setTimeout(function() {thingRestore()}, 500);
return;
}
effectSequence.push(keyboard3.children.keycsharp);
thingEffect();
soundContainer[25].play();
restoreSequence.push(keyboard3.children.keycsharp);
setTimeout(function() {thingRestore()}, 500);
return;
}
if(evt.id == "keyd") {
if(parent.id == "keyboard") {
effectSequence.push(keyboard1.children.keyd);
thingEffect();
soundContainer[2].play();
restoreSequence.push(keyboard1.children.keyd);
setTimeout(function() {thingRestore()}, 500);
return;
}
else if(parent.id == "keyboard2") {
effectSequence.push(keyboard2.children.keyd);
thingEffect();
soundContainer[14].play();
restoreSequence.push(keyboard2.children.keyd);
setTimeout(function() {thingRestore()}, 500);
return;
}
effectSequence.push(keyboard3.children.keyd);
thingEffect();
soundContainer[26].play();
restoreSequence.push(keyboard3.children.keyd);
setTimeout(function() {thingRestore()}, 500);
return;
}
if(evt.id == "keydsharp") {
if(parent.id == "keyboard") {
effectSequence.push(keyboard1.children.keydsharp);
thingEffect();
soundContainer[3].play();
restoreSequence.push(keyboard1.children.keydsharp);
setTimeout(function() {thingRestore()}, 500);
return;
}
else if(parent.id == "keyboard2") {
effectSequence.push(keyboard2.children.keydsharp);
thingEffect();
soundContainer[15].play();
restoreSequence.push(keyboard2.children.keydsharp);
setTimeout(function() {thingRestore()}, 500);
return;
}
effectSequence.push(keyboard3.children.keydsharp);
thingEffect();
soundContainer[27].play();
restoreSequence.push(keyboard3.children.keydsharp);
setTimeout(function() {thingRestore()}, 500);
return;
}
if(evt.id == "keye") {
if(parent.id == "keyboard") {
effectSequence.push(keyboard1.children.keye);
thingEffect();
soundContainer[4].play();
restoreSequence.push(keyboard1.children.keye);
setTimeout(function() {thingRestore()}, 500);
return;
}
else if(parent.id == "keyboard2") {
effectSequence.push(keyboard2.children.keye);
thingEffect();
soundContainer[16].play();
restoreSequence.push(keyboard2.children.keye);
setTimeout(function() {thingRestore()}, 500);
return;
}
effectSequence.push(keyboard3.children.keye);
thingEffect();
soundContainer[28].play();
restoreSequence.push(keyboard3.children.keye);
setTimeout(function() {thingRestore()}, 500);
return;
}
if(evt.id == "keyf") {
if(parent.id == "keyboard") {
effectSequence.push(keyboard1.children.keyf);
thingEffect();
soundContainer[5].play();
restoreSequence.push(keyboard1.children.keyf);
setTimeout(function() {thingRestore()}, 500);
return;
}
else if(parent.id == "keyboard2") {
effectSequence.push(keyboard2.children.keyf);
thingEffect();
soundContainer[17].play();
restoreSequence.push(keyboard2.children.keyf);
setTimeout(function() {thingRestore()}, 500);
return;
}
effectSequence.push(keyboard3.children.keyf);
thingEffect();
soundContainer[29].play();
restoreSequence.push(keyboard3.children.keyf);
setTimeout(function() {thingRestore()}, 500);
return;
}
if(evt.id == "keyfsharp") {
if(parent.id == "keyboard") {
effectSequence.push(keyboard1.children.keyfsharp);
thingEffect();
soundContainer[6].play();
restoreSequence.push(keyboard1.children.keyfsharp);
setTimeout(function() {thingRestore()}, 500);
return;
}
else if(parent.id == "keyboard2") {
effectSequence.push(keyboard2.children.keyfsharp);
thingEffect();
soundContainer[18].play();
restoreSequence.push(keyboard2.children.keyfsharp);
setTimeout(function() {thingRestore()}, 500);
return;
}
effectSequence.push(keyboard3.children.keyfsharp);
thingEffect();
soundContainer[30].play();
restoreSequence.push(keyboard3.children.keyfsharp);
setTimeout(function() {thingRestore()}, 500);
return;
}
if(evt.id == "keyg") {
if(parent.id == "keyboard") {
effectSequence.push(keyboard1.children.keyg);
thingEffect();
soundContainer[7].play();
restoreSequence.push(keyboard1.children.keyg);
setTimeout(function() {thingRestore()}, 500);
return;
}
else if(parent.id == "keyboard2") {
effectSequence.push(keyboard2.children.keyg);
thingEffect();
soundContainer[19].play();
restoreSequence.push(keyboard2.children.keyg);
setTimeout(function() {thingRestore()}, 500);
return;
}
effectSequence.push(keyboard3.children.keyg);
thingEffect();
soundContainer[31].play();
restoreSequence.push(keyboard3.children.keyg);
setTimeout(function() {thingRestore()}, 500);
return;
}
if(evt.id == "keygsharp") {
if(parent.id == "keyboard") {
effectSequence.push(keyboard1.children.keygsharp);
thingEffect();
soundContainer[8].play();
restoreSequence.push(keyboard1.children.keygsharp);
setTimeout(function() {thingRestore()}, 500);
return;
}
else if(parent.id == "keyboard2") {
effectSequence.push(keyboard2.children.keygsharp);
thingEffect();
soundContainer[20].play();
restoreSequence.push(keyboard2.children.keygsharp);
setTimeout(function() {thingRestore()}, 500);
return;
}
effectSequence.push(keyboard3.children.keygsharp);
thingEffect();
soundContainer[32].play();
restoreSequence.push(keyboard3.children.keygsharp);
setTimeout(function() {thingRestore()}, 500);
return;
}
if(evt.id == "keya") {
if(parent.id == "keyboard") {
effectSequence.push(keyboard1.children.keya);
thingEffect();
soundContainer[9].play();
restoreSequence.push(keyboard1.children.keya);
setTimeout(function() {thingRestore()}, 500);
return;
}
else if(parent.id == "keyboard2") {
effectSequence.push(keyboard2.children.keya);
thingEffect();
soundContainer[21].play();
restoreSequence.push(keyboard2.children.keya);
setTimeout(function() {thingRestore()}, 500);
return;
}
effectSequence.push(keyboard3.children.keya);
thingEffect();
soundContainer[33].play();
restoreSequence.push(keyboard3.children.keya);
setTimeout(function() {thingRestore()}, 500);
return;
}
if(evt.id == "keyasharp") {
if(parent.id == "keyboard") {
effectSequence.push(keyboard1.children.keyasharp);
thingEffect();
soundContainer[10].play();
restoreSequence.push(keyboard1.children.keyasharp);
setTimeout(function() {thingRestore()}, 500);
return;
}
else if(parent.id == "keyboard2") {
effectSequence.push(keyboard2.children.keyasharp);
thingEffect();
soundContainer[22].play();
restoreSequence.push(keyboard2.children.keyasharp);
setTimeout(function() {thingRestore()}, 500);
return;
}
effectSequence.push(keyboard3.children.keyasharp);
thingEffect();
soundContainer[34].play();
restoreSequence.push(keyboard3.children.keyasharp);
setTimeout(function() {thingRestore()}, 500);
return;
}
if(evt.id == "keyb") {
if(parent.id == "keyboard") {
effectSequence.push(keyboard1.children.keyb);
thingEffect();
soundContainer[11].play();
restoreSequence.push(keyboard1.children.keyb);
setTimeout(function() {thingRestore()}, 500);
return;
}
else if(parent.id == "keyboard2") {
effectSequence.push(keyboard2.children.keyb);
thingEffect();
soundContainer[23].play();
restoreSequence.push(keyboard2.children.keyb);
setTimeout(function() {thingRestore()}, 500);
return;
}
effectSequence.push(keyboard3.children.keyb);
thingEffect();
soundContainer[35].play();
restoreSequence.push(keyboard3.children.keyb);
setTimeout(function() {thingRestore()}, 500);
return;
}
}
function mouseUp(event) { //event handler for mouseup
evt = event.target || event.srcElement;
parent = evt.parentNode;
if(!evt.id.match(/(key[a-g]$)|(key[a-g]sharp$)/)) { //regex filtering
return;
}
if(evt.id == "keyc") { //todo: figure out a smarter way to do this
if(parent.id == "keyboard") {
soundContainer[0].stop();
restoreSequence.push(keyboard1.children.keyc); //pushes key to tracker array
thingRestore();
return;
}
else if(parent.id == "keyboard2") {
soundContainer[12].stop();
restoreSequence.push(keyboard2.children.keyc);
thingRestore();
return;
}
soundContainer[24].stop();
restoreSequence.push(keyboard3.children.keyc);
thingRestore();
return;
}
if(evt.id == "keycsharp") {
if(parent.id == "keyboard") {
soundContainer[1].stop();
restoreSequence.push(keyboard1.children.keycsharp);
thingRestore();
return;
}
else if(parent.id == "keyboard2") {
soundContainer[13].stop();
restoreSequence.push(keyboard2.children.keycsharp);
thingRestore();
return;
}
soundContainer[25].stop();
restoreSequence.push(keyboard3.children.keycsharp);
thingRestore();
return;
}
if(evt.id == "keyd") {
if(parent.id == "keyboard") {
soundContainer[2].stop();
restoreSequence.push(keyboard1.children.keyd);
thingRestore();
return;
}
else if(parent.id == "keyboard2") {
soundContainer[14].stop();
restoreSequence.push(keyboard2.children.keyd);
thingRestore();
return;
}
soundContainer[26].stop();
restoreSequence.push(keyboard3.children.keyd);
thingRestore();
return;
}
if(evt.id == "keydsharp") {
if(parent.id == "keyboard") {
soundContainer[3].stop();
restoreSequence.push(keyboard1.children.keydsharp);
thingRestore();
return;
}
else if(parent.id == "keyboard2") {
soundContainer[15].stop();
restoreSequence.push(keyboard2.children.keydsharp);
thingRestore();
return;
}
soundContainer[27].stop();
restoreSequence.push(keyboard3.children.keydsharp);
thingRestore();
return;
}
if(evt.id == "keye") {
if(parent.id == "keyboard") {
soundContainer[4].stop();
restoreSequence.push(keyboard1.children.keye);
thingRestore();
return;
}
else if(parent.id == "keyboard2") {
soundContainer[16].stop();
restoreSequence.push(keyboard2.children.keye);
thingRestore();
return;
}
soundContainer[28].stop();
restoreSequence.push(keyboard3.children.keye);
thingRestore();
return;
}
if(evt.id == "keyf") {
if(parent.id == "keyboard") {
soundContainer[5].stop();
restoreSequence.push(keyboard1.children.keyf);
thingRestore();
return;
}
else if(parent.id == "keyboard2") {
soundContainer[17].stop();
restoreSequence.push(keyboard2.children.keyf);
thingRestore();
return;
}
soundContainer[29].stop();
restoreSequence.push(keyboard3.children.keyf);
thingRestore();
return;
}
if(evt.id == "keyfsharp") {
if(parent.id == "keyboard") {
soundContainer[6].stop();
restoreSequence.push(keyboard1.children.keyfsharp);
thingRestore();
return;
}
else if(parent.id == "keyboard2") {
soundContainer[18].stop();
restoreSequence.push(keyboard2.children.keyfsharp);
thingRestore();
return;
}
soundContainer[30].stop();
restoreSequence.push(keyboard3.children.keyfsharp);
thingRestore();
return;
}
if(evt.id == "keyg") {
if(parent.id == "keyboard") {
soundContainer[7].stop();
restoreSequence.push(keyboard1.children.keyg);
thingRestore();
return;
}
else if(parent.id == "keyboard2") {
soundContainer[19].stop();
restoreSequence.push(keyboard2.children.keyg);
thingRestore();
return;
}
soundContainer[31].stop();
restoreSequence.push(keyboard3.children.keyg);
thingRestore();
return;
}
if(evt.id == "keygsharp") {
if(parent.id == "keyboard") {
soundContainer[8].stop();
restoreSequence.push(keyboard1.children.keygsharp);
thingRestore();
return;
}
else if(parent.id == "keyboard2") {
soundContainer[20].stop();
restoreSequence.push(keyboard2.children.keygsharp);
thingRestore();
return;
}
soundContainer[32].stop();
restoreSequence.push(keyboard3.children.keygsharp);
thingRestore();
return;
}
if(evt.id == "keya") {
if(parent.id == "keyboard") {
soundContainer[9].stop();
restoreSequence.push(keyboard1.children.keya);
thingRestore();
return;
}
else if(parent.id == "keyboard2") {
soundContainer[21].stop();
restoreSequence.push(keyboard2.children.keya);
thingRestore();
return;
}
soundContainer[33].stop();
restoreSequence.push(keyboard3.children.keya);
thingRestore();
return;
}
if(evt.id == "keyasharp") {
if(parent.id == "keyboard") {
soundContainer[10].stop();
restoreSequence.push(keyboard1.children.keyasharp);
thingRestore();
return;
}
else if(parent.id == "keyboard2") {
soundContainer[22].stop();
restoreSequence.push(keyboard2.children.keyasharp);
thingRestore();
return;
}
soundContainer[34].stop();
restoreSequence.push(keyboard3.children.keyasharp);
thingRestore();
return;
}
if(evt.id == "keyb") {
if(parent.id == "keyboard") {
soundContainer[11].stop();
restoreSequence.push(keyboard1.children.keyb);
thingRestore();
return;
}
else if(parent.id == "keyboard2") {
soundContainer[23].stop();
restoreSequence.push(keyboard2.children.keyb);
thingRestore();
return;
}
soundContainer[35].stop();
restoreSequence.push(keyboard3.children.keyb);
thingRestore();
return;
}
}
function keyDown(event) { //event handler for keypress
key = event.which || event.srcElement; //todo: customizable keys
keyChar = String.fromCharCode(key);
if(key == 16) {
shifted = 1;
return;
}
if(keyChar == '1') { //sorry
if(shifted == 1) {
effectSequence.push(keyboard1.children.keycsharp);
thingEffect();
soundContainer[1].play();
//restoreSequence.push(keyboard1.children.keycsharp);
//setTimeout(function() {thingRestore()}, 500);
return;
}
effectSequence.push(keyboard1.children.keyc);
thingEffect();
soundContainer[0].play();
//restoreSequence.push(keyboard1.children.keyc);
//setTimeout(function() {thingRestore()}, 500);
return;
}
if(keyChar == '2') {
if(shifted == 1) {
effectSequence.push(keyboard1.children.keydsharp);
thingEffect();
soundContainer[3].play();
//restoreSequence.push(keyboard1.children.keydsharp);
//setTimeout(function() {thingRestore()}, 500);
return;
}
effectSequence.push(keyboard1.children.keyd);
thingEffect();
soundContainer[2].play();
//restoreSequence.push(keyboard1.children.keyd);
//setTimeout(function() {thingRestore()}, 500);
return;
}
if(keyChar == '3') {
effectSequence.push(keyboard1.children.keye);
thingEffect();
soundContainer[4].play();
//restoreSequence.push(keyboard1.children.keye);
//setTimeout(function() {thingRestore()}, 500);
return;
}
if(keyChar == '4') {
if(shifted == 1) {
effectSequence.push(keyboard1.children.keyfsharp);
thingEffect();
soundContainer[6].play();
//restoreSequence.push(keyboard1.children.keyfsharp);
//setTimeout(function() {thingRestore()}, 500);
return;
}
effectSequence.push(keyboard1.children.keyf);
thingEffect();
soundContainer[5].play();
//restoreSequence.push(keyboard1.children.keyf);
//setTimeout(function() {thingRestore()}, 500);
return;
}
if(keyChar == '5') {
if(shifted == 1) {
effectSequence.push(keyboard1.children.keygsharp);
thingEffect();
soundContainer[8].play();
//restoreSequence.push(keyboard1.children.keygsharp);
//setTimeout(function() {thingRestore()}, 500);
return;
}
effectSequence.push(keyboard1.children.keyg);
thingEffect();
soundContainer[7].play();
//restoreSequence.push(keyboard1.children.keyg);
//setTimeout(function() {thingRestore()}, 500);
return;
}
if(keyChar == '6') {
if(shifted == 1) {
effectSequence.push(keyboard1.children.keyasharp);
thingEffect();
soundContainer[10].play();
//restoreSequence.push(keyboard1.children.keyasharp);
//setTimeout(function() {thingRestore()}, 500);
return;
}
effectSequence.push(keyboard1.children.keya);
thingEffect();
soundContainer[9].play();
//restoreSequence.push(keyboard1.children.keya);
//setTimeout(function() {thingRestore()}, 500);
return;
}
if(keyChar == '7') {
effectSequence.push(keyboard1.children.keyb);
thingEffect();
soundContainer[11].play();
//restoreSequence.push(keyboard1.children.keyb);
//setTimeout(function() {thingRestore()}, 500);
return;
}
if(keyChar == 'Q') {
if(shifted == 1) {
effectSequence.push(keyboard2.children.keycsharp);
thingEffect();
soundContainer[13].play();
//restoreSequence.push(keyboard2.children.keycsharp);
//setTimeout(function() {thingRestore()}, 500);
return;
}
effectSequence.push(keyboard2.children.keyc);
thingEffect();
soundContainer[12].play();
//restoreSequence.push(keyboard2.children.keyc);
//setTimeout(function() {thingRestore()}, 500);
return;
}
if(keyChar == 'W') {
if(shifted == 1) {
effectSequence.push(keyboard2.children.keydsharp);
thingEffect();
soundContainer[15].play();
//restoreSequence.push(keyboard2.children.keydsharp);
//setTimeout(function() {thingRestore()}, 500);
return;
}
effectSequence.push(keyboard2.children.keyd);
thingEffect();
soundContainer[14].play();
//restoreSequence.push(keyboard2.children.keyd);
//setTimeout(function() {thingRestore()}, 500);
return;
}
if(keyChar == 'E') {
effectSequence.push(keyboard2.children.keye);
thingEffect();
soundContainer[16].play();
//restoreSequence.push(keyboard2.children.keye);
//setTimeout(function() {thingRestore()}, 500);
return;
}
if(keyChar == 'R') {
if(shifted == 1) {
effectSequence.push(keyboard2.children.keyfsharp);
thingEffect();
soundContainer[18].play();
//restoreSequence.push(keyboard2.children.keyfsharp);
//setTimeout(function() {thingRestore()}, 500);
return;
}
effectSequence.push(keyboard2.children.keyf);
thingEffect();
soundContainer[17].play();
//restoreSequence.push(keyboard2.children.keyf);
//setTimeout(function() {thingRestore()}, 500);
return;
}
if(keyChar == 'T') {
if(shifted == 1) {
effectSequence.push(keyboard2.children.keygsharp);
thingEffect();
soundContainer[20].play();
//restoreSequence.push(keyboard2.children.keygsharp);
//setTimeout(function() {thingRestore()}, 500);
return;
}
effectSequence.push(keyboard2.children.keyg);
thingEffect();
soundContainer[19].play();
//restoreSequence.push(keyboard2.children.keyg);
//setTimeout(function() {thingRestore()}, 500);
return;
}
if(keyChar == 'Y') {
if(shifted == 1) {
effectSequence.push(keyboard2.children.keyasharp);
thingEffect();
soundContainer[22].play();
//restoreSequence.push(keyboard2.children.keyasharp);
//setTimeout(function() {thingRestore()}, 500);
return;
}
effectSequence.push(keyboard2.children.keya);
thingEffect();
soundContainer[21].play();
//restoreSequence.push(keyboard2.children.keya);
//setTimeout(function() {thingRestore()}, 500);
return;
}
if(keyChar == 'U') {
effectSequence.push(keyboard2.children.keyb);
thingEffect();
soundContainer[23].play();
//restoreSequence.push(keyboard2.children.keyb);
//setTimeout(function() {thingRestore()}, 500);
return;
}
if(keyChar == 'A') {
if(shifted == 1) {
effectSequence.push(keyboard3.children.keycsharp);
thingEffect();
soundContainer[25].play();
//restoreSequence.push(keyboard3.children.keycsharp);
//setTimeout(function() {thingRestore()}, 500);
return;
}
effectSequence.push(keyboard3.children.keyc);
thingEffect();
soundContainer[24].play();
//restoreSequence.push(keyboard3.children.keyc);
//setTimeout(function() {thingRestore()}, 500);
return;
}
if(keyChar == 'S') {
if(shifted == 1) {
effectSequence.push(keyboard3.children.keydsharp);
thingEffect();
soundContainer[27].play();
//restoreSequence.push(keyboard3.children.keydsharp);
//setTimeout(function() {thingRestore()}, 500);
return;
}
effectSequence.push(keyboard3.children.keyd);
thingEffect();
soundContainer[26].play();
//restoreSequence.push(keyboard3.children.keyd);
//setTimeout(function() {thingRestore()}, 500);
return;
}
if(keyChar == 'D') {
effectSequence.push(keyboard3.children.keye);
thingEffect();
soundContainer[28].play();
//restoreSequence.push(keyboard3.children.keye);
//setTimeout(function() {thingRestore()}, 500);
return;
}
if(keyChar == 'F') {
if(shifted == 1) {
effectSequence.push(keyboard3.children.keyfsharp);
thingEffect();
soundContainer[30].play();
//restoreSequence.push(keyboard3.children.keyfsharp);
//setTimeout(function() {thingRestore()}, 500);
return;
}
effectSequence.push(keyboard3.children.keyf);
thingEffect();
soundContainer[29].play();
//restoreSequence.push(keyboard3.children.keyf);
//setTimeout(function() {thingRestore()}, 500);
return;
}
if(keyChar == 'G') {
if(shifted == 1) {
effectSequence.push(keyboard3.children.keygsharp);
thingEffect();
soundContainer[32].play();
//restoreSequence.push(keyboard3.children.keygsharp);
//setTimeout(function() {thingRestore()}, 500);
return;
}
effectSequence.push(keyboard3.children.keyg);
thingEffect();
soundContainer[31].play();
//restoreSequence.push(keyboard3.children.keyg);
//setTimeout(function() {thingRestore()}, 500);
return;
}
if(keyChar == 'H') {
if(shifted == 1) {
effectSequence.push(keyboard3.children.keyasharp);
thingEffect();
soundContainer[34].play();
//restoreSequence.push(keyboard3.children.keyasharp);
//setTimeout(function() {thingRestore()}, 500);
return;
}
effectSequence.push(keyboard3.children.keya);
thingEffect();
soundContainer[33].play();
//restoreSequence.push(keyboard3.children.keya);
//setTimeout(function() {thingRestore()}, 500);
return;
}
if(keyChar == 'J') {
effectSequence.push(keyboard3.children.keyb);
thingEffect();
soundContainer[35].play();
//restoreSequence.push(keyboard3.children.keyb);
//setTimeout(function() {thingRestore()}, 500);
return;
}
}
function keyUp(event) {
key = event.which;
keyChar = String.fromCharCode(key);
if(key == 16) {
shifted = 0;
}
if(keyChar == '1') { //sorry
if(shifted == 1) {
soundContainer[1].stop();
restoreSequence.push(keyboard1.children.keycsharp);
thingRestore();
return;
}
soundContainer[0].stop();
restoreSequence.push(keyboard1.children.keyc);
thingRestore();
return;
}
if(keyChar == '2') {
if(shifted == 1) {
soundContainer[3].stop();
restoreSequence.push(keyboard1.children.keydsharp);
thingRestore();
return;
}
soundContainer[2].stop();
restoreSequence.push(keyboard1.children.keyd);
thingRestore();
return;
}
if(keyChar == '3') {
soundContainer[4].stop();
restoreSequence.push(keyboard1.children.keye);
thingRestore();
return;
}
if(keyChar == '4') {
if(shifted == 1) {
soundContainer[6].stop();
restoreSequence.push(keyboard1.children.keyfsharp);
thingRestore();
return;
}
soundContainer[5].stop();
restoreSequence.push(keyboard1.children.keyf);
thingRestore();
return;
}
if(keyChar == '5') {
if(shifted == 1) {
soundContainer[8].stop();
restoreSequence.push(keyboard1.children.keygsharp);
thingRestore();
return;
}
soundContainer[7].stop();
restoreSequence.push(keyboard1.children.keyg);
thingRestore();
return;
}
if(keyChar == '6') {
if(shifted == 1) {
soundContainer[10].stop();
restoreSequence.push(keyboard1.children.keyasharp);
thingRestore();
return;
}
soundContainer[9].stop();
restoreSequence.push(keyboard1.children.keya);
thingRestore();
return;
}
if(keyChar == '7') {
soundContainer[11].stop();
restoreSequence.push(keyboard1.children.keyb);
thingRestore();
return;
}
if(keyChar == 'Q') {
if(shifted == 1) {
soundContainer[13].stop();
restoreSequence.push(keyboard2.children.keycsharp);
thingRestore();
return;
}
soundContainer[12].stop();
restoreSequence.push(keyboard2.children.keyc);
thingRestore();
return;
}
if(keyChar == 'W') {
if(shifted == 1) {
soundContainer[15].stop();
restoreSequence.push(keyboard2.children.keydsharp);
thingRestore();
return;
}
soundContainer[14].stop();
restoreSequence.push(keyboard2.children.keyd);
thingRestore();
return;
}
if(keyChar == 'E') {
soundContainer[16].stop();
restoreSequence.push(keyboard2.children.keye);
thingRestore();
return;
}
if(keyChar == 'R') {
if(shifted == 1) {
soundContainer[18].stop();
restoreSequence.push(keyboard2.children.keyfsharp);
thingRestore();
return;
}
soundContainer[17].stop();
restoreSequence.push(keyboard2.children.keyf);
thingRestore();
return;
}
if(keyChar == 'T') {
if(shifted == 1) {
soundContainer[20].stop();
restoreSequence.push(keyboard2.children.keygsharp);
thingRestore();
return;
}
soundContainer[19].stop();
restoreSequence.push(keyboard2.children.keyg);
thingRestore();
return;
}
if(keyChar == 'Y') {
if(shifted == 1) {
soundContainer[22].stop();
restoreSequence.push(keyboard2.children.keyasharp);
thingRestore();
return;
}
soundContainer[21].stop();
restoreSequence.push(keyboard2.children.keya);
thingRestore();
return;
}
if(keyChar == 'U') {
soundContainer[23].stop();
restoreSequence.push(keyboard2.children.keyb);
thingRestore();
return;
}
if(keyChar == 'A') {
if(shifted == 1) {
soundContainer[25].stop();
restoreSequence.push(keyboard3.children.keycsharp);
thingRestore();
return;
}
soundContainer[24].stop();
restoreSequence.push(keyboard3.children.keyc);
thingRestore();
return;
}
if(keyChar == 'S') {
if(shifted == 1) {
soundContainer[27].stop();
restoreSequence.push(keyboard3.children.keydsharp);
thingRestore();
return;
}
soundContainer[26].stop();
restoreSequence.push(keyboard3.children.keyd);
thingRestore();
return;
}
if(keyChar == 'D') {
soundContainer[28].stop();
restoreSequence.push(keyboard3.children.keye);
thingRestore();
return;
}
if(keyChar == 'F') {
if(shifted == 1) {
soundContainer[30].stop();
restoreSequence.push(keyboard3.children.keyfsharp);
thingRestore();
return;
}
soundContainer[29].stop();
restoreSequence.push(keyboard3.children.keyf);
thingRestore();
return;
}
if(keyChar == 'G') {
if(shifted == 1) {
soundContainer[32].stop();
restoreSequence.push(keyboard3.children.keygsharp);
thingRestore();
return;
}
soundContainer[31].stop();
restoreSequence.push(keyboard3.children.keyg);
thingRestore();
return;
}
if(keyChar == 'H') {
if(shifted == 1) {
soundContainer[34].stop();
restoreSequence.push(keyboard3.children.keyasharp);
thingRestore();
return;
}
soundContainer[33].stop();
restoreSequence.push(keyboard3.children.keya);
thingRestore();
return;
}
if(keyChar == 'J') {
soundContainer[35].stop();
restoreSequence.push(keyboard3.children.keyb);
thingRestore();
return;
}
}
window.onload = init(); //initialize page
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment