-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
88 lines (81 loc) · 2.62 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
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
<!doctype html>
<!--
This demo was created using the jThump js audio library by Dave Alger -- http://r.unti.me
jThump can be downloaded from here -- https://github.com/run-time/jThump
-->
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Language" content="en-us" />
<meta name="author" content="Dave Alger" />
<script language="javascript" type="text/javascript" src="jthump.js"></script>
<style>
body { background-color: #f6f6f0; }
select, p, a { color:#ccaa99; padding:0; font-family:Georgia; text-align:center; }
p { margin:0; padding-top:8px; padding-bottom:18px; }
a { margin-top:20; padding-top:8px; }
select { border: 2px solid tan; font-size:26px; }
</style>
</head>
<body>
<div style="font-size:18px; color:#ccaa99; margin:20px; padding-bottom:20px; font-family:Georgia; text-align:center; border-bottom: 2px solid #f0e5e0;">This demo was made possible by the <a href="https://github.com/run-time/jThump">jThump audio library on github</a>.</div>
<p style="font-size:50px">Type on the Keyboard</p>
<p style="font-size:22px">play random notes by pressing the 'z' key</p>
<br/>
<div style="text-align:center">
<select id="instrument" onchange="window.sound=this.options[this.selectedIndex].value;">
<option value="piano">Piano</option>
<option value="flute">Flute</option>
<option value="drums">Drums</option>
</select>
</div>
<script>
var sound = 'piano';
document.onkeydown = checkKeycode
function checkKeycode(e)
{
var keycode = 1;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
if ( sound == "piano" )
{
if ( keycode < 1 || keycode > 88 )
{
switch (keycode)
{
case 90: jThump( randBetween(1,88), sound ); break; // the 'z' key plays random notes
case 107: chord(49,53,56); break;
case 109: chord(44,49,53); break;
case 219: chord(32,39,44); break;
case 220: chord(44,48,51); break;
case 221: chord(39,44,48); break;
default: stopAll(); break;
}
}
else
{
jThump( parseInt( keycode ), sound );
}
}
else if ( ( sound == 'flute' && keycode >= 1 && keycode <= 60 ) || ( sound == 'drums' && keycode >= 1 && keycode <= 50 ) )
{
jThump( parseInt( keycode ), sound );
}
else
{
jThump( randBetween(1,50), sound );
}
}
function chord(n1,n2,n3)
{
jThump( n1, sound );
jThump( n2, sound );
jThump( n3, sound );
}
function randBetween( low, high )
{
return Math.floor( Math.random() * ( high - low + 1 ) + low );
}
</script>
</body>
</html>