-- Computer Riddim!#
-- Following instructions in http://studio.dubroom.org/tutorials-computerdub15.htm
-- Skipped: Chap 18 (Why?)
-- Skipped: Chap 21 (Too complex, rather live synth)
-- TODO: Chap 22 - From reggae to dub

do
-- region Nova Utils
let gFactor = 2
let gG a = (gain (gFactor * "^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 gDJF = (# djfbus 1 (range 0.05 0.95 "^49"))
-- 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) -- TODO djf2 separate instruments
let chords = "<[a5,c5,e5] [e4,g4,b4]>"
let gDelay = id
let gDelayD = id
setcps (140/60/4) -- keep it between 110-190 BPM. You won't be sorry you did.
-- resetCycles
d1
  $ g -- Kick
  $ superimpose ((# "kick:5")
  . (# crush (range 6 2.5 "^50"))
  . (|* gain (range 0 1 "^50")))
  $ midiOn  "^73" (<| "~ ~ k ~") -- 1D
  $ midiOn  "^74" (<| "k*2") -- 2D
  $ midiOn  "^75" (<| "k ~ ~ <~!3 k>. k ~ <~ k> <k ~>")-- RubADub+adjustements
  $ midiOn  "^41" (<| "k k k <k [<~ k> k]>") -- 4F
  $ midiOff "^41" (<| "k . k <~ [<~ k> <k ~>]>")-- RubADub
  $ "[jazz,tech:5]"
  # room 0.05
  # midiG' "^78" 0 1.05
d2
  $ g -- Snare
  $ (|- lpf 1000)
  $ midiOn "^42" (|<| "s*4")
  $ "~ <~!7 s> ~ ~ . s"
  # "[snare:50,snare:4]"
  # orbit 1
  # gM' 0.2 1.3 "^79"
d3 $ g -- Hats
  $ midiOn ("^43")  (slice 8 (run 8) . (loopAt 1) . (>| "breaks165"))
  $ every' 4 3 (
    sometimesBy "0 . 1 0!3" ((# "ho:2") . (|* gain 0.9))
    . sometimesBy "0 . 0 1 0 0" (|* gain 0)
  )
  -- FIXME(#94) d3 drives more controls than the grid gives it (BT3 only — BL1-3 are the family mutes). ^44 now belongs to another orbit, so this step STILL FIRES ACROSS COLUMNS — turning ^44 for its new owner also moves this. NOT commented out: this is a `$`-step and something above it is a partial application waiting for it, so removing it would stop the whole block compiling. Fold it onto d3's own control with gSel.
  -- FIXME(#94) d3 drives more controls than the grid gives it (BT3 only — BL1-3 are the family mutes). ^44 now belongs to another orbit, so this step STILL FIRES ACROSS COLUMNS — turning ^44 for its new owner also moves this. NOT commented out: this is a `$`-step and something above it is a partial application waiting for it, so removing it would stop the whole block compiling. Fold it onto d3's own control with gSel.
  $ midiOn ("^44")  (degradeBy (slow 4 $ range 0.9 0 saw) . (<|"h*16")) -- TODO Eclaircir
  $ midiOff ("^44") (<| "h*[8 . 8 <8 16 32 4>]")
  $ (|* gain "[1 0.9]*4") -- make sure that you reduce the velocity of the Hi Hat hit
  $ s "gretsch:4"
  -- # pan "^52"
  # cut 3
  # orbit 1
  # pan 0.2
  # gM' 0.2 1.25 "^80"
d4 $ g -- Bassline
  $ midiOn  "^44"  (>| note "[~ a4] <a4 e e a4> [~ <a4 c>] <a4 e>") -- Naif
  $ midiOff "^44" (>| note "<[~ a4@1.5 . a4 a4 e c] [e e . b4*<1 <2 4>>]>") -- simple+adjustements
  $ note "0" # "bass1:3"
  # cut 4
  # pan 0.7
  # lpq (range 0 0.33 "^32")
  # release 0.95
  # orbit 1
  # crushbus 41 (range 16 3.5 "^52")
  # midiG' "^81" 0.25 1
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
  # midiG' ("^82" * (range 0.25 1.5 "^33")) 0 1
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 4
  # octave 6
  # pan 0.74
  # 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 "^35")))
d8 -- Trompette lancinante
  $ g $ gDelayD
  $ degradeBy "^36"
  $ midiOn "^60" (mask "<f!3 t>")
  $ superimpose ((|- note 12) . (# cut 81) . (|* gain 0.95))
  $ note ("<g [<a d> bf d ~]> <g [~ g a]>" + "0 <12 0>"
  - 12)
  # "brass" # n "2"
  # gM' 0.2 1 "^83"
  # attack 0.5
  # cut 8
d9 -- CP
  $ midiOn "^60" (fast 2)
  $ (# lpf 2000)
  $ g
  $ whenmod 4 2 (superimpose ((# "clap") . (# lpf 4500) . (|* gain 0.8)))
  $ fast 2
  $ "~ cp"
  # gM' 0 1.1 "^84"
  # room 0.2
  # dry 0.9
  # lpf 2000


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