# Varigate style sequencing in Sonic Pi

**URL:** <https://in-thread.sonic-pi.net/t/varigate-style-sequencing-in-sonic-pi/2448>\
**Category:** Creations & Ideas\
**Created:** [June 3, 2019, 11:11pm UTC](https://in-thread.sonic-pi.net/t/varigate-style-sequencing-in-sonic-pi/2448 "2019-06-03T23:11:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bendedavis](https://avatars.discourse-cdn.com/v4/letter/b/838e76/32.png) [@bendedavis](https://in-thread.sonic-pi.net/u/bendedavis)\
**Post date:** [June 3, 2019, 11:11pm UTC](https://in-thread.sonic-pi.net/t/varigate-style-sequencing-in-sonic-pi/2448/1 "2019-06-03T23:11:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![robin.newman](https://avatars.discourse-cdn.com/v4/letter/r/76d3ee/32.png) [@robin.newman](https://in-thread.sonic-pi.net/u/robin.newman)\
**Post date:** [June 4, 2019, 8:41am UTC](https://in-thread.sonic-pi.net/t/varigate-style-sequencing-in-sonic-pi/2448/2 "2019-06-04T08:41:03Z")

</div>

Is the function vt what you need?

vt  
Get the virtual time of the current thread.  
Introduced in v2.1  
Example

```ruby
# Example 1
puts vt
 sleep 1
puts vt
# prints 0
# prints 1

```

---

<div class="post-metadata">

**Author:** ![bendedavis](https://avatars.discourse-cdn.com/v4/letter/b/838e76/32.png) [@bendedavis](https://in-thread.sonic-pi.net/u/bendedavis)\
**Post date:** [June 4, 2019, 4:50pm UTC](https://in-thread.sonic-pi.net/t/varigate-style-sequencing-in-sonic-pi/2448/3 "2019-06-04T16:50:06Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![robin.newman](https://avatars.discourse-cdn.com/v4/letter/r/76d3ee/32.png) [@robin.newman](https://in-thread.sonic-pi.net/u/robin.newman)\
**Post date:** [June 4, 2019, 6:26pm UTC](https://in-thread.sonic-pi.net/t/varigate-style-sequencing-in-sonic-pi/2448/4 "2019-06-04T18:26:01Z")

</div>

Perhaps you could post some sample code that I could look at to see if I can make further suggestions.

---

<div class="post-metadata">

**Author:** ![bendedavis](https://avatars.discourse-cdn.com/v4/letter/b/838e76/32.png) [@bendedavis](https://in-thread.sonic-pi.net/u/bendedavis)\
**Post date:** [June 7, 2019, 5:17pm UTC](https://in-thread.sonic-pi.net/t/varigate-style-sequencing-in-sonic-pi/2448/5 "2019-06-07T17:17:33Z")

</div>

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.
