-- Accel: get faster, yet calmer
-- Tags: Techno, dark bass, synthe, sirenes
-- Ready: 7/10 (Melody+, Variations=, Parts=)
resetCycles

-- region Part 1: setup accel vivant
do
  solo 1 -- kick
  solo 2 -- snare
  solo 3 -- drumroll
  solo 4 -- bass
  unsolo 5 -- siren
  unsolo 6 -- clap
  unsolo 7 -- synth
  -- let mKick = "<1!32 0!15 [0 1] 1!64 0.9!4 0.8!4 0.7!4 0.6!4>"
  let gKick = 0.75 -- /128 On off semi-onon fadeout
  let gSnare = 0.65
  let gHats = 0.85
  let gDrums = 0.75
  let gBass = 0.65 * "<1!16 <[1 0]*4 [0 1]*4>!8 1!8>"
  let gSiren = 0.85 * "<0!64 0.7!32 0.6!32 0.5!32 0.4!32>"
  let gSynth = 0.65
  let gClap = 0.9
  let melody = "<0 0 0 0 2 2 4 -2>"
  setcps 0.5 -- TECHNOOO
  d1 -- Kick
    $ whenmod 16 14 (# silence) -- break frequent
    $ n "0 0 <0!3 0?> 0"
    # s "kick:5"
    # gain gKick
    # lpf (slow 16 $ range 500 200 isaw)
  d2 -- Snares + hats
    $ sometimesBy "0 0.25 . 0.5" (juxBy 0.25 rev)
    $ whenmod 64 16 ( -- Hats!
      superimpose (const
      $ whenmod 64 48 (-- disparition
        # gain (gHats * range 0.8 0.2 sine)
      )
      $ sometimes (# room 0.2)
      $ sometimes (fast 2)
      $ euclid (slow 4 $ "<5 7 8>") 8
      $ s "linnhats" # n (slow 2 $ "<0 1 [2 0]>")
      # gain gHats
      ))
    $ n "~ <3 3 [3 ~ 3 2] 3> ~ [2 <~ 3?>]"
    # s "sn"
    # pan (slow 8 $ range 0.3 0.6 sine)
    # dry 1
    # gain gSnare
  d3 -- Drumroll chuchoté
    $ every' 4 3 (juxBy 0.25 (|- gain 0.2))
    $ fast ( -- cycle/4 ralenti-accelere
      slow 4 $ "<1 [0.5 2] [2 0.5 1 2] [1 0.5 2]>"
      )
    $ s "dr*8"
    # s "ifdrums:1"
    # pan 0.4
    # gain gDrums
  d4 -- Basse
    $ superimpose ( -- Echo octave
      (|+ note 12)
    . (|- gain 0.2)
    . (# room 0.5)
    )
    $ note (scale "aeolian"
    (
      whenmod 16 8 (iter 6)
      "0 [4 5] 0"
    + melody
    ) - 36)
    # s "supersaw"
    # voice 0.1
    # gain gBass
  d5 -- Siren theme
    $ whenmod 128 64 (# gain (gSiren))
    $ slow 2
    $ note (scale "aeolian"
    (
    melody
    ) - 36)
    # s "supersiren"
    # sustain 4
    # gain 0
  d6 -- claps graduels sur 64
    -- $ whenmod 64 48 (>| n "~ 0*2 ~ 0*2")
    -- $ whenmod 64 40 (>| n "~ 0?*2 ~ 0?*2")
    -- $ whenmod 64 32 (>| n "~ 0 ~ 0*2")
    -- $ whenmod 64 0  (>| n "~")
    $ whenmod 16 13 (# note "<2 4 6>")
    $ n "~ ~ ~ 0"
    # s "clap:1"
    # gain gClap
    # lpf 4000
  d7 -- synthe echos electrique
    $ superimpose (
      (# s "supercomparator") .
      (# voice (slow 64 $ sine * 8)) . (|- note 12)
    )
    $ whenmod 16 8 (sometimes (juxBy 0.4 (|+ note 12))) -- jux eclairs!
    $ degradeBy "<1 1 1 0> <[1 1 1 0] [1 0] 0>"
    $ n "0*16"
    # voice "0.1"
    # s "supersquare"
    # note (scale "aeolian"
    "<0 0 0 0 2 2 4 -2>")
    # gain gSynth

once $ s "abstract:1" # cut 1 # gain 0.6
  -- endregion

-- region Part 2: Dry Melancholia
do
  solo 1 -- kick
  solo 2 -- snare + h
  solo 3 -- drumroll
  solo 4 -- bass
  solo 5 -- siren
  solo 6 -- clap
  solo 7 -- synth
  let gKick = 0.7 -- /128 On off semi-onon fadeout
  let gSnare = 0.65
  let gHats = 0.75
  let gBass = 0.6
  let gSiren = 0.6
  let gSynth = 0.9 * "<0!16 <[1 0]*4 [1? 1]*4>!16 1!32>"
  let gClap = 0.8
  let melody = "<0 0 0 0 2 2 4 -2>"
  setcps 0.5 -- TECHNOOO
  d1 -- Kick
    $ whenmod 16 14 (# silence) -- break frequent
    $ n "0 0 <0!3 0?> 0"
    # s "kick:5"
    # gain gKick
    # lpf (slow 16 $ range 500 200 isaw)
  d2 -- Snares + hats
    $ n "~ <3*2 3(<1 3>,8) 3 [3 ~ 3 2]> ~ [2 <~ 3?>]"
    # s "sn"
    # pan (slow 8 $ range 0.3 0.6 sine)
    # dry 1
    # gain gSnare
  d3 -- Drum metronome chuchoté parfois fou
    $ someCyclesBy "<0 0.5!2 0.75>" (fast "<2 2 2 [2|4]>")
    $ s "dr*4"
    # s "ifdrums:1"
    # pan 0.4
    # gain 0.9
    # room (slow 16 $ range 0 0.15 saw)
  d4 -- Basse
    $ superimpose ( -- Echo octave
      (|+ note 12)
    . (|- gain 0.2)
    . (# room 0.5)
    )
    $ note (scale "aeolian"
    (
      "0(2,8) [5 4]*<1!3 2> <0!4 2 5>"
    + melody
    ) - 36)
    # s "supersaw"
    # voice 0.1
    # gain gBass
  d5 -- Siren choppee
    $ mask "t(1,4,3)"
    $ segment 4
    $ slow 2
    $ note (scale "aeolian"
    (
    melody
    ) - 36)
    # s "supersiren"
    # sustain 4
    # gain gSiren
    # cut 5

-- endregion

-- region Part 3: Folie
do
  solo 1 -- kick
  unsolo 2 -- snare
  unsolo 3 -- drumroll
  solo 4 -- bass
  unsolo 5 -- siren
  solo 6 -- clap
  solo 7 -- synth
  let gKick = 0.6 -- /128 On off semi-onon fadeout
  let gSnare = 0.65
  let gHats = 0.75
  let gBass = 0.6
  let gSiren = 0.2 * "<0.7!32 0.6!32 0.5!32 0.4!32>"
  let gSynth = 1.3 -- * "<0!16 <[1 0]*4 [1? 1]*4>!16 1!32>"
  let gClap = 0.8
  let melody = "<0 0 0 0 2 2 4 -2>"
  setcps 0.5 -- TECHNOOO
  d1 -- Kick
    $ whenmod 16 14 (# silence) -- break frequent
    $ n "0 0 <0!3 0?> 0"
    # s "kick:5"
    # gain gKick
    # lpf (slow 16 $ range 500 200 isaw)
  d2 -- Snares + hats
    $ n "~ <3*2 3(<1 3>,8) 3 [3 ~ 3 2]> ~ [2 <~ 3?>]"
    # s "sn"
    # pan (slow 8 $ range 0.3 0.6 sine)
    # dry 1
    # gain gSnare
  d3 -- Drum metronome chuchoté parfois fou
    $ someCyclesBy "<0 0.5!2 0.75>" (fast "<2 2 2 [2|4]>")
    $ s "dr*4"
    # s "ifdrums:1"
    # pan 0.4
    # gain 0.9
    # room (slow 16 $ range 0 0.15 saw)
  d4 -- Basse
    $ superimpose ( -- Echo octave
      (|+ note 12)
    . (|- gain 0.2)
    . (# room 0.5)
    )
    $ note (scale "aeolian"
    (
      "0(2,8) [5 4]*<1!3 2> <0!4 2 5>"
    + melody
    ) - 36)
    # s "supersaw"
    # voice 0.1
    # gain gBass
  d5 -- Siren choppee
    $ segment "<2!4 4!2 8!2>"
    $ slow 2
    $ note (scale "aeolian"
    (
    melody
    ) - 36)
    # s "supersiren"
    # sustain 4
    # gain gSiren
    # cut 5

d7 -- synthe echos electrique
$ superimpose (
  (# s "supercomparator") .
  (# voice (slow 64 $ sine * 8)) . (|- note 12)
)
$ whenmod 16 8 (sometimes (juxBy 0.4 (|+ note 12))) -- jux eclairs!
$ n "0*12"
# voice "0.1"
# s "supersquare"
# note (scale "aeolian"
"<0 0 0 0 2 2 4 -2>" + "[0 <1!3 3>]")
# gain gSynth

-- endregion

-- region Part 4: Résolution
do
unsolo 1 -- kick
unsolo 2 -- snare
solo 3 -- drumroll
solo 4 -- bass
unsolo 5 -- choeur -- FIXME
solo 6 -- clap
solo 7 -- synth
let mKick = "<1!32 0!15 [0 1] 1!64 0.9!4 0.8!4 0.7!4 0.6!4>"
let gKick = 0.75 * mKick -- /128 On off semi-onon fadeout
let gSnare = 0.6
let gHats = 0.7
let gBass = 0.7 * "<1!16 <[1 0]*4 [0 1]*4>!8 1!8>"
let gSiren = "<0!64 0.7!32 0.6!32 0.5!32 0.4!32>"
let gSynth = 0.55 * "<0!16 <[1 0]*4 [1? 1]*4>!16 1!32>"
let gClap = 0.8
let melody = "<0 0 0 0 2 2 4 -2>"
setcps 0.5 -- TECHNOOO
d1 -- Kick
  $ whenmod 16 14 (# silence) -- break frequent
  $ n "0 0 <0!3 0?> 0"
  # s "kick:5"
  # gain gKick
  # lpf (slow 16 $ range 500 200 isaw)
d2 -- Snares + hats
  $ sometimesBy "0 0.25 . 0.5" (juxBy 0.25 rev)
  $ whenmod 64 16 ( -- Hats!
    superimpose (const
    $ whenmod 64 48 (-- disparition
      # gain (gHats * range 0.8 0.2 sine)
    )
    $ sometimes (# room 0.2)
    $ sometimes (fast 2)
    $ euclid (slow 4 $ "<5 7 8>") 8
    $ s "linnhats" # n (slow 2 $ "<0 1 [2 0]>")
    # gain gHats
    ))
  $ n "~ <3 3 [3 ~ 3 2] 3> ~ [2 <~ 3?>]"
  # s "sn"
  # pan (slow 8 $ range 0.3 0.6 sine)
  # dry 1
  # gain gSnare
d3 -- Drumroll chuchoté
  $ every' 4 3 (juxBy 0.25 (|- gain 0.2))
  $ fast ( -- cycle/4 ralenti-accelere
    slow 4 $ "<1 [0.5 2] [2 0.5 1 2] [1 0.5 2]>"
    )
  $ s "dr*8"
  # s "ifdrums:1"
  # pan 0.4
  # gain 0.7
d4 -- Basse
  $ superimpose ( -- Echo octave
    (|+ note 12)
  . (|- gain 0.2)
  . (# room 0.5)
  )
  $ note (scale "aeolian"
  (
    whenmod 16 8 (iter 6)
    "0 4 0"
  + melody
  ) - 36)
  # s "supersaw"
  # voice 0.1
  # gain gBass
d7 -- synthe echos electrique
    $ superimpose (
      (# s "supercomparator") .
      (# voice (slow 64 $ sine * 8)) . (|- note 12)
    )
    $ whenmod 16 8 (sometimes (juxBy 0.4 (|+ note 12))) -- jux eclairs!
    $ n "0*0"
    # voice "0.1"
    # s "supersquare"
    # note (scale "aeolian"
    "<0 0 0 0 2 2 4 -2>"
    )
    # gain gSynth
-- endregion

-- region Part 5: Restart minimal
do
  unsolo 1 -- kick
  unsolo 2 -- claps
  unsolo 3 -- drumroll
  unsolo 4 -- bass
  unsolo 5 -- Choeurs
  unsolo 6 -- piano
  solo 7 -- synth
  solo 8 -- Pistolets
  setcps 0.5 -- TECHNOOO
  d1 -- Kick
    $ whenmod 16 14 (# silence) -- break frequent
    $ n "0 0 <0!3 0?> 0" # s "reverbkick"
    # lpf 500
    # gain 0.7
  d2
    $ whenmod 4 3 (sometimesBy "0 0.75" (ply 2))
    $ fast 2 $ s "~ cp" # gain 0.8
  d3
    $ whenmod 32 28 (# gain 0)
    $ whenmod 16 8 (fast 2)
    $ fast "1 <1!3 2>"
    $ s "ifdrums:1*4"
    -- # gain 0.9
  d4 -- Basse nappes + arp aigues crushées
    $ superimpose (
      (# crush (range 1 3 perlin)) .
      swing "<3 2>" .
      fast 4 .
      arp "<pinkyup updown downup speedupdown>"
      . (|* gain 0.8)
      . every 2 (|+ note 12)
      . (|+ note 12)
      )
    $ note (scale "lydian"
    "<c4'maj e4'maj c4'maj e4'min>/4")
    # s "supersaw"
    # voice 0.01
    # gain (slow 64 $ range 0.45 0.5 sine)
  d5 -- Choeurs
    $ note (scale "lydian"
    "<c4'maj e4'maj c4'maj e4'min>/4")
    # s "moogBass"
    # gain (slow 100 $ range 0.65 0.9 cosine)
  d6
    $ mask "t([1|2|2|4|8],8)"
    $ often (off 0.25 rev)
    $ off (0.125) (|+ note
      (slow 4 $ "<12 7>")
      )
    $ note (scale "lydian"
    "<c4'maj e4'maj c4'maj e4'min>")
    # s "superpiano" # velocity 0.5
  d8 -- Random pistolets fin boucle 64
    $ whenmod 64 48 (sometimes (# gain 0.8))
    $ every' 4 3 ((sometimes $ jux rev) . (fast 2))
    $ sometimesBy "0 0.5" ((ply 2) . (|+ note "[-12|+6]"))
    $ s "~ s(<3!3 5>,8,3)"
    # s "snare:57"
    # pan 0.6
    # gain 0
-- endregion

-- region Part 6: Finish breakbeat
do
  solo 1 -- kick
  unsolo 2 -- claps
  unsolo 3 -- drumroll
  solo 4 -- bass -- FIXME
  unsolo 5 -- Choeurs
  unsolo 6 -- piano
  unsolo 7 -- synth
  solo 8 -- Pistolets
  setcps 0.5 -- TECHNOOO
  d1
    $ whenmod 4 3 (iter 4)
    $ loopAt 2
    -- $ slice 8 "[0(3,8) 1, 2(1,8)]"  -- finish [1]
    $ slice 8 "1"  -- finish [1]
    $ s "break"
    # gain 0.75
  d2
    $ whenmod 4 3 (sometimesBy "0 0.75" (ply 2))
    -- $ fast 2
    $ s "~ cp"
    # lpf (slow 32 $ range 20 20000 saw)
    # hpf (slow 64 $ range 200 1000 isaw)
    # gain 0.8
  d3
    $ whenmod 32 28 (# gain 0)
    $ whenmod 16 8 (fast 2)
    $ fast "1 <1!3 2>"
    $ s "ifdrums:1*4"
    # gain 0.7
  d4 -- Basse nappes + arp aigues
    $ note (scale "lydian"
    "<c4'maj e4'maj c4'maj e4'min>/4")
    # s "supersaw"
    # voice 0.01
    # gain 0
  d5 -- Choeurs
    $ note (scale "lydian"
    "<c4'maj e4'maj c4'maj e4'min>/4")
    # s "moogBass"
    # gain 0.8
  d6
    $ never (off 0.25 rev)
    $ rarely (off (0.125) (|+ note
      (slow 4 $ "<12 7>")
    ))
    $ note (scale "lydian"
    "<c4'maj e4'maj c4'maj e4'min>")
    # s "superpiano" # velocity 0.55
  d8 -- Random pistolets fin boucle 64
    $ whenmod 64 48 (sometimes (# gain 0.6))
    $ every' 4 3 ((sometimes $ jux rev) . (fast 2))
    $ sometimesBy "0 0.5" ((ply 2) . (|+ note "[-12|+6]"))
    $ s "~ s(<3!3 5>,8,3)"
    # s "snare:57"
    # pan 0.6
    # gain 0
-- endregion