Extra empty byte at end of Sequence Track Name MIDI message

• Sep 7, 2020 - 16:18

Hi folks,

It appears to me MuseScore generates an extra, second empty byte (\x00) at the end of a Sequence Track Name MIDI message, which may cause problems for music21 users--unless this output is correct and music21 needs to handle this case. I'm posting in the hope someone can point me in the right direction.

Use the Guitar template to create a one-measure file with an instrument named Classical Guitar.
Insert a note.
Export to midi.

Inspect the MIDI file -- there is an extra empty byte in the Sequence Track Name message:

In python:
>>> binascii.unhexlify('ff0311436c6173736963616c204775697461720000')
b'\xff\x03\x11Classical Guitar\x00\x00'

In Python with music21:
>>> from music21 import *
>>> mf = midi.MidiFile()
>>> mf.open('emptyByte.mid')
>>> mf.read()
>>> mf.close()
>>> [e for e in mf.tracks[0].events if 'Guitar' in repr(e)][0]
MidiEvent SEQUENCE_TRACK_NAME, t=0, track=0, channel=None, data=b'Classical Guitar\x00'

This will cause problems for music21 users who then export their work back out to musicXML.

Attachment Size
emptyByte.mid 131 bytes
emptyByte.mscz 3.15 KB

Comments

Hi, Jason,

I confirm seeing the same here with MuseScore 3.5.1.13199/Windows 7.

That item in MIDI is not to be null-terminated (there is an explicit length parameter in the meta-event encoding.)

Best regards,

Doug

Do you still have an unanswered question? Please log in first to post your question.