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

Add a parameter to ignore invisible objects when parsing MusicXML files #401

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

leleogere
Copy link

@leleogere leleogere commented Nov 26, 2024

As explained in #395, it can sometimes be useful to parse a score only with information available to a human, i.e. visible information. MusicXML allow some elements to be invisible with the attribute print-object that can be set to "yes" or "no".

This PR simply add a new parameter ignore_invisible_objects to the function load_musicxml, defaulting to False for old behavior. When set to True, the loop over all elements in a measure will first check if the element has an attribute print-object set to "no", and if so, continue to the next loop without adding the object to the score (for note objects, I had to update the position with the duration anyway to avoid errors with backups when notes were not added to the part, I don't know if this can cause issues downstream?).

Note: Initially, I wanted to fully parse the print-object attribute, and adding it to all objects supporting it, but it turns out it is a bit more complex than I thought. You need to filter objects that do support it, and maybe use some sort of CanBeInvisible mixin to avoid duplicated code, then handle the attribute parsing logic in all the relative _handle_*object* when parsing the XML, probably resulting in duplicated code without some sort of refactoring somewhere. Additionally, we would need to also implement the export logic. This PR is way simpler, simply filtering invisible object at import-time.

…ject` set to "no" when parsing MusicXML files
@manoskary manoskary added the enhancement New feature or request label Nov 27, 2024
@CarlosCancino-Chacon
Copy link
Member

Hey @leleogere, thanks for the contribution! It would be great if you could add a test case for this feature (for example inpartitura/tests/test_xml.py).

@leleogere
Copy link
Author

I'll do that this week!

@leleogere
Copy link
Author

Added some tests!

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

Successfully merging this pull request may close these issues.

3 participants