diff --git a/music21/romanText/translate.py b/music21/romanText/translate.py index 9d02ba90c9..e9a55e65b9 100644 --- a/music21/romanText/translate.py +++ b/music21/romanText/translate.py @@ -130,7 +130,6 @@ from music21 import bar from music21 import base from music21 import common -from music21 import duration from music21 import exceptions21 from music21 import harmony from music21 import key @@ -575,10 +574,8 @@ def translateMeasureLineToken(self, measureLineToken: rtObjects.RTMeasure): else: m = self.translateSingleMeasure(measureLineToken) - if self.tsCurrent is not None and m.duration.quarterLength == 0: - m.duration = duration.Duration( - self.tsCurrent.barDuration.quarterLength - ) + if m.duration.quarterLength == 0: + self.fillMeasureFromPreviousRn(m) p.coreAppend(m) def fillToMeasureToken(self, measureToken: rtObjects.RTMeasure): @@ -590,19 +587,7 @@ def fillToMeasureToken(self, measureToken: rtObjects.RTMeasure): for i in range(self.lastMeasureNumber + 1, measureToken.number[0]): mFill = stream.Measure() mFill.number = i - if self.previousRn is not None: - newRn = copy.deepcopy(self.previousRn) - newRn.lyric = '' - # set to entire bar duration and tie - newRn.duration = copy.deepcopy(self.tsAtTimeOfLastChord.barDuration) - if self.previousRn.tie is None: - self.previousRn.tie = tie.Tie('start') - else: - self.previousRn.tie.type = 'continue' - # set to stop for now; may extend on next iteration - newRn.tie = tie.Tie('stop') - self.previousRn = newRn - mFill.append(newRn) + self.fillMeasureFromPreviousRn(mFill) appendMeasureToRepeatEndingsDict(self.lastMeasureToken, mFill, self.repeatEndings, i) @@ -610,6 +595,21 @@ def fillToMeasureToken(self, measureToken: rtObjects.RTMeasure): self.lastMeasureNumber = measureToken.number[0] - 1 self.lastMeasureToken = measureToken + def fillMeasureFromPreviousRn(self, mFill: stream.Measure) -> None: + if self.previousRn is not None: + newRn = copy.deepcopy(self.previousRn) + newRn.lyric = '' + # set to entire bar duration and tie + newRn.duration = copy.deepcopy(self.tsAtTimeOfLastChord.barDuration) + if self.previousRn.tie is None: + self.previousRn.tie = tie.Tie('start') + else: + self.previousRn.tie.type = 'continue' + # set to stop for now; may extend on next iteration + newRn.tie = tie.Tie('stop') + self.previousRn = newRn + mFill.append(newRn) + def parseKeySignatureTag(self, rtTagged: rtObjects.RTTagged): ''' Parse a key signature tag which has already been determined to @@ -1695,6 +1695,14 @@ def _test_ending_contents( _repeat_tester(end_repeat1, 'end', 2.0, 3) _repeat_tester(start_repeat2, 'start', 0.0, 4) _repeat_tester(end_repeat2, 'end', 2.0, 4) + for measure in s[stream.Measure]: + rn_iter = measure[roman.RomanNumeral] + self.assertEqual(len(rn_iter), 1) + # mypy complains about the next line because + # RecursiveIterator.first() has t.Optional type, but we know + # it will not be None because we have just asserted that rn_iter + # has length 1 + self.assertEqual(rn_iter.first().figure, 'I') # type: ignore _test_expanded(s, 14.0)