-
Notifications
You must be signed in to change notification settings - Fork 1
/
reVisual.html
65 lines (55 loc) · 1.72 KB
/
reVisual.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
<!DOCTYPE HTML>
<html>
<head>
<script src="glue.js"></script>
<script src="makeSamples.js"></script>
<script src="benmu-riff.js"></script>
<script src="benmu-dataurl.js"></script>
<script src="sampleToImage.js"></script>
<link type="text/css" href="style.css" rel="stylesheet"/>
</head>
<body>
<form onsubmit="return false;">
<input type="text" id="oneliner" value="127*sin(t/1000)"/><br/>
<input type="submit" value="Generate Sound" id="gen" />
</form>
<div id="error"></div>
<pre>[enter] : play
[esc] : pause
</pre>
<canvas id="canvas" width="256" height="1024"></canvas>
<audio id="player" autoplay="true" controls="true"/>
<script>
var keyMap = { 13: onPlay, 27: stop};
var sampleFunction = null;
var errDiv = document.getElementById("error");
var oneLinerElt = document.getElementById('oneliner');
var canvas = document.getElementById('canvas');
var imageData = getImageData(canvas);
fillAlphas(imageData);
function onKey(event) {
var fn = keyMap[event.keyCode];
if(fn) fn();
else {
onPlay();
}
}
function updateFunction() {
var oneLiner = oneLinerElt.value;
sampleFunction = makeSampleFunction(oneLiner,errDiv);
}
function onPlay() {
updateFunction();
if(!sampleFunction) return;
sampleData = makeSampleData(sampleFunction);
play(sampleData);
drawIntoOneChannelImage(imageData,sampleData);
canvas.getContext("2d").putImageData(imageData,0,0);
}
document.getElementById("oneliner").focus();
document.getElementById("oneliner").onkeyup = onKey;
document.getElementById("gen").onclick = onPlay;
initPreview()
</script>
</body>
</html>