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