Differences From Artifact [82bf7ad059c0226a]:
- Executable file
cfg.py
- 2011-02-10 22:34:39 - part of checkin [702d933446] on branch master - Added lexical support for parens instead of quotes for chords, cleaned up the yacc parser, added lex tokens for syncopation (user: brian@linux-85dd.site) [annotate]
To Artifact [e9b556b4f37a3fa9]:
- Executable file
cfg.py
- 2011-02-10 23:50:20 - part of checkin [689adc054e] on branch master - Program generates a render order for the instruments based on their sync order (user: brian@linux-85dd.site) [annotate]
2 2
3 from __future__ import division 3 from __future__ import division
4 import os 4 import os
5 import random 5 import random
6 import sys 6 import sys
7 import time 7 import time
8 random.seed(time.time()) 8 random.seed(time.time())
> 9
9 import parse 10 import parse
> 11 import topsort
> 12 import yaml
10 13
11 def main(): 14 def main():
12 key = "A" 15 key = "A"
13 bps = 60/60 16 bps = 60/60
14 tempo = 1/bps 17 tempo = 1/bps
15 max_duration = 1 18 max_duration = 1
16 19
17 composition = { | 20 composition = yaml.load(open("score.yaml"))
18 "overview": { <
> 21
19 "melody": { # Instrument 'melody' | 22 max_t = 0 # max time encountered so far. Used for movement timing
20 "score_line": "i2 %(time)f %(duration)f 7000 %(octave)d.%(note)s | 23 progression = "chorus"
21 "octave": 8, <
> 24
22 "duration": 40, | 25 for movement in progression.split():
23 "grammars": { # Notes for this instrument to use in this piece | 26 for section in ["intro", "core", "outro"]:
24 "u": ["I V/2 V/2 V/2 I VII, IV' I IV I VII IV"], | 27 if section in composition[movement].keys():
25 }, <
> 28 try:
26 "score": "u", | 29 render_order = topsort.topsort([[composition[movement][secti
27 }, <
> 30 except topsort.CycleError as ex:
28 "rhythm": { | 31 print "Your instruments are synced in a circle! This makes n
29 "score_line": "i1 %(time)f %(duration)f 7000 %(octave)d.%(note)s | 32 print movement, section
30 "octave": 7, | 33 print ex
31 "duration": 44, | 34 sys.exit(1)
32 "grammars": { <
33 "u": ['(I) (ii)/4 (ii)/4 (IV)/2 (V)2 (IV) (ii) u', '(I) (vii <
34 }, <
35 "score": "u", <
36 }, <
37 }, <
38 } | 35
39 36
40 max_t = 0 # max time encountered so far. Used for movement timing <
41 progression = "overview" <
42 for comp_name in progression.split(): | 37 # for comp_name in progression.split():
43 comp_start_time = max_t | 38 # comp_start_time = max_t
44 for instr_name, instr in composition[comp_name].iteritems(): | 39 # for instr_name, instr in composition[comp_name].iteritems():
45 generated_score = generate_score(instr["score"], instr["grammars"]) | 40 # generated_score = generate_score(instr["score"], instr["grammars"])
46 # print generated_score | 41 ## print generated_score
47 score = parse.parse(generated_score, default_octave=instr["octave"]) | 42 # score = parse.parse(generated_score, default_octave=instr["octave"]
48 | 43 #
49 # Generate timestamps for the notes | 44 # # Generate timestamps for the notes
50 t = comp_start_time | 45 # t = comp_start_time
51 for note in range(len(score)): | 46 # for note in range(len(score)):
52 score[note].time = t | 47 # score[note].time = t
53 score[note].duration *= tempo | 48 # score[note].duration *= tempo
54 t += score[note].duration | 49 # t += score[note].duration
55 # print "time difference =", t-comp_start_time | 50 ## print "time difference =", t-comp_start_time
56 # print "instrument duration =",composition[comp_name][instr_name | 51 ## print "instrument duration =",composition[comp_name][instr_nam
57 if (t-comp_start_time) > float(composition[comp_name][instr_name | 52 # if (t-comp_start_time) > float(composition[comp_name][instr_nam
58 # print "here" | 53 ## print "here"
59 score = score[:note] | 54 # score = score[:note]
60 break <
> 55 # break
61 max_t = t if t > max_t else max_t | 56 # max_t = t if t > max_t else max_t
62 composition[comp_name][instr_name]["score"] = score | 57 # composition[comp_name][instr_name]["score"] = score
63 58
64 # Must be done after all note times keyed in, else you can't coordinate melo 59 # Must be done after all note times keyed in, else you can't coordinate melo
65 print '''f1 0 512 10 1 60 print '''f1 0 512 10 1
66 f2 0 8192 10 .24 .64 .88 .76 .06 .5 .34 .08 61 f2 0 8192 10 .24 .64 .88 .76 .06 .5 .34 .08
67 f3 0 1025 10 1 62 f3 0 1025 10 1
68 ''' 63 '''
69 for comp_name in progression.split(): 64 for comp_name in progression.split():