Get started

A Barmark chart is a plain-text file. Two packages read and draw it: barmark, the parser, and @barmark/render, which draws the bar grid as HTML or as a web component. The rest build on those two: @barmark/score shows the same chart as a full score beside the grid, @barmark/musicxml and @barmark/midi convert charts to and from MusicXML and MIDI, @barmark/sync and @barmark/listen line a chart up with a recording, @barmark/fretboard finds guitar chord shapes, @barmark/lyricsheet writes a chart as a ChordPro lyric sheet, and @barmark/cli puts them in the terminal, for checking charts without writing any code. The libraries are ESM, with TypeScript types, and run in Node 20 or later, Bun and the browser; the score's element runs in the browser, and its renderScoreHtml in Node or Bun. Every package is before 1.0, so pin the versions you use: each release's changes are in its changelog.

The packages

Install only what you use. Each has a step below with a short example, and its README has the whole API.

PackageWhat it doesUse it for
barmark READMEReads a chart (bars in play order, with problems by line), prints it in standard form, transposes it, converts Harte labels.Anything that reads or writes charts. The others build on it.
@barmark/render READMEDraws the bar grid, as HTML from renderChart or as the <barmark-chart> element.Showing a chart on a page. Light, with no engraver.
@barmark/score README<barmark-score>: the grid with a Grid / Score switch, the score engraved by Verovio; renderScoreHtml for servers.Readers want sheet music too, and Verovio's download on demand is acceptable.
@barmark/engraver READMEA smaller build of the same Verovio, which the score element can load from a CDN.You use the score and want it to download in under half the bytes.
@barmark/musicxml READMEExports a chart as MusicXML 4.0 and imports a score (.musicxml or .mxl) as a chart.Moving charts to and from MuseScore, Dorico, Sibelius or Finale.
@barmark/midi READMEExports a chart's play order as a MIDI file, imports a MIDI file as a chart, and gives the timed notes.Hearing a chart in a DAW or a practice player, or building a player of your own.
@barmark/cli READMEA command that checks, formats, renders, transposes, exports and imports charts, and pulls out a part.Working in a terminal or CI, with no code. Also a standalone binary.
@barmark/sync READMEWrites a chart and its timing map from a chord detector's bars and chords; reads timing maps.An audio tool that already knows where the bars and chords are.
@barmark/listen READMEFinds the bars in a recording, or reads them from a beat tracker's beats, and writes the chart; or lines a chart up with a recording. Early (0.2).An audio tool starting from the audio, which can declare the tempo and meter or has a beat tracker's reading.
@barmark/fretboard READMEFinds guitar chord shapes for Barmark chords, from a table and a shape finder, and the exact frets for notes you wrote. It draws nothing itself.Drawing chord boxes your own way, or fret numbers as text. The renderer already uses it for chord-diagrams.
@barmark/lyricsheet READMEWrites a chart as a ChordPro lyric sheet: chords over the words, with the title, key, time and tempo, and guitar chord diagrams if you ask. It says what ChordPro could not carry.A singer's sheet for any app that reads ChordPro, to show, print or transpose.

1. Write a chart

Bars sit between pipes, sections start with ##, and the key, meter and tempo are written out. Save it with the extension .chart.md: a Barmark file is a markdown file, so any markdown viewer shows it. The Syntax Guide has every rule, and you can try it in the browser.

example-song.chart.md

# Example Song
key: D, time: 4/4, tempo: 145

## Verse
|: D | A | Bm | G :|
| Em | / | A | A7 |

## Chorus
| G / D / | A | Bm / / A | G |

Rendered

2. Read it with the parser

parseChart gives you every bar in play order, with its chords, section, key, meter and tempo, and a list of problems, each with a line number. It never throws on what you type. The same package prints a chart in its standard form, transposes it, and converts chords to and from Harte labels.

Terminal

npm install barmark

app.ts

import { parseChart, printChart, transposeChart } from "barmark";

const chart = parseChart(text);
chart.title; // "Example Song"
chart.bars.length; // 16: the verse's repeat plays it twice
chart.sections.map((s) => s.name); // ["Verse", "Chorus"]
chart.diagnostics; // [] (each problem comes with its line number)

printChart("| D / A / |"); // "| D A |\n": the same music, written the standard way
transposeChart(text, { to: "E" }).text; // "… |: E | B | C#m | A :| …"

Everything it exports is in the parser's README.

3. Render it as HTML

renderChart returns the chart as HTML for a server or a static site. It carries its own styles in a declarative shadow root, so it shows without JavaScript and your page's CSS can't disturb the bars. It follows light and dark mode, scales with the reader's text size, and reads to a screen reader as music.

Terminal

npm install @barmark/render

page.ts

import { renderChart } from "@barmark/render";

// A <barmark-chart> element with its own styles: it shows with no script.
const html = renderChart(text, {
	theme: "auto", // or "light" / "dark"
	rehearsalLetters: true, // A, B, C on each section
	chordDiagrams: "guitar", // a guitar diagram for each distinct chord, above the bars (chord-diagrams="guitar" on the element)
	fontUrl: "/fonts/Edwin-Roman.otf", // copy it from @barmark/render/fonts/
});

4. Or use the web component

In the browser, <barmark-chart> draws a chart from a file, from the text inside it, or from its text property, and draws it again when any of them change. Attributes set the theme, bar numbers, rehearsal letters, a Nashville or Roman numeral view, and chord-diagrams="guitar": a strip of guitar chord diagrams under the title, above the first section, one for each distinct chord (diagram-hand="left" mirrors them for a left hand).

index.html

<script type="module">
	import "@barmark/render/element";
</script>

<barmark-chart src="/charts/example-song.chart.md"></barmark-chart>

<barmark-chart theme="dark" numerals="nashville">
	<script type="text/barmark">
		key: D
		| D | A | Bm | G |
	</script>
</barmark-chart>

For a live editor, set its text as the reader types:

editor.js

const chart = document.querySelector("barmark-chart");
editor.addEventListener("input", () => {
	chart.text = editor.value;
});

Every option and attribute is in the renderer's README.

5. Or show it as a full score

<barmark-score>, from @barmark/score, is <barmark-chart> with a Grid / Score switch above it. Score draws the same chart engraved on staves: chord symbols over rhythm slashes, a singer's melody and its lyrics as notes, and each part on a staff of its own. It takes the same sources and attributes as <barmark-chart>, plus view="score" to open on the score, and engraves again when its text changes.

Terminal

npm install @barmark/score

The example song · press Score

index.html

<script type="module">
	import "@barmark/score/element"; // registers <barmark-chart> too
</script>

<!-- The grid, with a Grid / Score switch above it -->
<barmark-score src="/charts/example-song.chart.md"></barmark-score>

<!-- Or open on the score -->
<barmark-score view="score" theme="dark">
	<script type="text/barmark">
		key: D
		| D | A | Bm | G |
	</script>
</barmark-score>

The score is the heavier of the two. Its engraver, Verovio, is several megabytes, so it loads only the first time a reader presses Score, in a background worker, and one copy serves every score on the page. A reader who stays on the grid never downloads it; when the grid is all you need, use <barmark-chart>. To have the score sooner, preload="intent" starts loading Verovio when a reader reaches for Score, and preload="idle" once the page is idle. With verovio-url and verovio-integrity it comes from a CDN, checked against its digest; the package exports jsDelivr's as VEROVIO_CDN_URL and VEROVIO_CDN_INTEGRITY.

Or load @barmark/engraver, a smaller build of the same Verovio made by Barmark: under half the download of stock, drawing the same score. Its WebAssembly is a file of its own, so it takes a second digest, verovio-wasm-integrity. The package exports jsDelivr's three as ENGRAVER_CDN_URL, ENGRAVER_CDN_INTEGRITY and ENGRAVER_WASM_INTEGRITY, which this site uses. If either file fails its digest, the element loads its own copy of stock Verovio instead.

index.html

<barmark-score
	verovio-url="https://cdn.jsdelivr.net/npm/@barmark/engraver@0.1.1/dist/verovio-module.mjs"
	verovio-integrity="sha384-klTppHZB0IPzdIOfSXNr8CbdhJU+1yp5eltjmgp8W3E8uhht5dlRy1mwrBSnmKJO"
	verovio-wasm-integrity="sha384-cBBw1xx6xHEb/I7QDrSFDgImfzzvZVvwru055NG6QbY1zHI/FFLQHjlKdtH7pr5i"
	src="/charts/example-song.chart.md"
></barmark-score>

On a server or a static site, renderScoreHtml draws the grid and the switch with no script, as renderChart does; the element takes it over in the browser.

page.ts

import { renderScoreHtml } from "@barmark/score/server";

// The grid and the switch, drawn with no script; Verovio is never loaded here.
const html = renderScoreHtml(text, {
	theme: "auto",
	fontUrl: "/fonts/Edwin-Roman.otf", // as for renderChart
});

Vite 8 draws a score with no configuration, but with verovio-url it needs worker: { format: "es" }, or the worker carries its own copy of Verovio and a reader downloads it twice. Vite 7 needs that setting in any case, and one more, so the worker can find Verovio:

vite.config.js

// vite.config.js
export default {
	worker: { format: "es" }, // Vite 8 with verovio-url; Vite 7 always
	optimizeDeps: { exclude: ["@barmark/score"] }, // Vite 7 only (harmless on Vite 8)
};

@barmark/score is MIT, like every Barmark package. It depends on Verovio, which is licensed LGPL-3.0, as an ordinary npm package, loaded unchanged, or, if you choose it, the modified build @barmark/engraver (LGPL-3.0-only, its source published with each release). A site that bundles the score ships Verovio inside its bundle; the README says how to keep it a separate file and its notice.

Without a web page, the CLI's render --score writes the same score as a page to print.

Every attribute, the worker and the licence are in the score package's README.

6. Convert to and from MusicXML

exportMusicXml writes a chart as MusicXML 4.0, so it opens in MuseScore, Dorico, Sibelius or Finale with the same bars, chords, repeats, sections and parts, and plays in the chart's play order. importMusicXml reads a score back into a chart: its chord symbols, sections, repeats and endings, parts, and a singer's melody and verses. Neither throws; what can't come over is a warning.

Terminal

npm install @barmark/musicxml

convert.ts

import { exportMusicXml, importMusicXml } from "@barmark/musicxml";

// A chart to MusicXML 4.0, for MuseScore, Dorico, Sibelius or Finale
const exported = exportMusicXml(text); // or exportMusicXml(text, { part: "Gtr" })
if (exported.ok) save("example-song.musicxml", exported.xml);

// A MusicXML score back to a chart: chord symbols, sections, repeats, parts and lyrics
const imported = importMusicXml(xml);
imported.text; // "# Example Song\nkey: D, tempo: 145\n\n## Verse\n…"
imported.diagnostics; // what didn't come over, one warning per kind

What each direction keeps is in the MusicXML package's README, with a note on compressed .mxl files.

7. Hear it as MIDI

exportMidi writes a chart's play order as a Standard MIDI File, to hear it in a DAW, a practice player or a notation program: each chord as a block chord on piano (or on its part's instrument), with the tempo map, time and key signatures, a marker for each section, and the lyrics. It is a guide to the harmony, not an arrangement. importMidi reads a MIDI file back as a chart, naming each chord from the notes that sound; repeats come back written out, and a change between beats lands on the beat. A file that is one line of notes, a bass line or a melody, comes back as that line: its notes with their octaves, holds and rests (notes: false, or import --chords from the terminal, reads chords from it instead). Neither throws: what MIDI can't hold comes back as a loss or a diagnostic, each with its bar.

Terminal

npm install @barmark/midi

midi.ts

import { exportMidi, importMidi } from "@barmark/midi";

// The chart's play order as a Standard MIDI File: a block chord a slot,
// with the tempo map, time and key signatures, section markers and lyrics
const exported = exportMidi(text); // or exportMidi(text, { part: "Gtr", tempo: 96 })
if (exported.ok) {
	save("example-song.mid", exported.bytes);
	exported.losses; // [] (what MIDI couldn't hold, such as an open repeat)
}

// A MIDI file back to a chart, each chord named from the notes that sound
// (a file that is one line of notes comes back as that line)
const imported = importMidi(bytes);
imported.text; // "# Example Song\nkey: D, time: 4/4, tempo: 145\n\n## Verse\n| D | A | Bm | G |\n…"

For a player of your own, the @barmark/midi/perform subpath gives the same performance as notes with no file: each with its pitch, velocity and time, in exact fractions of a quarter note that secondsAt turns into seconds through the tempo map. It loads none of the MIDI file code.

player.ts

import { perform, secondsAt } from "@barmark/midi/perform";
import { parseChart } from "barmark";

// The same performance with no file: timed notes, for a player to schedule
const p = perform(parseChart(text));
for (const track of p.tracks)
	for (const note of track.notes) play(note.pitch, secondsAt(p, note.at), note.velocity);
secondsAt(p, p.end); // 26.48…: 16 bars of 4/4 at 145

How each chord is voiced, swing, pushes and the pedal, and what import reads are in the MIDI package's README. Export has been checked in MuseScore 4.7.6, and other programs are untested; the CLI's export --midi does it from the terminal.

8. Check charts from the terminal

@barmark/cli is the barmark command. It checks a folder of charts and names each problem by file and line, rewrites charts in their standard form, transposes them, renders one as a page that opens in any browser (the bar grid, or the full score), exports one as MusicXML or MIDI, imports a MusicXML score or a MIDI file as a chart, and with part pulls one part out of a chart of several. It runs with npx on Node 20.6 or later, with nothing to install.

Terminal

npx @barmark/cli check songs          # every .chart.md in songs/, problems by line
npx @barmark/cli format --write songs # rewrite them in standard form
npx @barmark/cli transpose example-song.chart.md --to E
npx @barmark/cli render example-song.chart.md --out example-song.html
npx @barmark/cli render --score example-song.chart.md --out example-song-score.html  # the full score
npx @barmark/cli export --musicxml example-song.chart.md --out example-song.musicxml
npx @barmark/cli import example-song.musicxml --out imported.chart.md  # a MusicXML score as a chart
npx @barmark/cli export --midi example-song.chart.md --out example-song.mid  # for a DAW or a practice player
npx @barmark/cli import example-song.mid --out from-midi.chart.md  # chords named from the notes

Without Node, download the standalone binary for your system from the CLI's GitHub releases: one file, with the parser, the renderer, the converters and Verovio inside. Make it executable, and run it as you would barmark.

Terminal

# barmark-linux-x64, barmark-linux-arm64, barmark-darwin-x64, barmark-darwin-arm64, barmark-windows-x64.exe
chmod +x barmark-darwin-arm64
xattr -d com.apple.quarantine barmark-darwin-arm64  # macOS: the binaries aren't signed yet
./barmark-darwin-arm64 check songs

render --score writes a standalone HTML page of the full engraved score, the one <barmark-score> shows: open it in a browser and print it to PDF from there. --width sets the width it is laid out for (320 to 40000 pixels, 900 by default), which decides how many bars go on a line, and --part engraves one part alone. Verovio is built into the CLI and its standalone binaries, so there is nothing else to install; it is LGPL-3.0, and the binaries' release carries its licence as Verovio-LGPL-3.0.txt.

In CI it keeps a repository of charts readable: a chart with a mistake fails the build, and on GitHub each problem is marked on its line in the pull request. Pin the version, so a new release arrives as a change you review.

.github/workflows/check.yml

- uses: actions/setup-node@v4
  with:
    node-version: 22
- run: npx -y @barmark/cli@0.15.1 check --strict --format github songs
- run: npx -y @barmark/cli@0.15.1 format --check songs

Every command and flag is in the CLI's README, and kevinpeckham/songs is a repository of charts checked this way.

9. Sync a chart with a recording

@barmark/sync is for audio tools. chartFromDetections takes what a chord detector hears in a recording, its bar starts and chord runs in seconds, and writes a chart from it, with the title, sections, key, meter and tempo it is given. Beside the chart it returns a timing map, which says when each played bar starts, so a player can show the bar that is sounding or jump to a bar. It never throws; what it changed or couldn't use comes back as a diagnostic.

Terminal

npm install @barmark/sync

sync.ts

import { barAt, chartFromDetections, secondsAtBar } from "@barmark/sync";

// A chord detector's output: bar starts and chord runs, in seconds
const { chart, timing, diagnostics } = chartFromDetections({
	title: "Example Song",
	grid: { bars: [0, 2, 4, 6, 8] },
	meter: "4/4",
	sections: [{ name: "Verse", start: 0 }],
	chords: {
		runs: [
			{ start: 0, end: 4, label: "D:maj" },
			{ start: 4, end: 6, label: "A:maj" },
			{ start: 6, end: 8, label: "B:min" },
		],
	},
});
chart; // "# Example Song\ntime: 4/4, tempo: 120\n\n## Verse\n| D | / | A | Bm |\n"

// The timing map places each played bar in the recording (null if the grid is unusable)
if (timing) {
	secondsAtBar(timing, 3); // 4
	barAt(timing, 5); // { entry: 2, bar: 3, fraction: 0.5 }
}
diagnostics; // what the builder changed or couldn't use, each with a code

A player that only reads timing maps can import barAt and secondsAtBar from @barmark/sync/timing, which leaves the builder out.

The input it reads, the timing map's format and every diagnostic are in the sync package's README.

10. Or start from the recording

@barmark/listen is the newest package, at 0.2: the recording-to-chart code of Stem Shovel, ported with the app's arithmetic in the app's order, so the app and other tools run one copy. From a recording's samples and a chord model's runs, chartFromRecording finds the bar lines and bar one, then writes the chart and its timing map with @barmark/sync. alignChart lines up a chart you already have with a recording instead.

It detects neither chords, nor tempo, nor meter. The chords come from a chord model of your own, and you declare the tempo and meter: a wrong one gives a faithful chart on the wrong bars, so treat what it writes as a draft for a person to check. Every call returns a result or its refusals, and never throws.

Terminal

npm install @barmark/listen

listen.ts

import { alignChart, chartFromRecording } from "@barmark/listen";

// Mono samples, and your chord model's runs in seconds (sync's ChordRuns)
const built = chartFromRecording({
	samples,
	sampleRate: 44100,
	chords: { runs },
	declared: { meter: "4/4", tempo: 120 }, // required: it detects neither
	title: "Example Song",
});
if (built.ok) {
	const { chart, timing, features } = built.value;
	chart; // "# Example Song\ntime: 4/4, tempo: 120\n| D | A | Bm | G |\n…"
	timing; // when each played bar starts, as @barmark/sync's maps say

	// Or line up a chart you already have with the same recording
	const aligned = alignChart({ chart: text, features });
	if (aligned.ok) aligned.value.timing;
} else {
	built.refusals; // why not: every rule that failed, not the first only
}

Or bring a beat tracker. If a model of yours already finds the beats and the downbeats, chartFromBeats takes them as plain lists of seconds and needs no audio: the downbeats give the bar lines, the meter comes from the usual count of beats in a bar (4/4, 3/4 or 6/8), and the tempo from the bars themselves. You declare nothing. It runs no tracker of its own, as it runs no chord model.

A reading with too few bars, or one whose bars settle on no count of beats, is refused by name, with the numbers beside it. Up to half a bar of beats before the first downbeat is written as a pickup bar. The meter is one label for the whole piece, so a song in 5/4 or 7/4 reads as 4/4: check the draft.

beats.ts

import { chartFromBeats } from "@barmark/listen";

// A beat tracker's reading in seconds, and your chord model's runs
const drafted = chartFromBeats({
	beats, // [0, 0.5, 1, 1.5, 2, …]
	downbeats, // [0, 2, 4, …]: the first beat of each bar
	duration: 24, // seconds of audio the tracker read
	chords: { runs },
	title: "Example Song",
});
if (drafted.ok) {
	const { chart, timing, grid } = drafted.value;
	chart; // "# Example Song\ntime: 4/4, tempo: 120\n| D | A | Bm | G |\n…"
	timing; // when each played bar starts, on the tracker's bars
	grid.meter; // "4/4", from the usual count of beats in a bar
	grid.reading.beatsPerBar; // 4
} else {
	drafted.refusals; // "too-few-bars" or "bars-unsteady": no fallback inside,
	// so call chartFromRecording yourself if you can declare a tempo
}

The features it reads, each option and every refusal are in the listen package's README.

11. Find guitar chord shapes

@barmark/fretboard answers where the fingers go. shapeFor takes a chord the parser read and gives its frets in standard tuning, from a table of the usual open and movable shapes or, past it, a shape finder; a note set comes back exactly as written, each note on its own string. It draws nothing: the renderer's chord-diagrams="guitar" draws its shapes, and you can draw chord boxes of your own, or write the frets as text. It never throws.

Terminal

npm install @barmark/fretboard

shapes.ts

import { shapeFor, shapeText } from "@barmark/fretboard";
import { parseChord } from "barmark";

const chord = parseChord("Cmaj7");
if (chord.ok) {
	const result = shapeFor(chord.value);
	if (result.ok) {
		result.shape.frets; // [-1, 3, 2, 0, 0, 0]: low E to high E, -1 muted
		shapeText(result.shape); // "x32000"
	} else {
		result.reason; // "single-note" or "not-playable": no shape to show
	}
}

What a shape holds, how an altered chord becomes a shell and what it cannot find are in the fretboard package's README.

12. Write a lyric sheet

@barmark/lyricsheet writes a chart as a singer's lyric sheet: the chords over the words, with the title, key, time and tempo, in the text format ChordPro reads, so any app that reads ChordPro can show, print or transpose it. ChordPro is a separate project: this package only writes text for it. With diagrams: "guitar" it adds a guitar shape for every chord, from @barmark/fretboard. It never throws.

Terminal

npm install @barmark/lyricsheet

lyricsheet.ts

import { exportLyricsheet } from "@barmark/lyricsheet";

const result = exportLyricsheet(text, { diagrams: "guitar" });
if (result.ok) {
	result.text; // the ChordPro sheet, ready to save as song.cho
	result.losses; // what ChordPro could not carry, each with a code: [] here
} else {
	result.diagnostics; // why not: the chart's errors, each with its line number
}

It takes the chart's text, not the parsed chart. For this verse, with the words written under its four bars:

ferry-lights.chart.md

# Ferry Lights
key: G, time: 4/4

## Verse
| G | Cm | G | D |
lyrics: | Down / by the | riv- er | wait- ing | / |

it writes this, with diagrams on:

ferry-lights.cho

{title: Ferry Lights}
{key: G}
{time: 4/4}

{define: G base-fret 1 frets 3 2 0 0 0 3}
{define: Cm base-fret 3 frets x 1 3 3 2 1}
{define: D base-fret 1 frets x x 0 2 3 2}

{start_of_verse: label="Verse"}
[G]Down by the [Cm]river [G]waiting [D]
{end_of_verse}

A lyric sheet keeps the order of the chords and words, not their timing. What ChordPro cannot hold, such as a church mode or a part other than the one written, comes back in losses, each with a code, most with the bars it happened in. From a terminal, barmark export --lyricsheet song.chart.md --out song.cho does the same, with @barmark/cli 0.14.0 or later.

Every loss, the grid sections for bars with no words and the guitar diagram rules are in the lyricsheet package's README.