# (D) Chord sequencer
# LABELS: master=16

# 

# INPUTS:
#  I1: [CLOCK]
#  I2: [RESET]
#  I3: [Ch Trig]
#  I4: [LB Trig]

# OUTPUTS:
#  O1: [ROOT] Current root note (V/Oct)
#  O2: [SCALE] Current scale
#  O4: [LB] V/O for low bass
#  O5: [CH 1] Chord note 1
#  O6: [CH 2] Chord note 2
#  O7: [CH 3] Chord note 3
#  O8: [CH 4] Chord note 4

# CONTROLLER 1:
#  P1.1: [SLEW CHORDS]
#  P1.2: [SLEW LB]
#  P1.3: [Vib Chords]
#  P1.4: [Vib LB]
#  P1.5: [Length] Length of the chord sequence or loop as a number of steps
#  P1.6: [Detune]
#  P1.7: [Vib Del Ch]
#  P1.8: [Vib Del LB]
#  S1.1: [1 | 2 | 4] Length of a step as a number of bars (= 16 clock ticks)
#  S1.2: [x8 /8] Steps *8 or /8
#  S1.3: [Preset]
#  S1.4: [Loop]
#  S1.5: [Oct 1]
#  S1.6: [Oct 2]
#  S1.7: [Oct 3]
#  S1.8: [Oct 4]

# CONTROLLER 2:
#  B2.1: [C]
#  B2.2: [C#]
#  B2.3: [D]
#  B2.4: [D#]
#  B2.5: [E]
#  B2.6: [F]
#  B2.7: [F#]
#  B2.8: [G]
#  B2.9: [G#]
#  B2.10: [A]
#  B2.11: [A#]
#  B2.12: [B]
#  B2.13: [maj]
#  B2.14: [lyd]
#  B2.15: [ROOT] Jump to step 1
#  B2.16: [3RD]
#  B2.17: [min]
#  B2.18: [dor]
#  B2.19: [5TH]
#  B2.20: [7TH]
#  B2.21: [mixo]
#  B2.22: [hm5]
#  B2.23: [9TH]
#  B2.24: [11TH]
#  B2.25: [phr]
#  B2.26: [min#7]
#  B2.27: [13TH]
#  B2.28: [Unisono]
#  B2.29: [<] Move cursor one step left
#  B2.30: [>] Move cursor one step right
#  B2.31: [SEQ] Enable sequencer
#  B2.32: [TRANS] Global transposition

# CONTROLLER 3:
#  P3.1: [Tuning]
#  P3.2: [Vibrato Hz]
#  B3.1: [ROOT]
#  B3.2: [3RD]
#  B3.3: [5TH]
#  B3.4: [7TH]
#  B3.5: [9TH]
#  B3.6: [11TH]
#  B3.7: [13TH]
#  B3.8: [Freeze LB] Freezes the LB at the same pitch regardless of anything else

# CONTROLLER 4:
#  E4.1: [Spread] Chord spread
#  E4.2: [Inversion] Chord inversion
#  E4.3: [Chord pitch] Chord base pitch
#  E4.4: [Low Bass] Pitch of low bass

[p8s8]
[b32]
[p2b8]
[e4]

# -------------------------------------------------
# Global
# -------------------------------------------------

[copy]
    input = I1
    output = _CLOCK

[copy]
    input = I2
    output = _RESET

# Unisono mode
[button]
    button = B2.28
    output = _UNISONO
    onvalue = -3
    offvalue = 0
    states = 1
    led = L2.28

[pot]
    pot = P1.1 * _NO_TUNING_MODE
    outputscale = 0.9
    output = _CHORD_SLEW

[pot]
    pot = P1.2 * _NO_TUNING_MODE
    outputscale = 0.9
    output = _LOW_BASS_SLEW

[pot]
    pot = P1.5
    preset = _PRESET
    discrete = 8
    outputoffset = 1
    output = _SEQUENCE_NUM_STEPS

[button]
    button = B2.32
    led = L2.32
    states = 1
    output = _GLOBAL_TRANS_MODE
    inverted = _NO_GLOBAL_TRANS_MODE

[copy]
    input = S1.3
    output = _PRESET

# -------------------------------------------------
# Tuning mode
# -------------------------------------------------

[pot]
    pot = P3.1
    discrete = 8
    output = _TUNING_MODE

[ifequal]
    input1 = _TUNING_MODE
    input2 = 0
    ifequal = 1
    else = 0
    output = _NO_TUNING_MODE

[copy]
    input = _TUNING_MODE * 1V - 1V
    output = _TUNING_PITCH

# -------------------------------------------------
# Cursor + Sequencer
# -------------------------------------------------

# Move the step cursor forward and backward using a nudge circuit and two buttons.
[nudge]
    buttonup = B2.30
    buttondown = B2.29
    amount = 1
    startvalue = 1
    minimum = 1
    maximum = _SEQUENCE_NUM_STEPS
    wrap = 1
    ledup = L2.30
    leddown = L2.29
    output = _MANUAL_CURSOR_POSITION

# During tuning mode the cursor position is zero, otherwise between 1 and 8
[ifequal]
    input1 = _TUNING_MODE
    input2 = 0
    ifequal = _MANUAL_CURSOR_POSITION
    else = 0
    output = _CURSOR_POSITION

[copy]
    input = S1.1
    output = _BARS_PER_STEP_SWITCH

[copy]
    input = S1.2
    output = _BARSPERSTEP_DIVTIMES8_SWITCH

# Use nudge to create a pointer to the current sequence step. This nudge is forwarded by the
# clock, not manually.
#
# This is an eternal counter that does not wrap. It counts the bare clock ticks since the last
# reset or the system start. From this number the current sequence step is computed by taking
# into account the sequence length and the number of ticks per step.
#
# We start with -1 in order to get the math right.
[nudge]
    amount = 1
    buttonup = _CLOCK
    clear = _RESET
    dontsave = 1
    minimum = 0
    startvalue = 0
    output = _COUNTER_M1

# Right after reset the position is -1 (in order to exactly align the chord progression). Cap this to zero
# to avoid playing the last bar for one clock tick after reset.
[math]
    input1 = _COUNTER_M1
    input2 = 0
    maximum = _INFINTE_CLOCK_COUNTER

# Divide the infinite counter by the number of clock ticks a step has. This gives us the infinite step number.
[math]
    input1 = _INFINTE_CLOCK_COUNTER
    input2 = _CLOCKTICKS_PER_STEP
    quotient = _INFINITE_STEP_COUNTER_FLOAT

# The quotient created fractions. Round this down to the lower integer.
[math]
    input1 = _INFINITE_STEP_COUNTER_FLOAT
    floor = _INFINITE_STEP_COUNTER

# Now use a modulo operation to fold the bar number into the range 0 ... LENGTH-1
[math]
    input1 = _INFINITE_STEP_COUNTER
    input2 = _SEQUENCE_NUM_STEPS
    modulo = _CLOCKED_STEP

[switch]
    input1 = 1
    input2 = 0
    input3 = 0
    input4 = 0
    input5 = 0
    input6 = 0
    input7 = 0
    input8 = 0
    offset = _CURSOR_POSITION * -1 + 1
    output1 = _STEP1_CURSOR
    output2 = _STEP2_CURSOR
    output3 = _STEP3_CURSOR
    output4 = _STEP4_CURSOR
    output5 = _STEP5_CURSOR
    output6 = _STEP6_CURSOR
    output7 = _STEP7_CURSOR
    output8 = _STEP8_CURSOR

# Button for switching between the automatic sequencer and the manual one. In manual mode you move the active
# sequence step with the button < and >. In the automatic mode the step is moved forward with the clock
[button]
    button = B2.31
    led = L2.31
    offvalue = -1 * 1 + _CURSOR_POSITION
    onvalue = _CLOCKED_STEP
    output = _STEP

# -------------------------------------------------
# LED Screen
# The inputs LED 1-8 represent the eight steps of the sequencer
# 
# - blue -> step is part of the sequence (1 is always blue hence)
# - white -> step is currently played
# - red -> step is currently edited
# - orange -> step is edited and played
# -------------------------------------------------

[lfo]
    hz = 3
    square = _CURSOR_BLINK
    level = _CURSOR_POSITION

[copy]
    input = 1.2
    output = R1

[copy]
    input = 0
    output = R2

[copy]
    input = 0
    output = R3

[copy]
    input = 0
    output = R4

[copy]
    input = 0
    output = R5

[copy]
    input = 0
    output = R6

[copy]
    input = 0
    output = R7

[select]
    input = 0
    output = R8

[compare]
    input = _SEQUENCE_NUM_STEPS
    compare = 2
    ifless = 0
    else = 1
    output = _LEN_ATLEAST_2

[select]
    input = 1.2
    output = R2
    select = _LEN_ATLEAST_2

[compare]
    input = _SEQUENCE_NUM_STEPS
    compare = 3
    ifless = 0
    else = 1
    output = _LEN_ATLEAST_3

[select]
    input = 1.2
    output = R3
    select = _LEN_ATLEAST_3

[compare]
    input = _SEQUENCE_NUM_STEPS
    compare = 4
    ifless = 0
    else = 1
    output = _LEN_ATLEAST_4

[select]
    input = 1.2
    output = R4
    select = _LEN_ATLEAST_4

[compare]
    input = _SEQUENCE_NUM_STEPS
    compare = 5
    ifless = 0
    else = 1
    output = _LEN_ATLEAST_5

[select]
    input = 1.2
    output = R5
    select = _LEN_ATLEAST_5

[compare]
    input = _SEQUENCE_NUM_STEPS
    compare = 6
    ifless = 0
    else = 1
    output = _LEN_ATLEAST_6

[select]
    input = 1.2
    output = R6
    select = _LEN_ATLEAST_6

[compare]
    input = _SEQUENCE_NUM_STEPS
    compare = 7
    ifless = 0
    else = 1
    output = _LEN_ATLEAST_7

[select]
    input = 1.2
    output = R7
    select = _LEN_ATLEAST_7

[compare]
    input = _SEQUENCE_NUM_STEPS
    compare = 8
    ifless = 0
    else = 1
    output = _LEN_ATLEAST_8

[select]
    input = 1.2
    output = R8
    select = _LEN_ATLEAST_8

[select]
    input = 0.6
    output = R1
    select = _STEP
    selectat = 0

[select]
    input = 0.6
    output = R2
    select = _STEP
    selectat = 1

[select]
    input = 0.6
    output = R3
    select = _STEP
    selectat = 2

[select]
    input = 0.6
    output = R4
    select = _STEP
    selectat = 3

[select]
    input = 0.6
    output = R5
    select = _STEP
    selectat = 4

[select]
    input = 0.6
    output = R6
    select = _STEP
    selectat = 5

[select]
    input = 0.6
    output = R7
    select = _STEP
    selectat = 6

[select]
    input = 0.6
    output = R8
    select = _STEP
    selectat = 7

# Cursor at pos 1
[select]
    input = 0.31
    output = R1
    select = _CURSOR_BLINK
    selectat = 1

# Cursor at pos 2
[select]
    input = 0.31
    output = R2
    select = _CURSOR_BLINK
    selectat = 2

# Cursor at pos 3
[select]
    input = 0.31
    output = R3
    select = _CURSOR_BLINK
    selectat = 3

# Cursor at pos 4
[select]
    input = 0.31
    output = R4
    select = _CURSOR_BLINK
    selectat = 4

# Cursor at pos 5
[select]
    input = 0.31
    output = R5
    select = _CURSOR_BLINK
    selectat = 5

# Cursor at pos 6
[select]
    input = 0.31
    output = R6
    select = _CURSOR_BLINK
    selectat = 6

# Cursor at pos 7
[select]
    input = 0.31
    output = R7
    select = _CURSOR_BLINK
    selectat = 7

# Cursor at pos 8
[select]
    input = 0.31
    output = R8
    select = _CURSOR_BLINK
    selectat = 8

# -------------------------------------------------
# Step 1
# -------------------------------------------------

# Scale
[buttongroup]
    preset = _PRESET
    select = _STEP1_CURSOR
    button1 = B2.13
    button2 = B2.14
    button3 = B2.17
    button4 = B2.18
    button5 = B2.22
    button6 = B2.21
    button7 = B2.25
    button8 = B2.26
    value1 = 1
    value2 = 0
    value3 = 7
    value4 = 6
    value5 = 5
    value6 = 2
    value7 = 9
    value8 = 20
    led1 = L2.13
    led2 = L2.14
    led3 = L2.17
    led4 = L2.18
    led5 = L2.22
    led6 = L2.21
    led7 = L2.25
    led8 = L2.26
    output = _STEP1_SCALE

# Root
[notebuttons]
    preset = _PRESET
    select = _STEP1_CURSOR * _NO_GLOBAL_TRANS_MODE
    button1 = B2.1
    button2 = B2.2
    button3 = B2.3
    button4 = B2.4
    button5 = B2.5
    button6 = B2.6
    button7 = B2.7
    button8 = B2.8
    button9 = B2.9
    button10 = B2.10
    button11 = B2.11
    button12 = B2.12
    led1 = L2.1
    led2 = L2.2
    led3 = L2.3
    led4 = L2.4
    led5 = L2.5
    led6 = L2.6
    led7 = L2.7
    led8 = L2.8
    led9 = L2.9
    led10 = L2.10
    led11 = L2.11
    led12 = L2.12
    output = _STEP1_ROOT

# Chord voicing
[buttongroup]
    preset = _PRESET
    select = _STEP1_CURSOR
    button1 = B2.15
    button2 = B2.16
    button3 = B2.19
    button4 = B2.20
    button5 = B2.23
    button6 = B2.24
    button7 = B2.27
    minactive = 1
    maxactive = 4 + _UNISONO
    led1 = L2.15
    led2 = L2.16
    led3 = L2.19
    led4 = L2.20
    led5 = L2.23
    led6 = L2.24
    led7 = L2.27
    buttonoutput1 = _STEP1_SEL_ROOT
    buttonoutput2 = _STEP1_SEL_3RD
    buttonoutput3 = _STEP1_SEL_5TH
    buttonoutput4 = _STEP1_SEL_7TH
    buttonoutput5 = _STEP1_SEL_9TH
    buttonoutput6 = _STEP1_SEL_11TH
    buttonoutput7 = _STEP1_SEL_13TH

# Low bass note
[buttongroup]
    preset = _PRESET
    select = _STEP1_CURSOR
    button1 = B3.1
    button2 = B3.5
    button3 = B3.2
    button4 = B3.6
    button5 = B3.3
    button6 = B3.7
    button7 = B3.4
    minactive = 1
    maxactive = 1
    output = _STEP1_LOW_BASS_NOTE
    led1 = L3.1
    led2 = L3.5
    led3 = L3.2
    led4 = L3.6
    led5 = L3.3
    led6 = L3.7
    led7 = L3.4

# Chord spread
[encoder]
    preset = _PRESET
    select = _STEP1_CURSOR
    encoder = 1
    outputscale = 0.3
    color = 0.2
    output = _STEP1_CHORD_SPREAD

# Chord inversion
[encoder]
    preset = _PRESET
    select = _STEP1_CURSOR
    encoder = 2
    discrete = 5
    color = 1
    output = _STEP1_CHORD_INVERSION

# Chord pitch
[encoder]
    preset = _PRESET
    select = _STEP1_CURSOR * _NO_CHORD_PITCH_RAND_SEL
    encoder = 3
    outputscale = 5V
    outputoffset = -1 * 2V + 0
    color = 0.4
    output = _STEP1_CHORD_PITCH

# Low bass pitch
[encoder]
    preset = _PRESET
    select = _STEP1_CURSOR
    encoder = 4
    outputscale = 4V
    color = 1.2
    output = _STEP1_LOW_BASS_PITCH

# -------------------------------------------------
# Step 2
# -------------------------------------------------

# Scale
[buttongroup]
    preset = _PRESET
    select = _STEP2_CURSOR
    button1 = B2.13
    button2 = B2.14
    button3 = B2.17
    button4 = B2.18
    button5 = B2.22
    button6 = B2.21
    button7 = B2.25
    button8 = B2.26
    value1 = 1
    value2 = 0
    value3 = 7
    value4 = 6
    value5 = 5
    value6 = 2
    value7 = 9
    value8 = 20
    led1 = L2.13
    led2 = L2.14
    led3 = L2.17
    led4 = L2.18
    led5 = L2.22
    led6 = L2.21
    led7 = L2.25
    led8 = L2.26
    output = _STEP2_SCALE

# Root
[notebuttons]
    preset = _PRESET
    select = _STEP2_CURSOR * _NO_GLOBAL_TRANS_MODE
    button1 = B2.1
    button2 = B2.2
    button3 = B2.3
    button4 = B2.4
    button5 = B2.5
    button6 = B2.6
    button7 = B2.7
    button8 = B2.8
    button9 = B2.9
    button10 = B2.10
    button11 = B2.11
    button12 = B2.12
    led1 = L2.1
    led2 = L2.2
    led3 = L2.3
    led4 = L2.4
    led5 = L2.5
    led6 = L2.6
    led7 = L2.7
    led8 = L2.8
    led9 = L2.9
    led10 = L2.10
    led11 = L2.11
    led12 = L2.12
    output = _STEP2_ROOT

# Chord voicing
[buttongroup]
    preset = _PRESET
    select = _STEP2_CURSOR
    button1 = B2.15
    button2 = B2.16
    button3 = B2.19
    button4 = B2.20
    button5 = B2.23
    button6 = B2.24
    button7 = B2.27
    minactive = 1
    maxactive = 4 + _UNISONO
    led1 = L2.15
    led2 = L2.16
    led3 = L2.19
    led4 = L2.20
    led5 = L2.23
    led6 = L2.24
    led7 = L2.27
    buttonoutput1 = _STEP2_SEL_ROOT
    buttonoutput2 = _STEP2_SEL_3RD
    buttonoutput3 = _STEP2_SEL_5TH
    buttonoutput4 = _STEP2_SEL_7TH
    buttonoutput5 = _STEP2_SEL_9TH
    buttonoutput6 = _STEP2_SEL_11TH
    buttonoutput7 = _STEP2_SEL_13TH

# Low bass note
[buttongroup]
    preset = _PRESET
    select = _STEP2_CURSOR
    button1 = B3.1
    button2 = B3.5
    button3 = B3.2
    button4 = B3.6
    button5 = B3.3
    button6 = B3.7
    button7 = B3.4
    minactive = 1
    maxactive = 1
    output = _STEP2_LOW_BASS_NOTE
    led1 = L3.1
    led2 = L3.5
    led3 = L3.2
    led4 = L3.6
    led5 = L3.3
    led6 = L3.7
    led7 = L3.4

# Chord spread
[encoder]
    preset = _PRESET
    select = _STEP2_CURSOR
    encoder = 1
    outputscale = 0.3
    color = 0.2
    output = _STEP2_CHORD_SPREAD

# Chord inversion
[encoder]
    preset = _PRESET
    select = _STEP2_CURSOR
    encoder = 2
    discrete = 5
    color = 1
    output = _STEP2_CHORD_INVERSION

# Chord pitch
[encoder]
    preset = _PRESET
    select = _STEP2_CURSOR * _NO_CHORD_PITCH_RAND_SEL
    encoder = 3
    outputscale = 5V
    outputoffset = -1 * 2V + 0
    color = 0.4
    output = _STEP2_CHORD_PITCH

# Low bass pitch
[encoder]
    preset = _PRESET
    select = _STEP2_CURSOR
    encoder = 4
    outputscale = 4V
    color = 1.2
    output = _STEP2_LOW_BASS_PITCH

# -------------------------------------------------
# Step 3
# -------------------------------------------------

# Scale
[buttongroup]
    preset = _PRESET
    select = _STEP3_CURSOR
    button1 = B2.13
    button2 = B2.14
    button3 = B2.17
    button4 = B2.18
    button5 = B2.22
    button6 = B2.21
    button7 = B2.25
    button8 = B2.26
    value1 = 1
    value2 = 0
    value3 = 7
    value4 = 6
    value5 = 5
    value6 = 2
    value7 = 9
    value8 = 20
    led1 = L2.13
    led2 = L2.14
    led3 = L2.17
    led4 = L2.18
    led5 = L2.22
    led6 = L2.21
    led7 = L2.25
    led8 = L2.26
    output = _STEP3_SCALE

# Root
[notebuttons]
    preset = _PRESET
    select = _STEP3_CURSOR * _NO_GLOBAL_TRANS_MODE
    button1 = B2.1
    button2 = B2.2
    button3 = B2.3
    button4 = B2.4
    button5 = B2.5
    button6 = B2.6
    button7 = B2.7
    button8 = B2.8
    button9 = B2.9
    button10 = B2.10
    button11 = B2.11
    button12 = B2.12
    led1 = L2.1
    led2 = L2.2
    led3 = L2.3
    led4 = L2.4
    led5 = L2.5
    led6 = L2.6
    led7 = L2.7
    led8 = L2.8
    led9 = L2.9
    led10 = L2.10
    led11 = L2.11
    led12 = L2.12
    output = _STEP3_ROOT

# Chord voicing
[buttongroup]
    preset = _PRESET
    select = _STEP3_CURSOR
    button1 = B2.15
    button2 = B2.16
    button3 = B2.19
    button4 = B2.20
    button5 = B2.23
    button6 = B2.24
    button7 = B2.27
    minactive = 1
    maxactive = 4 + _UNISONO
    led1 = L2.15
    led2 = L2.16
    led3 = L2.19
    led4 = L2.20
    led5 = L2.23
    led6 = L2.24
    led7 = L2.27
    buttonoutput1 = _STEP3_SEL_ROOT
    buttonoutput2 = _STEP3_SEL_3RD
    buttonoutput3 = _STEP3_SEL_5TH
    buttonoutput4 = _STEP3_SEL_7TH
    buttonoutput5 = _STEP3_SEL_9TH
    buttonoutput6 = _STEP3_SEL_11TH
    buttonoutput7 = _STEP3_SEL_13TH

# Low bass note
[buttongroup]
    preset = _PRESET
    select = _STEP3_CURSOR
    button1 = B3.1
    button2 = B3.5
    button3 = B3.2
    button4 = B3.6
    button5 = B3.3
    button6 = B3.7
    button7 = B3.4
    minactive = 1
    maxactive = 1
    output = _STEP3_LOW_BASS_NOTE
    led1 = L3.1
    led2 = L3.5
    led3 = L3.2
    led4 = L3.6
    led5 = L3.3
    led6 = L3.7
    led7 = L3.4

# Chord spread
[encoder]
    preset = _PRESET
    select = _STEP3_CURSOR
    encoder = 1
    outputscale = 0.3
    color = 0.2
    output = _STEP3_CHORD_SPREAD

# Chord inversion
[encoder]
    preset = _PRESET
    select = _STEP3_CURSOR
    encoder = 2
    discrete = 5
    color = 1
    output = _STEP3_CHORD_INVERSION

# Chord pitch
[encoder]
    preset = _PRESET
    select = _STEP3_CURSOR * _NO_CHORD_PITCH_RAND_SEL
    encoder = 3
    outputscale = 5V
    outputoffset = -1 * 2V + 0
    color = 0.4
    output = _STEP3_CHORD_PITCH

# Low bass pitch
[encoder]
    preset = _PRESET
    select = _STEP3_CURSOR
    encoder = 4
    outputscale = 4V
    color = 1.2
    output = _STEP3_LOW_BASS_PITCH

# -------------------------------------------------
# Step 4
# -------------------------------------------------

# Scale
[buttongroup]
    preset = _PRESET
    select = _STEP4_CURSOR
    button1 = B2.13
    button2 = B2.14
    button3 = B2.17
    button4 = B2.18
    button5 = B2.22
    button6 = B2.21
    button7 = B2.25
    button8 = B2.26
    value1 = 1
    value2 = 0
    value3 = 7
    value4 = 6
    value5 = 5
    value6 = 2
    value7 = 9
    value8 = 20
    led1 = L2.13
    led2 = L2.14
    led3 = L2.17
    led4 = L2.18
    led5 = L2.22
    led6 = L2.21
    led7 = L2.25
    led8 = L2.26
    output = _STEP4_SCALE

# Root
[notebuttons]
    preset = _PRESET
    select = _STEP4_CURSOR * _NO_GLOBAL_TRANS_MODE
    button1 = B2.1
    button2 = B2.2
    button3 = B2.3
    button4 = B2.4
    button5 = B2.5
    button6 = B2.6
    button7 = B2.7
    button8 = B2.8
    button9 = B2.9
    button10 = B2.10
    button11 = B2.11
    button12 = B2.12
    led1 = L2.1
    led2 = L2.2
    led3 = L2.3
    led4 = L2.4
    led5 = L2.5
    led6 = L2.6
    led7 = L2.7
    led8 = L2.8
    led9 = L2.9
    led10 = L2.10
    led11 = L2.11
    led12 = L2.12
    output = _STEP4_ROOT

# Chord voicing
[buttongroup]
    preset = _PRESET
    select = _STEP4_CURSOR
    button1 = B2.15
    button2 = B2.16
    button3 = B2.19
    button4 = B2.20
    button5 = B2.23
    button6 = B2.24
    button7 = B2.27
    minactive = 1
    maxactive = 4 + _UNISONO
    led1 = L2.15
    led2 = L2.16
    led3 = L2.19
    led4 = L2.20
    led5 = L2.23
    led6 = L2.24
    led7 = L2.27
    buttonoutput1 = _STEP4_SEL_ROOT
    buttonoutput2 = _STEP4_SEL_3RD
    buttonoutput3 = _STEP4_SEL_5TH
    buttonoutput4 = _STEP4_SEL_7TH
    buttonoutput5 = _STEP4_SEL_9TH
    buttonoutput6 = _STEP4_SEL_11TH
    buttonoutput7 = _STEP4_SEL_13TH

# Low bass note
[buttongroup]
    preset = _PRESET
    select = _STEP4_CURSOR
    button1 = B3.1
    button2 = B3.5
    button3 = B3.2
    button4 = B3.6
    button5 = B3.3
    button6 = B3.7
    button7 = B3.4
    minactive = 1
    maxactive = 1
    output = _STEP4_LOW_BASS_NOTE
    led1 = L3.1
    led2 = L3.5
    led3 = L3.2
    led4 = L3.6
    led5 = L3.3
    led6 = L3.7
    led7 = L3.4

# Chord spread
[encoder]
    preset = _PRESET
    select = _STEP4_CURSOR
    encoder = 1
    outputscale = 0.3
    color = 0.2
    output = _STEP4_CHORD_SPREAD

# Chord inversion
[encoder]
    preset = _PRESET
    select = _STEP4_CURSOR
    encoder = 2
    discrete = 5
    color = 1
    output = _STEP4_CHORD_INVERSION

# Chord pitch
[encoder]
    preset = _PRESET
    select = _STEP4_CURSOR * _NO_CHORD_PITCH_RAND_SEL
    encoder = 3
    outputscale = 5V
    outputoffset = -1 * 2V + 0
    color = 0.4
    output = _STEP4_CHORD_PITCH

# Low bass pitch
[encoder]
    preset = _PRESET
    select = _STEP4_CURSOR
    encoder = 4
    outputscale = 4V
    color = 1.2
    output = _STEP4_LOW_BASS_PITCH

# -------------------------------------------------
# Step 5
# -------------------------------------------------

# Scale
[buttongroup]
    preset = _PRESET
    select = _STEP5_CURSOR
    button1 = B2.13
    button2 = B2.14
    button3 = B2.17
    button4 = B2.18
    button5 = B2.22
    button6 = B2.21
    button7 = B2.25
    button8 = B2.26
    value1 = 1
    value2 = 0
    value3 = 7
    value4 = 6
    value5 = 5
    value6 = 2
    value7 = 9
    value8 = 20
    led1 = L2.13
    led2 = L2.14
    led3 = L2.17
    led4 = L2.18
    led5 = L2.22
    led6 = L2.21
    led7 = L2.25
    led8 = L2.26
    output = _STEP5_SCALE

# Root
[notebuttons]
    preset = _PRESET
    select = _STEP5_CURSOR * _NO_GLOBAL_TRANS_MODE
    button1 = B2.1
    button2 = B2.2
    button3 = B2.3
    button4 = B2.4
    button5 = B2.5
    button6 = B2.6
    button7 = B2.7
    button8 = B2.8
    button9 = B2.9
    button10 = B2.10
    button11 = B2.11
    button12 = B2.12
    led1 = L2.1
    led2 = L2.2
    led3 = L2.3
    led4 = L2.4
    led5 = L2.5
    led6 = L2.6
    led7 = L2.7
    led8 = L2.8
    led9 = L2.9
    led10 = L2.10
    led11 = L2.11
    led12 = L2.12
    output = _STEP5_ROOT

# Chord voicing
[buttongroup]
    preset = _PRESET
    select = _STEP5_CURSOR
    button1 = B2.15
    button2 = B2.16
    button3 = B2.19
    button4 = B2.20
    button5 = B2.23
    button6 = B2.24
    button7 = B2.27
    minactive = 1
    maxactive = 4 + _UNISONO
    led1 = L2.15
    led2 = L2.16
    led3 = L2.19
    led4 = L2.20
    led5 = L2.23
    led6 = L2.24
    led7 = L2.27
    buttonoutput1 = _STEP5_SEL_ROOT
    buttonoutput2 = _STEP5_SEL_3RD
    buttonoutput3 = _STEP5_SEL_5TH
    buttonoutput4 = _STEP5_SEL_7TH
    buttonoutput5 = _STEP5_SEL_9TH
    buttonoutput6 = _STEP5_SEL_11TH
    buttonoutput7 = _STEP5_SEL_13TH

# Low bass note
[buttongroup]
    preset = _PRESET
    select = _STEP5_CURSOR
    button1 = B3.1
    button2 = B3.5
    button3 = B3.2
    button4 = B3.6
    button5 = B3.3
    button6 = B3.7
    button7 = B3.4
    minactive = 1
    maxactive = 1
    output = _STEP5_LOW_BASS_NOTE
    led1 = L3.1
    led2 = L3.5
    led3 = L3.2
    led4 = L3.6
    led5 = L3.3
    led6 = L3.7
    led7 = L3.4

# Chord spread
[encoder]
    preset = _PRESET
    select = _STEP5_CURSOR
    encoder = 1
    outputscale = 0.3
    color = 0.2
    output = _STEP5_CHORD_SPREAD

# Chord inversion
[encoder]
    preset = _PRESET
    select = _STEP5_CURSOR
    encoder = 2
    discrete = 5
    color = 1
    output = _STEP5_CHORD_INVERSION

# Chord pitch
[encoder]
    preset = _PRESET
    select = _STEP5_CURSOR * _NO_CHORD_PITCH_RAND_SEL
    encoder = 3
    outputscale = 5V
    outputoffset = -1 * 2V + 0
    color = 0.4
    output = _STEP5_CHORD_PITCH

# Low bass pitch
[encoder]
    preset = _PRESET
    select = _STEP5_CURSOR
    encoder = 4
    outputscale = 4V
    color = 1.2
    output = _STEP5_LOW_BASS_PITCH

# -------------------------------------------------
# Step 6
# -------------------------------------------------

# Scale
[buttongroup]
    preset = _PRESET
    select = _STEP6_CURSOR
    button1 = B2.13
    button2 = B2.14
    button3 = B2.17
    button4 = B2.18
    button5 = B2.22
    button6 = B2.21
    button7 = B2.25
    button8 = B2.26
    value1 = 1
    value2 = 0
    value3 = 7
    value4 = 6
    value5 = 5
    value6 = 2
    value7 = 9
    value8 = 20
    led1 = L2.13
    led2 = L2.14
    led3 = L2.17
    led4 = L2.18
    led5 = L2.22
    led6 = L2.21
    led7 = L2.25
    led8 = L2.26
    output = _STEP6_SCALE

# Root
[notebuttons]
    preset = _PRESET
    select = _STEP6_CURSOR * _NO_GLOBAL_TRANS_MODE
    button1 = B2.1
    button2 = B2.2
    button3 = B2.3
    button4 = B2.4
    button5 = B2.5
    button6 = B2.6
    button7 = B2.7
    button8 = B2.8
    button9 = B2.9
    button10 = B2.10
    button11 = B2.11
    button12 = B2.12
    led1 = L2.1
    led2 = L2.2
    led3 = L2.3
    led4 = L2.4
    led5 = L2.5
    led6 = L2.6
    led7 = L2.7
    led8 = L2.8
    led9 = L2.9
    led10 = L2.10
    led11 = L2.11
    led12 = L2.12
    output = _STEP6_ROOT

# Chord voicing
[buttongroup]
    preset = _PRESET
    select = _STEP6_CURSOR
    button1 = B2.15
    button2 = B2.16
    button3 = B2.19
    button4 = B2.20
    button5 = B2.23
    button6 = B2.24
    button7 = B2.27
    minactive = 1
    maxactive = 4 + _UNISONO
    led1 = L2.15
    led2 = L2.16
    led3 = L2.19
    led4 = L2.20
    led5 = L2.23
    led6 = L2.24
    led7 = L2.27
    buttonoutput1 = _STEP6_SEL_ROOT
    buttonoutput2 = _STEP6_SEL_3RD
    buttonoutput3 = _STEP6_SEL_5TH
    buttonoutput4 = _STEP6_SEL_7TH
    buttonoutput5 = _STEP6_SEL_9TH
    buttonoutput6 = _STEP6_SEL_11TH
    buttonoutput7 = _STEP6_SEL_13TH

# Low bass note
[buttongroup]
    preset = _PRESET
    select = _STEP6_CURSOR
    button1 = B3.1
    button2 = B3.5
    button3 = B3.2
    button4 = B3.6
    button5 = B3.3
    button6 = B3.7
    button7 = B3.4
    minactive = 1
    maxactive = 1
    output = _STEP6_LOW_BASS_NOTE
    led1 = L3.1
    led2 = L3.5
    led3 = L3.2
    led4 = L3.6
    led5 = L3.3
    led6 = L3.7
    led7 = L3.4

# Chord spread
[encoder]
    preset = _PRESET
    select = _STEP6_CURSOR
    encoder = 1
    outputscale = 0.3
    color = 0.2
    output = _STEP6_CHORD_SPREAD

# Chord inversion
[encoder]
    preset = _PRESET
    select = _STEP6_CURSOR
    encoder = 2
    discrete = 5
    color = 1
    output = _STEP6_CHORD_INVERSION

# Chord pitch
[encoder]
    preset = _PRESET
    select = _STEP6_CURSOR * _NO_CHORD_PITCH_RAND_SEL
    encoder = 3
    outputscale = 5V
    outputoffset = -1 * 2V + 0
    color = 0.4
    output = _STEP6_CHORD_PITCH

# Low bass pitch
[encoder]
    preset = _PRESET
    select = _STEP6_CURSOR
    encoder = 4
    outputscale = 4V
    color = 1.2
    output = _STEP6_LOW_BASS_PITCH

# -------------------------------------------------
# Step 7
# -------------------------------------------------

# Scale
[buttongroup]
    preset = _PRESET
    select = _STEP7_CURSOR
    button1 = B2.13
    button2 = B2.14
    button3 = B2.17
    button4 = B2.18
    button5 = B2.22
    button6 = B2.21
    button7 = B2.25
    button8 = B2.26
    value1 = 1
    value2 = 0
    value3 = 7
    value4 = 6
    value5 = 5
    value6 = 2
    value7 = 9
    value8 = 20
    led1 = L2.13
    led2 = L2.14
    led3 = L2.17
    led4 = L2.18
    led5 = L2.22
    led6 = L2.21
    led7 = L2.25
    led8 = L2.26
    output = _STEP7_SCALE

# Root
[notebuttons]
    preset = _PRESET
    select = _STEP7_CURSOR * _NO_GLOBAL_TRANS_MODE
    button1 = B2.1
    button2 = B2.2
    button3 = B2.3
    button4 = B2.4
    button5 = B2.5
    button6 = B2.6
    button7 = B2.7
    button8 = B2.8
    button9 = B2.9
    button10 = B2.10
    button11 = B2.11
    button12 = B2.12
    led1 = L2.1
    led2 = L2.2
    led3 = L2.3
    led4 = L2.4
    led5 = L2.5
    led6 = L2.6
    led7 = L2.7
    led8 = L2.8
    led9 = L2.9
    led10 = L2.10
    led11 = L2.11
    led12 = L2.12
    output = _STEP7_ROOT

# Chord voicing
[buttongroup]
    preset = _PRESET
    select = _STEP7_CURSOR
    button1 = B2.15
    button2 = B2.16
    button3 = B2.19
    button4 = B2.20
    button5 = B2.23
    button6 = B2.24
    button7 = B2.27
    minactive = 1
    maxactive = 4 + _UNISONO
    led1 = L2.15
    led2 = L2.16
    led3 = L2.19
    led4 = L2.20
    led5 = L2.23
    led6 = L2.24
    led7 = L2.27
    buttonoutput1 = _STEP7_SEL_ROOT
    buttonoutput2 = _STEP7_SEL_3RD
    buttonoutput3 = _STEP7_SEL_5TH
    buttonoutput4 = _STEP7_SEL_7TH
    buttonoutput5 = _STEP7_SEL_9TH
    buttonoutput6 = _STEP7_SEL_11TH
    buttonoutput7 = _STEP7_SEL_13TH

# Low bass note
[buttongroup]
    preset = _PRESET
    select = _STEP7_CURSOR
    button1 = B3.1
    button2 = B3.5
    button3 = B3.2
    button4 = B3.6
    button5 = B3.3
    button6 = B3.7
    button7 = B3.4
    minactive = 1
    maxactive = 1
    output = _STEP7_LOW_BASS_NOTE
    led1 = L3.1
    led2 = L3.5
    led3 = L3.2
    led4 = L3.6
    led5 = L3.3
    led6 = L3.7
    led7 = L3.4

# Chord spread
[encoder]
    preset = _PRESET
    select = _STEP7_CURSOR
    encoder = 1
    outputscale = 0.3
    color = 0.2
    output = _STEP7_CHORD_SPREAD

# Chord inversion
[encoder]
    preset = _PRESET
    select = _STEP7_CURSOR
    encoder = 2
    discrete = 5
    color = 1
    output = _STEP7_CHORD_INVERSION

# Chord pitch
[encoder]
    preset = _PRESET
    select = _STEP7_CURSOR * _NO_CHORD_PITCH_RAND_SEL
    encoder = 3
    outputscale = 5V
    outputoffset = -1 * 2V + 0
    color = 0.4
    output = _STEP7_CHORD_PITCH

# Low bass pitch
[encoder]
    preset = _PRESET
    select = _STEP7_CURSOR
    encoder = 4
    outputscale = 4V
    color = 1.2
    output = _STEP7_LOW_BASS_PITCH

# -------------------------------------------------
# Step 8
# -------------------------------------------------

# Scale
[buttongroup]
    preset = _PRESET
    select = _STEP8_CURSOR
    button1 = B2.13
    button2 = B2.14
    button3 = B2.17
    button4 = B2.18
    button5 = B2.22
    button6 = B2.21
    button7 = B2.25
    button8 = B2.26
    value1 = 1
    value2 = 0
    value3 = 7
    value4 = 6
    value5 = 5
    value6 = 2
    value7 = 9
    value8 = 20
    led1 = L2.13
    led2 = L2.14
    led3 = L2.17
    led4 = L2.18
    led5 = L2.22
    led6 = L2.21
    led7 = L2.25
    led8 = L2.26
    output = _STEP8_SCALE

# Root
[notebuttons]
    preset = _PRESET
    select = _STEP8_CURSOR * _NO_GLOBAL_TRANS_MODE
    button1 = B2.1
    button2 = B2.2
    button3 = B2.3
    button4 = B2.4
    button5 = B2.5
    button6 = B2.6
    button7 = B2.7
    button8 = B2.8
    button9 = B2.9
    button10 = B2.10
    button11 = B2.11
    button12 = B2.12
    led1 = L2.1
    led2 = L2.2
    led3 = L2.3
    led4 = L2.4
    led5 = L2.5
    led6 = L2.6
    led7 = L2.7
    led8 = L2.8
    led9 = L2.9
    led10 = L2.10
    led11 = L2.11
    led12 = L2.12
    output = _STEP8_ROOT

# Chord voicing
[buttongroup]
    preset = _PRESET
    select = _STEP8_CURSOR
    button1 = B2.15
    button2 = B2.16
    button3 = B2.19
    button4 = B2.20
    button5 = B2.23
    button6 = B2.24
    button7 = B2.27
    minactive = 1
    maxactive = 4 + _UNISONO
    led1 = L2.15
    led2 = L2.16
    led3 = L2.19
    led4 = L2.20
    led5 = L2.23
    led6 = L2.24
    led7 = L2.27
    buttonoutput1 = _STEP8_SEL_ROOT
    buttonoutput2 = _STEP8_SEL_3RD
    buttonoutput3 = _STEP8_SEL_5TH
    buttonoutput4 = _STEP8_SEL_7TH
    buttonoutput5 = _STEP8_SEL_9TH
    buttonoutput6 = _STEP8_SEL_11TH
    buttonoutput7 = _STEP8_SEL_13TH

# Low bass note
[buttongroup]
    preset = _PRESET
    select = _STEP8_CURSOR
    button1 = B3.1
    button2 = B3.5
    button3 = B3.2
    button4 = B3.6
    button5 = B3.3
    button6 = B3.7
    button7 = B3.4
    minactive = 1
    maxactive = 1
    output = _STEP8_LOW_BASS_NOTE
    led1 = L3.1
    led2 = L3.5
    led3 = L3.2
    led4 = L3.6
    led5 = L3.3
    led6 = L3.7
    led7 = L3.4

# Chord spread
[encoder]
    preset = _PRESET
    select = _STEP8_CURSOR
    encoder = 1
    outputscale = 0.3
    color = 0.2
    output = _STEP8_CHORD_SPREAD

# Chord inversion
[encoder]
    preset = _PRESET
    select = _STEP8_CURSOR
    encoder = 2
    discrete = 5
    color = 1
    output = _STEP8_CHORD_INVERSION

# Chord pitch
[encoder]
    preset = _PRESET
    select = _STEP8_CURSOR * _NO_CHORD_PITCH_RAND_SEL
    encoder = 3
    outputscale = 5V
    outputoffset = -1 * 2V + 0
    color = 0.4
    output = _STEP8_CHORD_PITCH

# Low bass pitch
[encoder]
    preset = _PRESET
    select = _STEP8_CURSOR
    encoder = 4
    outputscale = 4V
    color = 1.2
    output = _STEP8_LOW_BASS_PITCH

# -------------------------------------------------
# Global transposition
# -------------------------------------------------

[notebuttons]
    select = _GLOBAL_TRANS_MODE
    button1 = B2.1
    button2 = B2.2
    button3 = B2.3
    button4 = B2.4
    button5 = B2.5
    button6 = B2.6
    button7 = B2.7
    button8 = B2.8
    button9 = B2.9
    button10 = B2.10
    button11 = B2.11
    button12 = B2.12
    output = _GLOBAL_TRANSPOSITION
    dontsave = 1
    led1 = L2.1
    led2 = L2.2
    led3 = L2.3
    led4 = L2.4
    led5 = L2.5
    led6 = L2.6
    led7 = L2.7
    led8 = L2.8
    led9 = L2.9
    led10 = L2.10
    led11 = L2.11
    led12 = L2.12

# -------------------------------------------------
# Step switch
# For every parameter that exists per step (per bar), one switch circuit selects the parameter from
# the currently active step.
# -------------------------------------------------

# Switch for root note
[switch]
    input1 = _STEP1_ROOT
    input2 = _STEP2_ROOT
    input3 = _STEP3_ROOT
    input4 = _STEP4_ROOT
    input5 = _STEP5_ROOT
    input6 = _STEP6_ROOT
    input7 = _STEP7_ROOT
    input8 = _STEP8_ROOT
    offset = _STEP
    output1 = _ROOT_UNLOOPED

# Switch for scale
[switch]
    input1 = _STEP1_SCALE
    input2 = _STEP2_SCALE
    input3 = _STEP3_SCALE
    input4 = _STEP4_SCALE
    input5 = _STEP5_SCALE
    input6 = _STEP6_SCALE
    input7 = _STEP7_SCALE
    input8 = _STEP8_SCALE
    offset = _STEP
    output1 = _SCALE_UNLOOPED

# Switch for chord spread
[switch]
    input1 = _STEP1_CHORD_SPREAD
    input2 = _STEP2_CHORD_SPREAD
    input3 = _STEP3_CHORD_SPREAD
    input4 = _STEP4_CHORD_SPREAD
    input5 = _STEP5_CHORD_SPREAD
    input6 = _STEP6_CHORD_SPREAD
    input7 = _STEP7_CHORD_SPREAD
    input8 = _STEP8_CHORD_SPREAD
    offset = _STEP
    output1 = _CHORD_SPREAD

# Switch for chord pitch
[switch]
    input1 = _STEP1_CHORD_PITCH
    input2 = _STEP2_CHORD_PITCH
    input3 = _STEP3_CHORD_PITCH
    input4 = _STEP4_CHORD_PITCH
    input5 = _STEP5_CHORD_PITCH
    input6 = _STEP6_CHORD_PITCH
    input7 = _STEP7_CHORD_PITCH
    input8 = _STEP8_CHORD_PITCH
    offset = _STEP
    output1 = _CHORD_PITCH

# Switch for chord inversion
[switch]
    input1 = _STEP1_CHORD_INVERSION
    input2 = _STEP2_CHORD_INVERSION
    input3 = _STEP3_CHORD_INVERSION
    input4 = _STEP4_CHORD_INVERSION
    input5 = _STEP5_CHORD_INVERSION
    input6 = _STEP6_CHORD_INVERSION
    input7 = _STEP7_CHORD_INVERSION
    input8 = _STEP8_CHORD_INVERSION
    offset = _STEP
    output1 = _CHORD_INVERSION

# Switch for select root
[switch]
    input1 = _STEP1_SEL_ROOT
    input2 = _STEP2_SEL_ROOT
    input3 = _STEP3_SEL_ROOT
    input4 = _STEP4_SEL_ROOT
    input5 = _STEP5_SEL_ROOT
    input6 = _STEP6_SEL_ROOT
    input7 = _STEP7_SEL_ROOT
    input8 = _STEP8_SEL_ROOT
    offset = _STEP
    output1 = _SEL_ROOT

# Switch for select third
[switch]
    input1 = _STEP1_SEL_3RD
    input2 = _STEP2_SEL_3RD
    input3 = _STEP3_SEL_3RD
    input4 = _STEP4_SEL_3RD
    input5 = _STEP5_SEL_3RD
    input6 = _STEP6_SEL_3RD
    input7 = _STEP7_SEL_3RD
    input8 = _STEP8_SEL_3RD
    offset = _STEP
    output1 = _SEL_3RD

# Switch for select fifth
[switch]
    input1 = _STEP1_SEL_5TH
    input2 = _STEP2_SEL_5TH
    input3 = _STEP3_SEL_5TH
    input4 = _STEP4_SEL_5TH
    input5 = _STEP5_SEL_5TH
    input6 = _STEP6_SEL_5TH
    input7 = _STEP7_SEL_5TH
    input8 = _STEP8_SEL_5TH
    offset = _STEP
    output1 = _SEL_5TH

# Switch for select 7th
[switch]
    input1 = _STEP1_SEL_7TH
    input2 = _STEP2_SEL_7TH
    input3 = _STEP3_SEL_7TH
    input4 = _STEP4_SEL_7TH
    input5 = _STEP5_SEL_7TH
    input6 = _STEP6_SEL_7TH
    input7 = _STEP7_SEL_7TH
    input8 = _STEP8_SEL_7TH
    offset = _STEP
    output1 = _SEL_7TH

# Switch for select 9TH
[switch]
    input1 = _STEP1_SEL_9TH
    input2 = _STEP2_SEL_9TH
    input3 = _STEP3_SEL_9TH
    input4 = _STEP4_SEL_9TH
    input5 = _STEP5_SEL_9TH
    input6 = _STEP6_SEL_9TH
    input7 = _STEP7_SEL_9TH
    input8 = _STEP8_SEL_9TH
    offset = _STEP
    output1 = _SEL_9TH

# Switch for select 11th
[switch]
    input1 = _STEP1_SEL_11TH
    input2 = _STEP2_SEL_11TH
    input3 = _STEP3_SEL_11TH
    input4 = _STEP4_SEL_11TH
    input5 = _STEP5_SEL_11TH
    input6 = _STEP6_SEL_11TH
    input7 = _STEP7_SEL_11TH
    input8 = _STEP8_SEL_11TH
    offset = _STEP
    output1 = _SEL_11TH

# Switch for select root
[switch]
    input1 = _STEP1_SEL_13TH
    input2 = _STEP2_SEL_13TH
    input3 = _STEP3_SEL_13TH
    input4 = _STEP4_SEL_13TH
    input5 = _STEP5_SEL_13TH
    input6 = _STEP6_SEL_13TH
    input7 = _STEP7_SEL_13TH
    input8 = _STEP8_SEL_13TH
    offset = _STEP
    output1 = _SEL_13TH

# Switch for low bass note (0, 1, 2, 3, 4, 5, or 6)
[switch]
    input1 = _STEP1_LOW_BASS_NOTE
    input2 = _STEP2_LOW_BASS_NOTE
    input3 = _STEP3_LOW_BASS_NOTE
    input4 = _STEP4_LOW_BASS_NOTE
    input5 = _STEP5_LOW_BASS_NOTE
    input6 = _STEP6_LOW_BASS_NOTE
    input7 = _STEP7_LOW_BASS_NOTE
    input8 = _STEP8_LOW_BASS_NOTE
    offset = _STEP
    output1 = _LOW_BASS_NOTE

# Switch for low bass pitch
[switch]
    input1 = _STEP1_LOW_BASS_PITCH
    input2 = _STEP2_LOW_BASS_PITCH
    input3 = _STEP3_LOW_BASS_PITCH
    input4 = _STEP4_LOW_BASS_PITCH
    input5 = _STEP5_LOW_BASS_PITCH
    input6 = _STEP6_LOW_BASS_PITCH
    input7 = _STEP7_LOW_BASS_PITCH
    input8 = _STEP8_LOW_BASS_PITCH
    offset = _STEP
    output1 = _LOW_BASS_BASE_PITCH

# -------------------------------------------------
# Root and Scale + Looper
# -------------------------------------------------

# Selects the number of clock ticks per sequence step, if the 8/8 switch is in the lower position (div 8)
[switch]
    input1 = 2
    input2 = 4
    input3 = 8
    offset = _BARS_PER_STEP_SWITCH
    output1 = _CLOCKTICKS_PER_STEP_DIV8

# Selects the number of clock ticks per sequence step, if the 8/8 switch is in the center position.
[switch]
    input1 = 16
    input2 = 32
    input3 = 64
    offset = _BARS_PER_STEP_SWITCH
    output1 = _CLOCKTICKS_PER_STEP_NORMAL

# Selects the number of clock ticks per sequence step, if the 8/8 switch is in the upper position (times 8)
[switch]
    input1 = 128
    input2 = 256
    input3 = 512
    offset = _BARS_PER_STEP_SWITCH
    output1 = _CLOCKTICKS_PER_STEP_TIMES8

[switch]
    input1 = _CLOCKTICKS_PER_STEP_DIV8
    input2 = _CLOCKTICKS_PER_STEP_NORMAL
    input3 = _CLOCKTICKS_PER_STEP_TIMES8
    offset = _BARSPERSTEP_DIVTIMES8_SWITCH
    output1 = _CLOCKTICKS_PER_STEP

[copy]
    input = _CLOCKTICKS_PER_STEP * _SEQUENCE_NUM_STEPS
    output = _SEQUENCE_NUM_CLOCKTICKS

[ifequal]
    input1 = S1.4
    input2 = 1
    ifequal = 1
    else = 0
    output = _LOOP_MUTED

[ifequal]
    input1 = S1.4
    input2 = 0
    ifequal = 0
    else = 1
    output = _LOOP_SWITCH

# Note: The looper just records the CV range -1 ... 1. So we need to fold ROOT (which is 0 ... 11)
# into that range and back again later.
[cvlooper]
    cvin = _ROOT_UNLOOPED * 0.05
    tapespeed = 0.1
    cvout = _ROOT_DOWNSCALED
    clock = _CLOCK
    reset = _RESET
    length = _SEQUENCE_NUM_CLOCKTICKS
    loopswitch = _LOOP_SWITCH
    bypass = _LOOP_MUTED

[copy]
    input = _ROOT_DOWNSCALED * 20
    output = _ROOT_UNTRANSPOSED

[math]
    input1 = _ROOT_UNTRANSPOSED + _GLOBAL_TRANSPOSITION
    input2 = 12
    modulo = _ROOT

[cvlooper]
    cvin = _SCALE_UNLOOPED * 0.02
    tapespeed = 0.1
    cvout = _SCALE_DOWNSCALED
    clock = _CLOCK
    reset = _RESET
    length = _SEQUENCE_NUM_CLOCKTICKS
    loopswitch = _LOOP_SWITCH
    bypass = _LOOP_MUTED

[copy]
    input = _SCALE_DOWNSCALED * 50
    output = _SCALE

[copy]
    input = _ROOT / 120
    output = O1

[copy]
    input = _SCALE / 120
    output = O2

# -------------------------------------------------
# Chord generator
# -------------------------------------------------

[button]
    button = B4.3
    output = _CHORD_PITCH_RAND_SEL
    inverted = _NO_CHORD_PITCH_RAND_SEL
    startvalue = 0

# Randomization of chord pitch. We use a bipolar encoder. Left hemisphere: pseudo random (alogquencer), right hemisphere: true random.
[encoder]
    encoder = E4.3
    select = _CHORD_PITCH_RAND_SEL
    notch = 0.1
    mode = 2
    negativecolor = 1.2
    color = 0.8
    output = _CHORD_PITCH_RAND_SETTING

# True random generator for chord pitches
[random]
    maximum = _CHORD_PITCH_RAND_SETTING * 1V
    minimum = _CHORD_PITCH_RAND_SETTING * -1V
    output = _CHORD_PITCH_RAND_RANDOM

# Pseudo random generator for chord pitches
[algoquencer]
    clock = _CLOCK
    pitchhigh = 1V
    pitchlow = -1V
    morphs = 0.05
    pitch = _CHORD_PITCH_RAND_ALGO

[compare]
    input = _CHORD_PITCH_RAND_SETTING
    compare = 0
    ifgreater = _CHORD_PITCH_RAND_RANDOM * _CHORD_PITCH_RAND_SETTING
    else = _CHORD_PITCH_RAND_ALGO * _CHORD_PITCH_RAND_SETTING
    output = _CHORD_PITCH_RANDOM

[sample]
    input = _CHORD_PITCH_RANDOM
    sample = I3
    output = _CHORD_PITCH_RANDOM_SYNCED

[mixer]
    input1 = _CHORD_PITCH + 1V
    input2 = _CHORD_SPREAD * -0.5
    output = _CHORD_PITCH_COMPENSATED

[chord]
    root = _ROOT
    degree = _SCALE
    spread = _CHORD_SPREAD
    pitch = _CHORD_PITCH_COMPENSATED + _CHORD_PITCH_RANDOM_SYNCED
    inversion = _CHORD_INVERSION
    select1 = _SEL_ROOT
    select3 = _SEL_3RD
    select5 = _SEL_5TH
    select7 = _SEL_7TH
    select9 = _SEL_9TH
    select11 = _SEL_11TH
    select13 = _SEL_13TH
    tuningmode = _TUNING_MODE
    tuningpitch = _TUNING_PITCH
    output1 = _CH_OUT_1
    output2 = _CH_OUT_2
    output3 = _CH_OUT_3
    output4 = _CH_OUT_4

[slew]
    input = _CH_OUT_1
    slew = _CHORD_SLEW
    exponential = _CH_SLEWED_1

[slew]
    input = _CH_OUT_2
    slew = _CHORD_SLEW
    exponential = _CH_SLEWED_2

[slew]
    input = _CH_OUT_3
    slew = _CHORD_SLEW
    exponential = _CH_SLEWED_3

[slew]
    input = _CH_OUT_4
    slew = _CHORD_SLEW
    exponential = _CH_SLEWED_4

# -------------------------------------------------
# Chord calibrator
# -------------------------------------------------

[copy]
    input = S1.5 * 1V - 1V
    output = _OCT_SWITCH_1

[copy]
    input = S1.6 * 1V - 1V
    output = _OCT_SWITCH_2

[copy]
    input = S1.7 * 1V - 1V
    output = _OCT_SWITCH_3

[copy]
    input = S1.8 * 1V - 1V
    output = _OCT_SWITCH_4

[encoder]
    select = _TUNING_MODE
    encoder = E4.1
    movedup = _CAL_UP_1
    moveddown = _CAL_DOWN_1
    override = _CAL_CORRECTION_1 * 2
    button = _CAL_CLEARHERE_1
    mode = 2
    color = 0.4
    negativecolor = 0.8

[calibrator]
    input = _CH_SLEWED_1 + _OCT_SWITCH_1
    nudgeup = _CAL_UP_1
    nudgedown = _CAL_DOWN_1
    correction = _CAL_CORRECTION_1
    output = _CALIBRATED_CH_1
    nudgeamount = 0.01
    clearhere = _CAL_CLEARHERE_1

[encoder]
    select = _TUNING_MODE
    encoder = E4.2
    movedup = _CAL_UP_2
    moveddown = _CAL_DOWN_2
    override = _CAL_CORRECTION_2 * 2
    button = _CAL_CLEARHERE_2
    mode = 2
    color = 0.4
    negativecolor = 0.8

[calibrator]
    input = _CH_SLEWED_2 + _OCT_SWITCH_2
    nudgeup = _CAL_UP_2
    nudgedown = _CAL_DOWN_2
    correction = _CAL_CORRECTION_2
    output = _CALIBRATED_CH_2
    nudgeamount = 0.01
    clearhere = _CAL_CLEARHERE_2

[encoder]
    select = _TUNING_MODE
    encoder = E4.3
    movedup = _CAL_UP_3
    moveddown = _CAL_DOWN_3
    override = _CAL_CORRECTION_3 * 2
    button = _CAL_CLEARHERE_3
    mode = 2
    color = 0.4
    negativecolor = 0.8

[calibrator]
    input = _CH_SLEWED_3 + _OCT_SWITCH_3
    nudgeup = _CAL_UP_3
    nudgedown = _CAL_DOWN_3
    correction = _CAL_CORRECTION_3
    output = _CALIBRATED_CH_3
    nudgeamount = 0.01
    clearhere = _CAL_CLEARHERE_3

[encoder]
    select = _TUNING_MODE
    encoder = E4.4
    movedup = _CAL_UP_4
    moveddown = _CAL_DOWN_4
    override = _CAL_CORRECTION_4 * 2
    button = _CAL_CLEARHERE_4
    mode = 2
    color = 0.4
    negativecolor = 0.8

[calibrator]
    input = _CH_SLEWED_4 + _OCT_SWITCH_4
    nudgeup = _CAL_UP_4
    nudgedown = _CAL_DOWN_4
    correction = _CAL_CORRECTION_4
    output = _CALIBRATED_CH_4
    nudgeamount = 0.01
    clearhere = _CAL_CLEARHERE_4

# -------------------------------------------------
# Low bass
# -------------------------------------------------

[minifonion]
    input = 0V
    root = _ROOT
    degree = _SCALE
    noteshift = _LOW_BASS_NOTE
    output = _LOW_BASS_PITCH_UNFOLDED
    select1 = 1
    select3 = 0
    select5 = 0
    select7 = 0
    select9 = 0
    select11 = 0
    select13 = 0
    selectfill1 = 0
    selectfill2 = 0
    selectfill3 = 0
    selectfill4 = 0
    selectfill5 = 0

[fold]
    input = _LOW_BASS_PITCH_UNFOLDED
    minimum = _LOW_BASS_BASE_PITCH
    maximum = _LOW_BASS_BASE_PITCH + 0.999V
    foldby = 1V
    output = _LOW_BASS_PITCH_UNTUNED

[ifequal]
    input1 = _TUNING_MODE
    input2 = 0
    ifequal = _LOW_BASS_PITCH_UNTUNED
    else = _TUNING_PITCH
    output = _LOW_BASS_OUT

[button]
    button = B3.8
    led = L3.8
    onvalue = 0
    offvalue = 1
    output = _UNFREEZE_LB

[sample]
    input = _LOW_BASS_OUT
    gate = _UNFREEZE_LB
    output = _LOW_BASS_FROZEN

[slew]
    input = _LOW_BASS_FROZEN
    slew = _LOW_BASS_SLEW
    exponential = _LOW_BASS_SLEWED

# -------------------------------------------------
# Vibrato
# -------------------------------------------------

[pot]
    pot = P3.2
    slope = 2
    output = _VIBRATO_SPEED_POT

[pot]
    pot = P1.3
    slope = 2
    output = _VIBRATO_CH_DEPTH_POT

[pot]
    pot = P1.4
    slope = 2
    output = _VIBRATO_LB_DEPTH_POT

[lfo]
    hz = _VIBRATO_SPEED_POT * 100
    bipolar = 1
    level = _NO_TUNING_MODE * 0.1V
    triangle = _VIBRATO_LFO

# Delayed vibrato for Chords
[contour]
    trigger = I3
    hold = P1.7 * 2
    release = P1.7 * 1.1
    shape = 0.5
    level = _VIBRATO_CH_DEPTH_POT
    inverted = _CH_DELAYED_VIBRATO_LEVEL

# Delayed vibrato for low bass
[contour]
    trigger = I4
    hold = P1.8 * 2
    release = P1.8 * 1.1
    shape = 0.5
    level = _VIBRATO_LB_DEPTH_POT
    inverted = _LB_DELAYED_VIBRATO_LEVEL

[mixer]
    input1 = _CALIBRATED_CH_1
    input2 = _VIBRATO_LFO * _CH_DELAYED_VIBRATO_LEVEL
    output = _VIBRATED_CH_1

[mixer]
    input1 = _CALIBRATED_CH_2
    input2 = _VIBRATO_LFO * _CH_DELAYED_VIBRATO_LEVEL
    output = _VIBRATED_CH_2

[mixer]
    input1 = _CALIBRATED_CH_3
    input2 = _VIBRATO_LFO * _CH_DELAYED_VIBRATO_LEVEL
    output = _VIBRATED_CH_3

[mixer]
    input1 = _CALIBRATED_CH_4
    input2 = _VIBRATO_LFO * _CH_DELAYED_VIBRATO_LEVEL
    output = _VIBRATED_CH_4

[mixer]
    input1 = _LOW_BASS_SLEWED
    input2 = _VIBRATO_LFO * _LB_DELAYED_VIBRATO_LEVEL
    output = _VIBRATED_LB

# -------------------------------------------------
# Detune + Superjust
# -------------------------------------------------

[detune]
    input1 = _VIBRATED_CH_1
    input2 = _VIBRATED_CH_2
    input3 = _VIBRATED_CH_3
    input4 = _VIBRATED_CH_4
    input5 = _VIBRATED_LB
    detune = P1.6 * -0.6
    output1 = O5
    output2 = O6
    output3 = O7
    output4 = O8
    output5 = O4

# -------------------------------------------------
# MIDI output
# -------------------------------------------------

[lfo]
    hz = 200
    square = _MIDI_UPDATE

[midiout]
    pitch1 = _ROOT / 120
    gate1 = _MIDI_UPDATE
    ccnumber1 = 1
    cc1 = _SCALE / 127
    updateccs = _MIDI_UPDATE

# -------------------------------------------------
# LED Gauges
# -------------------------------------------------

[lfo]
    hz = 2.5
    square = _LOOP_BLINK

[mixer]
    input1 = _LOOP_SWITCH * 0.6
    input2 = _LOOP_MUTED * 0.4
    output = _LOOP_LED_COLOR

[copy]
    input = _LOOP_LED_COLOR * _LOOP_BLINK
    output = R13

[copy]
    input = _LOOP_LED_COLOR * _LOOP_BLINK
    output = R14

[copy]
    input = _LOOP_LED_COLOR * _LOOP_BLINK
    output = R15

[copy]
    input = _LOOP_LED_COLOR * _LOOP_BLINK
    output = R16

# Divide the infinite counter by the number of clock ticks a step has. This gives us the infinite step number.
[math]
    input1 = _INFINTE_CLOCK_COUNTER
    input2 = 16
    quotient = _INFINITE_BAR_COUNTER_FLOAT

# The quotient created fractions. Round this down to the lower integer.
[math]
    input1 = _INFINITE_BAR_COUNTER_FLOAT
    floor = _INFINITE_BAR_COUNTER

[math]
    input1 = _INFINITE_BAR_COUNTER
    input2 = 4
    modulo = _BAR_0_1_2_3

[switch]
    input1 = 0.2 * _PRESET + 0.3
    offset = _BAR_0_1_2_3 * -1
    output1 = R9
    output2 = R10
    output3 = R11
    output4 = R12
