-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogressions.py
More file actions
74 lines (54 loc) · 1.21 KB
/
progressions.py
File metadata and controls
74 lines (54 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import random
from mingus.core import progressions
from mingus.containers import NoteContainer, Note, Track
from mingus.extra import lilypond
TITLE = "Randomations No. 16"
KEY = "A"
LENGTH = 64
I = "I"
II = "II"
III = "III"
IV = "IV"
V = "V"
VI = "VI"
VIIdim7 = "VIIdim7"
progression_map = {
I: [I, II, III, IV, V, VI, VIIdim7],
II: [V, VIIdim7],
III: [IV, VI],
IV: [I, II, V, VIIdim7],
V: [I, VI],
VI: [II, IV, V],
VIIdim7: [I],
}
def random_progression(next_val=III):
rand = random.Random(TITLE)
while True:
yield next_val
next_val = rand.choice(progression_map[next_val])
progression = [n for n, _ in zip(random_progression(), range(LENGTH + 1))]
chords = progressions.to_chords(progression, KEY)
ncs = [NoteContainer([Note(note) for note in chord]) for chord in chords]
track = Track()
for nc in ncs:
track.add_notes(nc, duration=4)
lily_template = """
\\version "2.18.0"
\\header {{
title = "{title}"
composer = "bgr's Python script"
}}
prog = {notes}
\\score {{
\\new Staff {{
\\time 4/4
\\prog
}}
\\layout {{}}
\\midi {{}}
}}
""".strip()
print(lily_template.format(
title=TITLE,
notes=lilypond.from_Track(track)
))