Go to beats.bitwrap.io. Pick a genre — techno, jazz, ambient, drum & bass, 19 in total. Hit Generate. You'll hear a full track: drums, bass, melody, arpeggios. Change the seed, get a different track. Replay the same seed, get the exact same one.
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 literally a token moving 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 the Bjorklund algorithm — it spreads K hits across N steps as evenly as possible. 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 sounds like the cross-rhythms in Afro-Cuban and West African music, because it is the same math.
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, dnb — 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 AI, no samples — music theory and random numbers with a seed. Same seed, same track, every 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. Same result, way less diagram:
| Before | After | |
|---|---|---|
| Places | 37,148 | 800 |
| Transitions | 37,120 | 800 |
| File size | 22 MB | 242 KB |
One circle with many tokens does the job of many circles with one token each. Petri nets are flexible like that.
These fell out of the Petri net structure without any extra work.
Determinism. Same seed, same track. Always. Any machine, any browser. The token state is the only state — no hidden counters, no drift.
Visual debugging. Every net is circles and arrows. Draw it on screen and we can watch tokens hop in real time. When something sounds wrong, we can see why — a token stuck in the wrong place, a ring out of phase.
Composability. Each instrument is its own net. Song structure is a separate layer. They don't know about each other. Pull one out, add another, nothing breaks.
Formal properties. We can prove a pattern loops, that every instrument eventually plays, and that a song reaches its end. Standard Petri net analysis — boundedness, liveness, reachability — applied to music.
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.
The Petri net engine itself? About 100 lines of vanilla JS. The music theory — scales, chords, Euclidean rhythms, Markov chains — is another 3,700 lines. No npm, no bundler, no framework. Tone.js from CDN, a Go server that serves static files, 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.