@@ -11,10 +11,11 @@ def main(): key = "A" bps = 80/60 print bps tempo = 1/bps + max_duration = 1 composition = { "a": { # Movement block 'a' for reuse throughout the piece "melody": { # Instrument 'melody' "csound_parameters": { @@ -112,11 +113,11 @@ for key,value in grammars.iteritems(): if score.find(key) != -1: found_substitution = True while score.find(key) != -1: score = score.replace(key, random.choice(grammars[key]), 1) - if len(score.split()) > 20: + if len(score.split()) > 200: score = score.replace("u", "") score = score.replace("e", "") return score if found_substitution is False: break @@ -136,20 +137,22 @@ } keyed_score = [] for i in range(len(score)): if isinstance(score[i], parse.Note): score[i].value = scale[scale_conversion[score[i].value]-1] - else: + elif isinstance(score[i], parse.Chord): chord = [] root_note_index = scale.index(key) + scale_conversion[score[i].value] chord.append(scale[root_note_index]) if score[i].chord_type == "m": # Minor chords, flat the 3rd chord.append(scale[(root_note_index+2) % 8]) else: chord.append(scale[(root_note_index+3) % 8]) chord.append(scale[(root_note_index+5) % 8]) score[i].chord = chord + elif isinstance(score[i], parse.Rest): + pass return score def generate_csound_score(score): csound_note_values = { @@ -170,12 +173,12 @@ for token in score: if isinstance(token, parse.Chord): # Chords for note in token.chord: note = csound_note_values[note] csound_score.append("i2 %(time)f %(duration)f 7000 %(octave)d.%(note)s %(octave)d.%(note)s 0 6" % {"time": token.time, "octave": random.choice([7,8]), "note": note, "duration": token.duration}) - else: # Individual notes + elif isinstance(token, parse.Note): # Individual notes note = csound_note_values[token.value] csound_score.append("i2 %(time)f %(duration)f 7000 %(octave)d.%(note)s %(octave)d.%(note)s 0 6" % {"time": token.time, "octave": random.choice([8,9]), "note": note, "duration": token.duration}) return csound_score if __name__ == "__main__": main()