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

Importing note-seq changes PrettyMIDI behavior for corrupt MIDI files. #29

Open
christhetree opened this issue Jan 19, 2021 · 6 comments

Comments

@christhetree
Copy link
Contributor

christhetree commented Jan 19, 2021

I recently came across this bug while processing LMD with my own scripts and note-seq chord inference.
Usually, when processing a corrupt MIDI file, pretty midi throws an exception. However, if note-seq is imported, no exception is thrown anymore.

Reproducible code:

from pretty_midi import PrettyMIDI
# import note_seq  # Uncomment this line to prevent exception from being thrown


pm = PrettyMIDI('d6174dfc21a1449dc423c58065f14173.mid')  # Exception should be thrown about too many ticks

This was on python 3.8 with a clean virtualenv environment and the latest version of pretty midi and note-seq.
Naturally this kind of behavior causes a lot of problems downstream if you are relying on exceptions to be thrown for skipping corrupt MIDI files.

Let me know if it's reproducible, maybe I'm missing something on my side.
GitHub doesn't let me attach MIDI files, but you can find the corrupt file in the Lakh MIDI dataset in the d folder.

@christhetree
Copy link
Contributor Author

Possibly related to #27
If an exception is not thrown for corrupt MIDI files, an OOM error kills the process eventually.

@cghawthorne
Copy link
Contributor

I'm guessing it's because of this line: https://github.com/magenta/note-seq/blob/master/note_seq/midi_io.py#L32

If you reset that constant to its default, do you get the desired behavior? This is a little tricky because we need that line to read some of our datasets, so I'm not sure what the best general solution is.

@christhetree
Copy link
Contributor Author

Thanks, that's the problem.

For now I've found a workaround on my end, but yeah I see the issue with this. Forking PrettyMIDI or setting and unsetting the variable each time are probably not the best ways to handle this.
On the other hand, I would imagine users importing note-seq alongside their own code that uses PrettyMIDI will be a common scenario, so changing the package for everyone can result in situations like mine.

Maybe a warning about this behavior would suffice?

@cghawthorne
Copy link
Contributor

That seems reasonable. Where would be a good place to put the warning?

@christhetree
Copy link
Contributor Author

I was thinking in the README under the installation section. I can submit a PR in a bit for it.

@cghawthorne
Copy link
Contributor

That would be great, 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