barmark 0.15.0 → 0.17.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 +145 -1
- package/README.md +49 -0
- package/dist/chart/barLine.js +130 -18
- package/dist/chart/credits.d.ts +1 -1
- package/dist/chart/credits.js +5 -1
- package/dist/chart/document.d.ts +3 -3
- package/dist/chart/document.js +95 -51
- package/dist/chart/expand.d.ts +19 -1
- package/dist/chart/expand.js +51 -16
- package/dist/chart/index.d.ts +5 -0
- package/dist/chart/index.js +5 -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 +130 -0
- package/dist/chart/lyricRows.d.ts +25 -0
- package/dist/chart/lyricRows.js +178 -0
- package/dist/chart/parse.d.ts +8 -3
- package/dist/chart/parse.js +158 -20
- 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 +151 -26
- package/dist/chart/repeats.js +3 -1
- package/dist/chart/shares.d.ts +28 -0
- package/dist/chart/shares.js +31 -0
- package/dist/chart/syllable.d.ts +21 -0
- package/dist/chart/syllable.js +32 -0
- package/dist/chart/systems.d.ts +2 -0
- package/dist/chart/systems.js +19 -3
- package/dist/chart/types.d.ts +116 -8
- package/dist/chart/verses.d.ts +55 -0
- package/dist/chart/verses.js +351 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,148 @@ Releases follow the process in [RELEASING.md](RELEASING.md).
|
|
|
9
9
|
|
|
10
10
|
## [Unreleased]
|
|
11
11
|
|
|
12
|
+
## [0.17.0] - 2026-11-07
|
|
13
|
+
|
|
14
|
+
A grammar change: syllables on notes (4.3), lyric rows and verses in play
|
|
15
|
+
order (7.7), a part's bare line sharing a system with its named lines
|
|
16
|
+
(7.6, amended), `---` breaks and a leading `\` (1). Implements the
|
|
17
|
+
[grammar v0.1 draft](https://github.com/kevinpeckham/barmark/blob/main/docs/grammar-v0.1-draft.md).
|
|
18
|
+
|
|
19
|
+
**Changes what an existing chart means.** A line of only `---` (three or
|
|
20
|
+
more hyphens) is now a break that ends a system, not text. A part's bare
|
|
21
|
+
line followed directly by its named lines (`Pno | C |` then
|
|
22
|
+
`Pno.RH | … |`) is now one system, the bare line the part's first line;
|
|
23
|
+
it used to be two systems played one after the other (put `---` between
|
|
24
|
+
them for that). Also: a `lyrics:` or `lyrics N:` line followed by a bar
|
|
25
|
+
line is a lyric row, and a text line's leading `\` is no longer shown.
|
|
26
|
+
|
|
27
|
+
### Added
|
|
28
|
+
|
|
29
|
+
- `---` (three or more hyphens alone) ends a system and means nothing else;
|
|
30
|
+
it parses as a `break` line and prints as `---` (grammar 1, 7.4).
|
|
31
|
+
- Syllables on notes (grammar 4.3): `{G4}:maz-` sings a syllable on a note
|
|
32
|
+
set, a trailing `-` continues the word, `:/` holds the syllable before
|
|
33
|
+
over a new note and `~` joins elided syllables (`{C4}:the~end`). A dotted
|
|
34
|
+
note takes its dot before the colon (`{C4}.:maz-`). The slot gains
|
|
35
|
+
`syllable` (the new `Syllable` type); the printer writes it back, and `%`
|
|
36
|
+
copies a bar's notes without their syllables. A syllable on a chord
|
|
37
|
+
name, a voicing, `/`, `--`, `N.C.` or `?`, an empty one, or `:/-` (a
|
|
38
|
+
hold can't begin or continue a word) is an error.
|
|
39
|
+
A syllable ends only at a space, `_`, `|`, `{` or a straight quote, so
|
|
40
|
+
curly quotes and brackets are characters of it (`{C4}:“Ho-`,
|
|
41
|
+
`{C4}:[x]`): they open no words and no one-bar meter.
|
|
42
|
+
- Lyric rows (grammar 7.7): `lyrics:` or `lyrics N:` (verse N) then a bar
|
|
43
|
+
line writes syllables on the beats, its bars divided as a chord row's
|
|
44
|
+
(`/` holds, `_` splits a slot, `--` is a breath). A row covers the bar
|
|
45
|
+
line or system just above it, or under a replay heading the replayed
|
|
46
|
+
section's lines in order, and must match its bar count. It parses as a
|
|
47
|
+
`lyrics` line (the new `LyricSlot` type) with `verse`, `cells` and
|
|
48
|
+
`covers`, the source lines of the bar lines it covers. The printer lines
|
|
49
|
+
a row up under its bars, the wider cell of each column setting its
|
|
50
|
+
width. A row with no bar line above it, a wrong bar count, an empty bar
|
|
51
|
+
or syllable, a quote or brace, or a verse number of 0 or past
|
|
52
|
+
`Number.MAX_SAFE_INTEGER` is an error.
|
|
53
|
+
- Verses in play order (grammar 7.7): each played bar gains `lyrics`, one
|
|
54
|
+
`PlayedLyrics` per verse it sings, each syllable with its onset `at` in
|
|
55
|
+
whole notes and `note` (true when a note of the singing line starts
|
|
56
|
+
there). Syllables on notes are verse 1 and `lyrics N:` verse N; outside a
|
|
57
|
+
repeat every verse is sung, and inside one verse N on pass N (a second
|
|
58
|
+
ending holds verse 2's words; a jump's pass back sings pass 1's). Bars
|
|
59
|
+
whose only verse is verse 1 sing it on every pass; a lone `lyrics N:`
|
|
60
|
+
row (N from 2) sings on pass N only, and the other passes warn. A
|
|
61
|
+
replay's rows replace its words. The first part with `instrument: voice`,
|
|
62
|
+
else the first with syllables, sings; its `DeclaredPart` gains `sings`,
|
|
63
|
+
the line its notes carry the syllables on. `lyrics 1:` or an unnumbered
|
|
64
|
+
row under notes with syllables, an unnumbered row among numbered ones and
|
|
65
|
+
a verse written twice over the same bars are errors; a row's syllable
|
|
66
|
+
where the singing line starts no note, and a `:/` with nothing sung
|
|
67
|
+
before it, warn. Another part's extract (`extractPart`, `printPart`)
|
|
68
|
+
leaves the singer's rows out.
|
|
69
|
+
Syllables on a part's notes are that part's, so a choir chart's bars
|
|
70
|
+
carry one `PlayedLyrics` per part and verse (verse order, then score
|
|
71
|
+
order), each part's `DeclaredPart.sings` set; lyric rows stay the
|
|
72
|
+
singer's, and only the singer's syllables clash with a row over them.
|
|
73
|
+
A numbered verse that no pass sings, a repeat's pass that sings
|
|
74
|
+
nothing where other passes sing, and syllables on notes that no pass
|
|
75
|
+
sings (verse 1 on a second ending), warn.
|
|
76
|
+
A row's `/` where the singing line starts a new note is a held syllable
|
|
77
|
+
there (`{ kind: "held" }`, `note: true`), as `:/` on the notes is: a
|
|
78
|
+
melisma the converters extend and the renderer draws.
|
|
79
|
+
A row starting with `/` holds on what its verse last sang, in play
|
|
80
|
+
order, unless the verse breathed since, so a verse holds a word across
|
|
81
|
+
a line break. Before its verse has sung anything the `/` sings nothing
|
|
82
|
+
and warns as a `:/` with nothing sung before it does (so the export
|
|
83
|
+
writes no `<extend/>` with nothing before it).
|
|
84
|
+
|
|
85
|
+
### Changed
|
|
86
|
+
|
|
87
|
+
- `Line` gains the `break` and `lyrics` kinds, so an exhaustive `switch`
|
|
88
|
+
on `Line["kind"]` needs a case for each.
|
|
89
|
+
- A text line written with a leading `\` now holds its text without the
|
|
90
|
+
backslash, marked `escaped: true`; the printer writes the backslash back.
|
|
91
|
+
The escaped-pipes warning still applies to the rest of the line, and a
|
|
92
|
+
chart whose only text is escaped no longer warns that it has no bar lines.
|
|
93
|
+
- A `---` line between endings no longer ends the repeat (grammar 5.1);
|
|
94
|
+
like text and credit lines, it may sit between them, and so may a lyric
|
|
95
|
+
row under an ending.
|
|
96
|
+
- `lyrics:` followed by a bar line is now a lyric row, not text with a
|
|
97
|
+
warning to write `lyricist:`; followed by anything else it still warns.
|
|
98
|
+
- A part's named lines written after its bare line now join it in a
|
|
99
|
+
system (grammar 7.6, amended): `Vox` then `Vox.Mel` play together, the
|
|
100
|
+
bare line as the part's first line (it holds the harmony; `Vox.Mel` holds
|
|
101
|
+
notes only). Such a part lists the bare line first in
|
|
102
|
+
`DeclaredPart.lines` as `""`, and its bars' `lines` give it the name
|
|
103
|
+
`""`; `extractPart(text, "Vox", "")` extracts it alone. A bare line
|
|
104
|
+
counts toward the four lines. Named lines written straight after their
|
|
105
|
+
part's bare line used to start a new system and now join it; put `---`
|
|
106
|
+
between them to keep them apart. A bare line after its part's named
|
|
107
|
+
lines still starts a new system. A bare line that is a fifth line
|
|
108
|
+
(an error) is dropped and none of the part's lines plays it: its four
|
|
109
|
+
named lines play, the first of them first.
|
|
110
|
+
|
|
111
|
+
## [0.16.0] - 2026-11-04
|
|
112
|
+
|
|
113
|
+
A grammar change: part lines (7.6), sustain pedal marks (2.9), dotted
|
|
114
|
+
figures (2.2), and `instrument:` and `clef:` on the `part:` line (7.3).
|
|
115
|
+
Charts that read before read the same. Implements the
|
|
116
|
+
[grammar v0.1 draft](https://github.com/kevinpeckham/barmark/blob/main/docs/grammar-v0.1-draft.md).
|
|
117
|
+
|
|
118
|
+
### Added
|
|
119
|
+
|
|
120
|
+
- **Part lines** (grammar 7.6): up to four lines per part, labelled
|
|
121
|
+
`Pno.RH |` and `Pno.LH |`, in systems as parts are. The first line in a
|
|
122
|
+
system carries the harmony and the others notes only; a fifth line, or
|
|
123
|
+
a chord on another line, is an error. Bar lines gain `lineName`,
|
|
124
|
+
declared parts gain `lines`, and the canonical form sorts a system's
|
|
125
|
+
lines into score order: the order of the part's first system writing
|
|
126
|
+
two or more of its lines, so an intro for the left hand alone keeps the
|
|
127
|
+
right hand first. `streamKey` and `MAX_LINES` are exported.
|
|
128
|
+
Each line plays on its own: a played bar's part entry gains `lines`
|
|
129
|
+
(`LineBar`: name, line, slots, words), one per line playing there, and
|
|
130
|
+
the part's `slots` are its first playing line's. A bare line and a tutti
|
|
131
|
+
line play as the part's first line; a line not written rests. A
|
|
132
|
+
single-part chart's bars, and an extracted part's, carry `lines`
|
|
133
|
+
themselves, and `printPart` keeps the `Pno.RH |` labels.
|
|
134
|
+
`extractPart(text, label, lineName)` gives one line alone, as a
|
|
135
|
+
converter writes it: resting (tacet) where the line isn't written.
|
|
136
|
+
- **Sustain pedal marks** (grammar 2.9): `+G` presses or changes the
|
|
137
|
+
pedal, `*G` lifts it; `--`, a tacet bar and the chart's end lift it too.
|
|
138
|
+
A chord slot gains `pedal`, and `pedalStates` gives whether the pedal is
|
|
139
|
+
down at the end of each slot, in play order. A `*` with the pedal
|
|
140
|
+
already up is a warning.
|
|
141
|
+
- **Dotted figures** (grammar 2.2): a dot after one member of a
|
|
142
|
+
two-member group, `C._D` (a dotted eighth and a sixteenth in a beat)
|
|
143
|
+
or `C_D.`. Group members gain `dotted`, and `memberShares` gives each
|
|
144
|
+
member's share of its slot. `N.C._G` keeps its meaning, and a misplaced
|
|
145
|
+
`...`, `D.S.` or `D.C.` keeps its own message.
|
|
146
|
+
- **`instrument:` and `clef:` on the `part:` line** (grammar 7.3):
|
|
147
|
+
`part: Tpt = Trumpet, instrument: trumpet in Bb`, `part: Ld = Lead,
|
|
148
|
+
clef: bass`. The instrument comes from a list of 16 (`INSTRUMENTS`,
|
|
149
|
+
`instrumentInfo`), each with its clef, written transposition, staves
|
|
150
|
+
and General MIDI program, for converters. `Part` gains `instrument` and
|
|
151
|
+
`clef`, present when written. An unknown instrument is an error naming
|
|
152
|
+
the near ones; `clef:` on a keyboard is an error.
|
|
153
|
+
|
|
12
154
|
## [0.15.0] - 2026-11-04
|
|
13
155
|
|
|
14
156
|
A grammar change: credit lines (7.5). Charts that read before read the
|
|
@@ -383,7 +525,9 @@ The first working release: the reference parser and printer for the
|
|
|
383
525
|
|
|
384
526
|
- **A placeholder package that holds the `barmark` name** while the spec and parser are written.
|
|
385
527
|
|
|
386
|
-
[Unreleased]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.
|
|
528
|
+
[Unreleased]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.17.0...HEAD
|
|
529
|
+
[0.17.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.16.0...barmark-v0.17.0
|
|
530
|
+
[0.16.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.15.0...barmark-v0.16.0
|
|
387
531
|
[0.15.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.14.1...barmark-v0.15.0
|
|
388
532
|
[0.14.1]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.14.0...barmark-v0.14.1
|
|
389
533
|
[0.14.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.13.0...barmark-v0.14.0
|
package/README.md
CHANGED
|
@@ -96,10 +96,59 @@ printPart(text, "Pno"); // the same as text: tacet bars written N.C.
|
|
|
96
96
|
projectPart(chart.lines, chart.parts, "Pno"); // one part's lines
|
|
97
97
|
```
|
|
98
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
|
+
|
|
99
122
|
`printChart` sorts a system into score order and lines up its pipes.
|
|
100
123
|
`chart.part` still gives the one part of a single-part chart, and is
|
|
101
124
|
deprecated in favour of `parts`.
|
|
102
125
|
|
|
126
|
+
### Voice and lyrics
|
|
127
|
+
|
|
128
|
+
```
|
|
129
|
+
part: Vox = Voice, instrument: voice
|
|
130
|
+
key: G, time: 3/4
|
|
131
|
+
|
|
132
|
+
Vox | [1/4] N.C. | G | G / G7 |
|
|
133
|
+
Vox.Mel | [1/4] {D4}:A- | {G4}:maz- / {B4}:ing_{G4}:/ | {B4}:grace / {A4}:how |
|
|
134
|
+
lyrics 2: | 'Twas | grace / that | taught / my |
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
A lead sheet puts the chords on the voice part's bare line and its melody
|
|
138
|
+
on a second line, `Vox.Mel` (grammar 7.6). A syllable follows a note
|
|
139
|
+
after a colon (`{G4}:maz-`; a trailing `-` continues the word, `~` joins
|
|
140
|
+
elided syllables, `:/` holds the syllable over a new note). A **lyric
|
|
141
|
+
row** (`lyrics:`, or `lyrics N:` for verse N; grammar 7.7) writes later
|
|
142
|
+
verses under a system, one cell per bar. `---` on a line of its own
|
|
143
|
+
separates blocks, and a text line that starts with `\` is text.
|
|
144
|
+
|
|
145
|
+
```ts
|
|
146
|
+
chart.bars[0].lyrics; // a PlayedLyrics per verse the bar sings: { verse, part?, syllables }
|
|
147
|
+
chart.parts[0].sings; // the name of the line whose notes carry the words ("Mel" here; "" for a bare line)
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Verses come out in play order: inside a repeat, verse N is pass N.
|
|
151
|
+
|
|
103
152
|
- **`parseChart`** never throws. A line with an error is left out of the
|
|
104
153
|
play order and reported, and the rest of the chart still reads.
|
|
105
154
|
- **`printChart`** changes spelling and layout only: lines with errors and
|
package/dist/chart/barLine.js
CHANGED
|
@@ -3,6 +3,7 @@ import { parseNoteSet } from "../chords/noteSet.js";
|
|
|
3
3
|
import { parseChord } from "../chords/parse.js";
|
|
4
4
|
import { isDirectionWord, readDirection } from "./direction.js";
|
|
5
5
|
import { parseMeter } from "./directives.js";
|
|
6
|
+
import { readSyllable, splitSyllable } from "./syllable.js";
|
|
6
7
|
const FERMATA = new Set(["...", "…"]);
|
|
7
8
|
/** Whether a cell is a bar: `...`, a direction and a rehearsal mark mark a place between bars. */
|
|
8
9
|
export const isBar = (c) => c.kind === "slots" || c.kind === "simile";
|
|
@@ -67,6 +68,15 @@ export function misplacedRepeat(token) {
|
|
|
67
68
|
/** Diagnostics listed per line before the rest are summarized. */
|
|
68
69
|
const MAX_LINE_DIAGNOSTICS = 20;
|
|
69
70
|
/** Split a group on `_`, leaving any `_` inside braces to the note set. */
|
|
71
|
+
const DOT_PLACE = "a dot goes on one member of a two-member group (C._D or C_D.); write other rhythms with / holds";
|
|
72
|
+
/**
|
|
73
|
+
* Tokens that end in a dot without being dotted: `N.C.`'s spellings, a
|
|
74
|
+
* run of dots (`...`), and the directions `D.S.` and `D.C.`, which keep
|
|
75
|
+
* their own messages when misplaced.
|
|
76
|
+
*/
|
|
77
|
+
const UNDOTTED = /^[<>^+*]*n\.?c\.?$|^\.+$|^d\.[sc]\.$/i;
|
|
78
|
+
/** A member ending in a dot that is not one of the undotted tokens. */
|
|
79
|
+
const isDotted = (m) => m.endsWith(".") && !UNDOTTED.test(m);
|
|
70
80
|
function groupMembers(token) {
|
|
71
81
|
const out = [""];
|
|
72
82
|
let depth = 0;
|
|
@@ -170,6 +180,32 @@ const isDirectionCell = (p) => {
|
|
|
170
180
|
const d = readDirection(p);
|
|
171
181
|
return !!d && "direction" in d;
|
|
172
182
|
};
|
|
183
|
+
/** Where a syllable ends (grammar 4.3): a space, `_`, `|`, `{` or a straight quote. */
|
|
184
|
+
const SYLLABLE_END = /[\s_|{"]/;
|
|
185
|
+
/**
|
|
186
|
+
* Which of a cell's characters belong to a syllable: those after the colon
|
|
187
|
+
* that follows a note set's brace (and a rhythm's dot), up to its end. In a
|
|
188
|
+
* syllable a curly quote or a `[` is a character like any other.
|
|
189
|
+
*/
|
|
190
|
+
function inSyllables(chars) {
|
|
191
|
+
const out = [];
|
|
192
|
+
let sung = false;
|
|
193
|
+
chars.forEach((ch, i) => {
|
|
194
|
+
if (sung && SYLLABLE_END.test(ch))
|
|
195
|
+
sung = false;
|
|
196
|
+
out.push(sung);
|
|
197
|
+
const before = chars[i - 1] === "." ? chars[i - 2] : chars[i - 1];
|
|
198
|
+
if (!sung && ch === ":" && before === "}")
|
|
199
|
+
sung = true;
|
|
200
|
+
});
|
|
201
|
+
return out;
|
|
202
|
+
}
|
|
203
|
+
/** A cell's text with its syllables blanked, to look for what only the rest of it holds. */
|
|
204
|
+
const outsideSyllables = (cell) => {
|
|
205
|
+
const chars = [...cell];
|
|
206
|
+
const sung = inSyllables(chars);
|
|
207
|
+
return chars.map((ch, i) => (sung[i] ? " " : ch)).join("");
|
|
208
|
+
};
|
|
173
209
|
/**
|
|
174
210
|
* Quoted words out of a cell (grammar 2.6): the cell with each one blanked,
|
|
175
211
|
* and where each goes, before the slot it precedes.
|
|
@@ -178,8 +214,9 @@ function readWords(cell) {
|
|
|
178
214
|
const words = [];
|
|
179
215
|
let bare = "";
|
|
180
216
|
let open = null;
|
|
217
|
+
const sung = inSyllables([...cell]);
|
|
181
218
|
for (const [i, ch] of [...cell].entries()) {
|
|
182
|
-
if (!QUOTES.has(ch)) {
|
|
219
|
+
if (!QUOTES.has(ch) || (sung[i] && open === null)) {
|
|
183
220
|
if (open === null)
|
|
184
221
|
bare += ch;
|
|
185
222
|
continue;
|
|
@@ -239,13 +276,27 @@ function directionWithWords(bare, meter, words) {
|
|
|
239
276
|
}
|
|
240
277
|
const ARTICULATION = { ">": "accent", "^": "hit" };
|
|
241
278
|
const PUSH = { 1: "eighth", 2: "sixteenth" };
|
|
242
|
-
|
|
279
|
+
const PEDAL = { "+": "press", "*": "release" };
|
|
280
|
+
/** A slot's leading marks (grammar 2.7–2.9): a pedal mark, a push, an articulation, then the slot. */
|
|
243
281
|
function readMarks(token) {
|
|
282
|
+
const late = /^([<>^]+)([+*])(.*)$/.exec(token);
|
|
283
|
+
if (late)
|
|
284
|
+
return {
|
|
285
|
+
problem: "a pedal mark comes before a push or an accent",
|
|
286
|
+
token,
|
|
287
|
+
suggestion: `${late[2]}${late[1]}${late[3]}`,
|
|
288
|
+
};
|
|
289
|
+
const pedal = PEDAL[token[0] ?? ""];
|
|
290
|
+
const marked = readPushAndAccent(pedal ? token.slice(1) : token, token);
|
|
291
|
+
return "problem" in marked || !pedal ? marked : { pedal, ...marked };
|
|
292
|
+
}
|
|
293
|
+
/** A push, then an articulation, then the slot itself (grammar 2.7, 2.8). */
|
|
294
|
+
function readPushAndAccent(token, written) {
|
|
244
295
|
const pushes = /^<*/.exec(token)?.[0].length ?? 0;
|
|
245
296
|
const push = PUSH[pushes];
|
|
246
297
|
if (pushes && !push)
|
|
247
|
-
return { problem: "a push is < (an eighth) or << (a sixteenth)", token };
|
|
248
|
-
const marked = readArticulation(token.slice(pushes),
|
|
298
|
+
return { problem: "a push is < (an eighth) or << (a sixteenth)", token: written };
|
|
299
|
+
const marked = readArticulation(token.slice(pushes), written);
|
|
249
300
|
return "problem" in marked ? marked : { ...(push ? { push } : {}), ...marked };
|
|
250
301
|
}
|
|
251
302
|
/** A leading `>` or `^`, and the slot after it; a push after it is written in the wrong order. */
|
|
@@ -261,15 +312,48 @@ function readArticulation(text, token) {
|
|
|
261
312
|
}
|
|
262
313
|
const UNPUSHABLE = new Set(["/", "?", "%", "...", "…"]);
|
|
263
314
|
/** Why these marks can't go on this slot; null when they can. */
|
|
315
|
+
/** Whether a slot is one of `/`, `?`, `--` or `N.C.`, which take no accent or pedal. */
|
|
316
|
+
const isPlain = (rest) => UNPUSHABLE.has(rest) || SILENCE.has(rest) || /^n\.?c\.?$/i.test(rest);
|
|
317
|
+
/** Each rule on marks: when it is broken, and what the error says. */
|
|
318
|
+
const MARK_RULES = [
|
|
319
|
+
[(m, inGroup) => Boolean(m.push) && inGroup, "a push goes on a whole slot, not inside a group"],
|
|
320
|
+
[
|
|
321
|
+
(m) => Boolean(m.push) && UNPUSHABLE.has(m.rest),
|
|
322
|
+
"a push goes on a chord, a note set, N.C. or --",
|
|
323
|
+
],
|
|
324
|
+
[
|
|
325
|
+
(m) => Boolean(m.articulation) && isPlain(m.rest),
|
|
326
|
+
"an accent or a hit goes on a chord or a note set",
|
|
327
|
+
],
|
|
328
|
+
[(m) => Boolean(m.pedal) && isPlain(m.rest), "a pedal mark goes on a chord or a note set"],
|
|
329
|
+
];
|
|
264
330
|
function marksProblem(marks, inGroup, token) {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
331
|
+
const broken = MARK_RULES.find(([breaks]) => breaks(marks, inGroup));
|
|
332
|
+
return broken ? { problem: broken[1], token } : null;
|
|
333
|
+
}
|
|
334
|
+
const NOT_A_NOTE_SET = "a syllable follows a note set, like {G4}:la";
|
|
335
|
+
/** The slot with this syllable sung on it, or why it can't be (grammar 4.3). */
|
|
336
|
+
function sungOn(slot, written) {
|
|
337
|
+
if (slot.kind === "chord" && slot.voicing)
|
|
338
|
+
return {
|
|
339
|
+
problem: `a syllable goes on a note set, not a voicing; write the notes alone (${slot.voicing.canonical}:${written})`,
|
|
340
|
+
};
|
|
341
|
+
if (slot.kind !== "chord" || slot.chord.kind !== "notes")
|
|
342
|
+
return { problem: NOT_A_NOTE_SET };
|
|
343
|
+
if (written.includes("{"))
|
|
344
|
+
return { problem: "a syllable ends at {; put a space before the next note" };
|
|
345
|
+
const syllable = readSyllable(written);
|
|
346
|
+
if (syllable)
|
|
347
|
+
return { ...slot, syllable };
|
|
348
|
+
return { problem: unreadSyllable(written) };
|
|
349
|
+
}
|
|
350
|
+
/** Why a syllable token reads as no syllable. */
|
|
351
|
+
function unreadSyllable(written) {
|
|
352
|
+
if (written === "/-")
|
|
353
|
+
return "a hold can't begin or continue a word; write :/ alone";
|
|
354
|
+
return written.includes("~")
|
|
355
|
+
? "~ joins two syllables; write one on each side"
|
|
356
|
+
: "an empty syllable; write one after the colon, or leave the note unsung";
|
|
273
357
|
}
|
|
274
358
|
/** Whether a voicing's note is one of the chord's, by pitch class. */
|
|
275
359
|
const inChord = (note, chord) => {
|
|
@@ -433,22 +517,50 @@ export function parseBarLine(text, line) {
|
|
|
433
517
|
if (problem)
|
|
434
518
|
return report(problem);
|
|
435
519
|
const base = simple(marks.rest);
|
|
436
|
-
const { push, articulation } = marks;
|
|
520
|
+
const { pedal, push, articulation } = marks;
|
|
437
521
|
return (base &&
|
|
438
522
|
{
|
|
439
523
|
...base,
|
|
524
|
+
...(pedal ? { pedal } : {}),
|
|
440
525
|
...(push ? { push } : {}),
|
|
441
526
|
...(articulation ? { articulation } : {}),
|
|
442
527
|
});
|
|
443
528
|
};
|
|
529
|
+
/** A group member, dotted when it ends in a dot that is not part of `N.C.` (grammar 2.2). */
|
|
530
|
+
const memberOf = (m) => {
|
|
531
|
+
if (!isDotted(m))
|
|
532
|
+
return markedSlot(m, true);
|
|
533
|
+
const s = markedSlot(m.slice(0, -1), true);
|
|
534
|
+
return s && { ...s, dotted: true };
|
|
535
|
+
};
|
|
536
|
+
/** A slot read by `read`, with the syllable written after it, if any (grammar 4.3). */
|
|
537
|
+
const withSyllable = ({ note, syllable }, read) => {
|
|
538
|
+
const written = `${note}:${syllable}`;
|
|
539
|
+
if (syllable !== null && !note)
|
|
540
|
+
return error(NOT_A_NOTE_SET, written);
|
|
541
|
+
const slot = read(note);
|
|
542
|
+
if (syllable === null || !slot)
|
|
543
|
+
return slot;
|
|
544
|
+
const sung = sungOn(slot, syllable);
|
|
545
|
+
return "problem" in sung ? error(sung.problem, written) : sung;
|
|
546
|
+
};
|
|
444
547
|
/** One slot token: a simple slot, or a `_` group of them. */
|
|
445
548
|
const slotOf = (token) => {
|
|
446
|
-
const members = groupMembers(token);
|
|
447
|
-
|
|
448
|
-
|
|
549
|
+
const members = groupMembers(token).map(splitSyllable);
|
|
550
|
+
const dots = members.filter((m) => isDotted(m.note)).length;
|
|
551
|
+
if (dots && (members.length !== 2 || dots > 1))
|
|
552
|
+
return error(DOT_PLACE, token);
|
|
553
|
+
const [only] = members;
|
|
554
|
+
if (only && members.length === 1)
|
|
555
|
+
return withSyllable(only, (n) => markedSlot(n, false));
|
|
556
|
+
return groupOf(members, token);
|
|
557
|
+
};
|
|
558
|
+
const groupOf = (members, token) => {
|
|
449
559
|
const out = [];
|
|
450
560
|
for (const m of members) {
|
|
451
|
-
const s = m
|
|
561
|
+
const s = m.note || m.syllable !== null
|
|
562
|
+
? withSyllable(m, memberOf)
|
|
563
|
+
: error("an empty member in a group", token);
|
|
452
564
|
if (s)
|
|
453
565
|
out.push(s);
|
|
454
566
|
}
|
|
@@ -465,7 +577,7 @@ export function parseBarLine(text, line) {
|
|
|
465
577
|
if ("problem" in read)
|
|
466
578
|
return report(read);
|
|
467
579
|
const { bare, words } = read;
|
|
468
|
-
if (bare.includes("["))
|
|
580
|
+
if (outsideSyllables(bare).includes("["))
|
|
469
581
|
return error("a [n/d] meter must start its cell", rest);
|
|
470
582
|
const alone = standalone(bare, meter, words);
|
|
471
583
|
if (alone)
|
package/dist/chart/credits.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { ChartDiagnostic, CreditRole, Credits, Line } from "./types.js";
|
|
|
3
3
|
export declare const CREDIT_ROLES: readonly CreditRole[];
|
|
4
4
|
/** A credit line, or null when the line isn't one (grammar 7.5). */
|
|
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
|
|
6
|
+
/** A text line that reads like a credit under another name: `author: X` (not a lyric row, 7.7). */
|
|
7
7
|
export declare function nearCredit(text: string, line: number): ChartDiagnostic | null;
|
|
8
8
|
/** Every credit line's text, by role, in written order. */
|
|
9
9
|
export declare function creditsOf(lines: Line[]): Credits;
|
package/dist/chart/credits.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DIRECTIVE_AFTER } from "./directives.js";
|
|
2
|
+
import { LYRIC_ROW } from "./lyricRows.js";
|
|
2
3
|
/** The credit roles, in the order MusicXML writes them (grammar 7.5). */
|
|
3
4
|
export const CREDIT_ROLES = [
|
|
4
5
|
"composer",
|
|
@@ -38,8 +39,11 @@ export function readCredit(text, line, diagnostics) {
|
|
|
38
39
|
});
|
|
39
40
|
return { kind: "credit", line, role, text: value };
|
|
40
41
|
}
|
|
41
|
-
/** A text line that reads like a credit under another name: `author: X
|
|
42
|
+
/** A text line that reads like a credit under another name: `author: X` (not a lyric row, 7.7). */
|
|
42
43
|
export function nearCredit(text, line) {
|
|
44
|
+
// `lyrics:` then a bar line is a lyric row (7.7); escaped, it is text, and no near miss.
|
|
45
|
+
if (LYRIC_ROW.test(text))
|
|
46
|
+
return null;
|
|
43
47
|
const m = /^([^\s:]+)\s*:\s*(.*)$/.exec(text);
|
|
44
48
|
const role = m?.[1] ? NEAR_CREDITS[m[1].toLowerCase()] : undefined;
|
|
45
49
|
if (!m || !role)
|
package/dist/chart/document.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { ChartDiagnostic, Credits,
|
|
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
7
|
credits: Credits;
|
|
8
8
|
lines: Line[];
|
|
9
9
|
diagnostics: ChartDiagnostic[];
|