tidalcycles / Tidal

Pattern language
http://tidalcycles.org/
GNU General Public License v3.0
2.28k stars 255 forks source link

feature suggestion: plyWith #548

Closed kindohm closed 5 years ago

kindohm commented 5 years ago

Looking to make a function like ply but each repeated note is additionally altered by a function parameter:

d1 $ ply 5 (# gain 0.7) $ s "bd drum"

which would result in:

d1 $ s "[bd bd bd bd bd] [drum drum drum drum drum]" # gain "[1 0.7 0.7 0.7 0.7] [1 0.7 0.7 0.7 0.7]"

or

d1 $ ply "5 3" (# gain "0.7 0.5") $ s "bd drum"

d1 $ s "[bd bd bd bd bd] [drum drum drum]" # gain "[1 0.7 0.7 0.7 0.7] [1 0.5 0.5]"
kindohm commented 5 years ago

As per @yaxu on chat.toplap.org this could be defined like so:

let plyWith numPat f = arpeggiate  $ withEvents (reverse) $ stutWith numPat 0 f 
yaxu commented 5 years ago

This works:

plyWith numPat f = arpeggiate . withEvents (reverse) . stutWith numPat 0 f

I tried making a more efficient version:

plyWith np f p = innerJoin $ (\n -> _plyWith n f p) <$> np
_plyWith numPat f p = arpeggiate $ stack (p:(ps f numPat))
  where ps f n | n < 1 = []
               | otherwise = (f p):(ps (f.f) (n-1))

But it's much less efficient!