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.
A drum kit’s metadata: its samples, the notes they sit on and their files. Construct with Kit(name); pass it to Sampler() or SamplerMelodic().
Constructor
Section titled “Constructor”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()
samples
Section titled “samples”fn samples() -> ArrayReturns the kit’s sample names.
Returns: Array — one String per sample
sample_info
Section titled “sample_info”fn sample_info() -> ArrayReturns each sample with its note and file, sorted by note.
Returns: Array — one [name, note, file] array per sample
fn name() -> StringReturns the kit’s display name.
Returns: String — the name from the kit’s metadata
fn mode() -> StringReturns how the kit plays: “oneshot” or “melodic”.
Returns: String — the playback mode
author
Section titled “author”fn author() -> StringReturns the kit’s author.
Returns: String — the author, or an empty string when none is given
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")).sample("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.set_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")).
parameter
Section titled “parameter”fn parameter(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
set_parameter
Section titled “set_parameter”fn set_parameter(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
parameters
Section titled “parameters”fn parameters(filter: String?) -> ParamListReturns a ParamList with this slot’s parameters.
Parameters:
filter(String) — only include parameters whose name contains this substring, case-insensitive (optional)
Returns: ParamList — parameter data (columns: Parameter, Value, Range, Default)
set_envelope
Section titled “set_envelope”fn set_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
sample
Section titled “sample”fn sample(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_or_note: String or Note or Number) -> DrumSampleReturns a reference to a drum sample slot.
Parameters:
name_or_note(String | Note | Number) — the sound’s name, or the note that triggers it
Returns: DrumSample — a reference to that slot
Note mapping
Section titled “Note mapping”fn note(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: Note or Number) -> SamplerMoves a sound to a different trigger note.
The pad moves everywhere at once: the sampler’s own mapping, the slots taken off it, and the patterns on the track it is loaded on. Its per-slot settings — gain, pan, envelope, slice — move with it.
A note triggers one sound, so moving onto a note another sound already holds is refused; move that sound first.
Parameters:
name(String) — sample namenew_note(Note | Number) — the note to assign, e.g.C2or36
Returns: Sampler — the sampler, for chaining
set_choke_group
Section titled “set_choke_group”fn set_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”parameter
Section titled “parameter”fn parameter(name: String) -> InstrumentParamReturns a parameter reference by raw path. Tip: use .slot(“bd”).parameter(“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
set_parameter
Section titled “set_parameter”fn set_parameter(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
parameters
Section titled “parameters”fn parameters(filter: String?) -> ParamListReturns a ParamList with all sampler parameters.
Parameters:
filter(String) — only include parameters whose name contains this substring, case-insensitive (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.set_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: Note or Number?) -> SamplerMelodicLoads a sample from the kit directory.
Parameters:
name(String) — sample nameroot_note(Note | Number) — root note for pitch mapping, e.g.C4(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
sample
Section titled “sample”fn sample(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”set_root
Section titled “set_root”fn set_root(note: Note or Number) -> SamplerMelodicOverrides the root note for the current sample.
Parameters:
note(Note | Number) — the root pitch, e.g.C4or60
Returns: SamplerMelodic — the sampler, for chaining
fn root(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”set_envelope
Section titled “set_envelope”fn set_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”parameter
Section titled “parameter”fn parameter(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
set_parameter
Section titled “set_parameter”fn set_parameter(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
parameters
Section titled “parameters”fn parameters(filter: String?) -> ParamListReturns a ParamList with all sampler parameters.
Parameters:
filter(String) — only include parameters whose name contains this substring, case-insensitive (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