@libraz/libcantus - v0.9.3
    Preparing search index...

    Function generateRhythm

    • Generate a deterministic rhythmic pattern over bars bars of a time signature. A grid is built at the chosen subdivision; each slot becomes an onset with a probability derived from its metric weight scaled by density and sampled from the seeded PRNG. Every bar's downbeat is always an onset, so a pattern of any length has a reliable pulse independent of the seed. Each event's duration extends to the next onset, and the last event extends to the end of the span. density is clamped to [0, 1].

      Parameters

      Returns RhythmEvent[]

      Onset events sorted by position, non-overlapping, covering the span.

      import { parseTimeSignature, generateRhythm } from '@libraz/libcantus';
      const ts = parseTimeSignature('4/4');
      generateRhythm(ts, { seed: 42, density: 0.6 }); // onset events over one bar