-
Notifications
You must be signed in to change notification settings - Fork 18
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
Conversation
…ject` set to "no" when parsing MusicXML files
Hey @leleogere, thanks for the contribution! It would be great if you could add a test case for this feature (for example in |
I'll do that this week! |
Added some tests! |
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 PR covers the support of invisible objects when parsing MusicXML.
Excellent contribution by @leleogere !!!
The implementation is great, but it also raises some preference questions as well:
- Should notes be allowed to be invisible?
- Should invisible mean skip parsing or should it be a
TimedObject
attribute that forces it to not be returned whenpart.iter_all
is called and relevant functions?
As per this review, all questions are high-level and do not necessarily need to be addressed or correct the provided implementation but rather open a discussion.
# If the object is invisible and the user wants it, skip the object | ||
# Will probably not skip everything, but works at least for notes and rests |
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 is more of a high-level question, the implementation is very fine in my opinion.
I get the concept of invisible rests, or even invisible measures/time signatures, etc. but I am not sure about the utility of invisible notes. What would be a potential use-case for this and why should partitura support skipping some notes?
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.
The most frequent case I've seen invisible notes is to simulate trills/mordents/tremolos for MIDI export (this is not needed in MuseScore as it automatically render those notes, but some other software may not? Or some people might want to end the trill in a custom way?). When parsing this kind of score, I would like to only have access to visible note (eventually with trill/mordent/tremolo information), but not to notes that have been added here for the sole purpose of MIDI export.
A lot of scores in ASAP have such invisible notes, for example in measures 21 and 23 of Chopin/Sonata_2/2nd_no_repeat/xml_score.musicxml.
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.
Thank you, I hadn't thought of such an application. This would then definitely be a great addition to partitura.
Thanks again for all your work. I will resolve this review conversation once the PR is ready for merge.
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.
Great addition for parsing or skipping invisible objects in musicxml. Cases for invisible notes can be spelled out trills and others. This PR includes tests too.
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.