import Sound.Tidal.ParVagues.Control


-- New Dust: LoFi howto dust to dust
do
setcps (60/60/4)
let whenIntro    pat = someCyclesBy "<t!8 f!24>" pat
let whenNotIntro pat = someCyclesBy "<f!8 t!24>" pat
let whenBrk      pat = whenmod 16 10 pat
let whenNotBrk   pat = someCyclesBy "<t!10 f!6>" pat
let whenBrkLPF  = whenBrk (# lpf "<400 200 100 50 0 0>")
let gDJF = (# djfbus 1 (range 0.05 0.95 "^49"))
let gLPQ = (# lpqbus 2 (range 0.01 0.5 "^29"))
let gHPQ = (# hpqbus 3 (range 0.01 0.5 "^30"))
let g = gDJF . gLPQ . gHPQ
let prog =  "<e [a5,f] [e,gs5] ~>"
let att = pF "att"
let dec = pF "dec"
let sus = pF "sus"
let width = pF "width"
d1 $ g -- Kick
  $ whenBrkLPF
  $ whenNotBrk (# sz "<0.8 0.9 0.95 0.99>")
  -- $ superimpose (
  --   (# "reverbkick") . (|* gain 0.5)
  -- . (# cut 11)
  -- . (# attack 0.5)
  -- . (# release 0.5)
  -- )
  $ midiOn  "^41" (<| "k k k k k k k [<k ~> k*<1!7 2>]")
  $ midiOff "^41" (<| "k ~ <~ ~ k ~> k . k k(<1!4 <5 3>!12>,8)")
  $ "jazz"
  # attack 0.5
  # midiG' "^78" 0 1.7
  # cut 1
d2 $ g -- Contretemps snare
  $ whenBrkLPF
  $ whenmod 8 6 (mask "<f [f t]>")
  $ superimpose (# hpf 500)
  $ every' 8 7 (ply 2 . mask "f!7 t" . (|* gain 0.8)) -- Double final
  $ "~ s ~ <s [<~ s> s]>"
  # "[snare:20,gretsch:2]"
  # midiG "^79"
d3 $ g  -- Drumroll fantôme
  $ midiOn "^43" (const
      -- $ sometimesBy "0 0.8!6 0" (ply "<2 [2|4]>" . (|* gain 0.9))
      $ slice 8 (run 4 + "0 <~!4 4!4>")
      $ loopAt 2
      $ "break:21"
      # midiG' "^80" 0 1.3
      # room 0.2 # dry 1 # sz (slow 8 $ range 0.45 0.9 saw)
      # leslie 0.2 # lrate 0.1 # lsize 0.7
      # pan 0.7
  )
  -- $ whenBrk (slow "<2 2 4 4 8 8 16 16>")
  $ whenmod 8 4 (
    (often (degradeBy "0 0.25!6 0"))
    . (sometimesBy "0.75 0!6 0.75" (ply 2))
    )
  $ fast ("8" * "<[2 1!7] 1!3> <2 [2 1] [2 . 1 2] [2 4]>")
  $ "drum:2"
    # leslie (slow 12 perlin)
    # lsize 2.8 # lrate 6.7
  # room 0.6 # sz 0.9 # dry 1.01
  # pan (0.4 + (slow 4 perlin/4))
  # midiG' "^80" 0 0.8
d4 $ g -- Lead nostalgia gauche
  $ midiOn "^76" (fast 2)
  -- $ (|* gain "<1 [0.8 0.9] 0.8 ~>") -- ajust prog nombre variable
  $ note (prog
    |+|   "<0 [0 . ~!3 <~ <1 -2>>] 0 ~>" -- fillers
    -- $ note ("<e [g4,<d!3 f> . ~!3 <c!3 g>] [b4,e] ~>"
    - 24 -- Gamme
  )
  # s "FMRhodes1"
  # room 0.2
  # leslie (range 0.1 1 "^32") # lrate 0.7 # lsize 0.5
  # crushbus 4 (range 16 6 "^52")
  -- # note "<-20 -15 [-20,-16] ~>"
  -- # velocity "<0.7 0.6 0.7>"
  # midiG' "^81" 0 1.5
d5 $ g  -- Infectious Bassline
  $ whenmod 16 8 (degradeBy "[0 0.5!3]*2")
  $ midiOn "^89" (ply "[1 2]*<4 4 2 4>")
  $ note (fast 8 (often rev "<e d c b4>")
  - 24
  )
  # cut 5
  # "bassWarsaw"
  # width "^33"
  # crushbus 5 (range 16 2.5 "^53")
  # midiG' "^82" 0 1.3
  # room 0.2
d7 -- TOYS TODO Rework classico louche
  $ degradeBy (0.99 - "^35")
  $ somecyclesBy "<0!4 1 1 0 1>" (often (# speed "-1"))
  $ slice 8 (stack [
    "<~!8 4!4 [4 5]!4>", -- Classico
    "<0!4 1 0 1 [0 1]>*<4!4 8 4 8 8>", -- Toy melod
    ""])
  $ "toys"
  # midiG' "^83" 0 0.7
d8 $ g -- Toy bogdan
  $ fix (|* gain 0.75) "hh"
  $ every' 16 15 (>| "~ ~ ~ bogdan:4")
  $ every' 16 9 ((>| "~ ~ ~ bogdan:2") . (|* gain 0.8))
  $ every' 16 1 (>| "~ ~ ~ bogdan:4")
  $ "~ ~ ~ hh"
  # room 0.5
  # legato 2
  # hpf 200
  # midiG' "^84" 0.5 1.1
  # leslie 0.2 # lrate 6.7 # lsize 0.7
d9 $ g -- Toy Dusty
  $ slice 24
  (cat [ -- TODO: Confirm/refine progression, add echoes, :)
    "0 0",
    "~ 1 ~ 1",
      "0 0 0 0",
      "~ 1 1 1",
      "~ 1 1 1",
      "~ 1 1 1",
      "~ 1 1 1",
      "~ 1 ~ 1 ~ 1 2 3"
  -- "2",
  -- "0 1*2 2 ~ ~ ~ ~ ~"
  ])
  $ "dusty"
  # cut 9
  # midiG' "^56" 0.3 1.1
