-- Algolia DevCon23 - LiveCoding demo
setcps (120/60/4)

-- you can control short samples
once $ "jazz bd cpu kick:5" # gain 1.3

-- or longer ones
once $ "scratch_short:30" # cut 4

-- Or synthetizers
once $ arpeggiate $ note "c'majPent'3" # "moog"
  # cut 1
  # room "0@3 0.8"
  # crush "10@3 7.5"

-- Then loops
d1 $ "jazz <cp [dr*<8 [8 16]>]>" # gain 1.2

-- Then songs...
-- SlowMo: Lent mouvement
do
resetCycles
setcps (60/60/4)
let rMask = (mask "t!6 <t!4 t?!3 f> <t t t <t? f>>")
let rLPF = (someCyclesBy "<0!32 1!8 0!16 1!8>" (# lpf (slow 8 $ range 5000 200 saw)))
let gLPF = (someCyclesBy "<0!48 1!16>" (# lpf (slow 16 $ range 6000 100 saw)))
let gR = (rMask . rLPF)
let gMask = mask "[t <t!4 t <f t!3> t t>!3 . t <f!4 t!4> <f f t t t f f t> <f!4 t f t t>]"
let gMaskB = mask "[t <t!4 t <f t!3> t t>!3 . t <f!4 t!4> <f f t t t f f t> t]"
let g = (gLPF . gMask)
let gB = (gLPF . gMaskB)
      d1 $ g $ gR
        $ juxBy 0.1 id
  $ "k ~ ~ k . ~" # "[reverbkick,tech:6]"
  # legato 1.25
  # lpf 1000
  # gain 0.7
d2 $ g $ gR
  $ mask "<f!8 t!24>"
  $ "[~ cp]*2"
  # note "-4"
  # "snare"
  # n "[1,2,12]"
  # gain 0.65
d3 $ g $ gR
  $ mask "<f!3 t f!4 t!7 [t f]>"
  $ fix (|* gain 0.5) "snare"
  $ "t*[[16!3 [<8!3 16!5> 32]]!3 32]"
  # "[tech,snare:12]"
  # gain 0.7
d4 $ gB -- Bassline
  $ jux ((# crush (slow 16 (range 10 5 saw))) . (|* gain 0.93)) -- ELECTRIC TWIN
  $ mask "<f!32 t!32>"
  $ whenmod 16 8 (superimpose ( -- Overdrone
    chop ("[<4!4 8!4>!3 1]!2")
    . (|* gain 0.8)
  ))
  $ note (scale "aeolian" (
    -- "[7, ~!7 <~!3 3 ~ 3 ~ 3>] . [4, ~!7 <~ 8>]" -- Simplified main theme
    "[7, [~!3 9]] . [4, [~!3 <[8 9] <[11 9] [10 9]>>]]" -- Simplified laggy theme
  ))
  # "bassWarsaw"
  # octave "<2!16 3!16>"
  # lpf 1200
  # room 0.13
  # gain (slow 32 $ range 0.9 0.65 saw)
  # pan 0.2
d5 $ g -- Rhodes base
  $ mask "<f!6 t f t!24>"
  $ someCyclesBy "<0!12 1!20>" ( superimpose ( -- aigus
    (|+| note (scale "aeolian" (
      "[0 <7!16 7(<2 2 3 3>,4)!16>]*4"
    + 7)))
  . (# "[FMRhodes1,FMRhodes2]")
    . (|* gain (slow 8 $ range 0.85 0.96 saw))
    . (|+ pan 0.1)
    . (whenmod 16 6 (# crushbus 5 (slow 64 (range 10 6.5 saw))))
  ))
  $ note (scale "aeolian" ( -- Organically grown main theme
    "[7, ~!7 <~!3 3 ~ 3 ~ 3>] . [4, ~!3 <~ <[~ 8] [8 9] [~ . 8 9] [~ . 9 8]>>]"
    ))
  # "FMRhodes1"
  # pan 0.6
  # gain (slow 32 $ range 0.68 0.85 saw)
  # octave 2
  # modIndex 0
  # room 0.3
d8 $ g -- Runny Maracas
  $ mask "<f!6 t f t!8 f!4 t!4 t!8>"
  $ jux (|* gain 0.5)
  $ whenmod 16 8 (always $ fast "2 . [2|4]")
  $ someCyclesBy "<1!16 0!16>" (often $ slow "2!3 1")
  $ fix ((|* gain 0.9) . (# release 0.8)) (n 9)
  $ "hh27*[8 . 16 8]"
  # n "2 <2 <[2|9] [9 <9 ~> <~ 9> 2]>>"
  # pan 0.8
  # gain (slow 32 $ range 0.5 0.7 (saw + perlin / 10))
d11 -- FX gratos
  $ "fx_commodore/2"
  # n "<0 .. 24>"
  # gain 0.35
  # pan "<0.2 0.8>"
  # hpf (slow 32 $ range 6000 0 saw)
  # room (range 0.1 0.53 perlin)
  # sz (range 0.2 0.8 perlin)
  # cut 11
d9 -- Nappe de fond
  $ mask "<t!24 f!8>"
  $ mask "<t!6 f f>"
  $ "90s_megafx:194"
  # gain (slow 32 $ range 0.5 0.3 saw)
  # room 0.8
  -- # delay 0.9
  # delayfb 0.85
  # delayt 0.25
  # sz 0.8
  # cut 9
d10
  $ mask "<f!8 t!24 f!16 t!16>"
  $ n "<18!2 [18@3 19] [19 18 19]>"
  # "jungle_vocals"
  # gain (slow 64 $ range 0.3 0.5 saw)
  # pan 0.2
  # room 0.2
  # cut 10


-- once $ "fx_commodore:1"
--   # gain 0.6
--   # cut 11
