-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripter-file.js
40 lines (31 loc) · 894 Bytes
/
scripter-file.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
let midiNotes = [
// paste output from midi-to-array.js
];
let noteIndex = 0;
let startTime = null;
function ProcessMIDI() {
if (startTime === null) {
startTime = Date.now();
}
let elapsedTime = Date.now() - startTime;
while (noteIndex < midiNotes.length) {
let note = midiNotes[noteIndex];
if (elapsedTime >= note.start) {
let noteOn = new NoteOn();
noteOn.pitch = note.pitch;
noteOn.velocity = note.velocity;
Trace(`Playing note ${note.pitch} with velocity ${note.velocity} for ${note.duration} ms`);
noteOn.send();
let noteOff = new NoteOff(noteOn);
noteOff.sendAfterMilliseconds(note.duration);
noteIndex++;
} else {
break;
}
}
}
function Reset() {
noteIndex = 0;
startTime = null;
}
Reset();