This repository has been archived by the owner on Oct 1, 2018. It is now read-only.
/
live-loop-syncing-2.rb
261 lines (227 loc) · 6.91 KB
/
live-loop-syncing-2.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# -*- coding: utf-8 -*-
# "Ästhetik, Regel, Klang. Musikprogrammierung mit Sonic Pi"
# Session 4 - Synchronization of live loops
# filename: live-loop-syncing-2.rb
use_bpm 110 # set timing for the whole file
use_debug false # out only important things to reduce load
set_sched_ahead_time! 2 # maybe we need to give SP time to prepare
#########################################
# Metronome Helper Functions for synching
#########################################
# Count every beat
live_loop :beat do
16.times do
sample :elec_blip, amp: 0.5, rate: 3
sleep 1
end
end
# Sync 2-bar patterns
live_loop :two_bars, sync: :beat do
sample :elec_blip, amp: 0.25, rate: 1
sleep 8
end
# Synch 4-bar patterns
live_loop :four_bars, sync: :two_bars do
sample :elec_blip, amp: 0.5, rate: 0.25
sleep 16
end
#########################################
# Set up the Sound Material
#########################################
# Set up our bass line
bassline = [:b2,:b3,:e2,:e2,:r,:r,:e3,:g2,:r,:e2,:g3,:e2,:r,:g3,:e2,:g2, # Bar 1
:r,:e3,:e2,:g3,:e2,:r,:g2,:r,:e2,:g3,:e2,:g2,:r,:d2,:e2,:g2, # Bar 2
:a2,:r,:e2,:a2,:r,:e3,:a3,:a2,:gs2,:r,:r,:e2,:gs2,:gs3,:e2,:gs3, # Bar 3
:r,:e2,:e3,:gs3,:e2,:r,:gs3,:e2,:gs2,:r,:e3,:gs2,:r,:e2,:a2,:as2] # Bar 4
# Set up the Brass Section
phrase_a = [:r,:r,:r,:r,:r,:r,:r,:r,:r,:r,:r,:b4,:d5,:fs5,:d5,:r,
:fs5,:r,:fs5,:d5,:r,:r,:b4,:r,:a4,:b4,:r,:r,:a5,:r,:a5,:fs5]
phrase_b = [:r,:r,:d5,:r,:a4,:b4,:r,:r,:r,:r,:r,:r,:r,:r,:r,:r,
:r,:r,:r,:r,:r,:r,:r,:r,:r,:r,:b4,:r,:d5,:r,:e5,:fs5]
phrase_c = [:r,:r,:d5,:r,:a4,:b4,:r,:r,:r,:r,:r,:r,:r,:r,:r,:r,
:r,:r,:r,:r,:r,:r,:r,:r,:r,:r,:b5,:r,:gs5,:r,:e5,:d5]
# Set up the Flitter
b_chord = [:b5,:d6,:fs6,:a6,:b6,:d7,:fs7,:a7]
g_chord = [:g5,:a5,:d6,:g6,:a6,:d7,:g7,:a7]
a_chord = [:a5,:b5,:e6,:g6,:a6,:b6,:e7,:g7,:a7]
e_chord = [:e5,:gs5,:b5,:e6,:gs6,:b6,:e7,:gs7,:b7]
# Set up the 2nd brass section
# Helper function for various durations and crescendi/decrescendi
# notes and rests
n = [[:a4],[:d5],[:d5],[:cs5],[:a4],[:b4],[:fs4],[:a4,:e5],[:e4,:gs4,:e5],[:d3,:e4,:d4,:e5],[:e4,:e5,:d5]]
# duration for notes and rest; fade in/out
# if fade needed use subarray [ note, 1 = fade-in, 0 = fade-out ]
d = [[6,1],0.5,0.5,0.5,0.5,1,0.5,[2,1],[2.5,0],1,1]
ratio = 0.9
# This function plays note lengths and rests according to the given value
define :play_synth do | notes, durations |
notes.zip(durations).each do | n, d |
if n != :r # check if note or rest
if d.is_a?(Array) # check if fade is needed
if d[1] == 1 # fade in
play n, amp: 0.5, attack: d[0] * (ratio * 1/3), sustain: d[0] * (ratio * 2/3), release: d[0] * (1-ratio)
sleep d[0]
else # fade out
play n, amp: 0.5, attack: d[0] * (1-ratio), sustain: 0, release: d[0] * ratio
sleep d[0]
end
else
play n, sustain: d * ratio
sleep d
end
else
sleep d
end
end
end
#########################################
# Clumsy Mixer
#########################################
# 1 starts, 0 stops the loops
chords = 0
brass1 = 0
brass2 = 0
bass = 0
drums = 0
hihat1 = 0
hihat2 = 0
flittr = 0
chords_lv = 4 # 3
brass1_lv = 0.9 # 0.9
brass2_lv = 0.1 # 0.3
flittr_lv = 0.25 # 0.3
#########################################
# Love Loops for Playing
#########################################
# The Chords
live_loop :chords, sync: :four_bars do
stop if chords < 1
with_synth :hollow do
use_synth_defaults amp: chords_lv, attack: 0.1, sustain: 1, release: 5, noise: 4
with_fx :reverb, room: 0.5 do
play_pattern_timed [[:b3,:d4,:fs4,:a4,:b4,:fs5],
[:a3,:d4,:g4,:a4,:g5],
[:a3,:e4,:a4,:b4,:e5],[:gs3,:e4,:gs4,:b4,:e5]],
[(0.5 * 3), (0.5 * 13), (0.5 * 3),(0.5 * 13)]
end
end
end
# The Bass Line
live_loop :bass, sync: :four_bars do
stop if bass < 1
with_synth :fm do
use_synth_defaults amp: 1.5, attack: 0.0, sustain: 0.15, release: 0.01, cutoff: 65
play_pattern_timed bassline, [8.0 / 32 * 1]
end
end
# The Drums
# Bass Drum and Snare
live_loop :bass_snare, sync: :two_bars do
stop if drums < 1
2.times do
sample :drum_bass_soft
sleep 0.25
sample :drum_bass_soft
sleep 0.75
with_fx :reverb, room: 0.5 do
sample :elec_hi_snare, amp: 1.5
end
sleep 0.75
sample :drum_bass_soft
sleep 0.5
sample :drum_bass_soft
sleep 0.25
sample :drum_bass_soft
sleep 0.5
with_fx :reverb, room: 0.5 do
sample :elec_hi_snare, amp: 1.5
end
sleep 0.75
sample :drum_bass_soft
sleep 0.25
end
end
# Hihat1
hihat1_vol = 0.25
live_loop :hihat1, sync: :two_bars do
stop if hihat1 < 1
(4*2).times do
sleep 0.25
sample :drum_cymbal_closed, amp: 0.5 * hihat1_vol, finish: 1
sleep 0.25
sample :drum_cymbal_closed, amp: 0.35 * hihat1_vol, finish: 0.1
sleep 0.25
sample :drum_cymbal_closed, amp: 0.15 * hihat1_vol, finish: 0.2
sleep 0.25
sample :drum_cymbal_closed, amp: 0.35 * hihat1_vol, finish: 0.1
#sleep 0.25
end
end
# Hihat2
hihat2_vol = 0.5
live_loop :hihat2, sync: :two_bars do
stop if hihat2 < 1
(4*2).times do
sample :drum_cymbal_closed, amp: 0.5 * hihat2_vol
sleep 0.25
sample :drum_cymbal_closed, amp: 0.75 * hihat2_vol
sleep 0.25
sample :drum_cymbal_closed, amp: 0.5 * hihat2_vol
sleep 0.25
sample :drum_cymbal_closed, amp: 0.5 * hihat2_vol
sleep 0.25
end
end
live_loop :brass1, sync: :four_bars do
stop if brass1 < 1
with_synth :sine do
use_synth_defaults amp: brass1_lv, attack: 0.0, sustain: 0.15, release: 0.01, cutoff: 100, pan: -0.5
with_fx :reverb, room: 0.75 do
play_pattern_timed phrase_a, [0.25]
play_pattern_timed phrase_b, [0.25]
play_pattern_timed phrase_a, [0.25]
play_pattern_timed phrase_c, [0.25]
end
end
end
live_loop :brass2, sync: :four_bars do
stop if brass2 < 1
#use_synth :tri
#use_synth_defaults amp: brass2_lv, attack: 0, sustain: 0, release: 0.15
use_synth :fm
use_synth_defaults amp: brass2_lv, attack: 0, sustain: 0, release: 0.15, depth: 2, divisor: 0.5
with_fx :reverb, room: 0.75 do
#with_transpose +12 do
play_synth n, d
#end
end
end
# The Flitter
live_loop :flitter, sync: :four_bars do
stop if flittr < 1
with_synth :pretty_bell do
use_synth_defaults amp: flittr_lv, attack: 0.1, sustain: 0.2, release: 0
with_random_seed 11865 do
with_fx :reverb, room: 1 do
2.times do
6.times do
play b_chord.choose
sleep 4.0/16 * 1
end
26.times do
play g_chord.choose
sleep 4.0/16 * 1
end
6.times do
play a_chord.choose
sleep 4.0/16 * 1
end
26.times do
play e_chord.choose
sleep 4.0/16 * 1
end
end
end
end
end
end