forked from CleverProgrammers/beatbox-app-live
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
73 lines (70 loc) · 2.24 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* DONE: Create a keydown listener to track what keys are hit
* DONE: Create a Beat class to represent the beat object in utils.js
* DONE: Complete triggerBeat() to play upon the press of a,s,d,f,g,h,j,k,l
* DONE: Button pt1: Initialize color and element values
* DONE: Button pt2: Set button color upon initialization | Initialize button in beats["65"]
* DONE: Button pt3: Complete select function to set the color and shadow of button upon pressing
* DONE: Button pt4: Call the select() function upon key press ;)
* DONE: Button pt5: Add transition for button selection
* DONE: Button pt6: Remove the button style upon transition end | Use deselect function
* TODO: Complete all button instances with the following colors
* TODO: Add background image
* First 3: #00fffe
* 4,5,6,7: #FF00FF
* 8, 9: #FFFFFF
*/
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
* HINT: use the keyCode
*/
triggerBeat = (event) => {
var code = event.keyCode;
if(code in beats){
beats[code].beat.play();
beats[code].button.select();
}
}
/**
* Keydown listener to fire triggerBeat function
* HINT: Log the keyCode of the key
*/
document.addEventListener('keydown', triggerBeat);