# 4.3 Timevar Advanced ## 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: | Variable name | Description | |---------------|--------------------------------------------------| | `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: ``` python # 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: ``` python var([0, 4, 5, 3], start=1) ``` This can be combined with the `now` singleton to ‘start’ a var‘s cycle immediately. For example, we can ramp up a player’s amplitude from 0 to 1 over 8 beats, starting now: ``` python 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](https://en.wikipedia.org/wiki/Singleton_variable), 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: ``` python 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: ``` python d1 >> play("x-o-", amp = linvar([0, 1], [8, inf], start=now)) ``` _Note_: 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 the `linvar` used above would be starting/re-starting its cycle on every eighth beat.