barmark 0.17.0 → 0.18.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,46 @@ Releases follow the process in [RELEASING.md](RELEASING.md).
9
9
 
10
10
  ## [Unreleased]
11
11
 
12
+ ## [0.18.0] - 2026-11-07
13
+
14
+ ### Fixed
15
+
16
+ - **A cell of many quoted words parses in linear time.** Each word
17
+ re-read the whole cell and re-split what came before it, so 20,000
18
+ words in one bar took about 25 seconds; `barmark check` on a hostile
19
+ chart, and the MusicXML import's check of what it wrote, waited on it.
20
+ - **A text line starting `constructor:` or `__proto__:` gets no near-miss
21
+ warning.** The directive and credit near misses were looked up on plain
22
+ objects, so those words found `Object.prototype` and suggested
23
+ "function Object() { [native code] }:".
24
+
25
+ ### Changed
26
+
27
+ - **`title: X` warns as a near miss, suggesting `# X`** (Kevin's ruling,
28
+ 2026-11-07, issue #173), as `meter:` suggests `time:`. A chart's title
29
+ is its `#` line; the `title:` line stays text and prints as written.
30
+
31
+ ## [0.17.1] - 2026-11-07
32
+
33
+ A parse is plain data that owns its objects, and the README says what it
34
+ holds and how to store charts.
35
+
36
+ ### Fixed
37
+
38
+ - **A chord's unaltered interval is `alter: 0`, never `-0`,** so a parse
39
+ written to JSON and read back is the same object, as the README now
40
+ promises.
41
+ - **Two parses share no objects.** A chord's intervals were the chord
42
+ vocabulary's own objects, shared by every parse in the process, so
43
+ changing one parse's intervals changed every later parse's. Each chord
44
+ now has its own.
45
+
46
+ ### Technical
47
+
48
+ - **The README documents the parse result**: what is written and what is
49
+ played, and why to store a chart's text and treat a stored parse as a
50
+ cache. A test holds every example chart's parse to a JSON round trip.
51
+
12
52
  ## [0.17.0] - 2026-11-07
13
53
 
14
54
  A grammar change: syllables on notes (4.3), lyric rows and verses in play
@@ -525,7 +565,9 @@ The first working release: the reference parser and printer for the
525
565
 
526
566
  - **A placeholder package that holds the `barmark` name** while the spec and parser are written.
527
567
 
528
- [Unreleased]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.17.0...HEAD
568
+ [Unreleased]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.18.0...HEAD
569
+ [0.18.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.17.1...barmark-v0.18.0
570
+ [0.17.1]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.17.0...barmark-v0.17.1
529
571
  [0.17.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.16.0...barmark-v0.17.0
530
572
  [0.16.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.15.0...barmark-v0.16.0
531
573
  [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
  ```
@@ -212,32 +212,58 @@ const outsideSyllables = (cell) => {
212
212
  */
213
213
  function readWords(cell) {
214
214
  const words = [];
215
- let bare = "";
215
+ const chars = [...cell];
216
+ const sung = inSyllables(chars);
217
+ const bare = tokenCounter();
216
218
  let open = null;
217
- const sung = inSyllables([...cell]);
218
- for (const [i, ch] of [...cell].entries()) {
219
+ for (const [i, ch] of chars.entries()) {
219
220
  if (!QUOTES.has(ch) || (sung[i] && open === null)) {
220
221
  if (open === null)
221
- bare += ch;
222
+ bare.add(ch);
222
223
  continue;
223
224
  }
224
225
  if (open === null) {
225
226
  open = i;
226
227
  continue;
227
228
  }
228
- const text = [...cell]
229
+ const text = chars
229
230
  .slice(open + 1, i)
230
231
  .join("")
231
232
  .trim();
232
233
  if (!text)
233
234
  return { problem: "empty words between quotes", token: '""' };
234
- words.push({ text, at: tokens(bare).length });
235
- bare += " ";
235
+ words.push({ text, at: bare.count() });
236
+ bare.add(" ");
236
237
  open = null;
237
238
  }
238
239
  if (open !== null)
239
- return { problem: "words need a closing quote", token: [...cell].slice(open).join("") };
240
- return { bare, words };
240
+ return { problem: "words need a closing quote", token: chars.slice(open).join("") };
241
+ return { bare: bare.text(), words };
242
+ }
243
+ /** Text built a character at a time that knows how many `tokens` it holds, without splitting it again. */
244
+ function tokenCounter() {
245
+ const parts = [];
246
+ let done = 0;
247
+ let current = false;
248
+ let depth = 0;
249
+ return {
250
+ add(ch) {
251
+ parts.push(ch);
252
+ if (ch === "{")
253
+ depth++;
254
+ if (ch === "}")
255
+ depth = Math.max(0, depth - 1);
256
+ if (/\s/.test(ch) && depth === 0) {
257
+ if (current)
258
+ done++;
259
+ current = false;
260
+ }
261
+ else
262
+ current = true;
263
+ },
264
+ count: () => done + (current ? 1 : 0),
265
+ text: () => parts.join(""),
266
+ };
241
267
  }
242
268
  /** A leading `[n/d]` and the rest of the cell; `bad` is a bracket that is no time signature. */
243
269
  function readMeter(cell) {
@@ -45,7 +45,9 @@ export function nearCredit(text, line) {
45
45
  if (LYRIC_ROW.test(text))
46
46
  return null;
47
47
  const m = /^([^\s:]+)\s*:\s*(.*)$/.exec(text);
48
- const role = m?.[1] ? NEAR_CREDITS[m[1].toLowerCase()] : undefined;
48
+ const word = m?.[1]?.toLowerCase() ?? "";
49
+ // Own keys only: `constructor:` is not a credit's near miss.
50
+ const role = Object.hasOwn(NEAR_CREDITS, word) ? NEAR_CREDITS[word] : undefined;
49
51
  if (!m || !role)
50
52
  return null;
51
53
  return {
@@ -160,10 +160,9 @@ function oldFormat(text, line) {
160
160
  const credit = nearCredit(text, line);
161
161
  if (credit)
162
162
  return credit;
163
- const near = /^(\w+)\s*:\s*(.*)$/.exec(text);
164
- const name = near?.[1] ? NEAR_DIRECTIVES[near[1].toLowerCase()] : undefined;
165
- if (near && name)
166
- return warn(`not a directive; did you mean ${name}:?`, `${name}: ${near[2]}`);
163
+ const directive = nearDirective(text);
164
+ if (directive)
165
+ return warn(directive.message, directive.suggestion);
167
166
  const undeclared = undeclaredLabel(text, line);
168
167
  if (undeclared)
169
168
  return undeclared;
@@ -175,6 +174,19 @@ function oldFormat(text, line) {
175
174
  return warn("chords outside a bar line are text", `| ${words.join(" | ")} |`);
176
175
  return null;
177
176
  }
177
+ /** A misnamed directive (`meter:`), or `title:` for the `#` title (Kevin's ruling, 2026-11-07). */
178
+ function nearDirective(text) {
179
+ const near = /^(\w+)\s*:\s*(.*)$/.exec(text);
180
+ const [, word = "", value = ""] = near ?? [];
181
+ const lower = word.toLowerCase();
182
+ if (lower === "title" && value)
183
+ return { message: "not a directive; the title is the # line", suggestion: `# ${value}` };
184
+ // Own keys only: `constructor:` is not a directive's near miss.
185
+ const name = Object.hasOwn(NEAR_DIRECTIVES, lower) ? NEAR_DIRECTIVES[lower] : undefined;
186
+ if (!near || !name)
187
+ return null;
188
+ return { message: `not a directive; did you mean ${name}:?`, suggestion: `${name}: ${value}` };
189
+ }
178
190
  /** `D \| A \|` (an editor's escaping) as the bar line it would be, if it reads cleanly. */
179
191
  function escapedBarLine(text) {
180
192
  if (!text.includes("\\|"))
@@ -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.18.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": {