barmark 0.14.1 → 0.16.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 +65 -1
- package/README.md +24 -0
- package/dist/chart/barLine.js +57 -14
- package/dist/chart/credits.d.ts +9 -0
- package/dist/chart/credits.js +62 -0
- package/dist/chart/directives.d.ts +2 -0
- package/dist/chart/directives.js +2 -0
- package/dist/chart/document.d.ts +4 -3
- package/dist/chart/document.js +72 -48
- package/dist/chart/expand.d.ts +3 -1
- package/dist/chart/expand.js +11 -2
- package/dist/chart/index.d.ts +6 -0
- package/dist/chart/index.js +6 -0
- package/dist/chart/instruments.d.ts +27 -0
- package/dist/chart/instruments.js +48 -0
- package/dist/chart/lines.d.ts +14 -0
- package/dist/chart/lines.js +98 -0
- package/dist/chart/parse.d.ts +6 -3
- package/dist/chart/parse.js +99 -12
- package/dist/chart/partLine.d.ts +3 -0
- package/dist/chart/partLine.js +73 -0
- package/dist/chart/parts.d.ts +8 -3
- package/dist/chart/parts.js +50 -14
- package/dist/chart/pedal.d.ts +5 -0
- package/dist/chart/pedal.js +44 -0
- package/dist/chart/print.js +23 -8
- package/dist/chart/repeats.js +1 -1
- package/dist/chart/shares.d.ts +6 -0
- package/dist/chart/shares.js +10 -0
- package/dist/chart/systems.d.ts +2 -0
- package/dist/chart/systems.js +18 -3
- package/dist/chart/types.d.ts +50 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,68 @@ Releases follow the process in [RELEASING.md](RELEASING.md).
|
|
|
9
9
|
|
|
10
10
|
## [Unreleased]
|
|
11
11
|
|
|
12
|
+
## [0.16.0] - 2026-11-04
|
|
13
|
+
|
|
14
|
+
A grammar change: part lines (7.6), sustain pedal marks (2.9), dotted
|
|
15
|
+
figures (2.2), and `instrument:` and `clef:` on the `part:` line (7.3).
|
|
16
|
+
Charts that read before read the same. Implements the
|
|
17
|
+
[grammar v0.1 draft](https://github.com/kevinpeckham/barmark/blob/main/docs/grammar-v0.1-draft.md).
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
|
|
21
|
+
- **Part lines** (grammar 7.6): up to four lines per part, labelled
|
|
22
|
+
`Pno.RH |` and `Pno.LH |`, in systems as parts are. The first line in a
|
|
23
|
+
system carries the harmony and the others notes only; a fifth line, or
|
|
24
|
+
a chord on another line, is an error. Bar lines gain `lineName`,
|
|
25
|
+
declared parts gain `lines`, and the canonical form sorts a system's
|
|
26
|
+
lines into score order: the order of the part's first system writing
|
|
27
|
+
two or more of its lines, so an intro for the left hand alone keeps the
|
|
28
|
+
right hand first. `streamKey` and `MAX_LINES` are exported.
|
|
29
|
+
Each line plays on its own: a played bar's part entry gains `lines`
|
|
30
|
+
(`LineBar`: name, line, slots, words), one per line playing there, and
|
|
31
|
+
the part's `slots` are its first playing line's. A bare line and a tutti
|
|
32
|
+
line play as the part's first line; a line not written rests. A
|
|
33
|
+
single-part chart's bars, and an extracted part's, carry `lines`
|
|
34
|
+
themselves, and `printPart` keeps the `Pno.RH |` labels.
|
|
35
|
+
`extractPart(text, label, lineName)` gives one line alone, as a
|
|
36
|
+
converter writes it: resting (tacet) where the line isn't written.
|
|
37
|
+
- **Sustain pedal marks** (grammar 2.9): `+G` presses or changes the
|
|
38
|
+
pedal, `*G` lifts it; `--`, a tacet bar and the chart's end lift it too.
|
|
39
|
+
A chord slot gains `pedal`, and `pedalStates` gives whether the pedal is
|
|
40
|
+
down at the end of each slot, in play order. A `*` with the pedal
|
|
41
|
+
already up is a warning.
|
|
42
|
+
- **Dotted figures** (grammar 2.2): a dot after one member of a
|
|
43
|
+
two-member group, `C._D` (a dotted eighth and a sixteenth in a beat)
|
|
44
|
+
or `C_D.`. Group members gain `dotted`, and `memberShares` gives each
|
|
45
|
+
member's share of its slot. `N.C._G` keeps its meaning, and a misplaced
|
|
46
|
+
`...`, `D.S.` or `D.C.` keeps its own message.
|
|
47
|
+
- **`instrument:` and `clef:` on the `part:` line** (grammar 7.3):
|
|
48
|
+
`part: Tpt = Trumpet, instrument: trumpet in Bb`, `part: Ld = Lead,
|
|
49
|
+
clef: bass`. The instrument comes from a list of 16 (`INSTRUMENTS`,
|
|
50
|
+
`instrumentInfo`), each with its clef, written transposition, staves
|
|
51
|
+
and General MIDI program, for converters. `Part` gains `instrument` and
|
|
52
|
+
`clef`, present when written. An unknown instrument is an error naming
|
|
53
|
+
the near ones; `clef:` on a keyboard is an error.
|
|
54
|
+
|
|
55
|
+
## [0.15.0] - 2026-11-04
|
|
56
|
+
|
|
57
|
+
A grammar change: credit lines (7.5). Charts that read before read the
|
|
58
|
+
same, unless a text line starts with a credit's name and a colon.
|
|
59
|
+
Implements the
|
|
60
|
+
[grammar v0.1 draft](https://github.com/kevinpeckham/barmark/blob/main/docs/grammar-v0.1-draft.md).
|
|
61
|
+
|
|
62
|
+
### Added
|
|
63
|
+
|
|
64
|
+
- **Credit lines** (grammar 7.5): `composer:`, `lyricist:`, `arranger:`
|
|
65
|
+
and `copyright:`, each a line of its own, allowed anywhere in a chart
|
|
66
|
+
and repeatable. `ChartParse.credits` lists each role's entries in
|
|
67
|
+
written order; a `Line` of kind `"credit"` keeps the line, and the
|
|
68
|
+
printer writes it where it was written. An empty credit is an error;
|
|
69
|
+
`author:`, `music:`, `words:`, `arr:`, `rights:` and the other near
|
|
70
|
+
misses warn with the right name. `CREDIT_ROLES` is exported.
|
|
71
|
+
- A text line starting with one of the four names and a colon is now a
|
|
72
|
+
credit, not text.
|
|
73
|
+
|
|
12
74
|
## [0.14.1] - 2026-11-03
|
|
13
75
|
|
|
14
76
|
### Fixed
|
|
@@ -364,7 +426,9 @@ The first working release: the reference parser and printer for the
|
|
|
364
426
|
|
|
365
427
|
- **A placeholder package that holds the `barmark` name** while the spec and parser are written.
|
|
366
428
|
|
|
367
|
-
[Unreleased]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.
|
|
429
|
+
[Unreleased]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.16.0...HEAD
|
|
430
|
+
[0.16.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.15.0...barmark-v0.16.0
|
|
431
|
+
[0.15.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.14.1...barmark-v0.15.0
|
|
368
432
|
[0.14.1]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.14.0...barmark-v0.14.1
|
|
369
433
|
[0.14.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.13.0...barmark-v0.14.0
|
|
370
434
|
[0.13.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.12.0...barmark-v0.13.0
|
package/README.md
CHANGED
|
@@ -51,6 +51,7 @@ import {
|
|
|
51
51
|
const chart = parseChart(text);
|
|
52
52
|
chart.title; // "Example Song"
|
|
53
53
|
chart.parts; // [{ label: "Gtr", name: "Electric Guitar 1" }] from part: Gtr = Electric Guitar 1, in score order
|
|
54
|
+
chart.credits; // { composer: ["Kevin Peckham"], lyricist: [], arranger: [], copyright: [] } from composer: Kevin Peckham
|
|
54
55
|
chart.bars; // every bar in play order: its number as written, slots, section, key, meter, tempo, feel (and swingPercent)
|
|
55
56
|
chart.sections; // each section as played, with its first and last bar
|
|
56
57
|
chart.diagnostics; // errors and warnings, each with a line number
|
|
@@ -95,6 +96,29 @@ printPart(text, "Pno"); // the same as text: tacet bars written N.C.
|
|
|
95
96
|
projectPart(chart.lines, chart.parts, "Pno"); // one part's lines
|
|
96
97
|
```
|
|
97
98
|
|
|
99
|
+
A part can also write up to four **lines** that play together, a
|
|
100
|
+
pianist's two hands (grammar 7.6), and name its instrument and clef
|
|
101
|
+
(7.3):
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
part: Pno = Piano, instrument: piano
|
|
105
|
+
part: Bs = Bass, instrument: electric bass
|
|
106
|
+
|
|
107
|
+
Pno.RH | +G{B3 D4 G4} | *C{C4 E4 G4} |
|
|
108
|
+
Pno.LH | {G2}._{D3} / | {C3} |
|
|
109
|
+
Bs | {G1} | {C2} |
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
The first line in a system carries the chord symbols, the others note
|
|
113
|
+
sets only. `+` presses the sustain pedal and `*` lifts it (2.9);
|
|
114
|
+
`{G2}._{D3}` is a dotted eighth and a sixteenth (2.2).
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
chart.bars[0].parts[0].lines; // [{ name: "RH", line, slots }, { name: "LH", … }]
|
|
118
|
+
extractPart(text, "Pno", "LH"); // one line alone, resting where it isn't written
|
|
119
|
+
pedalStates(chart.bars); // whether the pedal is down after each slot
|
|
120
|
+
```
|
|
121
|
+
|
|
98
122
|
`printChart` sorts a system into score order and lines up its pipes.
|
|
99
123
|
`chart.part` still gives the one part of a single-part chart, and is
|
|
100
124
|
deprecated in favour of `parts`.
|
package/dist/chart/barLine.js
CHANGED
|
@@ -67,6 +67,15 @@ export function misplacedRepeat(token) {
|
|
|
67
67
|
/** Diagnostics listed per line before the rest are summarized. */
|
|
68
68
|
const MAX_LINE_DIAGNOSTICS = 20;
|
|
69
69
|
/** Split a group on `_`, leaving any `_` inside braces to the note set. */
|
|
70
|
+
const DOT_PLACE = "a dot goes on one member of a two-member group (C._D or C_D.); write other rhythms with / holds";
|
|
71
|
+
/**
|
|
72
|
+
* Tokens that end in a dot without being dotted: `N.C.`'s spellings, a
|
|
73
|
+
* run of dots (`...`), and the directions `D.S.` and `D.C.`, which keep
|
|
74
|
+
* their own messages when misplaced.
|
|
75
|
+
*/
|
|
76
|
+
const UNDOTTED = /^[<>^+*]*n\.?c\.?$|^\.+$|^d\.[sc]\.$/i;
|
|
77
|
+
/** A member ending in a dot that is not one of the undotted tokens. */
|
|
78
|
+
const isDotted = (m) => m.endsWith(".") && !UNDOTTED.test(m);
|
|
70
79
|
function groupMembers(token) {
|
|
71
80
|
const out = [""];
|
|
72
81
|
let depth = 0;
|
|
@@ -239,13 +248,27 @@ function directionWithWords(bare, meter, words) {
|
|
|
239
248
|
}
|
|
240
249
|
const ARTICULATION = { ">": "accent", "^": "hit" };
|
|
241
250
|
const PUSH = { 1: "eighth", 2: "sixteenth" };
|
|
242
|
-
|
|
251
|
+
const PEDAL = { "+": "press", "*": "release" };
|
|
252
|
+
/** A slot's leading marks (grammar 2.7–2.9): a pedal mark, a push, an articulation, then the slot. */
|
|
243
253
|
function readMarks(token) {
|
|
254
|
+
const late = /^([<>^]+)([+*])(.*)$/.exec(token);
|
|
255
|
+
if (late)
|
|
256
|
+
return {
|
|
257
|
+
problem: "a pedal mark comes before a push or an accent",
|
|
258
|
+
token,
|
|
259
|
+
suggestion: `${late[2]}${late[1]}${late[3]}`,
|
|
260
|
+
};
|
|
261
|
+
const pedal = PEDAL[token[0] ?? ""];
|
|
262
|
+
const marked = readPushAndAccent(pedal ? token.slice(1) : token, token);
|
|
263
|
+
return "problem" in marked || !pedal ? marked : { pedal, ...marked };
|
|
264
|
+
}
|
|
265
|
+
/** A push, then an articulation, then the slot itself (grammar 2.7, 2.8). */
|
|
266
|
+
function readPushAndAccent(token, written) {
|
|
244
267
|
const pushes = /^<*/.exec(token)?.[0].length ?? 0;
|
|
245
268
|
const push = PUSH[pushes];
|
|
246
269
|
if (pushes && !push)
|
|
247
|
-
return { problem: "a push is < (an eighth) or << (a sixteenth)", token };
|
|
248
|
-
const marked = readArticulation(token.slice(pushes),
|
|
270
|
+
return { problem: "a push is < (an eighth) or << (a sixteenth)", token: written };
|
|
271
|
+
const marked = readArticulation(token.slice(pushes), written);
|
|
249
272
|
return "problem" in marked ? marked : { ...(push ? { push } : {}), ...marked };
|
|
250
273
|
}
|
|
251
274
|
/** A leading `>` or `^`, and the slot after it; a push after it is written in the wrong order. */
|
|
@@ -261,15 +284,24 @@ function readArticulation(text, token) {
|
|
|
261
284
|
}
|
|
262
285
|
const UNPUSHABLE = new Set(["/", "?", "%", "...", "…"]);
|
|
263
286
|
/** Why these marks can't go on this slot; null when they can. */
|
|
287
|
+
/** Whether a slot is one of `/`, `?`, `--` or `N.C.`, which take no accent or pedal. */
|
|
288
|
+
const isPlain = (rest) => UNPUSHABLE.has(rest) || SILENCE.has(rest) || /^n\.?c\.?$/i.test(rest);
|
|
289
|
+
/** Each rule on marks: when it is broken, and what the error says. */
|
|
290
|
+
const MARK_RULES = [
|
|
291
|
+
[(m, inGroup) => Boolean(m.push) && inGroup, "a push goes on a whole slot, not inside a group"],
|
|
292
|
+
[
|
|
293
|
+
(m) => Boolean(m.push) && UNPUSHABLE.has(m.rest),
|
|
294
|
+
"a push goes on a chord, a note set, N.C. or --",
|
|
295
|
+
],
|
|
296
|
+
[
|
|
297
|
+
(m) => Boolean(m.articulation) && isPlain(m.rest),
|
|
298
|
+
"an accent or a hit goes on a chord or a note set",
|
|
299
|
+
],
|
|
300
|
+
[(m) => Boolean(m.pedal) && isPlain(m.rest), "a pedal mark goes on a chord or a note set"],
|
|
301
|
+
];
|
|
264
302
|
function marksProblem(marks, inGroup, token) {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
if (marks.push && UNPUSHABLE.has(marks.rest))
|
|
268
|
-
return { problem: "a push goes on a chord, a note set, N.C. or --", token };
|
|
269
|
-
const plain = UNPUSHABLE.has(marks.rest) || SILENCE.has(marks.rest) || /^n\.?c\.?$/i.test(marks.rest);
|
|
270
|
-
if (marks.articulation && plain)
|
|
271
|
-
return { problem: "an accent or a hit goes on a chord or a note set", token };
|
|
272
|
-
return null;
|
|
303
|
+
const broken = MARK_RULES.find(([breaks]) => breaks(marks, inGroup));
|
|
304
|
+
return broken ? { problem: broken[1], token } : null;
|
|
273
305
|
}
|
|
274
306
|
/** Whether a voicing's note is one of the chord's, by pitch class. */
|
|
275
307
|
const inChord = (note, chord) => {
|
|
@@ -433,22 +465,33 @@ export function parseBarLine(text, line) {
|
|
|
433
465
|
if (problem)
|
|
434
466
|
return report(problem);
|
|
435
467
|
const base = simple(marks.rest);
|
|
436
|
-
const { push, articulation } = marks;
|
|
468
|
+
const { pedal, push, articulation } = marks;
|
|
437
469
|
return (base &&
|
|
438
470
|
{
|
|
439
471
|
...base,
|
|
472
|
+
...(pedal ? { pedal } : {}),
|
|
440
473
|
...(push ? { push } : {}),
|
|
441
474
|
...(articulation ? { articulation } : {}),
|
|
442
475
|
});
|
|
443
476
|
};
|
|
477
|
+
/** A group member, dotted when it ends in a dot that is not part of `N.C.` (grammar 2.2). */
|
|
478
|
+
const memberOf = (m) => {
|
|
479
|
+
if (!isDotted(m))
|
|
480
|
+
return markedSlot(m, true);
|
|
481
|
+
const s = markedSlot(m.slice(0, -1), true);
|
|
482
|
+
return s && { ...s, dotted: true };
|
|
483
|
+
};
|
|
444
484
|
/** One slot token: a simple slot, or a `_` group of them. */
|
|
445
485
|
const slotOf = (token) => {
|
|
446
486
|
const members = groupMembers(token);
|
|
447
487
|
if (members.length === 1)
|
|
448
|
-
return markedSlot(token, false);
|
|
488
|
+
return isDotted(token) ? error(DOT_PLACE, token) : markedSlot(token, false);
|
|
489
|
+
const dots = members.filter(isDotted).length;
|
|
490
|
+
if (dots && (members.length > 2 || dots > 1))
|
|
491
|
+
return error(DOT_PLACE, token);
|
|
449
492
|
const out = [];
|
|
450
493
|
for (const m of members) {
|
|
451
|
-
const s = m ?
|
|
494
|
+
const s = m ? memberOf(m) : error("an empty member in a group", token);
|
|
452
495
|
if (s)
|
|
453
496
|
out.push(s);
|
|
454
497
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ChartDiagnostic, CreditRole, Credits, Line } from "./types.js";
|
|
2
|
+
/** The credit roles, in the order MusicXML writes them (grammar 7.5). */
|
|
3
|
+
export declare const CREDIT_ROLES: readonly CreditRole[];
|
|
4
|
+
/** A credit line, or null when the line isn't one (grammar 7.5). */
|
|
5
|
+
export declare function readCredit(text: string, line: number, diagnostics: ChartDiagnostic[]): Line | null;
|
|
6
|
+
/** A text line that reads like a credit under another name: `author: X`. */
|
|
7
|
+
export declare function nearCredit(text: string, line: number): ChartDiagnostic | null;
|
|
8
|
+
/** Every credit line's text, by role, in written order. */
|
|
9
|
+
export declare function creditsOf(lines: Line[]): Credits;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { DIRECTIVE_AFTER } from "./directives.js";
|
|
2
|
+
/** The credit roles, in the order MusicXML writes them (grammar 7.5). */
|
|
3
|
+
export const CREDIT_ROLES = [
|
|
4
|
+
"composer",
|
|
5
|
+
"lyricist",
|
|
6
|
+
"arranger",
|
|
7
|
+
"copyright",
|
|
8
|
+
];
|
|
9
|
+
const NEAR_CREDITS = {
|
|
10
|
+
author: "composer",
|
|
11
|
+
writer: "composer",
|
|
12
|
+
music: "composer",
|
|
13
|
+
words: "lyricist",
|
|
14
|
+
lyrics: "lyricist",
|
|
15
|
+
arr: "arranger",
|
|
16
|
+
arranged: "arranger",
|
|
17
|
+
rights: "copyright",
|
|
18
|
+
"©": "copyright",
|
|
19
|
+
};
|
|
20
|
+
/** A credit line, or null when the line isn't one (grammar 7.5). */
|
|
21
|
+
export function readCredit(text, line, diagnostics) {
|
|
22
|
+
const m = /^(composer|lyricist|arranger|copyright)\s*:(.*)$/i.exec(text);
|
|
23
|
+
if (!m)
|
|
24
|
+
return null;
|
|
25
|
+
const role = (m[1] ?? "").toLowerCase();
|
|
26
|
+
const value = (m[2] ?? "").trim().replace(/\s+/g, " ");
|
|
27
|
+
if (!value) {
|
|
28
|
+
diagnostics.push({ line, severity: "error", message: `${role}: needs a value`, token: text });
|
|
29
|
+
return { kind: "text", line, text };
|
|
30
|
+
}
|
|
31
|
+
const after = DIRECTIVE_AFTER.exec(value);
|
|
32
|
+
if (after)
|
|
33
|
+
diagnostics.push({
|
|
34
|
+
line,
|
|
35
|
+
severity: "warning",
|
|
36
|
+
message: `a credit runs to the end of the line; put ${after[1]?.toLowerCase()}: on its own line`,
|
|
37
|
+
token: text,
|
|
38
|
+
});
|
|
39
|
+
return { kind: "credit", line, role, text: value };
|
|
40
|
+
}
|
|
41
|
+
/** A text line that reads like a credit under another name: `author: X`. */
|
|
42
|
+
export function nearCredit(text, line) {
|
|
43
|
+
const m = /^([^\s:]+)\s*:\s*(.*)$/.exec(text);
|
|
44
|
+
const role = m?.[1] ? NEAR_CREDITS[m[1].toLowerCase()] : undefined;
|
|
45
|
+
if (!m || !role)
|
|
46
|
+
return null;
|
|
47
|
+
return {
|
|
48
|
+
line,
|
|
49
|
+
severity: "warning",
|
|
50
|
+
message: `not a credit; did you mean ${role}:?`,
|
|
51
|
+
token: text,
|
|
52
|
+
...(m[2] && { suggestion: `${role}: ${m[2]}` }),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/** Every credit line's text, by role, in written order. */
|
|
56
|
+
export function creditsOf(lines) {
|
|
57
|
+
const credits = { composer: [], lyricist: [], arranger: [], copyright: [] };
|
|
58
|
+
for (const l of lines)
|
|
59
|
+
if (l.kind === "credit")
|
|
60
|
+
credits[l.role].push(l.text);
|
|
61
|
+
return credits;
|
|
62
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { ChartDiagnostic, Directives, Meter } from "./types.js";
|
|
2
2
|
export declare const DIRECTIVE_NAMES: readonly ["key", "time", "tempo", "feel"];
|
|
3
|
+
/** A directive written after a comma, in a line that runs to its end (`part:`, credits). */
|
|
4
|
+
export declare const DIRECTIVE_AFTER: RegExp;
|
|
3
5
|
/** `n/d` with n from 1 to 32 and d in 2, 4, 8, 16. */
|
|
4
6
|
export declare function parseMeter(text: string): Meter | null;
|
|
5
7
|
/** Beats per bar: compound meters (6/8, 9/8, 12/8) count dotted quarters. */
|
package/dist/chart/directives.js
CHANGED
package/dist/chart/document.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type { ChartDiagnostic,
|
|
1
|
+
import type { ChartDiagnostic, Credits, DeclaredPart, Line } from "./types.js";
|
|
2
2
|
/** Classify every line of a chart: title, sections, directives, bar lines and text. */
|
|
3
3
|
export declare function readDocument(text: string): {
|
|
4
4
|
title: string | null;
|
|
5
|
-
part:
|
|
6
|
-
parts:
|
|
5
|
+
part: DeclaredPart | null;
|
|
6
|
+
parts: DeclaredPart[];
|
|
7
|
+
credits: Credits;
|
|
7
8
|
lines: Line[];
|
|
8
9
|
diagnostics: ChartDiagnostic[];
|
|
9
10
|
};
|
package/dist/chart/document.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { parseChord } from "../chords/parse.js";
|
|
2
2
|
import { misplacedRepeat, parseBarLine, readRepeat, repeatTail } from "./barLine.js";
|
|
3
|
+
import { creditsOf, nearCredit, readCredit } from "./credits.js";
|
|
3
4
|
import { parseDirectiveLine } from "./directives.js";
|
|
5
|
+
import { checkLines } from "./lines.js";
|
|
6
|
+
import { readPart } from "./partLine.js";
|
|
4
7
|
import { groupSystems } from "./systems.js";
|
|
5
8
|
const NEAR_DIRECTIVES = {
|
|
6
9
|
meter: "time",
|
|
@@ -10,25 +13,6 @@ const NEAR_DIRECTIVES = {
|
|
|
10
13
|
instrument: "part",
|
|
11
14
|
parts: "part",
|
|
12
15
|
};
|
|
13
|
-
const DIRECTIVE_AFTER = /,\s*(key|time|tempo|feel)\s*:/i;
|
|
14
|
-
/** A `part:` line's label and name, or why it has none (grammar 7.3). */
|
|
15
|
-
function readPart(text) {
|
|
16
|
-
const m = /^part\s*:(.*)$/i.exec(text);
|
|
17
|
-
if (!m)
|
|
18
|
-
return null;
|
|
19
|
-
const value = (m[1] ?? "").trim().replace(/\s+/g, " ");
|
|
20
|
-
if (DIRECTIVE_AFTER.test(value))
|
|
21
|
-
return "part: goes on a line of its own; the name runs to the end of the line";
|
|
22
|
-
const labelled = /^([^\s=]*)\s*=\s*(.*)$/.exec(value);
|
|
23
|
-
if (!labelled)
|
|
24
|
-
return value ? { name: value } : "part: needs a name";
|
|
25
|
-
const [, label, name] = labelled;
|
|
26
|
-
if (!label)
|
|
27
|
-
return "part: needs a label before =";
|
|
28
|
-
if (/^[|#@0-9]/.test(label))
|
|
29
|
-
return "a part label can't start with |, #, @ or a digit";
|
|
30
|
-
return name ? { label, name } : "part: needs a name after the label";
|
|
31
|
-
}
|
|
32
16
|
/**
|
|
33
17
|
* Several parts each need a label, and no two may share one in any case
|
|
34
18
|
* (grammar 7.4). A part that breaks either rule is text, with the error.
|
|
@@ -51,7 +35,12 @@ function checkParts(lines, diagnostics) {
|
|
|
51
35
|
}
|
|
52
36
|
return parts;
|
|
53
37
|
}
|
|
54
|
-
const partOf = (l) => (
|
|
38
|
+
const partOf = (l) => ({
|
|
39
|
+
...(l.label && { label: l.label }),
|
|
40
|
+
name: l.name,
|
|
41
|
+
...(l.instrument && { instrument: l.instrument }),
|
|
42
|
+
...(l.clef && { clef: l.clef }),
|
|
43
|
+
});
|
|
55
44
|
function partProblem(l, seen) {
|
|
56
45
|
if (!l.label)
|
|
57
46
|
return {
|
|
@@ -102,6 +91,22 @@ function readHeading(text, line, diagnostics) {
|
|
|
102
91
|
});
|
|
103
92
|
return { kind: "section", line, name: rest, repeat, elided };
|
|
104
93
|
}
|
|
94
|
+
/** A declared label written before a bar line, exactly, or a part's label, a dot and a line's name (grammar 7.6). */
|
|
95
|
+
function findLabel(word, declared) {
|
|
96
|
+
const match = (w) => declared.find((p) => p.label?.toLowerCase() === w.toLowerCase())?.label;
|
|
97
|
+
const exact = match(word);
|
|
98
|
+
if (exact)
|
|
99
|
+
return { part: exact };
|
|
100
|
+
const dot = word.lastIndexOf(".");
|
|
101
|
+
const label = dot > 0 ? match(word.slice(0, dot)) : undefined;
|
|
102
|
+
return label ? { part: label, lineName: word.slice(dot + 1) } : null;
|
|
103
|
+
}
|
|
104
|
+
/** The word before a bar line, whether a space follows it, and the bar line. */
|
|
105
|
+
function splitLabel(t) {
|
|
106
|
+
const m = LABELLED.exec(t);
|
|
107
|
+
return m ? { word: m[1] ?? "", space: Boolean(m[2]), rest: m[3] ?? "" } : null;
|
|
108
|
+
}
|
|
109
|
+
const LINE_NAME = /^[A-Za-z0-9]+$/;
|
|
105
110
|
/** A label and the bar line after it: `Gtr | G |` (grammar 7.4). */
|
|
106
111
|
const LABELLED = /^([^\s|]+)(\s*)(\|.*)$/;
|
|
107
112
|
const readsCleanly = (barLine) => {
|
|
@@ -149,6 +154,9 @@ function oldFormat(text, line) {
|
|
|
149
154
|
const label = /^\[([^\]]+)\]$/.exec(text) ?? /^([A-Za-z][\w ]*):$/.exec(text);
|
|
150
155
|
if (label?.[1])
|
|
151
156
|
return warn("a section label; barmark headings start with ##", `## ${label[1].trim()}`);
|
|
157
|
+
const credit = nearCredit(text, line);
|
|
158
|
+
if (credit)
|
|
159
|
+
return credit;
|
|
152
160
|
const near = /^(\w+)\s*:\s*(.*)$/.exec(text);
|
|
153
161
|
const name = near?.[1] ? NEAR_DIRECTIVES[near[1].toLowerCase()] : undefined;
|
|
154
162
|
if (near && name)
|
|
@@ -190,6 +198,22 @@ function noBarLines(lines) {
|
|
|
190
198
|
token: first.text,
|
|
191
199
|
};
|
|
192
200
|
}
|
|
201
|
+
/** A part's bare line in a single-part chart with no lines is unlabelled, as before (grammar 7.4). */
|
|
202
|
+
function unlabelled(l) {
|
|
203
|
+
if (l.kind !== "bars" && l.kind !== "invalid")
|
|
204
|
+
return l;
|
|
205
|
+
const { part: _p, ...rest } = l;
|
|
206
|
+
return rest;
|
|
207
|
+
}
|
|
208
|
+
/** Systems and part lines, when the chart has several parts or a part writes lines (grammar 7.4, 7.6). */
|
|
209
|
+
function groupParts(lines, parts) {
|
|
210
|
+
const lined = lines.some((l) => (l.kind === "bars" || l.kind === "invalid") && l.lineName !== undefined);
|
|
211
|
+
if (parts.length < 2 && !lined)
|
|
212
|
+
return { lines: lines.map(unlabelled), parts, diagnostics: [] };
|
|
213
|
+
const systems = groupSystems(lines);
|
|
214
|
+
const checked = checkLines(systems.lines, parts);
|
|
215
|
+
return { ...checked, diagnostics: [...systems.diagnostics, ...checked.diagnostics] };
|
|
216
|
+
}
|
|
193
217
|
/** Classify every line of a chart: title, sections, directives, bar lines and text. */
|
|
194
218
|
export function readDocument(text) {
|
|
195
219
|
const lines = [];
|
|
@@ -215,6 +239,9 @@ export function readDocument(text) {
|
|
|
215
239
|
return { kind: "part", line, ...read };
|
|
216
240
|
};
|
|
217
241
|
const otherLine = (t, line) => {
|
|
242
|
+
const credit = readCredit(t, line, diagnostics);
|
|
243
|
+
if (credit)
|
|
244
|
+
return credit;
|
|
218
245
|
const read = readPart(t);
|
|
219
246
|
if (read)
|
|
220
247
|
return partLine(read, t, line);
|
|
@@ -233,35 +260,30 @@ export function readDocument(text) {
|
|
|
233
260
|
diagnostics.push(...r.diagnostics);
|
|
234
261
|
return r.bars ?? { kind: "invalid", line, text: t, written: r.written };
|
|
235
262
|
};
|
|
236
|
-
|
|
263
|
+
const declaredParts = () => lines.filter((l) => l.kind === "part");
|
|
264
|
+
/** A labelled line that can't be read: no space before its pipe, or a bad line name. */
|
|
265
|
+
const badLabel = (t, line, word, rest, owner) => {
|
|
266
|
+
const space = t.length > word.length + rest.length;
|
|
267
|
+
diagnostics.push({
|
|
268
|
+
line,
|
|
269
|
+
severity: "error",
|
|
270
|
+
message: space ? "a line name is letters and digits" : "a space goes between the label and |",
|
|
271
|
+
token: t,
|
|
272
|
+
...(!space && { suggestion: `${word} ${rest}` }),
|
|
273
|
+
});
|
|
274
|
+
return { kind: "invalid", line, text: t, written: parseBarLine(rest, line).written, ...owner };
|
|
275
|
+
};
|
|
276
|
+
/** A declared part's bar line, or one of its lines (`Pno.RH`, grammar 7.6). */
|
|
237
277
|
const labelledLine = (t, line) => {
|
|
238
|
-
const
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
if (!m || !found?.label)
|
|
278
|
+
const split = splitLabel(t);
|
|
279
|
+
const owner = split && findLabel(split.word, declaredParts());
|
|
280
|
+
if (!split || !owner)
|
|
242
281
|
return null;
|
|
243
|
-
const
|
|
244
|
-
if (!space)
|
|
245
|
-
|
|
246
|
-
line,
|
|
247
|
-
severity: "error",
|
|
248
|
-
message: "a space goes between the label and |",
|
|
249
|
-
token: t,
|
|
250
|
-
suggestion: `${word} ${rest}`,
|
|
251
|
-
});
|
|
252
|
-
const written = parseBarLine(rest, line).written;
|
|
253
|
-
return {
|
|
254
|
-
kind: "invalid",
|
|
255
|
-
line,
|
|
256
|
-
text: t,
|
|
257
|
-
written,
|
|
258
|
-
...(declared.length > 1 && { part: found.label }),
|
|
259
|
-
};
|
|
260
|
-
}
|
|
282
|
+
const { word, space, rest } = split;
|
|
283
|
+
if (!space || !LINE_NAME.test(owner.lineName ?? "X"))
|
|
284
|
+
return badLabel(t, line, word, rest, owner);
|
|
261
285
|
const read = barLine(rest, line);
|
|
262
|
-
|
|
263
|
-
return read;
|
|
264
|
-
return { ...read, part: found.label };
|
|
286
|
+
return read.kind === "bars" || read.kind === "invalid" ? { ...read, ...owner } : read;
|
|
265
287
|
};
|
|
266
288
|
const classify = (t, line) => {
|
|
267
289
|
if (t.startsWith("|"))
|
|
@@ -286,13 +308,15 @@ export function readDocument(text) {
|
|
|
286
308
|
const empty = noBarLines(lines);
|
|
287
309
|
if (empty)
|
|
288
310
|
diagnostics.push(empty);
|
|
289
|
-
const
|
|
290
|
-
const grouped =
|
|
311
|
+
const read = checkParts(lines, diagnostics);
|
|
312
|
+
const grouped = groupParts(lines, read);
|
|
291
313
|
diagnostics.push(...grouped.diagnostics);
|
|
314
|
+
const { parts } = grouped;
|
|
292
315
|
return {
|
|
293
316
|
title,
|
|
294
317
|
part: parts.length === 1 ? (parts[0] ?? null) : null,
|
|
295
318
|
parts,
|
|
319
|
+
credits: creditsOf(lines),
|
|
296
320
|
lines: grouped.lines,
|
|
297
321
|
diagnostics,
|
|
298
322
|
};
|
package/dist/chart/expand.d.ts
CHANGED
|
@@ -11,7 +11,9 @@ export declare function flattenBars(events: ChartEvent[]): PlayedBar[];
|
|
|
11
11
|
* `label` names the part a projected chart is (grammar 7.4), for its
|
|
12
12
|
* messages; `share` is how many parts split the expansion budget.
|
|
13
13
|
*/
|
|
14
|
-
export declare function expand(lines: Line[], label?: string, share?: number
|
|
14
|
+
export declare function expand(lines: Line[], label?: string, share?: number,
|
|
15
|
+
/** False for one line of a part (grammar 7.6): the pedal is the part's, warned of once its lines are folded. */
|
|
16
|
+
pedal?: boolean): {
|
|
15
17
|
events: ChartEvent[];
|
|
16
18
|
sections: SectionOccurrence[];
|
|
17
19
|
diagnostics: ChartDiagnostic[];
|
package/dist/chart/expand.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { planJump } from "./direction.js";
|
|
2
2
|
import { beatsOf } from "./directives.js";
|
|
3
|
+
import { pedalWarnings } from "./pedal.js";
|
|
3
4
|
import { pairRepeats } from "./repeats.js";
|
|
5
|
+
import { memberShares } from "./shares.js";
|
|
4
6
|
/** Nested repeats multiply; expansion stops here rather than run away. */
|
|
5
7
|
export const MAX_EXPANDED_BARS = 10_000;
|
|
6
8
|
/**
|
|
@@ -31,7 +33,10 @@ const PUSH_LENGTH = { eighth: 1 / 8, sixteenth: 1 / 16 };
|
|
|
31
33
|
function timed(bar) {
|
|
32
34
|
const each = bar.meter.n / bar.meter.d / bar.slots.length;
|
|
33
35
|
return bar.slots.flatMap((s) => s.kind === "group"
|
|
34
|
-
? s.members.map((
|
|
36
|
+
? memberShares(s.members).map((share, i) => ({
|
|
37
|
+
slot: s.members[i],
|
|
38
|
+
length: each * share,
|
|
39
|
+
}))
|
|
35
40
|
: [{ slot: s, length: each }]);
|
|
36
41
|
}
|
|
37
42
|
/** Why a push can't take its time from a slot this long; null when it can. */
|
|
@@ -81,7 +86,9 @@ function removeLastBar(events) {
|
|
|
81
86
|
* `label` names the part a projected chart is (grammar 7.4), for its
|
|
82
87
|
* messages; `share` is how many parts split the expansion budget.
|
|
83
88
|
*/
|
|
84
|
-
export function expand(lines, label, share = 1
|
|
89
|
+
export function expand(lines, label, share = 1,
|
|
90
|
+
/** False for one line of a part (grammar 7.6): the pedal is the part's, warned of once its lines are folded. */
|
|
91
|
+
pedal = true) {
|
|
85
92
|
const diagnostics = [];
|
|
86
93
|
const maxBars = Math.max(1, Math.floor(MAX_EXPANDED_BARS / share));
|
|
87
94
|
// Repeats of bodies that play no bars (fermatas only) are bounded too.
|
|
@@ -457,5 +464,7 @@ export function expand(lines, label, share = 1) {
|
|
|
457
464
|
form: forms.get(written) ?? 0,
|
|
458
465
|
};
|
|
459
466
|
});
|
|
467
|
+
if (pedal)
|
|
468
|
+
diagnostics.push(...pedalWarnings(flattenBars(events)));
|
|
460
469
|
return { events, sections: sectionsOut, diagnostics };
|
|
461
470
|
}
|
package/dist/chart/index.d.ts
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
export { parseBarLine } from "./barLine.js";
|
|
2
|
+
export { CREDIT_ROLES } from "./credits.js";
|
|
2
3
|
export { degreeOf } from "./degree.js";
|
|
3
4
|
export { printDirection } from "./direction.js";
|
|
4
5
|
export { beatsOf, DIRECTIVE_NAMES, parseDirectiveLine, parseMeter } from "./directives.js";
|
|
5
6
|
export { readDocument } from "./document.js";
|
|
6
7
|
export { expand, flattenBars, MAX_EXPANDED_BARS } from "./expand.js";
|
|
8
|
+
export { CLEF_NAMES, type ClefName, INSTRUMENTS, type InstrumentInfo, type InstrumentName, instrumentInfo, type WrittenInterval, } from "./instruments.js";
|
|
9
|
+
export { MAX_LINES } from "./lines.js";
|
|
7
10
|
export { extractPart, parseChart } from "./parse.js";
|
|
8
11
|
export { projectPart } from "./parts.js";
|
|
12
|
+
export { pedalStates } from "./pedal.js";
|
|
9
13
|
export { printCell, printChart, printLine, printParsed, printPart, printPasses, printSlot, reduceSlots, } from "./print.js";
|
|
14
|
+
export { memberShares } from "./shares.js";
|
|
15
|
+
export { streamKey } from "./systems.js";
|
|
10
16
|
export { type TransposeBy, transposeChart } from "./transpose.js";
|
|
11
17
|
export type * from "./types.js";
|
package/dist/chart/index.js
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
export { parseBarLine } from "./barLine.js";
|
|
2
|
+
export { CREDIT_ROLES } from "./credits.js";
|
|
2
3
|
export { degreeOf } from "./degree.js";
|
|
3
4
|
export { printDirection } from "./direction.js";
|
|
4
5
|
export { beatsOf, DIRECTIVE_NAMES, parseDirectiveLine, parseMeter } from "./directives.js";
|
|
5
6
|
export { readDocument } from "./document.js";
|
|
6
7
|
export { expand, flattenBars, MAX_EXPANDED_BARS } from "./expand.js";
|
|
8
|
+
export { CLEF_NAMES, INSTRUMENTS, instrumentInfo, } from "./instruments.js";
|
|
9
|
+
export { MAX_LINES } from "./lines.js";
|
|
7
10
|
export { extractPart, parseChart } from "./parse.js";
|
|
8
11
|
export { projectPart } from "./parts.js";
|
|
12
|
+
export { pedalStates } from "./pedal.js";
|
|
9
13
|
export { printCell, printChart, printLine, printParsed, printPart, printPasses, printSlot, reduceSlots, } from "./print.js";
|
|
14
|
+
export { memberShares } from "./shares.js";
|
|
15
|
+
export { streamKey } from "./systems.js";
|
|
10
16
|
export { transposeChart } from "./transpose.js";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The instruments a part may name (grammar 7.3): a closed list, each with
|
|
3
|
+
* what a converter needs to notate it. A chart is always at concert pitch;
|
|
4
|
+
* `written` only says how far above it a converter writes the part.
|
|
5
|
+
*/
|
|
6
|
+
export type ClefName = "treble" | "bass" | "treble 8vb" | "alto";
|
|
7
|
+
export declare const CLEF_NAMES: readonly ClefName[];
|
|
8
|
+
export type InstrumentName = "piano" | "electric piano" | "organ" | "synth" | "acoustic guitar" | "electric guitar" | "electric bass" | "double bass" | "trumpet in Bb" | "alto sax" | "tenor sax" | "trombone" | "flute" | "violin" | "cello" | "voice";
|
|
9
|
+
/** How far above sounding pitch a part is written, in scale steps and semitones. */
|
|
10
|
+
export type WrittenInterval = {
|
|
11
|
+
diatonic: number;
|
|
12
|
+
chromatic: number;
|
|
13
|
+
};
|
|
14
|
+
export type InstrumentInfo = {
|
|
15
|
+
name: InstrumentName;
|
|
16
|
+
/** The clef of its (upper) staff; a two-staff instrument's lower staff is bass. */
|
|
17
|
+
clef: ClefName;
|
|
18
|
+
staves: 1 | 2;
|
|
19
|
+
written: WrittenInterval;
|
|
20
|
+
/** Its General MIDI program, 1–128. */
|
|
21
|
+
program: number;
|
|
22
|
+
};
|
|
23
|
+
export declare const INSTRUMENTS: readonly InstrumentInfo[];
|
|
24
|
+
/** The listed instrument with this name, in any case; null when there is none. */
|
|
25
|
+
export declare function instrumentInfo(name: string): InstrumentInfo | null;
|
|
26
|
+
/** The listed names an unknown one is near: those holding all its words, or else within two edits. */
|
|
27
|
+
export declare function nearInstruments(name: string): InstrumentName[];
|