Skip to content

data byte must be in range 0..127 Error when writing to MIDI file #177

@jasonyanwenl

Description

@jasonyanwenl

I am a newbie to MIDI file. When I try to write to a midi file using
pretty_midi.PrettyMIDI().write()
The erros happens shown as follows:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-9-7a1ea048921d> in <module>()
----> 1 mid.write("mid_save.midi")

~/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/pretty_midi/pretty_midi.py in write(self, filename)
   1327                 track.append(mido.Message(
   1328                     'note_on', time=self.time_to_tick(note.start),
-> 1329                     channel=channel, note=note.pitch, velocity=note.velocity))
   1330                 # Also need a note-off event (note on with velocity 0)
   1331                 track.append(mido.Message(

~/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/mido/messages/messages.py in __init__(self, type, **args)
     86         if type == 'sysex':
     87             msgdict['data'] = SysexData(convert_py2_bytes(msgdict['data']))
---> 88         check_msgdict(msgdict)
     89         vars(self).update(msgdict)
     90 

~/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/mido/messages/checks.py in check_msgdict(msgdict)
     97                 '{} message has no attribute {}'.format(spec['type'], name))
     98 
---> 99         check_value(name, value)

~/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/mido/messages/checks.py in check_value(name, value)
     84 
     85 def check_value(name, value):
---> 86     _CHECKS[name](value)
     87 
     88 

~/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/mido/messages/checks.py in check_data_byte(value)
     56         raise TypeError('data byte must be int')
     57     elif not 0 <= value <= 127:
---> 58         raise ValueError('data byte must be in range 0..127')
     59 
     60 

ValueError: data byte must be in range 0..127

Could anyone please tell me what does this error message indicate? And any suggestions on how to fix this? Or what is the possible reason for this error?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions