-- Good Morning Minneapolis
-- TODO Note default knob values
-- >1A 2A 3A 4A 5A 6A 7A 8A UP  DOWN
-- >1B 2B 3B 4B 5B 6B 7B 8B L   R
-- `29 30 31 32 33 34 35 36 106 107`
-- >1C 2C 3C 4C 5C 6C 7C 8C
-- `49 50 51 52 53 54 55 56`


-- XXX  XXX  XXX   XXX      XXX     pSust  fSpd    gunFreq
-- Dlay DFB  XXX   XXX      crBass  pRVel  cpStut  gunSpd
-- DJF  XXX  XXX   panDr    gmSiren  pLVel  cpSpd   gGuns
-- G    Kick Sn    DrRoll   Bass    Piano  CP      Fire
-- X    TCHN Stut  Wait/Run TCHN    XXX    XXX     XXX
do
-- region Nova Utils
let gF = 1.5 -- gain factor
let gG a = (gain (gF * "^77" * 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 novaOn  ch pat = someCyclesBy ch pat
let novaOff ch pat = someCyclesBy (1 - ch) pat
let gReverb = ((# room "^29") . (# sz (range 0 0.9 "^30")) . (# dry (range 0 2 "^13")))
let gLPF = (# lpf (min 10000 ((range 200 20400 ("^49")))))
let gHPF = (# hpf (max 0 (min 7500 ((range "-7500" 7500 ("^49"))))))
let gDJF = (gLPF . gHPF)
-- endregion Nova Utils
let g = (gDJF . gReverb)
-- let g = id
let melody = "<d4'min d4'min <a3'min g4'min e4'min> d4'min>"
let melodyFirst = "<d3 d3 <a3 g3 e3> d3>"
setcps 0.5
d1 $ g
  $ novaOn "^41"  (superimpose ((# "kick:5"))) -- TECHNO
  $ novaOn "^41"  (<| "k <k!4 ~!4> k <k!3 k*<1 2>>") -- TECHNO
  $ novaOff "^41" (<| "k . k(<1 <3 5>>,8,<0 4>)") -- Hip beat
  $ "reverbkick"
  # gM' 0 1 "^78"
d2 $ g
  $ mask "<f!8 t!8> <f!4 t!4> . t"
  $ novaOn "^75"  (slice 8 (run 8) . (loopAt 1 . (>| "breaks165")))
  $ sometimesBy ("^43") (mask "t(<8!2 12!2>,16)" . stut 4 0.9 "s")
  $ every' 8 7 (mask "f t!3" . jux rev)
  $ s "~ s ~ <~!4 s!4> ~ s*2 ~ s*2"
  # s "snare:20"
  # gM' 0 1.2 "^79"
  # pan 0.3
d3 $ g -- Drumroll opposé hit roll / hh when TECHNO
  $ novaOn "^41" ( -- TECHNO bells!
    whenmod 4 3 (
      sometimesBy "0!15 <0!4 1!4>" (# silence) .
      sometimesBy "0!14 <1!3 1> 0" ((# "hh:1") . (|* gain 1.4)) .
      fast 2) .
      (|* gain 0.75) .
    (>| "ho*8")
  )
  $ novaOff "^44" (fast "<4!3 <2 [2 <8 [8 16]>]>>") -- Waiting roll
  $ novaOn "^44" (fast "<16!3 [16 8]> [8 <8!3 16>]") -- Running roll
  $ s "drum:8"
  # pan (slow 8 $ range 0.1 0.9 (sine + "^52"))
  # gM' 0 1 "^80"
  # cut 3
d6 $ g -- Hit roll opposé drumroll
  $ 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)
    . (# velocity (range 0.35 0.75 ("^34" + (fast 4 perlin/8))))
    . (|* velocity 1.1)
    . (# room 0.2)
    . (/ sustain 2)
    . (# sz 0.8)
    . (|+ pan 0.15)
  )
  $ note (melody)
  # s "superpiano"
  # gM' 0 1.1 "^82"
  # velocity (range 0.35 0.60 ("^54" + (fast 4 perlin/8)))
  # sustain (max 0.45 $ min 1 (2 * range 0.15 1 "^18"))
  # room 0.4 # size 0.2
  # pan 0.5
d5 $ g -- Basse + Sirene
  $ sometimesBy ("^57") ( -- TECHNOPHILE
    chop "<2!3 4> <4!3 2>"
    -- . often (ply 4)
  )
  $ superimpose (
    slow 4
    . (# s "supersiren")
    . (-| note 12) -- 24 when crushed
    . (# gM' 0.2 0.8 ((
      "^81"  -- gain bass
      * (range 0.7 0.9 "^53") -- Modulated 5C
      )
      - (0.125 * "^57") -- When TECHNOPHILE
      ))
    . (# crush (range 10 3
       "^33"))
    . (# room 0.5)
    . (# size 0.8)
  )
  $ note (
    "0*2 0 . 0 <7 5 5 7> ~ 0"
    + melodyFirst
  )
  # s "supersaw"
  # voice 0.15
  # crush (range 10 2 "^33")
  # gM' 0.2 0.8 ("^81" * (range 1 0.45 "^53")) -- Modulated 5C
  # pan (slow 10 $ range 0.6 0.8 sine)
d7 $ g -- Claps fantome
  $ sometimesBy (range 0 0.25 "^55") (stut 4 0.9 "s")
  $ s "~ . cp*<1 1 2 1 1!3 2> ~"
  # room 0.2
  # sz (range 0.5 0.9 perlin)
  # dry 1.05
  # speed (range 0.125 1.25 "^35")
  # gM' 0 1 "^83"
  # lpf 2000
  # pan (slow 8 $ range 0.45 0.65 saw)
d8 $ g -- Gunfire
  $ sometimesBy "^20" (
    superimpose (const -- pistolets
      $ someCyclesBy 0.25 ( -- réplique
        off 0.5 (|+ gain 0.1)
      . (# room 0.25)
      )
      $ sometimes (stut 2 0.55 ("[s|e|h]")) -- écho
      $ s "~ ~ ~ snare:57"
      # speed (range 0.4 1 ("^36" + (slow 4 $ perlin/3)))
      # gM' 0 1 "^56"
      # cut 80
      # dry 1.02
      # pan (range 0.2 0.8 perlin)
    )
  )
  $ sometimes (off "h" id)
  $ s "fire"
  # begin (slow 4 "<0 0.2 0.5>")
  # cut 8
  # room 0.6 # size 0.4
  # speed (range 0.5 1.25 (segment 8 $ "^19" + perlin/4))
  # gM "^84"
  # delay 0.3 # delaytime (1/3) # delayfb 0.8
