Debian Codegraph @

pyo/examples/x22-events/07-managing-scales.py

raw symbols SCIP
1 """
2 07-managing-scales.py - Using EventScale to manage list of notes.
3
4 EventScale constructs a list of pitches according to its arguments.
5
6 EventScale works similarly to list, ie. uses slicing with square
7 brackets to access data, with the first element at index 0.
8
9 It also accept the len() function, which returns the number of
10 elements in the scale.
11
12 The object can generate most common scales, namely: 'major',
13 'minorH', 'minorM', 'ionian', 'dorian', 'phrygian', 'lydian',
14 'mixolydian', 'aeolian', 'locrian', 'wholeTone', 'majorPenta',
15 'minorPenta', 'egyptian', 'majorBlues', 'minorBlues' and
16 'minorHungarian'.
17
18 The pitches of the scales can be in one of three forms, midi note,
19 cycles per second or octave.degree notation, according to the 'type'
20 argument.
21
22 """
23
24 import random
25 from pyo import *
26
27 s = Server().boot()
28
29 # With type=2, the scale use octave.degree notation.
30 scl = EventScale(root="C", scale="major", first=4, octaves=2, type=2)
31
32
33 def change():
34 "This function asks for a new scale based on new random values."
35 scl.root = random.choice(["C", "D", "F"])
36 scl.scale = random.choice(["ionian", "dorian", "phrygian"])
37 scl.first = random.randint(3, 5)
38
39 # Show the new scale parameters.
40 print("Root = %s, scale = %s, first octave = %d" % (scl.root, scl.scale, scl.first))
41
42 # Start a new sequence of events.
43 e.play()
44
45
46 # This sequence produces 24 events and stop. We use the 'atend' argument
47 # to set a function to call when the sequence finishes. This function
48 # will change the scale used and start a new sequence of 24 notes.
49 e = Events(
50 degree=EventDrunk(scl, maxStep=-2, occurrences=24),
51 beat=1 / 4.0,
52 db=[-6, -12, -9, -12],
53 attack=0.001,
54 decay=0.05,
55 sustain=0.5,
56 release=0.005,
57 atend=change,
58 ).play()
59
60 s.gui(locals())