/
test_strum_move.py
72 lines (52 loc) · 1.92 KB
/
test_strum_move.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
68
69
70
71
72
from pyo import *
from pitches import Pitches
from shell import *
from move import *
from random import randint
from random import choice
s = Server().boot()
# Generate the pitches manager (see pitches.py)
p = Pitches(degrees=[0,4,7], tuning='just')
beat_time = Sig(.3)
m = Metro(beat_time, poly=1).play()
# Generate Adsr envelopes (see shell.py)
# shells = [
# ShellAdsr(dur=beat_time.value, dur_fact=.4, num=p.len),
# ShellAdsr(dur=beat_time.value, dur_fact=.8, num=p.len)
# ]
# Generate Adsr envelopes (see shell.py)
shells = [
ShellHann(dur=beat_time.value, dur_fact=.4, num=p.len),
ShellHann(dur=beat_time.value, dur_fact=.8, num=p.len)
]
# Generate the envelope manager (see shell.py)
env = ShellManager(shell=shells[1])
sin = Sine(freq=p.getPitches(), mul=env.getShell())
mix = Pan(sin).out()
count = 0
# Strummer move (see move.py)
strum = Strummer(inst=env)
def test_strum():
global count
# Set a random value for the metro time.
beat_time.setValue(randint(4,6)*.1)
print 'beat_time.value: ', beat_time.value
# Select envelopes to read.
shell_num = randint(0,1)
print 'shell num: ', shell_num
# Update the envelope durations (env is an instance of ShellManager
env.setShell(shells[shell_num])
env.setShellDur(beat_time.value*.5)
# @TODO the following calculations should be done within the Strummer class.
# diff_time the difference between the metro time and the envelope time.
diff_time = beat_time.value - env.getShellDur()
# Lapse_value is diff_time divided by the number of envelopes to read.
# The first envelope should be read at 0, and each subsequent envelope at lapse_value * i where i is
# the enveloppe's index in the list of envelopes, up to i = n - 1 where n is the number of envelopes.
lapse_value = diff_time / env.getLen()
# strum is an instance of Strummer
strum.setLapse(lapse_value)
strum.strum()
count+=1
tf = TrigFunc(m, test_strum)
s.gui(locals())