-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
57 lines (47 loc) · 1.78 KB
/
index.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
<!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">
<script src="https://cdnjs.cloudflare.com/ajax/libs/tone/13.8.9/Tone.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.4/ace.js"></script>
<script async type="text/javascript" src="./index.js"></script>
<link type="text/css" rel="stylesheet" href="index.css">
<title>Tone.js Test</title>
</head>
<body>
<div>
<div id="go" onclick="go()">play</div>
<div id="stop" onclick="stop()">stop</div>
</div>
<div id="editor">
// drums ---------------------
sampler.get("hihat").start();
if([0,1,4,8,12].indexOf(idx) >= 0)
sampler.get("kick").start();
if([2,6,10,14].indexOf(idx) >= 0)
sampler.get("snare").start();
// synth -----------------------
// E♭, F, G, A♭, B♭, C, D
const chords = [
['Eb2','Gb3','Bb3','D4'], //I
['C2','Eb3','G3','Bb4'], //VI
['F2','Ab3','C3','Eb4'], //II
['Bb2','D3','F3','Ab4'] // V
];
let chordIndex = -1;
if(idx === 0) chordIndex = 0;
if(idx === 4) chordIndex = 1;
if(idx === 8) chordIndex = 2;
if(idx === 12) chordIndex = 3;
if(chordIndex >= 0)
{
polySynth.triggerAttackRelease(chords[chordIndex][0],'8n');
polySynth.triggerAttackRelease(chords[chordIndex][1],'16n', '+16n');
polySynth.triggerAttackRelease(chords[chordIndex][2],'16n', '+8n');
polySynth.triggerAttackRelease(chords[chordIndex][3],'16n', '+4n');
}
</div>
</body>
</html>