-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.html
285 lines (255 loc) · 10.4 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
281
282
283
284
285
<!DOCTYPE html>
<html lang="en">
<head>
<script src='https://cwilso.github.io/WebMIDIAPIShim/build/WebMIDIAPI.min.js'></script>
<script src="https://cdn.jsdelivr.net/npm/webmidi"></script>
<script src="lumi_sysex.js"></script>
</head>
<body>
<h1> LUMI sysex commands </h1>
<form>
<p>
Midi device:
<select id="device" onchange="select_device(device.value)">
<option name="">No device detected</option>
</select>
Block:
<select id="block">
<option name="">no implemented yet</option>
</select>
</p>
<p id="keyboard">
</p>
<p>
Color 1: <input type="color" id="color1" value="#ff0000" oninput="change_color1()">
Color 2: <input type="color" id="color2" value="#0000ff" oninput="change_color2()">
</p>
<p>
<label for="brightness">Brightness</label>
<input id="brightness" type="range" value="100" min="0" max="100" oninput="set_brightness(brightness_value.value = brightness.value)">
<output id="brightness_value" for="brightness">100</output>
</p>
<p>
<label for="channel">Channel</label>
<input id="channel" type="range" value="0" min="0" max="127" oninput="set_channel(channel_value.value = channel.value)">
<output id="channel_value" for="channel">0</output>
</p>
<p>
<label for="octave">Octave</label>
<input id="octave" type="range" value="0" min="-4" max="5" oninput="set_octave(octave_value.value = octave.value)">
<output id="octave_value" for="octave">0</output>
</p>
<p>
<label for="transpose">Transpose</label>
<input id="transpose" type="range" value="0" min="-11" max="11" oninput="set_transpose(transpose_value.value = transpose.value)">
<output id="transpose_value" for="transpose">0</output>
</p>
<p>
<label for="strike">Strike sensitivity</label>
<input id="strike" type="range" value="127" min="0" max="127" oninput="set_strike_sensitivity(strike_value.value = strike.value)">
<output id="strike_value" for="strike">127</output>
</p>
<p>
<label for="sensitivity">Sensitivity</label>
<input id="sensitivity" type="range" value="127" min="0" max="127" oninput="set_sensitivity(sensitivity_value.value = sensitivity.value)">
<output id="sensitivity_value" for="sensitivity">127</output>
</p>
<p>
<label for="fixed_velocity">Fixed velocity</label>
<input id="fixed_velocity" type="checkbox" oninput="set_fixed_velocity(fixed_velocity.checked)">
</p>
<p>
<label for="fixed_velocity">Fixed velocity value</label>
<input id="fixed_velocity" type="range" value="127" min="0" max="127" oninput="set_fixed_velocity_value(fixed_velocity_value.value = fixed_velocity.value)">
<output id="fixed_velocity_value" for="fixed_velocity">0</output>
</p>
<p>
<label for="color_mode">Color mode</label>
<select id="color_mode" oninput="set_color_mode(color_mode.value)">
<option value="0">Rainbow</option>
<option value="1">Single color scale</option>
<option value="2">Piano</option>
<option value="3">Night</option>
</select>
</p>
<p>
<label for="scale">Scale</label>
<select id="scale" oninput="set_scale(scale.value)">
<option value="major">Major</option>
<option value="minor">Minor</option>
<option value="harmonic minor">Harmonic minor</option>
<option value="pentatonic neutral">Pentatonic neutral</option>
<option value="pentatonic major">Pentatonic major</option>
<option value="pentatonic minor">Pentatonic minor</option>
<option value="blues">Blues</option>
<option value="dorian">Dorian</option>
<option value="phrygian">Phrygian</option>
<option value="lydian">Lydian</option>
<option value="mixolydian">Mixolydian</option>
<option value="locrian">Locrian</option>
<option value="whole tone">Whole tone</option>
<option value="arabic (a)">Arabic (A)</option>
<option value="arabic (b)">Arabic (B)</option>
<option value="japanese">Japanese</option>
<option value="ryukyu">Ryukyu</option>
<option value="8-tone spanish">8-tone spanish</option>
<option value="chromatic">Chromatic</option>
</select>
</p>
<p>
<label for="key">TODO: Key</label>
<select id="key" oninput="set_key(event.target.value)">
<option value="C">C</option>
<option value="C#">C#</option>
<option value="D">D</option>
<option value="D#">D#</option>
<option value="E">E</option>
<option value="F">F</option>
<option value="F#">F#</option>
<option value="G">G</option>
<option value="G#">G#</option>
<option value="A">A</option>
<option value="A#">A#</option>
<option value="B">B</option>
</select>
</p>
<p>
<label for="pressure_tracking_mode">TODO: Pressure tracking mode</label>
<select id="pressure_tracking_mode" oninput="set_pressure_tracking_mode(pressure_tracking_mode.value)">
<option value="0"> Poly aftertouch </option>
<option value="1"> Channel pressure </option>
</select>
</p>
<p>
Custom command: F0 00 21 10 77 37 <input type="text" id="command" oninput="checksum.value = update_checksum(command.value)"> <span id="checksum">??</span> F7 <button type="button" onclick="run_command(command.value); return false;">Run</button>
</p>
<p>
<button type="button" onclick="query_serial(); return false;">Query serial</button>
<button type="button" onclick="send_reset(); return false;">Reset</button>
</p>
<p id="logs" style="color: red; height: 6rem; overflow-y: scroll;"></p>
</form>
<script>
function log(message) {
console.log(message);
var element = document.getElementById('logs');
element.appendChild(document.createTextNode(message));
element.appendChild(document.createElement('br'));
element.scrollTo(0, element.scrollHeight);
}
function make_keyboard() {
var keyboard = document.getElementById('keyboard');
var offset = 0;
var key_num = 0;
var minor = [1, 3, 6, 8, 10, 13, 15, 18, 20, 22];
for(var i = 0; i < 24; i++) {
var key = document.createElement('div');
key.style.cursor = 'pointer';
key.style.boxSizing = 'border-box';
key.style.display = 'inline-block';
key.style.width = '2rem';
key.style.height = '10rem';
key.style.border = '1px solid black';
key.style.position = 'relative';
if(minor.includes(i)) {
key.style.height = '6rem';
key.style.width = '1.25rem';
key.style.background = 'black';
key.style.left = (-(offset + 1.25/2)) + 'rem';
key.style.top = '-4rem';
key.style.zIndex = 99;
key.is_minor = true;
offset += 1.25;
} else {
key.style.left = -offset + 'rem';
key.is_minor = false;
if(i != 23) key.style.borderRight = '';
//offset = -2;
}
key.note_value = i;
key.onmousedown = function(event) {
lumi.output.playNote(lumi.octave_start + event.target.note_value);
event.target.style.background = 'gray';
event.preventDefault();
}
key.onmouseup = function(event) {
lumi.output.stopNote(lumi.octave_start + event.target.note_value);
if(event.target.is_minor)
event.target.style.background = 'black';
else
event.target.style.background = 'white';
event.preventDefault();
}
keyboard.appendChild(key);
}
}
function select_device(name) {
lumi.output = WebMidi.getOutputByName(name);
lumi.input = WebMidi.getInputByName(name);
if (lumi.input) {
lumi.input.addListener('sysex', 'all', (event) => {
log('RECV(' + event.data.length + ') ' + Array.from(event.data).map((value) => ('0' + value.toString(16)).toUpperCase().slice(-2)).join(' '));
});
}
log("device = " + lumi.output.name);
}
function update_device_list() {
var select = document.getElementById('device');
if(WebMidi.outputs.length > 0) select.innerHTML = '';
else select.innerHTML = '<option name="">No device detected</option>';
for(var i in WebMidi.outputs) {
var option = document.createElement('option');
option.innerText = WebMidi.outputs[i].name;
option.value = WebMidi.outputs[i].name;
select.appendChild(option);
if(WebMidi.outputs[i].name.includes('LUMI')) {
select.value = WebMidi.outputs[i].name;
}
}
select_device(select.value);
/*if(WebMidi.outputs.length == 0 || WebMidi.inputs.length == 0)
log('ERROR: no midi device detected. Make sure your LUMI register as the 2nd device (input[1] and output[1])).');
var input = WebMidi.inputs[1];
input.addListener('sysex', 'all', (event) => {
log('Recieved: ' + event.timestamp + ' ' + event.data.map((value) => value.toString(16).toUpperCase()).join(' '));
});*/
}
WebMidi.enable(function (err) {
if (err) {
log('ERROR: could not enable WebMidi. Use a webmidi-enabled browser such as chrome and allow it to use midi (see https://github.com/djipco/webmidi for details).');
} else {
log("WebMidi enabled!");
if(!WebMidi.sysexEnabled) {
log('ERROR: could not enable sysex support. Try a webmidi-enabled browser such as chrome.');
}
WebMidi.addListener('connected', update_device_list);
WebMidi.addListener('disconnected', update_device_list);
}
}, true);
make_keyboard();
function update_checksum(command) {
var values = command.trim().split(' ').map((text) => parseInt(text, 16));
for(i in values) {
if(isNaN(values[i])) {
return '??';
}
}
var computed = '' + checksum(values).toString(16).toUpperCase();
if(computed.length < 2) computed = '0' + computed;
return computed;
}
function run_command(command) {
var values = command.split(' ').map((text) => parseInt(text, 16));
send_sysex(values);
}
function change_color1() {
var value = parseInt(document.getElementById("color1").value.replace('#', ''), 16);
set_color(0, (value & 0xff0000) >> 16, (value & 0xff00) >> 8, value & 0xff);
}
function change_color2() {
var value = parseInt(document.getElementById("color2").value.replace('#', ''), 16);
set_color(1, (value & 0xff0000) >> 16, (value & 0xff00) >> 8, value & 0xff);
}
</script>
</body>
</html>