from pathlib import Path
from struct import pack

output = Path(__file__).parent
header = bytes.fromhex("4d546864000000060000000101e0")
fixtures = {}
for semitones in (2, 12):
    controls = bytes.fromhex("00b0650000b0640000b006") + bytes([semitones])
    tail = bytes.fromhex("00b0260000903c5000e000608360803c0000ff2f00")
    track = controls + tail
    fixture = header + b"MTrk" + pack(">I", len(track)) + track
    (output / f"range-{semitones}.mid").write_bytes(fixture)
    fixtures[semitones] = fixture

first, second = fixtures.values()
differences = [offset for offset, pair in enumerate(zip(first, second)) if pair[0] != pair[1]]
assert differences == [33]
wheel = first[first.index(bytes.fromhex("e00060")) + 1:][:2]
assert wheel[0] + 128 * wheel[1] == 12288
print(f"{len(first)} bytes each; changed byte offsets: {differences}; wheel: 12288")
