BeatFlow
Use Codex for musical decisions. Use the bundled engine for exact timing, functional pitch realization, voicing, validation, diagnostics, compilation, MIDI rendering, and inspection.
Runtime
Refer to this skill directory as <skill-root> and run:
python "<skill-root>/scripts/run.py" <command> ...
Require Python 3.10 or newer. Write composition scripts and generated
artifacts in the user's workspace, never in <skill-root>.
Workflow
-
Extract duration, form, tempo, meter, tonal language, instrumentation, energy path, priorities, and exclusions from the brief. Make reversible assumptions for missing details.
-
Classify each instrument as
essential,substitutable, oroptional. Separately classify its prominence asprimary,co-primary,support, orbackground. Preserve essential instruments and repair their writing, balance, or playback program before considering a contract change. -
Read composition-guidance.md and composition-format.md. Read phrasing-and-coordination.md for prominent melody, thematic development, complex meter, or timing repair. Read long-form.md for work longer than 90 seconds. Read diagnostics.md when revising or comparing candidates. Load research-foundations.md only when methodological evidence is useful.
-
Plan before writing events:
- frame: duration, sections, tempo, meter, tactus, tonic, and mode;
- phrase: grouping, harmonic rhythm, attention, arrivals, and releases;
- skeleton: pulse, bass, harmony, role entries, rests, and handoffs;
- foreground: rhythmic identity, contour, density, texture, and structural tones;
- decoration: fills, secondary attacks, counterlines, and articulation.
-
Render the quantized skeleton before adding foreground. Keep at least one stable time reference and make important harmony changes and arrivals perceptible. Treat foreground as optional; a bass hook, designed chord top line, or rhythmic texture may already lead attention.
-
Author a trusted Python file whose
build()function returnsComposition. UseSongBuilder; let style affect the authored music, not the schema or compiler. -
For a complete song, separate reusable section material from timeline occurrences. Use occurrence development and
arrange()treatments to create formal change without copying whole sections. -
For quality-sensitive melody or thematic work, audition short, structurally different candidates before expanding the form. Compare rhythm and duration without pitch decoration, preserve an early recognizable statement, and select by listening.
-
Render the selected candidate:
python "<skill-root>/scripts/run.py" compose "<output>/<name>.py" "<output>/<name>.mid" --composition-output "<output>/<name>.composition.json" --project-output "<output>/<name>.project.json" --report "<output>/<name>.report.json"
- Treat validation errors as hard failures. Treat diagnostics as evidence against the written intent, not as taste scores. Revise the highest causal layer responsible, rerender, and listen again.
- Report the musical design, assumptions, validation result, diagnostic findings, MIDI facts, and any decisions that still require listening judgment.
Core constraints
- Keep the default timing exactly quantized. Add onset drift or humanization only when the user explicitly requests a timing experiment, and preserve a quantized baseline.
- Count the perceptual tactus rather than assuming every quarter note is a
beat. Use
song.at(),song.tactus(), andsong.bars()for meter-aware plans. - Use regular whole-bar phrase grouping unless irregularity has a named musical function.
- Give important foreground phrases a clear identity, internal contrast, and
primary arrival. Use
phrase(),phrase_stage(), andarrival()when their intent needs to be testable. - Give related roles purposeful dependence without forcing identical attacks.
Use
interaction()when independence, interlocking, call-and-response, or handoff is central to the brief. - Use
top_targetwhen the highest note of a chord voicing carries the line. Add a separate lead only when it has a clear complementary role. - Keep every onset and duration explicit. Never infer note length from the next attack.
Revision
Diagnose in this order:
- meter and shared clock;
- role ownership and instrument contracts;
- phrase grouping, gesture continuity, and arrival;
- harmonic rhythm, bass support, and voicing;
- pitch contour and non-chord-tone behavior;
- articulation, balance, and playback timbre.
Use three simple comparisons before adding rules:
- audition the foreground rhythm on one pitch;
- mute optional or competing layers one at a time;
- compare the earliest complete phrase ending with one later ending.
Repair causal structure rather than isolated notes. Do not use random density, arbitrary jitter, blanket humanization, or a new genre-specific engine rule as a shortcut.
Commands
schema: print the Composition 1.1 JSON Schemavalidate COMPOSITION: run hard structural and semantic checksdiagnose COMPOSITION: report advisory musical observationscompare COMPOSITION...: compare candidate fingerprintscompile COMPOSITION PROJECT: compile to internal Project JSONrender COMPOSITION MIDI: validate, diagnose, compile, render, and inspectcompose SCRIPT MIDI: execute trustedbuild()and run the full pipelineinspect MIDI: report MIDI structure, programs, ranges, and controllersself-check: run the end-to-end installation smoke test
Use project-schema, project-validate, and render-project only for the
low-level compiled Project boundary.
Boundaries
- Create original symbolic music. Do not copy a reference melody or imitate a living artist.
- Verify licenses before importing analytical corpora or reference files.
- Treat General MIDI playback as a preview; evaluate production timbre in the destination instruments or DAW.
- Keep listening as the final musical decision.