-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmidi_dump.py
More file actions
31 lines (23 loc) · 932 Bytes
/
midi_dump.py
File metadata and controls
31 lines (23 loc) · 932 Bytes
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
import mido
FILENAME = "D:\\Users\\legoh\\Music\\midi\\Don't-Stop-Me-Now.mid"
def notes_from_file(filename):
mid = mido.MidiFile(FILENAME)
tpb = mid.ticks_per_beat
tps = 8000*tpb
notes = {}
current_notes = {}
for track in mid.tracks:
for note in track:
if hasattr(note, 'channel') and note.channel not in notes:
notes[note.channel] = []
for track in mid.tracks:
abstime = 0
for note in track:
abstime += note.time
if note.type == 'note_on' and note.velocity != 0:
current_notes[note.channel] = note.time
elif note.type =='note_off' or (note.type == 'note_on' and note.velocity == 0):
notes[note.channel].append((note.note, current_notes[note.channel]/tps, note.time/tps))
elif note.type == 'set_tempo':
tps = 1000000/note.tempo*tpb
return notes