barmark 0.23.1 → 0.25.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,81 @@ Releases follow the process in [RELEASING.md](RELEASING.md).
9
9
 
10
10
  ## [Unreleased]
11
11
 
12
+ ## [0.25.0] - 2026-11-19
13
+
14
+ Grammar changes: more spellings of the major seventh (Kevin, 2026-11-18).
15
+ No chord that read before changes meaning.
16
+
17
+ ### Added
18
+
19
+ - **More spellings of the major seventh** (Kevin, 2026-11-18, with
20
+ Claude's rulings the same day; grammar decisions log): `Maj` and `ma`
21
+ before 9 and 13 as before 7 (`CMaj9` and `Cma9` are `Cmaj9`, `Cma13` is
22
+ `Cmaj13`); the delta after `m`, `-` or `min` (`CmΔ`, `C-Δ7` and `CminΔ`
23
+ are `Cmmaj7`, `CmΔ9` is `Cmmaj9`); and the increment sign `∆` (a Mac's
24
+ Option-J) and the triangles `△` and `▵` as the delta (`C∆7` is `Cmaj7`,
25
+ `Cm△9` is `Cmmaj9`), each with whatever may follow its canonical
26
+ spelling (`CMaj9(#11)`, `CmΔ/Eb`). They print canonically. `Δ11`,
27
+ `Maj11`, `mΔ13`, `CmMaj7` and `Cmma7` stay errors, and no chord that
28
+ read before changes.
29
+
30
+ ## [0.24.0] - 2026-11-14
31
+
32
+ Grammar changes: the flat sixth, `add` before any tone, and `Δ9`/`Δ13`
33
+ (Kevin, 2026-11-13 and 2026-11-14). No chord that read before changes
34
+ meaning, except the misreadings fixed below.
35
+
36
+ ### Added
37
+
38
+ - **The flat sixth.** `b6` is a tone a parenthesis can add, with its own
39
+ canonical spelling: `F#m(b6)` and `F#m(♭6)` read (F♯ A C♯ D, Harte
40
+ `F#:min(b6)`) and print `F#m(b6)`, never rewritten to `(b13)`; after an
41
+ extension it needs no parentheses (`F#m7b6` is F♯ A C♯ D E and prints
42
+ `F#m7(b6)`).
43
+ It replaces the 6 of a sixth chord (`C6(b6)` is C E G A♭) and adds on
44
+ any other; `C(b6,b13)` warns that the chord already contains the note.
45
+ `Cb6` is still the C♭ sixth chord.
46
+ - **`add` before any tone a parenthesis can add**, bare or in the
47
+ parentheses, alone or in a list: `Cadd13` is `C(13)`, `Cadd#11` is
48
+ `C(#11)`, `F#maddb6` and `F#m(addb6)` are `F#m(b6)`, `F#maddb13` is
49
+ `F#m(b13)`, `Am(b9,add13)` is `Am(b9,13)`. Before, only `add2`, `add4`,
50
+ `add9` and `add11` read. Bare, a newly accepted tone is not followed by
51
+ a digit, nor by a slash that starts no bass: `Cadd69` stays an error,
52
+ never `C9(6)`, and `Cadd6/9` is refused as written.
53
+ - **`Δ9` and `Δ13`** are `maj9` and `maj13`, with whatever follows:
54
+ `CΔ9(#11)` is `Cmaj9(#11)`, `DΔ9/F#` is `Dmaj9/F#`. `Δ11` stays an error.
55
+ - **Suggestions for refused tones.** `(b2)`, `(#2)`, `(#4)` and `(b7)`
56
+ stay errors, now suggesting `(b9)`, `(#9)`, `(#11)` and `(7)`, every
57
+ such tone in a list replaced (`C7(b2,#4)` suggests `C7(b9,#11)`); and
58
+ an alteration straight after a quality or `sus` with no extension
59
+ suggests the parenthesised form, as an altered fifth after `m` did
60
+ (`Cmb6` suggests `Cm(b6)`, `Cdimb9` `Cdim(b9)`, `Csus4b9`
61
+ `Csus4(b9)`), however the quality is spelled (`C-b6` and `Cminb6`
62
+ suggest `Cm(b6)`, `C+b6` `Caug(b6)`, `Csusb9` `Csus4(b9)`). A suggestion is offered only when it reads with the root
63
+ and bass as written.
64
+
65
+ ### Changed
66
+
67
+ - **A Harte label with `b6` converts to `(b6)`**: `harteToBarmark("C:min(b6)")`
68
+ is `Cm(b6)`, where it was `Cm(b13)`, the same notes. Labels with `b13`
69
+ are unchanged, and naming a set of notes (`nameNotes`) still writes
70
+ `(b13)`. A Harte label with a flat sixth is not given a sixth-chord
71
+ name with its sixth replaced where a plainer name exists:
72
+ `C:maj(b6,9)` is `C(b6,9)`, not `C6/9(b6)`; `C:maj6(b6)` is `C(b6,6)`. Labels without a flat sixth
73
+ convert as before (`C:7(b9,13)` is `C13(b9)`).
74
+
75
+ ### Fixed
76
+
77
+ - **A bare `add` never changes the root.** `Cadd9b13` read as `Cb13(9)`,
78
+ a C♭ chord, and `Cadd9#11` as a C♯ chord: taking `add9` out left the
79
+ alteration's accidental against the root. Such a symbol is now an
80
+ error suggesting the items in one parenthesis (`C(9,b13)`, `C(9,#11)`),
81
+ refused tones replaced by their counterparts (`Cadd9#4` suggests
82
+ `C(9,#11)`), and none where that too would change the root
83
+ (`Cadd9b13bm7`).
84
+ `Bbadd9` and `Abaddb6` keep their roots; `Bbadd9b13` and `Cmadd9b13`
85
+ now suggest `Bb(9,b13)` and `Cm(9,b13)`.
86
+
12
87
  ## [0.23.1] - 2026-11-10
13
88
 
14
89
  ### Changed
@@ -854,7 +929,9 @@ The first working release: the reference parser and printer for the
854
929
 
855
930
  - **A placeholder package that holds the `barmark` name** while the spec and parser are written.
856
931
 
857
- [Unreleased]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.23.1...HEAD
932
+ [Unreleased]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.25.0...HEAD
933
+ [0.25.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.24.0...barmark-v0.25.0
934
+ [0.24.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.23.1...barmark-v0.24.0
858
935
  [0.23.1]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.23.0...barmark-v0.23.1
859
936
  [0.23.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.22.0...barmark-v0.23.0
860
937
  [0.22.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.21.0...barmark-v0.22.0
@@ -1,6 +1,6 @@
1
1
  import { formatInterval, intervalBetween, intervalKey, parseInterval, transpose, } from "./intervals.js";
2
2
  import { printSuffix } from "./print.js";
3
- import { enumerateSuffixes, intervalSetKey } from "./suffixes.js";
3
+ import { enumerateSuffixes, intervalSetKey, replacesOwnSixth } from "./suffixes.js";
4
4
  import { byDegree, chordIntervals, HARTE_SHORTHANDS, isOmission, } from "./vocabulary.js";
5
5
  /**
6
6
  * The Harte label for a parsed chord or note set: the largest shorthand
@@ -87,12 +87,17 @@ function shorthandFor(intervals) {
87
87
  }
88
88
  return shorthandNames.get(intervalSetKey(intervals));
89
89
  }
90
- /** The candidate naming most degrees as written; on a tie, a shorthand's name, else the first. */
90
+ /**
91
+ * The candidate naming most degrees as written; on a tie, a shorthand's
92
+ * name, else the first that is not a sixth chord with its sixth replaced
93
+ * by a flat sixth (`C(b6,9)`, not `C6/9(b6)`), else the first.
94
+ */
91
95
  function bestSuffix(candidates, exact, intervals) {
92
96
  const most = Math.max(...candidates.map(exact));
93
97
  const tied = candidates.filter((c) => exact(c) === most);
94
98
  const shorthand = shorthandFor(intervals);
95
- return (tied.find((c) => c.suffix === shorthand) ?? tied[0])?.suffix;
99
+ const plain = tied.find((c) => !replacesOwnSixth(c));
100
+ return (tied.find((c) => c.suffix === shorthand) ?? plain ?? tied[0])?.suffix;
96
101
  }
97
102
  const HARTE = /^([A-G][#b]*)(?::([^(/]*)(?:\(([^)]*)\))?)?(?:\/([#b]*\d+))?$/;
98
103
  /** A Harte label's root, intervals (shorthand at its intended meaning, list applied) and bass. */
@@ -84,8 +84,8 @@ function family(suffix) {
84
84
  return 2;
85
85
  return 4;
86
86
  }
87
- /** A tone the plain-tone tie-break puts last: `(2)`, `(4)`, `(6)` lose to `(9)`, `(11)`, `(13)`. */
88
- const PLAIN_TONES = ["2", "4", "6"];
87
+ /** A tone the plain-tone tie-break puts last: `(2)`, `(4)`, `(6)`, `(b6)` lose to `(9)`, `(11)`, `(13)`, `(b13)`. */
88
+ const PLAIN_TONES = ["2", "4", "6", "b6"];
89
89
  /**
90
90
  * The order spec 5.6 ranks candidates by: cost (added tones, a slash, a
91
91
  * supplied fifth), then family, root in the bass, plain tones, the shorter
@@ -1,10 +1,10 @@
1
1
  import { toHarte } from "./harte.js";
2
2
  import { noteSemitone, transpose } from "./intervals.js";
3
3
  import { canonicalParts, printChord } from "./print.js";
4
- import { alteredFifth, bareScan, intoGroup, pullBare, separate, stackedWarning, } from "./stacked.js";
5
- import { ALIASES, chordIntervals, EXTENSIONS, isOmission, OMISSIONS, rejection, TONES, validateParts, } from "./vocabulary.js";
4
+ import { ALTERATIONS, bareAlteration, bareScan, intoGroup, pullBare, separate, stackedWarning, } from "./stacked.js";
5
+ import { ADD_TONE, ALIASES, BARE_ADD_TONE, COUNTERPARTS, chordIntervals, EXTENSIONS, isOmission, OMISSIONS, rejection, TONES, validateParts, } from "./vocabulary.js";
6
6
  const ROOT = /^[A-G][#b]?/;
7
- const INLINE_ALTERATION = /^(b5|#5|b9|#9|#11|b13)/;
7
+ const INLINE_ALTERATION = new RegExp(`^(${ALTERATIONS})`);
8
8
  /** Splits a symbol into its parts, or names the text it could not read. */
9
9
  function tokenize(symbol) {
10
10
  const root = ROOT.exec(symbol)?.[0];
@@ -122,9 +122,27 @@ function logicGroups(rest) {
122
122
  const others = tones.filter((t) => t !== "5");
123
123
  return `5${others.length ? `(${others.join(",")})` : ""}${joined.slice(group[0].length)}`;
124
124
  }
125
- const BARE_ADD = bareScan("add(?:2|4|9|11)");
126
- /** The text a symbol is read from: ♯ and ♭ as # and b (Appendix A.5). */
127
- const ascii = (symbol) => symbol.replace(/♯/g, "#").replace(/♭/g, "b");
125
+ const BARE_ADD = bareScan(`add(?:${BARE_ADD_TONE})`);
126
+ /** A bare `add` and the accidental straight after it: `add9b` in `Cadd9b13`. */
127
+ const ADD_THEN_ACCIDENTAL = bareScan(`add(?:${BARE_ADD_TONE})[#b]`);
128
+ /** A bare `add` and the alterations straight after it: `add9b13` in `Cmadd9b13`. */
129
+ /** An alteration, or a refused tone with a counterpart (`#4`), as written after a bare `add`. */
130
+ const AFTER_ADD = `${ALTERATIONS}|${Object.keys(COUNTERPARTS).join("|")}`;
131
+ const ADD_THEN_ALTERATIONS = bareScan(`(add(?:${BARE_ADD_TONE}))((?:${AFTER_ADD})+)`);
132
+ const EACH_ALTERATION = new RegExp(AFTER_ADD, "g");
133
+ /** `add` before a tone inside a group: `(add9)`, `(b9,addb6)`. */
134
+ const GROUP_ADD = new RegExp(String.raw `(?<=[(,]\s*)add(${ADD_TONE})(?=\s*[,)])`, "g");
135
+ /** A group and its items. */
136
+ const GROUP_ITEMS = /\(([^()]*)\)/g;
137
+ const BASS_AT_END = /\/([A-G][#b]?)$/;
138
+ /** The text after a root with Appendix A.5's aliases applied: `-b6` is `mb6`. */
139
+ function aliased(rest) {
140
+ for (const [pattern, replacement] of ALIASES)
141
+ rest = rest.replace(pattern, replacement);
142
+ return rest;
143
+ }
144
+ /** The text a symbol is read from: ♯ and ♭ as # and b, ∆ △ ▵ as Δ (Appendix A.5). */
145
+ const ascii = (symbol) => symbol.replace(/♯/g, "#").replace(/♭/g, "b").replace(/[∆△▵]/g, "Δ");
128
146
  /** Appendix A.5 and A.6: rejections, then aliases into canonical vocabulary. */
129
147
  function normalizeSymbol(text) {
130
148
  const rejected = rejection(text, noteSemitone);
@@ -135,17 +153,73 @@ function normalizeSymbol(text) {
135
153
  // Stacked spellings first, on the name as written; the aliases then read what is left.
136
154
  const separated = separate(rest);
137
155
  rest = separated.text;
138
- for (const [pattern, replacement] of ALIASES)
139
- rest = rest.replace(pattern, replacement);
156
+ rest = aliased(rest);
140
157
  rest = logicGroups(rest);
141
158
  // `(omit3)` and `(omit 3)` are `(no3)`.
142
159
  rest = rest.replace(/(?<=[(,]\s*)omit\s*(\d+)(?=\s*[,)])/g, "no$1");
143
160
  // `(add9)` is `(9)`: inside a group, `add` before a tone it may add is dropped.
144
- rest = rest.replace(/(?<=[(,]\s*)add(2|4|9|11)(?=\s*[,)])/g, "$1");
161
+ rest = rest.replace(GROUP_ADD, "$1");
145
162
  // A bare `add9` outside any group; what is left inside one is the tokenizer's to name.
146
163
  const bare = pullBare(rest, BARE_ADD);
147
- rest = intoGroup(bare.text, bare.taken.map((a) => a.slice(3)));
148
- return { text: root + rest, separated };
164
+ const added = bare.taken.map((a) => a.slice(3));
165
+ if (added.length && root.length === 1 && /^[b#]/.test(bare.text))
166
+ return (addThenAlteration(text, true) ?? {
167
+ message: `${text}: an accidental would join the root ${root}`,
168
+ token: text,
169
+ });
170
+ return { text: root + intoGroup(bare.text, added), separated };
171
+ }
172
+ /**
173
+ * A bare `add` straight before an accidental (`Cadd9b13`, `Cmadd9b13`): an
174
+ * error when taking the `add` out would join the accidental to the root
175
+ * (`joins`) or leave text that does not read, suggesting the items in one
176
+ * parenthesis when that reads with the root and bass as written; null when
177
+ * there is no such `add`.
178
+ */
179
+ function addThenAlteration(text, joins) {
180
+ const found = pullBare(text, ADD_THEN_ACCIDENTAL).taken[0];
181
+ if (!found)
182
+ return null;
183
+ const [add, accidental] = [found.slice(0, -1), found.slice(-1)];
184
+ const root = ROOT.exec(text)?.[0] ?? "";
185
+ const why = joins ? `would join the root ${root}` : "starts an alteration";
186
+ const suggestion = offered(text, eachAdded(text));
187
+ return {
188
+ message: `${text}: the "${accidental}" after ${add} ${why}; the items go in one parenthesis`,
189
+ token: text,
190
+ ...(suggestion ? { suggestion: suggestion.canonical } : {}),
191
+ };
192
+ }
193
+ /** The text with each alteration straight after a bare `add` given an `add` of its own: `Cadd9addb13`. */
194
+ function eachAdded(text) {
195
+ return text.replace(ADD_THEN_ALTERATIONS, (match, ...args) => {
196
+ const [inner, add = "", alterations = ""] = args;
197
+ if (inner !== undefined)
198
+ return match;
199
+ return add + alterations.replace(EACH_ALTERATION, (tone) => `add${COUNTERPARTS[tone] ?? tone}`);
200
+ });
201
+ }
202
+ /** The chord `candidate` names, when it reads and keeps the root and bass `text` is written with. */
203
+ function offered(text, candidate) {
204
+ return candidate === text ? null : keepsWritten(text, parseChord(candidate));
205
+ }
206
+ /** The chord read, when it reads with the root and bass `text` is written with. */
207
+ function keepsWritten(text, r) {
208
+ const root = ROOT.exec(text)?.[0];
209
+ const bass = BASS_AT_END.exec(text)?.[1] ?? root;
210
+ return r.ok && r.value.root === root && r.value.bass === bass ? r.value : null;
211
+ }
212
+ /** Each refused tone in a group replaced by its counterpart (`(b2)` is `(b9)`), item by item. */
213
+ function counterparts(normal) {
214
+ return normal.replace(GROUP_ITEMS, (_, inner) => {
215
+ const items = inner.split(",").map((item) => {
216
+ const tone = item.trim();
217
+ return Object.hasOwn(COUNTERPARTS, tone)
218
+ ? item.replace(tone, COUNTERPARTS[tone] ?? tone)
219
+ : item;
220
+ });
221
+ return `(${items.join(",")})`;
222
+ });
149
223
  }
150
224
  /**
151
225
  * The warning a stacked spelling reads with (grammar 3): its suggestion is
@@ -168,12 +242,36 @@ export function parseChord(symbol) {
168
242
  if (!("text" in normal))
169
243
  return { ok: false, error: normal };
170
244
  const r = readChord(symbol, normal.text);
171
- if (!r.ok) {
172
- return { ok: false, error: alteredFifth(symbol, text, r.error, (s) => parseChord(s).ok) };
173
- }
245
+ if (!r.ok)
246
+ return { ok: false, error: suggest(symbol, text, normal.text, r.error) };
174
247
  const warning = stacked(symbol, text, normal, r.value.canonical);
175
248
  return warning ? { ...r, warnings: [warning, ...r.warnings] } : r;
176
249
  }
250
+ /**
251
+ * The error with a suggestion where one reads with the root and bass as
252
+ * written (Appendix A.6): an alteration after a bare `add` in one
253
+ * parenthesis with it (`Cmadd9b13` is `Cm(9,b13)`), an alteration moved into
254
+ * the parentheses (`Cmb6` is `Cm(b6)`), or each refused tone replaced by its
255
+ * counterpart (`C7(b2,#4)` is `C7(b9,#11)`).
256
+ */
257
+ function suggest(symbol, text, normal, error) {
258
+ const added = addThenAlteration(text, false);
259
+ if (added?.suggestion)
260
+ return added;
261
+ const reads = (s) => parseChord(s).ok;
262
+ const offers = (s) => offered(text, s) !== null;
263
+ const root = ROOT.exec(text)?.[0] ?? "";
264
+ const moved = bareAlteration(symbol, root + aliased(text.slice(root.length)), error, reads, offers);
265
+ if (moved !== error)
266
+ return moved;
267
+ // Only the refused tones change, so a rewrite that reads is the fix for this error. It is
268
+ // read as the normalised text it already is; an unchanged `normal` is never read again,
269
+ // which would recurse once per bare omission.
270
+ const suggestion = counterparts(normal);
271
+ if (suggestion === normal)
272
+ return error;
273
+ return keepsWritten(text, readChord(symbol, suggestion)) ? { ...error, suggestion } : error;
274
+ }
177
275
  /** The chord a normalized symbol names. */
178
276
  function readChord(symbol, text) {
179
277
  const parts = readParts(text, symbol);
@@ -34,12 +34,16 @@ export type Separated = {
34
34
  export declare function separate(rest: string): Separated;
35
35
  /** The warning a stacked spelling reads with, suggesting `suggestion`; null when it isn't one. */
36
36
  export declare function stackedWarning(symbol: string, separated: Separated, suggestion: string): Diagnostic | null;
37
+ /** The altered tones, which may follow an extension with no parenthesis (grammar 3). */
38
+ export declare const ALTERATIONS: string;
37
39
  /**
38
40
  * The error for a symbol that can't be read, with a suggestion when it
39
- * writes an altered fifth before the parenthesis on a chord with no
40
- * extension (grammar 3 keeps `Ab5` the A♭ power chord). `reads` says
41
- * whether a suggestion reads. Where the root's own accidental could be the
42
- * fifth's (`Gb5(omit3)`), the message says it is ambiguous, with no
43
- * suggestion; only when that fifth reading would itself read.
41
+ * writes an alteration (an altered fifth, `b6`, `b9`, …) before the
42
+ * parenthesis on a chord with no extension (grammar 3 keeps `Ab5` the A♭
43
+ * power chord and `Cb6` the C♭ sixth chord). `reads` says whether a
44
+ * symbol reads, `offers` whether it reads as a suggestion may (its root and
45
+ * bass as written). Where the root's own accidental could be the
46
+ * alteration's (`Gb5(omit3)`), the message says it is ambiguous, with no
47
+ * suggestion; only when that reading would itself read.
44
48
  */
45
- export declare function alteredFifth(symbol: string, text: string, error: Diagnostic, reads: (symbol: string) => boolean): Diagnostic;
49
+ export declare function bareAlteration(symbol: string, text: string, error: Diagnostic, reads: (symbol: string) => boolean, offers: (suggestion: string) => boolean): Diagnostic;
@@ -1,7 +1,8 @@
1
+ import { TONES } from "./vocabulary.js";
1
2
  /** The shape of one parenthesis item; the tokenizer judges what it names. */
2
- const ITEM = /^(?:add\d+|(?:omit\s*|no)\d+|[b#]?\d+)$/;
3
- /** Where an item run together with the one before it starts. */
4
- const ITEM_START = /(?=add|omit|no|[b#])/;
3
+ const ITEM = /^(?:add[b#]?\d+|(?:omit\s*|no)\d+|[b#]?\d+)$/;
4
+ /** Where an item run together with the one before it starts: never between `add` and its tone's accidental. */
5
+ const ITEM_START = /(?=add|omit|no|(?<!add)[b#])/;
5
6
  /** A slash bass at the end of the text after the root. */
6
7
  const BASS = /\/[A-G][#b]?$/;
7
8
  /** Where the chord's name ends: its first parenthesis or slash bass. */
@@ -80,42 +81,55 @@ export function stackedWarning(symbol, separated, suggestion) {
80
81
  return null;
81
82
  return { message: `${symbol}: ${why.join("; ")}`, token: symbol, suggestion };
82
83
  }
83
- /** An altered fifth straight after the root (and `m`), with no extension: `F#b5(omit3)`. */
84
- const ALTERED_FIFTH = /^([A-G][#b]?)(m?)([b#]5)(?:\(([^()]*)\))?(\/[A-G][#b]?)?$/;
85
- /** A root whose accidental a following `5` could be read with: `Gb5`, `G#5`. */
86
- const SWALLOWED = /^([A-G])([#b])5(?:\(([^()]*)\))?(\/[A-G][#b]?)?$/;
84
+ /** The altered tones, which may follow an extension with no parenthesis (grammar 3). */
85
+ export const ALTERATIONS = TONES.filter((t) => /^[b#]/.test(t)).join("|");
86
+ const GROUP_AND_BASS = String.raw `(?:\(([^()]*)\))?(\/[A-G][#b]?)?$`;
87
+ /** An alteration straight after the root (and its quality or sus), with no extension: `F#b5(omit3)`, `Cmb6`. */
88
+ const ALTERED = new RegExp(`^([A-G][#b]?)(m|dim|aug|5|sus2|sus4)?(${ALTERATIONS})${GROUP_AND_BASS}`);
89
+ /** A root whose accidental a following number could be read with: `Gb5`, `G#5`, `Ab6`. */
90
+ const SWALLOWED = new RegExp(`^([A-G])(${ALTERATIONS})${GROUP_AND_BASS}`);
91
+ /** What a root's accidental and the number after it always are (grammar 3). */
92
+ const CHORD_KIND = {
93
+ "5": "power",
94
+ "6": "sixth",
95
+ "9": "ninth",
96
+ "11": "eleventh",
97
+ "13": "thirteenth",
98
+ };
87
99
  /**
88
100
  * The error for a symbol that can't be read, with a suggestion when it
89
- * writes an altered fifth before the parenthesis on a chord with no
90
- * extension (grammar 3 keeps `Ab5` the A♭ power chord). `reads` says
91
- * whether a suggestion reads. Where the root's own accidental could be the
92
- * fifth's (`Gb5(omit3)`), the message says it is ambiguous, with no
93
- * suggestion; only when that fifth reading would itself read.
101
+ * writes an alteration (an altered fifth, `b6`, `b9`, …) before the
102
+ * parenthesis on a chord with no extension (grammar 3 keeps `Ab5` the A♭
103
+ * power chord and `Cb6` the C♭ sixth chord). `reads` says whether a
104
+ * symbol reads, `offers` whether it reads as a suggestion may (its root and
105
+ * bass as written). Where the root's own accidental could be the
106
+ * alteration's (`Gb5(omit3)`), the message says it is ambiguous, with no
107
+ * suggestion; only when that reading would itself read.
94
108
  */
95
- export function alteredFifth(symbol, text, error, reads) {
109
+ export function bareAlteration(symbol, text, error, reads, offers) {
96
110
  const s = SWALLOWED.exec(text);
97
111
  if (s) {
98
- const [, letter = "", accidental = "", inner, bass = ""] = s;
112
+ const [, letter = "", alteration = "", inner, bass = ""] = s;
99
113
  const items = inner?.trim() ? `,${inner}` : "";
100
- const fifth = letter + separate(`(${accidental}5${items})${bass}`).text;
101
- if (!reads(fifth))
114
+ const altered = letter + separate(`(${alteration}${items})${bass}`).text;
115
+ if (!reads(altered))
102
116
  return error;
103
- const power = `${letter}${accidental}5`;
117
+ const [accidental, n] = [alteration.slice(0, 1), alteration.slice(1)];
104
118
  return {
105
119
  ...error,
106
- message: `${error.message}; ambiguous: ${power} is always the ${letter}${accidental} power chord (grammar 3); a ${letter} chord with a ${accidental}5 writes it in the parentheses`,
120
+ message: `${error.message}; ambiguous: ${letter}${alteration} is always the ${letter}${accidental} ${CHORD_KIND[n]} chord (grammar 3); a ${letter} chord with a ${alteration} writes it in the parentheses`,
107
121
  };
108
122
  }
109
- const m = ALTERED_FIFTH.exec(text);
123
+ const m = ALTERED.exec(text);
110
124
  if (!m)
111
125
  return error;
112
- const [, root = "", minor = "", fifth = "", inner, bass = ""] = m;
126
+ const [, root = "", quality = "", alteration = "", inner, bass = ""] = m;
113
127
  const items = inner?.trim() ? `,${inner}` : "";
114
- const suggestion = root + separate(`${minor}(${fifth}${items})${bass}`).text;
115
- if (!reads(suggestion))
128
+ const suggestion = root + separate(`${quality}(${alteration}${items})${bass}`).text;
129
+ if (!offers(suggestion))
116
130
  return error;
117
131
  return {
118
- message: `${symbol}: an altered 5th goes in the parentheses unless it follows an extension (grammar 3)`,
132
+ message: `${symbol}: an altered ${alteration.slice(1)}th goes in the parentheses unless it follows an extension (grammar 3)`,
119
133
  token: symbol,
120
134
  suggestion,
121
135
  };
@@ -13,3 +13,11 @@ export type Suffix = {
13
13
  */
14
14
  export declare function enumerateSuffixes(): Map<string, Suffix[]>;
15
15
  export declare const intervalSetKey: (intervals: Interval[]) => string;
16
+ /**
17
+ * A sixth chord whose flat sixth replaces its own sixth (`6(b6)`, `6/9(b6)`,
18
+ * `m6(b6)`): a spelling to choose only when nothing plainer names the same
19
+ * notes, so a Harte label with a flat sixth is never given a sixth-chord
20
+ * name with its sixth replaced. The rule is the flat sixth's only: other
21
+ * altered tones keep the names they always had (`C:7(b9,13)` is `C13(b9)`).
22
+ */
23
+ export declare function replacesOwnSixth({ parts }: Suffix): boolean;
@@ -47,3 +47,13 @@ export function enumerateSuffixes() {
47
47
  return found;
48
48
  }
49
49
  export const intervalSetKey = (intervals) => [...new Set(intervals.map(intervalKey))].sort().join("|");
50
+ /**
51
+ * A sixth chord whose flat sixth replaces its own sixth (`6(b6)`, `6/9(b6)`,
52
+ * `m6(b6)`): a spelling to choose only when nothing plainer names the same
53
+ * notes, so a Harte label with a flat sixth is never given a sixth-chord
54
+ * name with its sixth replaced. The rule is the flat sixth's only: other
55
+ * altered tones keep the names they always had (`C:7(b9,13)` is `C13(b9)`).
56
+ */
57
+ export function replacesOwnSixth({ parts }) {
58
+ return parts.tones.includes("b6") && (parts.extension === "6" || parts.extension === "6/9");
59
+ }
@@ -16,8 +16,25 @@ export declare const EXTENSIONS: [Extension, Interval[]][];
16
16
  export declare const VALID_EXTENSIONS: Record<Quality, (Extension | null)[]>;
17
17
  /** `sus` is allowed only on the major quality, with these extensions. */
18
18
  export declare const SUS_ALLOWED_WITH: (Extension | null)[];
19
- /** Tones a parenthesis may hold. Tone `7` means the interval b7. */
19
+ /** Tones a parenthesis may hold, in the grammar's order. Tone `7` means the interval b7. */
20
20
  export declare const TONES: string[];
21
+ /**
22
+ * Tones a parenthesis refuses that name a tone it can add (Appendix A.6):
23
+ * the refusal suggests the counterpart. Tone `7` is already the flat seventh.
24
+ */
25
+ export declare const COUNTERPARTS: Record<string, string>;
26
+ /**
27
+ * What `add` may stand before (Appendix A.5), as a pattern alternation:
28
+ * every tone, and the refused tones with a counterpart, so the refusal can
29
+ * suggest it.
30
+ */
31
+ export declare const ADD_TONE: string;
32
+ /**
33
+ * What a bare `add` may stand before: a tone added on 2026-11-14 only when
34
+ * no digit follows it, nor a slash but one before a bass, so `Cadd69` never
35
+ * reads as `C9(6)` and `Cadd6/9` is refused as written.
36
+ */
37
+ export declare const BARE_ADD_TONE: string;
21
38
  /** Tones a parenthesis may leave out (grammar 3): the 3rd or the 5th. */
22
39
  export declare const OMISSIONS: string[];
23
40
  export declare const isOmission: (tone: string) => boolean;
@@ -32,9 +49,13 @@ export declare function chordIntervals(parts: ChordParts, symbol: string): {
32
49
  alteredOpen: boolean;
33
50
  };
34
51
  /**
35
- * Appendix A.5, applied in this order after ♯/♭ become #/b. Each pattern
36
- * reads the text after the root, so a rule can never touch the root's
37
- * own accidental.
52
+ * Appendix A.5, applied in this order after ♯/♭ become #/b and the
53
+ * increment sign and the triangles become Δ. Each pattern reads the text
54
+ * after the root, so a rule can never touch the root's own accidental.
55
+ * `ma` is read only at the start, before `min` and `-` become `m`, so it
56
+ * is never an alias after `m`, `-` or `min` (`Cmma7` stays an error); the
57
+ * delta is read after, so it follows any of the three. `Maj` after them
58
+ * (`CmMaj7`) is not an alias: Kevin, 2026-11-09.
38
59
  */
39
60
  export declare const ALIASES: [RegExp, string][];
40
61
  /** Appendix A.6: a rejection with its suggestion, or null when the symbol is not one. */
@@ -39,8 +39,30 @@ export const VALID_EXTENSIONS = {
39
39
  };
40
40
  /** `sus` is allowed only on the major quality, with these extensions. */
41
41
  export const SUS_ALLOWED_WITH = [null, "7", "9", "13"];
42
- /** Tones a parenthesis may hold. Tone `7` means the interval b7. */
43
- export const TONES = ["2", "4", "6", "7", "9", "11", "13", "b5", "#5", "b9", "#9", "#11", "b13"];
42
+ /** Tones a parenthesis may hold, in the grammar's order. Tone `7` means the interval b7. */
43
+ export const TONES = "2 4 6 7 9 11 13 b5 #5 b6 b9 #9 #11 b13".split(" ");
44
+ /**
45
+ * Tones a parenthesis refuses that name a tone it can add (Appendix A.6):
46
+ * the refusal suggests the counterpart. Tone `7` is already the flat seventh.
47
+ */
48
+ export const COUNTERPARTS = { b2: "b9", "#2": "#9", "#4": "#11", b7: "7" };
49
+ /** A pattern alternation of `tones`, longest first, so `#11` and `13` are read whole. */
50
+ const alternation = (tones) => [...tones].sort((a, b) => b.length - a.length).join("|");
51
+ /** The tones `add` took before 2026-11-14: bare, they read with a digit after, as before (`Cadd27`). */
52
+ const FIRST_ADD_TONES = ["2", "4", "9", "11"];
53
+ const ADD_TONES = [...TONES, ...Object.keys(COUNTERPARTS)];
54
+ /**
55
+ * What `add` may stand before (Appendix A.5), as a pattern alternation:
56
+ * every tone, and the refused tones with a counterpart, so the refusal can
57
+ * suggest it.
58
+ */
59
+ export const ADD_TONE = alternation(ADD_TONES);
60
+ /**
61
+ * What a bare `add` may stand before: a tone added on 2026-11-14 only when
62
+ * no digit follows it, nor a slash but one before a bass, so `Cadd69` never
63
+ * reads as `C9(6)` and `Cadd6/9` is refused as written.
64
+ */
65
+ export const BARE_ADD_TONE = `(?:${alternation(ADD_TONES.filter((t) => !FIRST_ADD_TONES.includes(t)))})(?!\\d|\\/(?![A-G]))|${alternation(FIRST_ADD_TONES)}`;
44
66
  /** Tones a parenthesis may leave out (grammar 3): the 3rd or the 5th. */
45
67
  export const OMISSIONS = ["no3", "no5"];
46
68
  export const isOmission = (tone) => tone.startsWith("no");
@@ -112,21 +134,27 @@ export function chordIntervals(parts, symbol) {
112
134
  return { intervals, warnings, alteredOpen: parts.extension === "7alt" };
113
135
  }
114
136
  /**
115
- * Appendix A.5, applied in this order after ♯/♭ become #/b. Each pattern
116
- * reads the text after the root, so a rule can never touch the root's
117
- * own accidental.
137
+ * Appendix A.5, applied in this order after ♯/♭ become #/b and the
138
+ * increment sign and the triangles become Δ. Each pattern reads the text
139
+ * after the root, so a rule can never touch the root's own accidental.
140
+ * `ma` is read only at the start, before `min` and `-` become `m`, so it
141
+ * is never an alias after `m`, `-` or `min` (`Cmma7` stays an error); the
142
+ * delta is read after, so it follows any of the three. `Maj` after them
143
+ * (`CmMaj7`) is not an alias: Kevin, 2026-11-09.
118
144
  */
119
145
  export const ALIASES = [
120
- [/^Δ7?/, "maj7"],
121
146
  [/^ø7?/, "m7(b5)"],
122
147
  [/^°7/, "dim7"],
123
148
  [/^°/, "dim"],
124
149
  [/^\+7/, "aug7"],
125
150
  [/^\+/, "aug"],
126
151
  [/^(minmaj7|m\(maj7\))/, "mmaj7"],
127
- [/^(Maj7|ma7)/, "maj7"],
152
+ [/^(Maj|ma)(?=7|9|13)/, "maj"],
128
153
  [/^min/, "m"],
129
154
  [/^-/, "m"],
155
+ [/^(m?)Δ9/, "$1maj9"],
156
+ [/^(m?)Δ13/, "$1maj13"],
157
+ [/^(m?)Δ7?/, "$1maj7"],
130
158
  [/^maj(?=$|\/)/, ""],
131
159
  [/sus(?![24])/, "sus4"],
132
160
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "barmark",
3
- "version": "0.23.1",
3
+ "version": "0.25.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": {