Allow cls
parameter of iter_all
to take an iterable of classes rather than a single class
#426
Labels
enhancement
New feature or request
When iterating over elements in a part, I sometimes need to iterate over multiple types of elements (e.g.
GenericNote
andTuplet
). However, currently, theiter_all
method only allows searching for one class (eventually including subclasses).If I want to get all
GenericNote
andTuplet
objects, I can currently think of two workarounds:iter_all
over all elements, and then filtering only forGenericNote
andTuplet
objectsiter_all
once for eachcls
I need and merge the two results somehowGenericNote
the first time, andTuplet
the second time (rather than over all objects as before)GenericNote
and once forTuplet
(and it would be even slower if I would like to gather 3, 4... types of objects)I feel like an interface like the following could be quite handy:
This would return an iterator with all
GenericNote
andTuplet
object (and their subclasses). In case of simultaneous event of both types, the order would be the same as the order of classes passed to the function, i.e. in this case allGenericNote
first, then allTuplet
. Note that this iterator would only iterate once over all timepoints, and only on required classes, which would make it faster than the two workaround explained above.Note that the
include_subclasses
parameter (as well as other parameters) would apply to all classes. I might be possible to allow passing a list of values (of the same size ascls
) specifying the parameter for each class, but I'm not sure that it would be that useful. Let me know if you think it would.I'm going to have a go at implementing that soon. I still have one interrogation: what if the user passes
cls=[GenericNote, Note]
withinclude_subclasses=True
? (or evencls=[Note, Note]
) Should theNote
objects be duplicated? Or should each object only appear once anyway? Or should the function raise an exception? I would be interested in hearing your thoughts about that.The text was updated successfully, but these errors were encountered: