std/instruments
Import: use "std/instruments";
Load and play audio samples as drum kits or melodic instruments.
Samples
Section titled “Samples”Audio sources.
A WAV file loaded as a clip, and the named collections of them that the samplers load.
fn Kit(kit_name: String = NUL) -> KitLoads kit metadata (samples, notes, files) without creating a plugin.
Parameters:
kit_name(String) — name of the kit (optional, defaults to “CR-78”)
Returns: Kit — kit metadata, inspectable or passable to Sampler()/SamplerMelodic()
Sample
Section titled “Sample”fn Sample(path: String) -> AudioClipLoads a WAV file as an audio clip. A loaded file and a recorded take are the same thing — audio, whole — so both arrive as an AudioClip over all of it, unplaced. The path is relative to the .non file that names it, the way use and load_file are; an absolute path is taken as given. Nothing else is searched. For a sound out of a kit, go through the kit and name it as the kit does — Sampler(Kit("CR-78")).get("bd"), not by filename.
Parameters:
path(String) — path to the .wav file, relative to this file
Returns: AudioClip — a clip over the whole of the loaded audio
Drum Sampler
Section titled “Drum Sampler”The drum sampler.
Sampler triggers one sample per slot from a loaded kit, mapping incoming pattern notes to kit slots. Build one from a Kit, load it onto a track with track.instrument(...), and drive it with a pattern.
DrumSample
Section titled “DrumSample”A reference to a single drum sample slot. Obtained via .slot() on a Sampler (e.g. kit.slot("bd")).
fn param(name: String) -> InstrumentParamReturns a parameter reference for this slot.
Parameters:
name(String) — parameter name: “gain”, “pan”, “attack”, “decay”, “sustain”, “release”, “slice_start”, “slice_end”, “reverse”
Returns: InstrumentParam — supports .get(), .set(), and << for modulation
param_get
Section titled “param_get”fn param_get(name: String) -> NumberGets a parameter value by name (shorthand for .param(name).get()).
Parameters:
name(String) — parameter name (e.g. “gain”, “pan”, “attack”)
Returns: Number — the current parameter value
param_set
Section titled “param_set”fn param_set(name: String, value: Number) -> DrumSampleSets a parameter value by name.
Parameters:
name(String) — parameter name (e.g. “gain”, “pan”, “attack”)value(Number) — new parameter value
Returns: DrumSample — the slot reference, for chaining
params
Section titled “params”fn params(filter: String?) -> ArrayReturns the available parameter names for this slot.
Parameters:
filter(String) — substring filter (optional)
Returns: Array — the available parameter names as Strings
envelope
Section titled “envelope”fn envelope(attack_ms: Number, decay_ms: Number, sustain: Number, release_ms: Number) -> DrumSampleSets the ADSR envelope for this sample.
Parameters:
attack_ms(Number) — attack time in millisecondsdecay_ms(Number) — decay time in millisecondssustain(Number) — sustain level (0.0-1.0)release_ms(Number) — release time in milliseconds
Returns: DrumSample — the slot reference, for chaining
fn name() -> StringReturns the sample name.
Returns: String — the sample name
fn note() -> NumberReturns the MIDI note number for this sample.
Returns: Number — the MIDI note mapped to this sample
Sampler
Section titled “Sampler”A CLAP drum sampler plugin with per-sample note mapping. Construct with Sampler(Kit("kit_name")).
Constructor
Section titled “Constructor”fn Sampler(kit: Kit = NUL) -> SamplerCreates a drum sampler instrument. No-arg form creates an empty sampler (use .load_kit() to load a kit later).
Examples:
Sampler()— empty samplerSampler(Kit("CR-78"))— with kit
Parameters:
kit(Kit) — kit value fromKit("name")(optional)
Returns: Sampler — the drum sampler
Kit & samples
Section titled “Kit & samples”samples
Section titled “samples”fn samples() -> ArrayReturns an array of loaded sample names.
Returns: Array — the loaded sample names as Strings
sample_info
Section titled “sample_info”fn sample_info() -> ArrayReturns an array of [name, note, file] for each sample.
Returns: Array — one [name, note, file] entry per sample
fn get(name: String) -> AudioClipGets the audio behind a kit sound, as a clip. The clip is the material only — the sound’s controls stay on the sampler.
Parameters:
name(String) — sample name
Returns: AudioClip — a clip over the whole of that sound’s audio
load_kit
Section titled “load_kit”fn load_kit(kit: Kit) -> SamplerLoads a kit into the sampler.
Parameters:
kit(Kit) — the kit to load
Returns: Sampler — the sampler, for chaining
fn slot(name: String) -> DrumSampleReturns a reference to a drum sample slot by name.
Parameters:
name(String) — slot name
Returns: DrumSample — a reference to the named slot
Note mapping
Section titled “Note mapping”note_for
Section titled “note_for”fn note_for(name: String) -> NumberReturns the MIDI note number for the given sample name.
Parameters:
name(String) — sample name
Returns: Number — the MIDI note mapped to that sample
set_note
Section titled “set_note”fn set_note(name: String, new_note: Number) -> SamplerRemaps a sample to a different MIDI note.
Parameters:
name(String) — sample namenew_note(Number) — MIDI note number to assign
Returns: Sampler — the sampler, for chaining
choke_group
Section titled “choke_group”fn choke_group(group: Number, samples: Array) -> SamplerAssigns samples to a choke group. Samples in the same group cut each other off (e.g. open/closed hi-hat).
Parameters:
group(Number) — choke group ID (1+)samples(Array) — sample names in the group
Returns: Sampler — the sampler, for chaining
Parameters
Section titled “Parameters”fn param(name: String) -> InstrumentParamReturns a parameter reference by raw path. Tip: use .slot(“bd”).param(“gain”) for named access.
Parameters:
name(String) — parameter path (e.g. “slot_0/gain”, “slot_1/attack”)
Returns: InstrumentParam — supports .get(), .set(), and << for modulation
param_get
Section titled “param_get”fn param_get(name: String) -> NumberGets a parameter value by raw path.
Parameters:
name(String) — parameter path (e.g. “slot_0/gain”)
Returns: Number — the current parameter value
param_set
Section titled “param_set”fn param_set(name: String, value: Number) -> SamplerSets a parameter value by raw path.
Parameters:
name(String) — parameter path (e.g. “slot_0/gain”)value(Number) — new value in the parameter’s native range
Returns: Sampler — the sampler, for chaining
param_set_norm
Section titled “param_set_norm”fn param_set_norm(name: String, value: Number) -> SamplerSets a parameter value using a normalized [0,1] input.
Parameters:
name(String) — parameter path (e.g. “slot_0/gain”)value(Number) — normalized value (0.0 to 1.0)
Returns: Sampler — the sampler, for chaining
params
Section titled “params”fn params(filter: String?) -> ParamListReturns a ParamList with all sampler parameters.
Parameters:
filter(String) — only include parameters whose name contains this substring (optional)
Returns: ParamList — parameter data (columns: Parameter, Value, Range, Default)
Identity
Section titled “Identity”fn name() -> StringReturns the kit name.
Returns: String — the kit name
Melodic Sampler
Section titled “Melodic Sampler”The melodic sampler.
SamplerMelodic pitch-shifts one sample across the keyboard, turning a single recording into a playable chromatic instrument. Load a sample, load it onto a track with track.instrument(...), and let pattern notes set the pitch.
SamplerMelodic
Section titled “SamplerMelodic”A CLAP melodic sampler plugin with pitch-shifting. Construct with SamplerMelodic(Kit("kit_name")) or SamplerMelodic() for empty.
Constructor
Section titled “Constructor”fn SamplerMelodic(kit: Kit = NUL) -> SamplerMelodicCreates a melodic sampler. A kit-backed sampler loads its declared default sample immediately. A kit with one sample may infer that default; a multi-sample kit must declare [kit].default_sample. No-arg form creates an intentionally empty sampler (use .load_kit() to load a kit later). Pitch-shifts a single sample for melodic playback.
Examples:
SamplerMelodic()— empty samplerSamplerMelodic(Kit("bass"))— with kit
Parameters:
kit(Kit) — kit value fromKit("name")(optional)
Returns: SamplerMelodic — the melodic sampler
Kit & samples
Section titled “Kit & samples”load_sample
Section titled “load_sample”fn load_sample(name: String, root_note: Number?) -> SamplerMelodicLoads a sample from the kit directory.
Parameters:
name(String) — sample nameroot_note(Number) — root note for pitch mapping (optional)
Returns: SamplerMelodic — the sampler, for chaining
samples
Section titled “samples”fn samples() -> ArrayReturns an array of loaded sample names.
Returns: Array — the loaded sample names as Strings
sample_info
Section titled “sample_info”fn sample_info() -> ArrayReturns an array of [name, root_or_nil, file] for each sample.
Returns: Array — one [name, root_or_nil, file] entry per sample
fn get(name: String) -> AudioClipGets the audio behind a kit sound, as a clip. The clip is the material only — the sound’s controls stay on the sampler.
Parameters:
name(String) — sample name
Returns: AudioClip — a clip over the whole of that sound’s audio
load_kit
Section titled “load_kit”fn load_kit(kit: Kit) -> SamplerMelodicLoads a kit into the sampler.
Parameters:
kit(Kit) — the kit to load
Returns: SamplerMelodic — the sampler, for chaining
Pitch & root
Section titled “Pitch & root”fn root(note: Number) -> SamplerMelodicOverrides the root note for the current sample.
Parameters:
note(Number) — MIDI note number for the root pitch
Returns: SamplerMelodic — the sampler, for chaining
root_for
Section titled “root_for”fn root_for(name: String) -> NumberReturns the root note for the given sample, or nil.
Parameters:
name(String) — sample name
Returns: Number — the root note for that sample, or nil if unset
Playback
Section titled “Playback”envelope
Section titled “envelope”fn envelope(attack_ms: Number, decay_ms: Number, sustain: Number, release_ms: Number) -> SamplerMelodicSets the ADSR envelope for the current sample.
Parameters:
attack_ms(Number) — attack time in millisecondsdecay_ms(Number) — decay time in millisecondssustain(Number) — sustain level (0.0-1.0)release_ms(Number) — release time in milliseconds
Returns: SamplerMelodic — the sampler, for chaining
set_loop
Section titled “set_loop”fn set_loop(start_secs: Number, end_secs: Number) -> SamplerMelodicSets the loop region in seconds.
Parameters:
start_secs(Number) — loop start time in secondsend_secs(Number) — loop end time in seconds
Returns: SamplerMelodic — the sampler, for chaining
set_loop_normalized
Section titled “set_loop_normalized”fn set_loop_normalized(start: Number, end: Number) -> SamplerMelodicSets the loop region using normalized [0,1] positions.
Parameters:
start(Number) — loop start position (0.0-1.0)end(Number) — loop end position (0.0-1.0)
Returns: SamplerMelodic — the sampler, for chaining
Parameters
Section titled “Parameters”fn param(name: String) -> InstrumentParamReturns a parameter reference by name.
Parameters:
name(String) — parameter name (e.g. “RootNote”, “Gain”)
Returns: InstrumentParam — supports .get(), .set(), and << for modulation
param_get
Section titled “param_get”fn param_get(name: String) -> NumberGets a parameter value by name (shorthand for .param(name).get()).
Parameters:
name(String) — parameter name (e.g. “RootNote”, “Gain”)
Returns: Number — the current parameter value
param_set
Section titled “param_set”fn param_set(name: String, value: Number) -> SamplerMelodicSets a parameter value by name.
Parameters:
name(String) — parameter name (e.g. “RootNote”, “Gain”)value(Number) — new value in the parameter’s native range
Returns: SamplerMelodic — the sampler, for chaining
param_set_norm
Section titled “param_set_norm”fn param_set_norm(name: String, value: Number) -> SamplerMelodicSets a parameter value using a normalized [0,1] input.
Parameters:
name(String) — parameter name (e.g. “RootNote”, “Gain”)value(Number) — normalized value (0.0 to 1.0)
Returns: SamplerMelodic — the sampler, for chaining
params
Section titled “params”fn params(filter: String?) -> ParamListReturns a ParamList with all sampler parameters.
Parameters:
filter(String) — only include parameters whose name contains this substring (optional)
Returns: ParamList — parameter data (columns: Parameter, Value, Range, Default)
Identity
Section titled “Identity”fn name() -> StringReturns the plugin name.
Returns: String — the plugin name