-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
356 lines (322 loc) · 9.9 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
//
const key1 = document.querySelector(".key-1");
const key2 = document.querySelector(".key-2");
const key3 = document.querySelector(".key-3");
const key4 = document.querySelector(".key-4");
const key5 = document.querySelector(".key-5");
const key6 = document.querySelector(".key-6");
const key7 = document.querySelector(".key-7");
const key8 = document.querySelector(".key-8");
const key9 = document.querySelector(".key-9");
const key10 = document.querySelector(".key-10");
const key11 = document.querySelector(".key-11");
const key12 = document.querySelector(".key-12");
const key13 = document.querySelector(".key-13");
const key14 = document.querySelector(".key-14");
const key15 = document.querySelector(".key-15");
const key16 = document.querySelector(".key-16");
const key17 = document.querySelector(".key-17");
const key18 = document.querySelector(".key-18");
const key19 = document.querySelector(".key-19");
const key20 = document.querySelector(".key-20");
const key21 = document.querySelector(".key-21");
const key22 = document.querySelector(".key-22");
const key23 = document.querySelector(".key-23");
const key24 = document.querySelector(".key-24");
const key25 = document.querySelector(".key-25");
//
const black1 = document.querySelector(".black-1");
const black2 = document.querySelector(".black-2");
const black3 = document.querySelector(".black-3");
const black4 = document.querySelector(".black-4");
const black5 = document.querySelector(".black-5");
const black6 = document.querySelector(".black-6");
const black7 = document.querySelector(".black-7");
const black8 = document.querySelector(".black-8");
const black9 = document.querySelector(".black-9");
const black10 = document.querySelector(".black-10");
// /////////////
// hideBtn.addEventListener('click', () =>{
// console.log("hi");
// });
// *****************
function keyPressWhite(key) {
key.classList.add("press");
setTimeout(function () {
key.classList.remove("press");
}, 200);
}
function keyPressBlack(key) {
key.classList.add("black-press");
setTimeout(function () {
key.classList.remove("black-press");
}, 200);
}
// **************************************************************************************************************
// Each key sound
// C
key1.addEventListener("click", () => {
// new Audio('24-paino-keys/key01.mp3').play();
new Audio("24-paino-keys/261-C.mp3").play();
keyPressWhite(key1);
});
// ************************************************
key2.addEventListener("click", () => {
new Audio("24-paino-keys/277-C-sharp.mp3").play();
keyPressBlack(black1);
});
// D
key3.addEventListener("click", () => {
new Audio("24-paino-keys/293-D.mp3").play();
console.log("key-1");
keyPressWhite(key3);
});
key4.addEventListener("click", () => {
new Audio("24-paino-keys/311-D-sharp.mp3").play();
keyPressBlack(black2);
});
/////////////////////////////////////////////////////////////////
// E
key5.addEventListener("click", () => {
new Audio("24-paino-keys/329-E.mp3").play();
console.log("key-1");
keyPressWhite(key5);
});
// F
key6.addEventListener("click", () => {
new Audio("24-paino-keys/349-F.mp3").play();
console.log("key-1");
keyPressWhite(key6);
});
key7.addEventListener("click", () => {
new Audio("24-paino-keys/369F-sharp.mp3").play();
keyPressBlack(black3);
});
// //////////////////////////////////////////////////////
// G
key8.addEventListener("click", () => {
new Audio("24-paino-keys/391-G.mp3").play();
keyPressWhite(key8);
});
key9.addEventListener("click", () => {
new Audio("24-paino-keys/415-G-sharp.mp3").play();
keyPressBlack(black4);
});
// A
key10.addEventListener("click", () => {
new Audio("24-paino-keys/440-A.mp3").play();
keyPressWhite(key10);
});
key11.addEventListener("click", () => {
new Audio("24-paino-keys/466-A-sharp.mp3").play();
keyPressBlack(black5);
});
// B
key12.addEventListener("click", () => {
new Audio("24-paino-keys/495-B.mp3").play();
keyPressWhite(key12);
});
// ***************************HIGHER OCTAVE*****************************************
// C
key13.addEventListener("click", () => {
new Audio("24-paino-keys/HIGHER-OCTAVE/523-C.mp3").play();
keyPressWhite(key13);
});
key14.addEventListener("click", () => {
new Audio("24-paino-keys/HIGHER-OCTAVE/545-C-sharp.mp3").play();
keyPressBlack(black6);
});
// D
key15.addEventListener("click", () => {
new Audio("24-paino-keys/HIGHER-OCTAVE/587-D.mp3").play();
keyPressWhite(key15);
});
key16.addEventListener("click", () => {
new Audio("24-paino-keys/HIGHER-OCTAVE/622-D-sharp.mp3").play();
keyPressBlack(black7);
});
// E
key17.addEventListener("click", () => {
new Audio("24-paino-keys/HIGHER-OCTAVE/659-E.mp3").play();
keyPressWhite(key17);
});
// F
key18.addEventListener("click", () => {
new Audio("24-paino-keys/HIGHER-OCTAVE/698-F.mp3").play();
keyPressWhite(key18);
});
key19.addEventListener("click", () => {
new Audio("24-paino-keys/HIGHER-OCTAVE/698-F-sharp.mp3").play();
keyPressBlack(black8);
});
// G
key20.addEventListener("click", () => {
new Audio("24-paino-keys/HIGHER-OCTAVE/783-G.mp3").play();
keyPressWhite(key20);
});
key21.addEventListener("click", () => {
new Audio("24-paino-keys/HIGHER-OCTAVE/830-G-sharp.mp3").play();
keyPressBlack(black9);
});
// A
key22.addEventListener("click", () => {
new Audio("24-paino-keys/HIGHER-OCTAVE/880-A.mp3").play();
keyPressWhite(key22);
});
key23.addEventListener("click", () => {
new Audio("24-paino-keys/HIGHER-OCTAVE/932-A-sharp.mp3").play();
keyPressBlack(black10);
});
// B
key24.addEventListener("click", () => {
new Audio("24-paino-keys/HIGHER-OCTAVE/987-B.mp3").play();
keyPressWhite(key24);
});
// C
key25.addEventListener("click", () => {
new Audio("24-paino-keys/HIGHER-OCTAVE/1046-C.mp3").play();
keyPressWhite(key25);
});
// //////////////////////////////////////////////
// KEYBOARD EVENTS
// //////////////////////////////////////////
document.addEventListener("keydown", function (e) {
if (e.key === "a") {
console.log("e.key");
new Audio("24-paino-keys/261-C.mp3").play();
keyPressWhite(key1);
}
if (e.key === "w") {
console.log("e.key");
new Audio("24-paino-keys/277-C-sharp.mp3").play();
keyPressBlack(black1);
}
if (e.key === "s") {
console.log("e.key");
new Audio("24-paino-keys/293-D.mp3").play();
keyPressWhite(key3);
}
if (e.key === "e") {
console.log("e.key");
new Audio("24-paino-keys/311-D-sharp.mp3").play();
keyPressBlack(black2);
}
// /////////////////////////////////////////////////////////
// EEEEEEEEEEEEEE
if (e.key === "d") {
console.log("e.key");
new Audio("24-paino-keys/329-E.mp3").play();
keyPressWhite(key5);
}
//FFFFFFFFFFFFFFF
if (e.key === "f") {
console.log("e.key");
new Audio("24-paino-keys/349-F.mp3").play();
keyPressWhite(key6);
}
if (e.key === "r") {
console.log("e.key");
new Audio("24-paino-keys/369F-sharp.mp3").play();
keyPressBlack(black3);
}
// /////////////////////////////////////////////
// GGGGGGGGGGGGG
if (e.key === "g") {
console.log("e.key");
new Audio("24-paino-keys/391-G.mp3").play();
keyPressWhite(key8);
}
if (e.key === "t") {
console.log("e.key");
new Audio("24-paino-keys/415-G-sharp.mp3").play();
keyPressBlack(black4);
}
// AAAAAAAAAAA
if (e.key === "h") {
console.log("e.key");
new Audio("24-paino-keys/440-A.mp3").play();
keyPressWhite(key10);
}
if (e.key === "y") {
console.log("e.key");
new Audio("24-paino-keys/466-A-sharp.mp3").play();
keyPressBlack(black5);
}
// B
if (e.key === "j") {
console.log("e.key");
new Audio("24-paino-keys/495-B.mp3").play();
keyPressWhite(key12);
}
// CCCCCCCCCCCCCCCCC
if (e.key === "k") {
console.log("e.key");
new Audio("24-paino-keys/HIGHER-OCTAVE/523-C.mp3").play();
keyPressWhite(key13);
}
if (e.key === "u") {
console.log("e.key");
new Audio("24-paino-keys/HIGHER-OCTAVE/545-C-sharp.mp3").play();
keyPressBlack(black6);
}
// DDDDDDDDDDDDDDDDD
if (e.key === "l") {
console.log("e.key");
new Audio("24-paino-keys/HIGHER-OCTAVE/587-D.mp3").play();
keyPressWhite(key15);
}
if (e.key === "i") {
console.log("e.key");
new Audio("24-paino-keys/HIGHER-OCTAVE/622-D-sharp.mp3").play();
keyPressBlack(black7);
}
// E
if (e.key === ";") {
console.log("e.key");
new Audio("24-paino-keys/HIGHER-OCTAVE/659-E.mp3").play();
keyPressWhite(key17);
}
//FFFFFFF
if (e.key === '"') {
console.log("e.key");
new Audio("24-paino-keys/HIGHER-OCTAVE/698-F.mp3").play();
keyPressWhite(key18);
}
if (e.key === "o") {
console.log("e.key");
new Audio("24-paino-keys/HIGHER-OCTAVE/698-F-sharp.mp3").play();
keyPressBlack(black8);
}
// ggggg
if (e.key === "v") {
console.log("e.key");
new Audio("24-paino-keys/HIGHER-OCTAVE/783-G.mp3").play();
keyPressWhite(key20);
}
if (e.key === "p") {
console.log("e.key");
new Audio("24-paino-keys/HIGHER-OCTAVE/830-G-sharp.mp3").play();
keyPressBlack(black9);
}
// aaaaaaa
if (e.key === "b") {
console.log("e.key");
new Audio("24-paino-keys/HIGHER-OCTAVE/880-A.mp3").play();
keyPressWhite(key22);
}
if (e.key === "[") {
console.log("e.key");
new Audio("24-paino-keys/HIGHER-OCTAVE/932-A-sharp.mp3").play();
keyPressBlack(black10);
}
if (e.key === "n") {
console.log("e.key");
new Audio("24-paino-keys/HIGHER-OCTAVE/987-B.mp3").play();
keyPressWhite(key24);
}
if (e.key === "m") {
console.log("e.key");
new Audio("24-paino-keys/HIGHER-OCTAVE/1046-C.mp3").play();
keyPressWhite(key25);
}
});