@@ -1,17 +1,20 @@ #!/usr/bin/env python from __future__ import division import os +import pdb import random import sys import time random.seed(time.time()) import parse import topsort import yaml + +from tree import * def main(): key = "A" bps = 60/60 tempo = 1/bps @@ -19,10 +22,11 @@ composition = yaml.load(open("score.yaml")) max_t = 0 # max time encountered so far. Used for movement timing progression = "chorus" + timeline = {} for movement in progression.split(): for section in ["intro", "core", "outro"]: if section in composition[movement].keys(): try: @@ -30,10 +34,35 @@ except topsort.CycleError as ex: print "Your instruments are synced in a circle! This makes no sense!" print movement, section print ex sys.exit(1) + while None in render_order: + render_order.remove(None) + for instrument in render_order: + grammars = composition[movement][section][instrument]["grammars"] + for grammar in grammars: + if isinstance(grammars[grammar], list): + for option in range(len(grammar)): + grammars[grammar][option] = parse.parse(grammars[grammar][option]) + else: + grammars[grammar] = parse.parse(grammars[grammar]) + print section, movement, instrument + print grammars + for grammar in grammars: + t = Tree() + pdb.set_trace() + while reduce(lambda x, y: x+y, [node.time for node in t.traverse_depth_first()]) < instrument["max_duration"]: + pass + timeline[movement][section][instrument] = Tree() + + +def generate_score_phrase(grammar, grammars): +# count_length = +# while count_length < 100000: + + # for comp_name in progression.split(): # comp_start_time = max_t # for instr_name, instr in composition[comp_name].iteritems():