-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmidi.js
More file actions
40 lines (35 loc) · 1.36 KB
/
Copy pathmidi.js
File metadata and controls
40 lines (35 loc) · 1.36 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
const TRANSPOSITION = 1
const NOTES_DOWN = 0
const {Midi} = require('@tonejs/midi')
const fs = require('fs')
const owo = new Midi(fs.readFileSync(process.argv.length > 2 ? process.argv[2] : 'input.mid'))
const base = {}
//owo.tracks = [owo.tracks[20],owo.tracks[22], owo.tracks[28]]
for(const ti in owo.tracks) {
const track = owo.tracks[ti]
const trackconv = []
const noteticks = [...new Set(track.notes.map(m=>m.time))]
for(const notetime of noteticks) {
const timenoteson = []
for(const note of track.notes){
if(note.time == notetime) {
timenoteson.push(note.midi - (TRANSPOSITION * 12) - NOTES_DOWN)
}
}
trackconv.push([Math.floor(notetime*100000000)/100000000,timenoteson])
}
const noteticks2 = [...new Set(track.notes.map(m=>m.time+m.duration))]
const trackconv2 = []
for(const notetime of noteticks2) {
const timenotesoff = []
for(const note of track.notes) {
if(note.time+note.duration == notetime) {
timenotesoff.push(note.midi - (TRANSPOSITION * 12) - NOTES_DOWN)
}
}
trackconv2.push([Math.floor(notetime*100000000)/100000000,timenotesoff])
}
base['track'+ti] = [trackconv,trackconv2]
}
fs.writeFileSync('input.seq',JSON.stringify(base))
console.log('done')