Shuffle Is Not Composition
A lot of "AI music" demos press shuffle and call the output creative, which is the same as calling a cat walking across a keyboard a sonata. I wanted a tiny generator that produces a real MIDI file and then grades itself on the things your ear notices first: key, repetition, downbeats, and leaps.
motifdiff uses a masked symbolic denoising loop. It starts from fixed anchors, fills pitch tokens from a small motif corpus, and nudges the result toward a chord progression instead of hoping randomness accidentally becomes a song.
A Listen Test With Receipts
The output is `artifacts/motifdiff.mid`, so you can actually listen to the evidence. The benchmark also compares it to a random pitch baseline on scale adherence, motif reuse, tonal anchor, and mean melodic leap, so you don't have to take my ears' word for it.
No model weights, no sample packs, no service running in the background pretending to be creative. Just a readable generator and a metric suite that makes it harder to fool yourself.
The Number
The guided sequence stays in key 100% of the time against the random baseline's coin-flip 46%. Tonal anchor lands at 0.50 versus 0.08. Mean leap drops from 9.87 semitones to 3.90, the difference between a melody and someone falling down a flight of stairs onto a piano.
3 tests pass locally and on GitHub Actions across Python 3.9, 3.11, and 3.13, with the MIDI artifact regenerated in CI every single run.