barmark 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -9,6 +9,25 @@ Releases follow the process in [RELEASING.md](RELEASING.md).
9
9
 
10
10
  ## [Unreleased]
11
11
 
12
+ ## [0.5.0] - 2026-11-01
13
+
14
+ Charts can say where the tempo slows down or speeds up. A grammar
15
+ decision (§7.2); no chart that read before changes meaning. Implements the
16
+ [grammar v0.1 draft](https://github.com/kevinpeckham/barmark/blob/main/docs/grammar-v0.1-draft.md).
17
+
18
+ ### Added
19
+
20
+ - Gradual tempo changes (grammar §7.2). `tempo:` also takes `rit.`,
21
+ `accel.`, either one `to` a tempo (`tempo: rit. to 90`), and
22
+ `a tempo`; `rall.`, `ritardando`, `rallentando` and `accelerando`
23
+ read too. A change runs from the next bar to the next `tempo:` or the
24
+ end of the chart. Each played bar inside one has `tempoChange`
25
+ (`{ kind, from, to }`), so a host knows the beat is not steady there;
26
+ `tempo` stays the steady tempo. The printer writes `rit.`, `accel.`
27
+ and `a tempo`.
28
+ - Two warnings: `a tempo` with no change in force, and `rit. to` a
29
+ tempo that isn't slower (or `accel. to` one that isn't faster).
30
+
12
31
  ## [0.4.0] - 2026-11-01
13
32
 
14
33
  Charts written in Logic Pro's chord spelling read as they are. A grammar
@@ -99,7 +118,8 @@ The first working release: the reference parser and printer for the
99
118
 
100
119
  - **A placeholder package that holds the `barmark` name** while the spec and parser are written.
101
120
 
102
- [Unreleased]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.4.0...HEAD
121
+ [Unreleased]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.5.0...HEAD
122
+ [0.5.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.4.0...barmark-v0.5.0
103
123
  [0.4.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.3.0...barmark-v0.4.0
104
124
  [0.3.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.2.0...barmark-v0.3.0
105
125
  [0.2.0]: https://github.com/kevinpeckham/barmark/compare/v0.1.0...barmark-v0.2.0
@@ -43,6 +43,18 @@ function parseTempo(text) {
43
43
  const n = m ? Number(m[1]) : 0;
44
44
  return n >= 1 && n <= 999 ? n : null;
45
45
  }
46
+ const CHANGE = /^(?:(rit|rall|ritardando|rallentando)|accel|accelerando)\.?(?:\s+to\s+(.+))?$/i;
47
+ /** `rit.`, `accel.` (and their long and `rall.` spellings), optionally `to` a tempo; or `a tempo`. */
48
+ function parseTempoChange(text) {
49
+ if (/^a\s+tempo$/i.test(text))
50
+ return { kind: "a tempo" };
51
+ const m = CHANGE.exec(text);
52
+ if (!m)
53
+ return null;
54
+ const kind = m[1] ? "rit" : "accel";
55
+ const to = m[2] === undefined ? null : parseTempo(m[2]);
56
+ return m[2] !== undefined && to === null ? null : { kind, to };
57
+ }
46
58
  function parseFeel(text) {
47
59
  const lower = text.toLowerCase();
48
60
  return FEELS.find((f) => f === lower) ?? null;
@@ -91,10 +103,13 @@ export function parseDirectiveLine(text, line) {
91
103
  }
92
104
  else if (name === "tempo") {
93
105
  const tempo = parseTempo(value);
106
+ const change = tempo ? null : parseTempoChange(value);
94
107
  if (tempo)
95
108
  set.tempo = tempo;
109
+ else if (change)
110
+ set.tempoChange = change;
96
111
  else
97
- error("tempo must be beats per minute, from 1 to 999", value);
112
+ error("tempo must be beats per minute (1 to 999), rit., accel. or a tempo", value);
98
113
  }
99
114
  else {
100
115
  const feel = parseFeel(value);
@@ -111,15 +111,41 @@ export function expand(lines) {
111
111
  key: null,
112
112
  time: { n: 4, d: 4 },
113
113
  tempo: null,
114
+ change: null,
114
115
  feel: "straight",
115
116
  };
116
- const apply = (set) => {
117
+ const warned = new Set();
118
+ const warn = (line, message, token) => {
119
+ if (warned.has(line))
120
+ return;
121
+ warned.add(line);
122
+ diagnostics.push({ line, severity: "warning", message, token });
123
+ };
124
+ /** A rit. or accel. runs from the next bar to the next `tempo:`; `a tempo` ends it. */
125
+ const changeTempo = (c, line) => {
126
+ if (c.kind === "a tempo") {
127
+ if (!state.change)
128
+ warn(line, "a tempo, but no rit. or accel. is in force", "a tempo");
129
+ state.change = null;
130
+ return;
131
+ }
132
+ const from = state.tempo;
133
+ const wrongWay = c.kind === "rit" ? (to, f) => to >= f : (to, f) => to <= f;
134
+ if (c.to !== null && from !== null && wrongWay(c.to, from))
135
+ warn(line, `${c.kind}. to ${c.to} is not ${c.kind === "rit" ? "slower" : "faster"} than ${from}`, `${c.kind}. to ${c.to}`);
136
+ state.change = { kind: c.kind, from, to: c.to };
137
+ };
138
+ const apply = (set, line) => {
117
139
  if (set.key)
118
140
  state.key = set.key;
119
141
  if (set.time)
120
142
  state.time = set.time;
121
- if (set.tempo)
143
+ if (set.tempo) {
122
144
  state.tempo = set.tempo;
145
+ state.change = null;
146
+ }
147
+ if (set.tempoChange)
148
+ changeTempo(set.tempoChange, line);
123
149
  if (set.feel)
124
150
  state.feel = set.feel;
125
151
  };
@@ -159,7 +185,7 @@ export function expand(lines) {
159
185
  token: `${k}`,
160
186
  });
161
187
  }
162
- const { key, tempo, feel } = state;
188
+ const { key, tempo, change: tempoChange, feel } = state;
163
189
  out.push({
164
190
  kind: "bar",
165
191
  bar: {
@@ -169,6 +195,7 @@ export function expand(lines) {
169
195
  meter,
170
196
  key,
171
197
  tempo,
198
+ tempoChange,
172
199
  feel,
173
200
  slots: p.slots,
174
201
  },
@@ -199,7 +226,7 @@ export function expand(lines) {
199
226
  };
200
227
  const playLine = ({ line: l, repeat }, out) => {
201
228
  if (l.kind === "directive")
202
- apply(l.set);
229
+ apply(l.set, l.line);
203
230
  if (l.kind !== "bars")
204
231
  return;
205
232
  times(repeat, l.line, out, (into) => {
@@ -63,6 +63,11 @@ function printKey(k) {
63
63
  return `${k.tonic}m`;
64
64
  return `${k.tonic} ${k.mode}`;
65
65
  }
66
+ function printTempoChange(c) {
67
+ if (c.kind === "a tempo")
68
+ return "a tempo";
69
+ return `${c.kind}.${c.to === null ? "" : ` to ${c.to}`}`;
70
+ }
66
71
  function printDirectives(d) {
67
72
  const parts = [];
68
73
  if (d.key)
@@ -71,6 +76,8 @@ function printDirectives(d) {
71
76
  parts.push(`time: ${d.time.n}/${d.time.d}`);
72
77
  if (d.tempo !== undefined)
73
78
  parts.push(`tempo: ${d.tempo}`);
79
+ if (d.tempoChange)
80
+ parts.push(`tempo: ${printTempoChange(d.tempoChange)}`);
74
81
  if (d.feel)
75
82
  parts.push(`feel: ${d.feel}`);
76
83
  return parts.join(", ");
@@ -18,10 +18,19 @@ export type Key = {
18
18
  mode: Mode;
19
19
  };
20
20
  export type Feel = "straight" | "swing" | "shuffle" | "swing 16";
21
+ /** A gradual change of tempo (rit., accel.) to an optional target, or the return from one (a tempo). */
22
+ export type TempoChange = {
23
+ kind: "rit" | "accel";
24
+ to: number | null;
25
+ } | {
26
+ kind: "a tempo";
27
+ };
28
+ /** `tempo:` gives either `tempo` (a steady tempo) or `tempoChange`, never both. */
21
29
  export type Directives = {
22
30
  key?: Key;
23
31
  time?: Meter;
24
32
  tempo?: number;
33
+ tempoChange?: TempoChange;
25
34
  feel?: Feel;
26
35
  };
27
36
  /** A chord slot holds a chord symbol or a note set; `chord.kind` tells which. */
@@ -92,7 +101,14 @@ export type PlayedBar = {
92
101
  section: string | null;
93
102
  meter: Meter;
94
103
  key: Key | null;
104
+ /** The steady tempo: where a change starts from, and what `a tempo` returns to. */
95
105
  tempo: number | null;
106
+ /** Set on every bar inside a rit. or accel.; `from` is the steady tempo, `to` the target if written. */
107
+ tempoChange: {
108
+ kind: "rit" | "accel";
109
+ from: number | null;
110
+ to: number | null;
111
+ } | null;
96
112
  feel: Feel;
97
113
  /** `%` resolved to the copied slots; holds stay holds. */
98
114
  slots: Slot[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "barmark",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Markdown-inspired plain-text notation for chord charts: a parser, a canonical printer and Harte-label conversion.",
5
5
  "type": "module",
6
6
  "exports": {