-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
113 lines (90 loc) · 2.18 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
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
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Fokker Organ</title>
<script type="text/javascript" src="Main.js"></script>
</head>
<body>
<script type="text/javascript">
var AudioContext = window.AudioContext || window.webkitAudioContext || window.mozAudioContext || window.oAudioContext;
if (!OscillatorNode.prototype.start) OscillatorNode.prototype.start = OscillatorNode.prototype.noteOn;
if (!OscillatorNode.prototype.stop) OscillatorNode.prototype.stop = OscillatorNode.prototype.noteOff;
var context = new AudioContext;
var oscillator = {};
var real = new Float32Array(16);
var imag = new Float32Array(16);
real[ 0] = 0;
real[ 1] = 0;
real[ 2] = 0;
real[ 3] = 0;
real[ 4] = 0;
real[ 5] = 0;
real[ 6] = 0;
real[ 7] = 0;
real[ 8] = 0;
real[ 9] = 0;
real[10] = 0;
real[11] = 0;
real[12] = 0;
real[13] = 0;
real[14] = 0;
real[15] = 0;
imag[ 0] = 0;
imag[ 1] = 1/( 1*2);
imag[ 2] = -1/( 2*2);
imag[ 3] = -1/( 3*2);
imag[ 4] = 0/( 4*2);
imag[ 5] = -1/( 5*2);
imag[ 6] = 1/( 6*2);
imag[ 7] = -1/( 7*2);
imag[ 8] = 0/( 8*2);
imag[ 9] = 0/( 9*2);
imag[10] = 1/(10*2);
imag[11] = -1/(11*2);
imag[12] = 0/(12*2);
imag[13] = -1/(13*2);
imag[14] = 1/(14*2);
imag[15] = 1/(15*2);
var wave = context.createPeriodicWave(real, imag);
function keydown(idx) {
if (oscillator[idx] != undefined)
return;
var osc = context.createOscillator();
osc.setPeriodicWave(wave);
osc.frequency.value = 2 ** ((idx[0] * 5 + idx[1] * 3 - 18) / 31) * 440;
var gain = context.createGain();
gain.gain.value = 0.1;
osc.connect(gain);
gain.connect(context.destination);
osc.start(0);
oscillator[idx] = osc;
}
function keyup(idx) {
if (oscillator[idx] == undefined)
return;
oscillator[idx].disconnect();
oscillator[idx] = undefined;
}
// Elm app
var app = Elm.Main.fullscreen();
//Elm -> JS
app.ports.keydown.subscribe(keydown);
app.ports.keyup.subscribe(keyup);
// JS -> Elm
var body = document.querySelector('body');
body.onkeydown = function (e) {
if ( !e.metaKey ) {
e.preventDefault();
}
app.ports.downs.send(e.keyCode);
}
body.onkeyup = function (e) {
if ( !e.metaKey ) {
e.preventDefault();
}
app.ports.ups.send(e.keyCode);
}
</script>
</body>
</html>