@@ -1,37 +1,40 @@ #!/usr/bin/env python +from __future__ import division import os import random import sys import time random.seed(time.time()) import parse def main(): key = "A" + bps = 80/60 + print bps + tempo = 1/bps composition = { "a": { # Movement block 'a' for reuse throughout the piece "melody": { # Instrument 'melody' "csound_parameters": { "instrument": 1, }, "grammars": { # Notes for this instrument to use in this piece "u": ["I V V V I I IV u u", "I IV u u", "I VII IV u u" , "e"], -# "u": ["I I I I u u", "e"], "e": [""], }, "score": "u u u u u", }, "rhythm": { "csound_parameters": { "instrument": 1, }, "grammars": { -# "u": ['"I" "ii"/4 "ii"/4 "IV"/2 "V"2 "IV" "I" u u', '"I" "vii" "IV" u u', '"I" "v" "IV" u u', "e"], - "u": ['"i" "I" "ii" "II" "v" "V" u', "e"], + "u": ['"I" "ii"/4 "ii"/4 "IV"/2 "V"2 "IV" "I" u u', '"I" "vii" "IV" u u', '"I" "v" "IV" u u', "e"], +# "u": ['"i" "I" "ii" "II" "v" "V" u', "e"], "e": [""] }, "score": "u u u", }, }, @@ -70,15 +73,17 @@ # Generate timestamps for the notes t = instr_start_time for note in range(len(score)): score[note].time = t +# print "Original duration:", score[note].duration + score[note].duration *= tempo +# print "New duration:", score[note].duration t += score[note].duration +# print "t:", t max_t = t if t > max_t else max_t -# print "end note,", max_t composition[comp_name][instr_name]["score"] = score -# print "end instr,", max_t # Must be done after all note times keyed in, else you can't coordinate melodies with the rhythm chords for comp_name in progression.split(): for instr_name, instr in composition[comp_name].iteritems(): composition[comp_name][instr_name]["score"] = transliterate_score(composition[comp_name][instr_name]["score"], key)