-- Castle beats
setcps 0.6

d1 -- Beat hip
$ mask "f(<8 7 6 5 4 3 2 1>,8)"
$ s "k(<<3 5>!3 <5 3>>,8)"
# s "jazz"
# gain 0.8

do
  let bars = 64
  let tEnd = (bars - 2)
  let bEnd = (bars - 4)
  let bMid = (bars - 32)
  d1 -- technoo
    $ whenmod bars tEnd       (fast 2)
    $ whenmod bars (tEnd - 3) (degrade)
    $ whenmod bars 16         (fast 2)
    $ whenmod bars 0          (slow 2)
    -- $ slow 2
    $ s "k k . [~ k|k . k k?]"
    # s "reverbkick"
    # gain 0.8
    # lpf (slow 16 $ range 1000 8000 sine)
  --
  d2 -- snares contretemps assez reguliers
    $ juxBy 0.3 rev
    $ someCyclesBy "<0!3 0.75>" (hurry 2)
    $ "~ <s [~ s] s*2 s?>"
    # s "snare:11"
    # note (-12)
    # gain (slow 4 $ range 0.8 0.95 sine)
  --
  d3 -- Carillon Roll
    $ whenmod 32 24 (mask "f(3,4)")
    $ fast "<2 4> <2!3 [4 2]>"
    $ fast "<[4 2] [8 4]>"
    $ s "hh:8"
    # gain 0.8
  d4 -- Pianooo
    -- $ degradeBy (slow 8 $ "<0 [0 0.75 0.9 0.5]>")
    -- $ sometimes (0.125 ~>)
    $ whenmod (bars * 2) bars ((euclid "<3!4 5!4>" 16) . slow 16)
    $ bite 4 "<0!4 3!4> <0!3 1 3!3 2> <0!3 2 3!3 1> <0!3 3 3!3 0>"
    $ note (scale "aeolian" (run 8)
    )
    # s "superpiano"
    # velocity 0.5
  d5
    $ mask "t(<1 3>,4)"
    $ whenmod 64 32 (often (superimpose
      (sometimesBy (slow 16 $ "<0 1>") (mask "t f*7"))
      . (# crush 2) . (|- gain 0.1)
    ))
    $ sometimesBy "0.8 0.2 0 0.05" (fast 2)
    $ every 8 rev
    $ often rev
    $ bite 4 "0 1 [2|3] [3|2]"
    $ note (scale "aeolian" (run 8) - 24)
    # s "supersaw"
    # voice 0.1
    # sustain 0.2
    # room 0.8
    # gain 0.5
  d6 -- Choeurs
    $ bite 4 (slow 2 $ "<0 <1 2>>")
    $ slow 2
    $ note (scale "aeolian" (run 8) + "[12]")
    # s "moogBass"
    # gain 0.8
  d7 -- claps
    $ sometimes (whenmod 4 2 (# s "cp"))
    $ s "~ ~ ~ <~ <c [c|c*2]>>"
    # s "clap"
    # n "~ ~ ~ [0 . 1]"
    # gain 0.9
