-
Notifications
You must be signed in to change notification settings - Fork 21
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 iter_all
to iterate over multiple classes
#428
base: develop
Are you sure you want to change the base?
Conversation
Hello @leleogere that is a very nice and cool addition to the package. May I ask you to add a test for that, it does not have to be much, you can use |
Thank you @manoskary! Yes I'll add some tests! Before that, do you have some insights about the two points I raised?
|
Hello @leleogere thanks for your message. Let me reply here. For the case where But that is just my opinion on this topic. |
I moved the class iteration logic from |
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
.