Go to beats.bitwrap.io. Pick a genre — techno, jazz, ambient, drum & bass, 19 in total (the preset table). Hit Generate. You'll hear a full track: drums, bass, melody, arpeggios. Change the seed, get a different track. Replay the same seed and the generator composes the same track again, note for note; the performance on top of it varies a little, which we come back to below.
There's no piano roll behind this. No timeline grid, no DAW. The whole thing runs on Petri nets — circles connected by arrows, with tokens moving through them. Every note is a transition firing as a token moves one step through the diagram.
Picture a ring of 8 circles connected by arrows. One dot — a token — sits at the first circle. Every tick, it hops to the next one. Some circles trigger a kick drum when the token lands. The rest are silent. The token goes around and around. You've got a beat.
The pattern of hits comes from Euclidean rhythm — popularized by Godfried Toussaint, it spreads K hits across N steps as evenly as possible (euclidean.js builds the ring from it). With 3 hits across 8 steps you get the tresillo, a rhythm that shows up everywhere from Afro-Cuban son to Rihanna.
That ring of circles? It's called a Petri net. The circles are places, the arrows pass through transitions, and the dot is a token. That's the whole vocabulary. Change the numbers — 4 hits across 16 steps — and you've got four-on-the-floor techno. Same structure, different rhythm.
Each instrument gets its own ring. Kick, snare, hihat, clap — all running in parallel. Make the rings different lengths and they drift in and out of sync, giving you polyrhythm for free. A 6-step hihat over a 16-step kick — the drum & bass preset's polyrhythm: 6 does exactly this — sounds like the cross-rhythms in Afro-Cuban and West African music, because it is the same arithmetic.
Melodies work the same way. Instead of drum hits, each step carries a note — pitch, velocity, duration. The music theory picks notes that make sense over the chord (chord tones on strong beats, passing tones on weak beats, rests so it can breathe), and lays them out in a ring.
Bass lines? Ring. Arpeggios? Ring. Harmony pads? You guessed it.
Pick a genre — techno, jazz, ambient, drum & bass — and a preset fills in the details: scales, chords, drum patterns, how much swing, how much humanize. The generator assembles a bunch of rings, and the sequencer just... runs them. No machine learning, no samples — music theory, Markov chains with hand-tuned weights for the melodies, and one seeded random number generator, all spent at compose time.
Loops are easy — tokens go around, patterns repeat. But a song needs intros, drops, breakdowns. The hihat should disappear for 8 bars, then come back. The bass should sneak in during the second verse.
So we added control nets — rings that don't make sound but fire commands like "mute the hihat" or "bring in the bass." A tiny stage director made of circles and arrows.
The first version was hilariously wasteful: a chain of 1,536 individual steps, one per tick, with a command every few hundred steps and nothing in between. It worked! But the project file was 22 MB for a 3-minute track.
The fix: countdown timers. Instead of 384 empty steps before a section change, we put 384 tokens in a single circle and drain one per tick. A special connection (called an inhibitor arc) holds back the control event until the countdown hits zero. In structure.js (buildAccumulatorNet) each event gets a delay place loaded with the gap in ticks, a drain transition that eats one token per tick, and a control transition behind an inhibitor arc on the delay place that passes a gate token to the next event. Same result, way less diagram:
| Before | After | |
|---|---|---|
| Places | 37,148 | 800 |
| Transitions | 37,120 | 800 |
| File size | 22 MB | 242 KB |
Those are the counts we recorded for one generated track when the change went in. The repo doesn't keep that project or a test that reproduces them, so read them as a reported measurement; we haven't re-run it. The change also didn't reach every path. The studio's composer calls the countdown version, but the arrangement expander (arrange.js) and the Go port (internal/generator/structure.go) still build song-structure nets as one place per tick plus a sink. One circle with many tokens does the job of many circles with one token each, where we've used it.
Auto-DJ regenerates a new track at the boundary, and we wanted a curated filter sweep, white-noise wash, or riser to land on the downbeat — not race the project swap from the main thread.
The first attempt coordinated main-thread timers against worker-side regen state. It mostly worked, except when a user gesture overlapped the boundary and the macro got silently dropped. We were fighting the runtime.
The fix was to stop treating transitions as a side channel. Each Auto-DJ transition is now injected as a one-transition control net with a fire-macro binding (buildTransitionFireNet). t0 fires on tick 1 of the new track; the worker emits control-fired; the main thread runs the macro through the normal queue. Tick-synchronized by construction, because the Petri net executor is already the scheduler.
Two timing bugs — the project-swap race and the macro-queue drop — collapsed into one piece of structure. The transition is just another token moving through the graph. Details in the v1.1.0 release notes; the curated transition pool itself shipped in v1.0.8.
The seed pins the composition: same genre and seed, same nets and the same notes in them, on any machine. It doesn't pin the performance, and the token state isn't the only state. The main thread adds humanize jitter with Math.random(), the default Drift loop mode varies velocity and occasionally shifts a token on loop wrap, control actions flip a mute table in the worker rather than moving tokens, and the FX macros are slider animations off the net. The runtime post draws that line exactly. What does hold is that the same diagram that runs the music can be drawn on screen and watched: when something sounds wrong, we can see a token stuck in the wrong place or a ring out of phase. And because each instrument is its own net and song structure is a separate layer, pulling one out or adding another doesn't disturb the others. We got that without extra work, from one primitive carrying the concurrency and the scheduling.
beats.bitwrap.io — 19 genres, all client-side, nothing to install.
A huge shoutout to Tone.js, which does all the heavy lifting on the audio side. Petri nets decide what plays and when — Tone.js makes it actually sound good. Polyphonic synths, reverb, compression, sub-millisecond scheduling — we got all of that essentially for free. It's one of those libraries where you keep expecting to hit a wall and never do. Tone.js is still the default; there is now a second, opt-in engine behind ?engine=wave that computes the audio from the marking in an AudioWorklet (Beats as a Wave).
The Petri net executor (pflow.js) is 668 lines of vanilla JS as of November, with another 818 in the sequencer worker; both have grown since March. The rest — music theory, generators, UI — is bigger, but none of it is framework code. No npm, no bundler. Tone.js from CDN, a Go server that serves the static files and the share store, and a 60-year-old idea about circles and arrows that turned out to be a pretty good sequencer.
Source: github.com/stackdump/beats-bitwrap-io
For the formal theory behind why token flow works as a computational model, see Declarative Differential Models. To build and simulate your own nets, try pflow.xyz.
Revised 2026-11-16 against the beats-bitwrap-io source and the runtime post, which had already corrected the same determinism claim. The code was read for this revision, not run.
Math.random() humanize jitter, and the default loop mode is literally called Drift. The token state is also not the only state (mute table, off-net FX macros).structure.js as described, but only the studio composer uses it; arrange.js and the Go port still build one-place-per-tick chains. The before/after table has no fixture behind it in the repo and is now labelled as a recorded measurement.Edit 2026-08-08: this post was discussed on Hacker News. Following the thread, "Bjorklund algorithm" above was changed to "Euclidean rhythm" — the standard term in the field, popularized by Godfried Toussaint. The mobile-performance issues commenters reported are tracked in beats-bitwrap-io#2.
Related: A browser music sequencer where every note is a Petri-net transition firing · beats.bitwrap.io is a Jambox Now · From Petri-net toy to jambox · A Generator You Can Read · Beats as a Wave · beats-btw-dj