Change a Pattern Every Cycle
When the next pattern depends on more than one value, compute it in a callback. on_cycle runs it
once per cycle with the cycle number, and what it sends lands on that cycle.
Send a pattern from a callback
Section titled “Send a pattern from a callback”use "std/instruments" { SamplerMelodic, Kit };
let lead = AudioTrack("lead");lead.set_instrument(SamplerMelodic(Kit("keys")));
on_cycle(fn(cycle) { let note = 60 + (cycle % 12); // one step up each cycle, then back down lead << Sequence(#[note]);});
PLAY;Seed any random choice with cycle, so the result is the same on every playback — see
Make a Reproducible Random Choice.
Stop the callbacks
Section titled “Stop the callbacks”off_cycle() removes every callback.
Start on an external clock
Section titled “Start on an external clock”When resonon follows a MIDI clock, call prime_cycles() before the clock starts, so the first cycle
is not empty — see
Sync to a MIDI Clock.
Related
Section titled “Related”- Cycles & Time — when a cycle is computed, and when a change lands
- Generate a Random Walk — a value that carries from cycle to cycle