forked from acidsound/band4all
-
Notifications
You must be signed in to change notification settings - Fork 0
/
piano.js
24 lines (24 loc) · 891 Bytes
/
piano.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
document.addEventListener("DOMContentLoaded", function () {
document
.querySelector(".modal>.dialog>.btnOk")
.addEventListener("click", async () => {
document.querySelector(".modal").classList.add("hidden");
context.state === "suspended" && (await context.resume());
console.log("audioContext state", context.state);
for (let downEvent of ["keydown"]) {
//, 'mousedown', 'touchstart']
window.addEventListener(downEvent, function (e) {
const key = keyMap[e.which] || e.target.getAttribute("data-note");
key && playKey(1, key);
});
}
["keyup"].map((
upEvent //, 'mouseup', 'touchend']
) =>
window.addEventListener(upEvent, function (e) {
const key = keyMap[e.which] || e.target.getAttribute("data-note");
key && playKey(0, key);
})
);
});
});