-
Notifications
You must be signed in to change notification settings - Fork 1
/
three-against-four.rb
73 lines (54 loc) · 1.34 KB
/
three-against-four.rb
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
73
define :my_play do |bpm, sample_sym, repeats|
in_thread do
with_bpm bpm do
repeats.times do
sample sample_sym
sleep 1.0/repeats
end
end
end
end
repeats_x = 3
repeats_y = 4
state = 1
start_bpm = 40.0
end_bpm = start_bpm*1.0*repeats_x/repeats_y
bpm = start_bpm
sound_a = :perc_snap
sound_b = :perc_snap2
live_loop :polyrythm do
with_bpm bpm do
if state == 1
if bpm == start_bpm
sample :perc_bell, amp: 0.5
end
my_play bpm, sound_a, repeats_x
my_play bpm, sound_b, repeats_y
getting_faster = start_bpm < end_bpm
if (getting_faster && (bpm >= end_bpm)) || (!getting_faster && (bpm <= end_bpm))
state = 2
bpm = end_bpm
else
bpm += (end_bpm - start_bpm)/6.0
end
elsif state == 2
sample :perc_bell, amp: 0.5
sample sound_a
my_play bpm, sound_b, repeats_y
bpm = start_bpm
state=3
elsif state == 3
sample :perc_bell, amp: 0.5
my_play bpm, sound_b, repeats_x
# swap sounds
helper = sound_a
sound_a = sound_b
sound_b = helper
state=1
else
# alarm
my_play bpm*2, :perc_bell, 7
end
sleep 1
end
end