This adds both a midi generator and a midi type 1 simulator. While I would have preferred to use an existing tool for this, I found that timidity++ does not emit pitch wheel events correctly, and I don't know of another widely-distributed tool that does midi-to-midi format conversion. The c++ and python versions were co-developed. I wrote one to test the other. There is more cleanup to do, but `roundtrip.cpp` produces a valid type 0 midi file given a type 1 or type 0 midi file as input.
24 lines
515 B
Python
24 lines
515 B
Python
import sys
|
|
|
|
from parser import *
|
|
|
|
def dump_file(buf):
|
|
buf, header = parse_header(buf)
|
|
print(header)
|
|
assert header.ntrks > 0
|
|
tracks = []
|
|
for track_num in range(header.ntrks):
|
|
buf, track = parse_track(buf)
|
|
tracks.append(track)
|
|
print(f"track {track_num}:")
|
|
for i, event in enumerate(track.events):
|
|
print(' ' + repr(event))
|
|
|
|
print("remaining data:", len(buf))
|
|
|
|
import sys
|
|
with open(sys.argv[1], 'rb') as f:
|
|
b = memoryview(f.read())
|
|
|
|
dump_file(b)
|