forked from steveseguin/social_stream
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmidimonitor.html
More file actions
133 lines (121 loc) · 4.26 KB
/
Copy pathmidimonitor.html
File metadata and controls
133 lines (121 loc) · 4.26 KB
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
<!DOCTYPE html>
<html>
<head>
<title>MIDI Monitor</title>
<script type="text/javascript" src="./thirdparty/webmidi3.js"></script>
<style>
body {
font-family: sans-serif;
padding: 20px;
background: #1a1a1a;
color: #ffffff;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
margin: 0;
}
#midiDisplay {
border: 1px solid #333;
padding: 20px;
border-radius: 8px;
background: #242424;
min-width: 300px;
text-align: center;
}
#midiDisplay > div {
margin: 15px 0;
font-size: 1.2em;
}
.active {
background: #2d5d2d;
padding: 5px 10px;
border-radius: 4px;
display: inline-block;
}
.inactive {
background: #5d2d2d;
padding: 5px 10px;
border-radius: 4px;
display: inline-block;
}
@keyframes flash {
0% { transform: scale(1); }
50% { transform: scale(1.1); }
100% { transform: scale(1); }
}
.flash {
animation: flash 0.2s ease;
}
#lastEvent {
display: inline-block;
}
</style>
</head>
<body>
<div id="midiDisplay">
<div>Device: <span id="deviceName">No device</span></div>
<div>Last Event: <span id="lastEvent">None</span></div>
<div>Note Status: <span id="noteStatus" class="inactive">OFF</span></div>
</div>
<script>
WebMidi.enable(function (err) {
if (err) {
console.log("WebMidi could not be enabled.", err);
return;
}
const deviceName = document.getElementById("deviceName");
const lastEvent = document.getElementById("lastEvent");
const noteStatus = document.getElementById("noteStatus");
let activeNotes = new Set();
function flashElement(element) {
element.classList.add('flash');
setTimeout(() => element.classList.remove('flash'), 200);
}
function updateNoteStatus() {
if (activeNotes.size > 0) {
noteStatus.textContent = "ON";
noteStatus.className = "active";
} else {
noteStatus.textContent = "OFF";
noteStatus.className = "inactive";
}
}
WebMidi.inputs.forEach((input, index) => {
deviceName.textContent = input.name || `MIDI Device #${index + 1}`;
input.addListener('noteon', "all", e => {
activeNotes.add(`${e.note.name}${e.note.octave}`);
lastEvent.textContent = `Note ON: ${e.note.name}${e.note.octave} (${e.note.number})`;
flashElement(lastEvent);
updateNoteStatus();
});
input.addListener('noteoff', "all", e => {
activeNotes.delete(`${e.note.name}${e.note.octave}`);
lastEvent.textContent = `Note OFF: ${e.note.name}${e.note.octave} (${e.note.number})`;
flashElement(lastEvent);
updateNoteStatus();
});
input.addListener('controlchange', "all", e => {
lastEvent.textContent = `CC: ${e.controller.number} = ${e.value}`;
flashElement(lastEvent);
});
input.addListener('pitchbend', "all", e => {
lastEvent.textContent = `Pitch Bend: ${e.value}`;
flashElement(lastEvent);
});
});
WebMidi.addListener("connected", e => {
deviceName.textContent = e.port.name || `MIDI Device #${WebMidi.inputs.indexOf(e.port) + 1}`;
});
WebMidi.addListener("disconnected", e => {
if (WebMidi.inputs.length === 0) {
deviceName.textContent = "No device";
lastEvent.textContent = "None";
activeNotes.clear();
updateNoteStatus();
}
});
});
</script>
</body>
</html>