Skip to content

Instantly share code, notes, and snippets.

@efairbanks
Created March 15, 2018 18:50
Show Gist options
  • Save efairbanks/d967a5f017c96084306638985c5991bb to your computer and use it in GitHub Desktop.
Save efairbanks/d967a5f017c96084306638985c5991bb to your computer and use it in GitHub Desktop.
TidalCycles Hierarchical Variation /w whenmod
whenmodr speeds numerators denominators modifier pattern -- applies the modifier to the pattern serially and conditionally, multiple times, dependent on the supplied speeds and whenmod parameters
| done = modifiedpattern
| otherwise = whenmodr rests restn restd modifier modifiedpattern
where modifiedpattern = inside speed (whenmod numerator denominator (modifier)) $ pattern
numerator = (head numerators)
denominator = (head denominators)
speed = (head speeds)
done = (null $ tail speeds) && (null $ tail numerators) && (null $ tail denominators)
restn = if null (tail numerators) then [numerator] else (tail numerators)
restd = if null (tail denominators) then [denominator] else (tail denominators)
rests = if null (tail speeds) then [speed] else (tail speeds)
whenmods' speeds numerators denominators modifier pattern
| done = modifiedpattern
| otherwise = whenmods' rests restn restd modifier modifiedpattern
where modifiedpattern = inside speed (whenmod numerator denominator ((slow speed).(modifier))) $ pattern
numerator = (head numerators)
denominator = (head denominators)
speed = (head speeds)
done = (null $ tail speeds) && (null $ tail numerators) && (null $ tail denominators)
restn = if null (tail numerators) then [numerator] else (tail numerators)
restd = if null (tail denominators) then [denominator] else (tail denominators)
rests = if null (tail speeds) then [speed] else (tail speeds)
whenmods speeds numerators denominators newpattern pattern = -- replaces the pattern conditionally, multiple times, dependent on the supplied speeds and whenmod parameters
whenmods' speeds numerators denominators (const newpattern) pattern
do
let fx = ((|*| gain 0.9).(superimpose (|*| speed 2) $).(fast 2).(|*| up 1).(|*| release 0.5))
d1 $ stack [
whenmods [1,2,4] [8] [7] (s "[bd bd sn:3]*8%3") $ s "[bd(2,2),sn:3(1,2,1),hh(2,4,1)]",
whenmodr [0.5,1,2,4] [8] [7] fx $ s "bass:3(1,1)"
]
@karangejo
Copy link

Hello,
Should I put this code in my BootTidal.hs file? I tried this and also tried to run it in tidal but it gave me lots of errors. Would love to use this just not sure how to get it working. Also enjoyed your MIDI in tutorial for tidal. Very cool! worked like a charm!

@ericfairbanks
Copy link

Hello,
Should I put this code in my BootTidal.hs file? I tried this and also tried to run it in tidal but it gave me lots of errors. Would love to use this just not sure how to get it working. Also enjoyed your MIDI in tutorial for tidal. Very cool! worked like a charm!

Hey there! Sorry, I never saw this. I would recommend putting it in a separate Haskell file and then including that in your BootTidal.hs. The BootTidal.hs is more of a Haskell initialization script, and you can't just put Haskell code in there willy-nilly, though depending on how it's written it might work.

Also glad my MIDI tutorial worked for you! I need to do a bit of massaging on my website though, as it appears some hosted files got lost in the shuffle when I had to rebuilt it. (my host went down and I almost lost it all) Going to try to host everything on Github from now on to mitigate this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment