Compose a piece of music in the Melos language, compile it to MIDI, and fix any errors. Use when asked to compose, write, or create music.
Early Feature: This skill is an early-stage portable AI skill for music composition. The bundled
melosbinary may not include all features from the main Melos compiler.
Compose music in the Melos domain-specific language, compile to MIDI, and iteratively fix errors.
Gather requirements - Determine the user's intent:
Plan the composition - Before writing code, work through the compositional process (see below)
Compose the piece - Write a .mel file in the current directory
Compile and validate - Use the included Melos compiler:
./melos compile <filename>.mel
This produces a .mid file with the same base name.
Fix errors - If compilation fails:
.mel file and recompileFinalize - Once compiled successfully, inform the user that the MIDI file is ready.
Before writing Melos code, work through these steps. They help produce music that's distinctive rather than generic.
Note: Skip any step that doesn't fit your intent. If you're deliberately avoiding a climax, don't add one just because it's a step here. This process surfaces options, not constraints.
Write 2-3 sentences describing the piece's core gesture. Be specific about what a listener would hear, not what they would understand intellectually.
Weak: "A piece about longing that builds to a climax" Better: "A solo clarinet phrase that keeps reaching for a high G but falls back; when it finally arrives, the piano drops out"
Ask: Can this be heard, or only explained? If it requires explanation, revise until it describes sound.
Write out the 3-5 rhythmic cells you'll use before assigning pitches:
Test: If you remove pitch information, can you still tell a theme from an accompaniment? If all parts have the same rhythmic values, they'll blur together.
Example:
Theme rhythm: long-short-short-LONG (half, eighth, eighth, half tied)
Accompaniment: offbeat pulses (rest-eighth, chord-quarter, rest-eighth, chord-quarter)
Countermelody: running eighths BUT with rests on strong beats
Before writing pitches, sketch the shape:
Test: Write the theme. Cover the page. Can you remember how it goes? If not, ask: what would make it stick? A wider leap? A distinctive rhythm? An unexpected direction?
List the textures you'll use and where:
If you have only one texture type, add another.
Before writing your moment of highest intensity, sketch three approaches:
Write a sentence for each. Then choose one—or combine elements. The goal isn't to avoid any particular gesture, but to consider alternatives before committing.
After drafting, ask "what if":
You don't have to accept every variation—but asking surfaces possibilities you wouldn't otherwise consider.
Imagine someone hearing this piece with no context—no title, no program note.
If something in your intention isn't audible, either make it more salient or remove it from your description.
For substantial works (string quartets, symphonies, multi-movement pieces), offer to create program notes and organize files properly.
Create a directory named after the work, with movements numbered using Roman numerals:
work_name/
├── PROGRAM_NOTES.md
├── I_first_movement.mel
├── I_first_movement.mid
├── II_second_movement.mel
├── II_second_movement.mid
└── ...
Program notes should be substantial, musicologically informed, and written with a distinct voice. They might include:
The structure and tone should emerge organically from the work itself. Some pieces call for analytical rigor; others for poetic reflection; others for historical narrative. Trust your creative instincts.
for f in work_name/*.mel; do ./melos compile "$f"; done
Title: "Piece Name"
Tempo: 120
Time: 4/4
Key: C "Major"
Part: "Part Name" Instrument: Piano {
| C4 q D4 q E4 q F4 q |
| G4 h E4 h |
}
w = whole note (4 beats in 4/4)h = half note (2 beats)q = quarter note (1 beat)e = eighth note (1/2 beat)s = sixteenth note (1/4 beat). for dotted: h. = 3 beats, q. = 1.5 beatsC4, F#5, Bb3C4r q (quarter rest), r h (half rest), etc.[C4 E4 G4] q // C major chord, quarter note
[D4 F#4 A4] h // D major chord, half note
ppp, pp, p, mp, mf, f, ff, fff
C4 q mf // quarter note C4 at mezzo-forte
. = staccato> = accent- = tenutoC4 q . // staccato quarter note
E4 q > // accented quarter note
Tuplet(3:2) { E4 q E4 q E4 q } // triplet: 3 quarters in time of 2
Time: 3/4
Key: G "Major"
Tempo: 140
Swing: e 0.66 // Apply swing to eighth notes
Swing: off // Disable swing
Piano, Violin, Viola, Cello, Flute, Clarinet, Oboe, Bassoon, Trumpet, French Horn, Trombone, Tuba, Acoustic Guitar (Nylon), Electric Guitar (Jazz), Acoustic Bass, Electric Bass, Strings, Choir Aahs, Synth Lead
Error: "Measure X has Y ticks but expected Z"
Error: "Expected octave number"
C4 not CTuplet(3:2) needs exactly 3 events insideKey: G "Major"Part: "Violin 1"Each instrument needs exactly ONE Part block containing all its measures. Multiple Part blocks with the same instrument play simultaneously as separate tracks—they do NOT concatenate.
Wrong (creates 3 simultaneous cello tracks):
Part: "Cello Intro" Instrument: Cello { | D3 w | }
Part: "Cello Theme" Instrument: Cello { | A3 w | }
Part: "Cello Coda" Instrument: Cello { | D2 w | }
Correct (one continuous part):
Part: "Cello" Instrument: Cello {
// Intro
| D3 w |
// Theme
| A3 w |
// Coda
| D2 w |
}
Title: "Morning Walk"
Tempo: 100
Time: 4/4
Key: G "Major"
Part: "Piano" Instrument: Piano {
| G4 q B4 q D5 q B4 q |
| A4 q C5 q E5 q C5 q |
| G4 h D5 h |
| G4 w |
}