-
Notifications
You must be signed in to change notification settings - Fork 53
/
04.ex-permutations.py
executable file
·67 lines (59 loc) · 2.23 KB
/
04.ex-permutations.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python3
#------------------------------------------------------------------------
# isobar: ex-permutations
#
# PPermut generates every possible permutation of a sequence:
# [1, 2, 3] -> [1, 2, 3, 1, 3, 2, 2, 1, 3, 2, 3, 1, 3, 1, 2, 3, 2, 1]
#
# Use simple permutations to generate intertwining musical structures.
#------------------------------------------------------------------------
from isobar import *
import random
import logging
def main():
#------------------------------------------------------------------------
# Create a pitch line comprised of multiple permutations on
# a pentatonic scale
#------------------------------------------------------------------------
ppitch = PShuffle([random.randint(-6, 6) for _ in range(6)])
ppitch = PPermut(ppitch)
ppitch = PDegree(ppitch, Key("C", "majorPenta"))
#------------------------------------------------------------------------
# Create permuted sets of durations and amplitudes.
# Different lengths mean poly-combinations.
#------------------------------------------------------------------------
pdur = PShuffle([1, 1, 2, 2, 4], 1)
pdur = PPermut(pdur) / 4
pamp = PShuffle([10, 15, 20, 35], 2)
pamp = PPermut(pamp)
#------------------------------------------------------------------------
# Schedule on a 60bpm timeline and send to MIDI output
#------------------------------------------------------------------------
timeline = Timeline(60)
timeline.schedule({
"note": ppitch + 60,
"duration": pdur,
"amplitude": pamp,
"channel": 0
})
timeline.schedule({
"note": ppitch + 24,
"duration": pdur * 4,
"amplitude": pamp,
"channel": 1,
"gate": 2
})
timeline.schedule({
"note": ppitch + 72,
"duration": pdur / 2,
"channel": 1,
"gate": 1,
"amplitude": pamp / 2
})
#------------------------------------------------------------------------
# Begin playback
#------------------------------------------------------------------------
timeline.run()
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO, format="[%(asctime)s] %(message)s")
main()