Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
DevStarks committed Apr 17, 2017
1 parent 148a754 commit ac1707d
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions src/Main/Toolbox/Keyboard/Keys/Key/utils/keybind.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
// the number following the note name corresponds to the relative octave of the key
const KEYMAP = {
'C1': 65,
'C1': 65,
'C#1': 87,
'D1': 83,
'D1': 83,
'D#1': 69,
'E1': 68,
'F1': 70,
'E1': 68,
'F1': 70,
'F#1': 84,
'G1': 71,
'G1': 71,
'G#1': 89,
'A1': 72,
'A1': 72,
'A#1': 85,
'B1': 74,
'C2': 75,
'B1': 74,
'C2': 75,
'C#2': 79,
'D2': 76,
'D2': 76,
'D#2': 80,
'E2': 186,
'F2': 222,
'E2': 186,
'F2': 222,
};

const keys = {};

function keybind(note, trigger, release) {
const code = KEYMAP[note];

document.addEventListener('keydown', onKeyDown.bind(null, code, trigger));
document.addEventListener('keyup', onKeyUp.bind(null, code, release));
document.addEventListener('keydown', () => onKeyDown(code, trigger));
document.addEventListener('keyup', () => onKeyUp(code, release));
}

const keys = {};

function onKeyDown(code, cb, e) {
const keyCode = e.which || e.keyCode;
const notAlreadyPlaying = !keys[keyCode];
Expand Down

0 comments on commit ac1707d

Please sign in to comment.