-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmidi.js
More file actions
64 lines (58 loc) · 2.61 KB
/
midi.js
File metadata and controls
64 lines (58 loc) · 2.61 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
// a fucking piano
const TRANSPOSITION = 1 //how many pitches to shift down
const NOTES_DOWN = 0 //how many notes to shift down (stacks with transposition) (why? idk i dont speak music)
const IGNORE_BLACK_NOTES = false
const ROUND_BLACK_NOTES = false
const Midi = require('@tonejs/midi').Midi
const Tone = require('tone')
const fs = require('fs')
const owo = new Midi(fs.readFileSync('freedomdive.mid'))
const base = {"_":"piano -https://paderos-neko.store"}
let scales = [
'C1', 'C#1', 'D1', 'D#1', 'E1', 'F1', 'F#1',
'G1', 'G#1', 'A1', 'A#1', 'B1', 'C2',
'C#2', 'D2', 'D#2', 'E2', 'F2', 'F#2', 'G2',
'G#2', 'A2', 'A#2', 'B2', 'C3', 'C#3',
'D3', 'D#3', 'E3', 'F3', 'F#3', 'G3', 'G#3',
'A3', 'A#3', 'B3', 'C4', 'C#4', 'D4',
'D#4', 'E4', 'F4', 'F#4', 'G4', 'G#4', 'A4',
'A#4', 'B4', 'C5', 'C#5', 'D5', 'D#5',
'E5', 'F5', 'F#5', 'G5', 'G#5', 'A5', 'A#5',
'B5' /*extra, 'C6', 'C#6', 'D6', 'D#6', 'E6', 'F6', 'F#6',
'G6', 'G#6', 'A6', 'A#6', 'B6'*/
]
if(IGNORE_BLACK_NOTES) scales = scales.filter(e=>!e.includes("#"))
console.log(scales,scales.length)
const detected = []
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) {
const noted = new Tone.Midi(note.midi-(TRANSPOSITION*12)-NOTES_DOWN).toNote()
if(!detected.includes(noted)) detected.push(noted)
timenoteson.push(scales.indexOf(noted)+1+(noted.includes('%')&&ROUND_BLACK_NOTES? 1 : 0))
}
}
trackconv.push([notetime,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) {
const noted = new Tone.Midi(note.midi-(TRANSPOSITION*12)-NOTES_DOWN).toNote()
timenotesoff.push(scales.indexOf(noted)+1+(noted.includes('%')&&ROUND_BLACK_NOTES? 1 : 0))
}
}
trackconv2.push([notetime,timenotesoff])
}
base['track'+ti] = [trackconv,trackconv2]
}
console.log('[note, index_in_range]',detected.filter((v,_,a)=>a.includes(v)),detected.map(m=>[m,scales.indexOf(m)]))
fs.writeFileSync('input.shitballspiano',JSON.stringify(base))
console.log('done')