From a40e41a7f04b829ef02e9d8cb66a7dea1a78af70 Mon Sep 17 00:00:00 2001 From: Malcolm Sailor Date: Thu, 8 Sep 2022 11:20:52 -0400 Subject: [PATCH 1/3] transpose key of RomanNumeral --- music21/roman.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/music21/roman.py b/music21/roman.py index 2ef2e4cf5a..7d3a5b6cd2 100644 --- a/music21/roman.py +++ b/music21/roman.py @@ -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 + + >>> rn.transpose(4) + + >>> rn.transpose(-4, inPlace=True) + >>> rn + + ''' + post = super().transpose(value, inPlace=inPlace) + if not inPlace: + post.key = self.key.transpose(value, inPlace=False) + return post + else: + self.key.transpose(value, inPlace=True) + return None + # PUBLIC PROPERTIES # From 05c56343900ee1728da2c524a2dfc4c1a9f673c0 Mon Sep 17 00:00:00 2001 From: Malcolm Sailor Date: Wed, 21 Sep 2022 11:38:03 -0400 Subject: [PATCH 2/3] copy key objects --- music21/roman.py | 2 +- music21/romanText/translate.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/music21/roman.py b/music21/roman.py index 7d3a5b6cd2..af41eb5ad1 100644 --- a/music21/roman.py +++ b/music21/roman.py @@ -3110,7 +3110,7 @@ def transpose(self, value, *, inPlace=False) -> t.Optional[T]: post.key = self.key.transpose(value, inPlace=False) return post else: - self.key.transpose(value, inPlace=True) + self.key = self.key.transpose(value, inPlace=False) return None diff --git a/music21/romanText/translate.py b/music21/romanText/translate.py index 9a1d3a9cad..3fa0b74359 100644 --- a/music21/romanText/translate.py +++ b/music21/romanText/translate.py @@ -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) @@ -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) From 4c71baba1a2a27c8b523ab44ce31eaf213018b23 Mon Sep 17 00:00:00 2001 From: Malcolm Sailor Date: Tue, 27 Sep 2022 15:37:53 -0400 Subject: [PATCH 3/3] add T to type annot --- music21/roman.py | 2 +- music21/romanText/tsvEg_v2_measures.tsv | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 music21/romanText/tsvEg_v2_measures.tsv diff --git a/music21/roman.py b/music21/roman.py index af41eb5ad1..806292eea3 100644 --- a/music21/roman.py +++ b/music21/roman.py @@ -3091,7 +3091,7 @@ 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]: + def transpose(self: T, value, *, inPlace=False) -> t.Optional[T]: ''' Overrides :meth:`~music21.harmony.Harmony.transpose` so that `key` attribute is transposed as well. diff --git a/music21/romanText/tsvEg_v2_measures.tsv b/music21/romanText/tsvEg_v2_measures.tsv new file mode 100644 index 0000000000..f0870da600 --- /dev/null +++ b/music21/romanText/tsvEg_v2_measures.tsv @@ -0,0 +1,7 @@ +mn volta repeats +1 +2 1 end +2 2 +3 startend +4 start +5 end