-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
62 lines (55 loc) · 1.65 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
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/webmidi@2.5.3"></script>
</head>
<body>
<script>
const voltage_change_time = 10; // milliseconds
// YOU NEED TO EDIT THESE NUMBERS TO
// GET THE CORRECT PITCH
var currentVoltage = 0;
var voltageMap = {
"C": 0,
"C#": 0.7,
"D": 0.9,
"D#": 1.2,
"E": 1.45,
"F": 1.8,
"F#": 2.1,
"G": 3.3,
"G#": 2.6,
"A": 3.0,
"A#": 0,
"B": 0,
}
function sendVoltage(volts) {
console.log(volts);
fetch(`/msg?msg=voltage${volts}`)
.then(response => response.json())
.then(data => console.log(data));
}
var inputs = [];
WebMidi.enable(function(err) {
if (err) {
console.log("WebMidi could not be enabled.", err);
}
for (var i = 0; i < WebMidi.inputs.length; i++) {
inputs[i] = WebMidi.inputs[i];
inputs[i].addListener('noteon', "all",
function(e) {
console.log(e);
var newVoltage = voltageMap[e.note.name];
var voltageDiff = newVoltage - currentVoltage;
var steps = Math.floor(Math.abs(voltageDiff / 0.1));
for (var j = 0; j < steps; j++) {
setTimeout(sendVoltage, voltage_change_time * j, voltageDiff / steps * j + currentVoltage);
}
setTimeout(sendVoltage, steps * voltage_change_time, newVoltage);
currentVoltage = newVoltage;
}
);
}
});
</script>
</body>
</html>