# (A) Drum sequencer

# 

# INPUTS:
#  I1: [Clock]
#  I2: [Reset]

# OUTPUTS:
#  O1: [Frq mod] Frequency shifter modulation
#  O3: [PC Lvl]
#  O4: [Duck]
#  O5: [HH Acc]
#  O6: [SD Velo] SD Velocity
#  O7: [PC Trig]
#  O8: [PC BW] PC Bandwidth

# GATES ON MODULE 1:
#  G1.1: [BD Trig]
#  G1.2: [BD Acc]
#  G1.3: [SD Trig]
#  G1.4: [HC Trig]
#  G1.5: [HO Trigg]
#  G1.6: [M Clk]
#  G1.7: [CL Trig]

# CONTROLLER 1:
#  P1.1: [Morphs]
#  P1.2: [Activity]
#  B1.1: [BD]
#  B1.2: [Alt]
#  B1.3: [SD]
#  B1.4: [Alt 2|4]
#  B1.5: [HH]
#  B1.6: [Length]
#  B1.7: [CL]
#  B1.8: [Accent]

# CONTROLLER 2:
#  P2.1: [PC Level anim] Animation for the level of the PC voice
#  P2.2: [PC Bandwid anim] Animation of the bandwidth of the PC voice (same source as P2.1)
#  B2.1: [DB Fills]
#  B2.2: [Ducking] Choose to use either DB trigger or clock/4
#  B2.3: [DB Rolls]
#  B2.4: [SD->CL]
#  B2.5: [HH x2]
#  B2.6: [PC BW] If on the bandwidth for the PC voice is randomized, otherwise (off) it's determined by the accents
#  B2.7: [M 2|4|6]
#  B2.8: [PC]

# CONTROLLER 3:
#  P3.1: [Dejavu]
#  P3.2: [Fills]

# CONTROLLER 4:
#  P4.1: [DB Variation]
#  P4.2: [DB Activity]

# CONTROLLER 5:
#  P5.1: [SD Rolls]
#  P5.2: [SD Offbeats]

# CONTROLLER 6:
#  P6.1: [SD Variation]
#  P6.2: [SD Activity]

# CONTROLLER 7:
#  P7.1: [HH Variation]
#  P7.2: [HH Activity]

# CONTROLLER 8:
#  P8.1: [HH Accents]
#  P8.2: [Freq Modulat]

# CONTROLLER 9:
#  P9.1: [PC Variation]
#  P9.2: [PC Activity]

[p2b8]
[p2b8]
[p2b8]
[p2b8]
[p2b8]
[p2b8]
[p2b8]
[p2b8]
[p2b8]

# -------------------------------------------------
# Inputs
# -------------------------------------------------

# [copy]
#   input = I1
#   output = _CLOCK

[gatetool]
    gatelength = 0.01
    inputtrigger = I1
    outputgate = _CLOCK

[copy]
    input = I2
    output = _RESET

# -------------------------------------------------
# Controls
# -------------------------------------------------

[pot]
    notch = 0.1
    pot = P1.2
    output = _POT_ACTIVITY

[pot]
    notch = 0.1
    pot = P4.2
    output = _POT_ACTIVITY_BD

[pot]
    notch = 0.1
    pot = P6.2
    output = _POT_ACTIVITY_SD

[pot]
    notch = 0.1
    pot = P7.2
    output = _POT_ACTIVITY_HH

[pot]
    notch = 0.1
    pot = P9.2
    output = _POT_ACTIVITY_PC

[mixer]
    input1 = _POT_ACTIVITY
    input2 = -0.5
    output = _ACTIVITY

[button]
    button = B1.4
    led = L1.4
    offvalue = 2
    onvalue = 4
    output = _ALTERNATE_BARS

[copy]
    input = 1
    output = _BRANCHES

[copy]
    input = B1.8
    output = _ACCENTS

[button]
    button = B1.1
    led = L1.1
    inverted = _BD_UNMUTED

[button]
    button = B1.3
    led = L1.3
    inverted = _SD_UNMUTED

[button]
    button = B1.5
    led = L1.5
    inverted = _HH_UNMUTED

[button]
    button = B2.8
    led = L2.8
    inverted = _PC_UNMUTED

[button]
    button = B1.2
    states = 1
    led = L1.2
    output = _ALT_BUTTON

# -------------------------------------------------
# Bass drum (BD)
# -------------------------------------------------

[button]
    button = B2.3
    led = L2.3
    onvalue = 0.5
    output = _BD_ROLLS

[button]
    button = B2.1
    led = L2.1
    onvalue = P3.2
    offvalue = 0
    output = _BD_FILLS

[algoquencer]
    clock = _CLOCK
    reset = _RESET
    branches = _BRANCHES
    branch = _BRANCH
    trigger = _BD_TRIGGER
    accent = G1.2
    morphs = P1.1
    dejavu = P3.1
    fills = _BD_FILLS
    fillsled = _FILLS_LED_BD
    fillorder = 3
    activity = _POT_ACTIVITY_BD + _ACTIVITY
    variation = P4.1
    rolls = _BD_ROLLS
    rollcount = 1
    lengthbutton = B1.6
    accentbutton = _ACCENTS
    alternatebutton = _ALT_BUTTON
    alternatebars = _ALTERNATE_BARS
    accenthigh = 5V
    button1 = B3.1
    button2 = B3.2
    button3 = B4.1
    button4 = B4.2
    button5 = B3.3
    button6 = B3.4
    button7 = B4.3
    button8 = B4.4
    button9 = B3.5
    button10 = B3.6
    button11 = B4.5
    button12 = B4.6
    button13 = B3.7
    button14 = B3.8
    button15 = B4.7
    button16 = B4.8
    led1 = L3.1
    led2 = L3.2
    led3 = L4.1
    led4 = L4.2
    led5 = L3.3
    led6 = L3.4
    led7 = L4.3
    led8 = L4.4
    led9 = L3.5
    led10 = L3.6
    led11 = L4.5
    led12 = L4.6
    led13 = L3.7
    led14 = L3.8
    led15 = L4.7
    led16 = L4.8
    barled1 = R5
    barled2 = R6
    barled3 = R7
    barled4 = R8

[copy]
    input = _BD_TRIGGER * _BD_UNMUTED
    output = G1.1

[copy]
    input = _BRANCH * 0.2
    output = R3

# -------------------------------------------------
# Snare drum (SD)
# -------------------------------------------------

[algoquencer]
    clock = _CLOCK
    reset = _RESET
    branches = _BRANCHES
    trigger = _SD_TRIGGER
    rollvelocity = _ROLL_VELO
    morphs = P1.1
    dejavu = P3.1
    offbeats = P5.2
    fills = P3.2
    fillsled = _FILLS_LED_SD
    fillorder = 3
    activity = _POT_ACTIVITY_SD + _ACTIVITY
    variation = P6.1
    rolls = P5.1
    rollcount = 1
    rollsteps = 2
    rollstartvelo = 0.5V
    lengthbutton = B1.6
    accentbutton = _ACCENTS
    alternatebutton = _ALT_BUTTON
    alternatebars = _ALTERNATE_BARS
    button1 = B5.1
    button2 = B5.2
    button3 = B6.1
    button4 = B6.2
    button5 = B5.3
    button6 = B5.4
    button7 = B6.3
    button8 = B6.4
    button9 = B5.5
    button10 = B5.6
    button11 = B6.5
    button12 = B6.6
    button13 = B5.7
    button14 = B5.8
    button15 = B6.7
    button16 = B6.8
    led1 = L5.1
    led2 = L5.2
    led3 = L6.1
    led4 = L6.2
    led5 = L5.3
    led6 = L5.4
    led7 = L6.3
    led8 = L6.4
    led9 = L5.5
    led10 = L5.6
    led11 = L6.5
    led12 = L6.6
    led13 = L5.7
    led14 = L5.8
    led15 = L6.7
    led16 = L6.8
    accent = _SD_ACCENT_OUT
    accentlow = 0.2
    accenthigh = 1

[copy]
    input = _SD_TRIGGER * _SD_UNMUTED
    output = G1.3

[ifequal]
    input1 = _ROLL_VELO
    input2 = 1
    ifequal = _SD_ACCENT_OUT
    else = 0.2
    output = O6

# -------------------------------------------------
# Hi Hats (HH)
# -------------------------------------------------

[button]
    button = B2.5
    led = L2.5
    output = _HH_ROLLS
    onvalue = 0.5
    offvalue = 0

[algoquencer]
    clock = _CLOCK
    reset = I2
    trigger = _HH_TRIGGER
    accent = _HH_ACCENTS
    branches = _BRANCHES
    repeats = 2
    morphs = P1.1
    dejavu = P3.1
    activity = _POT_ACTIVITY_HH + _ACTIVITY
    variation = P7.1
    lengthbutton = B1.6
    accentbutton = _ACCENTS
    alternatebutton = _ALT_BUTTON
    alternatebars = _ALTERNATE_BARS
    alternaterepeats = 1
    rolls = _HH_ROLLS
    rollcount = 1
    button1 = B7.1
    button2 = B7.2
    button3 = B8.1
    button4 = B8.2
    button5 = B7.3
    button6 = B7.4
    button7 = B8.3
    button8 = B8.4
    button9 = B7.5
    button10 = B7.6
    button11 = B8.5
    button12 = B8.6
    button13 = B7.7
    button14 = B7.8
    button15 = B8.7
    button16 = B8.8
    led1 = L7.1
    led2 = L7.2
    led3 = L8.1
    led4 = L8.2
    led5 = L7.3
    led6 = L7.4
    led7 = L8.3
    led8 = L8.4
    led9 = L7.5
    led10 = L7.6
    led11 = L8.5
    led12 = L8.6
    led13 = L7.7
    led14 = L7.8
    led15 = L8.7
    led16 = L8.8

[mixer]
    input1 = _FILLS_LED_BD
    input2 = _FILLS_LED_SD
    output = R4

# Open HH = HH plus Accent
[logic]
    input1 = _HH_TRIGGER * _HH_UNMUTED
    input2 = _HH_ACCENTS
    and = G1.5

# Closed HH = HH without Accent
[logic]
    input1 = _HH_ACCENTS
    nand = _HH_NO_ACC

[logic]
    input1 = _HH_TRIGGER * _HH_UNMUTED
    input2 = _HH_NO_ACC
    and = G1.4

[switch]
    reset = _RESET
    forward = _CLOCK
    input1 = P8.1 * -1 + 1
    input2 = P8.1
    output1 = O5

# -------------------------------------------------
# Percussion (PC)
# -------------------------------------------------

[button]
    button = B2.6
    offvalue = _PC_ACCENTS
    onvalue = _PC_RANDOM_BW
    led = L2.6
    output = _PC_MODULATION

[random]
    output = _PC_RANDOM_BW
    minimum = 0
    maximum = 1
    steps = 2
    clock = _PC_TRIGGER * _PC_UNMUTED

[slew]
    input = _PC_MODULATION * P2.2
    linear = O8
    slew = 0.005

[slew]
    input = _PC_MODULATION * P2.1
    linear = O3
    slew = 0.005

[algoquencer]
    clock = _CLOCK
    reset = _RESET
    trigger = _PC_TRIGGER
    accent = _PC_ACCENTS
    branches = _BRANCHES
    repeats = 2
    morphs = P1.1
    dejavu = P3.1
    activity = _POT_ACTIVITY_PC + _ACTIVITY
    variation = P9.1
    lengthbutton = B1.6
    accentbutton = _ACCENTS
    alternatebutton = _ALT_BUTTON
    alternatebars = _ALTERNATE_BARS
    button1 = B9.1
    button2 = B9.2
    button3 = B9.3
    button4 = B9.4
    button5 = B9.5
    button6 = B9.6
    button7 = B9.7
    button8 = B9.8
    led1 = L9.1
    led2 = L9.2
    led3 = L9.3
    led4 = L9.4
    led5 = L9.5
    led6 = L9.6
    led7 = L9.7
    led8 = L9.8

# [gatetool]
#   inputtrigger = _PC_TRIGGER
#   outputgate = O7
#   gatelength = 0.0001

[flipflop]
    toggle = _PC_TRIGGER * _PC_UNMUTED
    output = _PC_TRIGGER_EDGED

[copy]
    input = _PC_TRIGGER_EDGED * _PC_UNMUTED
    output = O7

# [contour]
#   trigger = _PC_TRIGGER
#   release = P8.2
#   output = O7

# [button]
#   button = _PC_TRIGGER
#   output = O7
#   startvalue = 0

# [copy]
#   input = _PC_BW_UNSLEWED + 0.5
#   output = _PC_BW_MOD

[droid]
    lpfilter7 = 0

# [contour]
#   trigger = _PC_TRIGGER
#   attack = 0.04
#   release = P2.1 * _PC_BW_MOD
#   output = O3
#   level = 5V

# [switch]
#   input1 = 0
#   input2 = -1
#   offset = L2.8
#   output1 = O3

# -------------------------------------------------
# Claps (CL)
# -------------------------------------------------

[sequencer]
    clock = _CLOCK
    reset = _RESET
    steps = 8
    stages = 8
    gate1 = off
    gate2 = off
    gate3 = off
    gate4 = off
    gate5 = on
    gate6 = off
    gate7 = off
    gate8 = off
    gateoutput = _CLAPS_TRIGGER_SEQ

# SD -> CL (Claps doubles SD rhythm)
[button]
    button = B2.4
    led = L2.4
    offvalue = _CLAPS_TRIGGER_SEQ
    onvalue = _SD_TRIGGER
    output = _CLAPS_TRIGGER

# Mute button
[button]
    button = B1.7
    led = L1.7
    onvalue = 0
    offvalue = _CLAPS_TRIGGER
    output = G1.7

# -------------------------------------------------
# Ducking
# -------------------------------------------------

# Ducking source
[button]
    button = B2.2
    onvalue = G1.1
    offvalue = _CLOCK_DIV_4
    output = O4

[contour]
    gate = O4
    release = 0.3
    output = L2.2

[clocktool]
    clock = _CLOCK
    reset = _RESET
    output = _CLOCK_DIV_4
    divide = 4
    gatelength = 0.01

# -------------------------------------------------
# Clockteiler für Magneto
# -------------------------------------------------

[button]
    button = B2.7
    led = L2.7
    value1 = 2
    value2 = 4
    value3 = 6
    output = _MAGNETO_CLOCK_DIV

[clocktool]
    clock = _CLOCK
    reset = _RESET
    divide = _MAGNETO_CLOCK_DIV
    output = G1.6

# -------------------------------------------------
# Modulation of Frequency Shifter
# -------------------------------------------------

[clocktool]
    clock = _CLOCK
    divide = 8
    output = _FREQ_MOD_CLOCK

[sequencer]
    clock = _FREQ_MOD_CLOCK
    pitch1 = 0
    pitch2 = 0.5 * P8.2
    pitchoutput = O1
