Possible to use `struct` to conditionally apply effects/transforms?

Can struct somehow be used more like a boolean function? for example what if a structWith function existed:

structWith functionIfTrue functionIfFalse structure

d1 $ structWith (# speed 2) (# gain 0) ("t f*2 t*2 [t f]") $ s "arpy"

or

d1 $ structWith (|+ n 1) (# pan 1) ("t f*2 t*2 [t f]") $ s "arpy" # pan 0 # n 3

Instead of just turning the f's to ~'s, could struct be used to supply my own function for what to do on the t and f events?

Hi Mike, howabout this:

import Sound.Tidal.Utils

-- | chooses between a list of functions, using a pattern of integers
pickF :: Pattern Int -> [Pattern a -> Pattern a] -> Pattern a -> Pattern a
pickF pi fs pat = innerJoin $ (\i -> _pickF i fs pat) <$> pi

_pickF :: Int -> [Pattern a -> Pattern a] -> Pattern a -> Pattern a
_pickF i fs p =  (fs !!! i) p

Then you can do this:

d1 $ pickF "<0 2> 1 2" [(# crush 4),(# djf sine),iter 4] $ n (run 8) # sound "bd"
2 Likes

Thanks @yaxu. Indexing into a list of patterns isn’t exactly what I had in mind, but I think it will solve my issue perfectly.