-
Notifications
You must be signed in to change notification settings - Fork 0
/
Launchpad.js
54 lines (43 loc) · 1.35 KB
/
Launchpad.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
class Launchpad {
grid;
soundsFolder = 'sounds';
constructor(launchset) {
this.launchset = launchset;
this.createGrid();
this.createButtons();
this.pressButtons();
document.getElementById('launchpad').append(this.grid);
}
createGrid() {
this.grid = document.createElement('div');
this.grid.classList.add('grid');
}
createButtons() {
this.launchset.forEach((set, i) => {
let button = document.createElement('button');
button.innerText = set.key;
this.grid.append(button);
let audio = new Audio(this.soundsFolder + '/' + set.name + '.wav');
button.addEventListener('click', () => {
audio.pause();
audio.currentTime = 0;
audio.play();
button.classList.add('active');
setTimeout(() => {
button.classList.remove('active');
}, 100);
});
this.launchset[i].button = button;
})
}
pressButtons() {
document.addEventListener('keydown', (e) => {
this.launchset.forEach(set => {
if (e.key === set.key) {
set.button.click();
}
})
})
}
}
let launchpad = new Launchpad(launchset);