barmark 0.25.1 → 0.26.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,24 @@ Releases follow the process in [RELEASING.md](RELEASING.md).
9
9
 
10
10
  ## [Unreleased]
11
11
 
12
+ ## [0.26.0] - 2026-11-29
13
+
14
+ ### Added
15
+
16
+ - **Each bar line's first written bar number** (Kevin, 2026-11-28; grammar
17
+ A.7 and decisions log): a bar line in `lines`, and a bar line excluded for
18
+ an error, carries `firstWritten`, the written number of its first bar (0 for
19
+ the pickup), as `PlayedBar.written` counts, whether or not any pass plays
20
+ it. Every line of a system that has one has the same. It is absent on a
21
+ line that writes no bar, and on a line of a system whose bars the
22
+ numbering does not count (a one-line system whose line is dropped, a
23
+ system whose reference line writes none, a system with no reference line
24
+ whose counted line is a dropped bar line), and on a line past a part's
25
+ share of the lines in a chart of many parts. So a host can number and
26
+ pair every written bar, played or not, without recounting from the
27
+ lines. `extractPart` gives its lines the numbers its bars are played
28
+ with. No chart changes meaning, and nothing else in the parse changes.
29
+
12
30
  ## [0.25.1] - 2026-11-29
13
31
 
14
32
  ### Fixed
@@ -958,7 +976,8 @@ The first working release: the reference parser and printer for the
958
976
 
959
977
  - **A placeholder package that holds the `barmark` name** while the spec and parser are written.
960
978
 
961
- [Unreleased]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.25.1...HEAD
979
+ [Unreleased]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.26.0...HEAD
980
+ [0.26.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.25.1...barmark-v0.26.0
962
981
  [0.25.1]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.25.0...barmark-v0.25.1
963
982
  [0.25.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.24.0...barmark-v0.25.0
964
983
  [0.24.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.23.1...barmark-v0.24.0
package/README.md CHANGED
@@ -191,7 +191,14 @@ an object. It has two kinds of field:
191
191
  - **The chart as written:** `title`, `parts`, `credits` and `lines`, one
192
192
  entry per source line in order (the title, a bar line, a heading, a
193
193
  directive, a `part:` line, a credit, a lyric row, text, a break, or an
194
- invalid bar line kept as written), each with its line number.
194
+ invalid bar line kept as written), each with its line number. A bar
195
+ line, and an invalid one, carries `firstWritten`: the written number of its
196
+ first bar (0 for a pickup), played or not; absent on a line that writes
197
+ no bar, and on a line of a system whose bars the numbering does not
198
+ count (a one-line system whose line is dropped, say), and on a line past
199
+ a part's share of the lines in a very long chart of many parts (the
200
+ grammar's A.7 row lists every case). A pickup's line has
201
+ `firstWritten: 0`, which is falsy: test it with `!== undefined`.
195
202
  - **The chart as played**, worked out from the written lines:
196
203
  - `events` is play order with fermatas and an open repeat kept as
197
204
  events.
@@ -46,4 +46,12 @@ sing?: Sing): {
46
46
  diagnostics: ChartDiagnostic[];
47
47
  /** Whether play stopped at a limit: what follows from that alone goes unreported. */
48
48
  stopped: boolean;
49
+ /**
50
+ * The first written number of each line this expansion reads that writes
51
+ * a bar, by its line number: counting from 1 with no pickup shift, over
52
+ * the lines given (one stream's, in a chart of parts: no system sharing),
53
+ * played or not. None for a line that writes no bar, and for a line past
54
+ * a part's share of lines. `withFirstWritten` makes the bar lines' field.
55
+ */
56
+ firsts: Map<number, number>;
49
57
  };
@@ -227,17 +227,27 @@ sing) {
227
227
  return markBar(c, line);
228
228
  return c.kind === "simile" ? simile(c, line) : ownBar(c, line);
229
229
  };
230
- for (const l of sections.flatMap((s) => s.lines)) {
231
- if (l.kind === "invalid")
232
- written += l.written;
233
- if (l.kind !== "bars")
234
- continue;
230
+ /** Each bar line's first written number, by its line number; none for a line that writes no bar. */
231
+ const firsts = new Map();
232
+ const resolveLine = (l) => {
235
233
  let bar = 0;
236
- resolved.set(l, l.cells
234
+ return l.cells
237
235
  .map((c) => resolveCell(c, l.line))
238
236
  .filter((p) => p !== null)
239
- .map((p) => (p.kind === "bar" ? { ...p, bar: bar++ } : p)));
240
- }
237
+ .map((p) => (p.kind === "bar" ? { ...p, bar: bar++ } : p));
238
+ };
239
+ /** A line's bars take the numbers after those written before it; an excluded line's too. */
240
+ const readLine = (l) => {
241
+ const first = written + 1;
242
+ if (l.kind === "invalid")
243
+ written += l.written;
244
+ if (l.kind === "bars")
245
+ resolved.set(l, resolveLine(l));
246
+ if (written >= first)
247
+ firsts.set(l.line, first);
248
+ };
249
+ for (const l of sections.flatMap((s) => s.lines))
250
+ readLine(l);
241
251
  const unused = pending.mark;
242
252
  if (unused)
243
253
  error(unused.line, "a rehearsal mark marks the bar after it; none follows", `@${unused.label}`);
@@ -636,5 +646,5 @@ sing) {
636
646
  });
637
647
  if (pedal)
638
648
  diagnostics.push(...pedalWarnings(flattenBars(events)));
639
- return { events, sections: sectionsOut, diagnostics, stopped: capped };
649
+ return { events, sections: sectionsOut, diagnostics, stopped: capped, firsts };
640
650
  }
@@ -0,0 +1,10 @@
1
+ import type { Line } from "./types.js";
2
+ /**
3
+ * The lines with each bar line's `firstWritten` (grammar 2.4, A.7), from the
4
+ * numbering the parse's bars were played with: `firsts`, `expand`'s first
5
+ * number of each line it read (counting from 1, by line number), one
6
+ * lower when the chart opens with a pickup. A system's lines take the
7
+ * number of the one line of it that stream read, found among `written`
8
+ * (the chart's lines as written); a line that writes no bar takes none.
9
+ */
10
+ export declare function withFirstWritten(lines: Line[], written: Line[], firsts: Map<number, number>, pickup: boolean): Line[];
@@ -0,0 +1,30 @@
1
+ const isBarLine = (l) => l.kind === "bars" || l.kind === "invalid";
2
+ /** Whether a line writes a bar: a bar or `%` cell, or for an excluded line a bar its pipes write. */
3
+ const writesBar = (l) => l.kind === "invalid"
4
+ ? l.written > 0
5
+ : l.cells.some((c) => c.kind === "slots" || c.kind === "simile");
6
+ /**
7
+ * The lines with each bar line's `firstWritten` (grammar 2.4, A.7), from the
8
+ * numbering the parse's bars were played with: `firsts`, `expand`'s first
9
+ * number of each line it read (counting from 1, by line number), one
10
+ * lower when the chart opens with a pickup. A system's lines take the
11
+ * number of the one line of it that stream read, found among `written`
12
+ * (the chart's lines as written); a line that writes no bar takes none.
13
+ */
14
+ export function withFirstWritten(lines, written, firsts, pickup) {
15
+ const bySystem = new Map();
16
+ for (const l of written) {
17
+ if (!isBarLine(l) || l.system === undefined)
18
+ continue;
19
+ const first = firsts.get(l.line);
20
+ if (first !== undefined)
21
+ bySystem.set(l.system, first);
22
+ }
23
+ const shift = pickup ? 1 : 0;
24
+ return lines.map((l) => {
25
+ if (!isBarLine(l) || !writesBar(l))
26
+ return l;
27
+ const first = l.system === undefined ? firsts.get(l.line) : bySystem.get(l.system);
28
+ return first === undefined ? l : { ...l, firstWritten: first - shift };
29
+ });
30
+ }
@@ -16,7 +16,8 @@ export declare function parseChart(text: string): ChartParse;
16
16
  * line: the part's first line also plays its bare and tutti lines, and a
17
17
  * line rests where it isn't written. A part that writes its bare line
18
18
  * beside its named lines makes it a line of its own (`lineName` `""`), and
19
- * the named lines no longer play it. Null when the chart declares no part
19
+ * the named lines no longer play it. Its bar lines' `firstWritten` are the
20
+ * numbers its bars are played with. Null when the chart declares no part
20
21
  * with that label, or the part no line of that name. Never throws.
21
22
  */
22
23
  export declare function extractPart(text: string, label: string, lineName?: string): ChartParse | null;
@@ -1,5 +1,6 @@
1
1
  import { readDocument } from "./document.js";
2
2
  import { expand, flattenBars, workFor } from "./expand.js";
3
+ import { withFirstWritten } from "./firstWritten.js";
3
4
  import { projectPart, projectPartLines } from "./parts.js";
4
5
  import { pedalWarnings } from "./pedal.js";
5
6
  import { numberFromPickup } from "./pickup.js";
@@ -213,7 +214,15 @@ function playStreams(lines, parts, shown, voices) {
213
214
  const zipped = zipEvents(played.map((p) => p.events), (d) => diagnostics.push(d), stopped);
214
215
  const events = foldEvents(zipped, byPart(streams, shown), shown);
215
216
  diagnostics.push(...linedPedalWarnings(events, shown));
216
- return { events, sections: played[0]?.sections ?? [], diagnostics, stopped };
217
+ // The bars carry the first stream's numbers (`zipBar`), so its lines' numbers are the chart's.
218
+ const lead = played[0];
219
+ return {
220
+ events,
221
+ sections: lead?.sections ?? [],
222
+ diagnostics,
223
+ stopped,
224
+ firsts: lead?.firsts ?? new Map(),
225
+ };
217
226
  }
218
227
  const lined = (parts) => parts.some((p) => p.lines?.length);
219
228
  /** What the voices found as they sang (grammar 7.7), once playing is done; past a stop, not what it left unsung. */
@@ -238,7 +247,7 @@ export function parseChart(text) {
238
247
  part,
239
248
  parts: withSings(doc.parts, voice.all),
240
249
  credits: doc.credits,
241
- lines: doc.lines,
250
+ lines: withFirstWritten(doc.lines, doc.lines, played.firsts, pickup),
242
251
  events: played.events,
243
252
  bars,
244
253
  pickup,
@@ -277,7 +286,8 @@ function extractOf(doc, part, voices, lineName) {
277
286
  * line: the part's first line also plays its bare and tutti lines, and a
278
287
  * line rests where it isn't written. A part that writes its bare line
279
288
  * beside its named lines makes it a line of its own (`lineName` `""`), and
280
- * the named lines no longer play it. Null when the chart declares no part
289
+ * the named lines no longer play it. Its bar lines' `firstWritten` are the
290
+ * numbers its bars are played with. Null when the chart declares no part
281
291
  * with that label, or the part no line of that name. Never throws.
282
292
  */
283
293
  export function extractPart(text, label, lineName) {
@@ -293,7 +303,8 @@ export function extractPart(text, label, lineName) {
293
303
  const pickup = numberFromPickup(bars);
294
304
  // The lyric rows are their owner's, or the chart's when no part sings (grammar 7.7).
295
305
  const rows = voices.some((v) => v.singer === voice.owner);
296
- const lines = rows ? extract.lines : extract.lines.filter((l) => l.kind !== "lyrics");
306
+ const numbered = withFirstWritten(extract.lines, doc.lines, played.firsts, pickup);
307
+ const lines = rows ? numbered : numbered.filter((l) => l.kind !== "lyrics");
297
308
  const kept = new Set(lines.map((l) => l.line));
298
309
  // A stand-in may sit on another part's line; that part's problems are not this one's.
299
310
  for (const l of doc.lines)
@@ -218,6 +218,27 @@ export type Line = {
218
218
  system?: number;
219
219
  /** Set when the line's bars or structure differ from its system's (an error): its part is tacet there. */
220
220
  dropped?: true;
221
+ /**
222
+ * The written number of the line's first bar (grammar 2.4, A.7): what
223
+ * `PlayedBar.written` is for that bar when a pass plays it, and the number
224
+ * it would have when none does. 0 when that bar is the chart's pickup.
225
+ * Every line of a system that writes a bar has the system's, a `dropped`
226
+ * line included.
227
+ * Absent when the line writes no bar (no bar or `%` cell), and on a line
228
+ * of a system whose bars the numbering does not count. The numbering is
229
+ * the first part's (its first line, when it writes lines): the chart's
230
+ * first declared part, or in an extract the extracted part. A system
231
+ * counts what its reference line (its first bar line not `dropped`)
232
+ * writes, whatever that part's own line there is: none when it writes no
233
+ * bar (a reference of only `...`, say). With no reference, it counts
234
+ * that part's own line there, else the system's first line: an excluded
235
+ * line's `written`, and none for a `dropped` bar line (a one-line system
236
+ * whose line is dropped, say). A line past a part's share of the lines
237
+ * (`expand`'s limit for a chart of several parts) has none either. A
238
+ * played bar's `line` may be a line with none (a tacet bar on a dropped
239
+ * line that writes no bar): `PlayedBar.written` is the bar's number.
240
+ */
241
+ firstWritten?: number;
221
242
  }
222
243
  /** A text line; `escaped` when written with a leading `\` (grammar 1), which `text` leaves off. */
223
244
  | {
@@ -264,6 +285,13 @@ export type Line = {
264
285
  part?: string;
265
286
  lineName?: string;
266
287
  system?: number;
288
+ /**
289
+ * The written number its first bar would have (grammar 2.4, A.7), as on
290
+ * a bar line: in a system, the system's. Absent when `written` is 0, and
291
+ * when the parse's numbering counts no bars for it, by the rule on a bar
292
+ * line's `firstWritten`.
293
+ */
294
+ firstWritten?: number;
267
295
  };
268
296
  export type PlayedBar = {
269
297
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "barmark",
3
- "version": "0.25.1",
3
+ "version": "0.26.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": {