From ab68d73b611780d2c57fd1df0ee054168bed3031 Mon Sep 17 00:00:00 2001 From: Malcolm Sailor Date: Fri, 9 Sep 2022 10:24:50 -0400 Subject: [PATCH] write 'slow 3/8' etc. --- music21/romanText/writeRoman.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/music21/romanText/writeRoman.py b/music21/romanText/writeRoman.py index a42bd25fd3..93f0885d1f 100644 --- a/music21/romanText/writeRoman.py +++ b/music21/romanText/writeRoman.py @@ -249,7 +249,14 @@ def prepSequentialListOfLines(self): tsThisMeasure = thisMeasure.getElementsByClass(meter.TimeSignature) if tsThisMeasure: firstTS = tsThisMeasure[0] - self.combinedList.append(f'Time Signature: {firstTS.ratioString}') + if (firstTS.ratioString in ('3/8', '6/8') + and firstTS.beatDivisionCountName == 'Simple'): + tsPrefix = 'slow ' + else: + tsPrefix = '' + self.combinedList.append( + f'Time Signature: {tsPrefix}{firstTS.ratioString}' + ) if len(tsThisMeasure) > 1: unprocessedTSs = [x.ratioString for x in tsThisMeasure[1:]] msg = f'further time signature change(s) unprocessed: {unprocessedTSs}' @@ -413,7 +420,8 @@ class Test(unittest.TestCase): along with two test by modifying those scores. Additional tests for the standalone functions rnString and intBeat and - for handling the special case of opus objects. + for handling the special case of opus objects, plus a test to verify + handling of 'slow' 6/8 and 3/8. ''' def testOpus(self): @@ -542,6 +550,25 @@ def testTypeParses(self): rn = roman.RomanNumeral('viio6', 'G') RnWriter(rn) # and even (perhaps dubiously) directly on other music21 objects + def test_slow_meters(self): + from io import StringIO + from itertools import product + import textwrap + from music21 import converter + for ts, fast_or_slow in product(('3/8', '6/8'), ('slow ', 'fast ', '')): + rntxt = textwrap.dedent(f'''Time Signature: {fast_or_slow}{ts} + m1 C: I + ''') + text_stream = StringIO() + s = converter.parse(rntxt, format='romanText') + s.write('romanText', text_stream) + new_rntxt = text_stream.getvalue() + # Since the default is 'fast', it is not written out. + if fast_or_slow == 'fast ': + fast_or_slow = '' + self.assertIn(f'Time Signature: {fast_or_slow}{ts}', new_rntxt) + + # ------------------------------------------------------------------------------ def testRnString(self):