diff options
Diffstat (limited to 'gen_pitches.py')
| -rw-r--r-- | gen_pitches.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/gen_pitches.py b/gen_pitches.py new file mode 100644 index 0000000..8c15317 --- /dev/null +++ b/gen_pitches.py @@ -0,0 +1,58 @@ +from functools import partial +from string import Template + +index_to_pitch = [ "a", "b", "c", "d", "e", "f", "g"] +pitch_to_index = { "a": 0, "b": 1, "c": 2, "d": 3, "e": 4, "f": 5, "g": 6} + +def pitch_transpose(pitch, delta=1): + return index_to_pitch[(pitch_to_index[pitch[0]] + delta) % 7] + pitch[1:] + +def bar_transpose(bar, delta=1): + return " ".join(pitch_transpose(pitch, delta) for pitch in bar.split()) + +def compile_exercise(seed_asc, seed_desc): + asc = "\n".join(bar_transpose(seed_asc, i) for i in xrange(7)) + desc = "\n".join(bar_transpose(seed_desc, -i) for i in xrange(7)) + right = """\\relative e { +$asc + +$asc +\\bar "||" +} +\\relative e'' { +$desc + +$desc +\\bar "|." +} +""" + left = """\\relative e, { +$asc + +$asc +\\bar "||" +} +\\relative e' { +$desc + +$desc +\\bar "|." +} +""" + tpl_left, tpl_right = Template(left), Template(right) + return (tpl_left.substitute(asc=asc, desc=desc), + tpl_right.substitute(asc=asc, desc=desc)) + + +if __name__ == "__main__": + import sys + from string import Template + seeds = sys.argv[1] + with open(seeds) as fh: + for line in fh: + num, seed_asc, seed_desc = line.split("#") + lh, rh = compile_exercise(seed_asc, seed_desc) + with open("rh" + num + ".ily", "w") as fhr: + fhr.write(rh) + with open("lh" + num + ".ily", "w") as fhr: + fhr.write(lh) |
