sequ
Prev | Orchestra Opcodes and Operators | Next

## sequ

sequ — Emulate a hardware sequencer

## Description

Uses a collection of arrays to generate a sequence of events with variable tempo that can be played in forward, reverse, back and forth, and random directions. The max length of the arrays is 128, and it can be scaled dynamically. Permutational playback modes feature randomisation, probability and other algorithms.

## Syntax

    kres  sequ  irhythm[], iinstr[], idata[], kbpm, klen [, kmode] [, kstep] [, kreset] [, kverbose]

    kres  sequ  irhythm[], iinstr[],
        idata[][], kbpm, klen [, kmode] [, kstep] [, kreset] [, kverbose]

## Initialization

irhythm - array of durations in beats. The actual duration is determined by these values divided by the current BPM.

iinstr - array of instrument numbers scheduled per step. An instrument number zero does nothing. It skips the note associated with the step and produces a silence for that note's duration.

idata - Either a vector of p4 values to the associated iinstr step or a two dimensional array of p4, p5, p6...values. Typically, one would specify pitch information in cps, or MIDI note number; but the arbitrary list of p4 data values could have other uses in the called iinstr.

## Performance

kbpm - speed of looping in beats per minute.

klen - length of the active part of the sequence (starting from step 0).

kmode - control the sequencer playback. A value of 0 (default) loops forward through the sequence, calling the associated instrument on each step. Other modes are supported. (See below).

Current playback options for kmode are:

- 0 - forward loop

- n>0 - forward loop with a mutation every n events

- -1 - backward loop

- -2 - back and forth

- -3 - random events

- -4 - play the entire sequence forward one time and stop

- -5 - play the entire sequence backward one time and stop

- -6 - shuffle the events

- -7 - reset to the initial state

kstep - if non zero replace the irhythm array with k-rate triggers. These could be from a MIDI keyboard or any other krate controller. An event is scheduled if this argument is positive, and just waits if it is negative. Default is zero.

reset - if non zero resets the sequencer (like mode -7). Default is zero.

kverbose - if non zero prints messages about the internal state changes. Default is zero.

kres - gives the index of the event created for the current k-cycle, or -1 if no event happened.

| Note
While the irhythm, iinstr, and idata, arrays are i-time, the values of the entries are read at k-rate when used. This means that by using global i-rate vectors, it is possible (with care) to change the specific values and other details at performance time.

## Examples

Here is an example of the sequ opcode. It uses the file sequ1.csd

Example 947. Example of the sequ opcode.

    <CsoundSynthesizer>

    <CsInstruments>

    ksmps = 32
    0dbfs = 1.0
    nchnls = 2

    instr 1
    ;; rhythm array - these steps values multiplied by tempo (ticks) in BPM
    irhythm[] fillarray 1, 1.5, 0.5, 0.5, 0.5, 0.5, 1.5, 1

    ;; instrument array - instrument number to render for each step
    inst0[] fillarray 11, 12, 13, 14, 15, 16, 17, 18
    inst1[] fillarray 19, 20, 21, 22, 23, 24, 25, 26

    ;; note array - here in cpsmidinn - esentially the 'p4' output from opcode
    ;;               can be any sequence of values
    inotes[] fillarray 60, 61, 62, 63, 64, 65, 66, 67

    ;; variable tempo
    kspeed line 60, p3, 180

    ;; rhythm, inst, notes, bpm, length, mode, verbose
    kSeq0 sequ irhythm, inst0, inotes, kspeed, 8
    kSeq1 sequ irhythm, inst1, inotes, kspeed * 1.2, 8
    endin

    instr 11, 12, 13, 14, 15, 16, 17, 18
    kl linseg 0, p3*0.01, 1, p3*.99, 0
    a1 oscil 0.9, cpsmidinn(p4)
    outs1 a1*kl
    endin

    instr 19, 20, 21, 22, 23, 24, 25, 26
    kl linseg 0, p3*0.01, 1,p3*.99, 0
    a1 oscil 0.9, cpsmidinn(p4)
    outs2 a1*kl
    endin
    </CsInstruments>

    <CsScore>
    i1 0 60
    e
    </CsScore>
    </CsoundSynthesizer>

Here is another example of the sequ opcode showing the various modes. It uses the file sequ2.csd

Example 948. Example of the sequ opcode.

    <CsoundSynthesizer>

    <CsInstruments>
    ksmps = 32
    0dbfs = 1.0
    nchnls = 2

    instr 1
    ;; rhythm array - these values are multiplied by tempo (ticks) in BPM
    irhythm0[] fillarray 1, 1.5, 0.5, 0.5, 0.5, 0.5, 1.5, 1
    ;; instrument array - instrument number to render for each step
    iinsts0[] fillarray 11, 12, 13, 14, 15, 16, 17, 18
    ;; note array - here cpsmidinn(p4), amps(p5), mod ratios(p6), mod indices(p7)
    ;; - esentially the 'p4', 'p5', 'p6' and 'p7' are output from sequ
    inotes[][] init 4,8 ;initialize 4 rows with 8 columns - p4=pitch, p5=amp, p6=modratio, p7=modindex
    inotes fillarray 60, 61, 62, 63, 64, 65, 66, 67, \
                     0.8, 0.3, 0.6, 0.2, 0.7, 0.4, 0.5, 0.6, \
                     1, 2, 3, 4, 5, 6, 7, 8, \
                     1, 11, 2, 12, 3, 21, 4, 22
    ;; NOTE: this can be any sequence of values
    ;; variable tempo
    kspeed linseg 85, p3*.7, 85, p3*.3, 240
    ;; rhythms, insts, notes, bpm, length, mode, step, reset, verbose
    kSeq sequ irhythm0, iinsts0, inotes, kspeed, 8, p4
    endin

    instr 11, 12, 13, 14, 15, 16, 17, 18
    kenv linseg 0, p3*0.01, 1, p3*.99, 0
    asig foscil p5, cpsmidinn(p4), 1, p6, p7
    outall asig * kenv
    endin

    </CsInstruments>

    <CsScore>
    i1 0 15 0 ;; forward mode
    s
    f0 1
    s
    i1 0 15 -1 ;; backward mode
    s
    f0 1
    s
    i1 0 15 -2 ;; forward and backward mode
    s
    f0 1
    s
    i1 0 15 -3 ;; random
    s
    f0 1
    s
    i1 0 6 -4 ;; play forward once and stop
    s
    f0 1
    s
    i1 0 6 -5 ;; play backward once and stop
    s
    f0 1
    s
    i1 0 15 -6 ;; shuffle mode
    s
    f0 1
    s
    i1 0 30 1 ;; mutate after each step
    s
    f0 1
    s
    i1 0 30 2 ;; mutate each second step
    s
    f0 1
    s
    i1 0 30 4 ;; mutate every four steps
    e
    </CsScore>
    </CsoundSynthesizer>

## Credits

Written by John ffitch

New in Csound 6.17

Prev | Up | Next
seed | Home | sekere