barmark 0.13.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -9,6 +9,39 @@ Releases follow the process in [RELEASING.md](RELEASING.md).
9
9
 
10
10
  ## [Unreleased]
11
11
 
12
+ ## [0.14.0] - 2026-11-03
13
+
14
+ ### Added
15
+
16
+ - **Several parts in one chart** (grammar 7.4): one `part: Label = Name`
17
+ line per part, bar lines labelled with their part (`Gtr | G | C |`),
18
+ and **systems**: consecutive labelled lines that share bars, one per
19
+ part. A part missing from a system is tacet; an unlabelled line is
20
+ tutti. Every line of a system writes the same bars and structure
21
+ (repeats, endings, marks, directions, fermatas, one-bar meters), and
22
+ the reader checks it. `%` and a leading `/` resolve per part, in
23
+ written order; after the part was tacet they are errors.
24
+ - The parse gains `parts` (score order); in a multi-part chart each
25
+ played bar gains `parts` (`{ line, slots, words? }` per part, null
26
+ where tacet), and `tacet: true` where the first part rests (its slots
27
+ then read `N.C.`). Lines gain `part` and `system`.
28
+ - `extractPart(text, label)`, `printPart(text, label)` and
29
+ `projectPart(lines, parts, label)`: one part as a single-part chart.
30
+ - `printChart` prints a system in score order with its labels padded and
31
+ its pipes lined up.
32
+ - A bar line after a word that is not a declared part (`Bass | E | A |`)
33
+ is text with a warning, in any chart; one whose first word is a chord
34
+ (`G | C | D |`) warns that a bar line starts with `|` and suggests
35
+ `| G | C | D |`.
36
+
37
+ ### Changed
38
+
39
+ - A second `part:` line is no longer an error. `ChartParse.part` is the
40
+ one part of a single-part chart (null for several) and is deprecated
41
+ in favour of `parts`.
42
+ - Several parts share the expansion budget: each part expands at most
43
+ `MAX_EXPANDED_BARS / parts` bars.
44
+
12
45
  ## [0.13.0] - 2026-11-03
13
46
 
14
47
  ### Added
@@ -317,7 +350,8 @@ The first working release: the reference parser and printer for the
317
350
 
318
351
  - **A placeholder package that holds the `barmark` name** while the spec and parser are written.
319
352
 
320
- [Unreleased]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.13.0...HEAD
353
+ [Unreleased]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.14.0...HEAD
354
+ [0.14.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.13.0...barmark-v0.14.0
321
355
  [0.13.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.12.0...barmark-v0.13.0
322
356
  [0.12.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.11.0...barmark-v0.12.0
323
357
  [0.11.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.10.0...barmark-v0.11.0
package/README.md CHANGED
@@ -37,17 +37,20 @@ declarations included and no runtime dependencies.
37
37
  ```ts
38
38
  import {
39
39
  degreeOf,
40
+ extractPart,
40
41
  harteToBarmark,
41
42
  parseChart,
42
43
  parseChord,
43
44
  printChart,
44
45
  printParsed,
46
+ printPart,
47
+ projectPart,
45
48
  transposeChart,
46
49
  } from "barmark";
47
50
 
48
51
  const chart = parseChart(text);
49
52
  chart.title; // "Example Song"
50
- chart.part; // { name: "Electric Guitar 1", label: "Gtr" } from part: Gtr = Electric Guitar 1, or null
53
+ chart.parts; // [{ label: "Gtr", name: "Electric Guitar 1" }] from part: Gtr = Electric Guitar 1, in score order
51
54
  chart.bars; // every bar in play order: its number as written, slots, section, key, meter, tempo, feel (and swingPercent)
52
55
  chart.sections; // each section as played, with its first and last bar
53
56
  chart.diagnostics; // errors and warnings, each with a line number
@@ -67,6 +70,35 @@ if (chord.ok) chord.value.harte; // "B:hdim7"
67
70
  harteToBarmark("A:sus4(b7,9)"); // "A9sus4"
68
71
  ```
69
72
 
73
+ ### Several parts
74
+
75
+ ```
76
+ part: Gtr = Electric Guitar 1
77
+ part: Pno = Piano
78
+
79
+ Gtr | G | C | G | D |
80
+ Pno | G/B | C | Em | D |
81
+ | C | G | D | G |
82
+ ```
83
+
84
+ A chart with several `part:` lines writes **systems** (grammar 7.4):
85
+ labelled lines that share bars, one per part. A part missing from a
86
+ system is tacet there; an unlabelled line is tutti, played by every part.
87
+
88
+ ```ts
89
+ const chart = parseChart(text);
90
+ chart.bars[0].parts; // [{ line, slots, words? }, …] per part, in score order; null where tacet
91
+ chart.bars[0].slots; // the first part's slots (N.C., with tacet: true, where it is tacet)
92
+
93
+ extractPart(text, "Pno"); // one part as a single-part ChartParse, or null
94
+ printPart(text, "Pno"); // the same as text: tacet bars written N.C.
95
+ projectPart(chart.lines, chart.parts, "Pno"); // one part's lines
96
+ ```
97
+
98
+ `printChart` sorts a system into score order and lines up its pipes.
99
+ `chart.part` still gives the one part of a single-part chart, and is
100
+ deprecated in favour of `parts`.
101
+
70
102
  - **`parseChart`** never throws. A line with an error is left out of the
71
103
  play order and reported, and the rest of the chart still reads.
72
104
  - **`printChart`** changes spelling and layout only: lines with errors and
@@ -8,6 +8,7 @@ export declare const isBar: (c: Cell) => c is {
8
8
  meter: Meter | null;
9
9
  slots: Slot[];
10
10
  words?: Words[];
11
+ tacet?: true;
11
12
  } | {
12
13
  kind: "simile";
13
14
  words?: Words[];
@@ -3,6 +3,7 @@ import type { ChartDiagnostic, Line, Part } from "./types.js";
3
3
  export declare function readDocument(text: string): {
4
4
  title: string | null;
5
5
  part: Part | null;
6
+ parts: Part[];
6
7
  lines: Line[];
7
8
  diagnostics: ChartDiagnostic[];
8
9
  };
@@ -1,6 +1,7 @@
1
1
  import { parseChord } from "../chords/parse.js";
2
2
  import { misplacedRepeat, parseBarLine, readRepeat, repeatTail } from "./barLine.js";
3
3
  import { parseDirectiveLine } from "./directives.js";
4
+ import { groupSystems } from "./systems.js";
4
5
  const NEAR_DIRECTIVES = {
5
6
  meter: "time",
6
7
  signature: "time",
@@ -24,8 +25,46 @@ function readPart(text) {
24
25
  const [, label, name] = labelled;
25
26
  if (!label)
26
27
  return "part: needs a label before =";
28
+ if (/^[|#@0-9]/.test(label))
29
+ return "a part label can't start with |, #, @ or a digit";
27
30
  return name ? { label, name } : "part: needs a name after the label";
28
31
  }
32
+ /**
33
+ * Several parts each need a label, and no two may share one in any case
34
+ * (grammar 7.4). A part that breaks either rule is text, with the error.
35
+ */
36
+ function checkParts(lines, diagnostics) {
37
+ const declared = lines.filter((l) => l.kind === "part");
38
+ if (declared.length < 2)
39
+ return declared.map(partOf);
40
+ const seen = new Map();
41
+ const parts = [];
42
+ for (const l of declared) {
43
+ const problem = partProblem(l, seen);
44
+ if (!problem) {
45
+ parts.push(partOf(l));
46
+ continue;
47
+ }
48
+ const text = l.label ? `part: ${l.label} = ${l.name}` : `part: ${l.name}`;
49
+ diagnostics.push({ line: l.line, severity: "error", token: text, ...problem });
50
+ lines[lines.indexOf(l)] = { kind: "text", line: l.line, text };
51
+ }
52
+ return parts;
53
+ }
54
+ const partOf = (l) => (l.label ? { label: l.label, name: l.name } : { name: l.name });
55
+ function partProblem(l, seen) {
56
+ if (!l.label)
57
+ return {
58
+ message: "a chart with several parts labels each one",
59
+ suggestion: `part: Label = ${l.name}`,
60
+ };
61
+ const key = l.label.toLowerCase();
62
+ const first = seen.get(key);
63
+ if (first)
64
+ return { message: `two parts share the label ${first}` };
65
+ seen.set(key, l.label);
66
+ return null;
67
+ }
29
68
  function readHeading(text, line, diagnostics) {
30
69
  let rest = text.trim();
31
70
  const elided = /(->|→)$/.test(rest);
@@ -63,6 +102,41 @@ function readHeading(text, line, diagnostics) {
63
102
  });
64
103
  return { kind: "section", line, name: rest, repeat, elided };
65
104
  }
105
+ /** A label and the bar line after it: `Gtr | G |` (grammar 7.4). */
106
+ const LABELLED = /^([^\s|]+)(\s*)(\|.*)$/;
107
+ const readsCleanly = (barLine) => {
108
+ const read = parseBarLine(barLine, 0);
109
+ return Boolean(read.bars) && read.diagnostics.length === 0;
110
+ };
111
+ /** `G | C | D |`: a bar line with its leading pipe left off. */
112
+ function missingPipe(text, line) {
113
+ const fixed = `| ${text}`;
114
+ if (!readsCleanly(fixed))
115
+ return null;
116
+ return {
117
+ line,
118
+ severity: "warning",
119
+ message: "a bar line starts with |",
120
+ token: text,
121
+ suggestion: fixed,
122
+ };
123
+ }
124
+ /** A warning when a word before a clean bar line is not a declared part (grammar 7.4). */
125
+ function undeclaredLabel(text, line) {
126
+ const m = LABELLED.exec(text);
127
+ if (!m?.[1] || !m[3])
128
+ return null;
129
+ if (parseChord(m[1]).ok)
130
+ return missingPipe(text, line);
131
+ if (!readsCleanly(m[3]))
132
+ return null;
133
+ return {
134
+ line,
135
+ severity: "warning",
136
+ message: `${m[1]} is not a part of this chart; declare it with part: ${m[1]} = …`,
137
+ token: m[1],
138
+ };
139
+ }
66
140
  /** A warning when a text line looks like an older chart format. */
67
141
  function oldFormat(text, line) {
68
142
  const warn = (message, suggestion) => ({
@@ -79,6 +153,9 @@ function oldFormat(text, line) {
79
153
  const name = near?.[1] ? NEAR_DIRECTIVES[near[1].toLowerCase()] : undefined;
80
154
  if (near && name)
81
155
  return warn(`not a directive; did you mean ${name}:?`, `${name}: ${near[2]}`);
156
+ const undeclared = undeclaredLabel(text, line);
157
+ if (undeclared)
158
+ return undeclared;
82
159
  const unescaped = escapedBarLine(text);
83
160
  if (unescaped)
84
161
  return warn("escaped pipes; a bar line uses a plain |", unescaped);
@@ -118,7 +195,6 @@ export function readDocument(text) {
118
195
  const lines = [];
119
196
  const diagnostics = [];
120
197
  let title = null;
121
- let part = null;
122
198
  /** The line kept as text, with why it isn't what it looks like. */
123
199
  const asText = (t, line, severity, message) => {
124
200
  diagnostics.push({ line, severity, message, token: t });
@@ -136,9 +212,6 @@ export function readDocument(text) {
136
212
  return asText(t, line, "error", read);
137
213
  if (lines.some((l) => l.kind === "bars" || l.kind === "invalid"))
138
214
  return asText(t, line, "error", "part: names the whole chart; put it before the first bar");
139
- if (part)
140
- return asText(t, line, "error", "a chart names one part; several parts are not supported yet");
141
- part = read;
142
215
  return { kind: "part", line, ...read };
143
216
  };
144
217
  const otherLine = (t, line) => {
@@ -155,12 +228,47 @@ export function readDocument(text) {
155
228
  diagnostics.push(old);
156
229
  return { kind: "text", line, text: t };
157
230
  };
158
- const classify = (t, line) => {
159
- if (t.startsWith("|")) {
160
- const r = parseBarLine(t, line);
161
- diagnostics.push(...r.diagnostics);
162
- return r.bars ?? { kind: "invalid", line, text: t, written: r.written };
231
+ const barLine = (t, line) => {
232
+ const r = parseBarLine(t, line);
233
+ diagnostics.push(...r.diagnostics);
234
+ return r.bars ?? { kind: "invalid", line, text: t, written: r.written };
235
+ };
236
+ /** A declared part's bar line; labelled only when the chart has several parts. */
237
+ const labelledLine = (t, line) => {
238
+ const m = LABELLED.exec(t);
239
+ const declared = lines.filter((l) => l.kind === "part");
240
+ const found = declared.find((p) => p.label?.toLowerCase() === m?.[1]?.toLowerCase());
241
+ if (!m || !found?.label)
242
+ return null;
243
+ const [, word = "", space, rest = ""] = m;
244
+ if (!space) {
245
+ diagnostics.push({
246
+ line,
247
+ severity: "error",
248
+ message: "a space goes between the label and |",
249
+ token: t,
250
+ suggestion: `${word} ${rest}`,
251
+ });
252
+ const written = parseBarLine(rest, line).written;
253
+ return {
254
+ kind: "invalid",
255
+ line,
256
+ text: t,
257
+ written,
258
+ ...(declared.length > 1 && { part: found.label }),
259
+ };
163
260
  }
261
+ const read = barLine(rest, line);
262
+ if (declared.length < 2 || (read.kind !== "bars" && read.kind !== "invalid"))
263
+ return read;
264
+ return { ...read, part: found.label };
265
+ };
266
+ const classify = (t, line) => {
267
+ if (t.startsWith("|"))
268
+ return barLine(t, line);
269
+ const labelled = labelledLine(t, line);
270
+ if (labelled)
271
+ return labelled;
164
272
  if (t.startsWith("# "))
165
273
  return titleLine(t, line);
166
274
  if (t === "##" || t.startsWith("## "))
@@ -178,5 +286,14 @@ export function readDocument(text) {
178
286
  const empty = noBarLines(lines);
179
287
  if (empty)
180
288
  diagnostics.push(empty);
181
- return { title, part, lines, diagnostics };
289
+ const parts = checkParts(lines, diagnostics);
290
+ const grouped = parts.length > 1 ? groupSystems(lines) : { lines, diagnostics: [] };
291
+ diagnostics.push(...grouped.diagnostics);
292
+ return {
293
+ title,
294
+ part: parts.length === 1 ? (parts[0] ?? null) : null,
295
+ parts,
296
+ lines: grouped.lines,
297
+ diagnostics,
298
+ };
182
299
  }
@@ -7,7 +7,11 @@ export declare function flattenBars(events: ChartEvent[]): PlayedBar[];
7
7
  * Turn the written chart into the bars in play order: sections and their
8
8
  * replays, repeats, directive changes, `%` and elision.
9
9
  */
10
- export declare function expand(lines: Line[]): {
10
+ /**
11
+ * `label` names the part a projected chart is (grammar 7.4), for its
12
+ * messages; `share` is how many parts split the expansion budget.
13
+ */
14
+ export declare function expand(lines: Line[], label?: string, share?: number): {
11
15
  events: ChartEvent[];
12
16
  sections: SectionOccurrence[];
13
17
  diagnostics: ChartDiagnostic[];
@@ -3,8 +3,6 @@ import { beatsOf } from "./directives.js";
3
3
  import { pairRepeats } from "./repeats.js";
4
4
  /** Nested repeats multiply; expansion stops here rather than run away. */
5
5
  export const MAX_EXPANDED_BARS = 10_000;
6
- /** Repeats of bodies that play no bars (fermatas only) are bounded too. */
7
- const MAX_WORK = MAX_EXPANDED_BARS * 10;
8
6
  /**
9
7
  * How each mark moves play along. A mark the jump does not use is an error
10
8
  * that drops the jump, so with a jump planned every mark here applies.
@@ -79,8 +77,15 @@ function removeLastBar(events) {
79
77
  * Turn the written chart into the bars in play order: sections and their
80
78
  * replays, repeats, directive changes, `%` and elision.
81
79
  */
82
- export function expand(lines) {
80
+ /**
81
+ * `label` names the part a projected chart is (grammar 7.4), for its
82
+ * messages; `share` is how many parts split the expansion budget.
83
+ */
84
+ export function expand(lines, label, share = 1) {
83
85
  const diagnostics = [];
86
+ const maxBars = Math.max(1, Math.floor(MAX_EXPANDED_BARS / share));
87
+ // Repeats of bodies that play no bars (fermatas only) are bounded too.
88
+ const maxWork = maxBars * 10;
84
89
  // The return after a jump plays sections again: it reports only what the first pass did not.
85
90
  const reported = new Set();
86
91
  let again = false;
@@ -101,6 +106,7 @@ export function expand(lines) {
101
106
  // % copies the bar written before it, one-bar meter included, so a section plays the same wherever it is replayed.
102
107
  const resolved = new Map();
103
108
  let previous = null;
109
+ const tacetBefore = (line, what) => error(line, `${label ?? "this part"} was tacet in the bar before; ${what}`, what.slice(0, 1));
104
110
  let written = 0;
105
111
  /** A rehearsal mark waiting for the bar after it (grammar 2.5). */
106
112
  const pending = { mark: null };
@@ -123,22 +129,33 @@ export function expand(lines) {
123
129
  const simile = (c, line) => {
124
130
  if (!previous)
125
131
  error(line, "% has no bar before it to repeat", "%");
132
+ else if (previous.tacet)
133
+ tacetBefore(line, "% has nothing to copy");
126
134
  const meter = previous?.meter ?? null;
127
135
  const slots = previous?.slots ?? [{ kind: "hold" }];
128
136
  return marked({ kind: "bar", meter, slots, own: false, written: ++written }, c.words);
129
137
  };
130
- const ownBar = (c, line) => {
138
+ /** A bar that opens with `/` holds what was sounding before it. */
139
+ const checkHold = (c, line) => {
131
140
  const first = c.slots[0];
132
141
  const head = first?.kind === "group" ? first.members[0] : first;
133
- if (!previous && head?.kind === "hold")
142
+ if (head?.kind !== "hold")
143
+ return;
144
+ if (!previous)
134
145
  error(line, "/ has nothing before it to hold", "/");
135
- previous = { meter: c.meter, slots: c.slots };
146
+ else if (previous.tacet)
147
+ tacetBefore(line, "/ has nothing to hold");
148
+ };
149
+ const ownBar = (c, line) => {
150
+ checkHold(c, line);
151
+ previous = { meter: c.meter, slots: c.slots, ...(c.tacet && { tacet: c.tacet }) };
136
152
  const bar = {
137
153
  kind: "bar",
138
154
  meter: c.meter,
139
155
  slots: c.slots,
140
156
  own: true,
141
157
  written: ++written,
158
+ ...(c.tacet && { tacet: c.tacet }),
142
159
  };
143
160
  return marked(bar, c.words);
144
161
  };
@@ -218,7 +235,7 @@ export function expand(lines) {
218
235
  const checked = new Set();
219
236
  const stop = (line) => {
220
237
  capped = true;
221
- error(line, `expansion stopped at ${MAX_EXPANDED_BARS} bars`, "x");
238
+ error(line, `expansion stopped at ${maxBars} bars`, "x");
222
239
  };
223
240
  let sectionName = null;
224
241
  let phase = "main";
@@ -254,6 +271,7 @@ export function expand(lines) {
254
271
  slots: p.slots,
255
272
  ...(p.rehearsal === undefined ? {} : { rehearsal: p.rehearsal }),
256
273
  ...(p.words === undefined ? {} : { words: p.words }),
274
+ ...(p.tacet && { tacet: p.tacet }),
257
275
  };
258
276
  };
259
277
  /** How long the slot played just before is, in whole notes; null after a fermata or at the start. */
@@ -278,13 +296,13 @@ export function expand(lines) {
278
296
  return direct(p.direction);
279
297
  if (seeking())
280
298
  return;
281
- if (++work > MAX_WORK)
299
+ if (++work > maxWork)
282
300
  return stop(line);
283
301
  if (p.kind === "fermata") {
284
302
  before.length = null;
285
303
  return void out.push({ kind: "fermata", line });
286
304
  }
287
- if (count >= MAX_EXPANDED_BARS)
305
+ if (count >= maxBars)
288
306
  return stop(line);
289
307
  count++;
290
308
  const bar = barOf(p, line);
@@ -311,7 +329,7 @@ export function expand(lines) {
311
329
  // After the jump every repeat plays once.
312
330
  const passes = phase === "main" ? (repeat ?? 1) : 1;
313
331
  for (let i = 0; i < passes && !stopped(); i++) {
314
- if (++work > MAX_WORK)
332
+ if (++work > maxWork)
315
333
  return stop(line);
316
334
  body(out);
317
335
  }
@@ -346,7 +364,7 @@ export function expand(lines) {
346
364
  const highest = typeof it.repeat === "number" ? it.repeat : 1;
347
365
  const first = phase === "main" ? 1 : highest;
348
366
  for (let pass = first; pass <= highest && !stopped(); pass++) {
349
- if (++work > MAX_WORK)
367
+ if (++work > maxWork)
350
368
  return stop(it.line);
351
369
  for (const e of it.entries)
352
370
  playLine(e, out);
@@ -4,7 +4,8 @@ export { printDirection } from "./direction.js";
4
4
  export { beatsOf, DIRECTIVE_NAMES, parseDirectiveLine, parseMeter } from "./directives.js";
5
5
  export { readDocument } from "./document.js";
6
6
  export { expand, flattenBars, MAX_EXPANDED_BARS } from "./expand.js";
7
- export { parseChart } from "./parse.js";
8
- export { printCell, printChart, printLine, printParsed, printPasses, printSlot, reduceSlots, } from "./print.js";
7
+ export { extractPart, parseChart } from "./parse.js";
8
+ export { projectPart } from "./parts.js";
9
+ export { printCell, printChart, printLine, printParsed, printPart, printPasses, printSlot, reduceSlots, } from "./print.js";
9
10
  export { type TransposeBy, transposeChart } from "./transpose.js";
10
11
  export type * from "./types.js";
@@ -4,6 +4,7 @@ export { printDirection } from "./direction.js";
4
4
  export { beatsOf, DIRECTIVE_NAMES, parseDirectiveLine, parseMeter } from "./directives.js";
5
5
  export { readDocument } from "./document.js";
6
6
  export { expand, flattenBars, MAX_EXPANDED_BARS } from "./expand.js";
7
- export { parseChart } from "./parse.js";
8
- export { printCell, printChart, printLine, printParsed, printPasses, printSlot, reduceSlots, } from "./print.js";
7
+ export { extractPart, parseChart } from "./parse.js";
8
+ export { projectPart } from "./parts.js";
9
+ export { printCell, printChart, printLine, printParsed, printPart, printPasses, printSlot, reduceSlots, } from "./print.js";
9
10
  export { transposeChart } from "./transpose.js";
@@ -1,3 +1,9 @@
1
1
  import type { ChartParse } from "./types.js";
2
2
  /** Read a whole barmark chart: the document as written and the bars in play order. Never throws. */
3
3
  export declare function parseChart(text: string): ChartParse;
4
+ /**
5
+ * One part of a chart as a single-part chart (grammar 7.4): the tutti bars,
6
+ * its own bars, and `N.C.` marked `tacet` where it rests. Null when the
7
+ * chart declares no part with that label. Never throws.
8
+ */
9
+ export declare function extractPart(text: string, label: string): ChartParse | null;
@@ -1,18 +1,106 @@
1
1
  import { readDocument } from "./document.js";
2
2
  import { expand, flattenBars } from "./expand.js";
3
+ import { projectPart } from "./parts.js";
4
+ const RANK = { error: 0, warning: 1 };
5
+ /** Sorted by line, errors before warnings. */
6
+ const sortDiagnostics = (all) => all.sort((a, b) => a.line - b.line || RANK[a.severity] - RANK[b.severity]);
7
+ const keyOf = (d) => `${d.line}\u0000${d.severity}\u0000${d.message}`;
8
+ /** What every part reported, a problem the parts share once: each kept as often as one part reports it. */
9
+ function mergeReports(each) {
10
+ const most = new Map();
11
+ for (const list of each) {
12
+ const mine = new Map();
13
+ for (const d of list)
14
+ mine.set(keyOf(d), [...(mine.get(keyOf(d)) ?? []), d]);
15
+ for (const [k, ds] of mine)
16
+ if (ds.length > (most.get(k)?.length ?? 0))
17
+ most.set(k, ds);
18
+ }
19
+ return [...most.values()].flat();
20
+ }
21
+ const partBar = (b) => b.tacet ? null : { line: b.line, slots: b.slots, ...(b.words && { words: b.words }) };
22
+ /** One bar of every part: shared fields from the first, the meter from the first that plays. */
23
+ function zipBar(bars, report) {
24
+ const [first, ...rest] = bars;
25
+ const playing = bars.filter((b) => !b.tacet);
26
+ const meter = playing[0]?.meter ?? first.meter;
27
+ if (playing.some((b) => b.meter.n !== meter.n || b.meter.d !== meter.d))
28
+ report({
29
+ line: playing[1]?.line ?? first.line,
30
+ severity: "error",
31
+ message: "the parts disagree on this bar's meter",
32
+ token: "|",
33
+ });
34
+ return { ...first, meter, parts: [first, ...rest].map(partBar) };
35
+ }
36
+ /** Each part's events, played in lockstep: the shapes match because every line of a system shares its structure. */
37
+ function zipEvents(each, report) {
38
+ const [lead = []] = each;
39
+ return lead.map((e, i) => {
40
+ const peers = each.map((events) => events[i] ?? e);
41
+ if (e.kind === "bar")
42
+ return {
43
+ kind: "bar",
44
+ bar: zipBar(peers.map((p) => (p.kind === "bar" ? p.bar : e.bar)), report),
45
+ };
46
+ if (e.kind === "open")
47
+ return {
48
+ ...e,
49
+ events: zipEvents(peers.map((p) => (p.kind === "open" ? p.events : e.events)), report),
50
+ };
51
+ return e;
52
+ });
53
+ }
54
+ /** Several parts: each projected and played, then zipped into one timeline (grammar 7.4). */
55
+ function playParts(lines, parts) {
56
+ const played = parts.map((p) => expand(projectPart(lines, parts, p.label ?? ""), p.label, parts.length));
57
+ const diagnostics = mergeReports(played.map((p) => p.diagnostics));
58
+ const events = zipEvents(played.map((p) => p.events), (d) => diagnostics.push(d));
59
+ return { events, sections: played[0]?.sections ?? [], diagnostics };
60
+ }
3
61
  /** Read a whole barmark chart: the document as written and the bars in play order. Never throws. */
4
62
  export function parseChart(text) {
5
63
  const doc = readDocument(text);
6
- const played = expand(doc.lines);
7
- const rank = { error: 0, warning: 1 };
8
- const diagnostics = [...doc.diagnostics, ...played.diagnostics].sort((a, b) => a.line - b.line || rank[a.severity] - rank[b.severity]);
64
+ const played = doc.parts.length > 1 ? playParts(doc.lines, doc.parts) : expand(doc.lines);
9
65
  return {
10
66
  title: doc.title,
11
67
  part: doc.part,
68
+ parts: doc.parts,
12
69
  lines: doc.lines,
13
70
  events: played.events,
14
71
  bars: flattenBars(played.events),
15
72
  sections: played.sections,
16
- diagnostics,
73
+ diagnostics: sortDiagnostics([...doc.diagnostics, ...played.diagnostics]),
74
+ };
75
+ }
76
+ /**
77
+ * One part of a chart as a single-part chart (grammar 7.4): the tutti bars,
78
+ * its own bars, and `N.C.` marked `tacet` where it rests. Null when the
79
+ * chart declares no part with that label. Never throws.
80
+ */
81
+ export function extractPart(text, label) {
82
+ const doc = readDocument(text);
83
+ const part = doc.parts.find((p) => p.label?.toLowerCase() === label.toLowerCase());
84
+ if (!part)
85
+ return null;
86
+ const lines = doc.parts.length > 1 ? projectPart(doc.lines, doc.parts, label) : doc.lines;
87
+ const played = expand(lines, part.label);
88
+ const kept = new Set(lines.map((l) => l.line));
89
+ // A stand-in may sit on another part's line; that part's problems are not this one's.
90
+ for (const l of doc.lines)
91
+ if ((l.kind === "bars" || l.kind === "invalid") && l.part && l.part !== part.label)
92
+ kept.delete(l.line);
93
+ return {
94
+ title: doc.title,
95
+ part,
96
+ parts: [part],
97
+ lines,
98
+ events: played.events,
99
+ bars: flattenBars(played.events),
100
+ sections: played.sections,
101
+ diagnostics: sortDiagnostics([
102
+ ...doc.diagnostics.filter((d) => kept.has(d.line)),
103
+ ...played.diagnostics,
104
+ ]),
17
105
  };
18
106
  }
@@ -0,0 +1,7 @@
1
+ import type { Line, Part } from "./types.js";
2
+ /**
3
+ * One part of a multi-part chart as a single-part chart's lines (grammar
4
+ * 7.4): the tutti lines, the part's own lines, and a bar of `N.C.` marked
5
+ * `tacet` for each bar of a system it doesn't play. Never throws.
6
+ */
7
+ export declare function projectPart(lines: Line[], parts: Part[], label: string): Line[];
@@ -0,0 +1,77 @@
1
+ /** A bar of `N.C.` where the part rests; the system's marks stay (grammar 7.4). */
2
+ const standInCell = (c) => c.kind === "slots" || c.kind === "simile"
3
+ ? {
4
+ kind: "slots",
5
+ meter: c.kind === "slots" ? c.meter : null,
6
+ slots: [{ kind: "nc" }],
7
+ tacet: true,
8
+ }
9
+ : c;
10
+ /** A system no line of which reads: kept as an error line, so its bars still count. */
11
+ function unread(first) {
12
+ const invalid = first?.kind === "invalid" ? first : null;
13
+ return {
14
+ kind: "invalid",
15
+ line: first?.line ?? 0,
16
+ text: invalid?.text ?? "",
17
+ written: invalid?.written ?? 0,
18
+ };
19
+ }
20
+ /** The line a system's structure is read from: its first line that reads and agrees. */
21
+ const referenceOf = (system) => system.find((l) => l.kind === "bars" && !l.dropped);
22
+ /**
23
+ * The system's structure with every bar a tacet bar, numbered `at`: the
24
+ * part's own line when it has one that errs, so its error stays its own,
25
+ * or else the reference line, which has none.
26
+ */
27
+ function standIn(system, at) {
28
+ const ref = referenceOf(system);
29
+ if (!ref)
30
+ return unread(at);
31
+ const { part: _p, system: _s, dropped: _d, ...rest } = ref;
32
+ return { ...rest, line: at.line, cells: ref.cells.map(standInCell) };
33
+ }
34
+ /** A part's own line, as a single-part chart writes it. */
35
+ function unlabelled(l) {
36
+ if (l.kind === "invalid") {
37
+ const { part: _p, system: _s, ...rest } = l;
38
+ return rest;
39
+ }
40
+ const { part: _p, system: _s, dropped: _d, ...rest } = l;
41
+ return rest;
42
+ }
43
+ const plays = (l, key) => l.part?.toLowerCase() === key && l.kind === "bars" && !l.dropped;
44
+ const inSystem = (l) => (l.kind === "bars" || l.kind === "invalid") && l.system !== undefined;
45
+ function systemsOf(lines) {
46
+ const systems = new Map();
47
+ for (const l of lines)
48
+ if (inSystem(l))
49
+ systems.set(l.system, [...(systems.get(l.system) ?? []), l]);
50
+ return systems;
51
+ }
52
+ /** What one line becomes in the part's chart: itself, its unlabelled self, a stand-in, or nothing. */
53
+ function projectLine(l, key, systems) {
54
+ if (l.kind === "part")
55
+ return l.label?.toLowerCase() === key ? l : null;
56
+ return inSystem(l) ? projectSystemLine(l, key, systems.get(l.system) ?? []) : l;
57
+ }
58
+ /** A system's line in one part's chart: the part's own line, a stand-in where it rests, or nothing. */
59
+ function projectSystemLine(l, key, system) {
60
+ const own = system.find((m) => m.part?.toLowerCase() === key);
61
+ if (own === l && plays(l, key))
62
+ return unlabelled(l);
63
+ const at = own ?? referenceOf(system) ?? system[0];
64
+ return at === l ? standIn(system, l) : null;
65
+ }
66
+ /**
67
+ * One part of a multi-part chart as a single-part chart's lines (grammar
68
+ * 7.4): the tutti lines, the part's own lines, and a bar of `N.C.` marked
69
+ * `tacet` for each bar of a system it doesn't play. Never throws.
70
+ */
71
+ export function projectPart(lines, parts, label) {
72
+ if (!parts.length)
73
+ return lines;
74
+ const key = label.toLowerCase();
75
+ const systems = systemsOf(lines);
76
+ return lines.map((l) => projectLine(l, key, systems)).filter((l) => l !== null);
77
+ }
@@ -30,3 +30,9 @@ export declare function printChart(text: string): string;
30
30
  * text isn't read twice. `edit`, if given, changes each line before it prints.
31
31
  */
32
32
  export declare function printParsed(text: string, parsed: ChartParse, edit?: (l: Line) => Line): string;
33
+ /**
34
+ * One part of a chart in canonical form, as a single-part chart (grammar
35
+ * 7.4): its `part:` line, the tutti lines, its own lines, and `N.C.` bars
36
+ * where it is tacet. Null when no part has that label. Never throws.
37
+ */
38
+ export declare function printPart(text: string, label: string): string | null;
@@ -1,7 +1,8 @@
1
1
  import { isBar } from "./barLine.js";
2
2
  import { printDirection } from "./direction.js";
3
3
  import { beatsOf } from "./directives.js";
4
- import { parseChart } from "./parse.js";
4
+ import { readDocument } from "./document.js";
5
+ import { extractPart, parseChart } from "./parse.js";
5
6
  /** A slot with no attack of its own continues whatever sounds before it. A repeated chord name is a re-attack. */
6
7
  function continues(sounding, s) {
7
8
  if (s.kind === "hold")
@@ -124,6 +125,15 @@ function printDirectives(d) {
124
125
  parts.push(`feel: ${d.feel}${d.swingPercent === undefined ? "" : ` ${d.swingPercent}%`}`);
125
126
  return parts.join(", ");
126
127
  }
128
+ /** A bar line's opening, cells and closing, each printed. */
129
+ function barPieces(l, beats) {
130
+ return {
131
+ open: l.opens ? "|:" : l.ending ? `|${printPasses(l.ending)}` : "|",
132
+ cells: l.cells.map((c, i) => printCell(c, beats[i])),
133
+ close: `${l.closes ? ":|" : "|"}${printRepeat(l.repeat)}`,
134
+ };
135
+ }
136
+ const joinPieces = (p) => `${p.open} ${p.cells.join(" | ")} ${p.close}`;
127
137
  /**
128
138
  * One parsed line in canonical form. Text and invalid lines print as stored.
129
139
  * `beats` gives each cell's beat count where known, so reduction adds no warning.
@@ -139,7 +149,7 @@ export function printLine(l, beats = []) {
139
149
  case "part":
140
150
  return `part: ${l.label ? `${l.label} = ` : ""}${l.name}`;
141
151
  case "bars":
142
- return `${l.opens ? "|:" : l.ending ? `|${printPasses(l.ending)}` : "|"} ${l.cells.map((c, i) => printCell(c, beats[i])).join(" | ")} ${l.closes ? ":|" : "|"}${printRepeat(l.repeat)}`;
152
+ return joinPieces(barPieces(l, beats));
143
153
  default:
144
154
  return l.text;
145
155
  }
@@ -152,50 +162,127 @@ export function printLine(l, beats = []) {
152
162
  export function printChart(text) {
153
163
  return printParsed(text, parseChart(text));
154
164
  }
155
- /**
156
- * `printChart` over a parse you already have (`parseChart(text)`), so the
157
- * text isn't read twice. `edit`, if given, changes each line before it prints.
158
- */
159
- export function printParsed(text, parsed, edit = (l) => l) {
165
+ /** A system's lines in score order, labels padded and pipes lined up (section 8, grammar 7.4). */
166
+ function alignSystem(system, parsed, beatsFor, edit) {
167
+ const score = (l) => parsed.parts.findIndex((p) => p.label === l.part);
168
+ const width = Math.max(...parsed.parts.map((p) => p.label?.length ?? 0));
169
+ const pieces = [...system]
170
+ .sort((a, b) => score(a) - score(b))
171
+ .map((l) => ({ label: l.part ?? "", ...barPieces(edit(l), beatsFor(l)) }));
172
+ const columns = pieces[0]?.cells.map((_, i) => Math.max(...pieces.map((p) => p.cells[i]?.length ?? 0)));
173
+ return pieces.map((p) => `${p.label.padEnd(width)} ${joinPieces({ ...p, cells: p.cells.map((c, i) => c.padEnd(columns?.[i] ?? 0)) })}`.trimEnd());
174
+ }
175
+ function systemsOf(lines) {
176
+ const systems = new Map();
177
+ for (const l of lines)
178
+ if ((l.kind === "bars" || l.kind === "invalid") && l.system !== undefined)
179
+ systems.set(l.system, [...(systems.get(l.system) ?? []), l]);
180
+ return [...systems.values()];
181
+ }
182
+ /** Canonical text for the lines of a multi-part chart's systems, by line number. */
183
+ function systemTexts(parsed, errored, beatsFor, edit) {
184
+ const texts = new Map();
185
+ for (const lines of systemsOf(parsed.lines)) {
186
+ const valid = lines.filter((l) => l.kind === "bars" && !errored.has(l.line));
187
+ // A system with an error is neither sorted nor padded, so the error's line stays where it was written.
188
+ const printed = valid.length === lines.length
189
+ ? alignSystem(valid, parsed, beatsFor, edit)
190
+ : valid.map((l) => `${l.part} ${printLine(edit(l), beatsFor(l))}`);
191
+ for (const [i, l] of valid.entries())
192
+ texts.set(l.line, printed[i] ?? "");
193
+ }
194
+ return texts;
195
+ }
196
+ /** Each line's beat counts on its first play, every part's lines included. */
197
+ function beatsOfLines(parsed) {
160
198
  const byLine = new Map(parsed.lines.map((l) => [l.line, l]));
161
- const errored = new Set(parsed.diagnostics.filter((d) => d.severity === "error").map((d) => d.line));
162
- // Each cell's beat count on its first play, which is when its slot count is checked.
163
199
  const firstPlay = new Map();
164
200
  for (const b of parsed.bars) {
165
- const l = byLine.get(b.line);
166
- const meters = firstPlay.get(b.line) ?? [];
167
- const cells = l?.kind === "bars" ? l.cells.filter(isBar).length : 0;
168
- if (meters.length < cells)
169
- firstPlay.set(b.line, [...meters, beatsOf(b.meter)]);
201
+ const lines = new Set([b.line, ...(b.parts ?? []).flatMap((p) => (p ? [p.line] : []))]);
202
+ for (const line of lines) {
203
+ const l = byLine.get(line);
204
+ const meters = firstPlay.get(line) ?? [];
205
+ const cells = l?.kind === "bars" ? l.cells.filter(isBar).length : 0;
206
+ if (meters.length < cells)
207
+ firstPlay.set(line, [...meters, beatsOf(b.meter)]);
208
+ }
170
209
  }
171
- const beatsFor = (l) => {
210
+ return (l) => {
172
211
  if (l.kind !== "bars")
173
212
  return [];
174
213
  const meters = firstPlay.get(l.line) ?? [];
175
214
  let next = 0;
176
215
  return l.cells.map((c) => (isBar(c) ? meters[next++] : undefined));
177
216
  };
217
+ }
218
+ /**
219
+ * `printChart` over a parse you already have (`parseChart(text)`), so the
220
+ * text isn't read twice. `edit`, if given, changes each line before it prints.
221
+ */
222
+ export function printParsed(text, parsed, edit = (l) => l) {
223
+ return printLines(text, parsed, edit, new Set());
224
+ }
225
+ function linePrinter(parsed, edit) {
226
+ const errored = new Set(parsed.diagnostics.filter((d) => d.severity === "error").map((d) => d.line));
227
+ const beatsFor = beatsOfLines(parsed);
228
+ const systems = systemTexts(parsed, errored, beatsFor, edit);
229
+ return (raw, l) => {
230
+ if (!l)
231
+ return raw.trim().startsWith("```") ? raw.trim() : raw.trimEnd();
232
+ if (l.kind === "text" || errored.has(l.line))
233
+ return raw.trimEnd();
234
+ return systems.get(l.line) ?? printLine(edit(l), beatsFor(l));
235
+ };
236
+ }
237
+ /** Blank lines: runs collapse to one, and one goes before a heading unless the line before is one. */
238
+ function spaceBefore(out, l, afterHeading) {
239
+ if (out.length === 0 || out.at(-1) === "")
240
+ return;
241
+ if (!l || (l.kind === "section" && !afterHeading))
242
+ out.push("");
243
+ }
244
+ /** The printer, leaving out the physical lines in `skip`. */
245
+ function printLines(text, parsed, edit, skip) {
246
+ const byLine = new Map(parsed.lines.map((l) => [l.line, l]));
247
+ const print = linePrinter(parsed, edit);
178
248
  const out = [];
179
249
  let lastWasHeading = false;
180
250
  const physical = text.replace(/^\uFEFF/, "").split(/\r?\n/);
181
251
  for (const [i, raw] of physical.entries()) {
252
+ if (skip.has(i + 1))
253
+ continue;
182
254
  const t = raw.trim();
183
255
  if (!t) {
184
- if (out.length > 0 && out.at(-1) !== "")
185
- out.push("");
256
+ spaceBefore(out, undefined, false);
186
257
  continue;
187
258
  }
188
259
  const l = t.startsWith("```") ? undefined : byLine.get(i + 1);
189
260
  // Consecutive headings (a run of replays) stay together, as the spec's examples write them.
190
- if (l?.kind === "section" && !lastWasHeading && out.length > 0 && out.at(-1) !== "")
191
- out.push("");
261
+ if (l?.kind === "section")
262
+ spaceBefore(out, l, lastWasHeading);
192
263
  lastWasHeading = l?.kind === "section";
193
- if (!l)
194
- out.push(t.startsWith("```") ? t : raw.trimEnd());
195
- else
196
- out.push(l.kind === "text" || errored.has(l.line) ? raw.trimEnd() : printLine(edit(l), beatsFor(l)));
264
+ out.push(print(raw, l));
197
265
  }
266
+ return finish(out);
267
+ }
268
+ /** The lines as text, without trailing blank lines. */
269
+ function finish(out) {
198
270
  while (out.at(-1) === "")
199
271
  out.pop();
200
272
  return out.length ? `${out.join("\n")}\n` : "";
201
273
  }
274
+ /**
275
+ * One part of a chart in canonical form, as a single-part chart (grammar
276
+ * 7.4): its `part:` line, the tutti lines, its own lines, and `N.C.` bars
277
+ * where it is tacet. Null when no part has that label. Never throws.
278
+ */
279
+ export function printPart(text, label) {
280
+ const parsed = extractPart(text, label);
281
+ if (!parsed)
282
+ return null;
283
+ const kept = new Set(parsed.lines.map((l) => l.line));
284
+ const skip = new Set(readDocument(text)
285
+ .lines.filter((l) => (l.kind === "part" || l.kind === "bars" || l.kind === "invalid") && !kept.has(l.line))
286
+ .map((l) => l.line));
287
+ return printLines(text, parsed, (l) => l, skip);
288
+ }
@@ -0,0 +1,16 @@
1
+ import type { ChartDiagnostic, Line } from "./types.js";
2
+ type BarsLine = Extract<Line, {
3
+ kind: "bars";
4
+ }>;
5
+ /** The marks of a bar line that shape the timeline, which every line of a system shares (grammar 7.4). */
6
+ export declare function structureOf(l: BarsLine): string;
7
+ /**
8
+ * Group a multi-part chart's labelled bar lines into systems and check that
9
+ * each system's lines share their bars and structure. A line that differs is
10
+ * an error and is marked `dropped`. Never throws.
11
+ */
12
+ export declare function groupSystems(lines: Line[]): {
13
+ lines: Line[];
14
+ diagnostics: ChartDiagnostic[];
15
+ };
16
+ export {};
@@ -0,0 +1,78 @@
1
+ import { printDirection } from "./direction.js";
2
+ const repeatOf = (r) => (r === null ? "" : r === "open" ? " x ..." : ` x${r}`);
3
+ function cellShape(c) {
4
+ switch (c.kind) {
5
+ case "slots":
6
+ return c.meter ? `B[${c.meter.n}/${c.meter.d}]` : "B";
7
+ case "simile":
8
+ return "B";
9
+ case "fermata":
10
+ return "...";
11
+ case "rehearsal":
12
+ return `@${c.label}`;
13
+ default:
14
+ return printDirection(c.direction);
15
+ }
16
+ }
17
+ const opening = (l) => (l.opens ? "|:" : l.ending ? `|${l.ending.join(",")}` : "|");
18
+ const closing = (l) => `${l.closes ? ":|" : "|"}${repeatOf(l.repeat)}`;
19
+ /** The marks of a bar line that shape the timeline, which every line of a system shares (grammar 7.4). */
20
+ export function structureOf(l) {
21
+ return `${opening(l)} ${l.cells.map(cellShape).join(" ")} ${closing(l)}`;
22
+ }
23
+ const barCount = (l) => l.cells.filter((c) => c.kind === "slots" || c.kind === "simile").length;
24
+ /** Why a system's line differs from its first, or null. */
25
+ function differs(l, ref) {
26
+ const n = barCount(ref);
27
+ if (barCount(l) !== n)
28
+ return `this system's lines have ${n} bars (line ${ref.line}); this one has ${barCount(l)}`;
29
+ if (opening(l) !== opening(ref) || closing(l) !== closing(ref))
30
+ return `every line of a system writes the same repeat marks (line ${ref.line})`;
31
+ if (structureOf(l) !== structureOf(ref))
32
+ return `every line of a system writes the same marks in the same places (line ${ref.line})`;
33
+ return null;
34
+ }
35
+ const isLabelled = (l) => (l.kind === "bars" || l.kind === "invalid") && l.part !== undefined;
36
+ /** Number each run of labelled lines with no label twice (grammar 7.4). */
37
+ function numberSystems(lines) {
38
+ let system = -1;
39
+ let seen = null;
40
+ return lines.map((l) => {
41
+ if (!isLabelled(l)) {
42
+ seen = null;
43
+ return l;
44
+ }
45
+ const label = l.part ?? "";
46
+ if (!seen || seen.has(label)) {
47
+ system++;
48
+ seen = new Set();
49
+ }
50
+ seen.add(label);
51
+ return { ...l, system };
52
+ });
53
+ }
54
+ /**
55
+ * Group a multi-part chart's labelled bar lines into systems and check that
56
+ * each system's lines share their bars and structure. A line that differs is
57
+ * an error and is marked `dropped`. Never throws.
58
+ */
59
+ export function groupSystems(lines) {
60
+ const diagnostics = [];
61
+ const numbered = numberSystems(lines);
62
+ const first = new Map();
63
+ const out = numbered.map((l) => {
64
+ if (l.kind !== "bars" || l.system === undefined)
65
+ return l;
66
+ const ref = first.get(l.system);
67
+ if (!ref) {
68
+ first.set(l.system, l);
69
+ return l;
70
+ }
71
+ const problem = differs(l, ref);
72
+ if (!problem)
73
+ return l;
74
+ diagnostics.push({ line: l.line, severity: "error", message: problem, token: l.part ?? "" });
75
+ return { ...l, dropped: true };
76
+ });
77
+ return { lines: out, diagnostics };
78
+ }
@@ -117,6 +117,8 @@ export type Cell = {
117
117
  meter: Meter | null;
118
118
  slots: Slot[];
119
119
  words?: Words[];
120
+ /** A stand-in bar of `N.C.` for a part that is tacet there (grammar 7.4); only a projected part has one. */
121
+ tacet?: true;
120
122
  } | {
121
123
  kind: "simile";
122
124
  words?: Words[];
@@ -158,6 +160,12 @@ export type Line = {
158
160
  repeat: Repeat;
159
161
  /** The passes an ending plays on (grammar 5.1), in order; null for any other bar line. */
160
162
  ending: number[] | null;
163
+ /** The declared label of the part whose line this is (grammar 7.4); absent on a tutti line and in a single-part chart. */
164
+ part?: string;
165
+ /** Which system a labelled line is in, from 0 in chart order. */
166
+ system?: number;
167
+ /** Set when the line's bars or structure differ from its system's (an error): its part is tacet there. */
168
+ dropped?: true;
161
169
  } | {
162
170
  kind: "text";
163
171
  line: number;
@@ -172,6 +180,8 @@ export type Line = {
172
180
  line: number;
173
181
  text: string;
174
182
  written: number;
183
+ part?: string;
184
+ system?: number;
175
185
  };
176
186
  export type PlayedBar = {
177
187
  /** 1-based measure number in play order; fermatas are not counted. */
@@ -204,7 +214,21 @@ export type PlayedBar = {
204
214
  rehearsal?: string;
205
215
  /** Words written on this bar; absent when none. `%` copies chords, not words. */
206
216
  words?: Words[];
217
+ /** Set when the part is tacet in this bar (grammar 7.4): its slots then read `N.C.`. */
218
+ tacet?: true;
219
+ /**
220
+ * In a chart of several parts, each part's bar, aligned with
221
+ * `ChartParse.parts`; null where that part is tacet. The top-level
222
+ * `slots` and `words` are the first part's.
223
+ */
224
+ parts?: PartBar[];
207
225
  };
226
+ /** One part's share of a played bar (grammar 7.4): the line it is written on, its slots and words. */
227
+ export type PartBar = {
228
+ line: number;
229
+ slots: Slot[];
230
+ words?: Words[];
231
+ } | null;
208
232
  /** An open repeat shows one pass; the number of passes is unknown. */
209
233
  export type ChartEvent = {
210
234
  kind: "bar";
@@ -233,8 +257,14 @@ export type SectionOccurrence = {
233
257
  };
234
258
  export type ChartParse = {
235
259
  title: string | null;
236
- /** What `part:` names (grammar 7.3); null when the chart names none. */
260
+ /**
261
+ * The one part a single-part chart names (grammar 7.3); null when it names
262
+ * none or several.
263
+ * @deprecated use `parts`.
264
+ */
237
265
  part: Part | null;
266
+ /** Every part the chart declares, in score order (grammar 7.4); empty when none. */
267
+ parts: Part[];
238
268
  lines: Line[];
239
269
  events: ChartEvent[];
240
270
  /** `events` flattened, with an open repeat's pass included once. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "barmark",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "description": "Markdown-inspired plain-text notation for chord charts: a parser, a canonical printer and Harte-label conversion.",
5
5
  "type": "module",
6
6
  "exports": {