@barmark/cli
A command that checks, formats, renders, transposes, exports and imports charts, and pulls out a part.
When to use it: Working in a terminal or CI, with no code. Also a standalone binary.
- Version
0.22.0- Install
npm install --save-dev @barmark/cli
Example
The example song with one mistake, and what barmark check prints for it.
example-song.chart.md
# Example Song
key: D, time: 4/4, tempo: 145
## Verse
|: D | A | Hm | G :|
| Em | / | A | A7 |
## Chorus
| G / D / | A | Bm / / A | G |
Terminal
$ npx @barmark/cli check example-song.chart.md
example-song.chart.md:5: error: Hm: German "H" is ambiguous; write B (write Bm)
1 file, 1 error, 0 warningsThe barmark command: check, format, key, part, render, transpose, export and import
Barmark chord charts (.chart.md files) in a
terminal or in CI. It runs the same barmark parser and @barmark/render
renderer as barmark.dev, @barmark/musicxml for MusicXML,
@barmark/score (with Verovio) for full scores and @barmark/midi for
MIDI files, at exact versions, so a chart means the same thing everywhere.
Install
With Node 20.6 or later:
npx @barmark/cli check . # run once
npm install --save-dev @barmark/cli # or keep it in a project
Without Node, download the binary for your system from the
GitHub release
(barmark-linux-x64, barmark-linux-arm64, barmark-darwin-x64,
barmark-darwin-arm64, barmark-windows-x64.exe). The binaries are not
signed yet; on macOS, clear the download flag before the first run:
chmod +x barmark-darwin-arm64
xattr -d com.apple.quarantine barmark-darwin-arm64
Commands
Folders mean every *.chart.md file inside them, skipping node_modules,
dot-folders and symlinks. - reads from stdin.
barmark check songs # errors and warnings, file:line
barmark export --musicxml song.chart.md --out song.musicxml # for MuseScore, Dorico…
barmark import song.musicxml --out song.chart.md # or a compressed song.mxl
barmark export --midi song.chart.md --out song.mid # for a DAW or a practice player
barmark import song.mid --out song.chart.md # chords named from the notes
barmark import bass.mid --chords # chords from a one-line file, not its notes
barmark export --lyricsheet song.chart.md --out song.cho # a ChordPro lyric sheet
barmark check --strict --format github songs # warnings fail too; PR annotations
barmark format song.chart.md # print it in standard form
barmark format --write songs # rewrite the files that change
barmark format --check songs # list them and fail, for CI
barmark key song.chart.md # the key its chords are in
barmark part Bass song.chart.md # one part of a chart of several
barmark render song.chart.md --out song.html # a standalone page, font included
barmark render --score song.chart.md --out song.html # the full engraved score
barmark render song.chart.md --diagrams guitar --left-handed --out song.html # with chord diagrams
barmark transpose song.chart.md --to E # or --semitones -2
A problem the parser can suggest a fix for ends with it, as song.chart.md:4: error: C(b2): "b2" is not a tone a parenthesis can add (write C(b9))
(check, export, part and transpose; --format json gives it as a
suggestion field). check --format json prints the diagnostics for other tools. render
takes the renderer's options as flags: --theme auto|light|dark,
--numerals nashville|roman, --bar-numbers written|played|off (played:
each row's place in play order, 1 · 5, ~ after a vamp; written, each bar
down the page once (a replayed section counted again), is the default; --no-bar-numbers is off, and giving
both is a usage error), --rehearsal-letters,
--no-wrap, --columns shared|row, --diagrams guitar (a strip of guitar
chord diagrams above the grid; --left-handed mirrors them),
--diagnostics, --part <label> to draw one part, and --font-url <url> to link the font
instead of embedding it. barmark <command> --help lists each command's
flags; barmark --version prints the versions of the CLI, every
Barmark library it runs and Verovio.
render --score writes a standalone page of the full engraved score
instead of the bar grid: the drawing <barmark-score> shows, the chart
exported to MusicXML and engraved by Verovio,
which the CLI carries (nothing else to install). The output is HTML: open
it in a browser, and print it to PDF from there. --theme colours it as
it does the grid, --part <label> engraves that part alone, and
--width <px> sets the width it is laid out for (320 to 40000; default
900, a comfortable reading width: the page scales the score to fit the
window or the paper, so the width decides how many bars go on a line,
not how big the page is). The grid's own flags (--numerals,
--bar-numbers, --no-bar-numbers, --rehearsal-letters, --no-wrap, --columns,
--diagrams, --left-handed, --diagnostics, --font-url) are usage errors with --score, and --width is one
without it. A chart that won't engrave (one with errors, or no bars)
writes nothing: the reason goes to stderr as song.chart.md: Line 5: message, and the exit code is 1. The score's text is set in Verovio's own
fonts, so Edwin is not embedded.
export --musicxml writes MusicXML 4.0 that notation programs open and
play in the chart's order; --part <label> exports one part. A chart
with errors is not exported. A chart with no title takes its file name.
import reads a MusicXML score (.musicxml, .xml or compressed .mxl)
as a chart. What the chart can't carry over is listed on stderr, one line
each, as check prints its findings: song.mxl: measure 12 (Piano): warning: message (the measure left out when the message lists the
measures itself). --part <name> (a
part's name, abbreviation or id, ignoring case and punctuation) imports
one part alone, its notes as note sets. It exits 0 when a chart came out,
even with warnings, and 1 when none did or the .mxl is bad. It does not
read stdin.
export --midi writes a Standard MIDI File of the chart's play order
(chords voiced on piano, the tempo map, markers and lyrics); --out is
required, and --part <label> exports one part. What MIDI can't hold is
listed on stderr as song.chart.md: bar 9: warning: message, such as an
open repeat (x ...) played once. Bars are numbered as the chart
numbers them: a pickup is bar 0, here and in import. A chart with errors is not exported.
import reads a MIDI file (.mid or .midi) as a chart too, naming a
chord from the notes of the tracks that carry the harmony and turning
lyric events into lyric rows. Its messages are listed on stderr as
song.mid: bar 12 (track 2): warning: message. --tracks 2,Piano
names the harmony's tracks by number or name (ignoring case) instead of
letting the import choose. A file that is one line of notes (a bass line,
a melody) is written as those notes, with their octaves and rhythm,
whichever tracks they are on; --tracks then says which tracks the line
is read from, and --chords reads chords from the file instead, as
import did before. --chords with a MusicXML score is a usage error,
as --tracks is. As for MusicXML, it exits 1 when no chart came
out.
export --lyricsheet writes the chart as a ChordPro lyric sheet, text for
any app that reads ChordPro (the usual extension is .cho), to stdout or
--out. --part <label> writes one part's chords with the singer's
words, and --diagrams guitar adds guitar chord diagrams. A chart with no
title takes its file name. What a lyric sheet can't hold goes to stderr as
song.chart.md: warning: message, each message naming its own bars. A
chart with errors is not exported.
$ barmark export --lyricsheet examples/shenandoah.chart.md
{title: Shenandoah}
{key: C}
{time: 4/4}
{comment: A simplified arrangement of the traditional song, every note a quarter.}
{start_of_verse: label="Verse"}
[*N.C.]Oh [C]Shenandoah [C]I long to hear [F]you
key reads the key a chart's chords are in (barmark's keyFromChart)
and prints it, one fact a line. First the key, clear or unsure: an
unsure read, under the library's KEY_SURE (a margin a rounding short of
it counts as clear), names the key it could be taken for. When the
chords move through more than one key, that first line names the home
key (the one held longest), and a line follows for each key (twelve at
most; --json has them all), clear or unsure on its own: about bar 21: G major, where bar 21 is the played bar the read's ten-second window
starts in, within a few bars of the change, not the bar of the change
itself. Last, the keys the chart's key: lines declare, each change in
play order (the chart says key: Eb, then G (bar 21)), and what the read
makes of them: as its chords read when every key read matches one of
them, however it is spelled (key: Gb and F# major); its chords read … when a clearly read key matches none; its chords do not settle it
when only unsure keys miss. A declared mode other than major or minor
(ionian and aeolian count as major and minor) cannot be confirmed, since
the read names only major and minor keys. It changes nothing, and exits
0 whether or not they agree: it reports. A chart with no chord symbols
prints no key: the chart has no chord symbols to read, exit 0. A
chart's problems go to stderr, as check prints them, and an error exits
1, the read printed all the same. --json prints the library's read as
it is (keys, home, homeMargin, homeRunnerUp, margin) with
declared ({ bar, key } for each declared key, empty when none) and
agrees (true, false, or null when not settled, for a modal key,
or with nothing declared or nothing read).
$ barmark key examples/blues-in-f.chart.md
F major, or G minor (unsure)
the chart says key: F, as its chords read
Exit codes
| Code | Meaning |
|---|---|
| 0 | Done (warnings are allowed unless --strict) |
| 1 | The charts have problems: an error, a warning with --strict, or a file format --check would change |
| 2 | The command was used wrongly: an unknown flag, a missing or unreadable file |
In CI
- uses: actions/setup-node@v4
with:
node-version: 22
- run: npx -y @barmark/cli@0.22.0 check --strict --format github songs
- run: npx -y @barmark/cli@0.22.0 format --check songs
Pin the version: a new release can read a chart differently, and a pinned version turns that into a pull request you review.
License
MIT. render embeds Edwin, which @barmark/render ships under the SIL
Open Font License (fonts/OFL.txt there; the binaries' release carries it
as Edwin-OFL.txt).
render --score uses Verovio,
which is LGPL-3.0-only. From npm, Verovio is an ordinary dependency
(through @barmark/score), installed and loaded unchanged. The standalone
binaries bundle it unmodified, at the version this package pins; the
release carries
its licence as Verovio-LGPL-3.0.txt and the GPL it builds on as
Verovio-GPL-3.0.txt. barmark's own code stays MIT.
Verovio © Laurent Pugin and others, LGPL-3.0-only. Its source, at the
version the binaries bundle, is
rism-digital/verovio at the matching version- tag
(barmark --version names that version). To build the binaries with
another or a modified Verovio: in a checkout of this repository, point the
verovio dependency of packages/cli and packages/score at it, run
bun install, then bun scripts/compile.ts <target> <out> (the targets
are listed in that script).