spiffyscore
Diff
Not logged in

Differences From Artifact [172b01d6f65b871d]:

To Artifact [2306af4935eb1f3c]:


6 import sys 6 import sys 7 import time 7 import time 8 random.seed(time.time()) 8 random.seed(time.time()) 9 import parse 9 import parse 10 10 11 def main(): 11 def main(): 12 key = "A" 12 key = "A" 13 bps = 80/60 | 13 bps = 60/60 14 print bps < 15 tempo = 1/bps 14 tempo = 1/bps 16 max_duration = 1 15 max_duration = 1 17 16 18 composition = { 17 composition = { 19 "a": { # Movement block 'a' for reuse throughout the piece 18 "a": { # Movement block 'a' for reuse throughout the piece 20 "melody": { # Instrument 'melody' | 19 "bassline": { # Instrument 'melody' 21 "score_line": "i2 %(time)f %(duration)f 7000 %(octave)d.%(note)s | 20 "score_line": "i1 %(time)f %(duration)f 10000 %(octave)d.%(note) > 21 "octave": 6, 22 "grammars": { # Notes for this instrument to use in this piece 22 "grammars": { # Notes for this instrument to use in this piece 23 "u": ["I V V V I I IV u u", "I IV u u", "I VII IV u u" , "e < > 23 "u": ["I,/2 z/2 I,/2 z/2 I,/2 z/2 V,/2 z/2 u u", "e"], 24 "e": [""], 24 "e": [""], 25 }, 25 }, 26 "score": "u u u u u", 26 "score": "u u u u u", 27 }, 27 }, 28 "rhythm": { < 29 "score_line": "i2 %(time)f %(duration)f 7000 %(octave)d.%(note)s < 30 "grammars": { < 31 "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"], < 33 "e": [""] < 34 }, < 35 "score": "u u u", < 36 }, < 37 }, < 38 "b": { < 39 "melody": { # Instrument 'melody' < 40 "score_line": "i2 %(time)f %(duration)f 7000 %(octave)d.%(note)s < 41 "grammars": { # Notes for this instrument to use in this piece < 42 "u": ["I V I I/2 IV/2 u u", "I2 IV u u", "I IV IV VI V u u" < 43 "e": [""], < 44 }, < 45 "score": "u u u", < 46 }, < 47 "rhythm": { < 48 "score_line": "i2 %(time)f %(duration)f 7000 %(octave)d.%(note)s < 49 "grammars": { < 50 "u": ['"I" "IV"/2 "V"2 "IV" "I" u u', '"I" "VII" "IV" u u', < 51 "e": [""] < 52 }, < 53 "score": "u u u", < 54 }, < 55 }, 28 }, 56 } 29 } 57 30 58 max_t = 0 # max time encountered so far. Used for movement timing 31 max_t = 0 # max time encountered so far. Used for movement timing 59 progression = "a b" | 32 progression = "a" 60 for comp_name in progression.split(): 33 for comp_name in progression.split(): 61 instr_start_time = max_t 34 instr_start_time = max_t 62 for instr_name, instr in composition[comp_name].iteritems(): 35 for instr_name, instr in composition[comp_name].iteritems(): 63 generated_score = generate_score(instr["score"], instr["grammars"]) 36 generated_score = generate_score(instr["score"], instr["grammars"]) 64 score = parse.parse(generated_score) # Return Node/Chord objects | 37 score = parse.parse(generated_score, default_octave=instr["octave"]) 65 38 66 # Generate timestamps for the notes 39 # Generate timestamps for the notes 67 t = instr_start_time 40 t = instr_start_time 68 for note in range(len(score)): 41 for note in range(len(score)): 69 score[note].time = t 42 score[note].time = t 70 score[note].duration *= tempo 43 score[note].duration *= tempo 71 t += score[note].duration 44 t += score[note].duration 72 max_t = t if t > max_t else max_t 45 max_t = t if t > max_t else max_t 73 composition[comp_name][instr_name]["score"] = score 46 composition[comp_name][instr_name]["score"] = score 74 47 75 # Must be done after all note times keyed in, else you can't coordinate melo 48 # Must be done after all note times keyed in, else you can't coordinate melo 76 print "f1 0 256 10 1 0 3 ; sine wave function table" | 49 print "f1 0 512 10 1" > 50 # print "f1 0 513 9 1 1 0 3 .33 180 5 .2 0 7 .143 180 9 .111 0" > 51 # print "f2 0 8192 10 .24 .64 .88 .76 ,96 .5 .24 .08" 77 for comp_name in progression.split(): 52 for comp_name in progression.split(): 78 for instr_name, instr in composition[comp_name].iteritems(): 53 for instr_name, instr in composition[comp_name].iteritems(): 79 composition[comp_name][instr_name]["score"] = transliterate_score(co 54 composition[comp_name][instr_name]["score"] = transliterate_score(co 80 # print "\nMovement %s instrument %s" % (comp_name, instr_name) 55 # print "\nMovement %s instrument %s" % (comp_name, instr_name) 81 # print composition[comp_name][instr_name]["score"] 56 # print composition[comp_name][instr_name]["score"] 82 final_score = generate_csound_score(composition[comp_name][instr_nam 57 final_score = generate_csound_score(composition[comp_name][instr_nam 83 for line in final_score: 58 for line in final_score: ................................................................................................................................................................................ 162 if isinstance(token, parse.Chord): # Chords 137 if isinstance(token, parse.Chord): # Chords 163 for note in token.chord: 138 for note in token.chord: 164 note = csound_note_values[note] 139 note = csound_note_values[note] 165 # csound_score.append("i2 %(time)f %(duration)f 7000 %(octave)d.% 140 # csound_score.append("i2 %(time)f %(duration)f 7000 %(octave)d.% 166 csound_score.append(score_line % {"time": token.time, "octave": 141 csound_score.append(score_line % {"time": token.time, "octave": 167 elif isinstance(token, parse.Note): # Individual notes 142 elif isinstance(token, parse.Note): # Individual notes 168 note = csound_note_values[token.value] 143 note = csound_note_values[token.value] 169 csound_score.append(score_line % {"time": token.time, "octave": rand | 144 csound_score.append(score_line % {"time": token.time, "octave": toke 170 # csound_score.append("i2 %(time)f %(duration)f 7000 %(octave)d.%(not 145 # csound_score.append("i2 %(time)f %(duration)f 7000 %(octave)d.%(not 171 return csound_score 146 return csound_score 172 147 173 148 174 if __name__ == "__main__": main() 149 if __name__ == "__main__": main()