Okay, I’m deep in the weeds here.
I’ve been working on a method to slide the bpm over time for accelerando / ritardo effects. But when it runs in a separate thread, the rest of the code ignores the changes to bpm.
I rtfm’d and found sync_bpm, which will do what I want. But now I need to test whether a named thread currently exists, and if it does, sync_bpm.
Any idea how to do this? Is there a global list of current thread names that I can sniff? If the cue isn’t defined, the syncing code just waits indefinitely.
Thanks!
All right, I’ve got a kludgey solution here. I’d like some feedback on it.
eval_file "e:/yummy/yummyfillings.rb"
define :slidebpm do |targetbpm, slidetime=16, steptime=0.25, startbpm=nil, cuename=:bpmsync, setname: :slidingbpm, **kwargs|
eval overridekwargs(kwargs, method(__method__).parameters)
cleanargs = stripparams kwargs, method(__method__).parameters
debugprint "top of slidebpm"
set setname, true
steptime = steptime.to_f
slidetime = slidetime.to_f
if !ringorlist targetbpm
targetbpm = [targetbpm]
end #if not ring or list already
debugprint "targetbpm: ", targetbpm
debugprint "slidetime: ", slidetime
debugprint "steptime: ", steptime
debugprint "startbpm: ", startbpm
thisbpm = startbpm || current_bpm
debugprint "thisbpm: ", thisbpm
targetbpm.each do |tbpm|
debugprint "tbpm: ", tbpm
stepsize = (tbpm - thisbpm) * steptime / slidetime
debugprint "stepsize: ", stepsize
while !equalish(thisbpm, tbpm)
thisbpm += stepsize
debugprint "thisbpm: ", thisbpm
use_bpm thisbpm
cue cuename
sleep steptime
end #while
end #each tbpm
set :slidingbpm, nil
end #define slidebpm
define :synctoslidingbpm do |cuename: :bpmsync, setname: :slidingbpm, **kwargs|
eval overridekwargs(kwargs, method(__method__).parameters)
cleanargs = stripparams kwargs, method(__method__).parameters
debugprint "top of bpmsync"
setflag = get[setname]
if setflag
sync_bpm cuename
end #if currently sliding
end #define synctoslidingbpm
in_thread delay: 0.05 do
slidebpm [200, 120]
stop
end
in_thread do
32.times do
debugprint "current_bpm: ", current_bpm
synctoslidingbpm
sample :perc_bell
sleep 1
end
sample :bd_808
stop
end
Fyi, debugprint and equalish are methods defined in yummyfillings.rb.
I’m using a set/get variable to flag the current state, leveraging the fact that doing get on an undefined symbol returns nil.
It works, but it’s kind of a kludge. Any more elegant solutions?