barmark 0.0.3 → 0.1.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 +52 -0
- package/LICENSE +21 -0
- package/README.md +74 -9
- package/dist/chart/barLine.d.ts +26 -0
- package/dist/chart/barLine.js +242 -0
- package/dist/chart/directives.d.ts +14 -0
- package/dist/chart/directives.js +108 -0
- package/dist/chart/document.d.ts +7 -0
- package/dist/chart/document.js +116 -0
- package/dist/chart/expand.d.ts +14 -0
- package/dist/chart/expand.js +271 -0
- package/dist/chart/index.d.ts +7 -0
- package/dist/chart/index.js +6 -0
- package/dist/chart/parse.d.ts +3 -0
- package/dist/chart/parse.js +17 -0
- package/dist/chart/print.d.ts +25 -0
- package/dist/chart/print.js +144 -0
- package/dist/chart/types.d.ts +130 -0
- package/dist/chart/types.js +1 -0
- package/dist/chords/harte.d.ts +16 -0
- package/dist/chords/harte.js +122 -0
- package/dist/chords/index.d.ts +6 -0
- package/dist/chords/index.js +4 -0
- package/dist/chords/intervals.d.ts +11 -0
- package/dist/chords/intervals.js +60 -0
- package/dist/chords/noteSet.d.ts +3 -0
- package/dist/chords/noteSet.js +73 -0
- package/dist/chords/parse.d.ts +6 -0
- package/dist/chords/parse.js +116 -0
- package/dist/chords/print.d.ts +5 -0
- package/dist/chords/print.js +10 -0
- package/dist/chords/suffixes.d.ts +13 -0
- package/dist/chords/suffixes.js +49 -0
- package/dist/chords/types.d.ts +30 -0
- package/dist/chords/types.js +1 -0
- package/dist/chords/vocabulary.d.ts +41 -0
- package/dist/chords/vocabulary.js +207 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/package.json +36 -6
- package/index.js +0 -11
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Grammar Appendix A as data: the one source the parser, printer and
|
|
3
|
+
* Harte converter read.
|
|
4
|
+
*/
|
|
5
|
+
import { intervalKey, parseInterval } from "./intervals.js";
|
|
6
|
+
const ivs = (...s) => s.map((x) => {
|
|
7
|
+
const i = parseInterval(x);
|
|
8
|
+
if (!i)
|
|
9
|
+
throw new Error(`bad interval ${x}`);
|
|
10
|
+
return i;
|
|
11
|
+
});
|
|
12
|
+
export const QUALITIES = {
|
|
13
|
+
"": ivs("1", "3", "5"),
|
|
14
|
+
m: ivs("1", "b3", "5"),
|
|
15
|
+
dim: ivs("1", "b3", "b5"),
|
|
16
|
+
aug: ivs("1", "3", "#5"),
|
|
17
|
+
"5": ivs("1", "5"),
|
|
18
|
+
};
|
|
19
|
+
/** Longest first, so the tokenizer can take the first prefix that matches. */
|
|
20
|
+
export const EXTENSIONS = [
|
|
21
|
+
["7alt", ivs("b7")],
|
|
22
|
+
["maj13", ivs("7", "9", "13")],
|
|
23
|
+
["maj9", ivs("7", "9")],
|
|
24
|
+
["maj7", ivs("7")],
|
|
25
|
+
["6/9", ivs("6", "9")],
|
|
26
|
+
["13", ivs("b7", "9", "13")],
|
|
27
|
+
["11", ivs("b7", "9", "11")],
|
|
28
|
+
["9", ivs("b7", "9")],
|
|
29
|
+
["7", ivs("b7")],
|
|
30
|
+
["6", ivs("6")],
|
|
31
|
+
];
|
|
32
|
+
/** Appendix A.3. */
|
|
33
|
+
export const VALID_EXTENSIONS = {
|
|
34
|
+
"": [null, "6", "6/9", "7", "maj7", "9", "maj9", "11", "13", "maj13", "7alt"],
|
|
35
|
+
m: [null, "6", "6/9", "7", "maj7", "9", "maj9", "11", "13"],
|
|
36
|
+
dim: [null, "7"],
|
|
37
|
+
aug: [null, "7", "maj7"],
|
|
38
|
+
"5": [null],
|
|
39
|
+
};
|
|
40
|
+
/** `sus` is allowed only on the major quality, with these extensions. */
|
|
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"];
|
|
44
|
+
export const toneInterval = (tone) => {
|
|
45
|
+
const i = parseInterval(tone === "7" ? "b7" : tone);
|
|
46
|
+
if (!i)
|
|
47
|
+
throw new Error(`bad tone ${tone}`);
|
|
48
|
+
return i;
|
|
49
|
+
};
|
|
50
|
+
const same = (a, b) => a.degree === b.degree && a.alter === b.alter;
|
|
51
|
+
/** Degree order, then flat before natural before sharp. */
|
|
52
|
+
export const byDegree = (a, b) => a.degree - b.degree || a.alter - b.alter;
|
|
53
|
+
export function validateParts(parts, symbol) {
|
|
54
|
+
if (!VALID_EXTENSIONS[parts.quality].includes(parts.extension)) {
|
|
55
|
+
return {
|
|
56
|
+
message: `"${parts.quality || "major"}" with "${parts.extension}" is not a valid combination (Appendix A.3)`,
|
|
57
|
+
token: symbol,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
if (parts.sus && (parts.quality !== "" || !SUS_ALLOWED_WITH.includes(parts.extension))) {
|
|
61
|
+
return { message: `"${parts.sus}" is not allowed on this chord (Appendix A.3)`, token: symbol };
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
/** The chord's intervals after every rule in Appendix A.2, without the slash bass. */
|
|
66
|
+
export function chordIntervals(parts, symbol) {
|
|
67
|
+
const warnings = [];
|
|
68
|
+
let s = [...QUALITIES[parts.quality]];
|
|
69
|
+
const add = (i) => {
|
|
70
|
+
if (!s.some((x) => same(x, i)))
|
|
71
|
+
s.push(i);
|
|
72
|
+
};
|
|
73
|
+
const remove = (i) => {
|
|
74
|
+
s = s.filter((x) => !same(x, i));
|
|
75
|
+
};
|
|
76
|
+
const ext = EXTENSIONS.find(([name]) => name === parts.extension)?.[1] ?? [];
|
|
77
|
+
if (parts.extension === "7" && parts.quality === "dim")
|
|
78
|
+
add({ degree: 7, alter: -2 });
|
|
79
|
+
else
|
|
80
|
+
for (const i of ext)
|
|
81
|
+
add(i);
|
|
82
|
+
if (parts.extension === "7alt")
|
|
83
|
+
remove({ degree: 5, alter: 0 });
|
|
84
|
+
// The eleventh rule: a natural 11 and a major third never sound together.
|
|
85
|
+
if (parts.extension === "11" && parts.quality === "")
|
|
86
|
+
remove({ degree: 3, alter: 0 });
|
|
87
|
+
if (parts.extension === "13" && parts.quality === "m")
|
|
88
|
+
add({ degree: 11, alter: 0 });
|
|
89
|
+
if (parts.sus) {
|
|
90
|
+
remove({ degree: 3, alter: 0 });
|
|
91
|
+
remove({ degree: 3, alter: -1 });
|
|
92
|
+
add({ degree: parts.sus === "sus2" ? 2 : 4, alter: 0 });
|
|
93
|
+
}
|
|
94
|
+
// Applied in the order the printer writes them, so a symbol and its canonical
|
|
95
|
+
// form always name the same chord.
|
|
96
|
+
const tones = [...parts.tones].sort((a, b) => byDegree(toneInterval(a), toneInterval(b)));
|
|
97
|
+
for (const tone of tones) {
|
|
98
|
+
const i = toneInterval(tone);
|
|
99
|
+
if (tone !== "7" && i.alter !== 0)
|
|
100
|
+
remove({ degree: i.degree, alter: 0 });
|
|
101
|
+
if (s.some((x) => intervalKey(x) === intervalKey(i))) {
|
|
102
|
+
warnings.push({ message: `${symbol} already contains ${tone}`, token: tone });
|
|
103
|
+
}
|
|
104
|
+
else
|
|
105
|
+
s.push(i);
|
|
106
|
+
}
|
|
107
|
+
return { intervals: s.sort(byDegree), warnings, alteredOpen: parts.extension === "7alt" };
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Appendix A.5, applied in this order after ♯/♭ become #/b. Each pattern
|
|
111
|
+
* reads the text after the root, so a rule can never touch the root's
|
|
112
|
+
* own accidental.
|
|
113
|
+
*/
|
|
114
|
+
export const ALIASES = [
|
|
115
|
+
[/^Δ7?/, "maj7"],
|
|
116
|
+
[/^ø7?/, "m7(b5)"],
|
|
117
|
+
[/^°7/, "dim7"],
|
|
118
|
+
[/^°/, "dim"],
|
|
119
|
+
[/^\+7/, "aug7"],
|
|
120
|
+
[/^\+/, "aug"],
|
|
121
|
+
[/^(minmaj7|m\(maj7\))/, "mmaj7"],
|
|
122
|
+
[/^(Maj7|ma7)/, "maj7"],
|
|
123
|
+
[/^min/, "m"],
|
|
124
|
+
[/^-/, "m"],
|
|
125
|
+
[/^maj(?=$|\/)/, ""],
|
|
126
|
+
[/sus(?![24])/, "sus4"],
|
|
127
|
+
];
|
|
128
|
+
const NATURALS = {
|
|
129
|
+
0: "C",
|
|
130
|
+
2: "D",
|
|
131
|
+
4: "E",
|
|
132
|
+
5: "F",
|
|
133
|
+
7: "G",
|
|
134
|
+
9: "A",
|
|
135
|
+
11: "B",
|
|
136
|
+
};
|
|
137
|
+
const SHARPS = { 1: "C#", 3: "D#", 6: "F#", 8: "G#", 10: "A#" };
|
|
138
|
+
const FLATS = { 1: "Db", 3: "Eb", 6: "Gb", 8: "Ab", 10: "Bb" };
|
|
139
|
+
/** The single-accidental spelling of a double-sharp or double-flat root. */
|
|
140
|
+
function enharmonicRoot(semitone, sharp) {
|
|
141
|
+
return NATURALS[semitone] ?? (sharp ? SHARPS : FLATS)[semitone] ?? "";
|
|
142
|
+
}
|
|
143
|
+
/** Appendix A.6: a rejection with its suggestion, or null when the symbol is not one. */
|
|
144
|
+
export function rejection(symbol, semitoneOf) {
|
|
145
|
+
const reject = (message, suggestion) => ({
|
|
146
|
+
message: `${symbol}: ${message}`,
|
|
147
|
+
token: symbol,
|
|
148
|
+
suggestion,
|
|
149
|
+
});
|
|
150
|
+
if (/^[a-g]/.test(symbol)) {
|
|
151
|
+
return reject("a root is an uppercase letter", symbol[0]?.toUpperCase() + symbol.slice(1));
|
|
152
|
+
}
|
|
153
|
+
if (symbol.startsWith("H"))
|
|
154
|
+
return reject('German "H" is ambiguous; write B', `B${symbol.slice(1)}`);
|
|
155
|
+
const double = /^([A-G])(bb|##)(.*)$/.exec(symbol);
|
|
156
|
+
if (double) {
|
|
157
|
+
const [, letter = "", acc = "", rest = ""] = double;
|
|
158
|
+
const root = enharmonicRoot(semitoneOf(letter + acc), acc === "##");
|
|
159
|
+
return reject("a root takes at most one accidental", root + rest);
|
|
160
|
+
}
|
|
161
|
+
const big = /^([A-G][#b]?)M(?!aj)(.*)$/.exec(symbol);
|
|
162
|
+
if (big) {
|
|
163
|
+
const [, root = "", rest = ""] = big;
|
|
164
|
+
const fixed = /^aj/i.test(rest)
|
|
165
|
+
? `maj${rest.slice(2)}`
|
|
166
|
+
: /^\d/.test(rest)
|
|
167
|
+
? `maj${rest}`
|
|
168
|
+
: rest === "" || rest.startsWith("/")
|
|
169
|
+
? rest
|
|
170
|
+
: `m${rest}`;
|
|
171
|
+
return reject('"M" is one shifted letter from "m"; write maj', root + fixed);
|
|
172
|
+
}
|
|
173
|
+
const bare = /^([A-G][#b]?)([24])(?=$|\/)/.exec(symbol);
|
|
174
|
+
if (bare) {
|
|
175
|
+
const [, root = "", n = ""] = bare;
|
|
176
|
+
const [sus, add] = n === "2" ? ["sus2", "9"] : ["sus4", "11"];
|
|
177
|
+
return reject(`"${n}" means different chords in different traditions`, `${root}${sus} or ${root}(${add})`);
|
|
178
|
+
}
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
/** Harte (2005) shorthands with Harte's own definitions, in tie-break order. */
|
|
182
|
+
export const HARTE_SHORTHANDS = [
|
|
183
|
+
["maj", ivs("1", "3", "5")],
|
|
184
|
+
["min", ivs("1", "b3", "5")],
|
|
185
|
+
["dim", ivs("1", "b3", "b5")],
|
|
186
|
+
["aug", ivs("1", "3", "#5")],
|
|
187
|
+
["maj7", ivs("1", "3", "5", "7")],
|
|
188
|
+
["min7", ivs("1", "b3", "5", "b7")],
|
|
189
|
+
["7", ivs("1", "3", "5", "b7")],
|
|
190
|
+
["dim7", ivs("1", "b3", "b5", "bb7")],
|
|
191
|
+
["hdim7", ivs("1", "b3", "b5", "b7")],
|
|
192
|
+
["minmaj7", ivs("1", "b3", "5", "7")],
|
|
193
|
+
["maj6", ivs("1", "3", "5", "6")],
|
|
194
|
+
["min6", ivs("1", "b3", "5", "6")],
|
|
195
|
+
["9", ivs("1", "3", "5", "b7", "9")],
|
|
196
|
+
["maj9", ivs("1", "3", "5", "7", "9")],
|
|
197
|
+
["min9", ivs("1", "b3", "5", "b7", "9")],
|
|
198
|
+
["sus4", ivs("1", "4", "5")],
|
|
199
|
+
["sus2", ivs("1", "2", "5")],
|
|
200
|
+
["11", ivs("1", "3", "5", "b7", "9", "11")],
|
|
201
|
+
["min11", ivs("1", "b3", "5", "b7", "9", "11")],
|
|
202
|
+
["13", ivs("1", "3", "5", "b7", "9", "11", "13")],
|
|
203
|
+
["min13", ivs("1", "b3", "5", "b7", "9", "11", "13")],
|
|
204
|
+
["maj13", ivs("1", "3", "5", "7", "9", "11", "13")],
|
|
205
|
+
["5", ivs("1", "5")],
|
|
206
|
+
["1", ivs("1")],
|
|
207
|
+
];
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/package.json
CHANGED
|
@@ -1,19 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "barmark",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "Markdown-inspired plain-text notation for chord charts
|
|
3
|
+
"version": "0.1.0",
|
|
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": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"import": "./dist/index.js"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"sideEffects": false,
|
|
7
14
|
"files": [
|
|
8
|
-
"
|
|
9
|
-
"
|
|
15
|
+
"dist",
|
|
16
|
+
"CHANGELOG.md"
|
|
10
17
|
],
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=20"
|
|
20
|
+
},
|
|
11
21
|
"keywords": [
|
|
12
22
|
"chord-chart",
|
|
23
|
+
"chords",
|
|
13
24
|
"music",
|
|
14
25
|
"notation",
|
|
15
26
|
"markdown",
|
|
16
|
-
"
|
|
27
|
+
"harte",
|
|
28
|
+
"lead-sheet",
|
|
17
29
|
"parser",
|
|
18
30
|
"barmark"
|
|
19
31
|
],
|
|
@@ -23,5 +35,23 @@
|
|
|
23
35
|
"repository": {
|
|
24
36
|
"type": "git",
|
|
25
37
|
"url": "git+https://github.com/kevinpeckham/barmark.git"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@biomejs/biome": "^2.6.4",
|
|
41
|
+
"@types/bun": "^1.4.4",
|
|
42
|
+
"@varlock/1password-plugin": "^2.0.5",
|
|
43
|
+
"typescript": "^7.0.2",
|
|
44
|
+
"varlock": "^1.23.0"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"test": "bun test",
|
|
48
|
+
"check": "biome check . && tsc",
|
|
49
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
50
|
+
"verify:package": "bun scripts/verify-package.ts",
|
|
51
|
+
"verify:release": "bun scripts/verify-release.ts",
|
|
52
|
+
"prepack": "bun run build"
|
|
53
|
+
},
|
|
54
|
+
"bugs": {
|
|
55
|
+
"url": "https://github.com/kevinpeckham/barmark/issues"
|
|
26
56
|
}
|
|
27
57
|
}
|
package/index.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* barmark — markdown-inspired plain-text notation for chord charts.
|
|
3
|
-
* This is a name-holding stub while the spec and reference parser are
|
|
4
|
-
* extracted from production code (see the repository's BRIEF.md).
|
|
5
|
-
*/
|
|
6
|
-
export const VERSION = "0.0.3";
|
|
7
|
-
export function parse() {
|
|
8
|
-
throw new Error(
|
|
9
|
-
"The barmark reference parser is not published yet. Follow https://github.com/kevinpeckham/barmark",
|
|
10
|
-
);
|
|
11
|
-
}
|