craffel / pretty-midi

Utility functions for handling MIDI data in a nice/intuitive way.
MIT License
856 stars 151 forks source link

Numpy type error for int loading midi #217

Closed JohanValero closed 11 months ago

JohanValero commented 1 year ago

It's generated the next error when executing for the file midi published for public use in "https://musescore.com/user/27983973/scores/5644401".

$ py main.py C:\Users\JohanValero\Downloads\Projects\Python\MidiApp\env\lib\site-packages\pretty_midi\pretty_midi.py:97: RuntimeWarning: Tempo, Key or Time signature change events found on non-zero tracks. This is not a valid type 0 or type 1 MIDI file. Tempo, Key or Time Signature may be wrong. warnings.warn( Traceback (most recent call last): File "C:\Users\JohanValero\Downloads\Projects\Python\MidiApp\main.py", line 188, in process_midi(cMIDI_EXAMPLE) File "C:\Users\JohanValero\Downloads\Projects\Python\MidiApp\main.py", line 167, in process_midi vMidiData = pretty_midi.PrettyMIDI("./resources/midi/" + iMidiFileName) File "C:\Users\JohanValero\Downloads\Projects\Python\MidiApp\env\lib\site-packages\pretty_midi\pretty_midi.py", line 104, in init self._load_instruments(midi_data) File "C:\Users\JohanValero\Downloads\Projects\Python\MidiApp\env\lib\site-packages\pretty_midi\pretty_midi.py", line 295, in _load_instruments current_instrument = np.zeros(16, dtype=np.int) File "C:\Users\JohanValero\Downloads\Projects\Python\MidiApp\env\lib\site-packages\numpy__init.py", line 284, in getattr__ raise AttributeError("module {!r} has no attribute " AttributeError: module 'numpy' has no attribute 'int'. Did you mean: 'inf'?

I must modify the file "pretty_midi.py" modifying the line 295: current_instrument = np.zeros(16, dtype=np.int) to: current_instrument = np.zeros(16, dtype=np.intp)

This issue was corrected in "https://github.com/craffel/pretty-midi/commit/91f58bedb2cc4a5022f837809cf642afd6577e9b" but installed the library using "pip install pretty_midi" then PyPI repository it's not updated with the correction.

My python version is: 3.10.5 My pip version is: 22.0.4

My enviroment library is: mido==1.2.10 numpy==1.24.1
pretty-midi==0.2.9 six==1.16.0

craffel commented 1 year ago

Yes, I haven't made a new release since then. I will try to do one soon, in the meantime you can just install directly from source via !pip install git+https://github.com/craffel/pretty-midi

Mechazo11 commented 11 months ago

@craffel your suggestion fixes this problem. Would you push this update to the build that is found from conda-forge?

craffel commented 11 months ago

The fix is in the version of pretty-midi on pypi (0.2.10, https://pypi.org/project/pretty-midi/). I don't manage the build on conda-forge.