List indexing operator in Tidal (select notes from polyphonic patterns)

@hellocatfood asked for something like this on Discord so I wrote it as an operator:

xs `getWrap` i = xs !! (i `mod` length xs)
a |!!| b = getWrap <$> (collect a) <*> b
a |!!  b = getWrap <$> (collect a) Sound.Tidal.Context.<* b
a !!|  b = getWrap <$> (collect a) Sound.Tidal.Context.*> b
a ||!! b = getWrap <$> (collect a) <<* b

d1 $ note ("<d4'minor7 d4'13 cf4'13 a4'minor7>" !!| "[0 1 . [2|3]*4]") # s "superpiano"

Posting here to see if anyone comes up with cool ways of using this!

4 Likes

There is also dagoarp by yaxu:

dagoarp :: (Num a, Eq a) => Pattern Int -> Pattern a -> Pattern a
dagoarp ipat pat = squeezeJoin $ (\l -> (octavise l) <$> ipat) <$> collect pat
   where octavise xs i = (xs !! (i `mod` length xs)) + (fromIntegral $ 12 * (i `div` length xs))

Usage:

d1 $ dagoarp "0 [4 2] 3 <1 4>" 
   $ n "c'maj'5 c'min'5 e'maj'5" 
   # sound "superpiano"

See here for more

3 Likes