Add a parameter to ignore invisible objects when parsing MusicXML files #401
+273
−5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 functionload_musicxml
, defaulting toFalse
for old behavior. When set toTrue
, the loop over all elements in a measure will first check if the element has an attributeprint-object
set to"no"
, and if so, continue to the next loop without adding the object to the score (fornote
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 ofCanBeInvisible
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.