-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.js
56 lines (48 loc) · 1.1 KB
/
demo.js
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
var miku, timer;
Miku.init((instance) => {
miku = instance;
setLyrics();
miku.on('noteOn', (noteNum, velocity) => {
console.log('note on', noteNum, velocity);
}).on('pitchBend', (bend1, bend2) => {
console.log('bend', bend1, bend2);
}).on('noteOff', (noteNum, velocity) => {
console.log('note off', noteNum, velocity);
}).on('sysEx', (data) => {
console.log('sys ex', data);
});
});
function setLyrics() {
let lyrics = document.getElementById('lyrics').value
miku.lyrics(lyrics);
}
function noteOn(num) {
miku.noteOn(num, 64, 0);
clearTimeout(timer);
timer = setTimeout(function () {
miku.noteOff(num, 0, 0);
}, 1000)
}
function pitchBend(value) {
miku.pitchBend(value, 0);
}
// send pitch bend test
let pitch = 8192;
document.addEventListener('keydown', function (e) {
switch (e.keyCode) {
case 37:
miku.controlChange(1, 0);
break;
case 38:
pitch += 128;
miku.pitchBend(pitch);
break;
case 39:
miku.controlChange(1, 127);
break;
case 40:
pitch -= 128;
miku.pitchBend(pitch);
break;
}
});