Repository navigation
Library Usage
croma-core is the library under the whole toolkit — the CLI, formatter, and
language server all call it rather than reparsing ABC. Its default build is
zero-dependency and crates.io-publishable.
cargo add croma-coreuse croma_core::abc_to_musicxml;
let xml = abc_to_musicxml("X:1\nT:Scale\nM:4/4\nL:1/8\nK:C\nC D E F G A B c|\n")?;
// xml: a String of MusicXML 4.0abc_to_musicxml(source: &str) -> croma_core::Result<String> returns the
MusicXML string, or an error carrying parse diagnostics on malformed input.
When you want the warnings alongside the output (e.g. to surface them in your
own UI), use export_musicxml, which returns a MusicXmlExport:
use croma_core::export_musicxml;
let export = export_musicxml("X:1\nT:Scale\nL:1/8\nK:C\n^C =D __E\n")?;
println!("{}", export.musicxml); // the MusicXML String
for d in &export.diagnostics { // Vec<croma_core::Diagnostic>
eprintln!("{}: {}", d.code, d.message);
}pub struct MusicXmlExport {
pub musicxml: String,
pub diagnostics: Vec<Diagnostic>,
}
pub fn abc_to_musicxml(source: &str) -> Result<String>;
pub fn export_musicxml(source: &str) -> Result<MusicXmlExport>;abc_to_musicxml is just export_musicxml(...).map(|e| e.musicxml). Both
default to ABC 2.1.
For non-default parsing (e.g. the ABC 2.2 draft) or staged access to the model, the crate also re-exports:
-
export_musicxml_with_options(source, ExportOptions)— convert under explicitExportOptions(ParseMode,AbcSpecVersion, …). -
parse_document(source, ParseOptions) -> ParseReport<AbcDocument>— parse only. -
lower_score(&AbcDocument, LowerOptions)— lower a parsed document to aScore. -
write_musicxml(&Score) -> MusicXmlExport— render aScoreto MusicXML.
The model and option types (Score, Tune, Part, Voice, NoteEvent,
Pitch, Diagnostic, Span, ParseOptions, ExportOptions, ParseMode,
AbcSpecVersion, …) are all re-exported from the crate root. Browse the full
API on docs.rs/croma-core.
croma-core's default feature set pulls in no runtime dependencies. This is
a hard project invariant — CI asserts it
(cargo tree -p croma-core --edges normal resolves to the crate alone). Keep it
in mind if you contribute: new runtime deps belong on the binaries or behind an
opt-in feature, never the library default (Contributing).
The reverse direction (MusicXML → Score) is behind the opt-in
musicxml-reader feature, whose only dependency is roxmltree:
cargo add croma-core --features musicxml-reader# // requires the `musicxml-reader` feature
use croma_core::read_musicxml;
let report = read_musicxml(&xml); // ParseReport<Score>
let score = report.value; // the reconstructed Scoreread_musicxml and complete_score_for_abc are compiled only under that
feature (#[cfg(feature = "musicxml-reader")]); the default build never
compiles them nor roxmltree. Reader scope and evidence: MusicXML-Reader.
| Crate | Role |
|---|---|
croma-core |
the library — ABC 2.1 parser, model, ABC ↔ MusicXML |
croma-fmt |
the formatter / auto-fixer (format, auto_fix) over the core model |
croma-cli |
the croma CLI binary |
croma-lsp |
the stdio language server |
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