barmark 0.14.0 → 0.14.1

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,20 @@ Releases follow the process in [RELEASING.md](RELEASING.md).
9
9
 
10
10
  ## [Unreleased]
11
11
 
12
+ ## [0.14.1] - 2026-11-03
13
+
14
+ ### Fixed
15
+
16
+ - In a system, the line that differs from the one most lines agree with
17
+ is the error, wherever it sits; before, an odd first line made every
18
+ other line of its system the error (grammar 7.4).
19
+ - Parts that play one bar in different meters (a `%` copying a one-bar
20
+ meter) are reported on every line that plays it, naming the meters.
21
+ - `printPart` leaves out a `part:` line set aside for sharing a label,
22
+ which would otherwise declare a part again in the extract.
23
+ - If parts ever fell out of step, the first place they part is now an
24
+ error instead of a silent fallback.
25
+
12
26
  ## [0.14.0] - 2026-11-03
13
27
 
14
28
  ### Added
@@ -350,7 +364,8 @@ The first working release: the reference parser and printer for the
350
364
 
351
365
  - **A placeholder package that holds the `barmark` name** while the spec and parser are written.
352
366
 
353
- [Unreleased]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.14.0...HEAD
367
+ [Unreleased]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.14.1...HEAD
368
+ [0.14.1]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.14.0...barmark-v0.14.1
354
369
  [0.14.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.13.0...barmark-v0.14.0
355
370
  [0.13.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.12.0...barmark-v0.13.0
356
371
  [0.12.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.11.0...barmark-v0.12.0
@@ -1,4 +1,10 @@
1
- import type { ChartParse } from "./types.js";
1
+ import type { ChartDiagnostic, ChartEvent, ChartParse } from "./types.js";
2
+ /**
3
+ * Each part's events, played in lockstep: the shapes match because every
4
+ * line of a system shares its structure. Where they don't, the lead's
5
+ * shape is kept and the first place they part is an error.
6
+ */
7
+ export declare function zipEvents(each: ChartEvent[][], report: (d: ChartDiagnostic) => void): ChartEvent[];
2
8
  /** Read a whole barmark chart: the document as written and the bars in play order. Never throws. */
3
9
  export declare function parseChart(text: string): ChartParse;
4
10
  /**
@@ -19,23 +19,50 @@ function mergeReports(each) {
19
19
  return [...most.values()].flat();
20
20
  }
21
21
  const partBar = (b) => b.tacet ? null : { line: b.line, slots: b.slots, ...(b.words && { words: b.words }) };
22
+ const meterText = (b) => `${b.meter.n}/${b.meter.d}`;
22
23
  /** One bar of every part: shared fields from the first, the meter from the first that plays. */
23
24
  function zipBar(bars, report) {
24
25
  const [first, ...rest] = bars;
25
26
  const playing = bars.filter((b) => !b.tacet);
26
27
  const meter = playing[0]?.meter ?? first.meter;
27
- if (playing.some((b) => b.meter.n !== meter.n || b.meter.d !== meter.d))
28
+ const meters = [...new Set(playing.map(meterText))];
29
+ // A `%` copies its bar's one-bar meter, so parts can disagree: say so on every line that plays the bar.
30
+ if (meters.length > 1)
31
+ for (const line of new Set(playing.map((b) => b.line)))
32
+ report({
33
+ line,
34
+ severity: "error",
35
+ message: `the parts disagree on this bar's meter (${meters.join(", ")})`,
36
+ token: "|",
37
+ });
38
+ return { ...first, meter, parts: [first, ...rest].map(partBar) };
39
+ }
40
+ const lineOf = (e) => (e.kind === "bar" ? e.bar.line : e.line);
41
+ /** The first event at which some part's timeline differs in shape from the lead's, or -1. */
42
+ function stepAt(each) {
43
+ const [lead = []] = each;
44
+ const longest = Math.max(...each.map((events) => events.length));
45
+ for (let i = 0; i < longest; i++)
46
+ if (each.some((events) => events[i]?.kind !== lead[i]?.kind))
47
+ return i;
48
+ return -1;
49
+ }
50
+ /**
51
+ * Each part's events, played in lockstep: the shapes match because every
52
+ * line of a system shares its structure. Where they don't, the lead's
53
+ * shape is kept and the first place they part is an error.
54
+ */
55
+ export function zipEvents(each, report) {
56
+ const [lead = []] = each;
57
+ const apart = stepAt(each);
58
+ const at = lead[apart] ?? lead[lead.length - 1];
59
+ if (apart >= 0 && at)
28
60
  report({
29
- line: playing[1]?.line ?? first.line,
61
+ line: lineOf(at),
30
62
  severity: "error",
31
- message: "the parts disagree on this bar's meter",
63
+ message: "the parts fall out of step here; check that every line of this system writes the same marks",
32
64
  token: "|",
33
65
  });
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
66
  return lead.map((e, i) => {
40
67
  const peers = each.map((events) => events[i] ?? e);
41
68
  if (e.kind === "bar")
@@ -282,7 +282,10 @@ export function printPart(text, label) {
282
282
  return null;
283
283
  const kept = new Set(parsed.lines.map((l) => l.line));
284
284
  const skip = new Set(readDocument(text)
285
- .lines.filter((l) => (l.kind === "part" || l.kind === "bars" || l.kind === "invalid") && !kept.has(l.line))
285
+ .lines.filter((l) =>
286
+ // A `part:` demoted to text (a shared label) would declare a part again in the extract.
287
+ (l.kind === "text" && /^part\s*:/i.test(l.text)) ||
288
+ ((l.kind === "part" || l.kind === "bars" || l.kind === "invalid") && !kept.has(l.line)))
286
289
  .map((l) => l.line));
287
290
  return printLines(text, parsed, (l) => l, skip);
288
291
  }
@@ -51,6 +51,23 @@ function numberSystems(lines) {
51
51
  return { ...l, system };
52
52
  });
53
53
  }
54
+ /**
55
+ * Each system's reference line: the first whose structure most of the
56
+ * system's lines share, so one odd line is the error wherever it sits.
57
+ */
58
+ function referenceLines(lines) {
59
+ const bySystem = new Map();
60
+ for (const l of lines)
61
+ if (l.kind === "bars" && l.system !== undefined)
62
+ bySystem.set(l.system, [...(bySystem.get(l.system) ?? []), l]);
63
+ const refs = new Map();
64
+ for (const [system, members] of bySystem) {
65
+ const votes = (l) => members.filter((m) => structureOf(m) === structureOf(l)).length;
66
+ const best = members.reduce((a, b) => (votes(b) > votes(a) ? b : a));
67
+ refs.set(system, best);
68
+ }
69
+ return refs;
70
+ }
54
71
  /**
55
72
  * Group a multi-part chart's labelled bar lines into systems and check that
56
73
  * each system's lines share their bars and structure. A line that differs is
@@ -59,15 +76,13 @@ function numberSystems(lines) {
59
76
  export function groupSystems(lines) {
60
77
  const diagnostics = [];
61
78
  const numbered = numberSystems(lines);
62
- const first = new Map();
79
+ const refs = referenceLines(numbered);
63
80
  const out = numbered.map((l) => {
64
81
  if (l.kind !== "bars" || l.system === undefined)
65
82
  return l;
66
- const ref = first.get(l.system);
67
- if (!ref) {
68
- first.set(l.system, l);
83
+ const ref = refs.get(l.system);
84
+ if (!ref || ref === l)
69
85
  return l;
70
- }
71
86
  const problem = differs(l, ref);
72
87
  if (!problem)
73
88
  return l;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "barmark",
3
- "version": "0.14.0",
3
+ "version": "0.14.1",
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": {