-- region Init
do
  d1
    $ whenmod 8 6 (mask "<f [f . f t]>")
    $
    -- "<k [~ k]> . k(<1 3>,8)" -- Attente hip
    "k k k <k k? k [k? k]>" -- Techno
    # "[jazz,cpu2,cpu2:1]"
  d2
    $ fast "<1!4 2!2 4 8>"
    $ sometimesBy "0 0.5" (stut 4 0.75 "e")
    $ "~ cpu2:2" # gain 0.7
    # pan 0.7
  d3
    $ whenmod 16 8 (degradeBy "0 0.2 0.5 <0.75 0>")
    $ fast "8 <16!3 <[8 4] [8 16]>>"
    $ "dr:21"
    # pan (slow 16 "<0.8 0.2>")
    # gain (slow 32 $ range 0.4 0.8 saw)
  d4
    $ juxBy 0.25 rev
    $ whenmod 4 2 (off "q" (|+ note 12) . (|* gain 0.8))
    $ note (scale "lydian"
    (slow 2 "[<c'maj!3 c'min>](3,8) ~ f*4 e*2")
    )
    # octave 3
    # pan 0.3
    # "supersaw" # voice 0.01
    # gain 0.55
  d6
    $ swing 2
    $ arp "up"
    $ off "e" (|* gain 0.7)
    $ note (scale "lydian" (
      slow 2 "[<c'maj!3 e'maj>] ~ f*2 <e'maj!3 c'maj>*2"
    ))
    # "superfork"
    # octave 3
    # legato 2
    # gain 0.8
  d7 $ "~ cp"

  d5 -- Orchestra winds
    $ every' 4 3 (jux rev)
    $ whenmod 32 16 (|* gain (slow 2 "<1.1 0.9 0.8 0.7>"))
    $ off "q" (|+ note 12)
    $ off "e" (|+ note (slow 4 $ "<4 7>"))
    $ "~ ~ brass:1 ~"
    # note ("<c6'maj f6'maj f6'min f6'maj>")
    # gain 0.75
    # room 0.5
    # size 0.2
    # legato 2
    # lpf (slow 64 $ range 200 500 sine)

-- endregion

-- region Techno-FONK
resetCycles


do
  let mHats   = "[<t t? [f|f|t] t>*2]"
  let mBass   = "<t t f t>"
  let mGuitar = "<f t f t>"
  setcps (104/60/4)
  d1
    $ euclid "<1!8 2!4 3!3 4 4!8 5!4>" 8
    $ "[jazz,cpu2]" # gain 0.5
    # lpf 5000
  d2 -- Hats en mouvements
    $ mask (slow 8 $ mHats)
    $ ply "1 . 2"
    $ loopAt 2
    $ slice 4 "0 1 2 <3 [~ 3]>"
    $ "break:7"
    # gain (slow 16 $ range 0.35 0.55 saw)
    # panbd (segment 8 $ range 0.2 0.8 perlin)
  d4 -- Bass hypnotique
    $ mask (slow 8 $ mBass)
    $ bite 4 ("<3 0> <1 3> 2 3")
    $ s "fbass:<2!3 1>"
    # cut 2 # gain 0.65
  d5 -- Guitare résolue
    $ juxBy 0.8 id
    $ whenmod 8 6 (sometimesBy "0 0.9" (# silence))
    $ mask (slow 4 $ mGuitar)
    $ bite 4 "0*2 <3!3 2>*4"
    $ n "[<5!3 6>,~ . <4 7>]"
    # "fguitar"
    # cut 2
    # gain 0.5
    # pan (range 0.6 0.8 perlin)
  d6 -- Claps!
    $ whenmod 32 8 (# gain 0.55)
    $ someCyclesBy "<0!3 0.9>" (stut 3 0.75 "[e|s]")
    $ "~ ~ ~ clap"
    # pan "0.3 0.7"
    # gain 0
  d7 -- Ready?
    $ whenmod 16 12 (slice 2 "[0*4, 1*2]")
    $ "rave"
    # cut 7
    # gain "<0!12 0.45!4>"

-- endregion

-- region Beat-FunkaLesson
once $ "reverbkick" # gain 0.8


setcps 0.5

-- This all works nicely with chopped-up loops:
do
  unsolo 1 -- Kick
  unsolo 2 -- Breakbeat
  unsolo 3 -- Drumroll
  unsolo 4 -- Bass
  unsolo 5 -- Guitar
  setcps (
    70
    /60/4)
  d1
    $ whenmod 16 8 (slow "<2!4 8!2 4 2>")
    $ "k k k <k [~ k]>"
    # "jungbass" # n "[0,4]"
    # gain 0.9
    # hpf 110
  d2
    $ every 2 ("e" <~)
    $ every 3 (0.25 <~)
    $ loopAt 2 $ chop 8 $ "break"
    # gain 0.65
  d3 -- Drum / Hats roll
     $ sew "t(<5 7 1>,8)" "dr:21*16" "[dr:22 dr?]*[8|4]"
     # gain 0.7
  d4
    $ whenmod 64 32 (# n "5")
    $ whenmod 16 10 (mask "f(3,8)")
    -- $ bite 4 "0(3,8)" # n "<2!3 3>"
    $ n "<4!7 5>"
    # "fbass" # cut 2
    # gain 0.9
  d5 -- Guitare
    -- $ fast (slow 8 $ "<1 2 4!3 8>")
    $ juxBy 0.25 (degrade . rev)
    $ slice 4 (iter 2 $ run 4)
    $ s "~ ~ ~ g"
    # n (slow 16 $ "<1 2>")
    # "fguitar"
    # gain 0.65 # cut 5
  d6
    $ s "clap*2 ~!<7!3 3 7!2 3!2>"
    # room 0.2 # dry 0.9
    # djf (range 0.1 0.9 (slow 16 $ perlin))
  d7 -- Gemissement nappé
    $ arp "up"
    $ chop 8
    $ note ("<d5'maj <f5'min d6'maj>>")
    # s "moan"
    # crush (range 3 6 perlin)
    # gain 0.4
  d9 -- Numbers!
    -- $ bite 4 "0 <1? 1> <2 2? ~ 2> 3?"
    $ (0.75 ~>)
    $ slice 2 "[0 1]"
    $ s "toys:11"
    # speed 0.8
    # cut 10 # lpf 1200
    # gain 0.95



  d8 -- Whitenoise spatial
    $ n "[2*<0 1?>]"
    # "cosmicg"
    # gain 0.65
    # cut 8

-- Sandbox

  d9
    $ every 3 rev
    $ off "e" (|+ note 7)
    $ note ("<c4!3 f4>")
    # "monsterb"
    # gain 0.8

once $ s "cosmicg:3"


-- todo stitch
-- endregion
