Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jasonyanwenl opened this issue Mar 25, 2020 · 2 comments
Open

Comments

@jasonyanwenl
Copy link

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?

@craffel
Copy link
Owner

craffel commented Mar 25, 2020

Is the note.pitch or note.velocity for any of your notes larger than 127

@jasonyanwenl
Copy link
Author

OK. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants