# Melody sequencer with 1 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

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

# CONTROLLER 1:
#  P1.1: [REPEAT] Repeat note shift
#  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.4: [CLR] Short press: reset play mode, with CTRL: clear track, long press factory reset
#  B2.6: [INV] Invert the melody (change low to high and vice versa)
#  B2.8: [CHRO] Disable scale and note selection, allow all 12 notes
#  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.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.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: [9 - 16] Select second page of steps
#  B2.29: [Mute] Mute the gate outputs

[p2b8]
[b32]
[m4]
[m4]

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

# 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

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

# Select the color for the scale fader
[multicompare]
    input = _DEGREE
    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 = _LED_GLOBAL_OCTAVE
    output = _GLOBAL_OCTAVE_SWITCH
    button = _RESET_OCTAVE_SWITCH
    clear = _RESET_OCTAVE_SWITCH

# Make the LED just a bit brighter if the switch is at neutral position
[compare]
    input = _GLOBAL_OCTAVE_SWITCH
    compare = 2
    ifequal = 1
    else = 0.3
    output = _LED_GLOBAL_OCTAVE

# Global diatonic transposition for all tracks
[motorfader]
    select = _GLOBAL_FADER_SELECTION
    selectat = 97
    fader = 4
    notches = 15
    startvalue = 7
    ledcolor = 0.4
    ledvalue = _LED_GLOBAL_NOTESHIFT
    output = _GLOBAL_NOTESHIFT
    button = _RESET_NOTESHIFT
    clear = _RESET_NOTESHIFT

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

# Make the LED just a bit brighter if the switch is at neutral position
[compare]
    input = _GLOBAL_NOTESHIFT
    compare = 7
    ifequal = 1
    else = 0.3
    output = _LED_GLOBAL_NOTESHIFT

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

# Make the LED just a bit brighter if the switch is at neutral position
[compare]
    input = _GLOBAL_TRANSPOSITION
    compare = 12
    ifequal = 1
    else = 0.3
    output = _LED_GLOBAL_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

# 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
    selectat = 97
    fader = 7
    startvalue = 0.3
    ledcolor = 0.5
    ledvalue = 1
    output = _T1_GLIDE_LENGTH_FADER

# 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
    selectat = 97
    fader = 8
    notches = 6
    startvalue = 1
    ledcolor = 0.65
    ledvalue = _TUNING_LED + 0.3
    output = _T1_CVRANGE

# -------------------------------------------------
# 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

# 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

# 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

# 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

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

# Let the LED light bright if the bending alteration is exactly zero.
[compare]
    input = _CLOCK_BEND
    compare = 0.5
    precision = 0
    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_UNMUTED

# 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

# Small hack for letting the user toggle the state with the touch button
[switch]
    input1 = -1 * _INT_CLOCK_UNMUTED + 1
    input2 = 1
    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 = _CLOCK_MUTE_STARTVALUE
    ledcolor = _INT_CLOCK_UNMUTED * -0.4 + 0.8
    ledvalue = 1

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

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

# 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

# Convert BPM (beat = quarter note) to 16th note clock measured in Hz
[copy]
    input = _CLOCK_BPM / 15
    output = _CLOCK_HZ

# The actual clock, use a very short pulse so we have essentially just triggers
[lfo]
    hz = _CLOCK_HZ * _CLOCK_BEND_LINEAR
    rate = _CLOCK_BEND_EXP * 1V
    pulsewidth = 0.1
    square = _CLOCK_UNSWUNG

# Swing for our internal clock
[timing]
    clock = _CLOCK_UNSWUNG
    reset = _RESET
    timing1 = 0
    timing2 = _CLOCK_SWING * 0.3
    output = _INT_CLOCK

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

# Get clock via MIDI TRS jack port 1
[midiin]
    trs = 1
    clock = _TRS1_CLOCK

# Detect a clock signal, if within the last 2 seconds there is a pulse
[gatetool]
    inputtrigger = _TRS1_CLOCK
    gatelength = 2
    outputgate = _TRS1_CLOCK_PRESENT

# Get clock via MIDI TRS jack port 2
[midiin]
    trs = 2
    clock = _TRS2_CLOCK

# Detect a clock signal, if within the last 2 seconds there is a pulse
[gatetool]
    inputtrigger = _TRS2_CLOCK
    gatelength = 2
    outputgate = _TRS2_CLOCK_PRESENT

# Get clock via MIDI USB jack port 1
[midiin]
    usb = 1
    clock = _USB1_CLOCK

# Detect a clock signal, if within the last 2 seconds there is a pulse
[gatetool]
    inputtrigger = _USB1_CLOCK
    gatelength = 2
    outputgate = _USB1_CLOCK_PRESENT

# Select first avaiable clock in defined precedence order
[case]
    case1 = _INT_CLOCK_UNMUTED
    value1 = _INT_CLOCK
    case2 = _EXTERNAL_CLOCK_PRESENT
    value2 = I1
    case3 = _TRS1_CLOCK_PRESENT
    value3 = _TRS1_CLOCK
    case4 = _TRS2_CLOCK_PRESENT
    value4 = _TRS2_CLOCK
    case5 = _USB1_CLOCK_PRESENT
    value5 = _USB1_CLOCK
    output = _CLOCK

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

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

# Mute the gate outputs
[button]
    button = B2.29
    led = L2.29
    output = _T1_MUTED

# -------------------------------------------------
# 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 = 1 + 10
    button4 = B2.16
    led4 = L2.16
    value4 = 98
    clear = _FADERMODE_CHANGED
    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.
[compare]
    input = _GLOBAL_MENU
    compare = 0
    ifequal = 1
    else = _GLOBAL_MENU
    output = _GLOBAL_FADER_SELECTION

# 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

# 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.27
    led5 = L2.27
    value5 = 20
    buttonpress = _FADERMODE_CHANGED
    output = _FADERMODE

# 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
[compare]
    input = _RANGE
    compare = 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
    output = _RESET

# Button for run/stop
[button]
    led = L2.12
    output = _RUNNING
    button = B2.12
    startvalue = 1

# 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
    led = L2.28
    output = _PAGE

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

# Provide trigger when the clear button is pressed (no Ctrl needed)
[button]
    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]
    input = _T1_CLEAR_LED + 0.3
    output = L2.4

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

# Button for copying the current page of the current track
[button]
    button = B2.24
    states = 1
    output = _T1_COPY_BUTTON

# Disables scale and note selection if on
[button]
    button = B2.8
    led = L2.8
    output = _T1_12TONE

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

# Selects melodic inversion (swap low and high notes)
[button]
    clear = _T1_CLEAR
    button = B2.6
    led = L2.6
    output = _T1_INVERT

# Make LED brighter if the fader is in its default position
[compare]
    input = _T1_AUTORESET
    compare = 0
    ifequal = 1
    else = 0.3
    output = _T1_AUTORESET_LED

# 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
    selectat = 11
    notches = 17
    startvalue = 0
    ledcolor = 0.8
    ledvalue = _T1_AUTORESET_LED
    clear = _T1_CLEAR_PAR
    output = _T1_AUTORESET
    fader = 1
    button = _T1_BPAR_1

# Make LED brighter if the fader is in its default position
[compare]
    input = _T1_SHIFTSTEPS
    compare = 0
    ifequal = 1
    else = 0.3
    output = _T1_SHIFTSTEPS_LED

# 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
    selectat = 11
    notches = 17
    startvalue = 0
    ledcolor = 0.6
    ledvalue = _T1_SHIFTSTEPS_LED
    clear = _T1_CLEAR_PSS
    output = _T1_SHIFTSTEPS
    fader = 2
    button = _T1_BPSS_1

# Make LED brighter if the fader is in its default position
[compare]
    input = _T1_OCTAVE
    compare = 2
    ifequal = 1
    else = 0.3
    output = _T1_OCTAVE_LED

# 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
    selectat = 11
    notches = 5
    startvalue = 2
    ledcolor = 0.2
    ledvalue = _T1_OCTAVE_LED
    clear = _T1_CLEAR_POCT
    sharewithnext = 1
    fader = 3
    button = _T1_BPOCT_1

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

# Make LED brighter if the fader is in its default position
[compare]
    input = _T1_NOTESHIFT
    compare = 7
    ifequal = 1
    else = 0.3
    output = _T1_NOTESHIFT_LED

# 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
    selectat = 11
    notches = 15
    startvalue = 7
    ledcolor = 0.4
    ledvalue = _T1_NOTESHIFT_LED
    clear = _T1_CLEAR_PDT
    sharewithnext = 1
    fader = 4
    button = _T1_BPDT_1

# Diatonic transposition
[motorfader]
    notches = 15
    startvalue = 7
    ledcolor = 0.4
    ledvalue = _T1_NOTESHIFT_LED
    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

# Disable this unused fader
[unusedfaders]
    select = _GLOBAL_FADER_SELECTION
    selectat = 11
    firstfader = 5

# Make LED brighter if the fader is in its default position
[compare]
    input = _T1_PATTERN_FADER
    compare = 0
    ifequal = 1
    else = 0.3
    output = _T1_PATTERN_FADER_LED

# 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
    selectat = 11
    notches = 10
    startvalue = 0
    ledcolor = 0.3
    ledvalue = _T1_PATTERN_FADER_LED
    clear = _T1_CLEAR_PPAT
    output = _T1_PATTERN_FADER
    fader = 6
    button = _T1_BPPAT_1

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

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

# Make LED brighter if the fader is in its default position
[compare]
    input = _T1_CD_EVEN
    compare = 3
    ifequal = 1
    else = 0.3
    output = _T1_CD_EVEN_LED

# 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
    selectat = 11
    notches = 7
    startvalue = 3
    ledcolor = 1.1
    ledvalue = _T1_CD_EVEN_LED
    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

# Make LED brighter if the fader is in its default position
[compare]
    input = _T1_CD_ODD
    compare = 3
    ifequal = 1
    else = 0.3
    output = _T1_CD_ODD_LED

# 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
    selectat = 11
    notches = 7
    startvalue = 3
    ledcolor = 1.2
    ledvalue = _T1_CD_ODD_LED
    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

# Select interval note 1 from the current scale
[button]
    button = B1.1
    led = L1.1
    startvalue = 1
    output = _T1_SEL_1

# Select interval note 2 from the current scale
[button]
    button = B1.2
    led = L1.2
    startvalue = 1
    output = _T1_SEL_2

# Select interval note 3 from the current scale
[button]
    button = B1.3
    led = L1.3
    startvalue = 1
    output = _T1_SEL_3

# Select interval note 4 from the current scale
[button]
    button = B1.4
    led = L1.4
    startvalue = 1
    output = _T1_SEL_4

# Select interval note 5 from the current scale
[button]
    button = B1.5
    led = L1.5
    startvalue = 1
    output = _T1_SEL_5

# Select interval note 6 from the current scale
[button]
    button = B1.6
    led = L1.6
    startvalue = 1
    output = _T1_SEL_6

# Select interval note 7 from the current scale
[button]
    button = B1.7
    led = L1.7
    startvalue = 1
    output = _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 = -1 * 7 + _T1_NOTESHIFT_CLOCKED
    input2 = -1 * 7 + _GLOBAL_NOTESHIFT_CLOCKED
    output = _T1_NOTESHIFT_SUM

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

# Note shift for each step repetition
[pot]
    pot = P1.1
    discrete = 15
    startvalue = 7
    output = _T1_REPEATSHIFT

# Sequencer for pitch and gate of track 1
[motoquencer]
    select = _GLOBAL_FADER_SELECTION
    selectat = 1
    page = _PAGE
    copy = _T1_COPY_BUTTON * _NO_CONTROL
    paste = _T1_COPY_BUTTON * _CONTROL
    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 + 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 = _GLOBAL_OCTAVE_SWITCH * 1V
    root = _ROOT
    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
    invert = _T1_INVERT
    buttonmode = _BUTTONMODE
    composemode = _COMPOSEMODE
    clearskips = _T1_CLEAR + _T1_PEACE
    clearrepeats = _T1_CLEAR + _T1_PEACE
    clearstartend = _T1_CLEARSTARTEND
    repeatshift = -1 * 7 + _T1_REPEATSHIFT

# Sequencer for velocity
[motoquencer]
    select = _GLOBAL_FADER_SELECTION
    selectat = 1
    page = _PAGE
    copy = _T1_COPY_BUTTON * _NO_CONTROL
    paste = _T1_COPY_BUTTON * _CONTROL
    clear = _T1_CLEAR
    cv = _T1_VELOCITY
    cvrange = 1
    defaultcv = 0.5
    quantize = 0
    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
    copy = _T1_COPY_BUTTON * _NO_CONTROL
    paste = _T1_COPY_BUTTON * _CONTROL
    clear = _T1_CLEAR
    cv = _T1_GATELENGTH
    cvrange = 1
    defaultcv = 0.5
    defaultgate = 0
    quantize = 0
    buttoncolor = 0.5
    linktonext = 0
    gate = _T1_GLIDE

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

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

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

# Compute gate length for arpeggiator output
[gatetool]
    taptempo = _T1_CLOCK
    inputgate = _T1_MUTED_GATE * _RUNNING
    outputgate = _T1_FINAL_GATE
    gatelength = _T1_GATELENGTH * 0.9 + 0.05

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

# Disable faders that are not in use
[unusedfaders]
    select = _GLOBAL_FADER_SELECTION
    selectat = 98
    firstfader = 3
    numfaders = 6

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

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