barmark 0.17.0 → 0.17.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,27 @@ Releases follow the process in [RELEASING.md](RELEASING.md).
9
9
 
10
10
  ## [Unreleased]
11
11
 
12
+ ## [0.17.1] - 2026-11-07
13
+
14
+ A parse is plain data that owns its objects, and the README says what it
15
+ holds and how to store charts.
16
+
17
+ ### Fixed
18
+
19
+ - **A chord's unaltered interval is `alter: 0`, never `-0`,** so a parse
20
+ written to JSON and read back is the same object, as the README now
21
+ promises.
22
+ - **Two parses share no objects.** A chord's intervals were the chord
23
+ vocabulary's own objects, shared by every parse in the process, so
24
+ changing one parse's intervals changed every later parse's. Each chord
25
+ now has its own.
26
+
27
+ ### Technical
28
+
29
+ - **The README documents the parse result**: what is written and what is
30
+ played, and why to store a chart's text and treat a stored parse as a
31
+ cache. A test holds every example chart's parse to a JSON round trip.
32
+
12
33
  ## [0.17.0] - 2026-11-07
13
34
 
14
35
  A grammar change: syllables on notes (4.3), lyric rows and verses in play
@@ -525,7 +546,8 @@ The first working release: the reference parser and printer for the
525
546
 
526
547
  - **A placeholder package that holds the `barmark` name** while the spec and parser are written.
527
548
 
528
- [Unreleased]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.17.0...HEAD
549
+ [Unreleased]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.17.1...HEAD
550
+ [0.17.1]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.17.0...barmark-v0.17.1
529
551
  [0.17.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.16.0...barmark-v0.17.0
530
552
  [0.16.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.15.0...barmark-v0.16.0
531
553
  [0.15.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.14.1...barmark-v0.15.0
package/README.md CHANGED
@@ -167,6 +167,53 @@ Verses come out in play order: inside a repeat, verse N is pass N.
167
167
  convert both ways. Every label in the McGill Billboard and Isophonics
168
168
  Beatles datasets converts to barmark with exactly the same notes.
169
169
 
170
+ ### The parse result, and storing charts
171
+
172
+ `parseChart` returns plain data: no classes, Maps or functions, so
173
+ `JSON.stringify` and `JSON.parse` give an equal object back. Inside one
174
+ parse, objects are shared (a bar in `bars` is the same object as in
175
+ `events`, and a `%` bar shares its slots), so treat a parse as read-only;
176
+ `structuredClone(chart)` gives a copy to change. Two parses never share
177
+ an object. It has two kinds of field:
178
+
179
+ - **The chart as written:** `title`, `parts`, `credits` and `lines`, one
180
+ entry per source line in order (the title, a bar line, a heading, a
181
+ directive, a `part:` line, a credit, a lyric row, text, a break, or an
182
+ invalid bar line kept as written), each with its line number.
183
+ - **The chart as played**, worked out from the written lines:
184
+ - `events` is play order with fermatas and an open repeat kept as
185
+ events.
186
+ - `bars` is the same flattened to one `PlayedBar` per measure played,
187
+ repeats, endings, jumps and replays spelled out. A bar's `index` counts
188
+ in play order; `written` is the number a band reads on the page, the
189
+ same on every pass. Each bar carries its slots, section, key, meter,
190
+ tempo, feel and, when sung, each verse's syllables (`lyrics`).
191
+ - `sections` is each section as played, with its first and last bar and
192
+ `form` (which distinct section it is; replays share their section's
193
+ number).
194
+ - **`diagnostics`:** every error and warning, with its line. `parseChart`
195
+ never throws; a chart with errors still parses what it can.
196
+
197
+ The parse is tens to hundreds of times the size of the text, a few
198
+ kilobytes for each bar played: a 700-byte song whose repeats and replays
199
+ play out parses to about 170 KB of JSON. Its shape follows this
200
+ package's minor versions: 0.17.0, for example, added the `break` and
201
+ `lyrics` line kinds. So:
202
+
203
+ - **Store the text.** It is the stable format: the grammar defines it,
204
+ `printChart` gives it one canonical spelling, and re-parsing an old
205
+ chart with a newer barmark gives the current shape.
206
+ - **Treat a stored parse as a cache**, tagged with the barmark version
207
+ that made it, and parse again when the version changes.
208
+ - **To check a chart before storing it**, parse it and look for
209
+ diagnostics with `severity: "error"`; store `printChart(text)` to keep
210
+ one spelling of each chart.
211
+ - **Times in a recording** belong beside the chart, not in it: key them
212
+ by `PlayedBar.index`, which names the same bar however the chart is
213
+ reformatted or its repeats are spelled (`|: :|` or `x2`), until the
214
+ music itself changes. An open repeat (`x ...`) plays its bars once in
215
+ `bars`, so its later passes have no index of their own.
216
+
170
217
  ## Develop
171
218
 
172
219
  ```
@@ -9,7 +9,10 @@ export function parseInterval(s) {
9
9
  if (!m)
10
10
  return null;
11
11
  const acc = m[1] ?? "";
12
- return { degree: Number(m[2]), alter: acc.startsWith("#") ? acc.length : -acc.length };
12
+ return {
13
+ degree: Number(m[2]),
14
+ alter: acc.startsWith("#") ? acc.length : acc.length === 0 ? 0 : -acc.length,
15
+ };
13
16
  }
14
17
  export function formatInterval(i) {
15
18
  return `${accidentals(i.alter)}${i.degree}`;
@@ -107,7 +107,9 @@ export function chordIntervals(parts, symbol) {
107
107
  else
108
108
  s.push(i);
109
109
  }
110
- return { intervals: s.sort(byDegree), warnings, alteredOpen: parts.extension === "7alt" };
110
+ // Copies: the qualities' intervals are shared constants, and a parse must own its objects.
111
+ const intervals = s.sort(byDegree).map((i) => ({ ...i }));
112
+ return { intervals, warnings, alteredOpen: parts.extension === "7alt" };
111
113
  }
112
114
  /**
113
115
  * Appendix A.5, applied in this order after ♯/♭ become #/b. Each pattern
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "barmark",
3
- "version": "0.17.0",
3
+ "version": "0.17.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": {