-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpiano.html
60 lines (56 loc) · 2.45 KB
/
piano.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>My Website</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-geWF76RCwLtnZ8qwWowPQNguL3RmwHVBC9FhGdlKrxdiJJigb/j/68SIy3Te4Bkz" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tone/14.8.49/Tone.js" integrity="sha512-jduERlz7En1IUZR54bqzpNI64AbffZWR//KJgF71SJ8D8/liKFZ+s1RxmUmB+bhCnIfzebdZsULwOrbVB5f3nQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
</head>
<body>
<main class = "container">
<h1>Welcome to My Website 1.2</h1>
<div>
<button id = "C4">C</button>
<button id = "D4">D</button>
<button id = "E4">E</button>
<button id = "F4">F</button>
<button id = "G4">G</button>
<button id = "A4">A</button>
<button id = "B4">B</button>
<button id = "C5">C</button>
</div>
</main>
<script>
document.addEventListener("DOMContentLoaded", function(){
const synth = new Tone.PolySynth(Tone.Synth,{
oscillator: {
type: "amtriangle",
harmonicity: 0.5,
modulationType: "sine"
},
envelope: {
attackCurve: "exponential",
attack: 0.05,
decay: 0.2,
sustain: 0.2,
release: 1.5,
},
portamento: 0.05
}).toDestination();
function buttonPressed(event){
synth.triggerAttack(this.id)
synth.triggerRelease(this.id, Tone.now()+0.5)
};
let buttons = document.getElementsByTagName("button");
console.log(buttons);
for (let i=0; i< buttons.length; i++){
buttons[i].addEventListener("touchstart", buttonPressed);
buttons[i].addEventListener("touchmove", buttonPressed);
}
})
</script>
</body>
</html>