I was wondering how I might implement brownian motion with Tidal. I was thinking you could use state to add a random value (with a specified range) to an existing variable. Unfortunately I don't know enough about haskell to go about implementing this
The use case is a control pattern like # pan "variable" where the variable is updating every cycle with a new number that's randomly incremented.
use markovPat (for a fixed, finite set of pan values). Something like
d1 $ s "casio:1"
+ pan (let n = 8
in fmap (\ i -> fromIntegral i / n)
$ markovPat n 0
[[ if abs(x-y)== 1 then 1 else 0 | x <- [0..n-1]]| y <-[0..n-1]]
)
incidentally, why does the source have
{- @markovPat n xi tp@ generates a one-cycle pattern of @n@ steps in a Markov ...
^^^^
I made another realization of randomly increasing sequences, using the scanl function ( Data.List ) . For a sequence xs, the sequence scanl (+) 0 xs contains the partial sums, e.g.,
in the following code, the elements of the list are patterns, not plain numbers - I only use that to get some randomness. From that, scanl (+) 0 makes a randomly increasing sequence, and I play that, in parallel to its mirror image (decreasing). And I drown it in reverb. Have fun.
I don't know how this solution compares to other options, but there's already a sort of state implemented in Tidal: State Values | Tidal Cycles
Normally the way those states are updated is to always rise by 1 modulo some divisor. That has the strange effect that reversing the rising sequence results in another rising sequence, not a falling one. But anyway, if you hacked into that and replaced the function that increments things with a function that adds a random value, you'd have Brownian motion.
There's the nuance that random sequences in Tidal require IO. If you're a fan of purity -- which you should be -- you can restrict that IO to the top calling levels by writing deterministic functions that receive a random sequence from on high.