Checking current time

Hi all,

I’d like to have Sonic Pi play something different based on the time of day (for example, if the time is between 12am and 1pm, play loop A, between 1pm and 2 pm, play loop B, etc). Is there a way to access the current date/time in sonic pi? Or alternatively, the time since sonic pi was launched?

Thanks for any help!!

Hi there,

nice question. You can always access time with:

You can then convert that to a number to use as a random seed with:

Hope that this helps :slight_smile:


That is a great answer to question 1.
The second question “time since sonic pi was launched” could be resolved by saving the launchtime in a variable and substract it from current time in each loop.

But i think time is here more a question of “beats”.
And there i have no answer how to access the current “beattime”.
It is printed out in the console
{run: 1, time: 0.0}

How can i access this time?

Hi @synchron :slight_smile: There are two options for getting the beat time of the current thread/loop - beat and vt. (You can find these described in the lang help section).
The difference between these is that beat does not have any concept of ‘rate’, while vt does.

1 Like