So… I’m trying to change bpms of loops, using set and get (like a good little soldier)… but I’m missing
something… perhaps current_bpm always gets the global bpm? Erm… lickle help please.
Eli…
#Some defaults
default_bpm = 125
set :this_bpm, default_bpm
use_bpm default_bpm
# Various defines controlling how our loops work.
define :set_bpm do |newbpm|
if newbpm == default_bpm then
set :this_bpm, default_bpm
else
set :this_bpm, newbpm
end
end
define :change_speed do |newspeed, steps|
if !steps then
steps = 4
end
this_speed = current_bpm
changes = (line this_speed, newspeed, step: steps, inclusive: true)
changes.each do |speed|
set :this_bpm, speed
sleep 1
end
end
live_loop :bar do
use_bpm get[:this_bpm]
puts get[:this_bpm]
sleep 1
end
live_loop :drum do
sync :bar
sample :bd_ada ,amp: 2
sleep 1
end
sleep 8
change_speed 300, 10
sleep 16
change_speed 150, 6
sleep 16
stop
Hi @Eli,
I would suggest to use explicit variable fromspeed, like
define :change_speed do |fromspeed, tospeed, steps|
if !steps then
steps = 4
end
changes = (line fromspeed, tospeed, steps: steps, inclusive: true)
changes.each do |speed|
set :this_bpm, speed
sleep 1
end
end
So you do not depend on what bpm which loop is assuming as its bpm.
Then use it like
change_speed 125, 300, 10
(in your code there is also a typo: the parameter to line is steps:)
I think I’ll leave this tomorrow, I’ve just been put on a much stronger corticosteroid,
took my 1st batch about 4 hours ago, and I’m not doing so fine…
I think the point you’re missing is that the bpm is thread local, meaning that each thread (or live_loop) has its own bpm. Therefore the use_bpm in the :bar live_loop is only setting the bpm in that thread, but not in the outer scope.
If you also call use_bpm at the same time as you set :this_bpm then it will also be set in the outer scope, and then it will be picked up properly next time you call change_speed.
You might also want to remove the sleep in the :drum live_loop, as I think this is making it miss the next cue so the delay is doubled.
Finally, there is also a typo in your call to the line function, it should be steps: steps instead of step: steps - at the moment that option is being ignored so it is always using 4 steps.