@@ -1475,6 +1475,7 @@ def __init__(self,
14751475
14761476 self .atSoundingPitch = True
14771477
1478+ # a list of StaffReferenceType dicts -- one for each Measure parsed by MeasureParser
14781479 self .staffReferenceList : list [StaffReferenceType ] = []
14791480
14801481 self .lastTimeSignature : meter .TimeSignature | None = None
@@ -1826,14 +1827,19 @@ def separateOutPartStaves(self) -> list[stream.PartStaff]:
18261827 'TempoIndication' ,
18271828 'TimeSignature' ,
18281829 ]
1830+ # spanners generally appear only on the first staff.
1831+ # RepeatBracket spanners, however, need to appear on every staff.
1832+ EXEMPT_FROM_REMOVE = frozenset (
1833+ ['RepeatBracket' ],
1834+ )
18291835
18301836 uniqueStaffKeys : list [int ] = self ._getUniqueStaffKeys ()
18311837 partStaves : list [stream .PartStaff ] = []
18321838 appendedElementIds : set [int ] = set () # id is id(el) not el.id
18331839
18341840 def copy_into_partStaff (source : stream .Stream ,
18351841 target : stream .Stream ,
1836- omitTheseElementIds : set [int ]):
1842+ omitTheseElementIds : set [int ]) -> None :
18371843 elementIterator = source .getElementsByClass (STAFF_SPECIFIC_CLASSES )
18381844 elementIterator .restoreActiveSites = False
18391845 for sourceElem in elementIterator :
@@ -1858,7 +1864,9 @@ def copy_into_partStaff(source: stream.Stream,
18581864 removeClasses = STAFF_SPECIFIC_CLASSES [:]
18591865 if staffIndex != 0 : # spanners only on the first staff.
18601866 removeClasses .append ('Spanner' )
1861- newPartStaff = self .stream .template (removeClasses = removeClasses , fillWithRests = False )
1867+ newPartStaff = self .stream .template (removeClasses = removeClasses ,
1868+ fillWithRests = False ,
1869+ exemptFromRemove = EXEMPT_FROM_REMOVE )
18621870 partStaffId = f'{ self .partId } -Staff{ staffKey } '
18631871 newPartStaff .id = partStaffId
18641872 # set group for components (recurse?)
@@ -1867,7 +1875,11 @@ def copy_into_partStaff(source: stream.Stream,
18671875 partStaves .append (newPartStaff )
18681876 self .parent .m21PartObjectsById [partStaffId ] = newPartStaff
18691877 elementsIdsNotToGoInThisStaff : set [int ] = set ()
1878+
1879+ # iterate over the StaffReferenceType dicts, one for each measure.
18701880 for staffReference in self .staffReferenceList :
1881+ # this is a list of Music21Objects that should not go into the staff
1882+ # called by staffKey.
18711883 excludeOneMeasure = self ._getStaffExclude (
18721884 staffReference ,
18731885 staffKey
@@ -1905,7 +1917,8 @@ def _getStaffExclude(
19051917 targetKey : int
19061918 ) -> list [base .Music21Object ]:
19071919 '''
1908- Given a staff reference dictionary, remove and combine in a list all elements that
1920+ Given a staff reference dictionary (for a single measure),
1921+ remove and combine in a list all elements that
19091922 are NOT part of the given targetKey. Thus, return a list of all entries to remove.
19101923 It keeps those elements under the staff key None (common to all) and
19111924 those under given key. This then is the list of all elements that should be deleted.
0 commit comments