-
Notifications
You must be signed in to change notification settings - Fork 433
transpose key of RomanNumeral #1414
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,6 +42,8 @@ | |
|
|
||
| # TODO: setting inversion should change the figure | ||
|
|
||
| T = t.TypeVar('T', bound='RomanNumeral') | ||
|
|
||
| # ----------------------------------------------------------------------------- | ||
|
|
||
|
|
||
|
|
@@ -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, 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) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why couldn't this be
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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).
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 # | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for this to work, self has to be annotated with T as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see Harmony L 2338
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, fixed, but mypy didn't seem to be complaining. The "x" seems to be because coverage decreased slightly. (Not quite sure why since both
inPlace=Trueandinplace=Falseare tested in theRomanNumeral.transpose()doctest.)