Hello everyone!
I’m pretty new to FoxDot and live coding in general, so to practice a little bit I tried to reproduce the melody of the song “Children” of Robert Miles using TimeVars. After some time of playing around I obtained this:
Clock.bpm = 136
Scale.default = "minor"
Scale.key = "f"
pat1 = [0,2,1,-1,2,1,-3,2,1,-5]
dur1 = [6,1,.5,6.5,1,.5,6.5,1,.5,8.5]
p1 >> piano(var(pat1, dur1), dur=dur1, oct=6)
Then, I realized the pattern [2,1,X] is repeated, so I checked this:
p2 >> piano(var([2,1,[-1,-3,-5]], [1,.5,[6.5,6.5,8.5]]), dur=[1,.5,[6.5,6.5,8.5]], oct=6)
So far so good. The problem comes when I try to add the “0” at the start of the sequence. All the things that I tried ended with the TimeVar var([0,2,1,[-1,-3,-5]], [6,1,.5,[6.5,6.5,8.5]]), which does not yield the same pattern as var(pat1, dur1).
My question is the following: is there any way to concatenate TimeVars in a similar way as we can concatenate patterns? For example, var(0,6) | var([2,1,[-1,-3,-5]], [1,.5,[6.5,6.5,8.5]]) == var([0,2,1,-1,2,1,-3,2,1,-5], [6,1,.5,6.5,1,.5,6.5,1,.5,8.5]).
To try to solve this problem I implemented this custom function, but maybe there is an easier way to do that:
import functools
def flatten(pat, dur):
pat_flat = functools.reduce(lambda a, b: list(a) + list(b), pat)
dur_flat = functools.reduce(lambda a, b: list(a) + list(b), dur)
return pat_flat, dur_flat
pat2_raw, dur2_raw = [P[0],P[2,1,[-1,-3,-5]]], [P[6],P[1,.5,[6.5,6.5,8.5]]]
pat2, dur2 = flatten(pat, dur)
p3 >> piano(var(pat2, dur2), dur=dur2, oct=6)
Thank you for your help and sorry if the question is too basic, keep rocking!
Edward