Last active
August 29, 2015 14:17
-
-
Save Shinpeim/f213b8b830555e1c9998 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var KeyBoard = function(){ | |
var keys = []; | |
for (var i = 0, l= 64; i < l; i++ ){ | |
keys[i] = false; | |
} | |
this.keys = keys; | |
}; | |
KeyBoard.prototype = { | |
indexOf: function(keyCode, oct){ | |
var base; | |
switch (keyCode) { | |
case 'c': | |
base = 0; | |
break; | |
case 'c#': | |
base = 1; | |
break; | |
case 'd': | |
base = 2; | |
break; | |
case 'd#': | |
base = 3; | |
break; | |
case 'e': | |
base = 4; | |
break; | |
case 'f': | |
base = 5; | |
break; | |
case 'f#': | |
base = 6; | |
break; | |
case 'g': | |
base = 7; | |
break; | |
case 'g#': | |
base = 8; | |
break; | |
case 'a': | |
base = 9; | |
break; | |
case 'a#': | |
base = 10; | |
break; | |
case 'b': | |
base = 11; | |
break; | |
} | |
var index = base + (11 * oct); | |
return index; | |
}, | |
push: function(keyCode, oct){ | |
this.keys[this.indexOf(keyCode, oct)] = true; | |
}, | |
unpush: function(keyCode, oct){ | |
this.keys[this.indexOf(keyCode, oct)] = false; | |
}, | |
asArray: function(){ | |
return this.keys; | |
} | |
}; | |
var keyBoard = new KeyBoard(); | |
keyBoard.push('c', 0); | |
keyBoard.push('e', 0); | |
keyBoard.push('g', 0); | |
console.log(keyBoard.asArray()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment