live_loop :drums do
tick
sample :bd_tek if 5[look%4] >0
sample :bd_klub if 3[look%5] >0
sample :bd_boom if cycle.look[look%4] >0
sample :elec_cymbal, rate: 3 if 10[look%4] >0
sleep 0.5
end
end
I’m interested mostly in the ‘3[look%5] >0’ stuff, and just what
it’s up to…
I don’t think, this code is complete and/or correct. There is an end to much but more importantly cycle is not defined and the expression 5[look%4] make - at least to me - no sense.
You know the modulo operator%, do you? It returns the rest of an integer division: It tries to divide an integer by another integer and if this works out it returns 0 because this is the rest of the division; there is nothing left to devide. If it does not work out evenly, it returns the first number which is the ’ rest’ .
Let’s see for different values of look:
look is 0: look % 4 = 0 look is 1: look % 4 = 1 look is 2: look % 4 = 2 look is 3: look % 4 = 3 look is 4: look % 4 = 0 look is 5: look % 4 = 1 look is 6: look % 4 = 2 look is 7: look % 4 = 3 look is 8: look % 4 = 0
You can use modulo division to get a counter, which counts only from 0 to 3 (see the example) and then starts again. Very handy in the context of music. See some of my experiments for further use cases.
I hope this helps although I couldn’t help with the example you provided.
it took me a while to understand, what modulo does (although it is not too complicated, which is always easy to say after you’ve wrapped your head around something). Even more important IMHO is, what you can do with it. Check out the following code for one suggestion:
use_bpm 170
live_loop :bass do
# this counter only counts from 0 - 7 and then starts all over again
cnt = tick % 8
n = :cs1
# here we use cnt to change the notes during the course of the bass phrase
if cnt < 4 then
n = :cs1
elsif cnt < 6 then
n = :e1
elsif cnt < 8
n = :fs1
end
use_synth :fm
use_synth_defaults attack: 0.001, attack_level: 8, sustain: 3, release: 0.025, divisor: 1, depth: 1, amp: 0.75
s = play n
i = 0
32.times do
i += 1
control s, depth: (ring 2, 8)[i]
sleep 0.25
end
end
PS.: ‘stumped’: I didn’t know that. The translation to colloquial German is: ‘to be at the end with your Latin’
Experimenting with this, I think that it looks at the intial number in binary and returns the various digits of that.
Try first
5.times do |i|
puts i,5[i]
end
You will see the various values of i and the value returned from 5[i]
The separate issue is the use of look with the modulo operator %. This returns the remainder when look is divided by the second number ie look%4 returns 0,1,2,3,0,1,2,3 as look increases in value. So you get:
use_bpm 120
cycle = (ring 2, 4, 6,8)
co = 10 #cutoff
sc = scale(:e4, :minor_pentatonic) #scale stored in variable
live_loop :drums do
if rand(1) > 0.75 then
8.times do
tick
sample :bd_tek if 5[look%4] >0
sample :bd_klub if 3[look%5] >0
sample :bd_boom if cycle.look[look%4] >0
sample :elec_cymbal, rate: 4 if 10[look%4] >0
sleep 0.5
end
else
4.times do
tick
sample :bd_tek if 5[look%4] >0
sample :bd_klub if 3[look%5] >0
sample :bd_boom if cycle.look[look%4] >0
sample :elec_cymbal, rate: 3 if 10[look%4] >0
sleep 0.5
end
end
end
with_synth :dpulse do
live_loop :starp1 do
sync :drums
with_transpose -12 do
if rand() < 0.65
play_pattern_timed [:Gs3, :Fs3, :A3, :b3, :c5, :b4, :g4, :e4], [0.25],
attack: 0.1,
release: 0.5,
cutoff: co
else
play_pattern_timed [:c4, :e4, :g4, :b4, :c5, :b4, :g4, :e4], [0.25],
attack: 0.1,
release: 0.5,
cutoff: co
end
end
end
end