Hello !

Welcome to this blog and here is an article about using vars in FoxDot.

What do they do exactly ?

a = var([0,4],4)
b = linvar([0,4],4)
c = sinvar([0,4],4)
d = expvar([0,4],4)
e = Pvar([P[0,1,2,3],P[1,4,4,2]],4)
# identical to
e = var([0,1,2,3,1,4,4,2],1)
Variable shapes
Different variable shapes met in FoxDot

a is a discrete variable; it means it cannot take another value than the values defined.

b is a linear variable, meaning it will go from start point to end point in a linear motion.

c is a sin variable, meaning it will go from start point to end point in a circular arc motion.

d is an exponential variable, meaning it will go from start point to end point in an exponential motion.

e is a pattern variable, meaning that it will change its patterns over time. The default dur value for a note stays at 1.

In any case, it is possible to change the second argument by a time duration. Instead of giving the number of beats necessary to go to next variable end point, we give the time measure of each note in the variable :

f = Pvar([P[0,1,2,3],P[1,4,4,2]],dur=2)

How can we visualize variables properly ?

We know FoxDot uses a Clock object that updates itself every beat. So we can schedule an event to visualize the value of a variable, for instance :

Clock.bpm = 120
Clock.every(1/2, lambda: print(sinvar([0,1],4)))

This allows us to get various points that we can plot as value = function(time). For this just export the console log, copy/paste the measurements in Excel, and build the time values points. As the tempo is 120 bpm, it means that it has 120 beats in a minute, or 2 beats in a second, so 1 beat every half-second. As we have set our every to 1/2, we can scale our time points to an array of 0,1,2,3,4,…

Then we can plot this in Excel or any online plot generator, such as this one.

What makes vars valuable, is that we can use them in any context. We can use them with operators, in patterns, we can also vary the time delay each time the var is passed :

Clock.every(1/2, lambda: print(var([0,1],[2,4]) + PRange(4)))

In this example, we have a Pattern consisting of [0,1,2,3].
We want every var change to add 0 or 1 to out pattern items. The second array in var means the var value will change over 2 beats, then over 4 beats, etc…

More vars experiments in the official var demo.

Cheers !