spiffyscore
Diff
Not logged in

Differences From Artifact [79cec58b407b1335]:

To Artifact [f043e9a7854c719d]:


8 import parse 8 import parse 9 9 10 def main(): 10 def main(): 11 key = "A" 11 key = "A" 12 12 13 composition = { 13 composition = { 14 "a": { # Movement block 'a' for reuse throughout the piece 14 "a": { # Movement block 'a' for reuse throughout the piece 15 # "melody": { # Instrument 'melody' | 15 "melody": { # Instrument 'melody' 16 # "csound_parameters": { | 16 "csound_parameters": { 17 # "instrument": 1, | 17 "instrument": 1, 18 # }, | 18 }, 19 # "grammars": { # Notes for this instrument to use in this piece | 19 "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" , " | 20 "u": ["I V V V I I IV u u", "I IV u u", "I VII IV u u" , "e 21 # "e": [""], | 21 # "u": ["I I I I u u", "e"], 22 # }, | 22 "e": [""], > 23 }, 23 # "score": "u u u", | 24 "score": "u u u u u", 24 # }, < > 25 }, 25 "rhythm": { 26 "rhythm": { 26 "csound_parameters": { 27 "csound_parameters": { 27 "instrument": 1, 28 "instrument": 1, 28 }, 29 }, 29 "grammars": { 30 "grammars": { 30 # "u": ['"I" "ii"/4 "ii"/4 "IV"/2 "V"2 "IV" "I" u u', '"I" "v 31 # "u": ['"I" "ii"/4 "ii"/4 "IV"/2 "V"2 "IV" "I" u u', '"I" "v 31 "u": ['"i" "I" "ii" "II" "v" "V" u', "e"], 32 "u": ['"i" "I" "ii" "II" "v" "V" u', "e"], 32 "e": [""] 33 "e": [""] 33 }, 34 }, 34 "score": "u u u", 35 "score": "u u u", 35 }, 36 }, 36 }, 37 }, 37 # "b": { | 38 "b": { 38 # "melody": { # Instrument 'melody' | 39 "melody": { # Instrument 'melody' 39 # "csound_parameters": { | 40 "csound_parameters": { 40 # "instrument": 1, | 41 "instrument": 1, 41 # }, | 42 }, 42 # "grammars": { # Notes for this instrument to use in this piece | 43 "grammars": { # Notes for this instrument to use in this piece 43 # "u": ["I V I I/2 IV/2 u u", "I4 IV u u", "I IV IV VI V u u" | 44 "u": ["I V I I/2 IV/2 u u", "I2 IV u u", "I IV IV VI V u u" 44 # "e": [""], | 45 # "u": ["I IV I V u u u", "e"], 45 # }, | 46 "e": [""], > 47 }, 46 # "score": "u u u", | 48 "score": "u u u", 47 # }, < > 49 }, 48 # "rhythm": { | 50 "rhythm": { 49 # "csound_parameters": { | 51 "csound_parameters": { 50 # "instrument": 1, | 52 "instrument": 1, 51 # }, < > 53 }, 52 # "grammars": { | 54 "grammars": { 53 # "u": ['"I" "IV"/2 "V"2 "IV" "I" u u', '"I" "VII" "IV" u u', | 55 "u": ['"I" "IV"/2 "V"2 "IV" "I" u u', '"I" "VII" "IV" u u', 54 # "e": [""] | 56 "e": [""] 55 # }, < > 57 }, 56 # "score": "u u u", | 58 "score": "u u u", 57 # }, < 58 # }, | 59 }, 59 } | 60 }, 60 | 61 } 61 for comp_name, comp in composition.iteritems(): < > 62 > 63 max_t = 0 # max time encountered so far. Used for movement timing > 64 progression = "a b" > 65 for comp_name in progression.split(): > 66 instr_start_time = max_t 62 for instr_name, instr in comp.iteritems(): | 67 for instr_name, instr in composition[comp_name].iteritems(): 63 generated_score = generate_score(instr["score"], instr["grammars"]) 68 generated_score = generate_score(instr["score"], instr["grammars"]) 64 # composition[comp_name][instr_name][grammar]["score"] = parse.pa < 65 score = parse.parse(generated_score) # Return Node/Chord objects 69 score = parse.parse(generated_score) # Return Node/Chord objects 66 70 67 # Generate timestamps for the notes 71 # Generate timestamps for the notes 68 t = 0 | 72 t = instr_start_time 69 for note in range(len(score)): 73 for note in range(len(score)): 70 score[note].time = t 74 score[note].time = t 71 t += score[note].duration 75 t += score[note].duration > 76 max_t = t if t > max_t else max_t > 77 # print "end note,", max_t 72 composition[comp_name][instr_name]["score"] = score 78 composition[comp_name][instr_name]["score"] = score > 79 # print "end instr,", max_t 73 80 74 # Must be done after all note times keyed in, else you c,an't coordinate mel | 81 # Must be done after all note times keyed in, else you can't coordinate melo 75 for comp_name, comp in composition.iteritems(): < > 82 for comp_name in progression.split(): 76 for instr_name, instr in comp.iteritems(): | 83 for instr_name, instr in composition[comp_name].iteritems(): 77 composition[comp_name][instr_name]["score"] = transliterate_score(co 84 composition[comp_name][instr_name]["score"] = transliterate_score(co 78 # print "\nMovement %s instrument %s" % (comp_name, instr_name) 85 # print "\nMovement %s instrument %s" % (comp_name, instr_name) 79 # print composition[comp_name][instr_name]["score"] 86 # print composition[comp_name][instr_name]["score"] 80 print "f1 0 256 10 1 0 3 ; sine wave function table" 87 print "f1 0 256 10 1 0 3 ; sine wave function table" 81 final_score = generate_csound_score(composition[comp_name][instr_nam 88 final_score = generate_csound_score(composition[comp_name][instr_nam 82 for line in final_score: 89 for line in final_score: 83 print line 90 print line ................................................................................................................................................................................ 98 while 1: 105 while 1: 99 found_substitution = False 106 found_substitution = False 100 for key,value in grammars.iteritems(): 107 for key,value in grammars.iteritems(): 101 if score.find(key) != -1: 108 if score.find(key) != -1: 102 found_substitution = True 109 found_substitution = True 103 while score.find(key) != -1: 110 while score.find(key) != -1: 104 score = score.replace(key, random.choice(grammars[key]), 1) 111 score = score.replace(key, random.choice(grammars[key]), 1) 105 if len(score.split()) > 200: | 112 if len(score.split()) > 20: 106 score = score.replace("u", "") 113 score = score.replace("u", "") 107 score = score.replace("e", "") 114 score = score.replace("e", "") 108 return score 115 return score 109 if found_substitution is False: 116 if found_substitution is False: 110 break 117 break 111 return score 118 return score 112 119 ................................................................................................................................................................................ 150 "F#": "06", 157 "F#": "06", 151 "G": "07", 158 "G": "07", 152 "G#": "08", 159 "G#": "08", 153 "A": "09", 160 "A": "09", 154 "A#": "10", 161 "A#": "10", 155 "B": "11", 162 "B": "11", 156 } 163 } 157 t = 0 < 158 csound_score = [] 164 csound_score = [] 159 for token in score: 165 for token in score: 160 if isinstance(token, parse.Chord): # Chords 166 if isinstance(token, parse.Chord): # Chords 161 for note in token.chord: 167 for note in token.chord: 162 note = csound_note_values[note] 168 note = csound_note_values[note] 163 csound_score.append("i2 %(time)f 1 7000 %(octave)d.%(note)s %(oc | 169 csound_score.append("i2 %(time)f %(duration)f 7000 %(octave)d.%( 164 t += 1 < 165 else: # Individual notes 170 else: # Individual notes 166 note = csound_note_values[token.value] 171 note = csound_note_values[token.value] 167 csound_score.append("i2 %(time)f 1 7000 %(octave)d.%(note)s %(octave | 172 csound_score.append("i2 %(time)f %(duration)f 7000 %(octave)d.%(note 168 t += .25 < 169 return csound_score 173 return csound_score 170 174 171 175 172 if __name__ == "__main__": main() 176 if __name__ == "__main__": main()