# Melody sequencer with 4 tracks
# LABELS: master=18
# INPUTS:
#  I1: [CLK In] External clock
#  I2: [RST In] Reset all sequences to step 1 on a gate or trigger here

# OUTPUTS:
#  O1: [V/O 1] Pitch CV output track 1
#  O2: [Velo 1] Modulation CV output track 1
#  O3: [V/O 2] Pitch CV output track 2
#  O4: [Velo 2] Modulation CV output track 2
#  O5: [V/O 3] Pitch CV output track 3
#  O6: [Velo 3] Modulation CV output track 3
#  O7: [V/O 4] Pitch CV output track 4
#  O8: [Velo 4] Modulation CV output track 4

# GATES ON MODULE 1:
#  G1.1: [Gate 1] Gate output track 1
#  G1.2: [Gate 2] Gate output track 2
#  G1.3: [Gate 3] Gate output track 3
#  G1.4: [Gate 4] Gate output track 4

# CONTROLLER 1:
#  B1.1: [ROOT] Allow root note
#  B1.2: [3RD] Allow third note
#  B1.3: [5TH] Allow fifth note
#  B1.4: [7TH] Allow seventh note
#  B1.5: [9TH] Allow nineth note
#  B1.6: [11TH] Allow eleventh note
#  B1.7: [13TH] Allow thirtheenth note
#  B1.8: [CTRL] Switch some of the button functions

# CONTROLLER 2:
#  B2.1: [Preset A] Ctrl: Switch to preset A, long press: save to preset A
#  B2.2: [Preset B] Ctrl: Switch to preset B, long press: save to preset B
#  B2.3: [Preset C] Ctrl: Switch to preset C, long press: save to preset C
#  B2.4: [CLR] Short press: reset play mode, with CTRL: clear track, long press factory reset
#  B2.5: [TBR] If enabled, transposes the melody when the root note changes.
#  B2.6: [INV] Invert the melody (change low to high and vice versa)
#  B2.7: [AAAB] Switch between the song from A, AAAB and AABB
#  B2.8: [CHRO] Disable scale and note selection, allow all 12 notes
#  B2.9: [ARP] Switch this track to arpeggio mode
#  B2.10: [LUCK] Randomly change step buttons, if Ctrl is held, change the gates instead.
#  B2.11: [RST] Reset current track (Ctrl: all track) to step 1 immediately
#  B2.12: [START] Start/stop sequencer - start also does reset
#  B2.13: [TON] Tonality menu
#  B2.14: [CLK] Menu for clock speed and swing
#  B2.15: [TRK] Track menu
#  B2.16: [PERF] Performance menu
#  B2.17: [RATC] Number of sub gates per clock
#  B2.18: [REP] Number of repeats, skip steps
#  B2.19: [PAT] Pattern for repeated gates
#  B2.20: [S/E] Set start and end (range of steps to play)
#  B2.21: [RAND] Pitch randomization
#  B2.22: [ACT] Set step activities
#  B2.23: [PROB] Gate probability
#  B2.24: [COPY] Copy current page of current track. With CTRL: Paste
#  B2.25: [NOTE] Set motor faders to pitch
#  B2.26: [VELO] Velocity / Additional gate
#  B2.27: [GL] Gate length and glide
#  B2.28: [PAGE] Select second page of steps
#  B2.29: [Track 1] Select track 1
#  B2.30: [Track 2] Select track 2
#  B2.31: [Track 3] Select track 3
#  B2.32: [Track 4] Select track 4

[db8e]
[b32]
[m4]
[m4]

# -------------------------------------------------
# Tonality
# -------------------------------------------------

# Mix together all sources for the root note
[mixer]
    input1 = _ROOT_FADER
    input2 = _MIDI_IN_ROOT_PITCH * 120
    output = _ROOT

# Mix together sources for the scale
[mixer]
    input1 = _DEGREE_FADER
    input2 = _MIDI_IN_SCALE_CC * 127
    output = _DEGREE

# Set the root note (from C, C#, D, ... to C again)
[motorfader]
    select = _GLOBAL_FADER_SELECTION
    selectat = 97
    fader = 1
    notches = 13
    ledcolor = 1.1
    ledvalue = 1
    output = _ROOT_FADER

# Names for the display
[switch]
    input1 = "C"
    input2 = "C#"
    input3 = "D"
    input4 = "D#"
    input5 = "E"
    input6 = "F"
    input7 = "F#"
    input8 = "G"
    input9 = "G#"
    input10 = "A"
    input11 = "A#"
    input12 = "B"
    offset = _ROOT_FADER
    output1 = _ROOT_NAME

# Display the name of 'Root note' when edited
[display]
    linger = 0.1
    header = "ROOT NOTE"
    text = _ROOT_NAME
    fontsize = 4

# Set the musical scale
[motorfader]
    select = _GLOBAL_FADER_SELECTION
    selectat = 97
    fader = 2
    notches = 12
    startvalue = 0
    ledcolor = _COLOR_DEGREE_FADER
    ledvalue = 1
    output = _DEGREE_FADER

# Names for the display
[switch]
    input1 = "lydian major"
    input2 = "natuarl major"
    input3 = "mixolydian"
    input4 = "mixolyd. sus4"
    input5 = "altered"
    input6 = "spanish/hm5"
    input7 = "dorian minor"
    input8 = "natural minor"
    input9 = "harmonic minor"
    input10 = "phrygian minor"
    input11 = "diminished"
    input12 = "augmented"
    offset = _DEGREE_FADER
    output1 = _SCALE_NAME

# Display the name of 'Scale' when edited
[display]
    linger = 0.1
    header = "SCALE"
    text = _SCALE_NAME
    fontsize = 2

# Select the color for the scale fader
[multicompare]
    input = _DEGREE_FADER
    compare1 = 0
    ifequal1 = 0.5
    compare2 = 1
    ifequal2 = 0.4
    compare3 = 2
    ifequal3 = 0.73
    compare4 = 6
    ifequal4 = 0.2
    compare5 = 7
    ifequal5 = 1.2
    compare6 = 9
    ifequal6 = 1.1
    else = 0
    output = _COLOR_DEGREE_FADER

# Global octave switch for all tracks
[motorfader]
    select = _GLOBAL_FADER_SELECTION
    selectat = 97
    fader = 3
    notches = 5
    startvalue = 2
    ledcolor = 0.2
    ledvalue = -0.3
    output = _GLOBAL_OCTAVE_SWITCH
    button = _RESET_OCTAVE_SWITCH
    clear = _RESET_OCTAVE_SWITCH

# Names for the display
[switch]
    input1 = "2 octaves down"
    input2 = "1 octave down"
    input3 = "no octaving"
    input4 = "1 octave up"
    input5 = "2 octaves up"
    offset = _GLOBAL_OCTAVE_SWITCH
    output1 = _GLOBAL_OCT_SWITCH_NAME

# Display the name of 'Octave switch' when edited
[display]
    linger = 0.1
    header = "OCTAVE SWITCH"
    text = _GLOBAL_OCT_SWITCH_NAME
    fontsize = 2

# Global diatonic transposition for all tracks
[motorfader]
    select = _GLOBAL_FADER_SELECTION
    selectat = 97
    fader = 4
    notches = 15
    outputoffset = -7
    startvalue = 7
    ledcolor = 0.4
    ledvalue = -0.3
    output = _GLOBAL_NOTESHIFT
    button = _RESET_NOTESHIFT
    clear = _RESET_NOTESHIFT
    header = "DIATONIC TRANSPOSE"

# Prevent the pitch to change between clock ticks
[sample]
    input = _GLOBAL_NOTESHIFT
    sample = _CLOCK
    output = _GLOBAL_NOTESHIFT_CLOCKED

# Global transposition by semitones for all tracks
[motorfader]
    select = _GLOBAL_FADER_SELECTION
    selectat = 97
    fader = 5
    notches = 25
    startvalue = 12
    outputoffset = -12
    ledcolor = 0.85
    ledvalue = -0.3
    output = _GLOBAL_TRANSPOSITION
    button = _RESET_TRANSPOSITION
    clear = _RESET_TRANSPOSITION
    header = "TRANSPOSITION"

# Global transposition by semitones for all tracks
[motorfader]
    select = _GLOBAL_FADER_SELECTION
    selectat = 97
    fader = 6
    notches = 3
    startvalue = 0
    ledcolor = 0
    ledvalue = _TUNING_LED + 0.3
    output = _TUNING_COMPOSE
    display = 0

# Names for the display
[switch]
    input1 = "Normal"
    input2 = "Tuning mode"
    input3 = "Compose mode"
    offset = _TUNING_COMPOSE
    output1 = _TUNING_NAME

# Display the name of 'Tuning / Compose' when edited
[display]
    linger = 0.1
    header = "TUNING / COMPOSE"
    text = _TUNING_NAME
    fontsize = 2

# Make tuning mode or compose mode active depending on the fader position.
[switch]
    input1 = 1
    offset = _TUNING_COMPOSE
    output2 = _COMPOSEMODE
    output3 = _TUNINGMODE

# Let the LED blink so that we are aware of the special mode
[lfo]
    hz = 5
    level = 0.7 * _TUNING_COMPOSE
    square = _TUNING_LED

# Glide length (duration of slides)
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _SELECTED_TRACK
    selectat = 97
    fader = 7
    startvalue = 0.3
    ledcolor = 0.5
    ledvalue = 1
    output = _T1_GLIDE_LENGTH_FADER
    header = "GLIDE DURATION"

# Make glide reasonably fast, make fader curve zoomed in in the short glide times.
[math]
    input1 = _T1_GLIDE_LENGTH_FADER * 0.5
    input2 = 3
    power = _T1_GLIDE_LENGTH

# Set the CV range for track 1
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _SELECTED_TRACK
    selectat = 97
    fader = 8
    notches = 6
    startvalue = 1
    ledcolor = 0.65
    ledvalue = _TUNING_LED + 0.3
    outputoffset = 1
    output = _T1_CVRANGE
    header = "Range (octaves)"

# Glide length (duration of slides)
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _SELECTED_TRACK
    selectat = 194
    fader = 7
    startvalue = 0.3
    ledcolor = 0.5
    ledvalue = 1
    output = _T2_GLIDE_LENGTH_FADER
    header = "GLIDE DURATION"

# Make glide reasonably fast, make fader curve zoomed in in the short glide times.
[math]
    input1 = _T2_GLIDE_LENGTH_FADER * 0.5
    input2 = 3
    power = _T2_GLIDE_LENGTH

# Set the CV range for track 2
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _SELECTED_TRACK
    selectat = 194
    fader = 8
    notches = 6
    startvalue = 1
    ledcolor = 0.65
    ledvalue = _TUNING_LED + 0.3
    outputoffset = 1
    output = _T2_CVRANGE
    header = "Range (octaves)"

# Glide length (duration of slides)
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _SELECTED_TRACK
    selectat = 291
    fader = 7
    startvalue = 0.3
    ledcolor = 0.5
    ledvalue = 1
    output = _T3_GLIDE_LENGTH_FADER
    header = "GLIDE DURATION"

# Make glide reasonably fast, make fader curve zoomed in in the short glide times.
[math]
    input1 = _T3_GLIDE_LENGTH_FADER * 0.5
    input2 = 3
    power = _T3_GLIDE_LENGTH

# Set the CV range for track 3
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _SELECTED_TRACK
    selectat = 291
    fader = 8
    notches = 6
    startvalue = 1
    ledcolor = 0.65
    ledvalue = _TUNING_LED + 0.3
    outputoffset = 1
    output = _T3_CVRANGE
    header = "Range (octaves)"

# Glide length (duration of slides)
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _SELECTED_TRACK
    selectat = 388
    fader = 7
    startvalue = 0.3
    ledcolor = 0.5
    ledvalue = 1
    output = _T4_GLIDE_LENGTH_FADER
    header = "GLIDE DURATION"

# Make glide reasonably fast, make fader curve zoomed in in the short glide times.
[math]
    input1 = _T4_GLIDE_LENGTH_FADER * 0.5
    input2 = 3
    power = _T4_GLIDE_LENGTH

# Set the CV range for track 4
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _SELECTED_TRACK
    selectat = 388
    fader = 8
    notches = 6
    startvalue = 1
    ledcolor = 0.65
    ledvalue = _TUNING_LED + 0.3
    outputoffset = 1
    output = _T4_CVRANGE
    header = "Range (octaves)"

# -------------------------------------------------
# MIDI input
# -------------------------------------------------

# MIDI input for clock, start and stop
[midiin]
    trs = 10
    usb = 10
    start = _EXT_RUNNING_STARTED
    stop = _EXT_RUNNING_STOPPED
    clock = _MIDI_INPUT_CLOCK
    running = _RUNNING_EXT

# Detect a MIDI input clock signal if within the last 2 seconds there is a pulse
[gatetool]
    inputtrigger = _MIDI_INPUT_CLOCK
    gatelength = 2
    outputgate = _MIDI_INPUT_CLOCK_PRESENT

# Get root and scale via MIDI
[midiin]
    trs = 1
    pitch1 = _MIDI_IN_ROOT_PITCH
    ccnumber1 = 1
    cc1 = _MIDI_IN_SCALE_CC

# -------------------------------------------------
# Clocking
# -------------------------------------------------

# Selects 100s of BPM
[motorfader]
    select = _GLOBAL_FADER_SELECTION
    selectat = 99
    fader = 1
    notches = 3
    output = _CLOCK_BPM_100
    startvalue = 1
    ledcolor = 0.2
    ledvalue = 1
    display = 0

# Selects 10s of BPM
[motorfader]
    select = _GLOBAL_FADER_SELECTION
    selectat = 99
    fader = 2
    notches = 10
    output = _CLOCK_BPM_10
    startvalue = 2
    ledcolor = 0.2
    ledvalue = 1
    display = 0

# Selects 1s of BPM
[motorfader]
    select = _GLOBAL_FADER_SELECTION
    selectat = 99
    fader = 3
    notches = 10
    output = _CLOCK_BPM_1
    startvalue = 0
    ledcolor = 0.2
    ledvalue = 1
    display = 0

# Clock bend half speed / double speed. Touch button to reset.
[motorfader]
    select = _GLOBAL_FADER_SELECTION
    selectat = 99
    fader = 4
    output = _CLOCK_BEND_FADER
    startvalue = 0.5
    ledcolor = _CLOCK_BEND_COLOR
    ledvalue = 1
    button = _RESET_CLOCK_BEND
    clear = _RESET_CLOCK_BEND
    display = 0

# Snap to the perfectly neutral position if the fader is almost there.
[pot]
    pot = _CLOCK_BEND_FADER
    notch = 0.01
    output = _CLOCK_BEND
    display = 0

# Let the LED light bright if the bending alteration is exactly zero.
[ifequal]
    input1 = _CLOCK_BEND
    input2 = 0.5
    ifequal = 0.4
    else = 0.8
    output = _CLOCK_BEND_COLOR

# Add up all three BPM faders
[mixer]
    input1 = _CLOCK_BPM_100 * 100
    input2 = _CLOCK_BPM_10 * 10
    input3 = _CLOCK_BPM_1
    output = _CLOCK_BPM_THREE_FADERS

# Clock swing (shuffle)
[motorfader]
    select = _GLOBAL_FADER_SELECTION
    selectat = 99
    fader = 5
    output = _CLOCK_SWING
    ledcolor = 1.1
    ledvalue = _CLOCK_SWING * 0.9 + 0.1
    header = "SWING"

# Small hack for letting the user toggle the state with the touch button
[switch]
    input1 = _INT_CLOCK_UNMUTED
    input2 = 0
    offset = B2.4
    output1 = _CLOCK_MUTE_STARTVALUE

# Mute the clock, switch to external clocks if present. Touch button to toggle.
[motorfader]
    select = _GLOBAL_FADER_SELECTION
    selectat = 99
    fader = 6
    notches = 2
    output = _INT_CLOCK_UNMUTED
    button = _TOGGLE_CLOCK_MUTE
    clear = _TOGGLE_CLOCK_MUTE
    startvalue = -1 * _CLOCK_MUTE_STARTVALUE + 1
    ledcolor = _INT_CLOCK_UNMUTED * -0.4 + 0.8
    ledvalue = 1

# Names for the display
[ifequal]
    input1 = _INT_CLOCK_UNMUTED
    input2 = 0
    ifequal = "stopped"
    else = "running"
    output = _INT_CLOCK_STATE_NAME

# Display the name of 'Internal clock' when edited
[display]
    linger = 0.1
    header = "INTERNAL CLOCK"
    text = _INT_CLOCK_STATE_NAME
    fontsize = 2

# Disable this unused fader
[unusedfaders]
    select = _GLOBAL_FADER_SELECTION
    selectat = 99
    firstfader = 7

# Range of pitch accumulator
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _SELECTED_TRACK
    selectat = 99
    fader = 8
    startvalue = 3
    notches = 17
    ledcolor = 1.2
    ledvalue = 1
    output = _T1_ACCU_RANGE
    header = "ACCU CYCLES"

# Range of pitch accumulator
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _SELECTED_TRACK
    selectat = 198
    fader = 8
    startvalue = 3
    notches = 17
    ledcolor = 1.2
    ledvalue = 1
    output = _T2_ACCU_RANGE
    header = "ACCU CYCLES"

# Range of pitch accumulator
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _SELECTED_TRACK
    selectat = 297
    fader = 8
    startvalue = 3
    notches = 17
    ledcolor = 1.2
    ledvalue = 1
    output = _T3_ACCU_RANGE
    header = "ACCU CYCLES"

# Range of pitch accumulator
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _SELECTED_TRACK
    selectat = 396
    fader = 8
    startvalue = 3
    notches = 17
    ledcolor = 1.2
    ledvalue = 1
    output = _T4_ACCU_RANGE
    header = "ACCU CYCLES"

# Split clock bending fader in two hemispheres, so the the lower one is linear and can go to
# 0 Hz, while the upper half is going to exactly double speed.
[pot]
    pot = _CLOCK_BEND
    lefthalfinv = _CLOCK_BEND_LINEAR
    righthalf = _CLOCK_BEND_EXP

[math]
    input1 = 2
    input2 = _CLOCK_BEND_EXP
    power = _CLOCK_BEND_FACTOR

[copy]
    input = _CLOCK_BPM_THREE_FADERS * _CLOCK_BEND_LINEAR
    output = _CLOCK_BPM_LINEAR

[copy]
    input = _CLOCK_BPM_LINEAR * _CLOCK_BEND_FACTOR
    output = _CLOCK_BPM_UNMUTED

# Display current BPM setting
[display]
    value = _CLOCK_BPM_UNMUTED
    header = "CLOCK SPEED"
    fontsize = 3
    threshold = 0.1
    numbermode = 1

# Set the BPM to zero while the clock is muted.
[copy]
    input = _CLOCK_BPM_UNMUTED * _INT_CLOCK_UNMUTED
    output = _CLOCK_BPM

# The actual clock, use a very short pulse so we have essentially just triggers
[lfo]
    hz = _CLOCK_BPM / 15
    pulsewidth = 0.1
    square = _INT_CLOCK
    sync = _RUNNING

# Detect an external clock signal, if within the last 2 seconds there was a trigger
[gatetool]
    inputtrigger = I1
    gatelength = 2
    outputgate = _EXTERNAL_CLOCK_PRESENT

# Select first avaiable clock in defined precedence order
[case]
    case1 = _MIDI_INPUT_CLOCK_PRESENT
    value1 = _MIDI_INPUT_CLOCK
    case2 = _INT_CLOCK_UNMUTED
    value2 = _INT_CLOCK
    case3 = _EXTERNAL_CLOCK_PRESENT
    value3 = I1
    output = _CLOCK_UNSWUNG

# Apply swing to the clock
[timing]
    clock = _CLOCK_UNSWUNG
    reset = _RESET
    timing1 = 0
    timing2 = _CLOCK_SWING * 0.33
    output = _CLOCK

# Pulses for changes via lucky buttons / lucky faders
[lfo]
    hz = 40
    square = _LUCKY_CLOCK

# Clock division 3/2 for the arpeggiators
[clocktool]
    clock = _CLOCK
    output = _CLOCK_3_2
    multiply = 3
    divide = 2

# Clock division 2/1 for the arpeggiators
[clocktool]
    clock = _CLOCK
    output = _CLOCK_2_1
    multiply = 2
    divide = 1

# Clock division 3/1 for the arpeggiators
[clocktool]
    clock = _CLOCK
    output = _CLOCK_3_1
    multiply = 3
    divide = 1

# Clock division 4/1 for the arpeggiators
[clocktool]
    clock = _CLOCK
    output = _CLOCK_4_1
    multiply = 4
    divide = 1

# Clock division 6/1 for the arpeggiators
[clocktool]
    clock = _CLOCK
    output = _CLOCK_6_1
    multiply = 6
    divide = 1

# Clock division 8/1 for the arpeggiators
[clocktool]
    clock = _CLOCK
    output = _CLOCK_8_1
    multiply = 8
    divide = 1

# Names for the display
[ifequal]
    input1 = _RUNNING
    input2 = 0
    ifequal = "Stopped"
    else = "Started"
    output = _RUNNING_NAME

# Display the name of '' when edited
[display]
    linger = 0.1
    header = ""
    text = _RUNNING_NAME
    fontsize = 2

# -------------------------------------------------
# Global buttons
# -------------------------------------------------

# A long press on the clear button resets all settings of the sequencer to its default state
[button]
    button = B2.4
    states = 1
    longpress = _FACTORY_RESET

# Do the factory reset
[droid]
    clearall = _FACTORY_RESET

# Animation of track buttons when muted.
[lfo]
    level = 0.8
    bipolar = 0
    square = _MUTE_BLINK
    pulsewidth = 0.2
    hz = 2.5

# Mute button for track 1 (same as track button)
[button]
    select = _CONTROL
    button = B2.29
    led = L2.29
    output = _T1_MUTED

# Names for the display
[ifequal]
    input1 = _T1_MUTED
    input2 = 0
    ifequal = "T1 unmuted"
    else = "T1 muted"
    output = _T1_MUTED_NAME

# Display the name of '' when edited
[display]
    linger = 0.1
    header = ""
    text = _T1_MUTED_NAME
    fontsize = 2

# Compute state of track LED based on wether it is selected and/or muted
[switch]
    offset = _T1_SELECTED * 2 + _T1_MUTED
    input1 = 0
    input2 = _MUTE_BLINK
    input3 = 1
    input4 = -1 * _MUTE_BLINK + 1
    output1 = _T1_TRACKLED

# Show mute state of track while CTRL is held
[ifequal]
    input1 = _CONTROL
    input2 = 1
    ifequal = _T1_MUTED
    else = _T1_TRACKLED
    output = L2.29

# Mute button for track 2 (same as track button)
[button]
    select = _CONTROL
    button = B2.30
    led = L2.30
    output = _T2_MUTED

# Names for the display
[ifequal]
    input1 = _T2_MUTED
    input2 = 0
    ifequal = "T2 unmuted"
    else = "T2 muted"
    output = _T2_MUTED_NAME

# Display the name of '' when edited
[display]
    linger = 0.1
    header = ""
    text = _T2_MUTED_NAME
    fontsize = 2

# Compute state of track LED based on wether it is selected and/or muted
[switch]
    offset = _T2_SELECTED * 2 + _T2_MUTED
    input1 = 0
    input2 = _MUTE_BLINK
    input3 = 1
    input4 = -1 * _MUTE_BLINK + 1
    output1 = _T2_TRACKLED

# Show mute state of track while CTRL is held
[ifequal]
    input1 = _CONTROL
    input2 = 1
    ifequal = _T2_MUTED
    else = _T2_TRACKLED
    output = L2.30

# Mute button for track 3 (same as track button)
[button]
    select = _CONTROL
    button = B2.31
    led = L2.31
    output = _T3_MUTED

# Names for the display
[ifequal]
    input1 = _T3_MUTED
    input2 = 0
    ifequal = "T3 unmuted"
    else = "T3 muted"
    output = _T3_MUTED_NAME

# Display the name of '' when edited
[display]
    linger = 0.1
    header = ""
    text = _T3_MUTED_NAME
    fontsize = 2

# Compute state of track LED based on wether it is selected and/or muted
[switch]
    offset = _T3_SELECTED * 2 + _T3_MUTED
    input1 = 0
    input2 = _MUTE_BLINK
    input3 = 1
    input4 = -1 * _MUTE_BLINK + 1
    output1 = _T3_TRACKLED

# Show mute state of track while CTRL is held
[ifequal]
    input1 = _CONTROL
    input2 = 1
    ifequal = _T3_MUTED
    else = _T3_TRACKLED
    output = L2.31

# Mute button for track 4 (same as track button)
[button]
    select = _CONTROL
    button = B2.32
    led = L2.32
    output = _T4_MUTED

# Names for the display
[ifequal]
    input1 = _T4_MUTED
    input2 = 0
    ifequal = "T4 unmuted"
    else = "T4 muted"
    output = _T4_MUTED_NAME

# Display the name of '' when edited
[display]
    linger = 0.1
    header = ""
    text = _T4_MUTED_NAME
    fontsize = 2

# Compute state of track LED based on wether it is selected and/or muted
[switch]
    offset = _T4_SELECTED * 2 + _T4_MUTED
    input1 = 0
    input2 = _MUTE_BLINK
    input3 = 1
    input4 = -1 * _MUTE_BLINK + 1
    output1 = _T4_TRACKLED

# Show mute state of track while CTRL is held
[ifequal]
    input1 = _CONTROL
    input2 = 1
    ifequal = _T4_MUTED
    else = _T4_TRACKLED
    output = L2.32

# Track selection
[buttongroup]
    header = "TRACK"
    output = _SELECTED_TRACK
    select = _NO_CONTROL
    extrapress = _TRACK_EXTRA_PRESS
    button1 = B2.29
    value1 = 1
    led1 = _T1_SELECTED
    button2 = B2.30
    value2 = 2
    led2 = _T2_SELECTED
    button3 = B2.31
    value3 = 3
    led3 = _T3_SELECTED
    button4 = B2.32
    value4 = 4
    led4 = _T4_SELECTED

# -------------------------------------------------
# Special menus
# -------------------------------------------------

# Select a global menu function of the faders. There is no button for "normal" in order to save
# buttons. Simply press the currently lit button to deactivate all menu buttons and go back
# to controlling the sequence.
[buttongroup]
    button1 = B2.13
    led1 = L2.13
    value1 = 97
    button2 = B2.14
    led2 = L2.14
    value2 = 99
    button3 = B2.15
    led3 = L2.15
    value3 = _SELECTED_TRACK + 10
    button4 = B2.16
    led4 = L2.16
    value4 = 98
    clear = _FADERMODE_CHANGED
    display = 0
    startbutton = 0
    minactive = 0
    maxactive = 1
    output = _GLOBAL_MENU

# If there is no menu active, the fader edit the sequence of the currently selected track.
[ifequal]
    input1 = _GLOBAL_MENU
    input2 = 0
    ifequal = _SELECTED_TRACK
    else = _GLOBAL_MENU
    output = _GLOBAL_FADER_SELECTION

# LFO for blinking the ARP LED while it is in Autostop mode
[lfo]
    hz = 2.5
    bipolar = 0
    level = -0.8
    square = _ARP_AUTOSTOP_BLINK

# Provide state of the control button in a patch cable.
[copy]
    input = B1.8
    output = _CONTROL

# Inverted state of control button, is 1 of not held.
[copy]
    input = -1 * B1.8 + 1
    output = _NO_CONTROL

# Select the current mode of the faders for the sequencer
[buttongroup]
    button1 = B2.25
    led1 = L2.25
    value1 = 0
    button2 = B2.26
    led2 = L2.26
    value2 = 10
    button3 = B2.18
    led3 = L2.18
    value3 = 3
    button4 = B2.19
    led4 = L2.19
    value4 = 4
    button5 = B2.21
    led5 = L2.21
    value5 = 1
    button6 = B2.27
    led6 = L2.27
    value6 = 20
    button7 = B2.17
    led7 = L2.17
    value7 = 5
    button8 = B2.23
    led8 = L2.23
    value8 = 2
    button9 = B2.22
    led9 = L2.22
    value9 = 30
    display = 0
    buttonpress = _FADERMODE_CHANGED
    output = _FADERMODE

# Text for showing current fader mode in display
[multicompare]
    compare1 = 0
    ifequal1 = "Pitch"
    compare2 = 10
    ifequal2 = "Velocity"
    compare3 = 3
    ifequal3 = "Repeats/Skip"
    compare4 = 4
    ifequal4 = "Gate pattern"
    compare5 = 1
    ifequal5 = "Random pitch"
    compare6 = 20
    ifequal6 = "Length/Glide"
    compare7 = 5
    ifequal7 = "Ratchets"
    compare8 = 2
    ifequal8 = "Propability"
    compare9 = 30
    ifequal9 = "Activity"
    input = _FADERMODE
    output = _FADERMODE_NAME

# Texts for global menu buttons
[case]
    case1 = L2.13
    value1 = "Tonality"
    case2 = L2.14
    value2 = "Clocking"
    case3 = L2.15
    value3 = "Track"
    case4 = L2.16
    value4 = "Performance"
    else = _FADERMODE_NAME
    output = _GLOBAL_MODE_NAME

# Display global fader mode name
[display]
    text = _GLOBAL_MODE_NAME
    fontsize = 2

# Select a button mode that is most useful in the current fader mode
[multicompare]
    input = _FADERMODE
    compare1 = 3
    ifequal1 = 3
    compare2 = 4
    ifequal2 = 2
    else = 0
    output = _BM
    compare3 = 20
    ifequal3 = 20

# When the range button is active, it always has precedence
[ifequal]
    input1 = _RANGE
    input2 = 0
    ifequal = _BM
    else = 1
    output = _BUTTONMODE

# Button for choosing between gates on/off and start/end
[button]
    button = B2.20
    led = L2.20
    states = 1
    output = _RANGE

# Button for reseting all tracks to step 1
[button]
    button = B2.11 * _CONTROL
    led = L2.11
    states = 1
    output = _RESET_BUTTON

# Combine all source of global reset
[mixer]
    input1 = _RESET_BUTTON
    input2 = I2
    input3 = _STARTSTOP_RESET
    input4 = _EXT_RUNNING_STARTED
    output = _RESET

# Button for run/stop
[button]
    led = L2.12
    output = _RUNNING
    button = B2.12 + _EXT_RUNNING_STARTED
    startvalue = _RUNNING_EXT
    clear = _EXT_RUNNING_STOPPED

# Create a reset trigger when the button changes to 'running'
[gatetool]
    inputgate = _RUNNING
    outputtrigger = _STARTSTOP_RESET

# Button for selecting the second page of steps
[button]
    button = B2.28 + _TRACK_EXTRA_PRESS
    led = L2.28
    output = _PAGE
    states = 2

# Use buttons on DB8E for note selection
[display]
    takeovercontrols = 1

# Names for the display
[ifequal]
    input1 = _PAGE
    input2 = 0
    ifequal = "Steps 1 ... 8"
    else = "Steps 9 ... 16"
    output = _PAGE_NAME

# Display the name of 'Page' when edited
[display]
    linger = 0.1
    header = "PAGE"
    text = _PAGE_NAME
    fontsize = 2

# -------------------------------------------------
# Track 1
# -------------------------------------------------

# Provide trigger when the clear button is pressed (no Ctrl needed)
[button]
    select = _SELECTED_TRACK
    selectat = 1
    button = B2.4
    shortpress = _T1_CLEAR_BUTTON
    states = 1

# Clear button with control together clears the track
[copy]
    input = _T1_CLEAR_BUTTON * _CONTROL
    output = _T1_CLEAR

# Clear button without control removes all mode that alter the pattern length
[logic]
    input1 = _T1_CLEAR_BUTTON
    input2 = -1 * _CONTROL + 1
    and = _T1_PEACE

# Five blinks for the clear LED
[burst]
    trigger = _T1_CLEAR + _FACTORY_RESET
    hz = 5
    count = 5
    output = _T1_CLEAR_LED

# LED only blinks when track is selected
[select]
    select = _SELECTED_TRACK
    selectat = 1
    input = _T1_CLEAR_LED + 0.3
    output = L2.4

# Reset track immediately
[button]
    select = _SELECTED_TRACK
    selectat = 1
    button = B2.11 * _NO_CONTROL
    states = 1
    output = _T1_RESET

# Show a message when _T1_RESET triggers
[display]
    trigger = _T1_RESET
    text = "Reset track 1"

# Button for copy and paste
[button]
    select = _SELECTED_TRACK
    selectat = 1
    button = B2.24
    states = 1
    output = _T1_COPY_BUTTON

# This button cycles between the song froms A, AAAB and AABB
[button]
    select = _SELECTED_TRACK
    selectat = 1
    clear = _T1_CLEAR
    loadpreset = _T1_LOAD_PRESET
    savepreset = _T1_SAVE_PRESET
    button = B2.7
    led = L2.7
    output = _T1_FORM
    states = 3

# Disables scale and note selection if on
[button]
    select = _SELECTED_TRACK
    selectat = 1
    loadpreset = _T1_LOAD_PRESET
    savepreset = _T1_SAVE_PRESET
    button = B2.8
    led = L2.8
    output = _T1_12TONE

# Enable transposing the melody by the difference of the root note to C
[button]
    select = _SELECTED_TRACK
    selectat = 1
    loadpreset = _T1_LOAD_PRESET
    savepreset = _T1_SAVE_PRESET
    button = B2.5
    led = L2.5
    output = _T1_TBR_ON
    inverted = _T1_TBR_OFF

# Provide the amount of 'transpose by root' in a patch cable
[ifequal]
    input1 = _T1_TBR_ON
    input2 = 1
    ifequal = _ROOT / 120
    output = _T1_TBR

# Names for the display
[ifequal]
    input1 = _T1_TBR_ON
    input2 = 0
    ifequal = "don't transpose"
    else = "transpose"
    output = _T1_TBR_ON_NAME

# Display the name of 'Transpose by root' when edited
[display]
    linger = 0.1
    header = "TRANSPOSE BY ROOT"
    text = _T1_TBR_ON_NAME
    fontsize = 2

# Hold to contiously step faders to random positions, hold with Ctrl to change buttons
[button]
    select = _SELECTED_TRACK
    selectat = 1
    button = B2.10
    states = 1
    onvalue = _LUCKY_CLOCK
    output = _T1_LUCKY

# Show a message when _T1_LUCKY * _NO_CONTROL triggers
[display]
    trigger = _T1_LUCKY * _NO_CONTROL
    text = "I feel lucky!"

# Show a message when _T1_LUCKY * _CONTROL triggers
[display]
    trigger = _T1_LUCKY * _CONTROL
    text = "Lucky gates!"

# Selects melodic inversion (swap low and high notes)
[button]
    select = _SELECTED_TRACK
    selectat = 1
    clear = _T1_CLEAR
    loadpreset = _T1_LOAD_PRESET
    savepreset = _T1_SAVE_PRESET
    button = B2.6
    led = L2.6
    output = _T1_INVERT

# Names for the display
[ifequal]
    input1 = _T1_INVERT
    input2 = 0
    ifequal = "don't invert"
    else = "invert pitches"
    output = _T1_INVERT_NAME

# Display the name of 'Pitch inversion' when edited
[display]
    linger = 0.1
    header = "PITCH INVERSION"
    text = _T1_INVERT_NAME
    fontsize = 2

# Combine all triggers for clearing
[mixer]
    input1 = _T1_CLEAR + _T1_PEACE
    input2 = _T1_BPAR_1
    output = _T1_CLEAR_PAR

# Reset track after X clock ticks
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T1_ARP_OFF
    selectat = 11
    loadpreset = _T1_LOAD_PRESET
    savepreset = _T1_SAVE_PRESET
    notches = 17
    startvalue = 0
    ledcolor = 0.8
    ledvalue = -0.3
    header = "AUTORESET"
    clear = _T1_CLEAR_PAR
    output = _T1_AUTORESET
    fader = 1
    button = _T1_BPAR_1

# Combine all triggers for clearing
[mixer]
    input1 = _T1_CLEAR + _T1_PEACE
    input2 = _T1_BPSS_1
    output = _T1_CLEAR_PSS

# Shift the steps of the sequence by this number
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T1_ARP_OFF
    selectat = 11
    loadpreset = _T1_LOAD_PRESET
    savepreset = _T1_SAVE_PRESET
    notches = 17
    startvalue = 0
    ledcolor = 0.6
    ledvalue = -0.3
    header = "SHIFT STEPS"
    clear = _T1_CLEAR_PSS
    output = _T1_SHIFTSTEPS
    fader = 2
    button = _T1_BPSS_1

# Combine all triggers for clearing
[mixer]
    input1 = _T1_CLEAR
    input2 = _T1_BPOCT_1 + _T1_BPOCT_2
    output = _T1_CLEAR_POCT

# Octave switch: -2, -1, 0, +1, +2
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T1_ARP_OFF
    selectat = 11
    loadpreset = _T1_LOAD_PRESET
    savepreset = _T1_SAVE_PRESET
    notches = 5
    startvalue = 2
    ledcolor = 0.2
    ledvalue = -0.3
    display = 0
    clear = _T1_CLEAR_POCT
    sharewithnext = 1
    fader = 3
    button = _T1_BPOCT_1

# Octave switch: -2, -1, 0, +1, +2
[motorfader]
    loadpreset = _T1_LOAD_PRESET
    savepreset = _T1_SAVE_PRESET
    notches = 5
    startvalue = 2
    ledcolor = 0.2
    ledvalue = -0.3
    display = 0
    clear = _T1_CLEAR_POCT
    select = _GLOBAL_FADER_SELECTION
    selectat = 98
    fader = 1
    button = _T1_BPOCT_2
    output = _T1_OCTAVE

# Names for the display
[switch]
    input1 = "2 down"
    input2 = "1 down"
    input3 = "no octaving"
    input4 = "1 up"
    input5 = "2 up"
    offset = _T1_OCTAVE
    output1 = _T1_OCTAVE_NAME

# Display the name of 'Octave switch' when edited
[display]
    linger = 0.1
    header = "OCTAVE SWITCH"
    text = _T1_OCTAVE_NAME
    fontsize = 2

# Combine all triggers for clearing
[mixer]
    input1 = _T1_CLEAR
    input2 = _T1_BPDT_1 + _T1_BPDT_2
    output = _T1_CLEAR_PDT

# Diatonic transposition
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T1_ARP_OFF
    selectat = 11
    loadpreset = _T1_LOAD_PRESET
    savepreset = _T1_SAVE_PRESET
    notches = 15
    startvalue = 7
    ledcolor = 0.4
    ledvalue = -0.3
    outputoffset = -7
    header = "DIATONIC TRANSPOSE"
    clear = _T1_CLEAR_PDT
    sharewithnext = 1
    fader = 4
    button = _T1_BPDT_1

# Diatonic transposition
[motorfader]
    loadpreset = _T1_LOAD_PRESET
    savepreset = _T1_SAVE_PRESET
    notches = 15
    startvalue = 7
    ledcolor = 0.4
    ledvalue = -0.3
    outputoffset = -7
    header = "DIATONIC TRANSPOSE"
    clear = _T1_CLEAR_PDT
    select = _GLOBAL_FADER_SELECTION
    selectat = 98
    fader = 2
    button = _T1_BPDT_2
    output = _T1_NOTESHIFT

# Prevent diatonic transposition from happending between clock ticks
[sample]
    input = _T1_NOTESHIFT
    sample = _CLOCK
    output = _T1_NOTESHIFT_CLOCKED

# Combine all triggers for clearing
[mixer]
    input1 = _T1_CLEAR
    input2 = _T1_BPACT_1
    output = _T1_CLEAR_PACT

# Minimum activity a step needs to have to be played
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T1_ARP_OFF
    selectat = 11
    loadpreset = _T1_LOAD_PRESET
    savepreset = _T1_SAVE_PRESET
    notches = 8
    startvalue = 0
    ledcolor = 0.55
    ledvalue = -0.3
    header = "ACTIVITY"
    clear = _T1_CLEAR_PACT
    output = _T1_ACTIVITY
    fader = 5
    button = _T1_BPACT_1

# Combine all triggers for clearing
[mixer]
    input1 = _T1_CLEAR + _T1_PEACE
    input2 = _T1_BPPAT_1
    output = _T1_CLEAR_PPAT

# Movement pattern: normal, reverse, ping pong, >><, 2><, etc.
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T1_ARP_OFF
    selectat = 11
    loadpreset = _T1_LOAD_PRESET
    savepreset = _T1_SAVE_PRESET
    notches = 10
    startvalue = 0
    ledcolor = 0.3
    ledvalue = -0.3
    display = 0
    clear = _T1_CLEAR_PPAT
    output = _T1_PATTERN_FADER
    fader = 6
    button = _T1_BPPAT_1

# Names for the display
[switch]
    input1 = "Mforward"
    input2 = "Mbackward"
    input3 = "Mping pong"
    input4 = "D=>  =>  <="
    input5 = "D==>  <="
    input6 = "D==>  <==  =>"
    input7 = "D==>  =>  <==  =>"
    input8 = "Mbrownian"
    input9 = "Mrandom skips"
    input10 = "Mrandom"
    offset = _T1_PATTERN_FADER
    output1 = _T1_PATTERN_FADER_NAME

# Display the name of 'Movement pattern' when edited
[display]
    linger = 0.1
    header = "MOVEMENT PATTERN"
    text = _T1_PATTERN_FADER_NAME
    fontsize = 5

# Set the direction to reverse on fader position 1
[ifequal]
    input1 = _T1_PATTERN_FADER
    input2 = 1
    ifequal = 1
    output = _T1_DIRECTION

# Enable ping pong on fader position 2
[ifequal]
    input1 = _T1_PATTERN_FADER
    input2 = 2
    ifequal = 1
    output = _T1_PINGPONG

# Combine all triggers for clearing
[mixer]
    input1 = _T1_CLEAR
    input2 = _T1_BPCDEVEN_1
    output = _T1_CLEAR_PCDEVEN

# Clock division for even divides/multipliers
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T1_ARP_OFF
    selectat = 11
    loadpreset = _T1_LOAD_PRESET
    savepreset = _T1_SAVE_PRESET
    notches = 7
    startvalue = 3
    ledcolor = 1.1
    ledvalue = -0.3
    display = 0
    clear = _T1_CLEAR_PCDEVEN
    output = _T1_CD_EVEN
    fader = 7
    button = _T1_BPCDEVEN_1

# Select the multiplier based on the fader position
[switch]
    input1 = 1
    input2 = 1
    input3 = 1
    input4 = 1
    input5 = 2
    input6 = 4
    input7 = 8
    offset = _T1_CD_EVEN
    output1 = _T1_CD_EVEN_MULT

# Select the division based on the fader position
[switch]
    input1 = 8
    input2 = 4
    input3 = 2
    input4 = 1
    input5 = 1
    input6 = 1
    input7 = 1
    offset = _T1_CD_EVEN
    output1 = _T1_CD_EVEN_DIV

# Combine all triggers for clearing
[mixer]
    input1 = _T1_CLEAR
    input2 = _T1_BPCDODD_1
    output = _T1_CLEAR_PCDODD

# Clock division for odd divides/multipliers
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T1_ARP_OFF
    selectat = 11
    loadpreset = _T1_LOAD_PRESET
    savepreset = _T1_SAVE_PRESET
    notches = 7
    startvalue = 3
    ledcolor = 1.2
    ledvalue = -0.3
    display = 0
    clear = _T1_CLEAR_PCDODD
    output = _T1_CD_ODD
    fader = 8
    button = _T1_BPCDODD_1

# Select the multiplier based on the fader position
[switch]
    input1 = 1
    input2 = 1
    input3 = 1
    input4 = 1
    input5 = 3
    input6 = 5
    input7 = 7
    offset = _T1_CD_ODD
    output1 = _T1_CD_ODD_MULT

# Select the division based on the fader position
[switch]
    input1 = 7
    input2 = 5
    input3 = 3
    input4 = 1
    input5 = 1
    input6 = 1
    input7 = 1
    offset = _T1_CD_ODD
    output1 = _T1_CD_ODD_DIV

# Names for the display
[switch]
    input1 = "DY  8"
    input2 = "DY  4"
    input3 = "DY  2"
    input4 = "Mno division"
    input5 = "DX  2"
    input6 = "DX  4"
    input7 = "DX  8"
    offset = _T1_CD_EVEN
    output1 = _T1_CD_EVEN_NAMES

# Display the name of 'Clock divider' when edited
[display]
    linger = 0.1
    header = "CLOCK DIVIDER"
    text = _T1_CD_EVEN_NAMES
    fontsize = 5

# Names for the display
[switch]
    input1 = "DY  7"
    input2 = "DY  5"
    input3 = "DY  3"
    input4 = "Mno division"
    input5 = "DX  3"
    input6 = "DX  5"
    input7 = "DX  7"
    offset = _T1_CD_ODD
    output1 = _T1_CD_ODD_NAMES

# Display the name of 'Clock divider' when edited
[display]
    linger = 0.1
    header = "CLOCK DIVIDER"
    text = _T1_CD_ODD_NAMES
    fontsize = 5

# Switch on/off arpeggio mode for track 1
[button]
    select = _SELECTED_TRACK
    selectat = 1
    button = B2.9
    clear = _T1_START_OF_SEQUENCE * _T1_ARP_AUTOSTOP
    output = _T1_ARP
    negated = _T1_ARP_OFF

# The LED of the ARP button blinks when it is on but in Autostop mode
[select]
    select = _SELECTED_TRACK
    selectat = 1
    input = _T1_ARP_AUTOSTOP * _ARP_AUTOSTOP_BLINK + _T1_ARP
    output = L2.9

# Autostop mode for ARP: When you hold CTRL while switching ARP on, it will automatically switch
# off the next time the sequence starts. This allows for easier jamming the ARP for doing fills.
[flipflop]
    set = B2.9 * _CONTROL
    reset = _T1_ARP_OFF
    output = _T1_ARP_AUTOSTOP

# Sync switching ARP on/off with clock in order to avoid audible glitches
[sample]
    input = _T1_ARP
    sample = _T1_CLOCK
    output = _T1_ARP_SYNCED

# Auto reset arpeggiator after N number of steps
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T1_ARP
    selectat = 11
    loadpreset = _T1_LOAD_PRESET
    savepreset = _T1_SAVE_PRESET
    fader = 1
    notches = 17
    ledcolor = 0.8
    ledvalue = 1
    output = _T1_ARP_AUTORESET
    header = "AUTORESET"

# Enable ping pong mode
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T1_ARP
    selectat = 11
    loadpreset = _T1_LOAD_PRESET
    savepreset = _T1_SAVE_PRESET
    fader = 2
    notches = 3
    ledcolor = 0.85
    ledvalue = 1
    output = _T1_ARP_DIRECTION

# Names for the display
[switch]
    input1 = "up"
    input2 = "up/down"
    input3 = "down"
    offset = _T1_ARP_DIRECTION
    output1 = _T1_ARP_DIRECTION_NAME

# Display the name of 'Direction' when edited
[display]
    linger = 0.1
    header = "DIRECTION"
    text = _T1_ARP_DIRECTION_NAME
    fontsize = 2

# Provide gate for reversed direction of arpeggio
[ifequal]
    input1 = _T1_ARP_DIRECTION
    input2 = 2
    ifequal = 1
    else = 0
    output = _T1_ARP_UPDOWN

# Provide gate for ping pong of arpeggio
[ifequal]
    input1 = _T1_ARP_DIRECTION
    input2 = 1
    ifequal = 1
    else = 0
    output = _T1_ARP_PINGPONG

# Seperate octave switch for the arpeggio
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T1_ARP
    selectat = 11
    loadpreset = _T1_LOAD_PRESET
    savepreset = _T1_SAVE_PRESET
    fader = 3
    notches = 5
    ledcolor = 0.2
    startvalue = 2
    ledvalue = 1
    output = _T1_ARP_OCTAVE_SWITCH

# Names for the display
[switch]
    input1 = "2 down"
    input2 = "1 down"
    input3 = "no octaving"
    input4 = "1 up"
    input5 = "2 up"
    offset = _T1_ARP_OCTAVE_SWITCH
    output1 = _T1_ARP_OCTAVE_SWITCH_NAME

# Display the name of 'Octave switch' when edited
[display]
    linger = 0.1
    header = "OCTAVE SWITCH"
    text = _T1_ARP_OCTAVE_SWITCH_NAME
    fontsize = 2

# Enable butterfly mode
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T1_ARP
    selectat = 11
    loadpreset = _T1_LOAD_PRESET
    savepreset = _T1_SAVE_PRESET
    fader = 4
    notches = 2
    ledcolor = 1.15
    ledvalue = 1
    output = _T1_ARP_BUTTERFLY

# Names for the display
[ifequal]
    input1 = _T1_ARP_BUTTERFLY
    input2 = 0
    ifequal = "off"
    else = "on"
    output = _T1_ARP_BUTTERFLY_NAME

# Display the name of 'Butterfly' when edited
[display]
    linger = 0.1
    header = "BUTTERFLY"
    text = _T1_ARP_BUTTERFLY_NAME
    fontsize = 2

# Select one of three octaving patterns
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T1_ARP
    selectat = 11
    loadpreset = _T1_LOAD_PRESET
    savepreset = _T1_SAVE_PRESET
    fader = 5
    notches = 3
    ledcolor = 0.4
    ledvalue = 1
    output = _T1_ARP_OCTAVING

# Names for the display
[switch]
    input1 = "off"
    input2 = "up"
    input3 = "down"
    offset = _T1_ARP_OCTAVING
    output1 = _T1_ARP_OCTAVING_NAME

# Display the name of 'Octaving' when edited
[display]
    linger = 0.1
    header = "OCTAVING"
    text = _T1_ARP_OCTAVING_NAME
    fontsize = 2

# Compute octave offset pitches from fader setting
[copy]
    input = _T1_ARP_OCTAVE_SWITCH * 1V - 2V
    output = _T1_ARP_OCTAVE

# Select the arpeggio pattern
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T1_ARP
    selectat = 11
    loadpreset = _T1_LOAD_PRESET
    savepreset = _T1_SAVE_PRESET
    fader = 6
    notches = 7
    ledcolor = 0.3
    ledvalue = 1
    output = _T1_ARP_PATTERN

# Names for the display
[switch]
    input1 = "D=>"
    input2 = "D=>  =>  <="
    input3 = "D==>  <="
    input4 = "D==>  <==  =>"
    input5 = "D==>  =>  <==  =>"
    input6 = "Mbrownian"
    input7 = "Mrandom"
    offset = _T1_ARP_PATTERN
    output1 = _T1_ARP_PATTERN_NAME

# Display the name of 'Movement pattern' when edited
[display]
    linger = 0.1
    header = "MOVEMENT PATTERN"
    text = _T1_ARP_PATTERN_NAME
    fontsize = 5

# Select one of four different drop patterns
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T1_ARP
    selectat = 11
    loadpreset = _T1_LOAD_PRESET
    savepreset = _T1_SAVE_PRESET
    fader = 7
    notches = 4
    ledcolor = 0.5
    ledvalue = 1
    output = _T1_ARP_DROP

# Names for the display
[switch]
    input1 = "* * * * * *"
    input2 = "* * o * * o"
    input3 = "* o * o * o"
    input4 = "* o o * o o"
    offset = _T1_ARP_DROP
    output1 = _T1_ARP_DROP_NAME

# Display the name of 'Play/skip notes' when edited
[display]
    linger = 0.1
    header = "PLAY/SKIP NOTES"
    text = _T1_ARP_DROP_NAME
    fontsize = 4

# Select one of several clocking patterns
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T1_ARP
    selectat = 11
    loadpreset = _T1_LOAD_PRESET
    savepreset = _T1_SAVE_PRESET
    fader = 8
    notches = 8
    ledcolor = 1.1
    ledvalue = 1
    output = _T1_ARP_CLOCKING

# Names for the display
[switch]
    input1 = "master clock"
    input2 = "sequencer"
    input3 = "clock x 3/2"
    input4 = "clock x 2"
    input5 = "clock x 3"
    input6 = "clock x 4"
    input7 = "clock x 6"
    input8 = "clock x 8"
    offset = _T1_ARP_CLOCKING
    output1 = _T1_ARP_CLOCKING_NAME

# Display the name of 'Arpeggio clocking' when edited
[display]
    linger = 0.1
    header = "ARPEGGIO CLOCKING"
    text = _T1_ARP_CLOCKING_NAME
    fontsize = 2

# Button for loading preset 1 on track 1
[button]
    select = _SELECTED_TRACK
    selectat = 1
    button = B2.1 * _CONTROL
    states = 1
    onvalue = 1
    output = _T1_P1_LOAD

# Button for saving preset 1 on track 1
[button]
    select = _SELECTED_TRACK
    selectat = 1
    button = B2.1
    states = 1
    onvalue = 1
    longpress = _T1_P1_SAVE

# Show a message when _T1_P1_LOAD triggers
[display]
    trigger = _T1_P1_LOAD
    text = "Preset 1 loaded"

# Show a message when _T1_P1_SAVE triggers
[display]
    trigger = _T1_P1_SAVE
    text = "Preset 1 saved"

# Five blinks for the LED of the preset button on saving
[burst]
    trigger = _T1_P1_SAVE
    hz = 5
    count = 5
    output = _T1_P1_SAVE_LED

# Write the save LED animation to the LED if the track is still selected.
[select]
    select = _SELECTED_TRACK
    selectat = 1
    input = _T1_P1_SAVE_LED + 0.3
    output = L2.1

# Button for loading preset 2 on track 1
[button]
    select = _SELECTED_TRACK
    selectat = 1
    button = B2.2 * _CONTROL
    states = 1
    onvalue = 2
    output = _T1_P2_LOAD

# Button for saving preset 2 on track 1
[button]
    select = _SELECTED_TRACK
    selectat = 1
    button = B2.2
    states = 1
    onvalue = 2
    longpress = _T1_P2_SAVE

# Show a message when _T1_P2_LOAD triggers
[display]
    trigger = _T1_P2_LOAD
    text = "Preset 2 loaded"

# Show a message when _T1_P2_SAVE triggers
[display]
    trigger = _T1_P2_SAVE
    text = "Preset 2 saved"

# Five blinks for the LED of the preset button on saving
[burst]
    trigger = _T1_P2_SAVE
    hz = 5
    count = 5
    output = _T1_P2_SAVE_LED

# Write the save LED animation to the LED if the track is still selected.
[select]
    select = _SELECTED_TRACK
    selectat = 1
    input = _T1_P2_SAVE_LED + 0.3
    output = L2.2

# Button for loading preset 3 on track 1
[button]
    select = _SELECTED_TRACK
    selectat = 1
    button = B2.3 * _CONTROL
    states = 1
    onvalue = 3
    output = _T1_P3_LOAD

# Button for saving preset 3 on track 1
[button]
    select = _SELECTED_TRACK
    selectat = 1
    button = B2.3
    states = 1
    onvalue = 3
    longpress = _T1_P3_SAVE

# Show a message when _T1_P3_LOAD triggers
[display]
    trigger = _T1_P3_LOAD
    text = "Preset 3 loaded"

# Show a message when _T1_P3_SAVE triggers
[display]
    trigger = _T1_P3_SAVE
    text = "Preset 3 saved"

# Five blinks for the LED of the preset button on saving
[burst]
    trigger = _T1_P3_SAVE
    hz = 5
    count = 5
    output = _T1_P3_SAVE_LED

# Write the save LED animation to the LED if the track is still selected.
[select]
    select = _SELECTED_TRACK
    selectat = 1
    input = _T1_P3_SAVE_LED + 0.3
    output = L2.3

# Create a trigger with the preset as value when any of the presets is loaded
[mixer]
    input1 = _T1_P1_LOAD
    input2 = _T1_P2_LOAD
    input3 = _T1_P3_LOAD
    output = _T1_LOAD_PRESET

# Create a trigger with the preset as value when any of the presets is saved
[mixer]
    input1 = _T1_P1_SAVE * 1
    input2 = _T1_P2_SAVE * 2
    input3 = _T1_P3_SAVE * 3
    output = _T1_SAVE_PRESET

# Select which notes from the current scale should be played
[buttongroup]
    select = _SELECTED_TRACK
    selectat = 1
    minactive = 1
    maxactive = _CONTROL * -6 + 7
    startbutton = -1
    button1 = B1.1
    led1 = L1.1
    buttonoutput1 = _T1_SEL_1
    button2 = B1.2
    led2 = L1.2
    buttonoutput2 = _T1_SEL_2
    button3 = B1.3
    led3 = L1.3
    buttonoutput3 = _T1_SEL_3
    button4 = B1.4
    led4 = L1.4
    buttonoutput4 = _T1_SEL_4
    button5 = B1.5
    led5 = L1.5
    buttonoutput5 = _T1_SEL_5
    button6 = B1.6
    led6 = L1.6
    buttonoutput6 = _T1_SEL_6
    button7 = B1.7
    led7 = L1.7
    buttonoutput7 = _T1_SEL_7

# Clock divider for track 1
[clocktool]
    clock = _CLOCK
    reset = _RESET
    divide = _T1_CD_EVEN_DIV * _T1_CD_ODD_DIV
    multiply = _T1_CD_EVEN_MULT * _T1_CD_ODD_MULT
    output = _T1_CLOCK

# Mix global and per-track diatonic transposition
[mixer]
    input1 = _T1_NOTESHIFT_CLOCKED
    input2 = _GLOBAL_NOTESHIFT_CLOCKED
    output = _T1_NOTESHIFT_SUM

# The clear range logic should just affect the current track
[ifequal]
    input1 = _SELECTED_TRACK * _RANGE
    input2 = 1
    ifequal = 1
    output = _T1_CLEAR_RANGE

# Collect different sources of resetting the start/end point
[logic]
    input1 = _T1_CLEAR + _T1_PEACE
    input2 = _T1_CLEAR_RANGE * _CONTROL
    or = _T1_CLEARSTARTEND

# Select encoder if track 1 is selected, arp is off and control is not held
[logic]
    input1 = _T1_SELECTED * _NO_CONTROL
    input2 = _T1_ARP_OFF
    and = _T1_ENC_1_SELECTED

# Note shift for each step repetition
[encoder]
    select = _T1_ENC_1_SELECTED
    encoder = 1
    header = "Repeat shift"
    color = 0.6
    discrete = 15
    startvalue = 7
    outputoffset = -7
    output = _T1_REPEATSHIFT

# Select encoder if track 1 is selected, arp is off and control is held
[logic]
    input1 = _T1_SELECTED * _CONTROL
    input2 = _T1_ARP_OFF
    and = _T1_ENC_2_SELECTED

# Note shift for each ratchet
[encoder]
    select = _T1_ENC_2_SELECTED
    encoder = 1
    header = "Ratchet shift"
    color = 0.8
    discrete = 15
    startvalue = 7
    outputoffset = -7
    output = _T1_RATCHETSHIFT

# Sequencer for pitch and gate of track 1
[motoquencer]
    select = _GLOBAL_FADER_SELECTION
    selectat = 1
    page = _PAGE
    stepcopy = _T1_COPY_BUTTON
    doublerange = _T1_COPY_BUTTON
    loadpreset = _T1_LOAD_PRESET
    savepreset = _T1_SAVE_PRESET
    clear = _T1_CLEAR
    select1 = _T1_SEL_1 + _T1_12TONE
    select3 = _T1_SEL_2 + _T1_12TONE
    select5 = _T1_SEL_3 + _T1_12TONE
    select7 = _T1_SEL_4 + _T1_12TONE
    select9 = _T1_SEL_5 + _T1_12TONE
    select11 = _T1_SEL_6 + _T1_12TONE
    select13 = _T1_SEL_7 + _T1_12TONE
    selectfill1 = _T1_12TONE
    selectfill2 = _T1_12TONE
    selectfill3 = _T1_12TONE
    selectfill4 = _T1_12TONE
    selectfill5 = _T1_12TONE
    degree = _DEGREE
    clock = _T1_CLOCK * _RUNNING
    taptempo = _T1_CLOCK
    reset = _RESET + _T1_RESET
    cv = _T1_PITCH
    cvrange = _T1_CVRANGE * 1V
    defaultgate = 0
    gate = _T1_SEQUENCER_GATE
    numfaders = 8
    numsteps = 16
    linktonext = 1
    autoreset = _T1_AUTORESET
    shiftsteps = _T1_SHIFTSTEPS
    pattern = -1 * 2 + _T1_PATTERN_FADER
    direction = _T1_DIRECTION
    pingpong = _T1_PINGPONG
    selectnoteshift = _T1_NOTESHIFT_SUM
    tuningmode = _TUNINGMODE
    tuningpitch = 1V
    bulkedit = _CONTROL
    constantlength = B2.18
    accumulatorrange = _T1_ACCU_RANGE
    root = _ROOT * _T1_TBR_OFF
    transpose = _T1_TBR
    luckybuttons = _T1_LUCKY * _CONTROL
    luckyfaders = _T1_LUCKY * _NO_CONTROL
    luckychance = 1 / 8
    luckyamount = 0.5 * _NO_CONTROL + 0.5
    luckyscope = 3
    fadermode = _FADERMODE
    mute = -1 * _RUNNING + 1
    form = _T1_FORM
    invert = _T1_INVERT
    gatelength = _T1_GATELENGTH
    buttonmode = _BUTTONMODE
    composemode = _COMPOSEMODE
    clearskips = _T1_CLEAR + _T1_PEACE
    clearrepeats = _T1_CLEAR + _T1_PEACE
    clearstartend = _T1_CLEARSTARTEND
    repeatshift = _T1_REPEATSHIFT
    ratchetshift = _T1_RATCHETSHIFT
    startofsequence = _T1_START_OF_SEQUENCE

# Sequencer for velocity
[motoquencer]
    select = _GLOBAL_FADER_SELECTION
    selectat = 1
    page = _PAGE
    stepcopy = _T1_COPY_BUTTON
    doublerange = _T1_COPY_BUTTON
    clear = _T1_CLEAR
    loadpreset = _T1_LOAD_PRESET
    savepreset = _T1_SAVE_PRESET
    cv = _T1_VELOCITY
    defaultcv = 5.5V
    cvbase = 1V
    cvrange = 9V
    quantize = 0
    cvname = "Velocity"
    bulkedit = _CONTROL
    linktonext = 1

# Copy velocity to CV output
[copy]
    input = _T1_VELOCITY
    output = O2

# Sequencer for gate length and glide
[motoquencer]
    select = _GLOBAL_FADER_SELECTION
    selectat = 1
    page = _PAGE
    stepcopy = _T1_COPY_BUTTON
    doublerange = _T1_COPY_BUTTON
    clear = _T1_CLEAR
    loadpreset = _T1_LOAD_PRESET
    savepreset = _T1_SAVE_PRESET
    cv = _T1_GATELENGTH
    cvbase = 0.05
    cvrange = 0.9
    defaultcv = 0.5
    defaultgate = 0
    quantize = 0
    buttoncolor = 0.5
    cvname = "Gate length"
    bulkedit = _CONTROL
    linktonext = 1
    gate = _T1_GLIDE
    gatename = "Glide"

# Sequencer for activity level per step
[motoquencer]
    select = _GLOBAL_FADER_SELECTION
    selectat = 1
    clear = _T1_CLEAR
    loadpreset = _T1_LOAD_PRESET
    savepreset = _T1_SAVE_PRESET
    cv = _T1_STEP_ACTIVITY
    quantize = 0
    defaultcv = 7
    cvname = "Activity"
    cvnotches = 8
    bulkedit = _CONTROL

# Silence the gate if the step does not reach the required activity
[compare]
    input = _T1_STEP_ACTIVITY
    compare = _T1_ACTIVITY
    ifless = 0
    else = _T1_SEQUENCER_GATE
    output = _T1_ACT_GATE

# Modulate gate length for gate output in arpeggiator mode
[gatetool]
    taptempo = _T1_ARP_TAPTEMPO
    gatelength = _T1_GATELENGTH
    inputgate = _T1_ARP_CLOCK
    outputgate = _T1_ARP_MODULATED_GATE

# Switch gate to arpeggiator if active
[ifequal]
    input1 = _T1_ARP_SYNCED
    input2 = 0
    ifequal = _T1_ACT_GATE
    else = _T1_ARP_MODULATED_GATE
    output = _T1_SWITCHED_GATE

# Logic for make the gate silent if the track is muted
[logic]
    input1 = -1 * _T1_MUTED + 1
    input2 = _T1_SWITCHED_GATE
    and = _T1_MUTED_GATE

# Select clock for arpeggiator of track 1. It is either the master clock or a multiplication
# of it, or the sequencer gate output.
[switch]
    input1 = _CLOCK
    input2 = _T1_SEQUENCER_GATE
    input3 = _CLOCK_3_2
    input4 = _CLOCK_2_1
    input5 = _CLOCK_3_1
    input6 = _CLOCK_4_1
    input7 = _CLOCK_6_1
    input8 = _CLOCK_8_1
    output1 = _T1_ARP_CLOCK
    offset = _T1_ARP_CLOCKING

# Create taptempo for arp clock to be used for gate length
[switch]
    input1 = _CLOCK
    input2 = _T1_CLOCK
    input3 = _CLOCK_3_2
    input4 = _CLOCK_2_1
    input5 = _CLOCK_3_1
    input6 = _CLOCK_4_1
    input7 = _CLOCK_6_1
    input8 = _CLOCK_8_1
    output1 = _T1_ARP_TAPTEMPO
    offset = _T1_ARP_CLOCKING * _T1_ARP

# Select encoder if track 1 is selected, arp is on and control is not held
[logic]
    input1 = _T1_SELECTED * _NO_CONTROL
    input2 = _T1_ARP
    and = _T1_ENC_3_SELECTED

# Encoder for base pitch of arpeggiator
[encoder]
    encoder = 1
    select = _T1_ENC_3_SELECTED
    header = "Arp base pitch"
    color = 0.2
    discrete = 37
    sensivity = 3
    output = _T1_ARP_PITCH

# Select encoder if track 1 is selected, arp is on and control is held
[logic]
    input1 = _T1_SELECTED * _CONTROL
    input2 = _T1_ARP
    and = _T1_ENC_4_SELECTED

# Encoder for pitch range of arpeggiator
[encoder]
    encoder = 1
    select = _T1_ENC_4_SELECTED
    header = "Arp pitch range"
    color = 0.4
    discrete = 49
    startvalue = 24
    sensivity = 4
    output = _T1_ARP_RANGE

# Arpeggiator for track 1
[arpeggio]
    select1 = _T1_SEL_1
    select3 = _T1_SEL_2
    select5 = _T1_SEL_3
    select7 = _T1_SEL_4
    select9 = _T1_SEL_5
    select11 = _T1_SEL_6
    select13 = _T1_SEL_7
    selectfill1 = 0
    selectfill2 = 0
    selectfill3 = 0
    selectfill4 = 0
    selectfill5 = 0
    root = _ROOT * _T1_TBR_OFF
    transpose = _T1_TBR
    degree = _DEGREE
    clock = _T1_ARP_CLOCK * _RUNNING
    reset = _RESET
    tuningmode = _TUNINGMODE
    direction = _T1_ARP_UPDOWN
    pingpong = _T1_ARP_PINGPONG
    butterfly = _T1_ARP_BUTTERFLY
    octaves = _T1_ARP_OCTAVING
    drop = _T1_ARP_DROP
    pattern = _T1_ARP_PATTERN
    autoreset = _T1_ARP_AUTORESET
    pitch = _T1_ARP_PITCH / 120
    range = _T1_ARP_RANGE / 120
    output = _T1_ARP_OUTPUT

# Switch pitch output between sequencer and arpeggiator
[ifequal]
    input1 = _T1_ARP_SYNCED
    input2 = 0
    ifequal = _T1_PITCH
    else = _T1_ARP_OUTPUT + _T1_ARP_OCTAVE
    output = _T1_SWITCHED_PITCH

# Mix all sources of pitch together
[mixer]
    input1 = _T1_OCTAVE * 1V - 2V
    input2 = _T1_SWITCHED_PITCH
    input3 = _GLOBAL_OCTAVE_SWITCH * 1V - 2V
    input4 = _GLOBAL_TRANSPOSITION * 0.00833333
    output = _T1_FINAL_PITCH

# Slew limiter for glides
[slew]
    input = _T1_FINAL_PITCH
    exponential = O1
    slew = _T1_GLIDE * _T1_GLIDE_LENGTH

# If we are in compose mode and the arpeggiator is switched off, the gate is output even if
# the sequencer is stopped.
[ifequal]
    input1 = _T1_ARP
    input2 = 0
    ifequal = _RUNNING + _COMPOSEMODE
    else = _RUNNING
    output = _RUNNING_OR_COMPOSE_1

# Copy the gate to its final destination
[copy]
    input = _T1_MUTED_GATE * _RUNNING_OR_COMPOSE_1
    output = _T1_FINAL_GATE

# Copy the gate signal to the CV jack
[copy]
    input = _T1_FINAL_GATE
    output = G1.1

# Names for the display
[switch]
    input1 = "a"
    input2 = "a a a c"
    input3 = "a a c c"
    offset = _T1_FORM
    output1 = _T1_FORM_NAME

# Display the name of 'Song form' when edited
[display]
    linger = 0.1
    header = "SONG FORM"
    text = _T1_FORM_NAME
    fontsize = 4

# Names for the display
[ifequal]
    input1 = _T1_12TONE
    input2 = 0
    ifequal = "diatonic"
    else = "chromatic"
    output = _T1_12TONE_NAME

# Display the name of 'Scale' when edited
[display]
    linger = 0.1
    header = "SCALE"
    text = _T1_12TONE_NAME
    fontsize = 2

# Show a message when _T1_CLEARSTARTEND triggers
[display]
    trigger = _T1_CLEARSTARTEND
    text = "Reset start/end"

# Show a message when _T1_PEACE triggers
[display]
    trigger = _T1_PEACE
    text = "Track 1 peace"

# Show a message when _T1_CLEAR triggers
[display]
    trigger = _T1_CLEAR
    text = "Track 1 cleared"

# Names for the display
[ifequal]
    input1 = _T1_ARP
    input2 = 0
    ifequal = "Sequencer"
    else = "Arpeggiator"
    output = _T1_ARP_NAME

# Display the name of '' when edited
[display]
    linger = 0.1
    header = ""
    text = _T1_ARP_NAME
    fontsize = 2

# -------------------------------------------------
# Track 2
# -------------------------------------------------

# Provide trigger when the clear button is pressed (no Ctrl needed)
[button]
    select = _SELECTED_TRACK
    selectat = 2
    button = B2.4
    shortpress = _T2_CLEAR_BUTTON
    states = 1

# Clear button with control together clears the track
[copy]
    input = _T2_CLEAR_BUTTON * _CONTROL
    output = _T2_CLEAR

# Clear button without control removes all mode that alter the pattern length
[logic]
    input1 = _T2_CLEAR_BUTTON
    input2 = -1 * _CONTROL + 1
    and = _T2_PEACE

# Five blinks for the clear LED
[burst]
    trigger = _T2_CLEAR + _FACTORY_RESET
    hz = 5
    count = 5
    output = _T2_CLEAR_LED

# LED only blinks when track is selected
[select]
    select = _SELECTED_TRACK
    selectat = 2
    input = _T2_CLEAR_LED + 0.3
    output = L2.4

# Reset track immediately
[button]
    select = _SELECTED_TRACK
    selectat = 2
    button = B2.11 * _NO_CONTROL
    states = 1
    output = _T2_RESET

# Show a message when _T2_RESET triggers
[display]
    trigger = _T2_RESET
    text = "Reset track 2"

# Button for copy and paste
[button]
    select = _SELECTED_TRACK
    selectat = 2
    button = B2.24
    states = 1
    output = _T2_COPY_BUTTON

# This button cycles between the song froms A, AAAB and AABB
[button]
    select = _SELECTED_TRACK
    selectat = 2
    clear = _T2_CLEAR
    loadpreset = _T2_LOAD_PRESET
    savepreset = _T2_SAVE_PRESET
    button = B2.7
    led = L2.7
    output = _T2_FORM
    states = 3

# Disables scale and note selection if on
[button]
    select = _SELECTED_TRACK
    selectat = 2
    loadpreset = _T2_LOAD_PRESET
    savepreset = _T2_SAVE_PRESET
    button = B2.8
    led = L2.8
    output = _T2_12TONE

# Enable transposing the melody by the difference of the root note to C
[button]
    select = _SELECTED_TRACK
    selectat = 2
    loadpreset = _T2_LOAD_PRESET
    savepreset = _T2_SAVE_PRESET
    button = B2.5
    led = L2.5
    output = _T2_TBR_ON
    inverted = _T2_TBR_OFF

# Provide the amount of 'transpose by root' in a patch cable
[ifequal]
    input1 = _T2_TBR_ON
    input2 = 1
    ifequal = _ROOT / 120
    output = _T2_TBR

# Names for the display
[ifequal]
    input1 = _T2_TBR_ON
    input2 = 0
    ifequal = "don't transpose"
    else = "transpose"
    output = _T2_TBR_ON_NAME

# Display the name of 'Transpose by root' when edited
[display]
    linger = 0.1
    header = "TRANSPOSE BY ROOT"
    text = _T2_TBR_ON_NAME
    fontsize = 2

# Hold to contiously step faders to random positions, hold with Ctrl to change buttons
[button]
    select = _SELECTED_TRACK
    selectat = 2
    button = B2.10
    states = 1
    onvalue = _LUCKY_CLOCK
    output = _T2_LUCKY

# Show a message when _T2_LUCKY * _NO_CONTROL triggers
[display]
    trigger = _T2_LUCKY * _NO_CONTROL
    text = "I feel lucky!"

# Show a message when _T2_LUCKY * _CONTROL triggers
[display]
    trigger = _T2_LUCKY * _CONTROL
    text = "Lucky gates!"

# Selects melodic inversion (swap low and high notes)
[button]
    select = _SELECTED_TRACK
    selectat = 2
    clear = _T2_CLEAR
    loadpreset = _T2_LOAD_PRESET
    savepreset = _T2_SAVE_PRESET
    button = B2.6
    led = L2.6
    output = _T2_INVERT

# Names for the display
[ifequal]
    input1 = _T2_INVERT
    input2 = 0
    ifequal = "don't invert"
    else = "invert pitches"
    output = _T2_INVERT_NAME

# Display the name of 'Pitch inversion' when edited
[display]
    linger = 0.1
    header = "PITCH INVERSION"
    text = _T2_INVERT_NAME
    fontsize = 2

# Combine all triggers for clearing
[mixer]
    input1 = _T2_CLEAR + _T2_PEACE
    input2 = _T2_BPAR_1
    output = _T2_CLEAR_PAR

# Reset track after X clock ticks
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T2_ARP_OFF
    selectat = 12
    loadpreset = _T2_LOAD_PRESET
    savepreset = _T2_SAVE_PRESET
    notches = 17
    startvalue = 0
    ledcolor = 0.8
    ledvalue = -0.3
    header = "AUTORESET"
    clear = _T2_CLEAR_PAR
    output = _T2_AUTORESET
    fader = 1
    button = _T2_BPAR_1

# Combine all triggers for clearing
[mixer]
    input1 = _T2_CLEAR + _T2_PEACE
    input2 = _T2_BPSS_1
    output = _T2_CLEAR_PSS

# Shift the steps of the sequence by this number
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T2_ARP_OFF
    selectat = 12
    loadpreset = _T2_LOAD_PRESET
    savepreset = _T2_SAVE_PRESET
    notches = 17
    startvalue = 0
    ledcolor = 0.6
    ledvalue = -0.3
    header = "SHIFT STEPS"
    clear = _T2_CLEAR_PSS
    output = _T2_SHIFTSTEPS
    fader = 2
    button = _T2_BPSS_1

# Combine all triggers for clearing
[mixer]
    input1 = _T2_CLEAR
    input2 = _T2_BPOCT_1 + _T2_BPOCT_2
    output = _T2_CLEAR_POCT

# Octave switch: -2, -1, 0, +1, +2
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T2_ARP_OFF
    selectat = 12
    loadpreset = _T2_LOAD_PRESET
    savepreset = _T2_SAVE_PRESET
    notches = 5
    startvalue = 2
    ledcolor = 0.2
    ledvalue = -0.3
    display = 0
    clear = _T2_CLEAR_POCT
    sharewithnext = 1
    fader = 3
    button = _T2_BPOCT_1

# Octave switch: -2, -1, 0, +1, +2
[motorfader]
    loadpreset = _T2_LOAD_PRESET
    savepreset = _T2_SAVE_PRESET
    notches = 5
    startvalue = 2
    ledcolor = 0.2
    ledvalue = -0.3
    display = 0
    clear = _T2_CLEAR_POCT
    select = _GLOBAL_FADER_SELECTION
    selectat = 98
    fader = 3
    button = _T2_BPOCT_2
    output = _T2_OCTAVE

# Names for the display
[switch]
    input1 = "2 down"
    input2 = "1 down"
    input3 = "no octaving"
    input4 = "1 up"
    input5 = "2 up"
    offset = _T2_OCTAVE
    output1 = _T2_OCTAVE_NAME

# Display the name of 'Octave switch' when edited
[display]
    linger = 0.1
    header = "OCTAVE SWITCH"
    text = _T2_OCTAVE_NAME
    fontsize = 2

# Combine all triggers for clearing
[mixer]
    input1 = _T2_CLEAR
    input2 = _T2_BPDT_1 + _T2_BPDT_2
    output = _T2_CLEAR_PDT

# Diatonic transposition
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T2_ARP_OFF
    selectat = 12
    loadpreset = _T2_LOAD_PRESET
    savepreset = _T2_SAVE_PRESET
    notches = 15
    startvalue = 7
    ledcolor = 0.4
    ledvalue = -0.3
    outputoffset = -7
    header = "DIATONIC TRANSPOSE"
    clear = _T2_CLEAR_PDT
    sharewithnext = 1
    fader = 4
    button = _T2_BPDT_1

# Diatonic transposition
[motorfader]
    loadpreset = _T2_LOAD_PRESET
    savepreset = _T2_SAVE_PRESET
    notches = 15
    startvalue = 7
    ledcolor = 0.4
    ledvalue = -0.3
    outputoffset = -7
    header = "DIATONIC TRANSPOSE"
    clear = _T2_CLEAR_PDT
    select = _GLOBAL_FADER_SELECTION
    selectat = 98
    fader = 4
    button = _T2_BPDT_2
    output = _T2_NOTESHIFT

# Prevent diatonic transposition from happending between clock ticks
[sample]
    input = _T2_NOTESHIFT
    sample = _CLOCK
    output = _T2_NOTESHIFT_CLOCKED

# Combine all triggers for clearing
[mixer]
    input1 = _T2_CLEAR
    input2 = _T2_BPACT_1
    output = _T2_CLEAR_PACT

# Minimum activity a step needs to have to be played
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T2_ARP_OFF
    selectat = 12
    loadpreset = _T2_LOAD_PRESET
    savepreset = _T2_SAVE_PRESET
    notches = 8
    startvalue = 0
    ledcolor = 0.55
    ledvalue = -0.3
    header = "ACTIVITY"
    clear = _T2_CLEAR_PACT
    output = _T2_ACTIVITY
    fader = 5
    button = _T2_BPACT_1

# Combine all triggers for clearing
[mixer]
    input1 = _T2_CLEAR + _T2_PEACE
    input2 = _T2_BPPAT_1
    output = _T2_CLEAR_PPAT

# Movement pattern: normal, reverse, ping pong, >><, 2><, etc.
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T2_ARP_OFF
    selectat = 12
    loadpreset = _T2_LOAD_PRESET
    savepreset = _T2_SAVE_PRESET
    notches = 10
    startvalue = 0
    ledcolor = 0.3
    ledvalue = -0.3
    display = 0
    clear = _T2_CLEAR_PPAT
    output = _T2_PATTERN_FADER
    fader = 6
    button = _T2_BPPAT_1

# Names for the display
[switch]
    input1 = "Mforward"
    input2 = "Mbackward"
    input3 = "Mping pong"
    input4 = "D=>  =>  <="
    input5 = "D==>  <="
    input6 = "D==>  <==  =>"
    input7 = "D==>  =>  <==  =>"
    input8 = "Mbrownian"
    input9 = "Mrandom skips"
    input10 = "Mrandom"
    offset = _T2_PATTERN_FADER
    output1 = _T2_PATTERN_FADER_NAME

# Display the name of 'Movement pattern' when edited
[display]
    linger = 0.1
    header = "MOVEMENT PATTERN"
    text = _T2_PATTERN_FADER_NAME
    fontsize = 5

# Set the direction to reverse on fader position 1
[ifequal]
    input1 = _T2_PATTERN_FADER
    input2 = 1
    ifequal = 1
    output = _T2_DIRECTION

# Enable ping pong on fader position 2
[ifequal]
    input1 = _T2_PATTERN_FADER
    input2 = 2
    ifequal = 1
    output = _T2_PINGPONG

# Combine all triggers for clearing
[mixer]
    input1 = _T2_CLEAR
    input2 = _T2_BPCDEVEN_1
    output = _T2_CLEAR_PCDEVEN

# Clock division for even divides/multipliers
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T2_ARP_OFF
    selectat = 12
    loadpreset = _T2_LOAD_PRESET
    savepreset = _T2_SAVE_PRESET
    notches = 7
    startvalue = 3
    ledcolor = 1.1
    ledvalue = -0.3
    display = 0
    clear = _T2_CLEAR_PCDEVEN
    output = _T2_CD_EVEN
    fader = 7
    button = _T2_BPCDEVEN_1

# Select the multiplier based on the fader position
[switch]
    input1 = 1
    input2 = 1
    input3 = 1
    input4 = 1
    input5 = 2
    input6 = 4
    input7 = 8
    offset = _T2_CD_EVEN
    output1 = _T2_CD_EVEN_MULT

# Select the division based on the fader position
[switch]
    input1 = 8
    input2 = 4
    input3 = 2
    input4 = 1
    input5 = 1
    input6 = 1
    input7 = 1
    offset = _T2_CD_EVEN
    output1 = _T2_CD_EVEN_DIV

# Combine all triggers for clearing
[mixer]
    input1 = _T2_CLEAR
    input2 = _T2_BPCDODD_1
    output = _T2_CLEAR_PCDODD

# Clock division for odd divides/multipliers
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T2_ARP_OFF
    selectat = 12
    loadpreset = _T2_LOAD_PRESET
    savepreset = _T2_SAVE_PRESET
    notches = 7
    startvalue = 3
    ledcolor = 1.2
    ledvalue = -0.3
    display = 0
    clear = _T2_CLEAR_PCDODD
    output = _T2_CD_ODD
    fader = 8
    button = _T2_BPCDODD_1

# Select the multiplier based on the fader position
[switch]
    input1 = 1
    input2 = 1
    input3 = 1
    input4 = 1
    input5 = 3
    input6 = 5
    input7 = 7
    offset = _T2_CD_ODD
    output1 = _T2_CD_ODD_MULT

# Select the division based on the fader position
[switch]
    input1 = 7
    input2 = 5
    input3 = 3
    input4 = 1
    input5 = 1
    input6 = 1
    input7 = 1
    offset = _T2_CD_ODD
    output1 = _T2_CD_ODD_DIV

# Names for the display
[switch]
    input1 = "DY  8"
    input2 = "DY  4"
    input3 = "DY  2"
    input4 = "Mno division"
    input5 = "DX  2"
    input6 = "DX  4"
    input7 = "DX  8"
    offset = _T2_CD_EVEN
    output1 = _T2_CD_EVEN_NAMES

# Display the name of 'Clock divider' when edited
[display]
    linger = 0.1
    header = "CLOCK DIVIDER"
    text = _T2_CD_EVEN_NAMES
    fontsize = 5

# Names for the display
[switch]
    input1 = "DY  7"
    input2 = "DY  5"
    input3 = "DY  3"
    input4 = "Mno division"
    input5 = "DX  3"
    input6 = "DX  5"
    input7 = "DX  7"
    offset = _T2_CD_ODD
    output1 = _T2_CD_ODD_NAMES

# Display the name of 'Clock divider' when edited
[display]
    linger = 0.1
    header = "CLOCK DIVIDER"
    text = _T2_CD_ODD_NAMES
    fontsize = 5

# Switch on/off arpeggio mode for track 2
[button]
    select = _SELECTED_TRACK
    selectat = 2
    button = B2.9
    clear = _T2_START_OF_SEQUENCE * _T2_ARP_AUTOSTOP
    output = _T2_ARP
    negated = _T2_ARP_OFF

# The LED of the ARP button blinks when it is on but in Autostop mode
[select]
    select = _SELECTED_TRACK
    selectat = 2
    input = _T2_ARP_AUTOSTOP * _ARP_AUTOSTOP_BLINK + _T2_ARP
    output = L2.9

# Autostop mode for ARP: When you hold CTRL while switching ARP on, it will automatically switch
# off the next time the sequence starts. This allows for easier jamming the ARP for doing fills.
[flipflop]
    set = B2.9 * _CONTROL
    reset = _T2_ARP_OFF
    output = _T2_ARP_AUTOSTOP

# Sync switching ARP on/off with clock in order to avoid audible glitches
[sample]
    input = _T2_ARP
    sample = _T2_CLOCK
    output = _T2_ARP_SYNCED

# Auto reset arpeggiator after N number of steps
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T2_ARP
    selectat = 12
    loadpreset = _T2_LOAD_PRESET
    savepreset = _T2_SAVE_PRESET
    fader = 1
    notches = 17
    ledcolor = 0.8
    ledvalue = 1
    output = _T2_ARP_AUTORESET
    header = "AUTORESET"

# Enable ping pong mode
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T2_ARP
    selectat = 12
    loadpreset = _T2_LOAD_PRESET
    savepreset = _T2_SAVE_PRESET
    fader = 2
    notches = 3
    ledcolor = 0.85
    ledvalue = 1
    output = _T2_ARP_DIRECTION

# Names for the display
[switch]
    input1 = "up"
    input2 = "up/down"
    input3 = "down"
    offset = _T2_ARP_DIRECTION
    output1 = _T2_ARP_DIRECTION_NAME

# Display the name of 'Direction' when edited
[display]
    linger = 0.1
    header = "DIRECTION"
    text = _T2_ARP_DIRECTION_NAME
    fontsize = 2

# Provide gate for reversed direction of arpeggio
[ifequal]
    input1 = _T2_ARP_DIRECTION
    input2 = 2
    ifequal = 1
    else = 0
    output = _T2_ARP_UPDOWN

# Provide gate for ping pong of arpeggio
[ifequal]
    input1 = _T2_ARP_DIRECTION
    input2 = 1
    ifequal = 1
    else = 0
    output = _T2_ARP_PINGPONG

# Seperate octave switch for the arpeggio
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T2_ARP
    selectat = 12
    loadpreset = _T2_LOAD_PRESET
    savepreset = _T2_SAVE_PRESET
    fader = 3
    notches = 5
    ledcolor = 0.2
    startvalue = 2
    ledvalue = 1
    output = _T2_ARP_OCTAVE_SWITCH

# Names for the display
[switch]
    input1 = "2 down"
    input2 = "1 down"
    input3 = "no octaving"
    input4 = "1 up"
    input5 = "2 up"
    offset = _T2_ARP_OCTAVE_SWITCH
    output1 = _T2_ARP_OCTAVE_SWITCH_NAME

# Display the name of 'Octave switch' when edited
[display]
    linger = 0.1
    header = "OCTAVE SWITCH"
    text = _T2_ARP_OCTAVE_SWITCH_NAME
    fontsize = 2

# Enable butterfly mode
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T2_ARP
    selectat = 12
    loadpreset = _T2_LOAD_PRESET
    savepreset = _T2_SAVE_PRESET
    fader = 4
    notches = 2
    ledcolor = 1.15
    ledvalue = 1
    output = _T2_ARP_BUTTERFLY

# Names for the display
[ifequal]
    input1 = _T2_ARP_BUTTERFLY
    input2 = 0
    ifequal = "off"
    else = "on"
    output = _T2_ARP_BUTTERFLY_NAME

# Display the name of 'Butterfly' when edited
[display]
    linger = 0.1
    header = "BUTTERFLY"
    text = _T2_ARP_BUTTERFLY_NAME
    fontsize = 2

# Select one of three octaving patterns
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T2_ARP
    selectat = 12
    loadpreset = _T2_LOAD_PRESET
    savepreset = _T2_SAVE_PRESET
    fader = 5
    notches = 3
    ledcolor = 0.4
    ledvalue = 1
    output = _T2_ARP_OCTAVING

# Names for the display
[switch]
    input1 = "off"
    input2 = "up"
    input3 = "down"
    offset = _T2_ARP_OCTAVING
    output1 = _T2_ARP_OCTAVING_NAME

# Display the name of 'Octaving' when edited
[display]
    linger = 0.1
    header = "OCTAVING"
    text = _T2_ARP_OCTAVING_NAME
    fontsize = 2

# Compute octave offset pitches from fader setting
[copy]
    input = _T2_ARP_OCTAVE_SWITCH * 1V - 2V
    output = _T2_ARP_OCTAVE

# Select the arpeggio pattern
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T2_ARP
    selectat = 12
    loadpreset = _T2_LOAD_PRESET
    savepreset = _T2_SAVE_PRESET
    fader = 6
    notches = 7
    ledcolor = 0.3
    ledvalue = 1
    output = _T2_ARP_PATTERN

# Names for the display
[switch]
    input1 = "D=>"
    input2 = "D=>  =>  <="
    input3 = "D==>  <="
    input4 = "D==>  <==  =>"
    input5 = "D==>  =>  <==  =>"
    input6 = "Mbrownian"
    input7 = "Mrandom"
    offset = _T2_ARP_PATTERN
    output1 = _T2_ARP_PATTERN_NAME

# Display the name of 'Movement pattern' when edited
[display]
    linger = 0.1
    header = "MOVEMENT PATTERN"
    text = _T2_ARP_PATTERN_NAME
    fontsize = 5

# Select one of four different drop patterns
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T2_ARP
    selectat = 12
    loadpreset = _T2_LOAD_PRESET
    savepreset = _T2_SAVE_PRESET
    fader = 7
    notches = 4
    ledcolor = 0.5
    ledvalue = 1
    output = _T2_ARP_DROP

# Names for the display
[switch]
    input1 = "* * * * * *"
    input2 = "* * o * * o"
    input3 = "* o * o * o"
    input4 = "* o o * o o"
    offset = _T2_ARP_DROP
    output1 = _T2_ARP_DROP_NAME

# Display the name of 'Play/skip notes' when edited
[display]
    linger = 0.1
    header = "PLAY/SKIP NOTES"
    text = _T2_ARP_DROP_NAME
    fontsize = 4

# Select one of several clocking patterns
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T2_ARP
    selectat = 12
    loadpreset = _T2_LOAD_PRESET
    savepreset = _T2_SAVE_PRESET
    fader = 8
    notches = 8
    ledcolor = 1.1
    ledvalue = 1
    output = _T2_ARP_CLOCKING

# Names for the display
[switch]
    input1 = "master clock"
    input2 = "sequencer"
    input3 = "clock x 3/2"
    input4 = "clock x 2"
    input5 = "clock x 3"
    input6 = "clock x 4"
    input7 = "clock x 6"
    input8 = "clock x 8"
    offset = _T2_ARP_CLOCKING
    output1 = _T2_ARP_CLOCKING_NAME

# Display the name of 'Arpeggio clocking' when edited
[display]
    linger = 0.1
    header = "ARPEGGIO CLOCKING"
    text = _T2_ARP_CLOCKING_NAME
    fontsize = 2

# Button for loading preset 1 on track 2
[button]
    select = _SELECTED_TRACK
    selectat = 2
    button = B2.1 * _CONTROL
    states = 1
    onvalue = 1
    output = _T2_P1_LOAD

# Button for saving preset 1 on track 2
[button]
    select = _SELECTED_TRACK
    selectat = 2
    button = B2.1
    states = 1
    onvalue = 1
    longpress = _T2_P1_SAVE

# Show a message when _T2_P1_LOAD triggers
[display]
    trigger = _T2_P1_LOAD
    text = "Preset 1 loaded"

# Show a message when _T2_P1_SAVE triggers
[display]
    trigger = _T2_P1_SAVE
    text = "Preset 1 saved"

# Five blinks for the LED of the preset button on saving
[burst]
    trigger = _T2_P1_SAVE
    hz = 5
    count = 5
    output = _T2_P1_SAVE_LED

# Write the save LED animation to the LED if the track is still selected.
[select]
    select = _SELECTED_TRACK
    selectat = 2
    input = _T2_P1_SAVE_LED + 0.3
    output = L2.1

# Button for loading preset 2 on track 2
[button]
    select = _SELECTED_TRACK
    selectat = 2
    button = B2.2 * _CONTROL
    states = 1
    onvalue = 2
    output = _T2_P2_LOAD

# Button for saving preset 2 on track 2
[button]
    select = _SELECTED_TRACK
    selectat = 2
    button = B2.2
    states = 1
    onvalue = 2
    longpress = _T2_P2_SAVE

# Show a message when _T2_P2_LOAD triggers
[display]
    trigger = _T2_P2_LOAD
    text = "Preset 2 loaded"

# Show a message when _T2_P2_SAVE triggers
[display]
    trigger = _T2_P2_SAVE
    text = "Preset 2 saved"

# Five blinks for the LED of the preset button on saving
[burst]
    trigger = _T2_P2_SAVE
    hz = 5
    count = 5
    output = _T2_P2_SAVE_LED

# Write the save LED animation to the LED if the track is still selected.
[select]
    select = _SELECTED_TRACK
    selectat = 2
    input = _T2_P2_SAVE_LED + 0.3
    output = L2.2

# Button for loading preset 3 on track 2
[button]
    select = _SELECTED_TRACK
    selectat = 2
    button = B2.3 * _CONTROL
    states = 1
    onvalue = 3
    output = _T2_P3_LOAD

# Button for saving preset 3 on track 2
[button]
    select = _SELECTED_TRACK
    selectat = 2
    button = B2.3
    states = 1
    onvalue = 3
    longpress = _T2_P3_SAVE

# Show a message when _T2_P3_LOAD triggers
[display]
    trigger = _T2_P3_LOAD
    text = "Preset 3 loaded"

# Show a message when _T2_P3_SAVE triggers
[display]
    trigger = _T2_P3_SAVE
    text = "Preset 3 saved"

# Five blinks for the LED of the preset button on saving
[burst]
    trigger = _T2_P3_SAVE
    hz = 5
    count = 5
    output = _T2_P3_SAVE_LED

# Write the save LED animation to the LED if the track is still selected.
[select]
    select = _SELECTED_TRACK
    selectat = 2
    input = _T2_P3_SAVE_LED + 0.3
    output = L2.3

# Create a trigger with the preset as value when any of the presets is loaded
[mixer]
    input1 = _T2_P1_LOAD
    input2 = _T2_P2_LOAD
    input3 = _T2_P3_LOAD
    output = _T2_LOAD_PRESET

# Create a trigger with the preset as value when any of the presets is saved
[mixer]
    input1 = _T2_P1_SAVE * 1
    input2 = _T2_P2_SAVE * 2
    input3 = _T2_P3_SAVE * 3
    output = _T2_SAVE_PRESET

# Select which notes from the current scale should be played
[buttongroup]
    select = _SELECTED_TRACK
    selectat = 2
    minactive = 1
    maxactive = _CONTROL * -6 + 7
    startbutton = -1
    button1 = B1.1
    led1 = L1.1
    buttonoutput1 = _T2_SEL_1
    button2 = B1.2
    led2 = L1.2
    buttonoutput2 = _T2_SEL_2
    button3 = B1.3
    led3 = L1.3
    buttonoutput3 = _T2_SEL_3
    button4 = B1.4
    led4 = L1.4
    buttonoutput4 = _T2_SEL_4
    button5 = B1.5
    led5 = L1.5
    buttonoutput5 = _T2_SEL_5
    button6 = B1.6
    led6 = L1.6
    buttonoutput6 = _T2_SEL_6
    button7 = B1.7
    led7 = L1.7
    buttonoutput7 = _T2_SEL_7

# Clock divider for track 2
[clocktool]
    clock = _CLOCK
    reset = _RESET
    divide = _T2_CD_EVEN_DIV * _T2_CD_ODD_DIV
    multiply = _T2_CD_EVEN_MULT * _T2_CD_ODD_MULT
    output = _T2_CLOCK

# Mix global and per-track diatonic transposition
[mixer]
    input1 = _T2_NOTESHIFT_CLOCKED
    input2 = _GLOBAL_NOTESHIFT_CLOCKED
    output = _T2_NOTESHIFT_SUM

# The clear range logic should just affect the current track
[ifequal]
    input1 = _SELECTED_TRACK * _RANGE
    input2 = 2
    ifequal = 1
    output = _T2_CLEAR_RANGE

# Collect different sources of resetting the start/end point
[logic]
    input1 = _T2_CLEAR + _T2_PEACE
    input2 = _T2_CLEAR_RANGE * _CONTROL
    or = _T2_CLEARSTARTEND

# Select encoder if track 2 is selected, arp is off and control is not held
[logic]
    input1 = _T2_SELECTED * _NO_CONTROL
    input2 = _T2_ARP_OFF
    and = _T2_ENC_1_SELECTED

# Note shift for each step repetition
[encoder]
    select = _T2_ENC_1_SELECTED
    encoder = 1
    header = "Repeat shift"
    color = 0.6
    discrete = 15
    startvalue = 7
    outputoffset = -7
    output = _T2_REPEATSHIFT

# Select encoder if track 2 is selected, arp is off and control is held
[logic]
    input1 = _T2_SELECTED * _CONTROL
    input2 = _T2_ARP_OFF
    and = _T2_ENC_2_SELECTED

# Note shift for each ratchet
[encoder]
    select = _T2_ENC_2_SELECTED
    encoder = 1
    header = "Ratchet shift"
    color = 0.8
    discrete = 15
    startvalue = 7
    outputoffset = -7
    output = _T2_RATCHETSHIFT

# Sequencer for pitch and gate of track 2
[motoquencer]
    select = _GLOBAL_FADER_SELECTION
    selectat = 2
    page = _PAGE
    stepcopy = _T2_COPY_BUTTON
    doublerange = _T2_COPY_BUTTON
    loadpreset = _T2_LOAD_PRESET
    savepreset = _T2_SAVE_PRESET
    clear = _T2_CLEAR
    select1 = _T2_SEL_1 + _T2_12TONE
    select3 = _T2_SEL_2 + _T2_12TONE
    select5 = _T2_SEL_3 + _T2_12TONE
    select7 = _T2_SEL_4 + _T2_12TONE
    select9 = _T2_SEL_5 + _T2_12TONE
    select11 = _T2_SEL_6 + _T2_12TONE
    select13 = _T2_SEL_7 + _T2_12TONE
    selectfill1 = _T2_12TONE
    selectfill2 = _T2_12TONE
    selectfill3 = _T2_12TONE
    selectfill4 = _T2_12TONE
    selectfill5 = _T2_12TONE
    degree = _DEGREE
    clock = _T2_CLOCK * _RUNNING
    taptempo = _T2_CLOCK
    reset = _RESET + _T2_RESET
    cv = _T2_PITCH
    cvrange = _T2_CVRANGE * 1V
    defaultgate = 0
    gate = _T2_SEQUENCER_GATE
    numfaders = 8
    numsteps = 16
    linktonext = 1
    autoreset = _T2_AUTORESET
    shiftsteps = _T2_SHIFTSTEPS
    pattern = -1 * 2 + _T2_PATTERN_FADER
    direction = _T2_DIRECTION
    pingpong = _T2_PINGPONG
    selectnoteshift = _T2_NOTESHIFT_SUM
    tuningmode = _TUNINGMODE
    tuningpitch = 1V
    bulkedit = _CONTROL
    constantlength = B2.18
    accumulatorrange = _T2_ACCU_RANGE
    root = _ROOT * _T2_TBR_OFF
    transpose = _T2_TBR
    luckybuttons = _T2_LUCKY * _CONTROL
    luckyfaders = _T2_LUCKY * _NO_CONTROL
    luckychance = 1 / 8
    luckyamount = 0.5 * _NO_CONTROL + 0.5
    luckyscope = 3
    fadermode = _FADERMODE
    mute = -1 * _RUNNING + 1
    form = _T2_FORM
    invert = _T2_INVERT
    gatelength = _T2_GATELENGTH
    buttonmode = _BUTTONMODE
    composemode = _COMPOSEMODE
    clearskips = _T2_CLEAR + _T2_PEACE
    clearrepeats = _T2_CLEAR + _T2_PEACE
    clearstartend = _T2_CLEARSTARTEND
    repeatshift = _T2_REPEATSHIFT
    ratchetshift = _T2_RATCHETSHIFT
    startofsequence = _T2_START_OF_SEQUENCE

# Sequencer for velocity
[motoquencer]
    select = _GLOBAL_FADER_SELECTION
    selectat = 2
    page = _PAGE
    stepcopy = _T2_COPY_BUTTON
    doublerange = _T2_COPY_BUTTON
    clear = _T2_CLEAR
    loadpreset = _T2_LOAD_PRESET
    savepreset = _T2_SAVE_PRESET
    cv = _T2_VELOCITY
    defaultcv = 5.5V
    cvbase = 1V
    cvrange = 9V
    quantize = 0
    cvname = "Velocity"
    bulkedit = _CONTROL
    linktonext = 1

# Copy velocity to CV output
[copy]
    input = _T2_VELOCITY
    output = O4

# Sequencer for gate length and glide
[motoquencer]
    select = _GLOBAL_FADER_SELECTION
    selectat = 2
    page = _PAGE
    stepcopy = _T2_COPY_BUTTON
    doublerange = _T2_COPY_BUTTON
    clear = _T2_CLEAR
    loadpreset = _T2_LOAD_PRESET
    savepreset = _T2_SAVE_PRESET
    cv = _T2_GATELENGTH
    cvbase = 0.05
    cvrange = 0.9
    defaultcv = 0.5
    defaultgate = 0
    quantize = 0
    buttoncolor = 0.5
    cvname = "Gate length"
    bulkedit = _CONTROL
    linktonext = 1
    gate = _T2_GLIDE
    gatename = "Glide"

# Sequencer for activity level per step
[motoquencer]
    select = _GLOBAL_FADER_SELECTION
    selectat = 2
    clear = _T2_CLEAR
    loadpreset = _T2_LOAD_PRESET
    savepreset = _T2_SAVE_PRESET
    cv = _T2_STEP_ACTIVITY
    quantize = 0
    defaultcv = 7
    cvname = "Activity"
    cvnotches = 8
    bulkedit = _CONTROL

# Silence the gate if the step does not reach the required activity
[compare]
    input = _T2_STEP_ACTIVITY
    compare = _T2_ACTIVITY
    ifless = 0
    else = _T2_SEQUENCER_GATE
    output = _T2_ACT_GATE

# Modulate gate length for gate output in arpeggiator mode
[gatetool]
    taptempo = _T2_ARP_TAPTEMPO
    gatelength = _T2_GATELENGTH
    inputgate = _T2_ARP_CLOCK
    outputgate = _T2_ARP_MODULATED_GATE

# Switch gate to arpeggiator if active
[ifequal]
    input1 = _T2_ARP_SYNCED
    input2 = 0
    ifequal = _T2_ACT_GATE
    else = _T2_ARP_MODULATED_GATE
    output = _T2_SWITCHED_GATE

# Logic for make the gate silent if the track is muted
[logic]
    input1 = -1 * _T2_MUTED + 1
    input2 = _T2_SWITCHED_GATE
    and = _T2_MUTED_GATE

# Select clock for arpeggiator of track 2. It is either the master clock or a multiplication
# of it, or the sequencer gate output.
[switch]
    input1 = _CLOCK
    input2 = _T2_SEQUENCER_GATE
    input3 = _CLOCK_3_2
    input4 = _CLOCK_2_1
    input5 = _CLOCK_3_1
    input6 = _CLOCK_4_1
    input7 = _CLOCK_6_1
    input8 = _CLOCK_8_1
    output1 = _T2_ARP_CLOCK
    offset = _T2_ARP_CLOCKING

# Create taptempo for arp clock to be used for gate length
[switch]
    input1 = _CLOCK
    input2 = _T2_CLOCK
    input3 = _CLOCK_3_2
    input4 = _CLOCK_2_1
    input5 = _CLOCK_3_1
    input6 = _CLOCK_4_1
    input7 = _CLOCK_6_1
    input8 = _CLOCK_8_1
    output1 = _T2_ARP_TAPTEMPO
    offset = _T2_ARP_CLOCKING * _T2_ARP

# Select encoder if track 2 is selected, arp is on and control is not held
[logic]
    input1 = _T2_SELECTED * _NO_CONTROL
    input2 = _T2_ARP
    and = _T2_ENC_3_SELECTED

# Encoder for base pitch of arpeggiator
[encoder]
    encoder = 1
    select = _T2_ENC_3_SELECTED
    header = "Arp base pitch"
    color = 0.2
    discrete = 37
    sensivity = 3
    output = _T2_ARP_PITCH

# Select encoder if track 2 is selected, arp is on and control is held
[logic]
    input1 = _T2_SELECTED * _CONTROL
    input2 = _T2_ARP
    and = _T2_ENC_4_SELECTED

# Encoder for pitch range of arpeggiator
[encoder]
    encoder = 1
    select = _T2_ENC_4_SELECTED
    header = "Arp pitch range"
    color = 0.4
    discrete = 49
    startvalue = 24
    sensivity = 4
    output = _T2_ARP_RANGE

# Arpeggiator for track 2
[arpeggio]
    select1 = _T2_SEL_1
    select3 = _T2_SEL_2
    select5 = _T2_SEL_3
    select7 = _T2_SEL_4
    select9 = _T2_SEL_5
    select11 = _T2_SEL_6
    select13 = _T2_SEL_7
    selectfill1 = 0
    selectfill2 = 0
    selectfill3 = 0
    selectfill4 = 0
    selectfill5 = 0
    root = _ROOT * _T2_TBR_OFF
    transpose = _T2_TBR
    degree = _DEGREE
    clock = _T2_ARP_CLOCK * _RUNNING
    reset = _RESET
    tuningmode = _TUNINGMODE
    direction = _T2_ARP_UPDOWN
    pingpong = _T2_ARP_PINGPONG
    butterfly = _T2_ARP_BUTTERFLY
    octaves = _T2_ARP_OCTAVING
    drop = _T2_ARP_DROP
    pattern = _T2_ARP_PATTERN
    autoreset = _T2_ARP_AUTORESET
    pitch = _T2_ARP_PITCH / 120
    range = _T2_ARP_RANGE / 120
    output = _T2_ARP_OUTPUT

# Switch pitch output between sequencer and arpeggiator
[ifequal]
    input1 = _T2_ARP_SYNCED
    input2 = 0
    ifequal = _T2_PITCH
    else = _T2_ARP_OUTPUT + _T2_ARP_OCTAVE
    output = _T2_SWITCHED_PITCH

# Mix all sources of pitch together
[mixer]
    input1 = _T2_OCTAVE * 1V - 2V
    input2 = _T2_SWITCHED_PITCH
    input3 = _GLOBAL_OCTAVE_SWITCH * 1V - 2V
    input4 = _GLOBAL_TRANSPOSITION * 0.00833333
    output = _T2_FINAL_PITCH

# Slew limiter for glides
[slew]
    input = _T2_FINAL_PITCH
    exponential = O3
    slew = _T2_GLIDE * _T2_GLIDE_LENGTH

# If we are in compose mode and the arpeggiator is switched off, the gate is output even if
# the sequencer is stopped.
[ifequal]
    input1 = _T2_ARP
    input2 = 0
    ifequal = _RUNNING + _COMPOSEMODE
    else = _RUNNING
    output = _RUNNING_OR_COMPOSE_2

# Copy the gate to its final destination
[copy]
    input = _T2_MUTED_GATE * _RUNNING_OR_COMPOSE_2
    output = _T2_FINAL_GATE

# Copy the gate signal to the CV jack
[copy]
    input = _T2_FINAL_GATE
    output = G1.2

# Names for the display
[switch]
    input1 = "a"
    input2 = "a a a c"
    input3 = "a a c c"
    offset = _T2_FORM
    output1 = _T2_FORM_NAME

# Display the name of 'Song form' when edited
[display]
    linger = 0.1
    header = "SONG FORM"
    text = _T2_FORM_NAME
    fontsize = 4

# Names for the display
[ifequal]
    input1 = _T2_12TONE
    input2 = 0
    ifequal = "diatonic"
    else = "chromatic"
    output = _T2_12TONE_NAME

# Display the name of 'Scale' when edited
[display]
    linger = 0.1
    header = "SCALE"
    text = _T2_12TONE_NAME
    fontsize = 2

# Show a message when _T2_CLEARSTARTEND triggers
[display]
    trigger = _T2_CLEARSTARTEND
    text = "Reset start/end"

# Show a message when _T2_PEACE triggers
[display]
    trigger = _T2_PEACE
    text = "Track 2 peace"

# Show a message when _T2_CLEAR triggers
[display]
    trigger = _T2_CLEAR
    text = "Track 2 cleared"

# Names for the display
[ifequal]
    input1 = _T2_ARP
    input2 = 0
    ifequal = "Sequencer"
    else = "Arpeggiator"
    output = _T2_ARP_NAME

# Display the name of '' when edited
[display]
    linger = 0.1
    header = ""
    text = _T2_ARP_NAME
    fontsize = 2

# -------------------------------------------------
# Track 3
# -------------------------------------------------

# Provide trigger when the clear button is pressed (no Ctrl needed)
[button]
    select = _SELECTED_TRACK
    selectat = 3
    button = B2.4
    shortpress = _T3_CLEAR_BUTTON
    states = 1

# Clear button with control together clears the track
[copy]
    input = _T3_CLEAR_BUTTON * _CONTROL
    output = _T3_CLEAR

# Clear button without control removes all mode that alter the pattern length
[logic]
    input1 = _T3_CLEAR_BUTTON
    input2 = -1 * _CONTROL + 1
    and = _T3_PEACE

# Five blinks for the clear LED
[burst]
    trigger = _T3_CLEAR + _FACTORY_RESET
    hz = 5
    count = 5
    output = _T3_CLEAR_LED

# LED only blinks when track is selected
[select]
    select = _SELECTED_TRACK
    selectat = 3
    input = _T3_CLEAR_LED + 0.3
    output = L2.4

# Reset track immediately
[button]
    select = _SELECTED_TRACK
    selectat = 3
    button = B2.11 * _NO_CONTROL
    states = 1
    output = _T3_RESET

# Show a message when _T3_RESET triggers
[display]
    trigger = _T3_RESET
    text = "Reset track 3"

# Button for copy and paste
[button]
    select = _SELECTED_TRACK
    selectat = 3
    button = B2.24
    states = 1
    output = _T3_COPY_BUTTON

# This button cycles between the song froms A, AAAB and AABB
[button]
    select = _SELECTED_TRACK
    selectat = 3
    clear = _T3_CLEAR
    loadpreset = _T3_LOAD_PRESET
    savepreset = _T3_SAVE_PRESET
    button = B2.7
    led = L2.7
    output = _T3_FORM
    states = 3

# Disables scale and note selection if on
[button]
    select = _SELECTED_TRACK
    selectat = 3
    loadpreset = _T3_LOAD_PRESET
    savepreset = _T3_SAVE_PRESET
    button = B2.8
    led = L2.8
    output = _T3_12TONE

# Enable transposing the melody by the difference of the root note to C
[button]
    select = _SELECTED_TRACK
    selectat = 3
    loadpreset = _T3_LOAD_PRESET
    savepreset = _T3_SAVE_PRESET
    button = B2.5
    led = L2.5
    output = _T3_TBR_ON
    inverted = _T3_TBR_OFF

# Provide the amount of 'transpose by root' in a patch cable
[ifequal]
    input1 = _T3_TBR_ON
    input2 = 1
    ifequal = _ROOT / 120
    output = _T3_TBR

# Names for the display
[ifequal]
    input1 = _T3_TBR_ON
    input2 = 0
    ifequal = "don't transpose"
    else = "transpose"
    output = _T3_TBR_ON_NAME

# Display the name of 'Transpose by root' when edited
[display]
    linger = 0.1
    header = "TRANSPOSE BY ROOT"
    text = _T3_TBR_ON_NAME
    fontsize = 2

# Hold to contiously step faders to random positions, hold with Ctrl to change buttons
[button]
    select = _SELECTED_TRACK
    selectat = 3
    button = B2.10
    states = 1
    onvalue = _LUCKY_CLOCK
    output = _T3_LUCKY

# Show a message when _T3_LUCKY * _NO_CONTROL triggers
[display]
    trigger = _T3_LUCKY * _NO_CONTROL
    text = "I feel lucky!"

# Show a message when _T3_LUCKY * _CONTROL triggers
[display]
    trigger = _T3_LUCKY * _CONTROL
    text = "Lucky gates!"

# Selects melodic inversion (swap low and high notes)
[button]
    select = _SELECTED_TRACK
    selectat = 3
    clear = _T3_CLEAR
    loadpreset = _T3_LOAD_PRESET
    savepreset = _T3_SAVE_PRESET
    button = B2.6
    led = L2.6
    output = _T3_INVERT

# Names for the display
[ifequal]
    input1 = _T3_INVERT
    input2 = 0
    ifequal = "don't invert"
    else = "invert pitches"
    output = _T3_INVERT_NAME

# Display the name of 'Pitch inversion' when edited
[display]
    linger = 0.1
    header = "PITCH INVERSION"
    text = _T3_INVERT_NAME
    fontsize = 2

# Combine all triggers for clearing
[mixer]
    input1 = _T3_CLEAR + _T3_PEACE
    input2 = _T3_BPAR_1
    output = _T3_CLEAR_PAR

# Reset track after X clock ticks
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T3_ARP_OFF
    selectat = 13
    loadpreset = _T3_LOAD_PRESET
    savepreset = _T3_SAVE_PRESET
    notches = 17
    startvalue = 0
    ledcolor = 0.8
    ledvalue = -0.3
    header = "AUTORESET"
    clear = _T3_CLEAR_PAR
    output = _T3_AUTORESET
    fader = 1
    button = _T3_BPAR_1

# Combine all triggers for clearing
[mixer]
    input1 = _T3_CLEAR + _T3_PEACE
    input2 = _T3_BPSS_1
    output = _T3_CLEAR_PSS

# Shift the steps of the sequence by this number
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T3_ARP_OFF
    selectat = 13
    loadpreset = _T3_LOAD_PRESET
    savepreset = _T3_SAVE_PRESET
    notches = 17
    startvalue = 0
    ledcolor = 0.6
    ledvalue = -0.3
    header = "SHIFT STEPS"
    clear = _T3_CLEAR_PSS
    output = _T3_SHIFTSTEPS
    fader = 2
    button = _T3_BPSS_1

# Combine all triggers for clearing
[mixer]
    input1 = _T3_CLEAR
    input2 = _T3_BPOCT_1 + _T3_BPOCT_2
    output = _T3_CLEAR_POCT

# Octave switch: -2, -1, 0, +1, +2
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T3_ARP_OFF
    selectat = 13
    loadpreset = _T3_LOAD_PRESET
    savepreset = _T3_SAVE_PRESET
    notches = 5
    startvalue = 2
    ledcolor = 0.2
    ledvalue = -0.3
    display = 0
    clear = _T3_CLEAR_POCT
    sharewithnext = 1
    fader = 3
    button = _T3_BPOCT_1

# Octave switch: -2, -1, 0, +1, +2
[motorfader]
    loadpreset = _T3_LOAD_PRESET
    savepreset = _T3_SAVE_PRESET
    notches = 5
    startvalue = 2
    ledcolor = 0.2
    ledvalue = -0.3
    display = 0
    clear = _T3_CLEAR_POCT
    select = _GLOBAL_FADER_SELECTION
    selectat = 98
    fader = 5
    button = _T3_BPOCT_2
    output = _T3_OCTAVE

# Names for the display
[switch]
    input1 = "2 down"
    input2 = "1 down"
    input3 = "no octaving"
    input4 = "1 up"
    input5 = "2 up"
    offset = _T3_OCTAVE
    output1 = _T3_OCTAVE_NAME

# Display the name of 'Octave switch' when edited
[display]
    linger = 0.1
    header = "OCTAVE SWITCH"
    text = _T3_OCTAVE_NAME
    fontsize = 2

# Combine all triggers for clearing
[mixer]
    input1 = _T3_CLEAR
    input2 = _T3_BPDT_1 + _T3_BPDT_2
    output = _T3_CLEAR_PDT

# Diatonic transposition
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T3_ARP_OFF
    selectat = 13
    loadpreset = _T3_LOAD_PRESET
    savepreset = _T3_SAVE_PRESET
    notches = 15
    startvalue = 7
    ledcolor = 0.4
    ledvalue = -0.3
    outputoffset = -7
    header = "DIATONIC TRANSPOSE"
    clear = _T3_CLEAR_PDT
    sharewithnext = 1
    fader = 4
    button = _T3_BPDT_1

# Diatonic transposition
[motorfader]
    loadpreset = _T3_LOAD_PRESET
    savepreset = _T3_SAVE_PRESET
    notches = 15
    startvalue = 7
    ledcolor = 0.4
    ledvalue = -0.3
    outputoffset = -7
    header = "DIATONIC TRANSPOSE"
    clear = _T3_CLEAR_PDT
    select = _GLOBAL_FADER_SELECTION
    selectat = 98
    fader = 6
    button = _T3_BPDT_2
    output = _T3_NOTESHIFT

# Prevent diatonic transposition from happending between clock ticks
[sample]
    input = _T3_NOTESHIFT
    sample = _CLOCK
    output = _T3_NOTESHIFT_CLOCKED

# Combine all triggers for clearing
[mixer]
    input1 = _T3_CLEAR
    input2 = _T3_BPACT_1
    output = _T3_CLEAR_PACT

# Minimum activity a step needs to have to be played
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T3_ARP_OFF
    selectat = 13
    loadpreset = _T3_LOAD_PRESET
    savepreset = _T3_SAVE_PRESET
    notches = 8
    startvalue = 0
    ledcolor = 0.55
    ledvalue = -0.3
    header = "ACTIVITY"
    clear = _T3_CLEAR_PACT
    output = _T3_ACTIVITY
    fader = 5
    button = _T3_BPACT_1

# Combine all triggers for clearing
[mixer]
    input1 = _T3_CLEAR + _T3_PEACE
    input2 = _T3_BPPAT_1
    output = _T3_CLEAR_PPAT

# Movement pattern: normal, reverse, ping pong, >><, 2><, etc.
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T3_ARP_OFF
    selectat = 13
    loadpreset = _T3_LOAD_PRESET
    savepreset = _T3_SAVE_PRESET
    notches = 10
    startvalue = 0
    ledcolor = 0.3
    ledvalue = -0.3
    display = 0
    clear = _T3_CLEAR_PPAT
    output = _T3_PATTERN_FADER
    fader = 6
    button = _T3_BPPAT_1

# Names for the display
[switch]
    input1 = "Mforward"
    input2 = "Mbackward"
    input3 = "Mping pong"
    input4 = "D=>  =>  <="
    input5 = "D==>  <="
    input6 = "D==>  <==  =>"
    input7 = "D==>  =>  <==  =>"
    input8 = "Mbrownian"
    input9 = "Mrandom skips"
    input10 = "Mrandom"
    offset = _T3_PATTERN_FADER
    output1 = _T3_PATTERN_FADER_NAME

# Display the name of 'Movement pattern' when edited
[display]
    linger = 0.1
    header = "MOVEMENT PATTERN"
    text = _T3_PATTERN_FADER_NAME
    fontsize = 5

# Set the direction to reverse on fader position 1
[ifequal]
    input1 = _T3_PATTERN_FADER
    input2 = 1
    ifequal = 1
    output = _T3_DIRECTION

# Enable ping pong on fader position 2
[ifequal]
    input1 = _T3_PATTERN_FADER
    input2 = 2
    ifequal = 1
    output = _T3_PINGPONG

# Combine all triggers for clearing
[mixer]
    input1 = _T3_CLEAR
    input2 = _T3_BPCDEVEN_1
    output = _T3_CLEAR_PCDEVEN

# Clock division for even divides/multipliers
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T3_ARP_OFF
    selectat = 13
    loadpreset = _T3_LOAD_PRESET
    savepreset = _T3_SAVE_PRESET
    notches = 7
    startvalue = 3
    ledcolor = 1.1
    ledvalue = -0.3
    display = 0
    clear = _T3_CLEAR_PCDEVEN
    output = _T3_CD_EVEN
    fader = 7
    button = _T3_BPCDEVEN_1

# Select the multiplier based on the fader position
[switch]
    input1 = 1
    input2 = 1
    input3 = 1
    input4 = 1
    input5 = 2
    input6 = 4
    input7 = 8
    offset = _T3_CD_EVEN
    output1 = _T3_CD_EVEN_MULT

# Select the division based on the fader position
[switch]
    input1 = 8
    input2 = 4
    input3 = 2
    input4 = 1
    input5 = 1
    input6 = 1
    input7 = 1
    offset = _T3_CD_EVEN
    output1 = _T3_CD_EVEN_DIV

# Combine all triggers for clearing
[mixer]
    input1 = _T3_CLEAR
    input2 = _T3_BPCDODD_1
    output = _T3_CLEAR_PCDODD

# Clock division for odd divides/multipliers
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T3_ARP_OFF
    selectat = 13
    loadpreset = _T3_LOAD_PRESET
    savepreset = _T3_SAVE_PRESET
    notches = 7
    startvalue = 3
    ledcolor = 1.2
    ledvalue = -0.3
    display = 0
    clear = _T3_CLEAR_PCDODD
    output = _T3_CD_ODD
    fader = 8
    button = _T3_BPCDODD_1

# Select the multiplier based on the fader position
[switch]
    input1 = 1
    input2 = 1
    input3 = 1
    input4 = 1
    input5 = 3
    input6 = 5
    input7 = 7
    offset = _T3_CD_ODD
    output1 = _T3_CD_ODD_MULT

# Select the division based on the fader position
[switch]
    input1 = 7
    input2 = 5
    input3 = 3
    input4 = 1
    input5 = 1
    input6 = 1
    input7 = 1
    offset = _T3_CD_ODD
    output1 = _T3_CD_ODD_DIV

# Names for the display
[switch]
    input1 = "DY  8"
    input2 = "DY  4"
    input3 = "DY  2"
    input4 = "Mno division"
    input5 = "DX  2"
    input6 = "DX  4"
    input7 = "DX  8"
    offset = _T3_CD_EVEN
    output1 = _T3_CD_EVEN_NAMES

# Display the name of 'Clock divider' when edited
[display]
    linger = 0.1
    header = "CLOCK DIVIDER"
    text = _T3_CD_EVEN_NAMES
    fontsize = 5

# Names for the display
[switch]
    input1 = "DY  7"
    input2 = "DY  5"
    input3 = "DY  3"
    input4 = "Mno division"
    input5 = "DX  3"
    input6 = "DX  5"
    input7 = "DX  7"
    offset = _T3_CD_ODD
    output1 = _T3_CD_ODD_NAMES

# Display the name of 'Clock divider' when edited
[display]
    linger = 0.1
    header = "CLOCK DIVIDER"
    text = _T3_CD_ODD_NAMES
    fontsize = 5

# Switch on/off arpeggio mode for track 3
[button]
    select = _SELECTED_TRACK
    selectat = 3
    button = B2.9
    clear = _T3_START_OF_SEQUENCE * _T3_ARP_AUTOSTOP
    output = _T3_ARP
    negated = _T3_ARP_OFF

# The LED of the ARP button blinks when it is on but in Autostop mode
[select]
    select = _SELECTED_TRACK
    selectat = 3
    input = _T3_ARP_AUTOSTOP * _ARP_AUTOSTOP_BLINK + _T3_ARP
    output = L2.9

# Autostop mode for ARP: When you hold CTRL while switching ARP on, it will automatically switch
# off the next time the sequence starts. This allows for easier jamming the ARP for doing fills.
[flipflop]
    set = B2.9 * _CONTROL
    reset = _T3_ARP_OFF
    output = _T3_ARP_AUTOSTOP

# Sync switching ARP on/off with clock in order to avoid audible glitches
[sample]
    input = _T3_ARP
    sample = _T3_CLOCK
    output = _T3_ARP_SYNCED

# Auto reset arpeggiator after N number of steps
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T3_ARP
    selectat = 13
    loadpreset = _T3_LOAD_PRESET
    savepreset = _T3_SAVE_PRESET
    fader = 1
    notches = 17
    ledcolor = 0.8
    ledvalue = 1
    output = _T3_ARP_AUTORESET
    header = "AUTORESET"

# Enable ping pong mode
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T3_ARP
    selectat = 13
    loadpreset = _T3_LOAD_PRESET
    savepreset = _T3_SAVE_PRESET
    fader = 2
    notches = 3
    ledcolor = 0.85
    ledvalue = 1
    output = _T3_ARP_DIRECTION

# Names for the display
[switch]
    input1 = "up"
    input2 = "up/down"
    input3 = "down"
    offset = _T3_ARP_DIRECTION
    output1 = _T3_ARP_DIRECTION_NAME

# Display the name of 'Direction' when edited
[display]
    linger = 0.1
    header = "DIRECTION"
    text = _T3_ARP_DIRECTION_NAME
    fontsize = 2

# Provide gate for reversed direction of arpeggio
[ifequal]
    input1 = _T3_ARP_DIRECTION
    input2 = 2
    ifequal = 1
    else = 0
    output = _T3_ARP_UPDOWN

# Provide gate for ping pong of arpeggio
[ifequal]
    input1 = _T3_ARP_DIRECTION
    input2 = 1
    ifequal = 1
    else = 0
    output = _T3_ARP_PINGPONG

# Seperate octave switch for the arpeggio
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T3_ARP
    selectat = 13
    loadpreset = _T3_LOAD_PRESET
    savepreset = _T3_SAVE_PRESET
    fader = 3
    notches = 5
    ledcolor = 0.2
    startvalue = 2
    ledvalue = 1
    output = _T3_ARP_OCTAVE_SWITCH

# Names for the display
[switch]
    input1 = "2 down"
    input2 = "1 down"
    input3 = "no octaving"
    input4 = "1 up"
    input5 = "2 up"
    offset = _T3_ARP_OCTAVE_SWITCH
    output1 = _T3_ARP_OCTAVE_SWITCH_NAME

# Display the name of 'Octave switch' when edited
[display]
    linger = 0.1
    header = "OCTAVE SWITCH"
    text = _T3_ARP_OCTAVE_SWITCH_NAME
    fontsize = 2

# Enable butterfly mode
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T3_ARP
    selectat = 13
    loadpreset = _T3_LOAD_PRESET
    savepreset = _T3_SAVE_PRESET
    fader = 4
    notches = 2
    ledcolor = 1.15
    ledvalue = 1
    output = _T3_ARP_BUTTERFLY

# Names for the display
[ifequal]
    input1 = _T3_ARP_BUTTERFLY
    input2 = 0
    ifequal = "off"
    else = "on"
    output = _T3_ARP_BUTTERFLY_NAME

# Display the name of 'Butterfly' when edited
[display]
    linger = 0.1
    header = "BUTTERFLY"
    text = _T3_ARP_BUTTERFLY_NAME
    fontsize = 2

# Select one of three octaving patterns
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T3_ARP
    selectat = 13
    loadpreset = _T3_LOAD_PRESET
    savepreset = _T3_SAVE_PRESET
    fader = 5
    notches = 3
    ledcolor = 0.4
    ledvalue = 1
    output = _T3_ARP_OCTAVING

# Names for the display
[switch]
    input1 = "off"
    input2 = "up"
    input3 = "down"
    offset = _T3_ARP_OCTAVING
    output1 = _T3_ARP_OCTAVING_NAME

# Display the name of 'Octaving' when edited
[display]
    linger = 0.1
    header = "OCTAVING"
    text = _T3_ARP_OCTAVING_NAME
    fontsize = 2

# Compute octave offset pitches from fader setting
[copy]
    input = _T3_ARP_OCTAVE_SWITCH * 1V - 2V
    output = _T3_ARP_OCTAVE

# Select the arpeggio pattern
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T3_ARP
    selectat = 13
    loadpreset = _T3_LOAD_PRESET
    savepreset = _T3_SAVE_PRESET
    fader = 6
    notches = 7
    ledcolor = 0.3
    ledvalue = 1
    output = _T3_ARP_PATTERN

# Names for the display
[switch]
    input1 = "D=>"
    input2 = "D=>  =>  <="
    input3 = "D==>  <="
    input4 = "D==>  <==  =>"
    input5 = "D==>  =>  <==  =>"
    input6 = "Mbrownian"
    input7 = "Mrandom"
    offset = _T3_ARP_PATTERN
    output1 = _T3_ARP_PATTERN_NAME

# Display the name of 'Movement pattern' when edited
[display]
    linger = 0.1
    header = "MOVEMENT PATTERN"
    text = _T3_ARP_PATTERN_NAME
    fontsize = 5

# Select one of four different drop patterns
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T3_ARP
    selectat = 13
    loadpreset = _T3_LOAD_PRESET
    savepreset = _T3_SAVE_PRESET
    fader = 7
    notches = 4
    ledcolor = 0.5
    ledvalue = 1
    output = _T3_ARP_DROP

# Names for the display
[switch]
    input1 = "* * * * * *"
    input2 = "* * o * * o"
    input3 = "* o * o * o"
    input4 = "* o o * o o"
    offset = _T3_ARP_DROP
    output1 = _T3_ARP_DROP_NAME

# Display the name of 'Play/skip notes' when edited
[display]
    linger = 0.1
    header = "PLAY/SKIP NOTES"
    text = _T3_ARP_DROP_NAME
    fontsize = 4

# Select one of several clocking patterns
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T3_ARP
    selectat = 13
    loadpreset = _T3_LOAD_PRESET
    savepreset = _T3_SAVE_PRESET
    fader = 8
    notches = 8
    ledcolor = 1.1
    ledvalue = 1
    output = _T3_ARP_CLOCKING

# Names for the display
[switch]
    input1 = "master clock"
    input2 = "sequencer"
    input3 = "clock x 3/2"
    input4 = "clock x 2"
    input5 = "clock x 3"
    input6 = "clock x 4"
    input7 = "clock x 6"
    input8 = "clock x 8"
    offset = _T3_ARP_CLOCKING
    output1 = _T3_ARP_CLOCKING_NAME

# Display the name of 'Arpeggio clocking' when edited
[display]
    linger = 0.1
    header = "ARPEGGIO CLOCKING"
    text = _T3_ARP_CLOCKING_NAME
    fontsize = 2

# Button for loading preset 1 on track 3
[button]
    select = _SELECTED_TRACK
    selectat = 3
    button = B2.1 * _CONTROL
    states = 1
    onvalue = 1
    output = _T3_P1_LOAD

# Button for saving preset 1 on track 3
[button]
    select = _SELECTED_TRACK
    selectat = 3
    button = B2.1
    states = 1
    onvalue = 1
    longpress = _T3_P1_SAVE

# Show a message when _T3_P1_LOAD triggers
[display]
    trigger = _T3_P1_LOAD
    text = "Preset 1 loaded"

# Show a message when _T3_P1_SAVE triggers
[display]
    trigger = _T3_P1_SAVE
    text = "Preset 1 saved"

# Five blinks for the LED of the preset button on saving
[burst]
    trigger = _T3_P1_SAVE
    hz = 5
    count = 5
    output = _T3_P1_SAVE_LED

# Write the save LED animation to the LED if the track is still selected.
[select]
    select = _SELECTED_TRACK
    selectat = 3
    input = _T3_P1_SAVE_LED + 0.3
    output = L2.1

# Button for loading preset 2 on track 3
[button]
    select = _SELECTED_TRACK
    selectat = 3
    button = B2.2 * _CONTROL
    states = 1
    onvalue = 2
    output = _T3_P2_LOAD

# Button for saving preset 2 on track 3
[button]
    select = _SELECTED_TRACK
    selectat = 3
    button = B2.2
    states = 1
    onvalue = 2
    longpress = _T3_P2_SAVE

# Show a message when _T3_P2_LOAD triggers
[display]
    trigger = _T3_P2_LOAD
    text = "Preset 2 loaded"

# Show a message when _T3_P2_SAVE triggers
[display]
    trigger = _T3_P2_SAVE
    text = "Preset 2 saved"

# Five blinks for the LED of the preset button on saving
[burst]
    trigger = _T3_P2_SAVE
    hz = 5
    count = 5
    output = _T3_P2_SAVE_LED

# Write the save LED animation to the LED if the track is still selected.
[select]
    select = _SELECTED_TRACK
    selectat = 3
    input = _T3_P2_SAVE_LED + 0.3
    output = L2.2

# Button for loading preset 3 on track 3
[button]
    select = _SELECTED_TRACK
    selectat = 3
    button = B2.3 * _CONTROL
    states = 1
    onvalue = 3
    output = _T3_P3_LOAD

# Button for saving preset 3 on track 3
[button]
    select = _SELECTED_TRACK
    selectat = 3
    button = B2.3
    states = 1
    onvalue = 3
    longpress = _T3_P3_SAVE

# Show a message when _T3_P3_LOAD triggers
[display]
    trigger = _T3_P3_LOAD
    text = "Preset 3 loaded"

# Show a message when _T3_P3_SAVE triggers
[display]
    trigger = _T3_P3_SAVE
    text = "Preset 3 saved"

# Five blinks for the LED of the preset button on saving
[burst]
    trigger = _T3_P3_SAVE
    hz = 5
    count = 5
    output = _T3_P3_SAVE_LED

# Write the save LED animation to the LED if the track is still selected.
[select]
    select = _SELECTED_TRACK
    selectat = 3
    input = _T3_P3_SAVE_LED + 0.3
    output = L2.3

# Create a trigger with the preset as value when any of the presets is loaded
[mixer]
    input1 = _T3_P1_LOAD
    input2 = _T3_P2_LOAD
    input3 = _T3_P3_LOAD
    output = _T3_LOAD_PRESET

# Create a trigger with the preset as value when any of the presets is saved
[mixer]
    input1 = _T3_P1_SAVE * 1
    input2 = _T3_P2_SAVE * 2
    input3 = _T3_P3_SAVE * 3
    output = _T3_SAVE_PRESET

# Select which notes from the current scale should be played
[buttongroup]
    select = _SELECTED_TRACK
    selectat = 3
    minactive = 1
    maxactive = _CONTROL * -6 + 7
    startbutton = -1
    button1 = B1.1
    led1 = L1.1
    buttonoutput1 = _T3_SEL_1
    button2 = B1.2
    led2 = L1.2
    buttonoutput2 = _T3_SEL_2
    button3 = B1.3
    led3 = L1.3
    buttonoutput3 = _T3_SEL_3
    button4 = B1.4
    led4 = L1.4
    buttonoutput4 = _T3_SEL_4
    button5 = B1.5
    led5 = L1.5
    buttonoutput5 = _T3_SEL_5
    button6 = B1.6
    led6 = L1.6
    buttonoutput6 = _T3_SEL_6
    button7 = B1.7
    led7 = L1.7
    buttonoutput7 = _T3_SEL_7

# Clock divider for track 3
[clocktool]
    clock = _CLOCK
    reset = _RESET
    divide = _T3_CD_EVEN_DIV * _T3_CD_ODD_DIV
    multiply = _T3_CD_EVEN_MULT * _T3_CD_ODD_MULT
    output = _T3_CLOCK

# Mix global and per-track diatonic transposition
[mixer]
    input1 = _T3_NOTESHIFT_CLOCKED
    input2 = _GLOBAL_NOTESHIFT_CLOCKED
    output = _T3_NOTESHIFT_SUM

# The clear range logic should just affect the current track
[ifequal]
    input1 = _SELECTED_TRACK * _RANGE
    input2 = 3
    ifequal = 1
    output = _T3_CLEAR_RANGE

# Collect different sources of resetting the start/end point
[logic]
    input1 = _T3_CLEAR + _T3_PEACE
    input2 = _T3_CLEAR_RANGE * _CONTROL
    or = _T3_CLEARSTARTEND

# Select encoder if track 3 is selected, arp is off and control is not held
[logic]
    input1 = _T3_SELECTED * _NO_CONTROL
    input2 = _T3_ARP_OFF
    and = _T3_ENC_1_SELECTED

# Note shift for each step repetition
[encoder]
    select = _T3_ENC_1_SELECTED
    encoder = 1
    header = "Repeat shift"
    color = 0.6
    discrete = 15
    startvalue = 7
    outputoffset = -7
    output = _T3_REPEATSHIFT

# Select encoder if track 3 is selected, arp is off and control is held
[logic]
    input1 = _T3_SELECTED * _CONTROL
    input2 = _T3_ARP_OFF
    and = _T3_ENC_2_SELECTED

# Note shift for each ratchet
[encoder]
    select = _T3_ENC_2_SELECTED
    encoder = 1
    header = "Ratchet shift"
    color = 0.8
    discrete = 15
    startvalue = 7
    outputoffset = -7
    output = _T3_RATCHETSHIFT

# Sequencer for pitch and gate of track 3
[motoquencer]
    select = _GLOBAL_FADER_SELECTION
    selectat = 3
    page = _PAGE
    stepcopy = _T3_COPY_BUTTON
    doublerange = _T3_COPY_BUTTON
    loadpreset = _T3_LOAD_PRESET
    savepreset = _T3_SAVE_PRESET
    clear = _T3_CLEAR
    select1 = _T3_SEL_1 + _T3_12TONE
    select3 = _T3_SEL_2 + _T3_12TONE
    select5 = _T3_SEL_3 + _T3_12TONE
    select7 = _T3_SEL_4 + _T3_12TONE
    select9 = _T3_SEL_5 + _T3_12TONE
    select11 = _T3_SEL_6 + _T3_12TONE
    select13 = _T3_SEL_7 + _T3_12TONE
    selectfill1 = _T3_12TONE
    selectfill2 = _T3_12TONE
    selectfill3 = _T3_12TONE
    selectfill4 = _T3_12TONE
    selectfill5 = _T3_12TONE
    degree = _DEGREE
    clock = _T3_CLOCK * _RUNNING
    taptempo = _T3_CLOCK
    reset = _RESET + _T3_RESET
    cv = _T3_PITCH
    cvrange = _T3_CVRANGE * 1V
    defaultgate = 0
    gate = _T3_SEQUENCER_GATE
    numfaders = 8
    numsteps = 16
    linktonext = 1
    autoreset = _T3_AUTORESET
    shiftsteps = _T3_SHIFTSTEPS
    pattern = -1 * 2 + _T3_PATTERN_FADER
    direction = _T3_DIRECTION
    pingpong = _T3_PINGPONG
    selectnoteshift = _T3_NOTESHIFT_SUM
    tuningmode = _TUNINGMODE
    tuningpitch = 1V
    bulkedit = _CONTROL
    constantlength = B2.18
    accumulatorrange = _T3_ACCU_RANGE
    root = _ROOT * _T3_TBR_OFF
    transpose = _T3_TBR
    luckybuttons = _T3_LUCKY * _CONTROL
    luckyfaders = _T3_LUCKY * _NO_CONTROL
    luckychance = 1 / 8
    luckyamount = 0.5 * _NO_CONTROL + 0.5
    luckyscope = 3
    fadermode = _FADERMODE
    mute = -1 * _RUNNING + 1
    form = _T3_FORM
    invert = _T3_INVERT
    gatelength = _T3_GATELENGTH
    buttonmode = _BUTTONMODE
    composemode = _COMPOSEMODE
    clearskips = _T3_CLEAR + _T3_PEACE
    clearrepeats = _T3_CLEAR + _T3_PEACE
    clearstartend = _T3_CLEARSTARTEND
    repeatshift = _T3_REPEATSHIFT
    ratchetshift = _T3_RATCHETSHIFT
    startofsequence = _T3_START_OF_SEQUENCE

# Sequencer for velocity
[motoquencer]
    select = _GLOBAL_FADER_SELECTION
    selectat = 3
    page = _PAGE
    stepcopy = _T3_COPY_BUTTON
    doublerange = _T3_COPY_BUTTON
    clear = _T3_CLEAR
    loadpreset = _T3_LOAD_PRESET
    savepreset = _T3_SAVE_PRESET
    cv = _T3_VELOCITY
    defaultcv = 5.5V
    cvbase = 1V
    cvrange = 9V
    quantize = 0
    cvname = "Velocity"
    bulkedit = _CONTROL
    linktonext = 1

# Copy velocity to CV output
[copy]
    input = _T3_VELOCITY
    output = O6

# Sequencer for gate length and glide
[motoquencer]
    select = _GLOBAL_FADER_SELECTION
    selectat = 3
    page = _PAGE
    stepcopy = _T3_COPY_BUTTON
    doublerange = _T3_COPY_BUTTON
    clear = _T3_CLEAR
    loadpreset = _T3_LOAD_PRESET
    savepreset = _T3_SAVE_PRESET
    cv = _T3_GATELENGTH
    cvbase = 0.05
    cvrange = 0.9
    defaultcv = 0.5
    defaultgate = 0
    quantize = 0
    buttoncolor = 0.5
    cvname = "Gate length"
    bulkedit = _CONTROL
    linktonext = 1
    gate = _T3_GLIDE
    gatename = "Glide"

# Sequencer for activity level per step
[motoquencer]
    select = _GLOBAL_FADER_SELECTION
    selectat = 3
    clear = _T3_CLEAR
    loadpreset = _T3_LOAD_PRESET
    savepreset = _T3_SAVE_PRESET
    cv = _T3_STEP_ACTIVITY
    quantize = 0
    defaultcv = 7
    cvname = "Activity"
    cvnotches = 8
    bulkedit = _CONTROL

# Silence the gate if the step does not reach the required activity
[compare]
    input = _T3_STEP_ACTIVITY
    compare = _T3_ACTIVITY
    ifless = 0
    else = _T3_SEQUENCER_GATE
    output = _T3_ACT_GATE

# Modulate gate length for gate output in arpeggiator mode
[gatetool]
    taptempo = _T3_ARP_TAPTEMPO
    gatelength = _T3_GATELENGTH
    inputgate = _T3_ARP_CLOCK
    outputgate = _T3_ARP_MODULATED_GATE

# Switch gate to arpeggiator if active
[ifequal]
    input1 = _T3_ARP_SYNCED
    input2 = 0
    ifequal = _T3_ACT_GATE
    else = _T3_ARP_MODULATED_GATE
    output = _T3_SWITCHED_GATE

# Logic for make the gate silent if the track is muted
[logic]
    input1 = -1 * _T3_MUTED + 1
    input2 = _T3_SWITCHED_GATE
    and = _T3_MUTED_GATE

# Select clock for arpeggiator of track 3. It is either the master clock or a multiplication
# of it, or the sequencer gate output.
[switch]
    input1 = _CLOCK
    input2 = _T3_SEQUENCER_GATE
    input3 = _CLOCK_3_2
    input4 = _CLOCK_2_1
    input5 = _CLOCK_3_1
    input6 = _CLOCK_4_1
    input7 = _CLOCK_6_1
    input8 = _CLOCK_8_1
    output1 = _T3_ARP_CLOCK
    offset = _T3_ARP_CLOCKING

# Create taptempo for arp clock to be used for gate length
[switch]
    input1 = _CLOCK
    input2 = _T3_CLOCK
    input3 = _CLOCK_3_2
    input4 = _CLOCK_2_1
    input5 = _CLOCK_3_1
    input6 = _CLOCK_4_1
    input7 = _CLOCK_6_1
    input8 = _CLOCK_8_1
    output1 = _T3_ARP_TAPTEMPO
    offset = _T3_ARP_CLOCKING * _T3_ARP

# Select encoder if track 3 is selected, arp is on and control is not held
[logic]
    input1 = _T3_SELECTED * _NO_CONTROL
    input2 = _T3_ARP
    and = _T3_ENC_3_SELECTED

# Encoder for base pitch of arpeggiator
[encoder]
    encoder = 1
    select = _T3_ENC_3_SELECTED
    header = "Arp base pitch"
    color = 0.2
    discrete = 37
    sensivity = 3
    output = _T3_ARP_PITCH

# Select encoder if track 3 is selected, arp is on and control is held
[logic]
    input1 = _T3_SELECTED * _CONTROL
    input2 = _T3_ARP
    and = _T3_ENC_4_SELECTED

# Encoder for pitch range of arpeggiator
[encoder]
    encoder = 1
    select = _T3_ENC_4_SELECTED
    header = "Arp pitch range"
    color = 0.4
    discrete = 49
    startvalue = 24
    sensivity = 4
    output = _T3_ARP_RANGE

# Arpeggiator for track 3
[arpeggio]
    select1 = _T3_SEL_1
    select3 = _T3_SEL_2
    select5 = _T3_SEL_3
    select7 = _T3_SEL_4
    select9 = _T3_SEL_5
    select11 = _T3_SEL_6
    select13 = _T3_SEL_7
    selectfill1 = 0
    selectfill2 = 0
    selectfill3 = 0
    selectfill4 = 0
    selectfill5 = 0
    root = _ROOT * _T3_TBR_OFF
    transpose = _T3_TBR
    degree = _DEGREE
    clock = _T3_ARP_CLOCK * _RUNNING
    reset = _RESET
    tuningmode = _TUNINGMODE
    direction = _T3_ARP_UPDOWN
    pingpong = _T3_ARP_PINGPONG
    butterfly = _T3_ARP_BUTTERFLY
    octaves = _T3_ARP_OCTAVING
    drop = _T3_ARP_DROP
    pattern = _T3_ARP_PATTERN
    autoreset = _T3_ARP_AUTORESET
    pitch = _T3_ARP_PITCH / 120
    range = _T3_ARP_RANGE / 120
    output = _T3_ARP_OUTPUT

# Switch pitch output between sequencer and arpeggiator
[ifequal]
    input1 = _T3_ARP_SYNCED
    input2 = 0
    ifequal = _T3_PITCH
    else = _T3_ARP_OUTPUT + _T3_ARP_OCTAVE
    output = _T3_SWITCHED_PITCH

# Mix all sources of pitch together
[mixer]
    input1 = _T3_OCTAVE * 1V - 2V
    input2 = _T3_SWITCHED_PITCH
    input3 = _GLOBAL_OCTAVE_SWITCH * 1V - 2V
    input4 = _GLOBAL_TRANSPOSITION * 0.00833333
    output = _T3_FINAL_PITCH

# Slew limiter for glides
[slew]
    input = _T3_FINAL_PITCH
    exponential = O5
    slew = _T3_GLIDE * _T3_GLIDE_LENGTH

# If we are in compose mode and the arpeggiator is switched off, the gate is output even if
# the sequencer is stopped.
[ifequal]
    input1 = _T3_ARP
    input2 = 0
    ifequal = _RUNNING + _COMPOSEMODE
    else = _RUNNING
    output = _RUNNING_OR_COMPOSE_3

# Copy the gate to its final destination
[copy]
    input = _T3_MUTED_GATE * _RUNNING_OR_COMPOSE_3
    output = _T3_FINAL_GATE

# Copy the gate signal to the CV jack
[copy]
    input = _T3_FINAL_GATE
    output = G1.3

# Names for the display
[switch]
    input1 = "a"
    input2 = "a a a c"
    input3 = "a a c c"
    offset = _T3_FORM
    output1 = _T3_FORM_NAME

# Display the name of 'Song form' when edited
[display]
    linger = 0.1
    header = "SONG FORM"
    text = _T3_FORM_NAME
    fontsize = 4

# Names for the display
[ifequal]
    input1 = _T3_12TONE
    input2 = 0
    ifequal = "diatonic"
    else = "chromatic"
    output = _T3_12TONE_NAME

# Display the name of 'Scale' when edited
[display]
    linger = 0.1
    header = "SCALE"
    text = _T3_12TONE_NAME
    fontsize = 2

# Show a message when _T3_CLEARSTARTEND triggers
[display]
    trigger = _T3_CLEARSTARTEND
    text = "Reset start/end"

# Show a message when _T3_PEACE triggers
[display]
    trigger = _T3_PEACE
    text = "Track 3 peace"

# Show a message when _T3_CLEAR triggers
[display]
    trigger = _T3_CLEAR
    text = "Track 3 cleared"

# Names for the display
[ifequal]
    input1 = _T3_ARP
    input2 = 0
    ifequal = "Sequencer"
    else = "Arpeggiator"
    output = _T3_ARP_NAME

# Display the name of '' when edited
[display]
    linger = 0.1
    header = ""
    text = _T3_ARP_NAME
    fontsize = 2

# -------------------------------------------------
# Track 4
# -------------------------------------------------

# Provide trigger when the clear button is pressed (no Ctrl needed)
[button]
    select = _SELECTED_TRACK
    selectat = 4
    button = B2.4
    shortpress = _T4_CLEAR_BUTTON
    states = 1

# Clear button with control together clears the track
[copy]
    input = _T4_CLEAR_BUTTON * _CONTROL
    output = _T4_CLEAR

# Clear button without control removes all mode that alter the pattern length
[logic]
    input1 = _T4_CLEAR_BUTTON
    input2 = -1 * _CONTROL + 1
    and = _T4_PEACE

# Five blinks for the clear LED
[burst]
    trigger = _T4_CLEAR + _FACTORY_RESET
    hz = 5
    count = 5
    output = _T4_CLEAR_LED

# LED only blinks when track is selected
[select]
    select = _SELECTED_TRACK
    selectat = 4
    input = _T4_CLEAR_LED + 0.3
    output = L2.4

# Reset track immediately
[button]
    select = _SELECTED_TRACK
    selectat = 4
    button = B2.11 * _NO_CONTROL
    states = 1
    output = _T4_RESET

# Show a message when _T4_RESET triggers
[display]
    trigger = _T4_RESET
    text = "Reset track 4"

# Button for copy and paste
[button]
    select = _SELECTED_TRACK
    selectat = 4
    button = B2.24
    states = 1
    output = _T4_COPY_BUTTON

# This button cycles between the song froms A, AAAB and AABB
[button]
    select = _SELECTED_TRACK
    selectat = 4
    clear = _T4_CLEAR
    loadpreset = _T4_LOAD_PRESET
    savepreset = _T4_SAVE_PRESET
    button = B2.7
    led = L2.7
    output = _T4_FORM
    states = 3

# Disables scale and note selection if on
[button]
    select = _SELECTED_TRACK
    selectat = 4
    loadpreset = _T4_LOAD_PRESET
    savepreset = _T4_SAVE_PRESET
    button = B2.8
    led = L2.8
    output = _T4_12TONE

# Enable transposing the melody by the difference of the root note to C
[button]
    select = _SELECTED_TRACK
    selectat = 4
    loadpreset = _T4_LOAD_PRESET
    savepreset = _T4_SAVE_PRESET
    button = B2.5
    led = L2.5
    output = _T4_TBR_ON
    inverted = _T4_TBR_OFF

# Provide the amount of 'transpose by root' in a patch cable
[ifequal]
    input1 = _T4_TBR_ON
    input2 = 1
    ifequal = _ROOT / 120
    output = _T4_TBR

# Names for the display
[ifequal]
    input1 = _T4_TBR_ON
    input2 = 0
    ifequal = "don't transpose"
    else = "transpose"
    output = _T4_TBR_ON_NAME

# Display the name of 'Transpose by root' when edited
[display]
    linger = 0.1
    header = "TRANSPOSE BY ROOT"
    text = _T4_TBR_ON_NAME
    fontsize = 2

# Hold to contiously step faders to random positions, hold with Ctrl to change buttons
[button]
    select = _SELECTED_TRACK
    selectat = 4
    button = B2.10
    states = 1
    onvalue = _LUCKY_CLOCK
    output = _T4_LUCKY

# Show a message when _T4_LUCKY * _NO_CONTROL triggers
[display]
    trigger = _T4_LUCKY * _NO_CONTROL
    text = "I feel lucky!"

# Show a message when _T4_LUCKY * _CONTROL triggers
[display]
    trigger = _T4_LUCKY * _CONTROL
    text = "Lucky gates!"

# Selects melodic inversion (swap low and high notes)
[button]
    select = _SELECTED_TRACK
    selectat = 4
    clear = _T4_CLEAR
    loadpreset = _T4_LOAD_PRESET
    savepreset = _T4_SAVE_PRESET
    button = B2.6
    led = L2.6
    output = _T4_INVERT

# Names for the display
[ifequal]
    input1 = _T4_INVERT
    input2 = 0
    ifequal = "don't invert"
    else = "invert pitches"
    output = _T4_INVERT_NAME

# Display the name of 'Pitch inversion' when edited
[display]
    linger = 0.1
    header = "PITCH INVERSION"
    text = _T4_INVERT_NAME
    fontsize = 2

# Combine all triggers for clearing
[mixer]
    input1 = _T4_CLEAR + _T4_PEACE
    input2 = _T4_BPAR_1
    output = _T4_CLEAR_PAR

# Reset track after X clock ticks
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T4_ARP_OFF
    selectat = 14
    loadpreset = _T4_LOAD_PRESET
    savepreset = _T4_SAVE_PRESET
    notches = 17
    startvalue = 0
    ledcolor = 0.8
    ledvalue = -0.3
    header = "AUTORESET"
    clear = _T4_CLEAR_PAR
    output = _T4_AUTORESET
    fader = 1
    button = _T4_BPAR_1

# Combine all triggers for clearing
[mixer]
    input1 = _T4_CLEAR + _T4_PEACE
    input2 = _T4_BPSS_1
    output = _T4_CLEAR_PSS

# Shift the steps of the sequence by this number
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T4_ARP_OFF
    selectat = 14
    loadpreset = _T4_LOAD_PRESET
    savepreset = _T4_SAVE_PRESET
    notches = 17
    startvalue = 0
    ledcolor = 0.6
    ledvalue = -0.3
    header = "SHIFT STEPS"
    clear = _T4_CLEAR_PSS
    output = _T4_SHIFTSTEPS
    fader = 2
    button = _T4_BPSS_1

# Combine all triggers for clearing
[mixer]
    input1 = _T4_CLEAR
    input2 = _T4_BPOCT_1 + _T4_BPOCT_2
    output = _T4_CLEAR_POCT

# Octave switch: -2, -1, 0, +1, +2
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T4_ARP_OFF
    selectat = 14
    loadpreset = _T4_LOAD_PRESET
    savepreset = _T4_SAVE_PRESET
    notches = 5
    startvalue = 2
    ledcolor = 0.2
    ledvalue = -0.3
    display = 0
    clear = _T4_CLEAR_POCT
    sharewithnext = 1
    fader = 3
    button = _T4_BPOCT_1

# Octave switch: -2, -1, 0, +1, +2
[motorfader]
    loadpreset = _T4_LOAD_PRESET
    savepreset = _T4_SAVE_PRESET
    notches = 5
    startvalue = 2
    ledcolor = 0.2
    ledvalue = -0.3
    display = 0
    clear = _T4_CLEAR_POCT
    select = _GLOBAL_FADER_SELECTION
    selectat = 98
    fader = 7
    button = _T4_BPOCT_2
    output = _T4_OCTAVE

# Names for the display
[switch]
    input1 = "2 down"
    input2 = "1 down"
    input3 = "no octaving"
    input4 = "1 up"
    input5 = "2 up"
    offset = _T4_OCTAVE
    output1 = _T4_OCTAVE_NAME

# Display the name of 'Octave switch' when edited
[display]
    linger = 0.1
    header = "OCTAVE SWITCH"
    text = _T4_OCTAVE_NAME
    fontsize = 2

# Combine all triggers for clearing
[mixer]
    input1 = _T4_CLEAR
    input2 = _T4_BPDT_1 + _T4_BPDT_2
    output = _T4_CLEAR_PDT

# Diatonic transposition
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T4_ARP_OFF
    selectat = 14
    loadpreset = _T4_LOAD_PRESET
    savepreset = _T4_SAVE_PRESET
    notches = 15
    startvalue = 7
    ledcolor = 0.4
    ledvalue = -0.3
    outputoffset = -7
    header = "DIATONIC TRANSPOSE"
    clear = _T4_CLEAR_PDT
    sharewithnext = 1
    fader = 4
    button = _T4_BPDT_1

# Diatonic transposition
[motorfader]
    loadpreset = _T4_LOAD_PRESET
    savepreset = _T4_SAVE_PRESET
    notches = 15
    startvalue = 7
    ledcolor = 0.4
    ledvalue = -0.3
    outputoffset = -7
    header = "DIATONIC TRANSPOSE"
    clear = _T4_CLEAR_PDT
    select = _GLOBAL_FADER_SELECTION
    selectat = 98
    fader = 8
    button = _T4_BPDT_2
    output = _T4_NOTESHIFT

# Prevent diatonic transposition from happending between clock ticks
[sample]
    input = _T4_NOTESHIFT
    sample = _CLOCK
    output = _T4_NOTESHIFT_CLOCKED

# Combine all triggers for clearing
[mixer]
    input1 = _T4_CLEAR
    input2 = _T4_BPACT_1
    output = _T4_CLEAR_PACT

# Minimum activity a step needs to have to be played
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T4_ARP_OFF
    selectat = 14
    loadpreset = _T4_LOAD_PRESET
    savepreset = _T4_SAVE_PRESET
    notches = 8
    startvalue = 0
    ledcolor = 0.55
    ledvalue = -0.3
    header = "ACTIVITY"
    clear = _T4_CLEAR_PACT
    output = _T4_ACTIVITY
    fader = 5
    button = _T4_BPACT_1

# Combine all triggers for clearing
[mixer]
    input1 = _T4_CLEAR + _T4_PEACE
    input2 = _T4_BPPAT_1
    output = _T4_CLEAR_PPAT

# Movement pattern: normal, reverse, ping pong, >><, 2><, etc.
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T4_ARP_OFF
    selectat = 14
    loadpreset = _T4_LOAD_PRESET
    savepreset = _T4_SAVE_PRESET
    notches = 10
    startvalue = 0
    ledcolor = 0.3
    ledvalue = -0.3
    display = 0
    clear = _T4_CLEAR_PPAT
    output = _T4_PATTERN_FADER
    fader = 6
    button = _T4_BPPAT_1

# Names for the display
[switch]
    input1 = "Mforward"
    input2 = "Mbackward"
    input3 = "Mping pong"
    input4 = "D=>  =>  <="
    input5 = "D==>  <="
    input6 = "D==>  <==  =>"
    input7 = "D==>  =>  <==  =>"
    input8 = "Mbrownian"
    input9 = "Mrandom skips"
    input10 = "Mrandom"
    offset = _T4_PATTERN_FADER
    output1 = _T4_PATTERN_FADER_NAME

# Display the name of 'Movement pattern' when edited
[display]
    linger = 0.1
    header = "MOVEMENT PATTERN"
    text = _T4_PATTERN_FADER_NAME
    fontsize = 5

# Set the direction to reverse on fader position 1
[ifequal]
    input1 = _T4_PATTERN_FADER
    input2 = 1
    ifequal = 1
    output = _T4_DIRECTION

# Enable ping pong on fader position 2
[ifequal]
    input1 = _T4_PATTERN_FADER
    input2 = 2
    ifequal = 1
    output = _T4_PINGPONG

# Combine all triggers for clearing
[mixer]
    input1 = _T4_CLEAR
    input2 = _T4_BPCDEVEN_1
    output = _T4_CLEAR_PCDEVEN

# Clock division for even divides/multipliers
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T4_ARP_OFF
    selectat = 14
    loadpreset = _T4_LOAD_PRESET
    savepreset = _T4_SAVE_PRESET
    notches = 7
    startvalue = 3
    ledcolor = 1.1
    ledvalue = -0.3
    display = 0
    clear = _T4_CLEAR_PCDEVEN
    output = _T4_CD_EVEN
    fader = 7
    button = _T4_BPCDEVEN_1

# Select the multiplier based on the fader position
[switch]
    input1 = 1
    input2 = 1
    input3 = 1
    input4 = 1
    input5 = 2
    input6 = 4
    input7 = 8
    offset = _T4_CD_EVEN
    output1 = _T4_CD_EVEN_MULT

# Select the division based on the fader position
[switch]
    input1 = 8
    input2 = 4
    input3 = 2
    input4 = 1
    input5 = 1
    input6 = 1
    input7 = 1
    offset = _T4_CD_EVEN
    output1 = _T4_CD_EVEN_DIV

# Combine all triggers for clearing
[mixer]
    input1 = _T4_CLEAR
    input2 = _T4_BPCDODD_1
    output = _T4_CLEAR_PCDODD

# Clock division for odd divides/multipliers
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T4_ARP_OFF
    selectat = 14
    loadpreset = _T4_LOAD_PRESET
    savepreset = _T4_SAVE_PRESET
    notches = 7
    startvalue = 3
    ledcolor = 1.2
    ledvalue = -0.3
    display = 0
    clear = _T4_CLEAR_PCDODD
    output = _T4_CD_ODD
    fader = 8
    button = _T4_BPCDODD_1

# Select the multiplier based on the fader position
[switch]
    input1 = 1
    input2 = 1
    input3 = 1
    input4 = 1
    input5 = 3
    input6 = 5
    input7 = 7
    offset = _T4_CD_ODD
    output1 = _T4_CD_ODD_MULT

# Select the division based on the fader position
[switch]
    input1 = 7
    input2 = 5
    input3 = 3
    input4 = 1
    input5 = 1
    input6 = 1
    input7 = 1
    offset = _T4_CD_ODD
    output1 = _T4_CD_ODD_DIV

# Names for the display
[switch]
    input1 = "DY  8"
    input2 = "DY  4"
    input3 = "DY  2"
    input4 = "Mno division"
    input5 = "DX  2"
    input6 = "DX  4"
    input7 = "DX  8"
    offset = _T4_CD_EVEN
    output1 = _T4_CD_EVEN_NAMES

# Display the name of 'Clock divider' when edited
[display]
    linger = 0.1
    header = "CLOCK DIVIDER"
    text = _T4_CD_EVEN_NAMES
    fontsize = 5

# Names for the display
[switch]
    input1 = "DY  7"
    input2 = "DY  5"
    input3 = "DY  3"
    input4 = "Mno division"
    input5 = "DX  3"
    input6 = "DX  5"
    input7 = "DX  7"
    offset = _T4_CD_ODD
    output1 = _T4_CD_ODD_NAMES

# Display the name of 'Clock divider' when edited
[display]
    linger = 0.1
    header = "CLOCK DIVIDER"
    text = _T4_CD_ODD_NAMES
    fontsize = 5

# Switch on/off arpeggio mode for track 4
[button]
    select = _SELECTED_TRACK
    selectat = 4
    button = B2.9
    clear = _T4_START_OF_SEQUENCE * _T4_ARP_AUTOSTOP
    output = _T4_ARP
    negated = _T4_ARP_OFF

# The LED of the ARP button blinks when it is on but in Autostop mode
[select]
    select = _SELECTED_TRACK
    selectat = 4
    input = _T4_ARP_AUTOSTOP * _ARP_AUTOSTOP_BLINK + _T4_ARP
    output = L2.9

# Autostop mode for ARP: When you hold CTRL while switching ARP on, it will automatically switch
# off the next time the sequence starts. This allows for easier jamming the ARP for doing fills.
[flipflop]
    set = B2.9 * _CONTROL
    reset = _T4_ARP_OFF
    output = _T4_ARP_AUTOSTOP

# Sync switching ARP on/off with clock in order to avoid audible glitches
[sample]
    input = _T4_ARP
    sample = _T4_CLOCK
    output = _T4_ARP_SYNCED

# Auto reset arpeggiator after N number of steps
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T4_ARP
    selectat = 14
    loadpreset = _T4_LOAD_PRESET
    savepreset = _T4_SAVE_PRESET
    fader = 1
    notches = 17
    ledcolor = 0.8
    ledvalue = 1
    output = _T4_ARP_AUTORESET
    header = "AUTORESET"

# Enable ping pong mode
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T4_ARP
    selectat = 14
    loadpreset = _T4_LOAD_PRESET
    savepreset = _T4_SAVE_PRESET
    fader = 2
    notches = 3
    ledcolor = 0.85
    ledvalue = 1
    output = _T4_ARP_DIRECTION

# Names for the display
[switch]
    input1 = "up"
    input2 = "up/down"
    input3 = "down"
    offset = _T4_ARP_DIRECTION
    output1 = _T4_ARP_DIRECTION_NAME

# Display the name of 'Direction' when edited
[display]
    linger = 0.1
    header = "DIRECTION"
    text = _T4_ARP_DIRECTION_NAME
    fontsize = 2

# Provide gate for reversed direction of arpeggio
[ifequal]
    input1 = _T4_ARP_DIRECTION
    input2 = 2
    ifequal = 1
    else = 0
    output = _T4_ARP_UPDOWN

# Provide gate for ping pong of arpeggio
[ifequal]
    input1 = _T4_ARP_DIRECTION
    input2 = 1
    ifequal = 1
    else = 0
    output = _T4_ARP_PINGPONG

# Seperate octave switch for the arpeggio
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T4_ARP
    selectat = 14
    loadpreset = _T4_LOAD_PRESET
    savepreset = _T4_SAVE_PRESET
    fader = 3
    notches = 5
    ledcolor = 0.2
    startvalue = 2
    ledvalue = 1
    output = _T4_ARP_OCTAVE_SWITCH

# Names for the display
[switch]
    input1 = "2 down"
    input2 = "1 down"
    input3 = "no octaving"
    input4 = "1 up"
    input5 = "2 up"
    offset = _T4_ARP_OCTAVE_SWITCH
    output1 = _T4_ARP_OCTAVE_SWITCH_NAME

# Display the name of 'Octave switch' when edited
[display]
    linger = 0.1
    header = "OCTAVE SWITCH"
    text = _T4_ARP_OCTAVE_SWITCH_NAME
    fontsize = 2

# Enable butterfly mode
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T4_ARP
    selectat = 14
    loadpreset = _T4_LOAD_PRESET
    savepreset = _T4_SAVE_PRESET
    fader = 4
    notches = 2
    ledcolor = 1.15
    ledvalue = 1
    output = _T4_ARP_BUTTERFLY

# Names for the display
[ifequal]
    input1 = _T4_ARP_BUTTERFLY
    input2 = 0
    ifequal = "off"
    else = "on"
    output = _T4_ARP_BUTTERFLY_NAME

# Display the name of 'Butterfly' when edited
[display]
    linger = 0.1
    header = "BUTTERFLY"
    text = _T4_ARP_BUTTERFLY_NAME
    fontsize = 2

# Select one of three octaving patterns
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T4_ARP
    selectat = 14
    loadpreset = _T4_LOAD_PRESET
    savepreset = _T4_SAVE_PRESET
    fader = 5
    notches = 3
    ledcolor = 0.4
    ledvalue = 1
    output = _T4_ARP_OCTAVING

# Names for the display
[switch]
    input1 = "off"
    input2 = "up"
    input3 = "down"
    offset = _T4_ARP_OCTAVING
    output1 = _T4_ARP_OCTAVING_NAME

# Display the name of 'Octaving' when edited
[display]
    linger = 0.1
    header = "OCTAVING"
    text = _T4_ARP_OCTAVING_NAME
    fontsize = 2

# Compute octave offset pitches from fader setting
[copy]
    input = _T4_ARP_OCTAVE_SWITCH * 1V - 2V
    output = _T4_ARP_OCTAVE

# Select the arpeggio pattern
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T4_ARP
    selectat = 14
    loadpreset = _T4_LOAD_PRESET
    savepreset = _T4_SAVE_PRESET
    fader = 6
    notches = 7
    ledcolor = 0.3
    ledvalue = 1
    output = _T4_ARP_PATTERN

# Names for the display
[switch]
    input1 = "D=>"
    input2 = "D=>  =>  <="
    input3 = "D==>  <="
    input4 = "D==>  <==  =>"
    input5 = "D==>  =>  <==  =>"
    input6 = "Mbrownian"
    input7 = "Mrandom"
    offset = _T4_ARP_PATTERN
    output1 = _T4_ARP_PATTERN_NAME

# Display the name of 'Movement pattern' when edited
[display]
    linger = 0.1
    header = "MOVEMENT PATTERN"
    text = _T4_ARP_PATTERN_NAME
    fontsize = 5

# Select one of four different drop patterns
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T4_ARP
    selectat = 14
    loadpreset = _T4_LOAD_PRESET
    savepreset = _T4_SAVE_PRESET
    fader = 7
    notches = 4
    ledcolor = 0.5
    ledvalue = 1
    output = _T4_ARP_DROP

# Names for the display
[switch]
    input1 = "* * * * * *"
    input2 = "* * o * * o"
    input3 = "* o * o * o"
    input4 = "* o o * o o"
    offset = _T4_ARP_DROP
    output1 = _T4_ARP_DROP_NAME

# Display the name of 'Play/skip notes' when edited
[display]
    linger = 0.1
    header = "PLAY/SKIP NOTES"
    text = _T4_ARP_DROP_NAME
    fontsize = 4

# Select one of several clocking patterns
[motorfader]
    select = _GLOBAL_FADER_SELECTION * _T4_ARP
    selectat = 14
    loadpreset = _T4_LOAD_PRESET
    savepreset = _T4_SAVE_PRESET
    fader = 8
    notches = 8
    ledcolor = 1.1
    ledvalue = 1
    output = _T4_ARP_CLOCKING

# Names for the display
[switch]
    input1 = "master clock"
    input2 = "sequencer"
    input3 = "clock x 3/2"
    input4 = "clock x 2"
    input5 = "clock x 3"
    input6 = "clock x 4"
    input7 = "clock x 6"
    input8 = "clock x 8"
    offset = _T4_ARP_CLOCKING
    output1 = _T4_ARP_CLOCKING_NAME

# Display the name of 'Arpeggio clocking' when edited
[display]
    linger = 0.1
    header = "ARPEGGIO CLOCKING"
    text = _T4_ARP_CLOCKING_NAME
    fontsize = 2

# Button for loading preset 1 on track 4
[button]
    select = _SELECTED_TRACK
    selectat = 4
    button = B2.1 * _CONTROL
    states = 1
    onvalue = 1
    output = _T4_P1_LOAD

# Button for saving preset 1 on track 4
[button]
    select = _SELECTED_TRACK
    selectat = 4
    button = B2.1
    states = 1
    onvalue = 1
    longpress = _T4_P1_SAVE

# Show a message when _T4_P1_LOAD triggers
[display]
    trigger = _T4_P1_LOAD
    text = "Preset 1 loaded"

# Show a message when _T4_P1_SAVE triggers
[display]
    trigger = _T4_P1_SAVE
    text = "Preset 1 saved"

# Five blinks for the LED of the preset button on saving
[burst]
    trigger = _T4_P1_SAVE
    hz = 5
    count = 5
    output = _T4_P1_SAVE_LED

# Write the save LED animation to the LED if the track is still selected.
[select]
    select = _SELECTED_TRACK
    selectat = 4
    input = _T4_P1_SAVE_LED + 0.3
    output = L2.1

# Button for loading preset 2 on track 4
[button]
    select = _SELECTED_TRACK
    selectat = 4
    button = B2.2 * _CONTROL
    states = 1
    onvalue = 2
    output = _T4_P2_LOAD

# Button for saving preset 2 on track 4
[button]
    select = _SELECTED_TRACK
    selectat = 4
    button = B2.2
    states = 1
    onvalue = 2
    longpress = _T4_P2_SAVE

# Show a message when _T4_P2_LOAD triggers
[display]
    trigger = _T4_P2_LOAD
    text = "Preset 2 loaded"

# Show a message when _T4_P2_SAVE triggers
[display]
    trigger = _T4_P2_SAVE
    text = "Preset 2 saved"

# Five blinks for the LED of the preset button on saving
[burst]
    trigger = _T4_P2_SAVE
    hz = 5
    count = 5
    output = _T4_P2_SAVE_LED

# Write the save LED animation to the LED if the track is still selected.
[select]
    select = _SELECTED_TRACK
    selectat = 4
    input = _T4_P2_SAVE_LED + 0.3
    output = L2.2

# Button for loading preset 3 on track 4
[button]
    select = _SELECTED_TRACK
    selectat = 4
    button = B2.3 * _CONTROL
    states = 1
    onvalue = 3
    output = _T4_P3_LOAD

# Button for saving preset 3 on track 4
[button]
    select = _SELECTED_TRACK
    selectat = 4
    button = B2.3
    states = 1
    onvalue = 3
    longpress = _T4_P3_SAVE

# Show a message when _T4_P3_LOAD triggers
[display]
    trigger = _T4_P3_LOAD
    text = "Preset 3 loaded"

# Show a message when _T4_P3_SAVE triggers
[display]
    trigger = _T4_P3_SAVE
    text = "Preset 3 saved"

# Five blinks for the LED of the preset button on saving
[burst]
    trigger = _T4_P3_SAVE
    hz = 5
    count = 5
    output = _T4_P3_SAVE_LED

# Write the save LED animation to the LED if the track is still selected.
[select]
    select = _SELECTED_TRACK
    selectat = 4
    input = _T4_P3_SAVE_LED + 0.3
    output = L2.3

# Create a trigger with the preset as value when any of the presets is loaded
[mixer]
    input1 = _T4_P1_LOAD
    input2 = _T4_P2_LOAD
    input3 = _T4_P3_LOAD
    output = _T4_LOAD_PRESET

# Create a trigger with the preset as value when any of the presets is saved
[mixer]
    input1 = _T4_P1_SAVE * 1
    input2 = _T4_P2_SAVE * 2
    input3 = _T4_P3_SAVE * 3
    output = _T4_SAVE_PRESET

# Select which notes from the current scale should be played
[buttongroup]
    select = _SELECTED_TRACK
    selectat = 4
    minactive = 1
    maxactive = _CONTROL * -6 + 7
    startbutton = -1
    button1 = B1.1
    led1 = L1.1
    buttonoutput1 = _T4_SEL_1
    button2 = B1.2
    led2 = L1.2
    buttonoutput2 = _T4_SEL_2
    button3 = B1.3
    led3 = L1.3
    buttonoutput3 = _T4_SEL_3
    button4 = B1.4
    led4 = L1.4
    buttonoutput4 = _T4_SEL_4
    button5 = B1.5
    led5 = L1.5
    buttonoutput5 = _T4_SEL_5
    button6 = B1.6
    led6 = L1.6
    buttonoutput6 = _T4_SEL_6
    button7 = B1.7
    led7 = L1.7
    buttonoutput7 = _T4_SEL_7

# Clock divider for track 4
[clocktool]
    clock = _CLOCK
    reset = _RESET
    divide = _T4_CD_EVEN_DIV * _T4_CD_ODD_DIV
    multiply = _T4_CD_EVEN_MULT * _T4_CD_ODD_MULT
    output = _T4_CLOCK

# Mix global and per-track diatonic transposition
[mixer]
    input1 = _T4_NOTESHIFT_CLOCKED
    input2 = _GLOBAL_NOTESHIFT_CLOCKED
    output = _T4_NOTESHIFT_SUM

# The clear range logic should just affect the current track
[ifequal]
    input1 = _SELECTED_TRACK * _RANGE
    input2 = 4
    ifequal = 1
    output = _T4_CLEAR_RANGE

# Collect different sources of resetting the start/end point
[logic]
    input1 = _T4_CLEAR + _T4_PEACE
    input2 = _T4_CLEAR_RANGE * _CONTROL
    or = _T4_CLEARSTARTEND

# Select encoder if track 4 is selected, arp is off and control is not held
[logic]
    input1 = _T4_SELECTED * _NO_CONTROL
    input2 = _T4_ARP_OFF
    and = _T4_ENC_1_SELECTED

# Note shift for each step repetition
[encoder]
    select = _T4_ENC_1_SELECTED
    encoder = 1
    header = "Repeat shift"
    color = 0.6
    discrete = 15
    startvalue = 7
    outputoffset = -7
    output = _T4_REPEATSHIFT

# Select encoder if track 4 is selected, arp is off and control is held
[logic]
    input1 = _T4_SELECTED * _CONTROL
    input2 = _T4_ARP_OFF
    and = _T4_ENC_2_SELECTED

# Note shift for each ratchet
[encoder]
    select = _T4_ENC_2_SELECTED
    encoder = 1
    header = "Ratchet shift"
    color = 0.8
    discrete = 15
    startvalue = 7
    outputoffset = -7
    output = _T4_RATCHETSHIFT

# Sequencer for pitch and gate of track 4
[motoquencer]
    select = _GLOBAL_FADER_SELECTION
    selectat = 4
    page = _PAGE
    stepcopy = _T4_COPY_BUTTON
    doublerange = _T4_COPY_BUTTON
    loadpreset = _T4_LOAD_PRESET
    savepreset = _T4_SAVE_PRESET
    clear = _T4_CLEAR
    select1 = _T4_SEL_1 + _T4_12TONE
    select3 = _T4_SEL_2 + _T4_12TONE
    select5 = _T4_SEL_3 + _T4_12TONE
    select7 = _T4_SEL_4 + _T4_12TONE
    select9 = _T4_SEL_5 + _T4_12TONE
    select11 = _T4_SEL_6 + _T4_12TONE
    select13 = _T4_SEL_7 + _T4_12TONE
    selectfill1 = _T4_12TONE
    selectfill2 = _T4_12TONE
    selectfill3 = _T4_12TONE
    selectfill4 = _T4_12TONE
    selectfill5 = _T4_12TONE
    degree = _DEGREE
    clock = _T4_CLOCK * _RUNNING
    taptempo = _T4_CLOCK
    reset = _RESET + _T4_RESET
    cv = _T4_PITCH
    cvrange = _T4_CVRANGE * 1V
    defaultgate = 0
    gate = _T4_SEQUENCER_GATE
    numfaders = 8
    numsteps = 16
    linktonext = 1
    autoreset = _T4_AUTORESET
    shiftsteps = _T4_SHIFTSTEPS
    pattern = -1 * 2 + _T4_PATTERN_FADER
    direction = _T4_DIRECTION
    pingpong = _T4_PINGPONG
    selectnoteshift = _T4_NOTESHIFT_SUM
    tuningmode = _TUNINGMODE
    tuningpitch = 1V
    bulkedit = _CONTROL
    constantlength = B2.18
    accumulatorrange = _T4_ACCU_RANGE
    root = _ROOT * _T4_TBR_OFF
    transpose = _T4_TBR
    luckybuttons = _T4_LUCKY * _CONTROL
    luckyfaders = _T4_LUCKY * _NO_CONTROL
    luckychance = 1 / 8
    luckyamount = 0.5 * _NO_CONTROL + 0.5
    luckyscope = 3
    fadermode = _FADERMODE
    mute = -1 * _RUNNING + 1
    form = _T4_FORM
    invert = _T4_INVERT
    gatelength = _T4_GATELENGTH
    buttonmode = _BUTTONMODE
    composemode = _COMPOSEMODE
    clearskips = _T4_CLEAR + _T4_PEACE
    clearrepeats = _T4_CLEAR + _T4_PEACE
    clearstartend = _T4_CLEARSTARTEND
    repeatshift = _T4_REPEATSHIFT
    ratchetshift = _T4_RATCHETSHIFT
    startofsequence = _T4_START_OF_SEQUENCE

# Sequencer for velocity
[motoquencer]
    select = _GLOBAL_FADER_SELECTION
    selectat = 4
    page = _PAGE
    stepcopy = _T4_COPY_BUTTON
    doublerange = _T4_COPY_BUTTON
    clear = _T4_CLEAR
    loadpreset = _T4_LOAD_PRESET
    savepreset = _T4_SAVE_PRESET
    cv = _T4_VELOCITY
    defaultcv = 5.5V
    cvbase = 1V
    cvrange = 9V
    quantize = 0
    cvname = "Velocity"
    bulkedit = _CONTROL
    linktonext = 1

# Copy velocity to CV output
[copy]
    input = _T4_VELOCITY
    output = O8

# Sequencer for gate length and glide
[motoquencer]
    select = _GLOBAL_FADER_SELECTION
    selectat = 4
    page = _PAGE
    stepcopy = _T4_COPY_BUTTON
    doublerange = _T4_COPY_BUTTON
    clear = _T4_CLEAR
    loadpreset = _T4_LOAD_PRESET
    savepreset = _T4_SAVE_PRESET
    cv = _T4_GATELENGTH
    cvbase = 0.05
    cvrange = 0.9
    defaultcv = 0.5
    defaultgate = 0
    quantize = 0
    buttoncolor = 0.5
    cvname = "Gate length"
    bulkedit = _CONTROL
    linktonext = 1
    gate = _T4_GLIDE
    gatename = "Glide"

# Sequencer for activity level per step
[motoquencer]
    select = _GLOBAL_FADER_SELECTION
    selectat = 4
    clear = _T4_CLEAR
    loadpreset = _T4_LOAD_PRESET
    savepreset = _T4_SAVE_PRESET
    cv = _T4_STEP_ACTIVITY
    quantize = 0
    defaultcv = 7
    cvname = "Activity"
    cvnotches = 8
    bulkedit = _CONTROL

# Silence the gate if the step does not reach the required activity
[compare]
    input = _T4_STEP_ACTIVITY
    compare = _T4_ACTIVITY
    ifless = 0
    else = _T4_SEQUENCER_GATE
    output = _T4_ACT_GATE

# Modulate gate length for gate output in arpeggiator mode
[gatetool]
    taptempo = _T4_ARP_TAPTEMPO
    gatelength = _T4_GATELENGTH
    inputgate = _T4_ARP_CLOCK
    outputgate = _T4_ARP_MODULATED_GATE

# Switch gate to arpeggiator if active
[ifequal]
    input1 = _T4_ARP_SYNCED
    input2 = 0
    ifequal = _T4_ACT_GATE
    else = _T4_ARP_MODULATED_GATE
    output = _T4_SWITCHED_GATE

# Logic for make the gate silent if the track is muted
[logic]
    input1 = -1 * _T4_MUTED + 1
    input2 = _T4_SWITCHED_GATE
    and = _T4_MUTED_GATE

# Select clock for arpeggiator of track 4. It is either the master clock or a multiplication
# of it, or the sequencer gate output.
[switch]
    input1 = _CLOCK
    input2 = _T4_SEQUENCER_GATE
    input3 = _CLOCK_3_2
    input4 = _CLOCK_2_1
    input5 = _CLOCK_3_1
    input6 = _CLOCK_4_1
    input7 = _CLOCK_6_1
    input8 = _CLOCK_8_1
    output1 = _T4_ARP_CLOCK
    offset = _T4_ARP_CLOCKING

# Create taptempo for arp clock to be used for gate length
[switch]
    input1 = _CLOCK
    input2 = _T4_CLOCK
    input3 = _CLOCK_3_2
    input4 = _CLOCK_2_1
    input5 = _CLOCK_3_1
    input6 = _CLOCK_4_1
    input7 = _CLOCK_6_1
    input8 = _CLOCK_8_1
    output1 = _T4_ARP_TAPTEMPO
    offset = _T4_ARP_CLOCKING * _T4_ARP

# Select encoder if track 4 is selected, arp is on and control is not held
[logic]
    input1 = _T4_SELECTED * _NO_CONTROL
    input2 = _T4_ARP
    and = _T4_ENC_3_SELECTED

# Encoder for base pitch of arpeggiator
[encoder]
    encoder = 1
    select = _T4_ENC_3_SELECTED
    header = "Arp base pitch"
    color = 0.2
    discrete = 37
    sensivity = 3
    output = _T4_ARP_PITCH

# Select encoder if track 4 is selected, arp is on and control is held
[logic]
    input1 = _T4_SELECTED * _CONTROL
    input2 = _T4_ARP
    and = _T4_ENC_4_SELECTED

# Encoder for pitch range of arpeggiator
[encoder]
    encoder = 1
    select = _T4_ENC_4_SELECTED
    header = "Arp pitch range"
    color = 0.4
    discrete = 49
    startvalue = 24
    sensivity = 4
    output = _T4_ARP_RANGE

# Arpeggiator for track 4
[arpeggio]
    select1 = _T4_SEL_1
    select3 = _T4_SEL_2
    select5 = _T4_SEL_3
    select7 = _T4_SEL_4
    select9 = _T4_SEL_5
    select11 = _T4_SEL_6
    select13 = _T4_SEL_7
    selectfill1 = 0
    selectfill2 = 0
    selectfill3 = 0
    selectfill4 = 0
    selectfill5 = 0
    root = _ROOT * _T4_TBR_OFF
    transpose = _T4_TBR
    degree = _DEGREE
    clock = _T4_ARP_CLOCK * _RUNNING
    reset = _RESET
    tuningmode = _TUNINGMODE
    direction = _T4_ARP_UPDOWN
    pingpong = _T4_ARP_PINGPONG
    butterfly = _T4_ARP_BUTTERFLY
    octaves = _T4_ARP_OCTAVING
    drop = _T4_ARP_DROP
    pattern = _T4_ARP_PATTERN
    autoreset = _T4_ARP_AUTORESET
    pitch = _T4_ARP_PITCH / 120
    range = _T4_ARP_RANGE / 120
    output = _T4_ARP_OUTPUT

# Switch pitch output between sequencer and arpeggiator
[ifequal]
    input1 = _T4_ARP_SYNCED
    input2 = 0
    ifequal = _T4_PITCH
    else = _T4_ARP_OUTPUT + _T4_ARP_OCTAVE
    output = _T4_SWITCHED_PITCH

# Mix all sources of pitch together
[mixer]
    input1 = _T4_OCTAVE * 1V - 2V
    input2 = _T4_SWITCHED_PITCH
    input3 = _GLOBAL_OCTAVE_SWITCH * 1V - 2V
    input4 = _GLOBAL_TRANSPOSITION * 0.00833333
    output = _T4_FINAL_PITCH

# Slew limiter for glides
[slew]
    input = _T4_FINAL_PITCH
    exponential = O7
    slew = _T4_GLIDE * _T4_GLIDE_LENGTH

# If we are in compose mode and the arpeggiator is switched off, the gate is output even if
# the sequencer is stopped.
[ifequal]
    input1 = _T4_ARP
    input2 = 0
    ifequal = _RUNNING + _COMPOSEMODE
    else = _RUNNING
    output = _RUNNING_OR_COMPOSE_4

# Copy the gate to its final destination
[copy]
    input = _T4_MUTED_GATE * _RUNNING_OR_COMPOSE_4
    output = _T4_FINAL_GATE

# Copy the gate signal to the CV jack
[copy]
    input = _T4_FINAL_GATE
    output = G1.4

# Names for the display
[switch]
    input1 = "a"
    input2 = "a a a c"
    input3 = "a a c c"
    offset = _T4_FORM
    output1 = _T4_FORM_NAME

# Display the name of 'Song form' when edited
[display]
    linger = 0.1
    header = "SONG FORM"
    text = _T4_FORM_NAME
    fontsize = 4

# Names for the display
[ifequal]
    input1 = _T4_12TONE
    input2 = 0
    ifequal = "diatonic"
    else = "chromatic"
    output = _T4_12TONE_NAME

# Display the name of 'Scale' when edited
[display]
    linger = 0.1
    header = "SCALE"
    text = _T4_12TONE_NAME
    fontsize = 2

# Show a message when _T4_CLEARSTARTEND triggers
[display]
    trigger = _T4_CLEARSTARTEND
    text = "Reset start/end"

# Show a message when _T4_PEACE triggers
[display]
    trigger = _T4_PEACE
    text = "Track 4 peace"

# Show a message when _T4_CLEAR triggers
[display]
    trigger = _T4_CLEAR
    text = "Track 4 cleared"

# Names for the display
[ifequal]
    input1 = _T4_ARP
    input2 = 0
    ifequal = "Sequencer"
    else = "Arpeggiator"
    output = _T4_ARP_NAME

# Display the name of '' when edited
[display]
    linger = 0.1
    header = ""
    text = _T4_ARP_NAME
    fontsize = 2

# -------------------------------------------------
# MIDI Output
# -------------------------------------------------

# MIDI output for track 1
[midiout]
    trs = 1
    velocity1 = _T1_VELOCITY
    channel = 1
    pitch1 = _T1_FINAL_PITCH
    gate1 = _T1_FINAL_GATE
    activesensing = 0

# MIDI output for track 2
[midiout]
    trs = 2
    velocity1 = _T2_VELOCITY
    channel = 2
    pitch1 = _T2_FINAL_PITCH
    gate1 = _T2_FINAL_GATE
    activesensing = 0

# MIDI output for track 3
[midiout]
    usb = 1
    velocity1 = _T3_VELOCITY
    channel = 3
    pitch1 = _T3_FINAL_PITCH
    gate1 = _T3_FINAL_GATE
    activesensing = 0

# MIDI output for track 4
[midiout]
    usb = 1
    velocity1 = _T4_VELOCITY
    channel = 4
    pitch1 = _T4_FINAL_PITCH
    gate1 = _T4_FINAL_GATE
    activesensing = 0

# Show a message when _RESET_BUTTON triggers
[display]
    trigger = _RESET_BUTTON
    text = "Reset sequencer"

# Show a message when _FACTORY_RESET triggers
[display]
    trigger = _FACTORY_RESET
    text = "Factory reset!"
