spiffyscore
Check-in [872ae93059]
Not logged in
Overview
SHA1 Hash:872ae930598cac24eced9515f360579eee52d6e2
Date: 2011-11-16 00:14:47
User: brian
Comment:If I move from csound to midi I should actually rename function with 'csound' in the name
Timelines: family | ancestors | descendants | both | develop
Other Links: files | file ages | manifest
Tags And Properties
Changes
hide diffs unified diffs patch

Execute permission cleared for parse.py

Modified spiffyscore.py from [caa7e9ffa774c2cf] to [5ac9fc32526a68ed].

15 import tree 15 import tree 16 16 17 random.seed(time.time()) 17 random.seed(time.time()) 18 mymidi = midifile(15) 18 mymidi = midifile(15) 19 19 20 def main(): 20 def main(): 21 composition = { 21 composition = { 22 "fm_test": { < 23 "intro": { | 22 "intro": { 24 "melody": { # Instrument 'melody' < 25 "score_line": "i2 %(time)f %(duration)f 7000 %(octave)d.%(no < 26 "octave": 8, < 27 "duration": 10, < 28 "grammars": { # Notes for this instrument to use in this pi < 29 "u": ["G/2 G/2 | G/4 G/4 A/4 A/4 | A/2 A/2 | G | G | A | < 30 "w": ["E | E | F | F | G/2 G/2 | G3 (u)"], < 31 }, < 32 }, < 33 }, < 34 }, < 35 "verse1": { < 36 "intro": { < 37 "melody": { # Instrument 'melody' < 38 "score_line": "i2 %(time)f %(duration)f 7000 %(octave)d.%(no < 39 "octave": 8, < 40 "duration": 10, < 41 "grammars": { # Notes for this instrument to use in this pi < 42 "u": ["G/2 G/2 | G/4 G/4 A/4 A/4 | A/2 A/2 | G | G | A | < 43 "w": ["E | E | F | F | G/2 G/2 | G3 (u)"], < 44 }, < 45 }, < 46 }, < 47 "body": { 23 "body": { 48 "melody": { # Instrument 'melody' < 49 "score_line": "i2 %(time)f %(duration)f 7000 %(octave)d.%(no < 50 "octave": 8, < 51 "duration": 10, < 52 "grammars": { # Notes for this instrument to use in this pi < 53 "u": ["C | G/2 G/2 | G/2 G/2 | C | B, | F' | C | F | C | < 54 "w": ["E/4 A/4 D/4 G/4 | F/4 F/4 B2 | (u)"], < 55 }, < 56 }, < 57 }, < 58 "outro": { < 59 "melody": { # Instrument 'melody' < 60 "score_line": "i2 %(time)f %(duration)f 7000 %(octave)d.%(no < 61 "octave": 8, < 62 "duration": 10, < 63 "grammars": { # Notes for this instrument to use in this pi < 64 "u": ["C/4 C/4 C/4 C/4 | z2"], < 65 }, < 66 }, < 67 }, < 68 }, < 69 "verse2": { < 70 "body": { < 71 "melody": { # Instrument 'melody' < 72 "score_line": "i2 %(time)f %(duration)f 7000 %(octave)d.%(no < 73 "octave": 8, < 74 "duration": 30, < 75 "grammars": { # Notes for this instrument to use in this pi < 76 "u": ["C | C | C | C | F/2 F/2 | F/2 F/2 | (u)", "D | D < 77 }, < 78 }, < 79 "harmony": { # Instrument 'melody' < 80 "score_line": "i3 %(time)f %(duration)f 4000 %(octave)d.%(no < 81 "octave": 8, < 82 "duration": 30, < 83 "grammars": { # Notes for this instrument to use in this pi < 84 "u": ["C | C | z | C | C | z/2 F/4 F/2 F/2 | F/2 F/2 | z < 85 }, < 86 }, < 87 "percussion": { # Instrument 'melody' < 88 "score_line": "i1 %(time)f %(duration)f 7000 %(octave)d.%(no < 89 "octave": 8, < 90 "duration": 30, < 91 "grammars": { # Notes for this instrument to use in this pi < 92 "u": ["C/4 C/4 C/4 C/4 | F/2 F/2 | F/2 F/2 | (u)", "D/4 < 93 "v": ["C | D | E | F | E | D | C | (u)",], < 94 }, < 95 }, < 96 }, < 97 "outro": { < 98 "percussion": { # Instrument 'melody' < 99 "score_line": "i1 %(time)f %(duration)f 7000 %(octave)d.%(no < 100 "octave": 8, < 101 "duration": 30, < 102 "grammars": { # Notes for this instrument to use in this pi < 103 "u": ["C/4 C/4 C/4 C/4"], < 104 }, < 105 }, < 106 }, < 107 }, < 108 "sync_test": { < 109 "body": { < 110 "lead_instr": { # Instrument 'melody' 24 "lead_instr": { # Instrument 'melody' 111 "channel": 6, 25 "channel": 6, 112 "octave": 4, 26 "octave": 4, 113 "duration": 30, 27 "duration": 30, 114 "grammars": { # Notes for this instrument to use in this pi 28 "grammars": { # Notes for this instrument to use in this pi 115 # "u": ["A ^A B C ^C D ^D E F ^F G ^G"], < 116 "u": ["A/2, B/2, C/2 D/2 (u)", "D/2' D/2' D/2' D/2' (x)" | 29 "u": ["A/2, B/2, C/2 D/2 (u)", "D2' D2' D2' D2' (x)"], 117 "v": ["C/2 C/2 C/2 C/2 (w)"], 30 "v": ["C/2 C/2 C/2 C/2 (w)"], 118 "w": ["E/2 F/2 E/2 F/2 (u)"], 31 "w": ["E/2 F/2 E/2 F/2 (u)"], 119 "x": ["z4 (v)"], 32 "x": ["z4 (v)"], 120 }, 33 }, 121 }, 34 }, 122 "follow_instr": { # Instrument 'melody' | 35 "follow_instr": { # Instrument 'bass' 123 "channel": 0, | 36 "channel": 4, 124 "sync": "lead_instr", 37 "sync": "lead_instr", 125 "octave": 2, 38 "octave": 2, 126 "duration": 30, 39 "duration": 30, 127 "grammars": { # Notes for this instrument to use in this pi 40 "grammars": { # Notes for this instrument to use in this pi 128 # "u": ["A ^A B C ^C D ^D E F ^F G ^G"], < 129 "u": ["E F G E (v)"], 41 "u": ["E F G E (v)"], 130 "v": ["G A A A (e)", "G A A A (v)"], 42 "v": ["G A A A (e)", "G A A A (v)"], 131 "e": ["B A G A (u)"], 43 "e": ["B A G A (u)"], 132 "x": ["z4 (e)"], 44 "x": ["z4 (e)"], 133 }, 45 }, 134 }, 46 }, 135 # "instr2": { # Instrument 'melody' < 136 # "score_line": "i1 %(time)f %(duration)f 7000 %(octave)d.%(n < 137 # "score_line": "i1 %(time)f %(duration)f 7000 %(octave)d.%(n < 138 # "octave": 5, < 139 # "duration": 30, < 140 # "grammars": { # Notes for this instrument to use in this p < 141 ## "u": ["A ^A B C ^C D ^D E F ^F G ^G"], < 142 # "u": ["A/2, B/2, C/2 D/2 (u)", "D/2' D/2' D/2' D/2' (v) < 143 # "v": ["C/2 C/2 C/2 C/2 (w)"], < 144 # "w": ["E/2 F/2 E/2 F/2 (u)"], < 145 # }, < 146 # }, < 147 }, 47 }, 148 }, 48 }, 149 } 49 } 150 print '''f1 0 512 10 1 50 print '''f1 0 512 10 1 151 f2 0 8192 10 .24 .64 .88 .76 .06 .5 .34 .08 51 f2 0 8192 10 .24 .64 .88 .76 .06 .5 .34 .08 152 f3 0 1025 10 1 52 f3 0 1025 10 1 153 t 0 60 53 t 0 60 154 ''' 54 ''' 155 55 156 section_start = 0 56 section_start = 0 157 # for section in ["verse1", "verse2"]: < 158 for section in ["sync_test"]: | 57 for section in ["intro"]: 159 print "; Section " + section 58 print "; Section " + section 160 subsection_start = section_start 59 subsection_start = section_start 161 section = composition[section] 60 section = composition[section] 162 for subsection in ["intro", "body", "outro"]: 61 for subsection in ["intro", "body", "outro"]: 163 try: 62 try: 164 print "; Subsection " + subsection 63 print "; Subsection " + subsection 165 subsection = section[subsection] 64 subsection = section[subsection] ................................................................................................................................................................................ 178 track = 0 77 track = 0 179 for instr in ordered_instrs: 78 for instr in ordered_instrs: 180 print ";Instrument " + instr 79 print ";Instrument " + instr 181 instr = subsection[instr] 80 instr = subsection[instr] 182 max_time = instr["duration"] 81 max_time = instr["duration"] 183 instr_score, syncs = render_instr(instr, syncs, max_time) 82 instr_score, syncs = render_instr(instr, syncs, max_time) 184 instrs.append(instr_score) 83 instrs.append(instr_score) 185 generate_csound_score(instr_score, track, instr["channel"], | 84 midify_instr_score(instr_score, track, instr["channel"], sub 186 longest_score = max(instrs, key=lambda i: score_len(i)) 85 longest_score = max(instrs, key=lambda i: score_len(i)) 187 subsection_start += score_len(longest_score) 86 subsection_start += score_len(longest_score) 188 section_start += score_len(longest_score) 87 section_start += score_len(longest_score) 189 track += 1 88 track += 1 190 except KeyError: 89 except KeyError: 191 pass 90 pass 192 with open("out.mid", "wb") as outfile: 91 with open("out.mid", "wb") as outfile: ................................................................................................................................................................................ 276 return total 175 return total 277 176 278 177 279 def get_midi_note(octave, note): 178 def get_midi_note(octave, note): 280 return note + 12 * (octave+1) 179 return note + 12 * (octave+1) 281 180 282 181 283 def generate_csound_score(score, track, channel, t): | 182 def midify_instr_score(score, track, channel, t): 284 # Assume get_midi_note() 183 # Assume get_midi_note() 285 global mymidi 184 global mymidi 286 185 287 for token in score: 186 for token in score: 288 if isinstance(token, parse.Chord): # Chords 187 if isinstance(token, parse.Chord): # Chords 289 for note in token.chord: 188 for note in token.chord: 290 note = get_midi_note(token.octave, note) 189 note = get_midi_note(token.octave, note)