-
Notifications
You must be signed in to change notification settings - Fork 155
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
Allow pre-loaded mido.MidiFile objects to be passed as an argument to PrettyMIDI #241
Conversation
…o.MidiFile objects - implemented unit test to verify PrettyMIDI object initialization
We actually need to put the new arg at the end of the args list to avoid breaking code that uses positional arguments. |
@craffel I agree. I have modified |
Need to change argument order in docstring 😅 |
I was considering setting the However, I can set the |
Docstring argument lists must match the order of the arguments. |
…e constructor definition
Sounds good! I have updated the docstrings as suggested. Thanks for putting up with my repeated requests for clarifications! |
Can you raise a ValueError if both a filename and a mido object are provided? This should not work silently because the correct behavior is ambiguous. The logic would look like
and then the rest of the logic can proceed assuming that only one of them has been provided (e.g. you don't need an elif). |
…he midi_file and mido_object arguments are provided. Related Changes: - Updated test_pm_object_initialization to reflect this change. - Updated PrettyMIDI docstring to reflect this change. - Added ValueError tests in test_pm_object_initialization
Done! Now, a ValueError will be raised if both |
else: | ||
# Otherwise, try passing it in as a file pointer | ||
midi_data = mido.MidiFile(file=midi_file, charset=charset) | ||
if mido_object is not None or midi_file is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This conditional is no longer necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need that conditional to handle cases when both the midi_file
and mido_object
is None; in this case, the logic part of the else block on line 135 will get executed (same as existing logic).
Having this line ensures we only need to implement the logic from line 94 to line 134 once to handle both midi_file
and mido_object
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I missed the preexisting logic. Thanks.
else: | ||
# Otherwise, try passing it in as a file pointer | ||
midi_data = mido.MidiFile(file=midi_file, charset=charset) | ||
if mido_object is not None or midi_file is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I missed the preexisting logic. Thanks.
Thanks! |
mido_object
argument in PrettyMIDI to pass pre-loadedmido.MidiFile
objectsThis closes #200 and #201