TimeVar Advanced

This section outlines some more functionality of the TimeVar class that weren’t covered in the TimeVar Basics page.

TimeVar Singletons

These are instances of the TimeVar that already exist when FoxDot boots up and represent changing values, such as the clock beat, and can be used just like and other TimeVar:

  • now – represents the current clock beat
  • nextbar – represents the beat at the start of the next bar

Advanced Features

Offsetting the start time

Let’s say you want to create a chord sequence that changes not at the beginning of a bar, after the first beat of the bar. How would you do that with a TimeVar? Let’s have a look:

# Original chord sequence
var([0, 4, 5, 3], 4)

# Update value after 1 beat of the bar
var([3, 0, 4, 5, 3], [1, 4, 4, 4, 3])

Not a very elegant solution but it would work. It would be easier just to offset the start point of the durations by a single beat, wouldn’t it? This can be achieved by using the start keyword like so:

var([0, 4, 5, 3], start=1)

This can be combined with the now singleton to ‘start’ a linvar‘s cycle immediately. For example, we can ramp up a player’s amplitude from 0 to 1 over 8 beats, starting now:

d1 >> play("x-o-", amp=linvar([0, 1], 8, start=now))
Infinite duration

Sometimes it might be preferable for a TimeVar to reach a value and then stay that value. To do this we use a special variable called inf. It is a singleton, which means its an instance of a class but there is only one of it and can be used to tell a TimeVar not to change its value once reached. Here’s an example of a linvar ramping up amplitude to 1 over 8 beats and then staying there:

d1 >> play("x-o-", amp = linvar([0, 1], [8, inf]))

This can also be combined with the now and nextbar singletons to ramp up immediately:

d1 >> play("x-o-", amp = linvar([0, 1], [8, inf], start=now))

It’s worth noting that, when calculating the total cycle length off the TimeVar, inf is counted as 0 until it is reached once the TimeVar is implemented. That means that linvar used above would be starting/re-starting its cycle on every eighth beat.