
do
-- resetCycles
let width = pF "width"
let gMask = (midiOn "^41" (mask "t!3 <t!3 [f <t f>]>"))
let gMute = (midiOn "^73" (mask "f*16"))
let gMute2 = (midiOn "^74" (mask "f*16"))
let gMute3 = (midiOn "^75" (mask "f*16"))
let dMask = (whenmod 8 7 (mask "t t <t f> f"))
let gM1 = gMask . gMute
let gM2 = gMask . gMute2
let gM3 = gMask . gMute3
-- DARK NOIR CHORDS (matching the A->E->D pad progression)
let chords1 = "<Am9 Em7 [Dm9 Dm9]>"  -- Section 1: D held 2x
let chords2 = "<Am11 Em9 [Dm11 Dm11]>"  -- Section 2: Richer voicings
let chords = whenmod 128 64 (const $ jchord chords2) (jchord chords1)  -- Auto-switch at bar 32
let chordsRoot = whenmod 128 64 (const $ jroot chords2) (jroot chords1)
setcps (81/60/4)
d1 $ gF1 $ gM2 -- KICK TECHNO KICK TO DNB
  $ fast 2 
  $ midiOn "^42" (<| "k k k*<1 2 2 [4 2]> k*<1 <2 <4 [4 2]>>>")
  $ midiOff "^42" (<|"k . ~ k ~ <~ k>" )
  $ "[808bd:13,jazz]"
  # gain 1 
  # lpf 300
d2 $ gF1 $ gM1 
  $ midiOn "^43" (fast 2)
  $ "~ s ~ [s*<1!3 2> <~ <s s*[4 2]>>]" 
  # "hh27:12" 
  # cut 2 
  # gain 1.4
  # lpf 1500
  # legato 0.5
d3 $ gF1 $ gM1 
  $ degradeBy (slow 32 $ range 0.8 "-0.2" sine)
  $ midiOff "^44" (degradeBy "0 0.2 0.4 0.8 0 <0!4 0.5!4> 0.1 0")
  $ "dr*[<32!3 16> . 16 <32 [8 32]>]"
  # "h2ogmsn:4" 
  # gain (0.8 * "1 1 0.9 1 0.8 0.9 0.8 <0.9 0.8 0.9 [1.1|1]>")
d4 $ gF2 $ gM3
  $ struct "t ~ t t ~ t ~ t?"  -- Offbeat groove with probability
  $ chordsRoot  -- Auto-switches at bar 32!
  |+| n "0 7 0 <4 2> 7 0 <[0 12] [7 4]>"  -- Melodic bass linep
  -- |+| n "0 7 4 <0 2> 7 <0 4> [7|12] 0"  -- Alt: More melodic movement
  -- |+| n "0 ~ 7 ~ [4|0] ~ 7 <0 2>"  -- Alt: Sparser, half-time feel
  # "bassWarsaw"
  # octave 2
  # lpf (slow 16 $ range 300 800 sine)  -- Higher range for DNB
  # resonance (slow 8 $ range 0.1 0.3 sine)
  # room 0.3 # sz 0.4  -- Tighter reverb for punch
  # gain (1.3 * "<1 [0.9|1] 1 0.9>")  -- Consistent power with subtle variation
  # legato (slow 8 $ range 0.5 1 perlin) -- Not always full
  # crushbus 41 (range 16 3.5 "^53")
d5 $ gF3 $ gM3
  -- $ struct "<[t ~ ~ t? ~ t ~ ~] [t ~ t? ~ ~ ~ t ~]>"  -- Alternating patterns + random hits
  -- $ struct "t ~ [~|t] t ~ <t t?> ~ ~"  -- Alt: More random variation
  $ superimpose (id -- TODO ARPEGIATE PLZ)
  (midiOn "^90" (stut 4 "e" 0.9)) .
  struct "t(12,8)" .
  slow 4 
  . arp "up"
  . (# cut 51)
  . (|* gain (1.4 * "^34"))
  . (|+ octave 1)
  . (# pan 0.8)
  . (# modIndex 0)
  )
  $ struct "t(3,8) t(<3 4 5 8>,8,<0!3 1>)"
  $ slow 8 
  $ chords  -- Auto-switches at bar 32!
  # "FMRhodes1"
  # octave 4
  # modIndex (slow 8 $ range 0.1 5 sine)
  # gain (0.85 * "1 [0.8|1] [0.9|1.1] 1 <1 [0.7|0.9]> [0.8|1|1.2] 1 0.9")  -- Human dynamics
  # room 0.6 # sz 0.8 # dry 1.2
  # lpf (slow 24 $ range 2500 5500 sine)
  # pan ("<0.3 0.7 [0.5|0.6]>" + (slow 32 $ range (-0.1) 0.1 sine))  -- Drift + variation
  # attack (0.01 + (rand * 0.02))  -- Slight timing humanization
  # release (slow 16 $ range 0.8 1.5 sine)
  # crushbus 41 (range 16 3.5 "^54")
d7 $ gF3 $ gM3
  $ slow 16 $ chordsRoot  -- Very slow, ambient
  -- |+| n "[0,7] ~ ~ ~ [7,12]? ~ ~ ~"  -- Fifth chords, sparse hits 
  |+| n "[0,7] ~ [0,7,12]? ~ ~ ~ [7,12] ~"  -- Alt: More hits, triple voicing
  # "cbow"
  # octave "<3 3 4 3>"  -- Breathe with the progression
  # lpf (slow 32 $ range 1200 3000 sine)
  # lpq 0.3
  # room 0.8 # sz 0.9 # dry 0.8  -- Very ambient
  # gain (0.6 * "<1 [0.8|0.9] 1 [0.7|1]>")
  # pan (slow 24 $ range 0.2 0.8 sine)
  # attack (0.3 + (rand * 0.2))  -- Slow bowed attack
  # release 2
d8 $ gF1 $ gM1 
  $ midiOn "^60" (fast 2)
  $ slice 8 "0 1 2 3 4 <5 5*2 0 5> <6 6 3 6*2> <7 <~!3 7*<2 4>>>"
  $ midiOn "^36" (# "jungle_breaks:19")
  $ midiOn "^56" (# "jungle_breaks:45")
  -- $ loopAt 0.5 
  $ "breaks165" 
  # bandf 1400 
  # room 0.3 
  # dry 1.2 # sz 0.8
  # cut 8
  # gain 0.93
  # delay "<0 [0!3 0.4]>" 
  # delayfb 0.5 
  # delayt "[0.25]"
d11 $ gF3 $ gM3  
  $ degradeBy 0.1
  $ "noir_angels:15/4"
  # cut 11
  # gain 1.2
  # pan (slow 16 $ range 0.6 0.1 perlin)
  # delay 0.5 # delayt "1.25" 
  # delayfb 0.8
  # hpf (slow 32 $ range 0 5000 cosine)
d12 $ gF3 $ gM3  
  $ mask "<f f t f>"
  $ "noir_angels:4"
  # cut 12
  # gain 0.7
  # pan (slow 4 $ range 0.4 0.9 perlin)
  # hpf (slow 32 $ range 0 5000 sine)
  # room 0.4 # dry 1.1 # sz 0.8 # lpf 4500
  # delay 0.5 # delayt "1.25" # delayfb 0.8
