Repository navigation
Formatter
croma fmt is a canonical formatter for ABC 2.1 source, in the style of
rustfmt / gofmt. It is a proven, un-gated capability: idempotent and
lossless over the full 10,000-file corpus (10,000 / 10,000 — see
How-its-Proven).
croma fmt FILE # print canonical formatting to stdout
croma fmt --check FILE # exit non-zero if FILE is not already canonical
croma fmt --write FILE # rewrite FILE in place
croma fmt --auto-fix FILE # additionally apply safe, gated repairs to loose source-
format(plaincroma fmt) — lossless by construction. Musical tokens are copied verbatim by source byte span; only the whitespace between tokens, blank-line runs, and the final newline are normalized. Information fields and stylesheet directives stay byte-stable (trailing whitespace trimmed). Because no musical byte is reconstructed, formatting cannot change beaming or pitch. -
auto_fix(--auto-fix) — additionally applies a catalogue of safe curations that sanitise loose source into the canonical spelling the strict parser reads cleanly (detached note lengths, redundant/malformed barlines, field spacing, tempo normalisations,%%MIDIwhitespace). This is the designated home for repairs the strict parser defers. Every curation is runtime-verified by a safety gate and reverted (reported asskipped) if it would change the score.
Two invariants are the formatter's contract — unit-tested and proven over the external corpus:
-
Idempotent —
format(format(x)) == format(x);auto_fixoutput is itself aformatfixed point. -
Lossless — plain
formatrenders byte-identical MusicXML;auto_fixpreserves the ordered pitch sequence (step + alter + octave).
This pairs with the strict parser: the parser strict-rejects a malformation; the formatter repairs it. The two together are croma's reject → repair → recover pipeline.
The complete catalogue (each FixKind, its example, its safety gate, and its
ABC 2.1 citation), the safety-gate table, the %%MIDI scope and limits, and the
corpus-proof harness are documented in
docs/formatter.md.
See also: CLI-Usage ·
Language-Server (the LSP exposes formatting and a source.fixAll code
action backed by the same croma-fmt functions).
croma — licensed under Apache-2.0.
Commercial use is allowed but must retain the attribution in
NOTICE (license §4); provided
as-is, without warranty or liability (§7–8).
Repository · crates.io · docs.rs · Issues · docs/
Start here
Use it
Capabilities
Why trust it
Help