hraness

saved

Petri Nets as a Music Sequencer

by stackdumpStackdump Blogpublished

gist

Stackdump shows how one Petri-net primitive can drive every layer of a deterministic browser music generator. Token rings produce Euclidean rhythms, mismatched lengths create polyrhythms, and separate control nets schedule song sections and Auto-DJ transitions. Replacing long chains with token countdowns shrank a three-minute project from 22 MB to 242 KB. Because execution state stays inside the net, the running diagram also serves as the reproducible state model, scheduler, and debugging view.

ideas

  • Use one state primitive across layers. Notes, rhythms, song structure, and transition commands all become tokens moving through nets.
  • Let topology generate musical structure. Hit placement around a ring produces Euclidean rhythms, while unequal ring lengths create polyrhythm without a separate timing system.
  • Represent delay as quantity. A countdown place holding many tokens replaced long chains of mostly empty steps and cut the project representation sharply.
  • Bring boundary events into the scheduler. Encoding Auto-DJ transitions as control nets removed races between the worker and main-thread timers.
  • Make runtime state visible. The same diagram that executes the track reveals stuck tokens and phase errors while preserving deterministic replay.

quotes

Every note is literally a token moving one step through the diagram.

stackdump, stating the sequencer’s core representation.

One circle with many tokens does the job of many circles with one token each.

stackdump, explaining the countdown compression.

The transition is just another token moving through the graph.

stackdump, folding cross-thread timing into the existing execution model.

The token state is the only state, so the same seed produces the same track on any machine — no hidden counters, no drift.

stackdump, linking explicit state to deterministic playback.