[p2b8]
[p2b8]

# Arpeggiator with two P2B8s
# LIBRARY: number=2, version=1.0

# The arpeggiator is an algorithmic melody generator. Usually there
# is no randomization but several algorithms, which can be combined
# in order to create complex and interesting patterns.
# This version uses two P2B8s and add a scale note selection and
# two knobs for selecting the output pitch range.

# All four pots have two functions. You can switch between the two
# layers A and B with the button B1.7


# INPUTS
# I1: [CLK] optional external clock

# OUTPUTS
# O1: [CLK] internal clock
# O3: [ENV] envelope
# O4: [V/O] pitch (V/oct)


# CONTROLLER 1
# P1.1: [S/A] A: Clock speed       | B: Envelope attack
# P1.2: [PaR] A: Arpeggio pattern  | B: Envelope release
# B1.1: [DIR] Arpeggio direction up / down
# B1.2: [PNG] Arpeggio pingpong
# B1.3: [FLY] Arpeggio butterfly
# B1.4: [OCT] Arpeggio octaves off / up / down
# B1.5: [DRP] Arpeggio drop off / x. / xx. / x..
# B1.6: [STA] Arpeggio startnote off / root / 3rd / 5th
# B1.7: [A/B] Switch pot layer A / B
# B1.8: [MIN] Arpeggio minor / major

# CONTROLLER 2
# P2.1: [RaS] A: pitch range       | B: Envelope sustain
# P2.2: [PiR] A: base pitch        | B: Root note
# B2.1: [1]   select root
# B2.2: [3]   select 3rd
# B2.3: [5]   select 5th
# B2.4: [7]   select 7th
# B2.5: [9]   select 9th
# B2.6: [11]  select 11th
# B2.7: [13]  select 13th
# B2.8: [FIL] select fill1 ... fill5



# -------------------------------------------------------------
# MASTER CLOCK
# -------------------------------------------------------------

# Send the clock the the normalization of input 1. In the
# rest of the patch I1 will be used as input, and you can
# override the internal clock by patching an external in.

[lfo]
    hz = 40 * _P_SPEED
    square = N1

# Make the clock also available on O1
[copy]
    input = N1
    output = O1

# -------------------------------------------------------------
# SWITCHED POTS
# -------------------------------------------------------------
[button]
    button = B1.7
    led = L1.7
    onvalue = 1
    offvalue = 0
    output = _LAYER_B
    inverted = _LAYER_A


[switchedpot]
    pot = P1.1
    switch1 = _LAYER_A
    switch2 = _LAYER_B
    output1 = _P_SPEED
    output2 = _P_ATTACK

[switchedpot]
    pot = P1.2
    switch1 = _LAYER_A
    switch2 = _LAYER_B
    output1 = _P_PATTERN
    output2 = _P_RELEASE

[switchedpot]
    pot = P2.1
    switch1 = _LAYER_A
    switch2 = _LAYER_B
    output1 = _P_RANGE
    output2 = _P_SUSTAIN

[switchedpot]
    pot = P2.2
    switch1 = _LAYER_A
    switch2 = _LAYER_B
    output1 = _P_PITCH
    output2 = _P_ROOT



# -------------------------------------------------------------
# ALGORITHMS
# -------------------------------------------------------------

[button]
    button = B1.1
    led = L1.1
    output = _DIRECTION

[button]
    button = B1.2
    led = L1.2
    output = _PINGPONG

[button]
    button = B1.3
    led = L1.3
    output = _BUTTERFLY

[button]
    button = B1.4
    led = L1.4
    value1 = 0
    value2 = 1
    value3 = 2
    output = _OCTAVES

[button]
    button = B1.5
    led = L1.5
    value1 = 0
    value2 = 1
    value3 = 2
    value4 = 3
    output = _DROP

[button]
    button = B1.6
    led = L1.6
    value1 = 0
    value2 = 1
    value3 = 2
    value4 = 3
    output = _STARTNOTE

[button]
    button = B1.8
    led = L1.8
    offvalue = 7 # minor
    onvalue = 1 # major
    output = _DEGREE

# -------------------------------------------------------------
# SCALE NOTES
# -------------------------------------------------------------


[button]
    button = B2.1
    led = L2.1

[button]
    button = B2.2
    led = L2.2

[button]
    button = B2.3
    led = L2.3

[button]
    button = B2.4
    led = L2.4

[button]
    button = B2.5
    led = L2.5

[button]
    button = B2.6
    led = L2.6

[button]
    button = B2.7
    led = L2.7

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

[arpeggio]
    clock       = I1
    direction   = _DIRECTION
    pingpong    = _PINGPONG
    butterfly   = _BUTTERFLY
    octaves     = _OCTAVES
    drop        = _DROP
    startnote   = _STARTNOTE
    pattern     = _P_PATTERN * 6
    pitch       = _P_PITCH * 6V - 2V
    range       = _P_RANGE * 8V
    root        = _P_ROOT * 12
    degree      = _DEGREE
    select1     = L2.1
    select3     = L2.2
    select5     = L2.3
    select7     = L2.4
    select9     = L2.5
    select11    = L2.6
    select13    = L2.7
    selectfilL1 = L2.8
    selectfill2 = L2.8
    selectfill3 = L2.8
    selectfill4 = L2.8
    selectfill5 = L2.8
    output      = O4

# -------------------------------------------------------------
# ENVELOPE
# -------------------------------------------------------------

[contour]
    gate    = I1
    attack  = _P_ATTACK
    release = _P_RELEASE
    decay   = _P_RELEASE
    sustain = _P_SUSTAIN
    output  = O3


