-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
56 lines (54 loc) · 1.32 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
let beats = {
65: {
beat: new Beat("./assets/Piano Chord 331.mp3"),
button: new Button("#00fffe", 65),
},
83: {
beat: new Beat("./assets/Piano Chord 209.mp3"),
button: new Button("#00fffe", 83),
},
68: {
beat: new Beat("./assets/Piano Chord 208.mp3"),
button: new Button("#00fffe", 68),
},
70: {
beat: new Beat("./assets/Drum Sticks Hit 3.mp3"),
button: new Button("#FF00FF", 70),
},
71: {
beat: new Beat("./assets/Drum Snare Roll.mp3"),
button: new Button("#FF00FF", 71),
},
72: {
beat: new Beat("./assets/PREL Musical 57.mp3"),
button: new Button("#FF00FF", 72),
},
74: {
beat: new Beat("./assets/Cymbal Suspended 2.mp3"),
button: new Button("#FF00FF", 74),
},
75: {
beat: new Beat("./assets/Musical Compos 33.mp3"),
button: new Button("#FFFFFF", 75),
},
76: {
beat: new Beat("./assets/Musical Orches 4.mp3"),
button: new Button("#FFFFFF", 76),
},
};
/**
* Function to play the beat upon a press of key
*/
triggerBeat = (event) => {
const keyCode = event.keyCode;
if (keyCode in beats) {
let keyPress = beats[keyCode];
keyPress.beat.play();
keyPress.button.setButtonColorInHTML();
keyPress.button.select();
}
};
/**
* Keydown listener to fire triggerBeat function
*/
document.addEventListener("keydown", triggerBeat);