Hallo friends
my young student and I are exploring a few different and simple ways of programming drum patterns, including arrays of numbers or of symbols. When we came to this example:
k1 = [9,0,0,0,7,0,0,5] # how loud is each sound, div by 10.0
s1 = [0,0,6,0,0,0,4,0]
h1 = [0,8,0,5,0,7,0,4]
h2 = [5,0,4,0,3,0,2,0]
live_loop :drums98 do
#stop
sample :bd_zum, amp: k1.tick * 0.1
sample :sn_zome, amp: s1.look * 0.1
sample :hat_bdu, amp: h1.look * 0.1
sample :hat_gnu, amp: h2.look * 0.1
sleep 0.25
end
He asked if we could use a loop counter to tick through the arrays, and use k1[i] * 0.1 (as we had in a previous working example), instead of .tick. Using live_loop :drums98 do | i | the answer is no we can’t.
The previous working example was this one:
drm = [1,0,2,0,1,0,2,1]
cym = [0,1,0,2,0,1,0,2]
live_loop :drums1 do
stop
8.times do |i| #loop counter
sample :drum_bass_hard if drm[i] == 1
sample :sn_dolf if drm[i] == 2
sample :hat_bdu if cym[i] == 1
sample :hat_gnu if cym[i] == 2
sleep 0.25
end
end
I realise this example polls the array and then applies a conditional, and the example above that is polling the array for the actual value itself. Again, revealing my n00bosity - where is the nil coming from, and why can’t we index through the array values in the first example. I tried k[1].to_i without success.
Many thanks for your continued support
Brendan