@maruaudio/dsp/processors/midi-pattern walks the held notes as a step pattern and emits MIDI: an arpeggiator (mode 0) or a sixteen-step sequencer with per-step velocity and swing (mode 1). Steps run at a rate in steps per second; each step is 1 / rate seconds converted to exact fractional frames through @maru/control-musical-clock, and every onset is rounded once from a grid anchor, so onsets do not drift when a step is not a whole number of frames. Controls are held as integer millionths. The Steps and Arpeggiator module Processors own mode and schema; generated adapters own handles and I/O.
Parameters
configureMidiPatternProcessor(state, mode, sampleRate, rate, pattern, octaves, gate, swing, length, seed, enabled) sets them together.
| Argument or setter | Range as coded | Default |
|---|---|---|
mode | ≥ 1 is the sequencer, otherwise the arpeggiator | 0 |
rate | 0.5 to 32 steps per second | 8 |
pattern | Floored, at most 4: 0 up, 1 down, 2 up-down, 3 played order, 4 seeded random | 0 |
octaves | Floored, 1 to 4 | 1 |
gate | 0.05 to 0.95 of a step, then at most 95 % of it and at least one frame | 0.6 |
swing | 0.5 to 0.75; delays odd steps in the sequencer only | 0.5 |
length | Floored, 1 to 16 steps | 16 |
setMidiPatternTempo(bpm, stepsPerBeat) | Each at least 1, giving a rate clamped to 0.5 to 32 | none |
setMidiPatternStepVelocity(index, v) | Index below 16; velocity 0 to 1, scaling held velocity in the sequencer | 0.9, 0.45, 0, 0.45 repeating |
enabled 0 passes input through unchanged; sampleRate below 1 is refused.
Lifecycle
createMidiPatternState (fixed typed arrays) → configure and setters → enqueueMidiPatternEvent(frame, status, data1, data2) → processMidiPatternProcessor(blockStart, frames) → emitMidiPatternEvents (MIDI byte events); saveMidiPatternState / restoreMidiPatternState (a versioned 3,066-byte layout, refused when malformed); resetMidiPatternState.
When to use it
An arpeggiator or a step sequencer driven by held notes, where steps must stay on an exact grid at any host rate.
Limits
- Queues of 128 input events, 128 pending note-offs and 256 outputs. A full input queue refuses the enqueue; a full output or note-off queue, or caller output with too little room, makes
emitMidiPatternEventsreturnfalse. - A block may not start before the previous one or have no frames. Notes above 127 after the octave shift are skipped.