Skip to content
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

transpose key of RomanNumeral #1414

Merged
merged 3 commits into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions music21/roman.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@

# TODO: setting inversion should change the figure

T = t.TypeVar('T', bound='RomanNumeral')

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


Expand Down Expand Up @@ -3089,6 +3091,28 @@ def _updatePitches(self):
f'_updatePitches() was unable to derive pitches from the figure: {self.figure!r}'
) # pragma: no cover

def transpose(self: T, value, *, inPlace=False) -> t.Optional[T]:
'''
Overrides :meth:`~music21.harmony.Harmony.transpose` so that `key`
attribute is transposed as well.

>>> rn = roman.RomanNumeral('I', 'C')
>>> rn
<music21.roman.RomanNumeral I in C major>
>>> rn.transpose(4)
<music21.roman.RomanNumeral I in E major>
>>> rn.transpose(-4, inPlace=True)
>>> rn
<music21.roman.RomanNumeral I in A- major>
'''
post = super().transpose(value, inPlace=inPlace)
if not inPlace:
post.key = self.key.transpose(value, inPlace=False)
return post
else:
self.key = self.key.transpose(value, inPlace=False)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why couldn't this be self.key.transpose(value, inPlace=True) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I had in my initial commit (a40e41a) but I changed it based on the discussion in #1413 and your feedback at #1413 (comment).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah okay -- yes, we solved the problem in RomanText but not elsewhere, my bad.

return None


# PUBLIC PROPERTIES #

Expand Down
8 changes: 6 additions & 2 deletions music21/romanText/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@ def _copySingleMeasure(rtTagged, p, kCurrent):
else:
rnPast.key = kCurrent
if rnPast.secondaryRomanNumeral is not None:
newRN = roman.RomanNumeral(rnPast.figure, kCurrent)
newRN = roman.RomanNumeral(
rnPast.figure, copy.deepcopy(kCurrent)
)
newRN.duration = copy.deepcopy(rnPast.duration)
newRN.lyrics = copy.deepcopy(rnPast.lyrics)
m.replace(rnPast, newRN)
Expand Down Expand Up @@ -282,7 +284,9 @@ def _copyMultipleMeasures(rtMeasure: rtObjects.RTMeasure,
else:
rnPast.key = kCurrent
if rnPast.secondaryRomanNumeral is not None:
newRN = roman.RomanNumeral(rnPast.figure, kCurrent)
newRN = roman.RomanNumeral(
rnPast.figure, copy.deepcopy(kCurrent)
)
newRN.duration = copy.deepcopy(rnPast.duration)
newRN.lyrics = copy.deepcopy(rnPast.lyrics)
m.replace(rnPast, newRN)
Expand Down
7 changes: 7 additions & 0 deletions music21/romanText/tsvEg_v2_measures.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
mn volta repeats
1
2 1 end
2 2
3 startend
4 start
5 end