Libretto (谱文)

A validated, deterministic structural-assessment environment for symbolic music, within which an LLM agent composes and is steered.

Yichen Xu

UC Berkeley

29
structural axes
314
real-song corpus
0.019%
round-trip note loss
2→6 / 8
retrieval (newgen pass)
12→39%
loop (gap-fill pass)
62→94%
loop (newgen pass)

Abstract

Large language models can write music notation, but we lack a rigorous way to say whether what they write is structurally sound — and to steer them when it is not. We present Libretto, a validated, deterministic environment for symbolic music in which an LLM agent composes within a text grammar and is assessed and steered by a structural-assessment engine. The engine places any piece in a 29-axis fingerprint of token-derived, decorrelated structural features (rhythm, harmony, melody, texture, form), each scored as an empirical percentile against a frozen 314-song corpus; the axes are descriptive, not a learned “quality” score. We show the gates discriminate: real human music sits at a mean of 3.4 extreme axes (admitted), while degenerate generations pile up to 4–6, and a strict note-level copy gate cleanly separates novel material (≤0.29) from near-duplicates (≥0.31). On this substrate we add two interventions — a monotone-safe self-evolving loop that returns non-prescriptive “dosage” feedback to the agent, and mandatory retrieval of corpus-grounded idiom concepts plus centroid-nearest real exemplars. Across four applications (held-out gap-filling, component morphing, from-scratch generation, single-voice pedagogy), retrieval triples from-scratch pass rate (2/8→6/8) by de-degenerating the fingerprint, and the loop roughly triples gap-filling pass rate (12%→39%) and lifts from-scratch generation to 94%. Because every axis is deterministic and grounded, a failure is fully legible: a generated gap-fill’s “~2-chords-per-bar conveyor belt” and all-stepwise melody are pinpointed to specific axes at the 95th–100th percentile. The grammar round-trips to MIDI with 0.019% note loss, and the validated core is frozen under a sha256 manifest.


How it works

An LLM composes in the grammar; the deterministic engine scores it on the 29 axes and steers it — retrieve, compose, measure, and loop until it clears the gates.

Frozen substrate 314-song corpus → 29-axis fingerprint distribution percentile-scored against the frozen corpus 1 Retrieve KB concepts · real exemplars · genre target bands 2 Compose (LLM) write the grammar — aim mid-band, never copy 3 Measure & gate 29-axis fingerprint, then gate: non-degeneracy · novelty · fit · length Pass → MIDI gaptask · morph newgen · education ✗ fail → dosage feedback · ≤3 rounds (pick-best)

How music is represented

One compact, human-legible text grammar — exact pitch, rhythm, and voices, and nothing else. The same text round-trips to MIDI; the LLM reads and writes only this.

KEY: C major | METER: 4/4 | TEMPO: 120 | GRID: 16th | BARS: 2
VOICES: Melody, Piano, Bass
@1 [C]
  Melody: E4@1>2 G4@5>2 C5@9>4 G4@13>2
  Piano : C4+E4+G4@1>8 C4+E4+G4@9>8
  Bass  : C2@1>4 G2@9>4
@2 [G]
  Melody: D4@1>2 G4@5>2 B4@9>4 D5@13>2
  Piano : G3+B3+D4@1>8 G3+B3+D4@9>8
  Bass  : G2@1>4 D3@9>4
  • header — key · time signature · tempo · grid resolution · #bars
  • [C] — the bar's chord (always present)
  • Melody / Piano / Bass — the named voices (parts)
  • E4 — an exact pitch (scientific; middle C = C4)
  • @5>2 — onset at slot 5, lasts 2 slots (in 4/4 the four beats are slots 1·5·9·13)
  • C4+E4+G4+ stacks notes into a chord

Note content is exact and reversible; velocity, micro-timing, and timbre are intentionally dropped.


Try the grammar

Edit the grammar on the left — it renders to a piano-roll instantly, and you can play it. Runs entirely in your browser (no server).

↑ these structural axes are read directly from the text — every note's bar and slot is explicit, so they're exact lookups (off-beat notes are outlined). In ABC or raw MIDI you'd first have to reconstruct absolute timing (relative durations / tick deltas) before any of these is even well-defined.


Why not ABC notation?

ABC is the standard text music format, but it stores each note's onset as a relative duration — the onset is a running within-bar sum (O(n) to recover). Libretto stores an absolute slot (O(1) lookup). Same music, same information; only the representation differs.

What you ask of the notationABC (relative)Libretto (absolute slot)
Recover every note's onset — real folk tunes (Nottingham DB) O(n) prefix-sums0 — slot is the onset
Align voices, “what sounds together” — full 314-song corpus 5,896,110 additions0
LLM reads structure, tool-free benchmark (accuracy) 42%100%
LLM quick-read — impossible / out-of-meter answers (“beat 7”) 27%0% — unrepresentable

Two tiers. The top two rows are deterministic properties of the encoding, measured on real tunes and the whole corpus (no model). The bottom two are tool-free LLM reads of the same music in each notation: the same reasoning is more accurate in Libretto, and never lands out-of-meter — an absolute slot cannot name a beat outside its bar, so the hallucination is eliminated by construction, not merely rarer. ABC's honest advantage is being more token-terse. LLM rows are illustrative (small n, one model); full method & caveats in paper_data/grammar_compare/.


The 29-axis environment

Any piece is placed in a coordinate system of 29 token-derived structural axes, each a percentile against a frozen 314-song corpus. The axes are decorrelated (max |r| = 0.77, 12 of 406 pairs ≥ 0.5) and carry real — if soft — genre signal.

Axis structure
Axis structure. (left) 29×29 correlation heatmap — mostly pale (decorrelated); (middle) the classifier reads one song as a genre blend; (right) 5-fold CV confusion (acc 0.384, ≈3× chance).
Genre radar
Genre fingerprints. Mean percentile on all 29 axes (50 = corpus-typical) — each genre a legible structural signature.
Per-piece axis profiles
Per-piece profiles. Where each generated piece sits on every axis (• = extreme). Passing pieces show few •; failures show clustered extremes the loop must fix.

Data & provenance

Percentiles are scored against a frozen reference of 314 real songs that we curate across 8 genres from the Clean MIDI subset (~17k files, 2,199 artists) of the Lakh MIDI Dataset (Raffel, 2016; CC-BY 4.0). The 314-song selection and genre labels are ours; the source MIDIs — and their artist/title, “with some inaccuracy” — come from clean_midi (community transcriptions, hence anonymized Part{n} voices and occasional near-duplicates, which the copy gate accounts for).

genrengenren
Pop/Rock70Funk/Soul30
Electronic34Jazz28
Classical30Latin/Reggae/World28
Folk/Country25Film/Score10
The 314 curated songs (artist — title)
101 Strings — Theme From The Godfather
2 Unlimited — No One.1
2 Unlimited — Twilight Zone.1
808 State — Pacific 202
a-ha — Take On Me.3
a-ha — The Living Daylights.1
ABBA — Dancing Queen
ABBA — Dancing Queen.4
ABBA — Gimme! Gimme! Gimme!.1
ABBA — Mamma Mia
ABBA — The Winner Takes It All
Acoustic Alchemy — The Blue Chip Bop
Adamo — Lei
Adamski — Love and Life
Adiemus — Kayama.1
Adriano Celentano — Azzurro.1
Al Green — Let's Stay Together
Angelo Branduardi — Si puo fare
Annie Cordy — Tata Yoyo
Aretha Franklin — (You Make Me Feel Like a) Natural Woman.1
Astrud Gilberto — Once I Loved
Average White Band — Cut the Cake
Average White Band — Pick Up The Pieces.1
Bach Johann Sebastian — 2-Part Invention No. 1 in C major, BWV 772.3
Bach Johann Sebastian — Brandenburgisches Konzert Nr. 1 F-Dur, BWV 1046: IV. Menuet - Trio - Menuet - Polonaise - Menuet - Trio - Menuet.1
Bach Johann Sebastian — Flute Sonata in B minor, BWV 1030: I. Andante
Barry White — You're The First, The Last, My Everything
Barry White — Youre the First the Last My Everyting
Battisti — Vento nel vento
Bee Gees — How Deep Is Your Love
Bee Gees — Too Much Heaven.2
Billy Joel — Piano Man
Billy Joel — Piano Man.6
Billy Joel — Shameless
Bob Dylan — Blowin' in the Wind.2
Bob Dylan — Lay Lady Lay.1
Bob Dylan — Like A Rolling Stone
Bob Marley — Three Little Birds
Bon Jovi — Keep the Faith.1
Boston — More Than A Feeling.1
Boston — More Than A Feeling.3
Bryan Adams — Thought I'd Died and Gone to Heaven.1
Buena Vista Social Club — El cuarto de Tula
Buena Vista Social Club — Murmullo
Camaleonti — L'ora dell'amore.3
Cameo — Back and Forth
Carpenters — Close to You
Carpenters — Top of the World.1
Chic — Falling in Love With You
Chicago — 25 or 6 to 4
Chicago — Hard to Say Im Sorry
Chick Corea — Sometime Ago
Chick Corea — Spain
Chopin Frederic — Etude c moll opus 10 Nr.12
Chopin Frederic — Larghetto
Chopin Frederic — Nocturne In C Minor, Op. 48 Nr. 1
Claude Debussy — Arabesque Nr. 1 in E-dur L66 1 (feat. harp: Paola Larini).1
Claude Debussy — V. Pour l'Egyptienne
Claude Debussy — VI. Pour remercier la pluie au matin
Commodores — Night Shift
Corona — Rhythm of the Night.1
Creedence Clearwater Revival — Born On The Bayou.1
Creedence Clearwater Revival — Suzie Q
Crosby, Stills, Nash & Young — Carry On
Crosby, Stills, Nash & Young — Ohio
Crosby, Stills, Nash & Young — Southern Cross
Culture Beat — Anything
Culture Beat — Mr Vain (Mr Trance).1
Curtis Mayfield — Move On Up
Cyndi Lauper — I Drove All Night
Daft Punk — Around the World Harder Better Faster Stronger.1
Daft Punk — One More Time.1
Dave Brubeck — Take Five.2
David Bowie — Let's Dance
David Bowie — Suffragette City
Depeche Mode — Strange Love
Diana Ross — Theme From Mahogany (Do You Know Where You're Going To?)
Diana Ross — Upside Down
Dire Straits — Private Investigations.1
Dire Straits — Sultans of Swing.3
Doe Maar — Smoorverliefd
Dr. Alban — It's My Life
Dr. Alban — Look Who's Talking
Duke Ellington — Don't Get Around Much Anymore
Duke Ellington — Rockin' in Rhythm
Duran Duran — New Moon on Monday.1
Duran Duran — The Reflex.2
Dvorak — Four Romantic Pieces, op. 75: III. Allegro appassionato
Dvorak — Serenade op. 22 - 1 Waltz
Dvorak — Symphonie nr. 9 E-moll op. 95: II. Largo
Dvorak — Symphony No. 2 in B major, Op. 4 B 12 : II. Poco adagio
Eagles — Desperado
Eagles — Hotel California
Eagles — Please Come Home for Christmas
Eagles — Take It to the Limit
Earth, Wind & Fire — Boogie Wonderland
Earth, Wind & Fire — Got To Get You Into My Life (bonus track)
Earth, Wind & Fire — September (bonus track)
Earth, Wind & Fire — Sing A Song (bonus track).2
Eddy Grant — Gimme Hope Jo'Anna.1
Edvard Grieg — Elfin Dance, Op.12 No.4
Edvard Grieg — I Love Thee
Edvard Grieg — Varen
Eiffel 65 — Another Race
Elton John — Daniel
Elton John — I Guess That's Why They Call It the Blues
Elton John — Rocket Man
Elton John — Your Song
Erasure — Blue Savannah.1
Faithless — Insomnia (D Donatis mix)
Fatboy Slim — Going Out of My Head
Fatboy Slim — Praise You
Fleetwood Mac — Albatros.1
Fleetwood Mac — Dreams
Foreigner — Blue Morning, Blue Day
Foreigner — Hot Blooded
Four Tops — Reach Out I'll Be There.2
Frank Sinatra — Young At Heart
Genesis — I Can't Dance.5
Genesis — Mama
Genesis — The Knife
George Benson — Feel Like Making Love
George Benson — On Broadway.1
George Frideric Handel — Alcina, HWV 34: Act I. 6. Gavotte
George Frideric Handel — Messiah: 44. Halleluja!
George Frideric Handel — Passacaglia
Gillespie Dizzy — A Night in Tunesia
Gillespie Dizzy — Salt Peanuts
Gipsy Kings — Baila Me
Gipsy Kings — Bamboleo
Glen Campbell — Dreams Of The Everyday Housewife
Glen Campbell — Gentle On My Mind
Gloria Estefan — Words Get in the Way
Gordon Lightfoot — Rainy Day People
Gordon Lightfoot — Sundown.1
Haddaway — What Is Love.4
Hall & Oates — Everytime You Go Away.1
Hall & Oates — Rich Girl
Henry Mancini — Baby Elephant Walk
Henry Mancini — Le Jazz Hot
Henry Mancini — Moon River
Henry Mancini — Natasha's Theme
Henry Mancini — The Days of Wine and Roses
Herbie Hancock — My Funny Valentine
Huey Lewis & The News — I Want a New Drug
Huey Lewis & The News — Perfect World
James Brown — Sex Machine (Get Up I Feel Like Being A)
James Taylor — Carolina in My Mind
James Taylor — Fire & Rain
James Taylor — Handy Man
Jean Michel Jarre — Oxygene, Part 6
Jean Michel Jarre — Souvenir of China
Jimmy Cliff — I Can See Clearly Now.1
Jimmy Cliff — Reggae Night
Johannes Brahms — Danza Ungherese n. 8 in la minore - Presto
Johannes Brahms — Hungarian Dance Nr 1 In G Minor
Johannes Brahms — Liebeslieder Waltz, Op. 52, No. 6
John Denver — Back Home Again
John Denver — Poems, Prayers and Promises
John Denver — Take Me Home Country Roads.1
Johnny Cash — Folsom Prison Blues
Journey — Don't Stop Believin'
Journey — Faithfully.3
Journey — Open Arms.3
Julio Iglesias — Begin the Beguine
Julio Iglesias — Quiereme mucho
Kansas — Magnum Opus
Kenny G — Songbird
Kool & The Gang — Celebration.1
Kraftwerk — Music Non Stop
Kraftwerk — The Robots
La Bouche — Be My Lover.1
La Bouche — Falling in Love (Radio Version)
Led Zeppelin — Heartbreak
Led Zeppelin — Stairway To Heaven
Lionel Richie — All Night Long
Los Lobos — La Bamba
Lou Reed — Walk On The Wild Side.2
Louis Armstrong — (What a) Wonderful World.3
Louis Armstrong — What A Wonderful World.2
Ludwig van Beethoven — 5th Symphony.1
Ludwig van Beethoven — Fur Elise.1
Ludwig van Beethoven — Pathetique
Lunapop — Se ci sarai
Madonna — Like a Prayer
Madonna — Like A Virgin.4
Madonna — Papa Don't Preach.4
Madonna — The Power Of Goodbye.2
Marvin Gaye — (Sexual) Healing
Matt Bianco — Half a Minute.1
Michael Jackson — Beat It
Michael Jackson — Thriller
Moby — The Blue Terror of Lawns
Nat King Cole — Route 66.1
Nat King Cole — When Sunny Get's Blue
New Order — Bizarre Love Triangle
New Order — World
Nomadi — Canto alla luna
Ohio Players — Love Rollercoaster
Ornella Vanoni — Tristezza
Ornella Vanoni — Viaggerai (Mares de ti)
Oscar Peterson — Emily
Oscar Peterson — I've Got a Crush on You
Pat Metheny — American Garage
Pat Metheny — Are You Going With Me
Patti Smith — Because The Night
Pet Shop Boys — Before
Pet Shop Boys — Se a Vida E (That's the Way Life Is).1
Pet Shop Boys — Where the Streets Have No Name
Peter Tosh — Johnny B Goode
Peter, Paul & Mary — I Dig Rock 'n' Roll Music
Peter, Paul & Mary — Leaving on a Jet Plane
Peter, Paul & Mary — Puff.2
Phil Collins — Another Day in Paradise.1
Phil Collins — Sussudio
Pink Floyd — Hey You.2
Pink Floyd — Money
Pink Floyd — The Great Gig in the Sky
Pink Floyd — Wish You Were Here
Prince — Purple Rain
Queen — Bohemian Rhapsody
Queen — In Only Seven Days
Queen — Killer Queen
Queen — We Are The Champions.3
Reinhardt Django — Minor Swing
Rick James — Give It To Me Baby
Rick James — Super Freak
Ricky Martin — Vuelve.1
Rod Stewart — Rhythm of My Heart
Roy Black — Du bist nicht allein.1
Salvatore Adamo — Vous permettez Monsieur ?
Santana — Maria Maria
Santana — She's Not There.1
Sergio Mendes — Never Gonna Let You Go
Simon & Garfunkel — Bridge Over Troubled Water
Simon & Garfunkel — Bridge Over Troubled Water.2
Simon & Garfunkel — I Am a Rock
Simon & Garfunkel — Scarborough Fair.1
Simon & Garfunkel — The Sound of Silence
Sly & The Family Stone — I Want to Take You Higher
Smash Mouth — Then the Morning Comes
Snap — Rhythm Is a Dancer.6
Snap — Welcome to Tomorrow
Spyro Gyra — Morning Dance
Spyro Gyra — Swamp Thing
Stan Getz — Desafinado
Stan Getz — The Girl From Ipanema (Garota de Ipanema).1
Steely Dan — Aja.2
Steely Dan — Kid Charlemagne.1
Steely Dan — Peg
Stevie Wonder — Isn't She Lovely
Stevie Wonder — You Are the Sunshine of My Life
Sting — Russians
Supertramp — Crime of the Century.1
Supertramp — The Logical Song
Supertramp — The Logical Song.1
Technotronic — Move This.2
The Beach Boys — Cool, Cool Water
The Beach Boys — Do It Again
The Beach Boys — God Only Knows
The Beach Boys — Good Vibrations
The Beatles — Birthday.4
The Beatles — Hey Jude
The Beatles — Penny Lane
The Beatles — Tell Me What You See
The Byrds — Eight Miles High
The Byrds — Mr. Tambourine Man
The Doors — Riders on the Storm.1
The Four Seasons — Big Girls Don't Cry
The Four Seasons — Dawn (Go Away).1
The Four Seasons — I've Got You Under My Skin
The Gap Band — Oops Up Side Your Head
The Gap Band — You Dropped the Bomb on Me
The Isley Brothers — Harvest for the World (Prelude)
The Kinks — Chirpy Chirpy Cheep Cheep.1
The Kinks — You Really Got Me
The Police — Can't Stand Losing You.2
The Police — Every Breath You Take
The Police — Wrapped Around Your Finger.1
The Prodigy — One Love
The Prodigy — Wind It Up
The Rolling Stones — Lady Jane.2
The Rolling Stones — You Can't Always Get What You Want
The Temptations — Cloud Nine
The Who — My Generation
The Who — Pinball Wizard
Thelonious Monk — Blue Monk
Thelonious Monk — Nice Work If You Can Get It
Tina Turner — Private Dancer
Tina Turner — The Best.2
Toto — Africa
Toto — Georgy Porgy.1
Toto — I Won't Hold You Back
Tower of Power — Soul With A Capital S
U2 — Discotheque
U2 — With or Without You
U2 — With or Without You.2
UB40 — (I Can't Help) Falling In Love With You.2
UB40 — Kingston Town.1
Vangelis — 1492: Conquest of Paradise
Vangelis — Bladerunner
Vangelis — Chariots of Fire.5
Vangelis — Chung Kuo
Vangelis — Voices
Weather Report — Birdland
Whitney Houston — Greatest Love of All.4
Whitney Houston — Hold Me
Whitney Houston — I Wanna Dance With Somebody (Who Loves Me)
Willeke Alberti — Het wijnfeest
Willeke Alberti — Ome Jan
Willie Nelson — Always on My Mind
Wolfgang Amadeus Mozart — Eine kleine Nachtmusik
Wolfgang Amadeus Mozart — Serenade D-Dur KV 250 (248b) "Haffner-Serenade" - 1. Allegro maestoso - Allegro molto
Wolfgang Amadeus Mozart — Serenade D-Dur KV 250 (248b) "Haffner-Serenade" - 2. Andante

The metric is not gamed

The gates are calibrated against ground truth and discriminate real music from degenerate or copied output — a deterministic, auditable target rather than a learned score.

gatereal / good outputdegenerate / copythreshold
C1 non-degeneracy (#extreme axes/29)real songs mean 3.4 gap-task FAIL 4.36 vs PASS 2.25; un-grounded newgen 5.9budget 4–6
Novelty / copy-risk (note-level — one metric, per-task reference) gap-fill & newgen passing ≤0.29; education drills 0.065 gap-fill flagged ≥0.31 (17/51 caught) <0.30 vs corpus/answer · education <0.50 vs shown example
fidelity (grammar↔MIDI)pitch exact, 0.019% loss velocity/micro-timing/drums dropped by design

Frozen core certified — distribution + encoder/decoder + metric definitions match a pinned sha256 manifest (v2.0.0); guard tests for the 29-axis shape, exact round-trip, determinism, and copy self-match all pass.

Steering the agent

Two interventions sit on the substrate: mandatory retrieval (corpus idiom concepts + centroid-nearest real exemplars) and a monotone-safe self-evolving loop (≤3 rounds, pick-best) that feeds non-prescriptive dosage feedback back to the agent.

Retrieval ablation
Why retrieval helps. OFF (orange) pins axes at the degenerate walls; ON (blue) pulls them into the corpus-normal band — non-degeneration, not copying. Pass 2/8→6/8.
Loop per song
The loop, per song. Single-shot (grey) → loop-best (green = passes); green connectors = failures the loop turned into passes. Gap-task 12→39%, newgen 62→94%.

Four applications, one environment

One grammar and one assessment engine support held-out gap-filling (n=51), component morphing (n=21), from-scratch generation (n=8/16), and single-voice pedagogy (n=32).

Generated music across four applications
Generated output across the four applications (piano-roll; colour = distinct voices).
Gap-task triptych
Gap-filling. Context | generated fill | held-out answer.
Gradual morph
Morphing. A→B with a monotone progress curve + copy crossfade.

Listen

Audio rendered from the generated grammar (grammar → MIDI → General-MIDI synthesis). A few typical samples per task; the rest are browsable below.

From-scratch generation (newgen)

One typical sample per genre. In the full list below, s1 / s2 are independent samples of that genre — separate generations that use the same prompt and the same retrieval, so they may sound similar (same style neighborhood; measured pairwise note-overlap ≈ 0.15, well under the 0.30 copy gate, so they are still distinct pieces).

Classical · s3
Pop/Rock · s3
Electronic · s3
Film · s3
Folk · s3
Funk/Soul · s3
Jazz · s3
Latin · s3
All 30 newgen samples — browse & listen
Classical
Classical · s1
Classical · s2
Pop/Rock
Pop/Rock · s2
Electronic
Electronic · s1
Electronic · s2
Film
Film · s1
Film · s2
Folk · s1
Folk · s2
Funk/Soul
Funk/Soul · s1
Funk/Soul · s2
Jazz
Jazz · s1
Jazz · s2
Latin
Latin · s1
Latin · s2

Style morphing (morph)

Each clip glides from one style to another (real source → generated transition → real target).

Electronic → Folk
Folk → Classical
Folk → Electronic
Funk/Soul → Jazz
Jazz → Classical
Pop/Rock → Electronic
All 16 morph clips — browse & listen
Funk/Soul → Latin
Latin → Jazz
Electronic → Pop/Rock
Film → Jazz
Jazz → Funk/Soul
Pop/Rock → Folk
Classical → Pop/Rock
Folk → Latin
Funk/Soul → Latin
Latin → Electronic

Gap-filling (gaptask) — model fill vs. real held-out region

A/B the model's generated region against the true held-out answer for the same gap.

song 0150 cont · Jazz · continuation
model fill
real held-out
song 0223 cont · Funk/Soul · continuation
model fill
real held-out
song 0188 cont · Classical · continuation
model fill
real held-out
song 0121 infill · Pop/Rock · infill
model fill
real held-out
song 0306 cont · Latin · continuation
model fill
real held-out
song 0287 start · Film · opening
model fill
real held-out
All 29 gap-fill pairs — browse & listen
song 0062 start · Pop/Rock · openingfillreal
song 0075 cont · Pop/Rock · continuationfillreal
song 0083 start · Pop/Rock · openingfillreal
song 0102 start · Pop/Rock · openingfillreal
song 0108 start · Pop/Rock · openingfillreal
song 0110 cont · Pop/Rock · continuationfillreal
song 0119 start · Pop/Rock · openingfillreal
song 0138 start · Jazz · openingfillreal
song 0152 cont · Jazz · continuationfillreal
song 0175 start · Classical · openingfillreal
song 0177 start · Classical · openingfillreal
song 0179 cont · Classical · continuationfillreal
song 0182 cont · Classical · continuationfillreal
song 0232 start · Funk/Soul · openingfillreal
song 0234 infill · Funk/Soul · infillfillreal
song 0248 cont · Funk/Soul · continuationfillreal
song 0253 infill · Folk · infillfillreal
song 0259 infill · Folk · infillfillreal
song 0282 infill · Film · infillfillreal
song 0284 infill · Film · infillfillreal
song 0293 infill · Latin · infillfillreal
song 0304 infill · Latin · infillfillreal
song 0310 start · Latin · openingfillreal

Education — single-line reading drills (play · MIDI · score)

A monophonic reading study for every major key, in both the treble and the bass clef — each roams its clef's register, mixes rhythms, and is distinct from the others (no repeats). Listen, or download the MIDI and the engraved score (PDF). Scroll within the panel for all 24.

C major · treble clef
C major · bass clef
G major · treble clef
G major · bass clef
D major · treble clef
D major · bass clef
A major · treble clef
A major · bass clef
E major · treble clef
E major · bass clef
B major · treble clef
B major · bass clef
F♯ major · treble clef
F♯ major · bass clef
F major · treble clef
F major · bass clef
B♭ major · treble clef
B♭ major · bass clef
E♭ major · treble clef
E♭ major · bass clef
A♭ major · treble clef
A♭ major · bass clef
D♭ major · treble clef
D♭ major · bass clef

A failure you can read off the score

Because every axis is deterministic and grounded, the metric’s verdict is not a black box. A failing gap-fill is legible as visible musical structure, pinned to specific axes.

song 0308 diagnostic roll
song 0308 — a failing gap-fill. Melody (top) relentlessly stepwise; harmony ~2 chords per bar (the “conveyor belt”); every bar distinct.

Grounded diagnosis

FAILS with 6 extreme axes vs a budget of 3:

  • harmonic rhythm 100th pct
  • chord variety 99th
  • average note length 96th
  • stepwise motion 95th
  • bar distinctness 100th
  • density variation 3rd

Not a copy (copy-risk 0.134), rhythmically aligned (beat 86%) — the failure is purely structural, and every flagged axis is visible in the roll.

Get started

The package onboarding (libretto/ONBOARDING.md) — structure, what each task implements, and how to reproduce. Scroll within the panel.

Loading…

Code & data

The Libretto package (grammar codec, the 29-axis engine, the loop and retrieval, the four applications) and the full results bundle are open.

Citation

@misc{xu2026librettogivingllmagents,
      title={Libretto: Giving LLM Agents a Sense of Musical Structure},
      author={Yichen Xu},
      year={2026},
      eprint={2606.22708},
      archivePrefix={arXiv},
      primaryClass={cs.SD},
      url={https://arxiv.org/abs/2606.22708},
}