-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
280 lines (249 loc) · 11.2 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
<!DOCTYPE html>
<html>
<!-- For www.waveformer.net <script type="text/javascript" src="../common.js"></script> -->
<head>
<meta charset="UTF-8">
<title>Waveformer MIDI Monitor</title>
<link href="https://fonts.googleapis.com/css?family=Alata|Dosis|Didact|Roboto&display=swap" rel="stylesheet"/>
<!-- For www.waveformer.net <link rel="stylesheet" type="text/css" href="../common.css"/> -->
<!-- For www.waveformer.net <link rel="stylesheet" type="text/css" href="../navbar.css"/> -->
<style>
body {
font-family: 'Roboto', sans-serif;
}
h1
{
text-align: center;
margin: 5px 2px 0px 2px;
}
div.source {
text-align: right;
margin: 0px 4px 4px 2px;
}
table#midiInputsTable {
float: left;
}
table#midiOutputsTable {
float: right;
}
table#midiInputsTable, table#midiOutputsTable {
border: 1px solid black;
border-collapse: collapse;
text-align: center;
vertical-align: middle;
table-layout: fixed;
margin: 2px 4px 8px 4px;
}
table#midiInputsTable tr, table#midiOutputsTable tr {
border: 1px solid black;
border-collapse: collapse;
}
table#midiInputsTable td, table#midiInputsTable th, table#midiOutputsTable td, table#midiOutputsTable th {
border: 1px solid black;
border-collapse: collapse;
padding: 1px 4px 1px 4px;
}
table#midiInputsTable td, table#midiOutputsTable td {
text-align: left;
}
table#midiMonitorTable {
border: 1px solid black;
border-collapse: collapse;
text-align: center;
vertical-align: middle;
table-layout: auto;
width: calc(100% - 8px);
margin: 4px 2px 2px 4px
}
table#midiMonitorTable tr {
border: 1px solid black;
border-collapse: collapse;
}
table#midiMonitorTable td, table#midiMonitorTable th {
border: 1px solid black;
border-collapse: collapse;
white-space: nowrap;
padding: 1px 4px 1px 4px;
}
table#midiMonitorTable td {
text-align: left;
}
table#midiMonitorTable td#value {
background-image: linear-gradient(to right, rgb(240, 240, 240) 0%, rgb(180, 180, 180) 100%);
background-repeat: no-repeat;
}
table#midiMonitorTable td#time {
background-image: linear-gradient(to right, rgb(255, 255, 255) 0%, rgb(255, 255, 255) 45%, rgb(180, 180, 180) 50%, rgb(255, 255, 255) 55%, rgb(255, 255, 255) 100%);
background-repeat: no-repeat;
}
</style>
</head>
<body>
<!-- For www.waveformer.net <div w3-include-html="../navbar.html"></div> -->
<h1>Waveformer's MIDI Monitor</h1>
<div class="source"><a href="https://github.com/thammer/midimonitor">Source code on github</a></div>
<div id="content">
<table id="midiInputsTable"></table>
<table id="midiOutputsTable"></table>
<table id="midiMonitorTable">
<tr>
<th>Timestamp</th>
<th>Device</th>
<th>Status</th>
<th>Data 1</th>
<th>Data 2</th>
<th>Channel</th>
<th>Note</th>
<th>Event</th>
</tr>
</table>
</div>
<script>
if (!navigator.requestMIDIAccess)
{
var content = document.getElementById("content");
content.innerHTML = "Your web browser does not support the WebMIDI standard. Try using the latest version of the Chrome or Opera browsers.";
}
navigator.requestMIDIAccess().then(onMIDISuccess, onMIDIFailure);
function command2Name(command)
{
var name;
switch (command) {
case 8: name = "Note Off"; break;
case 9: name = "Note On"; break;
case 10: name = "Key Aftertouch"; break;
case 11: name = "Control Change"; break; // Could also be Channel Mode Message
case 12: name = "Program Change"; break;
case 13: name = "Channel Aftertouch"; break;
case 14: name = "Pitch Bend Change"; break;
default: name = "System Common or Real-Time"; break;
}
return name;
}
function midiNote2Name(note)
{
var oct = Math.trunc(note/12) - 1;
var offset = (note % 12) * 2;
var notes = "C C#D D#E F F#G G#A A#B ";
return notes.substring(offset, offset +2) + oct;
}
function midiMessageReceived(port, event)
{
var timestamp = event.timeStamp;
var channel = event.data[0] & 0x0f;
var command = event.data[0] >> 4;
var note = event.data[1];
var notename = (command == 8) || (command == 9) ? midiNote2Name(note) : "----";
if (command == 15) // System Common or System Real-Time Messages
{
// Ignore.
// Todo: Let user set filter instead.
}
else {
var color = ["#005500", "#00BB00", "#000000", "#550000", "#000000", "#000000", "#000000", "#000000", ];
var table = document.getElementById("midiMonitorTable");
var row = table.insertRow(1);
var c;
c = row.insertCell(-1); c.innerHTML = timestamp.toFixed(2);
c = row.insertCell(-1); c.innerHTML = port.name;
c = row.insertCell(-1); c.innerHTML = event.data[0]; c.style.color = color[command-8];
c = row.insertCell(-1); c.innerHTML = event.data[1];
c = row.insertCell(-1); c.innerHTML = event.data[2]; c.id = "value"; c.style.backgroundSize = (event.data[2]/127*100) + "%";
c = row.insertCell(-1); c.innerHTML = channel + 1;
c = row.insertCell(-1); c.innerHTML = notename;
c = row.insertCell(-1); c.innerHTML = command2Name(command); c.style.color = color[command-8];
var documentHeight = Math.max( document.body.scrollHeight, document.body.offsetHeight,
document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight );
// Remove old messages if table gets bigger than window.
// Todo: Let user set table height.
if ( (documentHeight > window.innerHeight) || (table.rows.length > 100)) {
table.deleteRow(table.rows.length - 1);
}
}
}
function openMIDIDevices(midiAccess)
{
var ports = midiAccess.inputs;
ports.forEach(function(port, key) {
if (port.connection !== "open")
{
console.log("Adding event listener for port: " + port.name);
port.open();
port.onmidimessage = function(event) {
midiMessageReceived(port, event)
};
}
});
ports = midiAccess.outputs;
ports.forEach(function(port, key) {
if (port.connection !== "open")
port.open();
});
}
function onMIDISuccess(midiAccess) {
midiAccess.addEventListener("statechange", function(event) {
console.log("Device updated: " + event.port.name + " [" + event.port.type + "] " + event.port.state);
openMIDIDevices(midiAccess);
updateMIDITables(midiAccess);
});
openMIDIDevices(midiAccess);
updateMIDITables(midiAccess);
}
function onMIDIFailure() {
console.log("Could not access MIDI devices");
}
function updateMIDITables(midiAccess)
{
var table = document.getElementById("midiInputsTable");
updateMIDITable(table, midiAccess.inputs, "MIDI Inputs");
table = document.getElementById("midiOutputsTable");
updateMIDITable(table, midiAccess.outputs, "MIDI Outputs");
}
function updateMIDITable(table, ports, deviceType)
{
table.innerHTML = "";
// Inputs
var row = document.createElement("tr");
table.appendChild(row);
var th = document.createElement("th");
row.appendChild(th);
var t = document.createTextNode(deviceType);
th.appendChild(t);
th = document.createElement("th");
row.appendChild(th);
t = document.createTextNode("ID");
th.appendChild(t);
th = document.createElement("th");
row.appendChild(th);
t = document.createTextNode("State");
th.appendChild(t);
th = document.createElement("th");
row.appendChild(th);
t = document.createTextNode("Connection");
th.appendChild(t);
var td;
ports.forEach(function(port, key) {
row = document.createElement("tr");
table.appendChild(row);
td = document.createElement("td");
row.appendChild(td);
t = document.createTextNode(port.name);
td.appendChild(t);
td = document.createElement("td");
row.appendChild(td);
t = document.createTextNode(port.id);
td.appendChild(t);
td = document.createElement("td");
row.appendChild(td);
t = document.createTextNode(port.state);
td.appendChild(t);
td = document.createElement("td");
row.appendChild(td);
t = document.createTextNode(port.connection);
td.appendChild(t);
});
}
</script>
<!-- For www.waveformer.net <script>includeHTML();</script> -->
</body>
</html>