Tidal icon indicating copy to clipboard operation
Tidal copied to clipboard

shared variables and trigger function

Open ovitus opened this issue 5 years ago • 1 comments

Trying to get the trigger function to work inside of shared variables.

--This works:
do
let var = (trigger 1 $ slow 2 envL)
d1 $ sound "9b*2 9cp:4(5,8,<0 2>)" # gain var

--But this doesn't?:
do
setF "var" (trigger 1 $ slow 2 envL)
d1 $ sound "9b*2 9cp:4(5,8,<0 2>)" # gain (cF0 "var")

ovitus avatar Dec 12 '19 20:12 ovitus

I can add some context: this doesn't work because trigger internally uses a state lookup to get the time offset when the d1 function was called (the actual code is a bit more convoluted, but trigger is essentially rotR (cR0 "pattern_start")). You can't currently nest shared variables like this, because that would allow infinite loops like so:

setF "var" (cf0 "var")
d1 $ sound "9b" # gain (cf0 "var") -- This pattern will take forever to evaluate

A more sophisticated state lookup that allows for nesting while avoiding infinite loops is possible, but I think this is just a corner of Tidal possibilities that hasn't been fully explored yet.

matthewkaney avatar Nov 26 '22 20:11 matthewkaney