Differences From Artifact [3046d9915bac52e1]:
- Executable file
cfg.py
- 2010-11-29 07:15:15 - part of checkin [4ab39b23ec] on branch master - Chords now respect octaves (user: spiffytech@gmail.com) [annotate]
To Artifact [2e13b2eb76a2ba5a]:
- Executable file
cfg.py
- 2010-11-30 06:22:23 - part of checkin [de7c009e4d] on branch master - Added a timbre instrument, doubled the length of the piece, added intros and outro (user: spiffytech@gmail.com) [annotate]
11 def main(): 11 def main():
12 key = "A" 12 key = "A"
13 bps = 60/60 13 bps = 60/60
14 tempo = 1/bps 14 tempo = 1/bps
15 max_duration = 1 15 max_duration = 1
16 16
17 composition = { 17 composition = {
> 18 "intro1": {
> 19 "rhythm": {
> 20 "score_line": "i1 %(time)f %(duration)f 7000 %(octave)d.%(note)s
> 21 "octave": 7,
> 22 "duration": 4,
> 23 "grammars": {
> 24 "u": ['"I" "ii"/4 "ii"/4 "IV"/2 "V"2 "IV" "ii" x u', '"I" "v
> 25 "w": ['"i" "VII"2 "VI"/4 "V"/4 "i"/4 "VII"2 "VI" "V" w u'],
> 26 "x": ['"III/2" "VI"/2 "III"/2 "vii"2 "i"2 "V" u'],
> 27 "y": ['"I" "vi"2 "IV" "V" y y u'],
> 28 },
> 29 "score": "u x u y x w u",
> 30 },
> 31 },
> 32 "intro2": {
> 33 "rhythm": {
> 34 "score_line": "i1 %(time)f %(duration)f 7000 %(octave)d.%(note)s
> 35 "octave": 7,
> 36 "duration": 6,
> 37 "grammars": {
> 38 "u": ['"I" "ii"/4 "ii"/4 "IV"/2 "V"2 "IV" "ii" x u', '"I" "v
> 39 "w": ['"i" "VII"2 "VI"/4 "V"/4 "i"/4 "VII"2 "VI" "V" w u'],
> 40 "x": ['"III/2" "VI"/2 "III"/2 "vii"2 "i"2 "V" u'],
> 41 "y": ['"I" "vi"2 "IV" "V" y y u'],
> 42 },
> 43 "score": "u x u y x w u",
> 44 },
> 45 "timbre": {
> 46 "score_line": "i3 %(time)f %(duration)f 2000 %(octave)d.%(note)s
> 47 "octave": 6,
> 48 "duration": 6,
> 49 "grammars": { # Notes for this instrument to use in this piece
> 50 "u": ['I2 VII2 V2 VI2 I2 IV/2 V/2 III2 u', 'I2 IV2 V2 IV I V
> 51 },
> 52 "score": "u u u u u",
> 53 },
> 54 },
18 "a": { # Movement block 'a' for reuse throughout the piece 55 "a": { # Movement block 'a' for reuse throughout the piece
19 # "melody": { # Instrument 'melody' | 56 "melody": { # Instrument 'melody'
20 # "score_line": "i2 %(time)f %(duration)f 7000 %(octave)d.%(note) | 57 "score_line": "i2 %(time)f %(duration)f 7000 %(octave)d.%(note)s
21 # "octave": 8, | 58 "octave": 8,
22 # "duration": 40, | 59 "duration": 40,
23 # "grammars": { # Notes for this instrument to use in this piece | 60 "grammars": { # Notes for this instrument to use in this piece
24 # "u": ["I V/2 V/2 V/2 I VII, IV' x u", "I IV w w", "I VII IV | 61 "u": ["I V/2 V/2 V/2 I VII, IV' x u", "I IV w w", "I VII IV
25 # "w": ['VII I IV V VI u', 'w w'], | 62 "w": ['VII I IV V VI VII I IV V VI VII u', 'x'],
26 # "x": ['VI/4 III/4 II/4 I/4 w', 'x x'], | 63 "x": ['VI/4 III/4 II/4 I/4 w', 'x x'],
27 # }, <
> 64 },
28 # "score": "u", | 65 "score": "u",
29 # }, <
> 66 },
30 # "rhythm": { | 67 "rhythm": {
31 # "score_line": "i1 %(time)f %(duration)f 7000 %(octave)d.%(note) | 68 "score_line": "i1 %(time)f %(duration)f 7000 %(octave)d.%(note)s
32 # "octave": 7, | 69 "octave": 7,
33 # "duration": 50, | 70 "duration": 48,
34 # "grammars": { | 71 "grammars": {
35 # "u": ['"I" "ii"/4 "ii"/4 "IV"/2 "V"2 "IV" "ii" x u', '"I" " | 72 "u": ['"I" "ii"/4 "ii"/4 "IV"/2 "V"2 "IV" "ii" x u', '"I" "v
36 # "w": ['"i" "VII"2 "VI"/4 "V"/4 "i"/4 "VII"2 "VI" "V" w u'], | 73 "w": ['"i" "VII"2 "VI"/4 "V"/4 "i"/4 "VII"2 "VI" "V" w u'],
37 # "x": ['"III/2" "VI"/2 "III"/2 "vii"2 "i"2 "V" u'], | 74 "x": ['"III/2" "VI"/2 "III"/2 "vii"2 "i"2 "V" u'],
38 # "y": ['"I" "vi"2 "IV" "V" y y u'], | 75 "y": ['"I" "vi"2 "IV" "V" y y u'],
39 # }, <
> 76 },
40 # "score": "u x u y x w u", | 77 "score": "u x u y x w u",
41 # }, <
> 78 },
42 "timbre": { 79 "timbre": {
43 "score_line": "i3 %(time)f %(duration)f 5000 %(octave)d.%(note)s | 80 "score_line": "i3 %(time)f %(duration)f 2000 %(octave)d.%(note)s
44 "octave": 5, | 81 "octave": 6,
45 "duration": 40, | 82 "duration": 42,
46 "grammars": { # Notes for this instrument to use in this piece 83 "grammars": { # Notes for this instrument to use in this piece
47 "u": ['I2 I2 V VI I/2 IV/2 "V"2 "I"2'] <
> 84 "u": ['I2 VII2 V2 VI2 I2 IV/2 V/2 III2 u', 'I2 IV2 V2 IV I V
48 }, 85 },
49 "score": "u u u u u", 86 "score": "u u u u u",
50 }, 87 },
51 }, 88 },
52 "b": { # Movement block 'a' for reuse throughout the piece 89 "b": { # Movement block 'a' for reuse throughout the piece
53 "melody": { # Instrument 'melody' 90 "melody": { # Instrument 'melody'
54 "score_line": "i2 %(time)f %(duration)f 7000 %(octave)d.%(note)s 91 "score_line": "i2 %(time)f %(duration)f 7000 %(octave)d.%(note)s
55 "octave": 8, 92 "octave": 8,
56 "duration": 20, | 93 "duration": 40,
57 "grammars": { # Notes for this instrument to use in this piece 94 "grammars": { # Notes for this instrument to use in this piece
58 "u": ['I VII V III u', "y"], 95 "u": ['I VII V III u', "y"],
59 "w": ['VII I IV V VI u', 'w w'], | 96 "w": ['VII I IV V VI u', 'w'],
60 "x": ['VI/4 III/4 II/4 I/4 w', 'x x'], 97 "x": ['VI/4 III/4 II/4 I/4 w', 'x x'],
61 "y": ["III/4 VI/4 II/4 V/4 VI/4 IV/4 VII2"], 98 "y": ["III/4 VI/4 II/4 V/4 VI/4 IV/4 VII2"],
62 }, 99 },
63 "score": "w w x x w", 100 "score": "w w x x w",
64 }, 101 },
65 "rhythm": { 102 "rhythm": {
66 "score_line": "i1 %(time)f %(duration)f 7000 %(octave)d.%(note)s 103 "score_line": "i1 %(time)f %(duration)f 7000 %(octave)d.%(note)s
67 "octave": 7, 104 "octave": 7,
68 "duration": 24, | 105 "duration": 44,
69 "grammars": { 106 "grammars": {
70 "u": ['"I" "V" "vi" "iii" "IV" "I" "IV" "V" u u', "y"], 107 "u": ['"I" "V" "vi" "iii" "IV" "I" "IV" "V" u u', "y"],
71 "y": ['"I" "vi"2 "IV" "V" y y u'], 108 "y": ['"I" "vi"2 "IV" "V" y y u'],
72 }, 109 },
73 "score": "u u y y u", 110 "score": "u u y y u",
74 }, 111 },
> 112 "timbre": {
> 113 "score_line": "i3 %(time)f %(duration)f 2000 %(octave)d.%(note)s
> 114 "octave": 6,
> 115 "duration": 40,
> 116 "grammars": { # Notes for this instrument to use in this piece
> 117 "u": ['I2 VII2 V2 VI2 I2 IV/2 V/2 III2 u', 'I2 IV2 V2 IV I V
75 }, | 118 },
> 119 "score": "u u u u u",
> 120 },
> 121 },
76 "c": { # Movement block 'a' for reuse throughout the piece | 122 "zelda1": { # Movement block 'a' for reuse throughout the piece
77 "melody": { # Instrument 'melody' 123 "melody": { # Instrument 'melody'
78 "score_line": "i2 %(time)f %(duration)f 7000 %(octave)d.%(note)s 124 "score_line": "i2 %(time)f %(duration)f 7000 %(octave)d.%(note)s
79 "octave": 8, 125 "octave": 8,
> 126 "duration": 40,
> 127 "grammars": { # Notes for this instrument to use in this piece
> 128 "u": ['I VI/2 VI/2 IV/2 u', "y"],
> 129 "w": ['VII/2 I/2 II/2 V/2 u', 'w w', 'u w'],
> 130 "x": ['VI/4 III/4 II/4 I/4 w', 'x x', 'x u'],
> 131 "y": ["III/4 VI/4 II/4 V/4 VI/4 IV/4 VII2", 'y y'],
> 132 },
> 133 "score": "w x w",
> 134 },
> 135 "rhythm": {
> 136 "score_line": "i1 %(time)f %(duration)f 7000 %(octave)d.%(note)s
> 137 "octave": 7,
> 138 "duration": 40,
> 139 "grammars": {
> 140 "u": ['"I"/2 "V"/2 "vi"/2 "iii"/2 "IV"/2 "I"/2 "IV"/2 "V"/2
> 141 "y": ['"I"/2 "vi" "IV"/2 "V"/2 y y u'],
> 142 },
> 143 "score": "u u y y u",
> 144 },
> 145 "timbre": {
> 146 "score_line": "i3 %(time)f %(duration)f 2000 %(octave)d.%(note)s
> 147 "octave": 6,
> 148 "duration": 40,
> 149 "grammars": { # Notes for this instrument to use in this piece
> 150 "u": ['I2 VII2 V2 VI2 I2 IV/2 V/2 III2 u', 'I2 IV2 V2 IV I V
> 151 },
> 152 "score": "u u u u u",
> 153 },
> 154 },
> 155 "zelda2": { # Movement block 'a' for reuse throughout the piece
> 156 "melody": { # Instrument 'melody'
> 157 "score_line": "i2 %(time)f %(duration)f 7000 %(octave)d.%(note)s
> 158 "octave": 8,
> 159 "duration": 40,
> 160 "grammars": { # Notes for this instrument to use in this piece
> 161 "u": ['I/2 I/2 VI IV/2 V2 z I/2 I/2 VI IV/2 V u', "w"],
> 162 "w": ['III/2 II/2 IV/2 III/2 V/2 IV/2 VI/2 V/2 w', 'u', 'x']
> 163 "x": ['VII3 z2 V/4 IV/4 V/4 IV/4 V/4 VI/4 II/4 II/4 II/4 u',
> 164 },
> 165 "score": "u",
> 166 },
> 167 "rhythm": {
> 168 "score_line": "i1 %(time)f %(duration)f 7000 %(octave)d.%(note)s
> 169 "octave": 7,
> 170 "duration": 40,
> 171 "grammars": {
> 172 "u": ['"I"/2 "V"/2 "vi"/2 "iii"/2 "IV"/2 "I"/2 "IV"/2 "V"/2
> 173 "y": ['"I"/2 "vi" "IV"/2 "V"/2 y y u'],
> 174 },
> 175 "score": "u u y y u",
> 176 },
> 177 "timbre": {
> 178 "score_line": "i3 %(time)f %(duration)f 2000 %(octave)d.%(note)s
> 179 "octave": 6,
> 180 "duration": 40,
> 181 "grammars": { # Notes for this instrument to use in this piece
> 182 "u": ['I2 VII2 V2 VI2 I2 IV/2 V/2 III2 u', 'I2 IV2 V2 IV I V
> 183 },
> 184 "score": "u u u u u",
> 185 },
> 186 },
> 187 "d": { # Movement block 'a' for reuse throughout the piece
> 188 "rhythm": {
> 189 "score_line": "i1 %(time)f %(duration)f 7000 %(octave)d.%(note)s
> 190 "octave": 7,
80 "duration": 20, 191 "duration": 20,
> 192 "grammars": {
> 193 "u": ['"I"/2 "V"/2 "vi"/2 "iii"/2 "IV"/2 "I"/2 "IV"/2 "V"/2
> 194 "y": ['"I"/2 "vi" "IV"/2 "V"/2 y y u'],
> 195 },
> 196 "score": "u u y y u",
> 197 },
> 198 "timbre": {
> 199 "score_line": "i3 %(time)f %(duration)f 2000 %(octave)d.%(note)s
> 200 "octave": 6,
> 201 "duration": 20,
81 "grammars": { # Notes for this instrument to use in this piece 202 "grammars": { # Notes for this instrument to use in this piece
82 "u": ['I VI/2 VI/2 IV/2 u', "y"], 203 "u": ['I VI/2 VI/2 IV/2 u', "y"],
83 "w": ['VII/2 I/2 II/2 V/2 u', 'w w'], | 204 "w": ['VII/2 I/2 II/2 V/2 u', 'w w', 'u w'],
84 "x": ['VI/4 III/4 II/4 I/4 w', 'x x'], | 205 "x": ['VI/4 III/4 II/4 I/4 w', 'x x', 'x u'],
85 "y": ["III/4 VI/4 II/4 V/4 VI/4 IV/4 VII2"], | 206 "y": ["III/4 VI/4 II/4 V/4 VI/4 IV/4 VII2", 'y y'],
86 }, 207 },
87 "score": "w w x x w", | 208 "score": "w x w",
88 }, 209 },
> 210 },
> 211 "e": { # Movement block 'a' for reuse throughout the piece
89 "rhythm": { 212 "rhythm": {
90 "score_line": "i1 %(time)f %(duration)f 7000 %(octave)d.%(note)s 213 "score_line": "i1 %(time)f %(duration)f 7000 %(octave)d.%(note)s
91 "octave": 7, 214 "octave": 7,
92 "duration": 20, 215 "duration": 20,
93 "grammars": { 216 "grammars": {
94 "u": ['"I"/2 "V"/2 "vi"/2 "iii"/2 "IV"/2 "I"/2 "IV"/2 "V"/2 217 "u": ['"I"/2 "V"/2 "vi"/2 "iii"/2 "IV"/2 "I"/2 "IV"/2 "V"/2
95 "y": ['"I"/2 "vi" "IV"/2 "V"/2 y y u'], 218 "y": ['"I"/2 "vi" "IV"/2 "V"/2 y y u'],
96 }, 219 },
97 "score": "u u y y u", 220 "score": "u u y y u",
98 }, 221 },
> 222 "timbre": {
> 223 "score_line": "i3 %(time)f %(duration)f 2000 %(octave)d.%(note)s
> 224 "octave": 6,
> 225 "duration": 20,
> 226 "grammars": { # Notes for this instrument to use in this piece
> 227 "u": ['I2 VII2 V2 VI2 I2 IV/2 V/2 III2 u', 'I2 IV2 V2 IV I V
> 228 "w": ['I/2 VII/4 IV/4 VI/2 V w', ''],
99 }, | 229 },
> 230 "score": "u w u",
> 231 },
> 232 },
100 "d": { # Movement block 'a' for reuse throughout the piece | 233 "outro": { # Movement block 'a' for reuse throughout the piece
101 "melody": { # Instrument 'melody' 234 "melody": { # Instrument 'melody'
102 "score_line": "i2 %(time)f %(duration)f 7000 %(octave)d.%(note)s 235 "score_line": "i2 %(time)f %(duration)f 7000 %(octave)d.%(note)s
103 "octave": 8, 236 "octave": 8,
104 "duration": 20, 237 "duration": 20,
105 "grammars": { # Notes for this instrument to use in this piece 238 "grammars": { # Notes for this instrument to use in this piece
106 "u": ['I VII V III u', "y"], 239 "u": ['I VII V III u', "y"],
107 "w": ['VII I IV V VI u', 'w w'], 240 "w": ['VII I IV V VI u', 'w w'],
................................................................................................................................................................................
109 "y": ["III/4 VI/4 II/4 V/4 VI/4 IV/4 VII2"], 242 "y": ["III/4 VI/4 II/4 V/4 VI/4 IV/4 VII2"],
110 }, 243 },
111 "score": "w w x x w", 244 "score": "w w x x w",
112 }, 245 },
113 "rhythm": { 246 "rhythm": {
114 "score_line": "i1 %(time)f %(duration)f 7000 %(octave)d.%(note)s 247 "score_line": "i1 %(time)f %(duration)f 7000 %(octave)d.%(note)s
115 "octave": 7, 248 "octave": 7,
116 "duration": 24, | 249 "duration": 26,
117 "grammars": { 250 "grammars": {
118 "u": ['"I" "V" "vi" "iii" "IV" "I" "IV" "V" u u', "y"], 251 "u": ['"I" "V" "vi" "iii" "IV" "I" "IV" "V" u u', "y"],
119 "y": ['"I" "vi"2 "IV" "V" y y u'], 252 "y": ['"I" "vi"2 "IV" "V" y y u'],
120 }, 253 },
121 "score": "u u y y u", 254 "score": "u u y y u",
122 }, 255 },
> 256 "timbre": {
> 257 "score_line": "i3 %(time)f %(duration)f 2000 %(octave)d.%(note)s
> 258 "octave": 6,
> 259 "duration": 30,
> 260 "grammars": { # Notes for this instrument to use in this piece
> 261 "u": ['I2 VII2 V2 VI2 I2 IV/2 V/2 III2 u', 'I2 IV2 V2 IV I V
> 262 },
> 263 "score": "u u u u u",
> 264 },
123 }, 265 },
124 } 266 }
125 267
126 max_t = 0 # max time encountered so far. Used for movement timing 268 max_t = 0 # max time encountered so far. Used for movement timing
> 269 progression = "intro1 intro2 a b zelda1 zelda2 d e outro"
127 progression = "a b c d" | 270 # progression = "zelda2"
128 for comp_name in progression.split(): 271 for comp_name in progression.split():
129 comp_start_time = max_t 272 comp_start_time = max_t
130 for instr_name, instr in composition[comp_name].iteritems(): 273 for instr_name, instr in composition[comp_name].iteritems():
131 generated_score = generate_score(instr["score"], instr["grammars"]) 274 generated_score = generate_score(instr["score"], instr["grammars"])
132 # print generated_score 275 # print generated_score
133 score = parse.parse(generated_score, default_octave=instr["octave"]) 276 score = parse.parse(generated_score, default_octave=instr["octave"])
134 277