Skip to content

Commit

Permalink
Preserve partName and partAbbreviation in expandRepeats() (cuthbertLa…
Browse files Browse the repository at this point in the history
…b#1260)

Create Part.mergeAttributes()

Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
  • Loading branch information
kir12 and jacobtylerwalls authored Apr 5, 2022
1 parent 8c9cefb commit 6d10446
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
17 changes: 17 additions & 0 deletions music21/repeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,8 @@ def process(self, deepcopy=True):
# TODO: need to copy spanners from each sub-group into their newest connects;
# must be done here as more than one connection is made

post.mergeAttributes(srcStream)

return post

def measureMap(self, returnType='index'):
Expand Down Expand Up @@ -4364,6 +4366,21 @@ def testRepeatEndingsImportedC(self):
# s.show()
# post = s.expandRepeats()

def test_expand_repeats_preserves_name(self):
# Test case provided by jacobtylerwalls on issue #1165
# https://github.com/cuthbertLab/music21/issues/1165#issuecomment-967293691

from music21 import converter
from music21 import bar

p = converter.parse('tinyNotation: c1 d e f')
p.measure(2).storeAtEnd(bar.Repeat(direction='end', times=1))
p.partName = 'mypartname'
p.partAbbreviation = 'mypartabbreviation'
exp = p.expandRepeats()
self.assertEqual(exp.partName, 'mypartname')
self.assertEqual(exp.partAbbreviation, 'mypartabbreviation')


# ------------------------------------------------------------------------------
# define presented order in documentation
Expand Down
13 changes: 13 additions & 0 deletions music21/stream/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13516,6 +13516,19 @@ def makeAccidentals(
else: # in place
return None

def mergeAttributes(self, other: 'Part'):
'''
Merge relevant attributes from the Other part
into this one. Key attributes of difference: partName and partAbbreviation.

TODO: doc test
'''

super().mergeAttributes(other)

for attr in ('_partName', '_partAbbreviation'):
if hasattr(other, attr):
setattr(self, attr, getattr(other, attr))

class PartStaff(Part):
'''
Expand Down
1 change: 0 additions & 1 deletion music21/stream/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -8587,7 +8587,6 @@ def testActiveSiteAfterBoolIteration(self):
self.assertIs(n.activeSite, s2)
self.assertTrue(s1.notes)
self.assertIs(n.activeSite, s2)

# -----------------------------------------------------------------------------


Expand Down

0 comments on commit 6d10446

Please sign in to comment.