barmark 0.7.0 → 0.9.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,67 @@ Releases follow the process in [RELEASING.md](RELEASING.md).
9
9
 
10
10
  ## [Unreleased]
11
11
 
12
+ ## [0.9.0] - 2026-11-02
13
+
14
+ An optional swing amount for `feel:` (`swing 58%`), issue #66. Charts
15
+ that read before read and print the same. Implements the
16
+ [grammar v0.1 draft](https://github.com/kevinpeckham/barmark/blob/main/docs/grammar-v0.1-draft.md).
17
+
18
+ ### Added
19
+
20
+ - **A swing amount** (grammar 7.1, issue #66): `feel: swing 58%`,
21
+ `feel: shuffle 62.5%`, `feel: swing 16 55%`. The amount is where the
22
+ swung note lands, as a percentage of its pair, from 50% to 75%
23
+ inclusive, with the `%` required. It reaches `Directives.swingPercent`
24
+ and each played bar's `swingPercent`; both are absent for the bare word,
25
+ which stays the triplet feel (66.7%). `swing 66.7%` reads and prints as
26
+ `swing`, so every chart that read before reads and prints the same.
27
+ - Errors, each on its line: an amount outside 50% to 75%, more than one
28
+ decimal place, a missing `%` (`swing 58` suggests `swing 58%`), an amount
29
+ on `straight` (suggests `swing` with it), and an amount with no kind.
30
+
31
+ ## [0.8.0] - 2026-11-02
32
+
33
+ `(add9)` and friends inside parentheses, clearer messages for an empty
34
+ section and a rejected tone, and grammar notes from Stem Shovel's issues.
35
+ Charts that read before read the same. Implements the
36
+ [grammar v0.1 draft](https://github.com/kevinpeckham/barmark/blob/main/docs/grammar-v0.1-draft.md).
37
+
38
+ ### Added
39
+
40
+ - **`(addN)` reads inside parentheses** (issue #62). `Am(add9)`,
41
+ `C(add2)`, `C(add4)` and `C(add11)` are aliases of `Am(9)`, `C(2)`,
42
+ `C(4)` and `C(11)`, alone or in a list (`C(b9,add11)` is `C(b9,11)`),
43
+ and print in the canonical form. `add13` and `add#11` stay errors.
44
+ Grammar Appendix A.5 and the decisions log.
45
+
46
+ ### Changed
47
+
48
+ - **An empty section that matches nothing says how to fix it** (issue
49
+ #63). `## Progression` with no bars and no earlier section of that name
50
+ reported `no earlier section named "Progression" to replay`; it now
51
+ reports `"Progression" has no bars and no earlier section has that
52
+ name; write its bars under it, or remove the heading`. When the name is
53
+ written out later in the chart, the message says replays use only
54
+ earlier sections and gives that line. It is still an error: a section
55
+ with no bars replays (grammar §6), and there is no intentionally empty
56
+ section.
57
+ - **Grammar notes; no chart changes meaning.** §8 gains a note for
58
+ generators: write one slot per beat (the 2.1 beat, so 6/8 has two),
59
+ then canonicalize; a length that is not a whole number of beats needs
60
+ an eighth-note grid or a `_` group; leave out a section with no bars
61
+ (issue #64). §2.3: a tool that knows only the chord part writes `N.C.`
62
+ for its rests, not `--` (issue #65). §7.1: `feel:` names a kind of
63
+ groove, not an amount, so `swing 60%` stays an error, and the "custom
64
+ swing ratios" open question is closed (issue #66).
65
+
66
+ ### Fixed
67
+
68
+ - **A rejected tone in parentheses is named as written.** `C(add9x)`
69
+ reported `"x" is not a tone a parenthesis can add`, and `Am(add9)`
70
+ reported `""`, because a bare `add9` was looked for inside the group
71
+ too; the message now quotes the tone as written (`"add9x"`).
72
+
12
73
  ## [0.7.0] - 2026-11-02
13
74
 
14
75
  Print a chart you have already parsed, and conformance fixtures from real
@@ -160,7 +221,9 @@ The first working release: the reference parser and printer for the
160
221
 
161
222
  - **A placeholder package that holds the `barmark` name** while the spec and parser are written.
162
223
 
163
- [Unreleased]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.7.0...HEAD
224
+ [Unreleased]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.9.0...HEAD
225
+ [0.9.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.8.0...barmark-v0.9.0
226
+ [0.8.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.7.0...barmark-v0.8.0
164
227
  [0.7.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.6.0...barmark-v0.7.0
165
228
  [0.6.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.5.0...barmark-v0.6.0
166
229
  [0.5.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.4.0...barmark-v0.5.0
package/README.md CHANGED
@@ -47,7 +47,7 @@ import {
47
47
 
48
48
  const chart = parseChart(text);
49
49
  chart.title; // "Example Song"
50
- chart.bars; // every bar in play order: slots, section, key, meter, tempo, feel
50
+ chart.bars; // every bar in play order: slots, section, key, meter, tempo, feel (and swingPercent)
51
51
  chart.sections; // each section as played, with its first and last bar
52
52
  chart.diagnostics; // errors and warnings, each with a line number
53
53
 
@@ -55,9 +55,40 @@ function parseTempoChange(text) {
55
55
  const to = m[2] === undefined ? null : parseTempo(m[2]);
56
56
  return m[2] !== undefined && to === null ? null : { kind, to };
57
57
  }
58
+ /** The amount that means the same as the bare word: the triplet feel, ⅔ written to one decimal. */
59
+ const TRIPLET_PERCENT = 66.7;
60
+ const FEEL_ERROR = "feel must be straight, swing, shuffle or swing 16, optionally with an amount (swing 58%)";
61
+ /** A feel and an amount: `swing 16 55%` is "swing 16", "55", "%". */
62
+ const WITH_AMOUNT = /^(.*?)\s*(\d+(?:\.\d+)?)(%?)$/;
63
+ /** Why `head digits sign` isn't a feel with an amount, or null when it is (7.1). */
64
+ function amountError(head, digits, sign) {
65
+ const feel = FEELS.find((f) => f === head);
66
+ if (head && !feel)
67
+ return FEEL_ERROR;
68
+ if (!feel)
69
+ return `a swing amount follows a feel: swing ${digits}%`;
70
+ if (feel === "straight")
71
+ return `straight takes no amount; write swing ${digits}%`;
72
+ if (!sign)
73
+ return `a swing amount needs a % sign: ${feel} ${digits}%`;
74
+ if (/\.\d{2}/.test(digits))
75
+ return "a swing amount takes at most one decimal place";
76
+ const amount = Number(digits);
77
+ return amount < 50 || amount > 75 ? "a swing amount must be from 50% to 75%" : null;
78
+ }
79
+ /** `swing`, `swing 58%`, `swing 16 55%`: a kind, then an optional amount (7.1). */
58
80
  function parseFeel(text) {
59
81
  const lower = text.toLowerCase();
60
- return FEELS.find((f) => f === lower) ?? null;
82
+ const bare = FEELS.find((f) => f === lower);
83
+ if (bare)
84
+ return { feel: bare };
85
+ const [, head = "", digits = "", sign = ""] = WITH_AMOUNT.exec(lower) ?? [];
86
+ const error = digits ? amountError(head, digits, sign) : FEEL_ERROR;
87
+ const feel = FEELS.find((f) => f === head);
88
+ if (error || !feel)
89
+ return { error: error ?? FEEL_ERROR };
90
+ const amount = Number(digits);
91
+ return amount === TRIPLET_PERCENT ? { feel } : { feel, swingPercent: amount };
61
92
  }
62
93
  /**
63
94
  * A directive line: one or more `name: value` parts separated by commas.
@@ -113,10 +144,10 @@ export function parseDirectiveLine(text, line) {
113
144
  }
114
145
  else {
115
146
  const feel = parseFeel(value);
116
- if (feel)
117
- set.feel = feel;
147
+ if ("error" in feel)
148
+ error(feel.error, value);
118
149
  else
119
- error("feel must be straight, swing, shuffle or swing 16", value);
150
+ Object.assign(set, feel);
120
151
  }
121
152
  }
122
153
  return { set, diagnostics };
@@ -4,6 +4,19 @@ export const MAX_EXPANDED_BARS = 10_000;
4
4
  /** Repeats of bodies that play no bars (fermatas only) are bounded too. */
5
5
  const MAX_WORK = MAX_EXPANDED_BARS * 10;
6
6
  const normalize = (name) => name.toLowerCase().replace(/\s+/g, " ").trim();
7
+ const isWritten = (s) => s.lines.some((l) => l.kind === "bars" || l.kind === "invalid");
8
+ /** Grammar §6: an empty section that matches nothing, and how to fix it. */
9
+ function unmatchedReplay(heading, sections) {
10
+ const name = normalize(heading.name);
11
+ const later = sections.find((s) => s.heading &&
12
+ s.heading.line > heading.line &&
13
+ normalize(s.heading.name) === name &&
14
+ isWritten(s))?.heading;
15
+ const fix = later
16
+ ? `replays use only earlier sections (it is written at line ${later.line})`
17
+ : "write its bars under it, or remove the heading";
18
+ return `"${heading.name}" has no bars and no earlier section has that name; ${fix}`;
19
+ }
7
20
  /** Every played bar in order, with an open repeat's pass included once. */
8
21
  export function flattenBars(events) {
9
22
  return events.flatMap((e) => e.kind === "bar" ? [e.bar] : e.kind === "open" ? flattenBars(e.events) : []);
@@ -113,6 +126,7 @@ export function expand(lines) {
113
126
  tempo: null,
114
127
  change: null,
115
128
  feel: "straight",
129
+ swingPercent: undefined,
116
130
  };
117
131
  const warned = new Set();
118
132
  const warn = (line, message, token) => {
@@ -146,8 +160,10 @@ export function expand(lines) {
146
160
  }
147
161
  if (set.tempoChange)
148
162
  changeTempo(set.tempoChange, line);
149
- if (set.feel)
163
+ if (set.feel) {
150
164
  state.feel = set.feel;
165
+ state.swingPercent = set.swingPercent;
166
+ }
151
167
  };
152
168
  let count = 0;
153
169
  let work = 0;
@@ -185,7 +201,7 @@ export function expand(lines) {
185
201
  token: `${k}`,
186
202
  });
187
203
  }
188
- const { key, tempo, change: tempoChange, feel } = state;
204
+ const { key, tempo, change: tempoChange, feel, swingPercent } = state;
189
205
  out.push({
190
206
  kind: "bar",
191
207
  bar: {
@@ -197,6 +213,7 @@ export function expand(lines) {
197
213
  tempo,
198
214
  tempoChange,
199
215
  feel,
216
+ ...(swingPercent === undefined ? {} : { swingPercent }),
200
217
  slots: p.slots,
201
218
  },
202
219
  });
@@ -258,7 +275,7 @@ export function expand(lines) {
258
275
  }
259
276
  sectionName = h.name;
260
277
  const out = [];
261
- const isDefinition = s.lines.some((l) => l.kind === "bars" || l.kind === "invalid");
278
+ const isDefinition = isWritten(s);
262
279
  let replayOf = null;
263
280
  if (isDefinition) {
264
281
  definitions.set(normalize(h.name), s);
@@ -272,7 +289,7 @@ export function expand(lines) {
272
289
  continue;
273
290
  const source = definitions.get(normalize(h.name));
274
291
  if (!source?.heading) {
275
- error(h.line, `no earlier section named "${h.name}" to replay`, h.name);
292
+ error(h.line, unmatchedReplay(h, sections), h.name);
276
293
  continue;
277
294
  }
278
295
  replayOf = source.heading.line;
@@ -79,7 +79,7 @@ function printDirectives(d) {
79
79
  if (d.tempoChange)
80
80
  parts.push(`tempo: ${printTempoChange(d.tempoChange)}`);
81
81
  if (d.feel)
82
- parts.push(`feel: ${d.feel}`);
82
+ parts.push(`feel: ${d.feel}${d.swingPercent === undefined ? "" : ` ${d.swingPercent}%`}`);
83
83
  return parts.join(", ");
84
84
  }
85
85
  /**
@@ -32,6 +32,12 @@ export type Directives = {
32
32
  tempo?: number;
33
33
  tempoChange?: TempoChange;
34
34
  feel?: Feel;
35
+ /**
36
+ * How far a swing or shuffle swings: where the swung note lands, as a
37
+ * percentage of its pair (50 to 75). Absent for the bare word, which
38
+ * means 66.7 (the triplet feel), and for straight.
39
+ */
40
+ swingPercent?: number;
35
41
  };
36
42
  /** A chord slot holds a chord symbol or a note set; `chord.kind` tells which. */
37
43
  export type SimpleSlot = {
@@ -110,6 +116,8 @@ export type PlayedBar = {
110
116
  to: number | null;
111
117
  } | null;
112
118
  feel: Feel;
119
+ /** The swing amount in force (Directives.swingPercent); absent when the feel has none. */
120
+ swingPercent?: number;
113
121
  /** `%` resolved to the copied slots; holds stay holds. */
114
122
  slots: Slot[];
115
123
  };
@@ -86,9 +86,13 @@ function normalizeSymbol(symbol) {
86
86
  for (const [pattern, replacement] of ALIASES)
87
87
  rest = rest.replace(pattern, replacement);
88
88
  rest = logicGroups(rest);
89
- const added = [...rest.matchAll(/add(2|4|9|11)/g)].map((m) => m[1] ?? "");
89
+ // `(add9)` is `(9)`: inside a group, `add` before a tone it may add is dropped.
90
+ rest = rest.replace(/(?<=[(,]\s*)add(2|4|9|11)(?=\s*[,)])/g, "$1");
91
+ // A bare `add9` outside any group; what is left inside one is the tokenizer's to name.
92
+ const bare = /add(2|4|9|11)(?![^(]*\))/g;
93
+ const added = [...rest.matchAll(bare)].map((m) => m[1] ?? "");
90
94
  if (added.length) {
91
- rest = rest.replace(/add(2|4|9|11)/g, "");
95
+ rest = rest.replace(bare, "");
92
96
  const close = rest.indexOf(")");
93
97
  if (close >= 0)
94
98
  rest = `${rest.slice(0, close)},${added.join(",")}${rest.slice(close)}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "barmark",
3
- "version": "0.7.0",
3
+ "version": "0.9.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": {