Can MIDI files written by MIDO provide custom tunings for the MIDI notes according to the MIDI Tuning Standard? And do players like windows media player support them? I am attempting to write a sample MIDI file that achieves this using the following python function:
def main():
mid = mido.MidiFile()
mid.ticks_per_beat = 8
track = mido.MidiTrack()
mid.tracks.append(track)
# Set all note tunings to midi 60
notes = []
for i in range(127):
notes += [i, 60, 0, 0]
track.append(mido.Message('sysex', data=(0x7F, 0, 8, 2, 0, 127) + tuple(notes)))
# Set tuning program to 0
track.append(mido.Message('control_change', control=64, value=3))
track.append(mido.Message('control_change', control=65, value=0))
track.append(mido.Message('control_change', control=6, value=0))
# Set tempo
track.append(mido.MetaMessage('set_tempo', tempo=2_000_000))
# Some notes
for note in (40, 41, 42, 43, 60, 59):
track.append(mido.Message('note_on', channel=0, velocity=63, note=note, time=0))
track.append(mido.Message('note_off', channel=0, velocity=63, note=note, time=1))
mid.save('micro.mid')
I would expect/hope this to retune all notes from 0-126 to the frequency of note 60 with 0 cents deviation using the sysex
message on tuning program 0, then explicitly select tuning program 0 through the 3 control_change
messages, then play a few arbitrary notes. Because all the played notes are in the range that were retuned by the sysex
, I expect they should all have the same pitch, but, instead, when playing the produced file, the notes all sound like they normally do.
For reference, here's the xxd
of the produced MIDI file:
00000000: 4d54 6864 0000 0006 0001 0001 0008 4d54 MThd..........MT
00000010: 726b 0000 024c 00f0 8403 7f00 0802 007f rk...L.......... Begin retunings
00000020: 003c 0000 013c 0000 023c 0000 033c 0000 .<...<...<...<..
00000030: 043c 0000 053c 0000 063c 0000 073c 0000 .<...<...<...<..
00000040: 083c 0000 093c 0000 0a3c 0000 0b3c 0000 .<...<...<...<..
00000050: 0c3c 0000 0d3c 0000 0e3c 0000 0f3c 0000 .<...<...<...<..
00000060: 103c 0000 113c 0000 123c 0000 133c 0000 .<...<...<...<..
00000070: 143c 0000 153c 0000 163c 0000 173c 0000 .<...<...<...<..
00000080: 183c 0000 193c 0000 1a3c 0000 1b3c 0000 .<...<...<...<..
00000090: 1c3c 0000 1d3c 0000 1e3c 0000 1f3c 0000 .<...<...<...<..
000000a0: 203c 0000 213c 0000 223c 0000 233c 0000 <..!<.."<..#<..
000000b0: 243c 0000 253c 0000 263c 0000 273c 0000 $<..%<..&<..'<..
000000c0: 283c 0000 293c 0000 2a3c 0000 2b3c 0000 (<..)<..*<..+<..
000000d0: 2c3c 0000 2d3c 0000 2e3c 0000 2f3c 0000 ,<..-<...<../<..
000000e0: 303c 0000 313c 0000 323c 0000 333c 0000 0<..1<..2<..3<..
000000f0: 343c 0000 353c 0000 363c 0000 373c 0000 4<..5<..6<..7<..
00000100: 383c 0000 393c 0000 3a3c 0000 3b3c 0000 8<..9<..:<..;<..
00000110: 3c3c 0000 3d3c 0000 3e3c 0000 3f3c 0000 <<..=<..><..?<..
00000120: 403c 0000 413c 0000 423c 0000 433c 0000 @<..A<..B<..C<..
00000130: 443c 0000 453c 0000 463c 0000 473c 0000 D<..E<..F<..G<..
00000140: 483c 0000 493c 0000 4a3c 0000 4b3c 0000 H<..I<..J<..K<..
00000150: 4c3c 0000 4d3c 0000 4e3c 0000 4f3c 0000 L<..M<..N<..O<..
00000160: 503c 0000 513c 0000 523c 0000 533c 0000 P<..Q<..R<..S<..
00000170: 543c 0000 553c 0000 563c 0000 573c 0000 T<..U<..V<..W<..
00000180: 583c 0000 593c 0000 5a3c 0000 5b3c 0000 X<..Y<..Z<..[<..
00000190: 5c3c 0000 5d3c 0000 5e3c 0000 5f3c 0000 \<..]<..^<.._<..
000001a0: 603c 0000 613c 0000 623c 0000 633c 0000 `<..a<..b<..c<..
000001b0: 643c 0000 653c 0000 663c 0000 673c 0000 d<..e<..f<..g<..
000001c0: 683c 0000 693c 0000 6a3c 0000 6b3c 0000 h<..i<..j<..k<..
000001d0: 6c3c 0000 6d3c 0000 6e3c 0000 6f3c 0000 l<..m<..n<..o<..
000001e0: 703c 0000 713c 0000 723c 0000 733c 0000 p<..q<..r<..s<..
000001f0: 743c 0000 753c 0000 763c 0000 773c 0000 t<..u<..v<..w<..
00000200: 783c 0000 793c 0000 7a3c 0000 7b3c 0000 x<..y<..z<..{<..
00000210: 7c3c 0000 7d3c 0000 7e3c 0000 f700 b040 |<..}<..~<.....@ End retunings, select tuning program
00000220: 0300 4100 0006 0000 ff51 031e 8480 0090 ..A......Q...... Set tempo, play some notes
00000230: 283f 0180 283f 0090 293f 0180 293f 0090 (?..(?..)?..)?..
00000240: 2a3f 0180 2a3f 0090 2b3f 0180 2b3f 0090 *?..*?..+?..+?..
00000250: 3c3f 0180 3c3f 0090 3b3f 0180 3b3f 00ff <?..<?..;?..;?..
00000260: 2f00