I’m looking to recreate most of the functionality I’ve programmed in the Varigate module in Sonic Pi. I’m having issues getting a loop to run at a high enough resolution it seems to get the best timing. I just need a few things for this to work but maybe I need to dig a bit further to find the best way to do it. All I really need is a floating point running time since the program was started and I can use that to multiply/divide and modulo for each instance.
Is the function vt what you need?
vt
Get the virtual time of the current thread.
Introduced in v2.1
Example
# Example 1
puts vt
sleep 1
puts vt
# prints 0
# prints 1
That almost works but I can only get sleep down to 0.1 without having timing issues. Is there no way to run a loop in real time even if I’m only triggering samples at a much slower rate?
Perhaps you could post some sample code that I could look at to see if I can make further suggestions.
So, here’s some pseudo code:
stepCount = 16
timeFactor = 4.0
timeBase = (currentTime*timeFactor)%stepCount
currentStep = int(timeBase)
lastGate = gate
gate = if((prob[currentStep]>rand(0,1.0) && fractional(timeBase) < pulseWidth[currentStep])
if(gate > lastGate)
playSample()
Wrote this up pretty quick but hopefully you get the idea. The current time is used to multiply or divide and then you get an integer for the step and fractional amount to determine pulsewidth on that step or further subdivide for repeats.