-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontrol poc.html
112 lines (101 loc) · 3.04 KB
/
control poc.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
<!DOCTYPE html>
<html>
<script>
if (String.prototype.padLeft === undefined) {
String.prototype.padLeft = function(targetLength, padChar) {
if (this.length >= targetLength) {
return this;
}
return (padChar[0]).repeat(targetLength - this.length) + this;
}
}
if (Number.prototype.hex === undefined) {
Number.prototype.hex = function() {
return this.toString(16).padLeft(2, '0').toUpperCase();
}
}
let globalVtxOutput = null;
window.navigator.requestMIDIAccess({
sysex: true
}).then(access => {
const vtxInput = Array.from(access.inputs.values()).find(input => input.name == "Valvetronix X");
const vtxOutput = Array.from(access.outputs.values()).find(input => input.name == "Valvetronix X");
if (!vtxInput) {
throw new Error("no input");
}
if (!vtxOutput) {
throw new Error("no output");
}
return {vtxInput, vtxOutput};
}).then(({vtxInput, vtxOutput}) => {
vtxInput.onmidimessage = (message) => {
if (message.data[0] != 0xf0 || message.data[message.data.length - 1] != 0xf7) {
console.log("received non-SysEx message %o", message);
return;
}
if (message.data[1] != 0x42) {
console.log("received SysEx message with unexpected manufacturer %o", message);
return;
}
if (message.data.length == 8 && message.data[2] == 0x30 && message.data[3] == 0x00
&& message.data[4] == 0x01 && message.data[5] == 0x34 && message.data[6] == 0x23) {
console.log("received SysEx ACK");
return;
}
const messageHex = Array.from(message.data)
.slice(2, message.data.length - 1)
.map(n => n.hex())
.join(' ');
console.log("received SysEx message " + messageHex);
if (message.data.length == 12 && message.data[2] == 0x30 && message.data[3] == 0x00
&& message.data[4] == 0x01 && message.data[5] == 0x34 && message.data[6] == 0x41
&& message.data[7] == 0x04) {
const dialNumber = message.data[8];
const value = message.data[10] << 8 | message.data[9];
console.log("received SysEx dial message: dial %o is at %o", dialNumber.hex(), value.hex());
return;
}
};
console.log("subscribe to messages on %o", vtxInput);
globalVtxOutput = vtxOutput;
});
function applyGain() {
const value = parseInt(document.getElementById("gain").value);
console.log("sending gain = %o to %o", value, globalVtxOutput);
globalVtxOutput.send([
// sysex header
0xf0,
// manufacturer ID
0x42,
// command
0x30, 0x00, 0x01, 0x34, 0x41, 0x04,
// gain dial
0x00,
// value
value, 0x00,
// sysex end delimiter
0xf7,
]);
}
function requestCurrentState() {
console.log("requesting current state");
globalVtxOutput.send([
// sysex header
0xf0,
// manufacturer ID
0x42,
// command
0x30, 0x00, 0x01, 0x34, 0x12,
// sysex end delimiter
0xf7,
]);
}
</script>
<body>
<label for="gain">Gain</label>
<input type="number" min="0" max="100" id="gain" value="20">
<button onclick="applyGain()">Apply</button>
<br><br>
<button onclick="requestCurrentState()">request current state</button>
</body>
</html>