Triggers
Triggers are a core feature of Devalang that let you load and execute sound samples with precision. They form the foundation for building reactive or rhythmic elements in your compositions.
You can trigger samples manually, link them to other events, or combine them in groups for more complex behaviors.
Types
Triggers can be categorized based on how they are activated:
- Manual triggers — explicitly called using their name in the script.
- Event triggers — react to time or custom events using
on
andemit
. - Dynamic triggers (coming soon) — based on external inputs (e.g., sensor data, MIDI).
Loading
To use a sample in Devalang, you first need to load it.
This is done using the @load
directive, which imports the sample file and assigns it a name for later use.
This is typically done at the beginning of your script.
For the moment, only WAV files are supported, but support for other formats like MP3 and OGG is planned.
Duration
When you load a sample, Devalang automatically calculates its duration in milliseconds.
You can choose between using the sample full duration (auto
), or specifying a custom duration in milliseconds.
You can also use beat units like 1/4
, 1/8
, etc., which will be converted to milliseconds based on the current tempo.
Bank Triggers
You can use the bank
triggers by chaining bank
and trigger
keywords together.
This allows you to load and trigger samples from a specific bank (optionally aliased).
Effects
When triggering a sample, you can configure its behavior using a set of parameters:
Option | Description | Example |
---|---|---|
drive | Adds harmonic saturation to the signal, simulating light distortion | drive: 0.5 |
gain | Adjusts the sample’s volume (1.0 = normal volume) | gain: 0.8 |
pitch | Changes the pitch (1.0 = original, 2.0 = +1 octave, 0.5 = -1 octave) | pitch: 0.75 |
pan | Positions the sound in the stereo field (-1.0 = left, 1.0 = right) | pan: -0.3 |
fade_in | Applies a fade-in at the beginning of the sample (in milliseconds) | fade_in: 50 |
fade_out | Applies a fade-out at the end of the sample (in milliseconds) | fade_out: 75 |
reverb | Adds a reverb effect (0.0 = dry, 1.0 = fully reverberated) | reverb: 0.4 |
Events
You can listen to time-based or custom events using on
, and emit your own events with emit
.
- Periodic events:
on beat: ...
,on bar: ...
- Custom events:
on custom: ...
withemit custom { key: value }
Examples
Here’s how to declare and trigger samples in Devalang: