Skip to content
Tech News
← Back to articles

Petri Nets as a Music Sequencer

read original more articles

Petri Nets as a Music Sequencer

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.

A Drum Machine Made of Tokens

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.

Everything Is a Ring

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.

... continue reading