Differences From Artifact [08a2f25157508e9a]:
- Executable file
cfg.py
- 2010-11-17 07:30:34 - part of checkin [aa88358397] on branch tld - Added support for rest notes (user: spiffytech@gmail.com) [annotate]
To Artifact [d40635785f8653ee]:
- Executable file
cfg.py
- 2010-11-17 07:42:51 - part of checkin [b8d35587a4] on branch master - csound score lines are no longer hardcoded, but are stored with each instrument (user: spiffytech@gmail.com) [annotate]
14 print bps 14 print bps
15 tempo = 1/bps 15 tempo = 1/bps
16 max_duration = 1 16 max_duration = 1
17 17
18 composition = { 18 composition = {
19 "a": { # Movement block 'a' for reuse throughout the piece 19 "a": { # Movement block 'a' for reuse throughout the piece
20 "melody": { # Instrument 'melody' 20 "melody": { # Instrument 'melody'
21 "csound_parameters": { | 21 "score_line": "i2 %(time)f %(duration)f 7000 %(octave)d.%(note)s
22 "instrument": 1, <
23 }, <
24 "grammars": { # Notes for this instrument to use in this piece 22 "grammars": { # Notes for this instrument to use in this piece
25 "u": ["I V V V I I IV u u", "I IV u u", "I VII IV u u" , "e 23 "u": ["I V V V I I IV u u", "I IV u u", "I VII IV u u" , "e
26 "e": [""], 24 "e": [""],
27 }, 25 },
28 "score": "u u u u u", 26 "score": "u u u u u",
29 }, 27 },
30 "rhythm": { 28 "rhythm": {
31 "csound_parameters": { | 29 "score_line": "i2 %(time)f %(duration)f 7000 %(octave)d.%(note)s
32 "instrument": 1, <
33 }, <
34 "grammars": { 30 "grammars": {
35 "u": ['"I" "ii"/4 "ii"/4 "IV"/2 "V"2 "IV" "I" u u', '"I" "vi 31 "u": ['"I" "ii"/4 "ii"/4 "IV"/2 "V"2 "IV" "I" u u', '"I" "vi
36 # "u": ['"i" "I" "ii" "II" "v" "V" u', "e"], 32 # "u": ['"i" "I" "ii" "II" "v" "V" u', "e"],
37 "e": [""] 33 "e": [""]
38 }, 34 },
39 "score": "u u u", 35 "score": "u u u",
40 }, 36 },
41 }, 37 },
42 "b": { 38 "b": {
43 "melody": { # Instrument 'melody' 39 "melody": { # Instrument 'melody'
44 "csound_parameters": { | 40 "score_line": "i2 %(time)f %(duration)f 7000 %(octave)d.%(note)s
45 "instrument": 1, <
46 }, <
47 "grammars": { # Notes for this instrument to use in this piece 41 "grammars": { # Notes for this instrument to use in this piece
48 "u": ["I V I I/2 IV/2 u u", "I2 IV u u", "I IV IV VI V u u" 42 "u": ["I V I I/2 IV/2 u u", "I2 IV u u", "I IV IV VI V u u"
49 # "u": ["I IV I V u u u", "e"], <
50 "e": [""], 43 "e": [""],
51 }, 44 },
52 "score": "u u u", 45 "score": "u u u",
53 }, 46 },
54 "rhythm": { 47 "rhythm": {
55 "csound_parameters": { | 48 "score_line": "i2 %(time)f %(duration)f 7000 %(octave)d.%(note)s
56 "instrument": 1, <
57 }, <
58 "grammars": { 49 "grammars": {
59 "u": ['"I" "IV"/2 "V"2 "IV" "I" u u', '"I" "VII" "IV" u u', 50 "u": ['"I" "IV"/2 "V"2 "IV" "I" u u', '"I" "VII" "IV" u u',
60 "e": [""] 51 "e": [""]
61 }, 52 },
62 "score": "u u u", 53 "score": "u u u",
63 }, 54 },
64 }, 55 },
................................................................................................................................................................................
72 generated_score = generate_score(instr["score"], instr["grammars"]) 63 generated_score = generate_score(instr["score"], instr["grammars"])
73 score = parse.parse(generated_score) # Return Node/Chord objects 64 score = parse.parse(generated_score) # Return Node/Chord objects
74 65
75 # Generate timestamps for the notes 66 # Generate timestamps for the notes
76 t = instr_start_time 67 t = instr_start_time
77 for note in range(len(score)): 68 for note in range(len(score)):
78 score[note].time = t 69 score[note].time = t
79 # print "Original duration:", score[note].duration <
80 score[note].duration *= tempo 70 score[note].duration *= tempo
81 # print "New duration:", score[note].duration <
82 t += score[note].duration 71 t += score[note].duration
83 # print "t:", t <
84 max_t = t if t > max_t else max_t 72 max_t = t if t > max_t else max_t
85 composition[comp_name][instr_name]["score"] = score 73 composition[comp_name][instr_name]["score"] = score
86 74
87 # Must be done after all note times keyed in, else you can't coordinate melo 75 # Must be done after all note times keyed in, else you can't coordinate melo
88 for comp_name in progression.split(): 76 for comp_name in progression.split():
89 for instr_name, instr in composition[comp_name].iteritems(): 77 for instr_name, instr in composition[comp_name].iteritems():
90 composition[comp_name][instr_name]["score"] = transliterate_score(co 78 composition[comp_name][instr_name]["score"] = transliterate_score(co
91 # print "\nMovement %s instrument %s" % (comp_name, instr_name) 79 # print "\nMovement %s instrument %s" % (comp_name, instr_name)
92 # print composition[comp_name][instr_name]["score"] 80 # print composition[comp_name][instr_name]["score"]
93 print "f1 0 256 10 1 0 3 ; sine wave function table" 81 print "f1 0 256 10 1 0 3 ; sine wave function table"
94 final_score = generate_csound_score(composition[comp_name][instr_nam | 82 final_score = generate_csound_score(composition[comp_name][instr_nam
95 for line in final_score: 83 for line in final_score:
96 print line 84 print line
97 85
98 86
99 def make_scale(key): 87 def make_scale(key):
100 notes = ["A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#"] 88 notes = ["A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#"]
101 scale = [key] 89 scale = [key]
................................................................................................................................................................................
150 chord.append(scale[(root_note_index+5) % 8]) 138 chord.append(scale[(root_note_index+5) % 8])
151 score[i].chord = chord 139 score[i].chord = chord
152 elif isinstance(score[i], parse.Rest): 140 elif isinstance(score[i], parse.Rest):
153 pass 141 pass
154 return score 142 return score
155 143
156 144
157 def generate_csound_score(score): | 145 def generate_csound_score(score, score_line):
158 csound_note_values = { 146 csound_note_values = {
159 "C": "00", 147 "C": "00",
160 "C#": "01", 148 "C#": "01",
161 "D": "02", 149 "D": "02",
162 "D#": "03", 150 "D#": "03",
163 "E": "04", 151 "E": "04",
164 "F": "05", 152 "F": "05",
................................................................................................................................................................................
170 "B": "11", 158 "B": "11",
171 } 159 }
172 csound_score = [] 160 csound_score = []
173 for token in score: 161 for token in score:
174 if isinstance(token, parse.Chord): # Chords 162 if isinstance(token, parse.Chord): # Chords
175 for note in token.chord: 163 for note in token.chord:
176 note = csound_note_values[note] 164 note = csound_note_values[note]
177 csound_score.append("i2 %(time)f %(duration)f 7000 %(octave)d.%( | 165 # csound_score.append("i2 %(time)f %(duration)f 7000 %(octave)d.%
> 166 csound_score.append(score_line % {"time": token.time, "octave":
178 elif isinstance(token, parse.Note): # Individual notes 167 elif isinstance(token, parse.Note): # Individual notes
179 note = csound_note_values[token.value] 168 note = csound_note_values[token.value]
> 169 csound_score.append(score_line % {"time": token.time, "octave": rand
180 csound_score.append("i2 %(time)f %(duration)f 7000 %(octave)d.%(note | 170 # csound_score.append("i2 %(time)f %(duration)f 7000 %(octave)d.%(not
181 return csound_score 171 return csound_score
182 172
183 173
184 if __name__ == "__main__": main() 174 if __name__ == "__main__": main()