Files
doux-copy/seq/docs/scripting.md
2026-01-19 16:44:17 +01:00

2.1 KiB

Scripting

Steps are programmed using Rhai, a simple scripting language.

Basic Syntax

Create sounds using sound() and chain parameters:

sound("kick").gain(0.8)
sound("hat").freq(8000).decay(0.1)

Context Variables

These are available in every step script:

  • step: Current step index (0-based)
  • beat: Current beat position
  • bank: Current bank index
  • pattern: Current pattern index
  • tempo: Current BPM
  • phase: Phase within the bar (0.0 to 1.0)
  • slot: Slot number playing this pattern

Randomness

  • rand(min, max): Random float in range
  • rrand(min, max): Random integer in range (inclusive)
  • seed(n): Set random seed for reproducibility

Variables

Store and retrieve values across steps:

  • set("name", value): Store a value
  • get("name"): Retrieve a value

Sound Parameters

Core

  • sound(name): Create sound command
  • freq(hz): Frequency
  • note(midi): MIDI note number
  • gain(amp): Volume (0.0-1.0)
  • pan(pos): Stereo position (-1.0 to 1.0)
  • dur(secs): Duration
  • gate(secs): Gate time

Envelope

  • attack(secs): Attack time
  • decay(secs): Decay time
  • sustain(level): Sustain level
  • release(secs): Release time

Filter

  • lpf(hz): Lowpass frequency
  • lpq(q): Lowpass resonance
  • hpf(hz): Highpass frequency
  • bpf(hz): Bandpass frequency

Effects

  • delay(mix): Delay amount
  • delaytime(secs): Delay time
  • delayfeedback(amt): Delay feedback
  • verb(mix): Reverb amount
  • verbdecay(secs): Reverb decay

Modulation

  • vib(hz): Vibrato rate
  • vibmod(amt): Vibrato depth
  • fm(hz): FM modulator frequency
  • fmh(ratio): FM harmonic ratio

Sample Playback

  • speed(ratio): Playback speed
  • begin(pos): Start position (0.0-1.0)
  • end(pos): End position (0.0-1.0)

Examples

Conditional based on step:

if step % 4 == 0 {
    sound("kick").gain(1.0)
} else {
    sound("hat").gain(0.5)
}

Random variation:

sound("synth")
    .freq(rand(200.0, 800.0))
    .gain(rand(0.3, 0.7))

Using variables:

let n = get("counter");
set("counter", n + 1);
sound("beep").note(60 + (n % 12))