spiffyscore
Diff
Not logged in

Differences From Artifact [f043e9a7854c719d]:

To Artifact [f7b2188978509418]:


1 #!/usr/bin/env python 1 #!/usr/bin/env python 2 2 > 3 from __future__ import division 3 import os 4 import os 4 import random 5 import random 5 import sys 6 import sys 6 import time 7 import time 7 random.seed(time.time()) 8 random.seed(time.time()) 8 import parse 9 import parse 9 10 10 def main(): 11 def main(): 11 key = "A" 12 key = "A" > 13 bps = 80/60 > 14 print bps > 15 tempo = 1/bps 12 16 13 composition = { 17 composition = { 14 "a": { # Movement block 'a' for reuse throughout the piece 18 "a": { # Movement block 'a' for reuse throughout the piece 15 "melody": { # Instrument 'melody' 19 "melody": { # Instrument 'melody' 16 "csound_parameters": { 20 "csound_parameters": { 17 "instrument": 1, 21 "instrument": 1, 18 }, 22 }, 19 "grammars": { # Notes for this instrument to use in this piece 23 "grammars": { # Notes for this instrument to use in this piece 20 "u": ["I V V V I I IV u u", "I IV u u", "I VII IV u u" , "e 24 "u": ["I V V V I I IV u u", "I IV u u", "I VII IV u u" , "e 21 # "u": ["I I I I u u", "e"], < 22 "e": [""], 25 "e": [""], 23 }, 26 }, 24 "score": "u u u u u", 27 "score": "u u u u u", 25 }, 28 }, 26 "rhythm": { 29 "rhythm": { 27 "csound_parameters": { 30 "csound_parameters": { 28 "instrument": 1, 31 "instrument": 1, 29 }, 32 }, 30 "grammars": { 33 "grammars": { 31 # "u": ['"I" "ii"/4 "ii"/4 "IV"/2 "V"2 "IV" "I" u u', '"I" "v | 34 "u": ['"I" "ii"/4 "ii"/4 "IV"/2 "V"2 "IV" "I" u u', '"I" "vi 32 "u": ['"i" "I" "ii" "II" "v" "V" u', "e"], | 35 # "u": ['"i" "I" "ii" "II" "v" "V" u', "e"], 33 "e": [""] 36 "e": [""] 34 }, 37 }, 35 "score": "u u u", 38 "score": "u u u", 36 }, 39 }, 37 }, 40 }, 38 "b": { 41 "b": { 39 "melody": { # Instrument 'melody' 42 "melody": { # Instrument 'melody' ................................................................................................................................................................................ 68 generated_score = generate_score(instr["score"], instr["grammars"]) 71 generated_score = generate_score(instr["score"], instr["grammars"]) 69 score = parse.parse(generated_score) # Return Node/Chord objects 72 score = parse.parse(generated_score) # Return Node/Chord objects 70 73 71 # Generate timestamps for the notes 74 # Generate timestamps for the notes 72 t = instr_start_time 75 t = instr_start_time 73 for note in range(len(score)): 76 for note in range(len(score)): 74 score[note].time = t 77 score[note].time = t > 78 # print "Original duration:", score[note].duration > 79 score[note].duration *= tempo > 80 # print "New duration:", score[note].duration 75 t += score[note].duration 81 t += score[note].duration > 82 # print "t:", t 76 max_t = t if t > max_t else max_t 83 max_t = t if t > max_t else max_t 77 # print "end note,", max_t < 78 composition[comp_name][instr_name]["score"] = score 84 composition[comp_name][instr_name]["score"] = score 79 # print "end instr,", max_t < 80 85 81 # Must be done after all note times keyed in, else you can't coordinate melo 86 # Must be done after all note times keyed in, else you can't coordinate melo 82 for comp_name in progression.split(): 87 for comp_name in progression.split(): 83 for instr_name, instr in composition[comp_name].iteritems(): 88 for instr_name, instr in composition[comp_name].iteritems(): 84 composition[comp_name][instr_name]["score"] = transliterate_score(co 89 composition[comp_name][instr_name]["score"] = transliterate_score(co 85 # print "\nMovement %s instrument %s" % (comp_name, instr_name) 90 # print "\nMovement %s instrument %s" % (comp_name, instr_name) 86 # print composition[comp_name][instr_name]["score"] 91 # print composition[comp_name][instr_name]["score"]