Pattern Methods
This content is for v0.7. Switch to the latest version for up-to-date documentation.
Method Reference
Section titled “Method Reference”| Method | Description |
|---|---|
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 |
Examples
Section titled “Examples”let pat = [C4 D4 E4 F4];
// Speed controlpat.fast(2); // Double speedpat.slow(2); // Half speed
// Pitch manipulationpat.transpose(12); // One octave uppat.transpose(-5); // Down a fifth
// Reorderingpat.reverse(); // [F4 E4 D4 C4]pat.rotate(1); // [D4 E4 F4 C4]
// Combining patternspat.cat([G4 A4]); // Concatenate sequentiallypat.stack([G4 A4]); // Play simultaneously
// Degradation and rhythmpat.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 offsetspat.swing(0.25); // Swing feel on odd eventspat.humanize(0.1); // Subtle random timing variation
// Indexingpat.at(0); // First element as patternpat[2]; // Third element (same as .at(2))
// Mappingpat.map(fn(note) { return note + 12; }); // Transpose up octavepat.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 cyclepat.fast([1 2 3]); // Cycles through 1x, 2x, 3x speedpat.transpose([0 7 12]); // Shift by 0, 7, 12 semitones each cyclepat.degrade([0.0 0.5 0.9]); // Increasing degradation across cyclesSee Also
Section titled “See Also”- Pattern Basics - Pattern fundamentals
- Euclidean Rhythms - Algorithmic pattern generation