# DROID example patch
# Library: number=1, version=1.0

# This example DROID patch implements a little melody sequencer with various
# useful patch points. The melody's pitch is quantized to a C minor scale and is
# output at O4. At O5 and O6 you get two further pitch outputs that are a couple
# of semitones higher. Together O4, O5 and O6 form a triad.
#
# At O7 you get stepped random voltages and at O8 you get these quantized
# to C minor.
#
# This patch works without any controller, but if you attach one,
# you get some additional control. The 8 buttons toggle the 8 steps
# of the melody. Knob 1 changes the speed of the LFO and knob 2 selects
# one out of 10 different melodies.
#
# INPUTS
#   I1: [CLK] optional external clock input
#   I2: [RST] reset input for sequencer
#   I3: [TRG] trigger for the envelope
#   I4:
#   I5: [D/R] decay/release timing
#   I6: [CHM] trigger to change the melody
#   I7: [QIN] input for O8-quantizer
#   I8: [TRA] trigger for random voltages
#
#
# OUTPUTS
#   O1: [CLK] Internal master clock
#   O2: [GAT] Sequencer gate output
#   O3: [ENV] Envelope output
#   O4: [PIT] Pitch, quantized to C minor
#   O5: [PI2] Same a some semitones higher
#   O6: [PI3] Same more semitones higher
#   O7: [RAN] Stepped random voltages
#   O8: [RAC] Same at O7, quantized to C minor
#
# CONTROLLER 1
#   P1.1: [SPE] Speed of the internal master clock
#   P1.2: [MEL] Select one out of 10 melodies
#   B1.1: [1] sequencer step 1
#   B1.2: [2] sequencer step 2
#   B1.3: [3] sequencer step 3
#   B1.4: [4] sequencer step 4
#   B1.5: [5] sequencer step 5
#   B1.6: [6] sequencer step 6
#   B1.7: [7] sequencer step 7
#   B1.8: [8] sequencer step 8
#

[p2b8]

# LFO used as internal master clock. Note: P1.1 will be 0.0, if
# no P2B8 is attached, so we *substract* it, so the patch will
# work without a controller as well.
[lfo]
    hz =  -8 * P1.1 + 8
    square = O1

# By sending the internal clock (available at O1) to N1, the input
# I1 will be normalized to that signal (Nx is the normalization of Ix).
# So If nothing is patched into I1, the sequencer will use the internal
# clock. If you patch something into I1, that will be used as clock
# instead.
[copy]
    input = O1
    output = N1 # "normalized" (i.e. unpatched) signal of I1

# Algoquencer here creates random 8-step melodies, that repeat over
# and over. If you do not like the melody, a trigger to I6 will switch
# to another pattern. Or you turn the second knob on your first controller
# (P1.2). The pitch output is unquantized and is sent to the internal
# patch cable _UNQUANTIZED_PITCH.
[algoquencer]
    clock = I1
    reset = I2
    nextpattern = I6
    length = 8
    gate = O2
    pitch = _UNQUANTIZED_PITCH
    pattern = P1.2 * 10
    button1 = B1.1
    button2 = B1.2
    button3 = B1.3
    button4 = B1.4
    button5 = B1.5
    button6 = B1.6
    button7 = B1.7
    button8 = B1.8
    led1 = L1.1
    led2 = L1.2
    led3 = L1.3
    led4 = L1.4
    led5 = L1.5
    led6 = L1.6
    led7 = L1.7
    led8 = L1.8

# Use sequencer gate output as the normalization for I3, which is
# the envelope trigger. If you patch something into I3 you can use
# envelope independent of the sequencer.
[copy]
    input = O2
    output = N3

# Input I5 controls the timing of decay and release of the envelope.
# We normalize it to 0.5, so when it is not patched, half of the
# decay/release is being used.
[copy]
    input = 0.5
    output = N5

# This is an envelope generator. Attack and sustain are fixed
# values. Decay and release can be voltage controlled. At output O3
# the envelope is available for patching into a filter or VCA.
[contour]
    gate = I3
    attack = 0.01
    decay = I5
    sustain = 0.2
    release = I5
    output = O3
    level = 5V

# Quantize the random output of the sequencer into a C minor
# scale, so that it will sound musically "right". Patch this
# to the 1V/Octave input of a VCO or another synth voice.
[minifonion]
    input = _UNQUANTIZED_PITCH
    root = 0 # C
    degree = 7 # natural minor
    output = O4

# We create a copy of the melody just a couple of notes
# higher, again quantized to C minor. This is done by adding
# 0.3V to the pitch output of the sequencer.
[minifonion]
    input = _UNQUANTIZED_PITCH + 0.3V
    root = 0 # C
    degree = 7 # natural minor
    output = O5

# Same again for the third note, this time with 0.6V
[minifonion]
    input = _UNQUANTIZED_PITCH + 0.6V
    root = 0 # C
    degree = 7 # natural minor
    output = O6


# Use the internal clock as normalization for the trigger input
# for some random voltages, so each time a clock happens a new
# voltage is being choosen. If you patch something into I8, that
# signal overrides the internal clock.
[copy]
    input = O1
    output = N8

[random]
    clock = I8
    minimum = 0
    maximum = 1
    output = O7

# Use random voltages as the normalization for the quantizer input
# of the extra quantizer on O8, while scaling down the range of
# 10 octaves into musically more useful 3 octaves.
[copy]
    input = O7 * 0.3 # Scale down the range
    output = N7

# Quantize the random voltages (or an external signal patched into I7)
# into the same C minor scale as the other three voices.
[minifonion]
    input = I7
    root = 0 # C
    degree = 7 # natural minor
    output = O8
