Skip to content

Commit bd45040

Browse files
committed
Tidy up examples
1 parent 93a98af commit bd45040

19 files changed

+580
-543
lines changed

examples/00.ex-hello-world.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,21 @@
77
# Make sure you have a MIDI device connected.
88
#------------------------------------------------------------------------
99

10-
import isobar as iso
11-
10+
from isobar import *
1211
import logging
13-
logging.basicConfig(level=logging.INFO, format="[%(asctime)s] %(message)s")
1412

15-
series = iso.PRange(60, 73, 1)
16-
timeline = iso.Timeline(120)
13+
def main():
14+
series = PRange(60, 73, 1)
15+
timeline = Timeline(120)
16+
17+
timeline.schedule({
18+
"note": series,
19+
"duration": 1
20+
})
21+
22+
timeline.run()
1723

18-
timeline.schedule({
19-
"note": series,
20-
"duration": 1
21-
})
2224

23-
timeline.run()
25+
if __name__ == "__main__":
26+
logging.basicConfig(level=logging.INFO, format="[%(asctime)s] %(message)s")
27+
main()

examples/01.ex-basics.py

Lines changed: 53 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -7,61 +7,60 @@
77
# sequences, scales, stochastic functions, scheduling and mapping.
88
#------------------------------------------------------------------------
99

10-
import isobar as iso
11-
12-
#------------------------------------------------------------------------
13-
# Turn on some basic logging output.
14-
#------------------------------------------------------------------------
10+
from isobar import *
1511
import logging
16-
logging.basicConfig(level=logging.INFO, format="[%(asctime)s] %(message)s")
17-
18-
#------------------------------------------------------------------------
19-
# Create a geometric series on a minor scale.
20-
# PingPong plays the series forward then backward. PLoop loops forever.
21-
#------------------------------------------------------------------------
22-
arpeggio = iso.PSeries(0, 2, 6)
23-
arpeggio = iso.PDegree(arpeggio, iso.Scale.minor) + 72
24-
arpeggio = iso.PPingPong(arpeggio)
25-
arpeggio = iso.PLoop(arpeggio)
26-
27-
#------------------------------------------------------------------------
28-
# Create a velocity sequence, with emphasis every 4th note,
29-
# plus a random walk to create gradual dynamic changes.
30-
# Amplitudes are in the MIDI velocity range (0..127).
31-
#------------------------------------------------------------------------
32-
amplitude = iso.PSequence([50, 35, 25, 35]) + iso.PBrown(0, 1, -20, 20)
33-
34-
#------------------------------------------------------------------------
35-
# Create a repeating sequence with scalar transposition:
36-
# [ 36, 38, 43, 39, 36, 38, 43, 39, ... ]
37-
#------------------------------------------------------------------------
38-
bassline = iso.PSequence([0, 2, 7, 3]) + 36
39-
40-
#------------------------------------------------------------------------
41-
# Repeat each note 3 times, and transpose each into a different octave
42-
# [ 36, 48, 60, 38, 50, 62, ... ]
43-
#------------------------------------------------------------------------
44-
bassline = iso.PStutter(bassline, 3) + iso.PSequence([0, 12, 24])
4512

46-
#------------------------------------------------------------------------
47-
# A Timeline schedules events at a specified tempo. By default, events
48-
# are send to the system's default MIDI output.
49-
#------------------------------------------------------------------------
50-
output = iso.MidiOutputDevice()
51-
52-
timeline = iso.Timeline(120, output)
13+
def main():
14+
#------------------------------------------------------------------------
15+
# Create a geometric series on a minor scale.
16+
# PingPong plays the series forward then backward. PLoop loops forever.
17+
#------------------------------------------------------------------------
18+
arpeggio = PSeries(0, 2, 6)
19+
arpeggio = PDegree(arpeggio, Scale.minor) + 72
20+
arpeggio = PPingPong(arpeggio)
21+
arpeggio = PLoop(arpeggio)
22+
23+
#------------------------------------------------------------------------
24+
# Create a velocity sequence, with emphasis every 4th note,
25+
# plus a random walk to create gradual dynamic changes.
26+
# Amplitudes are in the MIDI velocity range (0..127).
27+
#------------------------------------------------------------------------
28+
amplitude = PSequence([50, 35, 25, 35]) + PBrown(0, 1, -20, 20)
29+
30+
#------------------------------------------------------------------------
31+
# Create a repeating sequence with scalar transposition:
32+
# [ 36, 38, 43, 39, 36, 38, 43, 39, ... ]
33+
#------------------------------------------------------------------------
34+
bassline = PSequence([0, 2, 7, 3]) + 36
35+
36+
#------------------------------------------------------------------------
37+
# Repeat each note 3 times, and transpose each into a different octave
38+
# [ 36, 48, 60, 38, 50, 62, ... ]
39+
#------------------------------------------------------------------------
40+
bassline = PStutter(bassline, 3) + PSequence([0, 12, 24])
41+
42+
#------------------------------------------------------------------------
43+
# A Timeline schedules events at a specified tempo. By default, events
44+
# are send to the system's default MIDI output.
45+
#------------------------------------------------------------------------
46+
timeline = Timeline(120)
47+
48+
#------------------------------------------------------------------------
49+
# Schedule events, with properties generated by the Pattern objects.
50+
#------------------------------------------------------------------------
51+
timeline.schedule({
52+
"note": arpeggio,
53+
"duration": 0.25,
54+
"amplitude": amplitude
55+
})
56+
timeline.schedule({
57+
"note": bassline,
58+
"duration": 1
59+
})
60+
61+
timeline.run()
5362

54-
#------------------------------------------------------------------------
55-
# Schedule events, with properties generated by the Pattern objects.
56-
#------------------------------------------------------------------------
57-
timeline.schedule({
58-
"note": arpeggio,
59-
"duration": 0.25,
60-
"amplitude": amplitude
61-
})
62-
timeline.schedule({
63-
"note": bassline,
64-
"duration": 1
65-
})
6663

67-
timeline.run()
64+
if __name__ == "__main__":
65+
logging.basicConfig(level=logging.INFO, format="[%(asctime)s] %(message)s")
66+
main()

examples/02.ex-subsequence.py

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,48 @@
44
# isobar: ex-subsequence
55
#------------------------------------------------------------------------
66

7-
import isobar as iso
8-
7+
from isobar import *
98
import logging
10-
logging.basicConfig(level=logging.DEBUG, format="[%(asctime)s] %(message)s")
11-
12-
scale = iso.Scale.pelog
13-
sequence = iso.PDegree(iso.PBrown(0, 3, -12, 12), scale)
14-
15-
offset = iso.PStutter(iso.pattern.PWhite(0, 4), 2)
16-
sequence = iso.PSubsequence(sequence, offset, 4)
17-
sequence = iso.PPermut(sequence)
18-
sequence = sequence + 64
19-
sequence = iso.PReset(sequence, iso.PImpulse(24))
20-
21-
amp = iso.pattern.PSequence([45, 35, 25, 40]) + iso.PBrown(0, 1, -15, 10)
22-
23-
gate = iso.pattern.PBrown(1.5, 0.01, 0.6, 2.5)
24-
25-
timeline = iso.Timeline(120)
26-
timeline.schedule({
27-
"note": sequence.copy(),
28-
"amplitude": amp.copy(),
29-
"duration": 0.25,
30-
"gate": gate.copy()
31-
})
32-
timeline.schedule({
33-
"note": sequence.copy() + 24,
34-
"amplitude": amp.copy(),
35-
"duration": 0.5,
36-
"gate": gate.copy()
37-
})
38-
timeline.schedule({
39-
"note": sequence.copy() - 24,
40-
"amplitude": 10 + amp.copy() * 0.5,
41-
"duration": iso.PChoice([4, 4, 6, 8]),
42-
"gate": gate.copy()
43-
})
44-
45-
timeline.run()
9+
10+
def main():
11+
scale = Scale.pelog
12+
degree = PBrown(0, 3, -12, 12)
13+
sequence = PDegree(degree, scale)
14+
15+
offset = PStutter(PWhite(0, 16), 4)
16+
sequence = PSubsequence(sequence, offset, 4)
17+
sequence = PPermut(sequence)
18+
sequence = PReset(sequence, PImpulse(12))
19+
20+
amp = PSequence([45, 35, 25, 40]) + PBrown(0, 1, -20, 20)
21+
22+
gate = PBrown(1.5, 0.01, 0.6, 2.5)
23+
24+
timeline = Timeline(120)
25+
timeline.schedule({
26+
"note": sequence,
27+
"amplitude": amp.copy(),
28+
"duration": 0.25,
29+
"gate": gate.copy(),
30+
"transpose": 60
31+
})
32+
timeline.schedule({
33+
"note": sequence.copy() + 24,
34+
"amplitude": amp.copy(),
35+
"duration": 0.5,
36+
"gate": gate.copy(),
37+
"transpose": 60
38+
})
39+
timeline.schedule({
40+
"note": sequence.copy() - 24,
41+
"amplitude": 10 + amp.copy() * 0.5,
42+
"duration": PChoice([4, 4, 6, 8]),
43+
"gate": gate.copy(),
44+
"transpose": 60
45+
})
46+
47+
timeline.run()
48+
49+
if __name__ == "__main__":
50+
logging.basicConfig(level=logging.INFO, format="[%(asctime)s] %(message)s")
51+
main()

examples/03.ex-euclidean.py

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,36 @@
66
# Uses Euclidean rhythms to generate multiple polyrhythmic voices.
77
#------------------------------------------------------------------------
88

9-
import isobar as iso
9+
from isobar import *
1010

1111
import logging
12-
logging.basicConfig(level=logging.INFO, format="[%(asctime)s] %(message)s")
1312

14-
timeline = iso.Timeline(100)
13+
def main():
14+
timeline = Timeline(100)
1515

16-
timeline.schedule({
17-
"note": 60 * iso.PEuclidean(5, 8),
18-
"duration": 0.25
19-
}, delay=0.0)
20-
timeline.schedule({
21-
"note": 62 * iso.PEuclidean(5, 13),
22-
"duration": 0.5
23-
}, delay=0.25)
24-
timeline.schedule({
25-
"note": 64 * iso.PEuclidean(7, 15),
26-
"duration": 0.5
27-
}, delay=0.5)
28-
timeline.schedule({
29-
"note": 67 * iso.PEuclidean(6, 19),
30-
"duration": 0.25
31-
}, delay=0.75)
32-
timeline.schedule({
33-
"note": 71 * iso.PEuclidean(7, 23),
34-
"duration": 0.5
35-
}, delay=1.0)
16+
timeline.schedule({
17+
"note": 60 * PEuclidean(5, 8),
18+
"duration": 0.25
19+
}, delay=0.0)
20+
timeline.schedule({
21+
"note": 62 * PEuclidean(5, 13),
22+
"duration": 0.5
23+
}, delay=0.25)
24+
timeline.schedule({
25+
"note": 64 * PEuclidean(7, 15),
26+
"duration": 0.5
27+
}, delay=0.5)
28+
timeline.schedule({
29+
"note": 67 * PEuclidean(6, 19),
30+
"duration": 0.25
31+
}, delay=0.75)
32+
timeline.schedule({
33+
"note": 71 * PEuclidean(7, 23),
34+
"duration": 0.5
35+
}, delay=1.0)
3636

37-
timeline.run()
37+
timeline.run()
38+
39+
if __name__ == "__main__":
40+
logging.basicConfig(level=logging.INFO, format="[%(asctime)s] %(message)s")
41+
main()

0 commit comments

Comments
 (0)