-- region wit val
do
d1 $ euclidOff
  (discretise 8 ((cF "49")*16))
  8 -- (round ("^29" * 16))
  0  -- (round ("^13" * 16))
  $ "jazz"

-- endregion


do
-- region Nova Utils
let gG a = (gain (1.2 * a)) -- gain Global
let gM' l h a = (gG (range l h a)) -- gain Modéré
let gM a = (gM' 0.2 0.8 a) -- gain Modéré doux
-- let gLPF = (# lpf (min 10000 ((range 200 20000 ("^49")))))
-- let gHPF = (# hpf (max 0 (min 7500 ((range "-7500" 7500 ("^49"))))))
-- let gDJF = (gLPF . gHPF)
let novaOn  ch pat = (someCyclesBy ch pat)
let novaOff ch pat = someCyclesBy (1 - ch) (pat)
-- endregion Nova Utils
let gDelayD = (# delay (range 0 5 "^13"))
let gDelayFB = (# delayfb (range 0 0.9 "^14"))
let gRoom = ((|+ room (range 0 0.5 "^29")) . (# dry 0.99))
let gSize = (|+ size (min 0 (range "-0.5" 0.5 "^29")))
let gDelay = (gDelayD . gDelayFB . (# delayt 0.25) . (# orbit 2))
-- let g = (gDJF . gRoom)
let g = (id)
let chords = "<[a5,c5,e5] [e4,g4,b4]>"
setcps (140/60/4) -- keep it between 110-190 BPM. You won't be sorry you did.
-- resetCycles
d1
  $ g -- Kick
  $ "jazz"
  -- $ euclid (cF_ "49") 8 -- TODO: Fails too! :(
  # gM' 0 1.2 "^77"
  # cut 1

d1
  -- $ mask (8 - ("49"))
  -- $ euclid (quantise 8 (range 1 8 $ cI 1 ("49")) ) 8
  $ fast (quantise 1 $ range 1 8 (cT 1 "49")) -- FIXME doesn't quantise!
  $ "jazz"
  # gain (1.2 * "^77")

once $ "jazz" # gain 1.2

once $ "drum:2" # gain 1.2

once $ "hh" # gain 1.5

once $ "ho" # gain 1

once $ "hc" # gain 1.1


d2
  $ g -- Snare
  $ (|- lpf 1000)
  $ (|/ lpf 2)
  $ novaOn "^43" (|<| "s*4")
  $ "~ <~!7 s> ~ ~ . s"
  # "[snare:50,snare:4]"
  # orbit 1
  # gM' 0.2 0.9 "^79"
d3 $ g -- Hats
  $ every' 4 3 (
    sometimesBy "0 . 1 0!3" ((# "ho:2") . (|* gain 0.9))
    . sometimesBy "0 . 0 1 0 0" (|* gain 0)
  )
  $ novaOn ("^76")  (slice 8 (run 8) . (loopAt 1) . (>| "breaks165"))
  $ novaOn ("^44")  (<|"h*8") -- TODO Eclaircir
  $ novaOff ("^44") (<| "h*[8 . 8 <8 16 32 4>]")
  $ (|* gain "[1 0.9]*4") -- make sure that you reduce the velocity of the second Hi Hat hit
  $ s "gretsch:4"
  -- # pan "^52"
  # cut 3
  # orbit 1
  # gM' 0.2 1.5 "^80"
d4 $ g -- Bassline
  $ novaOn  "^57"  (>| note "[~ a4] <a4 e e a4> [~ <a4 c>] <a4 e>") -- Naif
  $ novaOff "^57" (>| note "<[~ a4@1.5 . a4 a4 e c] [e e . b4*<1 <2 4>>]>") -- simple+adjustements
  $ note "0" # "bass1:3"
  # cut 4
  # pan 0.6
  # attack (range 0 1 "^53")
  # crush (range 16 4 "^53")
  # release 0.95
  # orbit 1
  # gM' 0.25 1.2 "^81"
d5 $ g $ gDelay -- Skank Piano
  $ whenmod 4 3 (sometimesBy "0 1 . 0" (
    (# note "[d5,g4,b4]") . (|* gain 0.8)
  ))
  $ "<[~ p*<1 1 1 <1 2>> ~ p*<1 1 2 1>]>"
  -- TODO FIX ALIGNMENT CONTRETEMPS DE LA REPETITION
  -- $ "<[~ p  p] [~ [p <~ p*<1 2>>] . ~ p]>"
  # "superpiano"
  # note chords
  # velocity 0.6
  # sustain 0.34
  # release 0.8
  # room 0.13 # sz 0.4
  # pan 0.4
  # gM' 0 1 ("^82" * (range 0.25 1.5 "^54"))
d6 $ g $ gDelay-- Skank Hammond
  $ ("0.125" ~>)
  $ fast 2
  $ note (("[0 12 0 <~!6 12!2>]" |+ (slow 2 chords)))
  # "superhammond"
  # gM' 0 0.8 ("[0 0.25 0 0]" |+ "^82" * (range 0 0.9 "^34"))
  # voice 6
  # octave 6
  # sustain 0.25
d7
  $ g $ gDelay -- Skank Guitar
  $ note "[~ <a'min!2 e'min!2>]*2"
  # "pluck:5"
  # octave 5
  # gM' 0 1 ("^82" * ((range 0.25 1.5 "^18")))
d8 -- Trompette lancinante
  $ g $ gDelay
  $ novaOn "^59" (mask "<f!3 t>")
  $ note ("<g [<a d> bf d ~]> <g [~ g a]>" + "0 <12 0>")
  # "brass" # n "2"
  # gM' 0.2 0.85 ("^55")
  # attack 0.5 # cut 8
d9 -- CP
  $ sometimesBy "^59" (fast 2)
  $ (# lpf 2000)
  $ g
  $ whenmod 4 2 (superimpose ((# "clap") . (# lpf 4500) . (|* gain 0.8)))
  $ fast 2
  $ "~ cp"
  # gM' 0 1.1 "^83"
  # room 0.2
  # dry 0.9
  # lpf 2000

once $ "brass:4" # gain 0.6 # cut 1

-- TODO: BELOW COPIED FROM MINNEAPOLIS
d6 $ g --
  $ every' 4 3 ( -- acceleration + cymbale
    fast "2 1" . (# n "0!3 1")
  . (|* gain "1!3 <0.65 0.8>")
  )
  $ s "hh(<3!4 5!4>,8)"
  # gM' 0 0 "^80"
  # pan 0.7
d4 $ g
  -- $ degradeBy "0 0.9!7" -- OUTRO
  $ mask "t(<1 2!2 4>,4)"
  $ superimpose (
    often (off 0.125 (|+ note "<0!3 12>"))
    . arp (slow 8 $ "<up down updown downup>")
    . (|+ note 36)
    . (# sustain 0.5)
    . (|* velocity 1.1)
    . (# sz 0.8)
    . (|+ pan 0.15)
  )
  $ note (melody)
  # s "superpiano"
  # gM' 0 1 "^82"
  # velocity 0.55
  # sustain 1
  # room 0.4 # size 0.2
  # pan 0.5
d5 $ g -- Basse + Sirene
  $ sometimesBy ("^57") ( -- TECHNOPHILE
    chop 4
    . often (ply 4)
    -- . (# crush (range 16 3.5 "^33"))
  )
  $ superimpose (
    slow 4
    . (# s "supersiren")
    . (-| note 12) -- 24 when crushed
    . (# gM' 0 0.8 ((
      "^81"  -- gain bass
      * (range 0.6 0.9 "^53") -- Modulated 5C
      )
      - (0.125 * "^57") -- When TECHNOPHILE
      ))
    . (# room 0.5)
    . (# size 0.8)
  )
  $ note (
    "0*2 0 . 0 <7 5 5 7> ~ 0"
    + melodyFirst
  )
  # s "supersaw"
  # voice 0.02
  # crush (range 16 3.5 "^33")
  # gM' 0 0.8 "^81"
  # pan (slow 10 $ range 0.6 0.8 sine)
d7 $ g -- Claps fantomes
  $ s "~ . cp*<1 1 2 1 1!3 2> ~"
  # room (range 0.2 0.95 "^55")
  # sz (range 0.5 0.9 perlin)
  # dry 1.05
  # gM' 0 1 "^83"
  # pan (slow 8 $ range 0.45 0.65 saw)
d8 $ g -- Gunfire
  $ sometimesBy "^20" (
    superimpose (const -- pistolets
      $ sometimes ( -- réplique
        off 0.5 (|+ gain 0.1)
      . (# room 0.25)
      )
      $ often (stut 2 0.85 (1/16)) -- écho
      $ s "~ ~ ~ snare:57"
      # speed (range 0.4 1 ("^36" + perlin/4))
      # gM' 0 1 ("^56")
      # cut 80
      # dry 1.02
      # pan (range 0.2 0.8 perlin)
    )
  )
  $ s "fire"
  # begin (slow 4 "<0 0.2 0.5>")
  # cut 8
  # room 0.6 # size 0.4
  # speed (range 0.5 1 ("^35" + perlin/4))
  # gM "^84"
  # delay 0.3 # delaytime (1/3) # delayfb 0.8
