forked from kucerajacob/DRUM-SEQUENCER
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
151 lines (131 loc) · 4.18 KB
/
app.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
const rows = document.querySelector(".sequencer").children;
const kick = new Audio("/audio/kick.mp3"),
clap = new Audio("/audio/clap.mp3"),
hihat = new Audio("/audio/hihat.mp3"),
rim = new Audio("/audio/rim.mp3"),
Q = new Audio("/audio/Q.mp3"),
W = new Audio("/audio/W.mp3"),
E = new Audio("/audio/E.mp3"),
R = new Audio("/audio/R.mp3");
const item = document.querySelectorAll(".sample");
// Checkbox toggle functionality
item.forEach(function (el) {
el.onclick = function () {
if (el.classList.contains("item-selected")) {
el.classList.remove("item-selected");
} else {
el.classList.add("item-selected");
}
}
});
//fucker
// Clear button functionality
document.getElementById("clear-track").onclick = function () {
[].forEach.call(item, function (el) {
el.classList.remove("item-selected");
});
}
// Sample pad key press functionality
document.onkeydown = function (e) {
e = e || window.event;
switch (e.key) {
case "q":
Q.load();
Q.play();
document.getElementById("sampler1").classList.add("pressed");
break;
case "w":
W.load();
W.play();
document.getElementById("sampler2").classList.add("pressed");
break;
case "e":
E.load();
E.play();
document.getElementById("sampler3").classList.add("pressed");
break;
case "r":
R.load();
R.play();
document.getElementById("sampler4").classList.add("pressed");
break;
}
}
document.onkeyup = function (e) {
e = e || window.event;
switch (e.key) {
case "q":
// Q.pause();
// Q.currentTime = 0;
document.getElementById("sampler1").classList.remove("pressed");
break;
case "w":
// W.pause();
// W.currentTime = 0;
document.getElementById("sampler2").classList.remove("pressed");
break;
case "e":
// E.pause();
// E.currentTime = 0;
document.getElementById("sampler3").classList.remove("pressed");
break;
case "r":
// R.pause();
// R.currentTime = 0;
document.getElementById("sampler4").classList.remove("pressed");
break;
}
}
// BPM slider
const bpmSlider = document.getElementById("bpm-slider");
const bpmText = document.getElementById("bpm");
var BPM = bpmSlider.value;
bpmText.innerHTML = bpmSlider.value + " BPM";
bpmSlider.oninput = function () {
bpmText.innerHTML = this.value + " BPM";
BPM = parseInt(((60 / bpmSlider.value) * 1000) / 4);
}
let i = -1;
rowLoop = () => {
setTimeout(function () {
i++;
if (i === rows.length) {
i = 0;
document.querySelector(".d16").childNodes[1].classList.remove("row-highlight");
document.querySelector(".d16").childNodes[3].classList.remove("row-highlight");
document.querySelector(".d16").childNodes[5].classList.remove("row-highlight");
document.querySelector(".d16").childNodes[7].classList.remove("row-highlight");
}
document.querySelector(".d" + (i + 1)).childNodes[1].classList.add("row-highlight");
document.querySelector(".d" + (i + 1)).childNodes[3].classList.add("row-highlight");
document.querySelector(".d" + (i + 1)).childNodes[5].classList.add("row-highlight");
document.querySelector(".d" + (i + 1)).childNodes[7].classList.add("row-highlight");
if (i > 0) {
document.querySelector(".d" + i).childNodes[1].classList.remove("row-highlight");
document.querySelector(".d" + i).childNodes[3].classList.remove("row-highlight");
document.querySelector(".d" + i).childNodes[5].classList.remove("row-highlight");
document.querySelector(".d" + i).childNodes[7].classList.remove("row-highlight");
}
document.querySelectorAll(".d" + (i + 1)).forEach(function (bruh) {
if (bruh.childNodes[1].classList.contains("row-highlight") && bruh.childNodes[1].classList.contains("item-selected")) {
kick.load();
kick.play();
}
if (bruh.childNodes[3].classList.contains("row-highlight") && bruh.childNodes[3].classList.contains("item-selected")) {
clap.load();
clap.play();
}
if (bruh.childNodes[5].classList.contains("row-highlight") && bruh.childNodes[5].classList.contains("item-selected")) {
hihat.load();
hihat.play();
}
if (bruh.childNodes[7].classList.contains("row-highlight") && bruh.childNodes[7].classList.contains("item-selected")) {
rim.load();
rim.play();
}
});
rowLoop();
}, BPM);
}
// Call rowLoop() function
rowLoop();