| Function | Description |
|---|
clock() | Returns current time in nanoseconds |
setbpm(bpm) | Set tempo in BPM (4 beats per cycle) |
setbpm(bpm, beats) | Set tempo with custom beats per cycle |
reset() | Reset the entire runtime to a clean state |
setbpm(120); // 120 BPM, 4 beats per cycle
setbpm(140, 4); // 140 BPM, 4 beats per cycle
setbpm(90, 3); // 90 BPM in 3/4 time
let elapsed = clock() - start;
// Clear everything and start fresh
| Function | Description |
|---|
MidiTrack(channel) | Create MIDI track (velocity 100) |
MidiTrack(channel, velocity) | Create MIDI track with velocity |
MidiTrack(name, channel) | Create named MIDI track (velocity 100) |
MidiTrack(name, channel, velocity) | Create named MIDI track with velocity |
MidiTrack(name, channel, velocity, port) | Create named MIDI track on specific port alias |
midi_ports() | List available MIDI output ports |
midi_connect(port) | Connect to MIDI output port |
midi_connect(port, alias) | Connect to MIDI output port with alias |
midi_disconnect() | Disconnect default MIDI output |
midi_disconnect(alias) | Disconnect MIDI output by alias |
midi_connected() | Check connection status |
midi_input_ports() | List available MIDI input ports |
midi_input_connect(port, alias) | Connect to MIDI input port with alias |
midi_input_disconnect(alias) | Disconnect MIDI input by alias |
midi_clock_send(bool) | Enable/disable clock output (master mode, 24 PPQ) |
midi_clock_follow(alias) | Sync to external clock on input port |
midi_clock_follow(false) | Disable clock follow |
midi_delay(ms) | Set global MIDI output delay in ms (notes + clock) |
midi_delay() | Get current MIDI output delay in ms |
midi_clock_offset(ms) | Set clock-only offset in ms (positive = later, negative = earlier) |
midi_clock_offset() | Get current clock offset in ms |
Cc(cc_num) | MIDI CC input as signal (0.0-1.0) |
Cc(channel, cc_num) | CC input on specific channel (0-15) |
Cc_learn() | MIDI learn — move a knob to bind (10s timeout) |
let melody = MidiTrack(1); // Channel 1, default velocity
let bass = MidiTrack("bass", 2, 80); // Named, channel 2, velocity 80
let drums = MidiTrack("drums", 10, 127); // Named, channel 10, max velocity
midi_connect("IAC Driver Bus 1"); // Default port
midi_connect("USB MIDI", "ext"); // Named alias
let synth = MidiTrack("lead", 1, 100, "ext"); // Route to "ext" port
let port = midi_connected(); // Returns port name or dict
midi_disconnect("ext"); // Disconnect by alias
let in_ports = midi_input_ports();
midi_input_connect("Keystep", "keys");
midi_input_disconnect("keys");
let cutoff = Cc(74); // CC 74 (brightness), any channel
let mod = Cc(0, 1); // CC 1 on channel 0
filter.Cutoff << cutoff.smooth(50); // Smooth to avoid zipper noise
let knob = Cc_learn(); // Move a knob within 10s to bind
midi_clock_send(true); // Enable master clock output
midi_delay(15); // Delay all MIDI output by 15ms
midi_clock_offset(-5); // Send clock ticks 5ms earlier
| Function | Description |
|---|
Array(...) | Create array from arguments |
length(arr) | Get array length |
slice(arr, start, end) | Get subarray [start, end) |
concat(arr1, arr2) | Concatenate arrays |
range(end) | Generate integers [0, end) |
range(start, end) | Generate integers [start, end) |
let nums = #[1, 2, 3, 4];
slice(nums, 1, 3); // #[2, 3]
concat(nums, #[5, 6]); // #[1, 2, 3, 4, 5, 6]
range(5); // #[0, 1, 2, 3, 4]
range(2, 7); // #[2, 3, 4, 5, 6]
| Function | Description |
|---|
map(collection, func) | Apply function to each element |
filter(collection, func) | Keep elements matching predicate |
fold(collection, init, func) | Reduce to single value |
let nums = #[1, 2, 3, 4];
map(nums, fn(x) { return x * 2; }); // #[2, 4, 6, 8]
filter(nums, fn(x) { return x % 2 == 0; }); // #[2, 4]
fold(nums, 0, fn(acc, x) { return acc + x; }); // 10
| Function | Description |
|---|
euclid(hits, steps, pattern) | Create Euclidean rhythm |
euclid(hits, steps, pattern, rotation) | Euclidean with rotation |
Sequence(...) | Create sequential pattern |
Stack(...) | Create parallel pattern (chord) |
Alternating(...) | Create one-per-cycle pattern |
euclid(3, 8, kick); // Cuban tresillo rhythm
euclid(3, 8, kick, 2); // Tresillo rotated by 2 steps
let chord = Stack(C4, E4, G4); // Same as [C4, E4, G4]
let melody = Sequence(C4, D4, E4); // Same as [C4 D4 E4]
let alt = Alternating(C4, D4, E4); // Same as <C4 D4 E4>
| Function | Description |
|---|
AudioTrack() | Create unnamed audio track |
AudioTrack(name) | Create named audio track |
Sample(path) | Load WAV sample |
Kit(kit_name) | Load drum kit (returns kit data for Sampler/SamplerMelodic) |
Sampler() | Create empty drum sampler |
Sampler(kit) | Create drum sampler with Kit value |
SamplerMelodic() | Create empty melodic sampler |
SamplerMelodic(kit) | Create melodic sampler with Kit value |
Effect(name) | Load CLAP effect plugin |
Effect(name, plugin_id) | Load CLAP effect with explicit plugin ID |
Instrument(name) | Load CLAP instrument plugin |
Instrument(name, plugin_id) | Load CLAP instrument with explicit plugin ID |
timeline(length) | Create a timeline for arranging patterns at cycle offsets |
master is a global constant for routing audio to the master output bus.
let drums = AudioTrack("drums");
drums.load_instrument(Sampler(kit));
let quick = Sampler(); // Empty sampler (no default kit)
let bass = SamplerMelodic(Kit("bass"));
bass.load_sample("sub_bass.wav", "C1");
let synth = Instrument("Surge XT");
let lead = AudioTrack("lead");
lead.load_instrument(synth);
lead >> master; // Route to master output
| Function | Description |
|---|
audio_devices() | List audio output devices (array of dicts: name, input_channels, output_channels, sample_rate, is_default) |
audio_output(name) | Switch audio output device |
audio_output_channels(ch) | Set master output to mono channel |
audio_output_channels(l, r) | Set master output to stereo channels |
audio_output_channels(track, ch) | Set track output to mono channel |
audio_output_channels(track, l, r) | Set track output to stereo channels |
let devices = audio_devices();
audio_output("BlackHole 16ch"); // Switch output device
audio_output_channels(0, 1); // Master on channels 0, 1
audio_output_channels(drums, 2, 3); // Drums on channels 2, 3
audio_output_channels(bass, 4); // Bass mono on channel 4
| Function | Description |
|---|
plugin_scan() | Scan CLAP directories and update cache (returns plugin count) |
plugin_list() | List cached CLAP plugins (returns plugin count) |
plugin_scan(); // Scan for CLAP plugins
plugin_list(); // Show cached plugins
| Function | Description |
|---|
Delay(time, feedback) | Delay effect (defaults: 0.25s, 0.5) |
Lowpass(cutoff, resonance) | Lowpass filter (default: 1000 Hz, Q 0.707) |
Highpass(cutoff, resonance) | Highpass filter |
Bandpass(cutoff, resonance) | Bandpass filter |
Notch(cutoff, resonance) | Notch (band-reject) filter |
Allpass(cutoff, resonance) | Allpass filter (phase shift) |
Peak(cutoff, resonance) | Peak (bell) filter |
Reverb(room, damp, width, mix) | Freeverb reverb |
PlateReverb(size, damping, diffusion, predelay, mix) | Dattorro plate reverb |
Overdrive(drive, tone) | Tube-style soft clipping |
Distortion(drive, tone) | Transistor-style hard clipping |
let d = Delay(0.25, 0.7);
let bp = Bandpass(1000, 3.0);
let hall = Reverb(0.8, 0.3);
let plate = PlateReverb(0.7, 0.4, 0.8);
let warm = Overdrive(0.6, 0.8);
let crunch = Distortion(0.7, 0.5);
drums.load_effects(#[d, lp, hall]);
See Effects Reference for full parameter tables.
| Function | Description |
|---|
hz(n) | Create absolute frequency in Hz |
Sine(n) / Sine2(n) | Sine wave (unipolar / bipolar) |
Saw(n) / Saw2(n) | Sawtooth wave |
Tri(n) / Tri2(n) | Triangle wave |
Square(n) / Square2(n) | Square wave |
Rand(n) | Random noise |
Perlin(n) | Perlin noise (smooth random) |
signal(pattern) | Convert pattern to stepped signal |
signal_ramp(start, end) | Linear ramp signal |
signal_ramp(start, end, duration) | Ramp with custom duration |
automation(breakpoint, ...) | Automation curve with keyframes |
// All oscillators: no arg = 1 cycle/cycle, number = N cycles/cycle, hz() = absolute
Sine(); Saw(4); Tri(hz(2)); Square2(); Rand(); Perlin(8);
let lfo = Sine(4).range(0.2, 0.8);
let ramp = signal_ramp(0, 1, 4); // 0 to 1 over 4 cycles
let env = automation(#[0, 0], #[2, 1.0, "exp"], #[4, 0]);
| Function | Description |
|---|
stream(initial, fn(prev, cycle)) | Stateful stream pattern |
markov(states, transitions, initial) | Markov chain pattern |
rand(seed) | Deterministic random [0, 1) |
choose(seed, array) | Deterministic choice from array |
choose_weighted(seed, values, weights) | Weighted deterministic choice |
rand_true() | Non-deterministic random |
choose_true(array) | Non-deterministic choice |
on_cycle(fn(cycle)) | Register per-cycle callback (interpreter thread) |
off_cycle() | Clear all cycle callbacks |
prime_cycles() | Pre-fire callbacks (cycle 0) to set initial patterns |
let walk = stream(C4, fn(prev, cycle) {
return prev.transpose(choose(cycle, #[-2, -1, 1, 2]));
// Cycle callback — full interpreter access (native extensions, I/O, <<)
let data = my_extension.compute(cycle);
off_cycle(); // stop all cycle callbacks
| Function | Description |
|---|
Scale(name) | Create a scale from a built-in name |
Scale(array) | Create a custom scale from a semitone interval array |
Key(root, name_or_scale) | Create a key from a root note and scale name or Scale value |
scale(root, name_or_scale) | Get scale notes (accepts string or Scale) |
scale_degree(root, name_or_scale, degree) | Get specific scale degree (1-indexed) |
chord(root, name) | Get chord notes |
chord(root, name, inversion) | Get chord notes with inversion (positive = up, negative = down) |
interval(note, name) | Get note at interval |
scale_names() | List available scale names |
chord_names() | List available chord names |
Scale("major"); // Scale value
Scale(#[0, 2, 4, 5, 7, 9, 11]);// Custom scale from semitones
scale(C4, "major"); // #[C4, D4, E4, F4, G4, A4, B4]
scale_degree(C4, "major", 5); // G4
chord(C4, "min7"); // #[C4, Eb4, G4, Bb4]
chord(C4, "major", 1); // First inversion: #[E4, G4, C5]
chord(C4, "major", -1); // Drop last note down: #[B3, C4, E4, G4]
interval(C4, "P5"); // G4
| Method | Returns | Description |
|---|
s.name() | String | Scale name |
s.intervals() | Array | Interval array (semitones) |
s.period() | Number | Repeat period (12 = octave) |
s.length() | Number | Number of degrees |
s.degree(n) | Number | Interval at nth degree (1-indexed) |
s.mode(n) | Scale | Rotate to nth mode |
s.contains(n) | Boolean | Check if interval is in scale |
Scales: "major", "minor", "dorian", "phrygian", "lydian", "mixolydian", "locrian", "harmonic_minor", "melodic_minor", "pentatonic_major", "pentatonic_minor", "blues", "whole_tone", "chromatic". Aliases: "ionian" = major, "aeolian" = minor.
Chords: "major", "minor", "dim", "aug", "7", "maj7", "min7", "dim7", "aug7", "sus2", "sus4", "6", "min6", "9", "maj9", "min9", "add9", "power". Aliases: "maj" = major, "min" = minor, "dom7" = 7, "5" = power.
Intervals: "m2", "M2", "m3", "M3", "P4", "tritone", "P5", "m6", "M6", "m7", "M7", "P8". Aliases: "TT" = tritone, "oct" = P8.
| Function | Description |
|---|
project_title(title) | Set project title |
project_artist(artist) | Set artist name |
project_bpm(bpm) | Set project BPM (4 beats per cycle) |
project_bpm(bpm, beats_per_cycle) | Set project BPM with custom beats per cycle |
project_title("My Track");
project_artist("Producer Name");
project_bpm(140, 3); // 140 BPM in 3/4 time
| Function | Description |
|---|
render(track, cycles) | Render track to WAV |
render(tracks, cycles) | Render multiple tracks |
render(cycles) | Render master mix |
render_master(cycles) | Render master mix |
render(drums, 16); // Single track
render(#[drums, bass, lead], 16); // Multiple tracks
render(16); // Master mix
render_master(32); // Master mix
Output: renders/{project}/{datetime}/{track_name}.wav
| Function | Description |
|---|
midi_export(pattern, cycles) | Export pattern to MIDI file |
midi_export(pattern, cycles, path) | Export pattern to custom path |
midi_export(p, 4); // Auto path
midi_export(p, 4, "melody.mid"); // Custom path
Output: renders/{project}/{datetime}/export.mid (auto) or custom path.
Tempo is derived from the current CPS.
| Function | Description |
|---|
show(value) | Display detailed information |
type(value) | Get type name as string |
routing() | Print full audio routing graph |
routing(track, ...) | Print routing for specific tracks |
midi_routing() | Display MIDI routing configuration |
viz(pattern) | ASCII pattern visualization |
viz(pattern, cycles) | Visualize N cycles |
viz(pattern, cycles, start) | Visualize from start cycle |
type(#[1, 2]); // "Array"
routing(); // Full audio routing graph
midi_routing(); // MIDI ports, slots, clock config
viz([C4 D4 E4], 4); // 4 cycles of pattern