-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample-01.py
More file actions
47 lines (34 loc) · 1.35 KB
/
example-01.py
File metadata and controls
47 lines (34 loc) · 1.35 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
from musical.theory import Note, Scale, Chord
from musical.audio import playback
from timeline import Hit, Timeline
# Define key and scale
key = Note('D3')
scale = Scale(key, 'minor')
# Grab progression chords from scale starting at the octave of our key
progression = Chord.progression(scale, base_octave=key.octave)
time = 0.0 # Keep track of currect note placement time in seconds
timeline = Timeline()
# Add progression to timeline by arpeggiating chords from the progression
for index in [0, 2, 3, 1, 0, 2, 3, 4, 5, 4, 0]:
chord = progression[index]
root, third, fifth = chord.notes
arpeggio = [root, third, fifth, third, root, third, fifth, third]
for i, interval in enumerate(arpeggio):
ts = float(i * 2) / len(arpeggio)
timeline.add(time + ts, Hit(interval, 1.0))
time += 2.0
# Strum out root chord to finish
chord = progression[0]
timeline.add(time + 0.0, Hit(chord.notes[0], 4.0))
timeline.add(time + 0.1, Hit(chord.notes[1], 4.0))
timeline.add(time + 0.2, Hit(chord.notes[2], 4.0))
timeline.add(time + 0.3, Hit(chord.notes[1].transpose(12), 4.0))
timeline.add(time + 0.4, Hit(chord.notes[2].transpose(12), 4.0))
timeline.add(time + 0.5, Hit(chord.notes[0].transpose(12), 4.0))
print "Rendering audio..."
data = timeline.render()
# Reduce volume to 25%
data = data * 0.25
print "Playing audio..."
playback.play(data)
print "Done!"