MIDO: ValueError: variable int must be a positive integer

242 views Asked by At

In my code I get

Traceback (most recent call last):
  File "Midi Projects/symbolToChord_v1.py", line 160, in <module>
    mo.save("songWithChords.mid") 
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mido/midifiles/midifiles.py", line 432, in save
    self._save(file)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mido/midifiles/midifiles.py", line 445, in _save
    write_track(outfile, track)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mido/midifiles/midifiles.py", line 251, in write_track
    data.extend(encode_variable_int(msg.time))
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mido/midifiles/meta.py", line 112, in encode_variable_int
    raise ValueError('variable int must be a positive integer')
ValueError: variable int must be a positive intege

I suppose I am running the latest version on MIDO.

pip freeze | grep mido
mido==1.2.9

what am doing wrong?

Any help would be greatly appreciated.

1

There are 1 answers

0
Quantum_Something On

I am no expert, but I had a similar problem.

The time attribute in mido is a bit confusing as it can either represents ticks or time deltas. From the documentation (https://mido.readthedocs.io/en/latest/midi_files.html#about-the-time-attribute ):

The time attribute is used in several different ways:

inside a track, it is delta time in ticks. This must be an integer. in messages yielded from play(), it is delta time in seconds (time elapsed since the last yielded message) (only important to implementers) inside certain methods it is used for absolute time in ticks or seconds

You can also see this github issue for reference https://github.com/mido/mido/issues/189