Differences From Artifact [8ccb7c15cbf62012]:
- Executable file
cfg.py
- 2010-11-04 20:07:05 - part of checkin [6bfc2449ff] on branch ply - Generates a score randomly. Too little guarantee of program length (lots of empty or single-phrase strings) (user: spiffytech@gmail.com) [annotate]
To Artifact [73244ab69daa2c1b]:
- Executable file
cfg.py
- 2010-11-12 20:00:57 - part of checkin [338933c1a8] on branch ply - Program now generates a single voice with a I IV V pattern and spits out (among other things) the csound-ified score (user: spiffytech@gmail.com) [annotate]
7 random.seed(time.time()) 7 random.seed(time.time())
8 8
9 grammars = { 9 grammars = {
10 "u": ["I V I IV u", "e"], 10 "u": ["I V I IV u", "e"],
11 "e": [""], 11 "e": [""],
12 } 12 }
13 13
14 score = "u" | 14 # Generate the scale for the key we're in
> 15 comp_key = "C"
> 16 notes = ["A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#"]
> 17 scale = [comp_key]
> 18 pos = notes.index(comp_key)
> 19 progression = [2,2,1,2,2,2,1]
> 20 for p in progression:
> 21 pos = (pos + p) % 12
> 22 scale.append(notes[pos])
15 23
> 24 scale_conversion = {
> 25 "I": 1,
> 26 "II": 2,
> 27 "III": 3,
> 28 "IV": 4,
> 29 "V": 5,
> 30 "VI": 6,
> 31 "VII": 7,
> 32 "VIII": 8,
> 33 }
> 34
> 35 csound_note_values = {
> 36 "C": "00",
> 37 "C#": "01",
> 38 "D": "02",
> 39 "D#": "03",
> 40 "E": "04",
> 41 "F": "05",
> 42 "F#": "06",
> 43 "G": "07",
> 44 "F#": "08",
> 45 "A": "09",
> 46 "A#": "10",
> 47 "B": "11",
> 48 }
> 49
> 50
> 51 score = "u u u"
16 print score 52 print score
17 while 1: 53 while 1:
18 found_substitution = False 54 found_substitution = False
19 for key,value in grammars.iteritems(): 55 for key,value in grammars.iteritems():
20 print "key, value =", key, value <
21 if score.find(key) != -1: 56 if score.find(key) != -1:
22 print "here" <
23 found_substitution = True 57 found_substitution = True
24 while score.find(key) != -1: 58 while score.find(key) != -1:
25 score = score.replace(key, random.choice(grammars[key]), 1) 59 score = score.replace(key, random.choice(grammars[key]), 1)
26 print score 60 print score
27 time.sleep(.25) | 61 # time.sleep(.25)
28 if found_substitution is False: 62 if found_substitution is False:
29 break 63 break
> 64
> 65 csound_score = []
> 66 for token in score.split():
> 67 csound_score.append(scale[scale_conversion[token]-1])
> 68
30 print score | 69 print csound_score
> 70
> 71 t = 0
> 72 for token in csound_score:
> 73 note = csound_note_values[token]
> 74 print "i2 %f 2 7000 %d.%s %d.%s 0 6" % (t, random.choice([8,9]), note, rando
> 75 t += .25