From 1cfe02cbb1f30045b45ac0181cd1dd43fc601605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=A9stor=20N=C3=A1poles=20L=C3=B3pez?= Date: Wed, 4 Nov 2020 21:55:20 -0500 Subject: [PATCH 1/4] Parsing input with RomanText file instead of lists --- voicing.py | 44 +++++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/voicing.py b/voicing.py index 7cc3e42..5f74893 100644 --- a/voicing.py +++ b/voicing.py @@ -3,6 +3,7 @@ import itertools from fractions import Fraction +from music21.converter import parse from music21.note import Note from music21.pitch import Pitch from music21.chord import Chord @@ -256,37 +257,26 @@ def main(): "voice-leading procedures and dynamic programming." ) parser.add_argument( - "key", + "input", type=str, nargs="?", - help="the key of the chord progression", - ) - parser.add_argument( - "chord_progression", - type=str, - nargs="?", - help='a sequence of roman numeral annotations, e.g., "I I6 IV V43/ii ii V V7 I"', - ) - parser.add_argument( - "durations", - type=str, - nargs="?", - help="the associated durations of the chords (in quarter notes)", - ) - parser.add_argument( - "time_signature", type=str, nargs="?", help="the time signature" - ) - parser.set_defaults( - key="B-", - chord_progression="I I6 IV V43/ii ii V V7 I", - durations="1 1/2 1 1/2 1 1/2 1/2 1", - time_signature="6/8", + default='example.rntxt', + help="A RomanText input file with the chord progression", ) args = parser.parse_args() - key_and_chords = f"{args.key}: {args.chord_progression}" - durations = [Fraction(x) for x in args.durations.split()] - time_signature = args.time_signature - generateChorale(key_and_chords, durations, time_signature).show() + s = parse(args.input, format='rntxt') + key_it = s.flat.getElementsByClass('Key') + key = next(key_it, Key('C')).tonicPitchNameWithCase + ts_it = s.flat.getElementsByClass('TimeSignature') + ts = next(ts_it, TimeSignature('4/4')).ratioString + durations = [] + chords = [] + for rn in s.flat.getElementsByClass('RomanNumeral'): + durations.append(rn.duration.quarterLength) + chords.append(rn.figure) + chord_progression = ' '.join(chords) + key_and_chords = f"{key}: {chord_progression}" + generateChorale(key_and_chords, durations, ts).show() if __name__ == "__main__": From 6b5a440b57be9d1002f836e46239ce9b3ef65850 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=A9stor=20N=C3=A1poles=20L=C3=B3pez?= Date: Wed, 4 Nov 2020 22:02:59 -0500 Subject: [PATCH 2/4] Adding RomanText example file --- example.rntxt | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 example.rntxt diff --git a/example.rntxt b/example.rntxt new file mode 100644 index 0000000..7739abd --- /dev/null +++ b/example.rntxt @@ -0,0 +1,7 @@ +Composer: Eric Zhang +Title: Example progression + +Time signature: 6/8 + +m1 b1 Bb: I b1.66 I6 b2 IV b2.66 V43/ii +m2 b1 ii b1.67 V b2 V7 b2.33 I \ No newline at end of file From b80d73aa1355fdace16b5f80384ae3439c9ab4dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=A9stor=20N=C3=A1poles=20L=C3=B3pez?= Date: Wed, 4 Nov 2020 22:37:09 -0500 Subject: [PATCH 3/4] Formatting with black --- voicing.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/voicing.py b/voicing.py index 5f74893..ca367c7 100644 --- a/voicing.py +++ b/voicing.py @@ -260,21 +260,21 @@ def main(): "input", type=str, nargs="?", - default='example.rntxt', + default="example.rntxt", help="A RomanText input file with the chord progression", ) args = parser.parse_args() - s = parse(args.input, format='rntxt') - key_it = s.flat.getElementsByClass('Key') - key = next(key_it, Key('C')).tonicPitchNameWithCase - ts_it = s.flat.getElementsByClass('TimeSignature') - ts = next(ts_it, TimeSignature('4/4')).ratioString + s = parse(args.input, format="rntxt") + key_it = s.flat.getElementsByClass("Key") + key = next(key_it, Key("C")).tonicPitchNameWithCase + ts_it = s.flat.getElementsByClass("TimeSignature") + ts = next(ts_it, TimeSignature("4/4")).ratioString durations = [] chords = [] - for rn in s.flat.getElementsByClass('RomanNumeral'): + for rn in s.flat.getElementsByClass("RomanNumeral"): durations.append(rn.duration.quarterLength) chords.append(rn.figure) - chord_progression = ' '.join(chords) + chord_progression = " ".join(chords) key_and_chords = f"{key}: {chord_progression}" generateChorale(key_and_chords, durations, ts).show() From 5abc4c88edc9c8cfc30dae5fade10fa7c7b2eb38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=A9stor=20N=C3=A1poles=20L=C3=B3pez?= Date: Fri, 20 Nov 2020 15:57:58 -0500 Subject: [PATCH 4/4] Changing input format 'rntxt' -> 'rntext' --- voicing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/voicing.py b/voicing.py index ca367c7..86766d8 100644 --- a/voicing.py +++ b/voicing.py @@ -264,7 +264,7 @@ def main(): help="A RomanText input file with the chord progression", ) args = parser.parse_args() - s = parse(args.input, format="rntxt") + s = parse(args.input, format="rntext") key_it = s.flat.getElementsByClass("Key") key = next(key_it, Key("C")).tonicPitchNameWithCase ts_it = s.flat.getElementsByClass("TimeSignature")