Ahmed Doghri Logo Image
Ahmed Doghri

motifdiff

Random notes are not a music project. motifdiff generates a MIDI file, keeps the melody in key, reuses motifs, and measures the result against a random baseline.

motifdiff, a symbolic MIDI generation benchmark

Random Notes Are Not A Demo

A lot of music generation demos press shuffle and call the output creative. That is not enough. 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 with anchors, fills pitch tokens from a small motif corpus, and nudges the result toward a chord progression instead of hoping randomness becomes a song.

A Listen Test With Numbers Attached

The output is `artifacts/motifdiff.mid`. The benchmark compares it to a random pitch baseline on scale adherence, motif reuse, tonal anchor, and mean melodic leap.

No model weights. No sample packs. No service. Just a readable generator and a metric suite that makes it harder to fool yourself.

The Number

The guided sequence gets 1.00 scale adherence versus 0.46 for random. Tonal anchor lands at 0.50 versus 0.08. Mean leap drops from 9.87 semitones to 3.90, which is the difference between a melody and a stairwell.

3 tests pass locally and on GitHub Actions across Python 3.9, 3.11, and 3.13, with the MIDI artifact regenerated in CI.

Tools Used

Python
MIDI
Symbolic Music
Masked Denoising
Evaluation Metrics
pytest
GitHub Actions CI