Allow iter_all
to iterate over multiple classes
#428
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.
Fixes #426.
When iterating over a
Part
's elements, the user can only provide a single class to filter the output. If they want to get multiple classes, they can either iterate over all classes and filter a posteriori, or iterate multiple times over a single class. Those two workarounds are quite slow, so the possibility to iterate over multiple classes in a single pass would be useful.This PR simply allows the user to pass an iterable to the
cls
parameter ofiter_all
. For example, the following would allow to easily retrieve a list of all key/time signature/clef change over the score (in that order when they are simultaneous), in a single iteration over all time points.There are still a couple of things to discuss before merging this, briefly evoked in #426:
start
,end
andmode
apply to all classes. However, should the parameterinclude_subclasses
apply to all of them? Maybe I could add the possibility to pass either a single boolean (apply to all classes) or an iterable of booleans (apply to indivisual classes, same size as thecls
iterable).cls=[GenericNote, Note]
withinclude_subclasses=True
? (Or even simpler if they providecls=[Note, Note]
) Should the iterator return duplicate objects? Or deduplicated objects only? Or raise an error?I have not added any tests yet, but I can add some, although I'm not sure in which file they would belong. I haven't found any existing test for the function
iter_all
.