barmark 0.8.0 → 0.10.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 +35 -1
- package/README.md +1 -1
- package/dist/chart/barLine.d.ts +3 -1
- package/dist/chart/barLine.js +11 -2
- package/dist/chart/directives.js +35 -4
- package/dist/chart/document.js +1 -1
- package/dist/chart/expand.js +14 -5
- package/dist/chart/print.js +1 -1
- package/dist/chart/types.d.ts +19 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,38 @@ Releases follow the process in [RELEASING.md](RELEASING.md).
|
|
|
9
9
|
|
|
10
10
|
## [Unreleased]
|
|
11
11
|
|
|
12
|
+
## [0.10.0] - 2026-11-03
|
|
13
|
+
|
|
14
|
+
Written bar numbers on played bars, issue #70. No chart changes meaning.
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
|
|
18
|
+
- **Written bar numbers** (issue #70): every played bar has `written`, its
|
|
19
|
+
number as written, counting each written bar once in written order (`%`
|
|
20
|
+
included, `...` not). A repeat or replay plays its bars under the numbers
|
|
21
|
+
they were written with, so a host can speak a printed score's measure
|
|
22
|
+
numbers. A bar line dropped for an error has `written` too, the bars its
|
|
23
|
+
pipes write, so the numbers after it hold (grammar A.7).
|
|
24
|
+
|
|
25
|
+
## [0.9.0] - 2026-11-02
|
|
26
|
+
|
|
27
|
+
An optional swing amount for `feel:` (`swing 58%`), issue #66. Charts
|
|
28
|
+
that read before read and print the same. Implements the
|
|
29
|
+
[grammar v0.1 draft](https://github.com/kevinpeckham/barmark/blob/main/docs/grammar-v0.1-draft.md).
|
|
30
|
+
|
|
31
|
+
### Added
|
|
32
|
+
|
|
33
|
+
- **A swing amount** (grammar 7.1, issue #66): `feel: swing 58%`,
|
|
34
|
+
`feel: shuffle 62.5%`, `feel: swing 16 55%`. The amount is where the
|
|
35
|
+
swung note lands, as a percentage of its pair, from 50% to 75%
|
|
36
|
+
inclusive, with the `%` required. It reaches `Directives.swingPercent`
|
|
37
|
+
and each played bar's `swingPercent`; both are absent for the bare word,
|
|
38
|
+
which stays the triplet feel (66.7%). `swing 66.7%` reads and prints as
|
|
39
|
+
`swing`, so every chart that read before reads and prints the same.
|
|
40
|
+
- Errors, each on its line: an amount outside 50% to 75%, more than one
|
|
41
|
+
decimal place, a missing `%` (`swing 58` suggests `swing 58%`), an amount
|
|
42
|
+
on `straight` (suggests `swing` with it), and an amount with no kind.
|
|
43
|
+
|
|
12
44
|
## [0.8.0] - 2026-11-02
|
|
13
45
|
|
|
14
46
|
`(add9)` and friends inside parentheses, clearer messages for an empty
|
|
@@ -202,7 +234,9 @@ The first working release: the reference parser and printer for the
|
|
|
202
234
|
|
|
203
235
|
- **A placeholder package that holds the `barmark` name** while the spec and parser are written.
|
|
204
236
|
|
|
205
|
-
[Unreleased]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.
|
|
237
|
+
[Unreleased]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.10.0...HEAD
|
|
238
|
+
[0.10.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.9.0...barmark-v0.10.0
|
|
239
|
+
[0.9.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.8.0...barmark-v0.9.0
|
|
206
240
|
[0.8.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.7.0...barmark-v0.8.0
|
|
207
241
|
[0.7.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.6.0...barmark-v0.7.0
|
|
208
242
|
[0.6.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.5.0...barmark-v0.6.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: its number as written, 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
|
|
package/dist/chart/barLine.d.ts
CHANGED
|
@@ -17,10 +17,12 @@ export declare function repeatTail(text: string, boundary: boolean): {
|
|
|
17
17
|
export declare function misplacedRepeat(token: string): string | null;
|
|
18
18
|
/**
|
|
19
19
|
* One bar line: cells between pipes, each cell's slots, the `|:` and `:|`
|
|
20
|
-
* marks and an `x N` tail. Any error drops the whole line (`bars` is null)
|
|
20
|
+
* marks and an `x N` tail. Any error drops the whole line (`bars` is null);
|
|
21
|
+
* `written` still says how many bars it writes.
|
|
21
22
|
*/
|
|
22
23
|
export declare function parseBarLine(text: string, line: number): {
|
|
23
24
|
bars: BarsLine | null;
|
|
25
|
+
written: number;
|
|
24
26
|
diagnostics: ChartDiagnostic[];
|
|
25
27
|
};
|
|
26
28
|
export {};
|
package/dist/chart/barLine.js
CHANGED
|
@@ -98,9 +98,16 @@ function tokens(text) {
|
|
|
98
98
|
out.push(current);
|
|
99
99
|
return out;
|
|
100
100
|
}
|
|
101
|
+
/** The bars a bar line writes, read from its pipes alone (fermatas not counted), so a line dropped for an error still counts. */
|
|
102
|
+
const barsWritten = (body) => body
|
|
103
|
+
.split("|")
|
|
104
|
+
.slice(1)
|
|
105
|
+
.map((p) => p.trim())
|
|
106
|
+
.filter((p) => p !== "" && !FERMATA.has(p)).length;
|
|
101
107
|
/**
|
|
102
108
|
* One bar line: cells between pipes, each cell's slots, the `|:` and `:|`
|
|
103
|
-
* marks and an `x N` tail. Any error drops the whole line (`bars` is null)
|
|
109
|
+
* marks and an `x N` tail. Any error drops the whole line (`bars` is null);
|
|
110
|
+
* `written` still says how many bars it writes.
|
|
104
111
|
*/
|
|
105
112
|
export function parseBarLine(text, line) {
|
|
106
113
|
const diagnostics = [];
|
|
@@ -136,13 +143,14 @@ export function parseBarLine(text, line) {
|
|
|
136
143
|
const closes = body.endsWith(":|");
|
|
137
144
|
if (closes)
|
|
138
145
|
body = `${body.slice(0, -2)}|`;
|
|
146
|
+
const written = barsWritten(body);
|
|
139
147
|
if (/\|\d/.test(body))
|
|
140
148
|
error("endings are not supported in v0.1", /\|\d+/.exec(body)?.[0] ?? "|");
|
|
141
149
|
if (body.includes(":|") || body.includes("|:"))
|
|
142
150
|
error("|: must open a bar line and :| must close one", body.includes(":|") ? ":|" : "|:");
|
|
143
151
|
// A misplaced mark makes the cells unreadable: report it once, not again as chords.
|
|
144
152
|
if (diagnostics.some((d) => d.severity === "error"))
|
|
145
|
-
return { bars: null, diagnostics };
|
|
153
|
+
return { bars: null, written, diagnostics };
|
|
146
154
|
const parts = body.split("|").slice(1);
|
|
147
155
|
if (parts.at(-1)?.trim() === "")
|
|
148
156
|
parts.pop();
|
|
@@ -237,6 +245,7 @@ export function parseBarLine(text, line) {
|
|
|
237
245
|
const failed = diagnostics.some((d) => d.severity === "error");
|
|
238
246
|
return {
|
|
239
247
|
bars: failed ? null : { kind: "bars", line, opens, closes, cells, repeat },
|
|
248
|
+
written,
|
|
240
249
|
diagnostics,
|
|
241
250
|
};
|
|
242
251
|
}
|
package/dist/chart/directives.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
147
|
+
if ("error" in feel)
|
|
148
|
+
error(feel.error, value);
|
|
118
149
|
else
|
|
119
|
-
|
|
150
|
+
Object.assign(set, feel);
|
|
120
151
|
}
|
|
121
152
|
}
|
|
122
153
|
return { set, diagnostics };
|
package/dist/chart/document.js
CHANGED
|
@@ -108,7 +108,7 @@ export function readDocument(text) {
|
|
|
108
108
|
if (t.startsWith("|")) {
|
|
109
109
|
const r = parseBarLine(t, line);
|
|
110
110
|
diagnostics.push(...r.diagnostics);
|
|
111
|
-
lines.push(r.bars ?? { kind: "invalid", line, text: t });
|
|
111
|
+
lines.push(r.bars ?? { kind: "invalid", line, text: t, written: r.written });
|
|
112
112
|
return;
|
|
113
113
|
}
|
|
114
114
|
if (t.startsWith("# ")) {
|
package/dist/chart/expand.js
CHANGED
|
@@ -51,7 +51,10 @@ export function expand(lines) {
|
|
|
51
51
|
// % copies the bar written before it, one-bar meter included, so a section plays the same wherever it is replayed.
|
|
52
52
|
const resolved = new Map();
|
|
53
53
|
let previous = null;
|
|
54
|
+
let written = 0;
|
|
54
55
|
for (const l of sections.flatMap((s) => s.lines)) {
|
|
56
|
+
if (l.kind === "invalid")
|
|
57
|
+
written += l.written;
|
|
55
58
|
if (l.kind !== "bars")
|
|
56
59
|
continue;
|
|
57
60
|
const cells = [];
|
|
@@ -65,7 +68,8 @@ export function expand(lines) {
|
|
|
65
68
|
kind: "bar",
|
|
66
69
|
meter: previous?.meter ?? null,
|
|
67
70
|
slots: previous?.slots ?? [{ kind: "hold" }],
|
|
68
|
-
|
|
71
|
+
own: false,
|
|
72
|
+
written: ++written,
|
|
69
73
|
});
|
|
70
74
|
}
|
|
71
75
|
else {
|
|
@@ -73,7 +77,7 @@ export function expand(lines) {
|
|
|
73
77
|
const head = first?.kind === "group" ? first.members[0] : first;
|
|
74
78
|
if (!previous && head?.kind === "hold")
|
|
75
79
|
error(l.line, "/ has nothing before it to hold", "/");
|
|
76
|
-
cells.push({ kind: "bar", meter: c.meter, slots: c.slots,
|
|
80
|
+
cells.push({ kind: "bar", meter: c.meter, slots: c.slots, own: true, written: ++written });
|
|
77
81
|
previous = { meter: c.meter, slots: c.slots };
|
|
78
82
|
}
|
|
79
83
|
}
|
|
@@ -126,6 +130,7 @@ export function expand(lines) {
|
|
|
126
130
|
tempo: null,
|
|
127
131
|
change: null,
|
|
128
132
|
feel: "straight",
|
|
133
|
+
swingPercent: undefined,
|
|
129
134
|
};
|
|
130
135
|
const warned = new Set();
|
|
131
136
|
const warn = (line, message, token) => {
|
|
@@ -159,8 +164,10 @@ export function expand(lines) {
|
|
|
159
164
|
}
|
|
160
165
|
if (set.tempoChange)
|
|
161
166
|
changeTempo(set.tempoChange, line);
|
|
162
|
-
if (set.feel)
|
|
167
|
+
if (set.feel) {
|
|
163
168
|
state.feel = set.feel;
|
|
169
|
+
state.swingPercent = set.swingPercent;
|
|
170
|
+
}
|
|
164
171
|
};
|
|
165
172
|
let count = 0;
|
|
166
173
|
let work = 0;
|
|
@@ -186,7 +193,7 @@ export function expand(lines) {
|
|
|
186
193
|
return stop(line);
|
|
187
194
|
count++;
|
|
188
195
|
const meter = p.meter ?? state.time;
|
|
189
|
-
if (p.
|
|
196
|
+
if (p.own && !checked.has(p)) {
|
|
190
197
|
checked.add(p);
|
|
191
198
|
const k = p.slots.length;
|
|
192
199
|
const b = beatsOf(meter);
|
|
@@ -198,11 +205,12 @@ export function expand(lines) {
|
|
|
198
205
|
token: `${k}`,
|
|
199
206
|
});
|
|
200
207
|
}
|
|
201
|
-
const { key, tempo, change: tempoChange, feel } = state;
|
|
208
|
+
const { key, tempo, change: tempoChange, feel, swingPercent } = state;
|
|
202
209
|
out.push({
|
|
203
210
|
kind: "bar",
|
|
204
211
|
bar: {
|
|
205
212
|
index: 0,
|
|
213
|
+
written: p.written,
|
|
206
214
|
line,
|
|
207
215
|
section: sectionName,
|
|
208
216
|
meter,
|
|
@@ -210,6 +218,7 @@ export function expand(lines) {
|
|
|
210
218
|
tempo,
|
|
211
219
|
tempoChange,
|
|
212
220
|
feel,
|
|
221
|
+
...(swingPercent === undefined ? {} : { swingPercent }),
|
|
213
222
|
slots: p.slots,
|
|
214
223
|
},
|
|
215
224
|
});
|
package/dist/chart/print.js
CHANGED
|
@@ -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
|
/**
|
package/dist/chart/types.d.ts
CHANGED
|
@@ -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 = {
|
|
@@ -87,15 +93,25 @@ export type Line = {
|
|
|
87
93
|
line: number;
|
|
88
94
|
text: string;
|
|
89
95
|
}
|
|
90
|
-
/**
|
|
96
|
+
/**
|
|
97
|
+
* A bar line dropped for an error, kept as written so its section still
|
|
98
|
+
* counts as written out; `written` is how many bars its pipes write.
|
|
99
|
+
*/
|
|
91
100
|
| {
|
|
92
101
|
kind: "invalid";
|
|
93
102
|
line: number;
|
|
94
103
|
text: string;
|
|
104
|
+
written: number;
|
|
95
105
|
};
|
|
96
106
|
export type PlayedBar = {
|
|
97
107
|
/** 1-based measure number in play order; fermatas are not counted. */
|
|
98
108
|
index: number;
|
|
109
|
+
/**
|
|
110
|
+
* 1-based number of the bar as written, counting each written bar once
|
|
111
|
+
* (`%` included, fermatas not) in written order: a repeat or replay plays
|
|
112
|
+
* its bars under the numbers they were written with.
|
|
113
|
+
*/
|
|
114
|
+
written: number;
|
|
99
115
|
line: number;
|
|
100
116
|
/** Heading text of the section occurrence, as written. */
|
|
101
117
|
section: string | null;
|
|
@@ -110,6 +126,8 @@ export type PlayedBar = {
|
|
|
110
126
|
to: number | null;
|
|
111
127
|
} | null;
|
|
112
128
|
feel: Feel;
|
|
129
|
+
/** The swing amount in force (Directives.swingPercent); absent when the feel has none. */
|
|
130
|
+
swingPercent?: number;
|
|
113
131
|
/** `%` resolved to the copied slots; holds stay holds. */
|
|
114
132
|
slots: Slot[];
|
|
115
133
|
};
|