Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions example.rntxt
Original file line number Diff line number Diff line change
@@ -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
44 changes: 17 additions & 27 deletions voicing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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="rntext")
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__":
Expand Down