-
Notifications
You must be signed in to change notification settings - Fork 53
/
11.ex-lsystem-rhythm.py
executable file
·49 lines (42 loc) · 1.77 KB
/
11.ex-lsystem-rhythm.py
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
#!/usr/bin/env python3
#------------------------------------------------------------------------
# isobar: ex-lsystem-rhythm
#
# Generates a rhythm line based on an L-system sprouting structure,
# sending output over MIDI.
#------------------------------------------------------------------------
from isobar import *
import logging
def main():
#------------------------------------------------------------------------
# Generate a set of pitches based on an l-system, with recursive depth 4.
# symbols:
# N = generate note node
# + = transpose up one semitone
# - = transpose down one semitone
# [ = enter recursive branch
# ] = leave recursive branch
#------------------------------------------------------------------------
notes = PLSystem("N+[+N+N--N+N]+N[++N]", depth=4)
notes = notes + 60
#------------------------------------------------------------------------
# use another l-system to generate time intervals.
# take absolute values so that intervals are always positive.
#------------------------------------------------------------------------
times = PLSystem("[N+[NN]-N+N]+N-N+N", depth=3)
times = PAbs(PDiff(times)) * 0.25
#------------------------------------------------------------------------
# ...and another l-system for amplitudes.
#------------------------------------------------------------------------
velocity = (PLSystem("N+N[++N+N--N]-N[--N+N]") + PWhite(-4, 4)) * 8
velocity = PAbs(velocity)
timeline = Timeline(120)
timeline.schedule({
"note": notes,
"amplitude": velocity,
"duration": times
})
timeline.run()
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO, format="[%(asctime)s] %(message)s")
main()