Skip to content

Pattern Methods

MethodDescription
fast(factor)Speed up pattern by factor
slow(factor)Slow down pattern by factor
transpose(semitones)Pitch shift notes
reverse()Reverse pattern order
rotate(steps)Rotate pattern by steps
stack(other)Stack with another pattern (parallel)
cat(other)Concatenate with another pattern
concat(other)Alias for cat
degrade(probability)Randomly drop notes (0-1)
euclid(hits, steps)Apply Euclidean rhythm
euclid(hits, steps, rotation)Euclidean with rotation
nudge(offsets)Per-step timing offsets (array of cycle fractions)
swing(amount)Swing feel — shifts odd-indexed events forward
humanize(amount)Deterministic random timing variation (plus/minus amount)
map(fn(note))Transform each note (MIDI pitch)
map_with_timing(fn(note, start, dur))Transform with timing info
at(index)Get element at index
iter()Create infinite iterator over events
describe()Get human-readable description
length()Get number of elements
let pat = [C4 D4 E4 F4];
// Speed control
pat.fast(2); // Double speed
pat.slow(2); // Half speed
// Pitch manipulation
pat.transpose(12); // One octave up
pat.transpose(-5); // Down a fifth
// Reordering
pat.reverse(); // [F4 E4 D4 C4]
pat.rotate(1); // [D4 E4 F4 C4]
// Combining patterns
pat.cat([G4 A4]); // Concatenate sequentially
pat.stack([G4 A4]); // Play simultaneously
// Degradation and rhythm
pat.degrade(0.3); // 30% chance to drop each note
[C4].euclid(3, 8); // Euclidean rhythm
// Microtiming (step-relative fractions)
pat.nudge([0, 0.25, 0, -0.1]); // Per-step offsets
pat.swing(0.25); // Swing feel on odd events
pat.humanize(0.1); // Subtle random timing variation
// Indexing
pat.at(0); // First element as pattern
pat[2]; // Third element (same as .at(2))
// Mapping
pat.map(fn(note) { return note + 12; }); // Transpose up octave
pat.map_with_timing(fn(note, start, dur) {
if start == 0.0 { return note + 12; } // Accent downbeat
return note;
});
// Iteration (infinite -- always use .take()!)
let events = pat.iter().take(8).collect();
// Pattern-patterning -- parameter varies per cycle
pat.fast([1 2 3]); // Cycles through 1x, 2x, 3x speed
pat.transpose([0 7 12]); // Shift by 0, 7, 12 semitones each cycle
pat.degrade([0.0 0.5 0.9]); // Increasing degradation across cycles