@dsebastien/music-notation 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/README.md +1 -0
- package/dist/blocks/renderers.d.ts +6 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1486 -965
- package/dist/index.js.map +24 -22
- package/dist/music-notation.css +7 -0
- package/dist/music-notation.publish.min.js +37 -26
- package/dist/music-notation.tab.min.js +14 -7
- package/dist/playback/live-volume.d.ts +14 -0
- package/dist/playback/player.d.ts +2 -0
- package/dist/publish/auto.d.ts +3 -0
- package/dist/publish/index.js +1468 -965
- package/dist/publish/index.js.map +24 -22
- package/dist/render/dom.d.ts +0 -1
- package/dist/tab/index.js +1646 -1238
- package/dist/tab/index.js.map +8 -7
- package/dist/theory/naming.d.ts +64 -0
- package/dist/voicings/index.js +1211 -751
- package/dist/voicings/index.js.map +8 -6
- package/package.json +1 -1
package/dist/tab/index.js
CHANGED
|
@@ -1,99 +1,3 @@
|
|
|
1
|
-
// src/render/dom.ts
|
|
2
|
-
var SVG_NS = "http://www.w3.org/2000/svg";
|
|
3
|
-
var apply = (el, attrs) => {
|
|
4
|
-
for (const [name, value] of Object.entries(attrs)) {
|
|
5
|
-
if (value !== undefined)
|
|
6
|
-
el.setAttribute(name, String(value));
|
|
7
|
-
}
|
|
8
|
-
};
|
|
9
|
-
function svg(doc, tag, attrs = {}, children = []) {
|
|
10
|
-
const el = doc.createElementNS(SVG_NS, tag);
|
|
11
|
-
apply(el, attrs);
|
|
12
|
-
for (const child of children)
|
|
13
|
-
if (child)
|
|
14
|
-
el.appendChild(child);
|
|
15
|
-
return el;
|
|
16
|
-
}
|
|
17
|
-
function svgText(doc, text, attrs = {}) {
|
|
18
|
-
const el = svg(doc, "text", attrs);
|
|
19
|
-
el.textContent = text;
|
|
20
|
-
return el;
|
|
21
|
-
}
|
|
22
|
-
function svgLabel(doc, text, [x, y], cls, anchor = "middle") {
|
|
23
|
-
return svgText(doc, text, { class: cls, x, y: y + 4, "text-anchor": anchor });
|
|
24
|
-
}
|
|
25
|
-
function dotLabel(doc, text, point, r) {
|
|
26
|
-
const label = svgLabel(doc, text, point, "mn-dot-text");
|
|
27
|
-
if ([...text].length >= 3) {
|
|
28
|
-
label.classList.add("mn-dot-text-long");
|
|
29
|
-
label.setAttribute("textLength", String(2 * r - 2));
|
|
30
|
-
label.setAttribute("lengthAdjust", "spacingAndGlyphs");
|
|
31
|
-
}
|
|
32
|
-
return label;
|
|
33
|
-
}
|
|
34
|
-
function svgLine(doc, [x1, y1], [x2, y2], cls) {
|
|
35
|
-
return svg(doc, "line", { class: cls, x1, y1, x2, y2 });
|
|
36
|
-
}
|
|
37
|
-
function html(doc, tag, cls, text) {
|
|
38
|
-
const el = doc.createElement(tag);
|
|
39
|
-
if (cls)
|
|
40
|
-
el.className = cls;
|
|
41
|
-
if (text !== undefined)
|
|
42
|
-
el.textContent = text;
|
|
43
|
-
return el;
|
|
44
|
-
}
|
|
45
|
-
var NAME_PREFIX = `mn-name-${Math.random().toString(36).slice(2, 8)}-`;
|
|
46
|
-
var names = 0;
|
|
47
|
-
var uniqueId = () => `${NAME_PREFIX}${++names}`;
|
|
48
|
-
function svgRoot(doc, width, height, cls, label) {
|
|
49
|
-
const id = `${NAME_PREFIX}${++names}`;
|
|
50
|
-
const title = svg(doc, "title", { class: "mn-name", id });
|
|
51
|
-
title.textContent = label;
|
|
52
|
-
return svg(doc, "svg", {
|
|
53
|
-
xmlns: SVG_NS,
|
|
54
|
-
viewBox: `0 0 ${width} ${height}`,
|
|
55
|
-
width,
|
|
56
|
-
class: `mn-svg ${cls}`,
|
|
57
|
-
role: "img",
|
|
58
|
-
"aria-labelledby": id
|
|
59
|
-
}, [svg(doc, "defs", {}, [title])]);
|
|
60
|
-
}
|
|
61
|
-
var nameElement = (el) => {
|
|
62
|
-
const id = el.getAttribute("aria-labelledby");
|
|
63
|
-
if (!id)
|
|
64
|
-
return null;
|
|
65
|
-
for (const candidate of el.querySelectorAll("[id]")) {
|
|
66
|
-
if (candidate.getAttribute("id") === id)
|
|
67
|
-
return candidate;
|
|
68
|
-
}
|
|
69
|
-
return el.ownerDocument.getElementById(id);
|
|
70
|
-
};
|
|
71
|
-
function accessibleName(el) {
|
|
72
|
-
const named = nameElement(el);
|
|
73
|
-
if (named)
|
|
74
|
-
return named.textContent;
|
|
75
|
-
return el.getAttribute("aria-label");
|
|
76
|
-
}
|
|
77
|
-
function setAccessibleName(el, name) {
|
|
78
|
-
const named = nameElement(el);
|
|
79
|
-
if (named)
|
|
80
|
-
named.textContent = name;
|
|
81
|
-
else
|
|
82
|
-
el.setAttribute("aria-label", name);
|
|
83
|
-
}
|
|
84
|
-
function playableMark(doc, area, ...children) {
|
|
85
|
-
const hit = svg(doc, "rect", {
|
|
86
|
-
class: "mn-hit",
|
|
87
|
-
x: area.x,
|
|
88
|
-
y: area.y,
|
|
89
|
-
width: area.width,
|
|
90
|
-
height: area.height,
|
|
91
|
-
fill: "transparent",
|
|
92
|
-
"pointer-events": "all"
|
|
93
|
-
});
|
|
94
|
-
return svg(doc, "g", { class: "mn-mark" }, [hit, ...children]);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
1
|
// src/theory/pitch.ts
|
|
98
2
|
var SHARP_NAMES = [
|
|
99
3
|
"C",
|
|
@@ -141,1240 +45,1730 @@ function splitChordSymbol(symbol) {
|
|
|
141
45
|
var noteOf = (midi, preferFlats = false) => `${nameOf(midi, preferFlats)}${Math.floor(midi / 12) - 1}`;
|
|
142
46
|
var isFlat = (name) => /^[A-Ga-g][b♭]/.test(name.trim());
|
|
143
47
|
|
|
144
|
-
// src/
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
"
|
|
150
|
-
"
|
|
151
|
-
"
|
|
152
|
-
|
|
153
|
-
"
|
|
154
|
-
"
|
|
155
|
-
"
|
|
156
|
-
"
|
|
157
|
-
"
|
|
158
|
-
"
|
|
159
|
-
"
|
|
160
|
-
"
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
48
|
+
// src/theory/note-set.ts
|
|
49
|
+
import { Chord, Interval, Scale as Scale2 } from "tonal";
|
|
50
|
+
|
|
51
|
+
// src/theory/suffix.ts
|
|
52
|
+
var CANONICAL = new Map([
|
|
53
|
+
["M", ""],
|
|
54
|
+
["maj", ""],
|
|
55
|
+
["min", "m"],
|
|
56
|
+
["-", "m"],
|
|
57
|
+
["M7", "maj7"],
|
|
58
|
+
["Δ", "maj7"],
|
|
59
|
+
["Δ7", "maj7"],
|
|
60
|
+
["M9", "maj9"],
|
|
61
|
+
["Δ9", "maj9"],
|
|
62
|
+
["min6", "m6"],
|
|
63
|
+
["-6", "m6"],
|
|
64
|
+
["min7", "m7"],
|
|
65
|
+
["-7", "m7"],
|
|
66
|
+
["min9", "m9"],
|
|
67
|
+
["-9", "m9"],
|
|
68
|
+
["ø", "m7b5"],
|
|
69
|
+
["ø7", "m7b5"],
|
|
70
|
+
["m7-5", "m7b5"],
|
|
71
|
+
["mmaj7", "mMaj7"],
|
|
72
|
+
["mM7", "mMaj7"],
|
|
73
|
+
["m(maj7)", "mMaj7"],
|
|
74
|
+
["-(maj7)", "mMaj7"],
|
|
75
|
+
["°", "dim"],
|
|
76
|
+
["°7", "dim7"],
|
|
77
|
+
["+", "aug"],
|
|
78
|
+
["sus", "sus4"],
|
|
79
|
+
["add2", "add9"],
|
|
80
|
+
["69", "6/9"],
|
|
81
|
+
["alt", "7alt"],
|
|
82
|
+
["-5", "Mb5"],
|
|
83
|
+
["#5", "aug"],
|
|
84
|
+
["b5", "Mb5"],
|
|
85
|
+
["maj7b5", "M7b5"],
|
|
86
|
+
["mmaj9", "mMaj9"],
|
|
87
|
+
["m6/9", "m69"],
|
|
88
|
+
["m6add9", "m69"],
|
|
89
|
+
["sus2sus4", "sus24"]
|
|
90
|
+
]);
|
|
91
|
+
function withoutParentheses(suffix) {
|
|
92
|
+
if (!/[(),]/.test(suffix))
|
|
93
|
+
return suffix;
|
|
94
|
+
if (!/^[^(),]*(?:\([^(),]+(?:,[^(),]+)*\)[^(),]*)+$/.test(suffix))
|
|
176
95
|
return null;
|
|
177
|
-
|
|
178
|
-
for (const name of names) {
|
|
179
|
-
const chroma = chromaOf(name);
|
|
180
|
-
if (chroma === null)
|
|
181
|
-
return null;
|
|
182
|
-
const previous = midis[midis.length - 1];
|
|
183
|
-
if (previous === undefined) {
|
|
184
|
-
const candidates = [28, 40, 52].map((c) => c - c % 12 + chroma);
|
|
185
|
-
midis.push(candidates.reduce((a, b) => Math.abs(b - 40) < Math.abs(a - 40) ? b : a));
|
|
186
|
-
} else {
|
|
187
|
-
let midi = previous - previous % 12 + chroma;
|
|
188
|
-
while (midi <= previous)
|
|
189
|
-
midi += 12;
|
|
190
|
-
midis.push(midi);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
return midis;
|
|
96
|
+
return suffix.replace(/[(),\s]/g, "");
|
|
194
97
|
}
|
|
195
|
-
function
|
|
196
|
-
const
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
if (
|
|
201
|
-
return
|
|
202
|
-
|
|
203
|
-
const names = spaced.length > 1 ? spaced : trimmed.match(/[A-G][#♯b♭]?|[a-g][#♯♭]?/g) ?? [];
|
|
204
|
-
return names.map((n) => {
|
|
205
|
-
const letter = n.charAt(0).toUpperCase();
|
|
206
|
-
const accidental = n.slice(1).replace(/-?\d+$/, "").replace("♯", "#").replace("♭", "b");
|
|
207
|
-
return letter + accidental;
|
|
208
|
-
});
|
|
98
|
+
function canonicalSuffix(suffix) {
|
|
99
|
+
const direct = CANONICAL.get(suffix);
|
|
100
|
+
if (direct !== undefined)
|
|
101
|
+
return direct;
|
|
102
|
+
const flat = withoutParentheses(suffix);
|
|
103
|
+
if (flat === null || flat === suffix)
|
|
104
|
+
return suffix;
|
|
105
|
+
return CANONICAL.get(flat) ?? flat;
|
|
209
106
|
}
|
|
210
107
|
|
|
211
|
-
// src/
|
|
212
|
-
|
|
213
|
-
var
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
"
|
|
218
|
-
"
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
108
|
+
// src/theory/scales.ts
|
|
109
|
+
import { Note, Scale } from "tonal";
|
|
110
|
+
var ALIASES = new Map([
|
|
111
|
+
["natural minor", "minor"],
|
|
112
|
+
["blues", "minor blues"],
|
|
113
|
+
["whole-tone", "whole tone"],
|
|
114
|
+
["pentatonic major", "major pentatonic"],
|
|
115
|
+
["pentatonic minor", "minor pentatonic"]
|
|
116
|
+
]);
|
|
117
|
+
function scaleName(text) {
|
|
118
|
+
const m = /^\s*([A-Ga-g](?:#|b|♯|♭)?)\s+(.+?)\s*$/.exec(text);
|
|
119
|
+
const [tonic, type] = m ? [m[1], m[2]] : ["", text.trim()];
|
|
120
|
+
const lower = type.toLowerCase().replace(/\s+/g, " ");
|
|
121
|
+
const name = ALIASES.get(lower) ?? lower;
|
|
122
|
+
return tonic ? `${tonic[0].toUpperCase()}${tonic.slice(1).replace("♯", "#").replace("♭", "b")} ${name}` : name;
|
|
123
|
+
}
|
|
124
|
+
var isScaleWithoutRoot = (text) => {
|
|
125
|
+
const scale = Scale.get(scaleName(text));
|
|
126
|
+
return !scale.empty && !scale.tonic;
|
|
127
|
+
};
|
|
128
|
+
var CHARACTERISTIC = {
|
|
129
|
+
lydian: ["4A"],
|
|
130
|
+
dorian: ["6M"],
|
|
131
|
+
mixolydian: ["7m"],
|
|
132
|
+
phrygian: ["2m"],
|
|
133
|
+
locrian: ["5d"],
|
|
134
|
+
minor: ["6m"],
|
|
135
|
+
"minor blues": ["5d"],
|
|
136
|
+
"major blues": ["3m"],
|
|
137
|
+
"harmonic minor": ["7M"],
|
|
138
|
+
"melodic minor": ["6M", "7M"],
|
|
139
|
+
"phrygian dominant": ["2m", "3M"]
|
|
140
|
+
};
|
|
141
|
+
var MODE_WORDS = /\b(dorian|phrygian|lydian|mixolydian|aeolian|locrian|blues)\b/i;
|
|
142
|
+
var characteristicIntervals = (type) => CHARACTERISTIC[type] ?? [];
|
|
143
|
+
var marksByDefault = (written) => MODE_WORDS.test(written);
|
|
144
|
+
function modesOf(text) {
|
|
145
|
+
const scale = Scale.get(scaleName(text));
|
|
146
|
+
if (scale.empty || !scale.tonic)
|
|
147
|
+
return null;
|
|
148
|
+
const modes = Scale.modeNames(scale.name);
|
|
149
|
+
if (new Set(modes.map(([, mode]) => mode)).size < 2)
|
|
150
|
+
return null;
|
|
151
|
+
return modes.map(([tonic, mode]) => `${tonic} ${mode}`);
|
|
152
|
+
}
|
|
153
|
+
var DOUBLE_ACCIDENTAL = /^[A-G](##|bb)/;
|
|
154
|
+
var SUPERLOCRIAN = ["1P", "2m", "3m", "4d", "5d", "6m", "7m"];
|
|
155
|
+
function scaleSpelling(scale) {
|
|
156
|
+
const hasDouble = (notes) => notes.some((n) => DOUBLE_ACCIDENTAL.test(n));
|
|
157
|
+
if (!hasDouble(scale.notes))
|
|
158
|
+
return { notes: scale.notes, intervals: scale.intervals };
|
|
159
|
+
if (scale.type === "altered" && scale.tonic) {
|
|
160
|
+
const notes = SUPERLOCRIAN.map((interval) => Note.transpose(scale.tonic, interval));
|
|
161
|
+
if (!hasDouble(notes))
|
|
162
|
+
return { notes, intervals: SUPERLOCRIAN };
|
|
265
163
|
}
|
|
164
|
+
return { notes: scale.notes, intervals: scale.intervals };
|
|
266
165
|
}
|
|
267
|
-
var
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
function
|
|
271
|
-
const
|
|
272
|
-
if (
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
if (
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
166
|
+
var scaleTypes = () => Scale.names();
|
|
167
|
+
|
|
168
|
+
// src/theory/note-set.ts
|
|
169
|
+
function markClasses(set, chroma, marks = {}) {
|
|
170
|
+
const classes = [];
|
|
171
|
+
if (set.root === chroma)
|
|
172
|
+
classes.push("mn-root");
|
|
173
|
+
else if (marks.characteristic?.has(chroma))
|
|
174
|
+
classes.push("mn-char");
|
|
175
|
+
if (marks.different?.has(chroma))
|
|
176
|
+
classes.push("mn-diff");
|
|
177
|
+
if (marks.chordTones)
|
|
178
|
+
classes.push(marks.chordTones.has(chroma) ? "mn-tone" : "mn-passing");
|
|
179
|
+
return classes.length ? ` ${classes.join(" ")}` : "";
|
|
280
180
|
}
|
|
281
|
-
function
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
const
|
|
285
|
-
const
|
|
286
|
-
|
|
287
|
-
string = { name: m[1] ?? null, body, offset: m[0].length, barred: /[|:]$/.test(m[0]) };
|
|
288
|
-
let drum = null;
|
|
289
|
-
const d = DRUM_LINE.exec(line);
|
|
290
|
-
const name = d ? d[1].toLowerCase().replace(/[ .-]/g, "") : "";
|
|
291
|
-
const known = DRUM_NAMES.get(name);
|
|
292
|
-
if (d && known && (d[2].match(/[^\s|:]/g)?.length ?? 0) >= 4)
|
|
293
|
-
drum = { drum: known, name, body: d[2], lettered: /^[A-Ga-g]$/.test(d[1]) };
|
|
294
|
-
return string || drum ? { string, drum, text } : null;
|
|
181
|
+
function describeMarks(set, marks = {}) {
|
|
182
|
+
const names = (chromas) => set.members.filter((m) => chromas?.has(m.chroma)).map((m) => m.name);
|
|
183
|
+
const characteristic = names(marks.characteristic);
|
|
184
|
+
const different = names(marks.different);
|
|
185
|
+
const tones = names(marks.chordTones);
|
|
186
|
+
return (characteristic.length ? `, characteristic notes: ${characteristic.join(" ")}` : "") + (different.length ? `, different from the compared scale: ${different.join(" ")}` : "") + (tones.length ? `, chord tones: ${tones.join(" ")}` : "");
|
|
295
187
|
}
|
|
296
|
-
var
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
188
|
+
var memberFor = (set, chroma) => set.members.find((m) => m.chroma === chroma);
|
|
189
|
+
var memberOf = (set, midi) => set.pitches && !set.pitches.includes(midi) ? undefined : memberFor(set, (midi % 12 + 12) % 12);
|
|
190
|
+
function intervalLabel(interval) {
|
|
191
|
+
const m = /^(\d+)([PMmdA]+)$/.exec(interval);
|
|
192
|
+
if (!m)
|
|
193
|
+
return interval;
|
|
194
|
+
const [, number, quality] = m;
|
|
195
|
+
if (number === "1" && quality === "P")
|
|
196
|
+
return "R";
|
|
197
|
+
const perfect = ["1", "4", "5", "8", "11", "12"].includes(String((Number(number) - 1) % 7 + 1));
|
|
198
|
+
if (quality === "P" || quality === "M")
|
|
199
|
+
return number;
|
|
200
|
+
if (quality === "m")
|
|
201
|
+
return `b${number}`;
|
|
202
|
+
if (quality.startsWith("A"))
|
|
203
|
+
return `${"#".repeat(quality.length)}${number}`;
|
|
204
|
+
return `${"b".repeat(quality.length + (perfect ? 0 : 1))}${number}`;
|
|
205
|
+
}
|
|
206
|
+
function labelOf(member, label, finger) {
|
|
207
|
+
switch (label) {
|
|
208
|
+
case "none":
|
|
209
|
+
return "";
|
|
210
|
+
case "degrees":
|
|
211
|
+
return member.degree === null ? member.name : String(member.degree);
|
|
212
|
+
case "intervals":
|
|
213
|
+
return member.interval === null ? member.name : intervalLabel(member.interval);
|
|
214
|
+
case "fingers":
|
|
215
|
+
return finger ?? "";
|
|
216
|
+
default:
|
|
217
|
+
return member.name;
|
|
308
218
|
}
|
|
309
|
-
out.push(run.slice(start));
|
|
310
|
-
return out;
|
|
311
219
|
}
|
|
312
|
-
|
|
313
|
-
const
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
if (
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
220
|
+
var fromNames = (title, names, intervals, chord = false) => {
|
|
221
|
+
const members = [];
|
|
222
|
+
names.forEach((name, i) => {
|
|
223
|
+
const chroma = chromaOf(name);
|
|
224
|
+
if (chroma === null || members.some((m) => m.chroma === chroma))
|
|
225
|
+
return;
|
|
226
|
+
members.push({
|
|
227
|
+
chroma,
|
|
228
|
+
name,
|
|
229
|
+
degree: intervals ? chord ? Number(/^\d+/.exec(intervals[i] ?? "")?.[0] ?? i + 1) : i + 1 : null,
|
|
230
|
+
interval: intervals?.[i] ?? null
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
if (!members.length)
|
|
234
|
+
return null;
|
|
235
|
+
return {
|
|
236
|
+
title,
|
|
237
|
+
members,
|
|
238
|
+
root: intervals ? members[0].chroma : null,
|
|
239
|
+
pitches: null,
|
|
240
|
+
preferFlats: names.some(isFlat)
|
|
241
|
+
};
|
|
242
|
+
};
|
|
243
|
+
function chordNoteSet(symbol) {
|
|
244
|
+
const parts = splitChordSymbol(symbol);
|
|
245
|
+
if (!parts)
|
|
246
|
+
return null;
|
|
247
|
+
const chord = Chord.getChord(canonicalSuffix(parts.suffix), parts.root);
|
|
248
|
+
if (chord.empty)
|
|
249
|
+
return null;
|
|
250
|
+
const bass = parts.bass;
|
|
251
|
+
const set = fromNames(symbol.trim(), chord.notes, chord.intervals, true);
|
|
252
|
+
const bassChroma = bass ? chromaOf(bass) : null;
|
|
253
|
+
if (set && bass && bassChroma !== null && !memberFor(set, bassChroma)) {
|
|
254
|
+
set.members.push({ chroma: bassChroma, name: bass, degree: null, interval: null });
|
|
321
255
|
}
|
|
322
|
-
|
|
323
|
-
return out;
|
|
256
|
+
return set;
|
|
324
257
|
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
for (let i = 0;i < line.length; i++) {
|
|
332
|
-
const c = line[i];
|
|
333
|
-
const mark = (c === "P" || c === "p") && /^\.?[Mm]/.test(line.slice(i + 1, i + 3));
|
|
334
|
-
if (mark)
|
|
335
|
-
ranges.push([i, i]);
|
|
336
|
-
else if (c !== " " && ranges.length)
|
|
337
|
-
ranges[ranges.length - 1][1] = i;
|
|
258
|
+
function respell(set, chord) {
|
|
259
|
+
set.root = chord.root;
|
|
260
|
+
for (const member of set.members) {
|
|
261
|
+
const own = memberFor(chord, member.chroma);
|
|
262
|
+
if (own)
|
|
263
|
+
member.name = own.name;
|
|
338
264
|
}
|
|
339
|
-
return ranges;
|
|
340
265
|
}
|
|
341
|
-
function
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
for (const [a, b] of palmMutesOf(above))
|
|
351
|
-
for (let col = Math.max(a, offset);col <= b; col++)
|
|
352
|
-
muted.add(col - offset);
|
|
353
|
-
const openStart = part.some((l) => !l.string.barred);
|
|
354
|
-
return [{ kind: "strings", names, lines, texts: textsOf(part), muted, openStart }];
|
|
355
|
-
});
|
|
266
|
+
function scaleNoteSet(name) {
|
|
267
|
+
const scale = Scale2.get(scaleName(name));
|
|
268
|
+
if (scale.empty || !scale.tonic)
|
|
269
|
+
return null;
|
|
270
|
+
const { notes, intervals } = scaleSpelling(scale);
|
|
271
|
+
const set = fromNames(name.trim(), notes, intervals);
|
|
272
|
+
if (set)
|
|
273
|
+
set.scaleType = scale.type;
|
|
274
|
+
return set;
|
|
356
275
|
}
|
|
357
|
-
function
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
if (
|
|
368
|
-
return
|
|
369
|
-
const
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
276
|
+
function rootNameOf(text) {
|
|
277
|
+
const name = text.trim().replace(/-?\d$/, "").replace(/♯/g, "#").replace(/♭/g, "b");
|
|
278
|
+
if (chromaOf(name) === null)
|
|
279
|
+
return null;
|
|
280
|
+
return name[0].toUpperCase() + name.slice(1);
|
|
281
|
+
}
|
|
282
|
+
var PLAIN_INTERVALS = ["1P", "2m", "2M", "3m", "3M", "4P", "5d", "5P", "6m", "6M", "7m", "7M"];
|
|
283
|
+
function intervalFrom(root, name) {
|
|
284
|
+
const from = rootNameOf(root);
|
|
285
|
+
const to = rootNameOf(name);
|
|
286
|
+
if (from === null || to === null)
|
|
287
|
+
return null;
|
|
288
|
+
const semitones = (chromaOf(to) - chromaOf(from) + 12) % 12;
|
|
289
|
+
if (semitones === 0)
|
|
290
|
+
return "1P";
|
|
291
|
+
const spelled = Interval.distance(from, to);
|
|
292
|
+
const m = /^(\d+)([PMmdA]+)$/.exec(spelled);
|
|
293
|
+
return m && m[1] !== "1" && m[1] !== "8" ? spelled : PLAIN_INTERVALS[semitones];
|
|
294
|
+
}
|
|
295
|
+
function emptyNoteSet(title = "no notes") {
|
|
296
|
+
return { title, members: [], root: null, pitches: null, preferFlats: false, list: true };
|
|
297
|
+
}
|
|
298
|
+
function listNoteSet(text, root) {
|
|
299
|
+
const tokens = text.split(/[\s,]+/).filter(Boolean);
|
|
300
|
+
if (!tokens.length)
|
|
301
|
+
return null;
|
|
302
|
+
const withOctaves = tokens.every((t) => midiOf(t) !== null);
|
|
303
|
+
const names = withOctaves ? tokens.map((t) => t.replace(/-?\d$/, "")) : tokens;
|
|
304
|
+
if (!withOctaves && names.some((n) => chromaOf(n) === null))
|
|
305
|
+
return null;
|
|
306
|
+
const set = fromNames(tokens.join(" "), names, null);
|
|
307
|
+
if (!set)
|
|
308
|
+
return null;
|
|
309
|
+
set.list = true;
|
|
310
|
+
if (withOctaves)
|
|
311
|
+
set.pitches = tokens.map((t) => midiOf(t));
|
|
312
|
+
if (root === undefined)
|
|
313
|
+
return set;
|
|
314
|
+
const rootName = rootNameOf(root);
|
|
315
|
+
if (rootName === null)
|
|
316
|
+
return null;
|
|
317
|
+
set.root = chromaOf(rootName);
|
|
318
|
+
for (const member of set.members) {
|
|
319
|
+
member.interval = intervalFrom(rootName, member.name);
|
|
320
|
+
member.degree = Number(/^\d+/.exec(member.interval ?? "")?.[0] ?? 1);
|
|
321
|
+
}
|
|
322
|
+
return set;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// src/theory/chord-symbol.ts
|
|
326
|
+
var QUALITY_SUFFIXES = [
|
|
327
|
+
[/^(m7b5|m7-5|ø7?)$/, "Minor 7 flat 5"],
|
|
328
|
+
[/^(dim7|°7)$/, "Diminished 7"],
|
|
329
|
+
[/^(maj9|M9|Δ9)$/, "Major 9"],
|
|
330
|
+
[/^(maj7|M7|Δ7?)$/, "Major 7"],
|
|
331
|
+
[/^(7sus4)$/, "7sus4"],
|
|
332
|
+
[/^(m9|min9|-9)$/, "Minor 9"],
|
|
333
|
+
[/^(m7|min7|-7)$/, "Minor 7"],
|
|
334
|
+
[/^(m6|min6|-6)$/, "Minor 6"],
|
|
335
|
+
[/^(m|min|-)$/, "Minor"],
|
|
336
|
+
[/^(dim|°)$/, "Diminished"],
|
|
337
|
+
[/^(aug|\+|\+5|#5)$/, "Augmented"],
|
|
338
|
+
[/^(sus2)$/, "Sus2"],
|
|
339
|
+
[/^(sus4|sus)$/, "Sus4"],
|
|
340
|
+
[/^(add9|add2)$/, "Add9"],
|
|
341
|
+
[/^5$/, "5 (Power)"],
|
|
342
|
+
[/^(6\/9|69)$/, "6/9"],
|
|
343
|
+
[/^(m6\/9|m69|m6add9)$/, "Minor 6/9"],
|
|
344
|
+
[/^(Mb5|b5|-5)$/, "Major flat 5"],
|
|
345
|
+
[/^(mM7|mMaj7|mmaj7|m\(maj7\)|-\(maj7\))$/, "Minor major 7"],
|
|
346
|
+
[/^(13|11|9|7|6)$/, "$1"],
|
|
347
|
+
[/^(maj|M)?$/, "Major"]
|
|
348
|
+
];
|
|
349
|
+
var ACCIDENTAL_WORDS = {
|
|
350
|
+
"#": " Sharp",
|
|
351
|
+
"##": " Double Sharp",
|
|
352
|
+
b: " Flat",
|
|
353
|
+
bb: " Double Flat"
|
|
354
|
+
};
|
|
355
|
+
var spellNote = (note) => note[0] + (ACCIDENTAL_WORDS[note.slice(1)] ?? "");
|
|
356
|
+
var plain = (quality) => quality.replace(/\s*\([^)]*\)/g, "").trim();
|
|
357
|
+
function parseChord(symbol) {
|
|
358
|
+
const parts = splitChordSymbol(symbol);
|
|
359
|
+
if (!parts)
|
|
360
|
+
return null;
|
|
361
|
+
const trimmed = symbol.trim();
|
|
362
|
+
const { root, bass } = parts;
|
|
363
|
+
const suffix = withoutParentheses(parts.suffix);
|
|
364
|
+
let quality = null;
|
|
365
|
+
for (const written of suffix === null || suffix === parts.suffix ? [parts.suffix] : [parts.suffix, suffix]) {
|
|
366
|
+
for (const [re, label] of QUALITY_SUFFIXES) {
|
|
367
|
+
const hit = re.exec(written);
|
|
368
|
+
if (hit) {
|
|
369
|
+
quality = label.replace("$1", hit[1] ?? "");
|
|
370
|
+
break;
|
|
371
|
+
}
|
|
378
372
|
}
|
|
373
|
+
if (quality)
|
|
374
|
+
break;
|
|
379
375
|
}
|
|
380
|
-
|
|
376
|
+
if (suffix === null && !quality)
|
|
377
|
+
return null;
|
|
378
|
+
if (!quality && suffix !== null && chordNoteSet(trimmed))
|
|
379
|
+
quality = suffix;
|
|
380
|
+
if (!quality)
|
|
381
|
+
return null;
|
|
382
|
+
return {
|
|
383
|
+
symbol: trimmed,
|
|
384
|
+
root,
|
|
385
|
+
quality,
|
|
386
|
+
bass,
|
|
387
|
+
name: `${spellNote(root)} ${plain(quality)}${bass ? ` over ${spellNote(bass)}` : ""}`
|
|
388
|
+
};
|
|
381
389
|
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
390
|
+
|
|
391
|
+
// src/theory/naming.ts
|
|
392
|
+
var NAMINGS = ["letters", "solfege", "german"];
|
|
393
|
+
var NAMING_ERROR = "naming: write letters, solfege or german";
|
|
394
|
+
var DIRECTIVE_ERROR = "naming: write {naming: letters}, {naming: solfege} or {naming: german}";
|
|
395
|
+
var plain2 = (text) => text.trim().toLowerCase().normalize("NFD").replace(/[̀-ͯ]/g, "");
|
|
396
|
+
function parseNaming(text) {
|
|
397
|
+
const value = plain2(text);
|
|
398
|
+
if (NAMINGS.includes(value))
|
|
399
|
+
return value;
|
|
400
|
+
throw new Error(NAMING_ERROR);
|
|
401
|
+
}
|
|
402
|
+
function namingOf(value) {
|
|
403
|
+
if (typeof value !== "string")
|
|
404
|
+
return null;
|
|
405
|
+
try {
|
|
406
|
+
return parseNaming(value);
|
|
407
|
+
} catch {
|
|
408
|
+
return null;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
var SYLLABLE_LETTER = {
|
|
412
|
+
do: "C",
|
|
413
|
+
re: "D",
|
|
414
|
+
mi: "E",
|
|
415
|
+
fa: "F",
|
|
416
|
+
sol: "G",
|
|
417
|
+
la: "A",
|
|
418
|
+
si: "B"
|
|
419
|
+
};
|
|
420
|
+
var SYLLABLE = "(Do|DO|R[eé]|R[EÉ]|Mi|MI|Fa|FA|Sol|SOL|La|LA|Si|SI)";
|
|
421
|
+
var SIGN = "(##|bb|#|b|♯|♭)?";
|
|
422
|
+
var syllableLetter = (syllable) => SYLLABLE_LETTER[plain2(syllable)];
|
|
423
|
+
var AFTER_ROOT = /^(?:$|[0-9/(+°øΔ^-]|m|M|a(?:dd|ug|lt)|sus|dim)/;
|
|
424
|
+
var QUALITY_WORD = /^(?:[0-9(+°øΔ^]|m|M|a(?:dd|ug|lt)|sus|dim)/;
|
|
425
|
+
var WORD_QUALITY = /^(?:major|minor)$/i;
|
|
426
|
+
var joinsAsQuality = (word) => QUALITY_WORD.test(word) && !WORD_QUALITY.test(word);
|
|
427
|
+
var reads = (letters) => midiOf(letters) !== null || /^[A-G]/.test(letters) && parseChord(letters) !== null;
|
|
428
|
+
function rootToken(token, naming, h, solfegeLine = false) {
|
|
429
|
+
const b = naming === "german" ? /^B(?![#♯b♭x])(.*)$/.exec(token) : null;
|
|
430
|
+
if (b && AFTER_ROOT.test(b[1])) {
|
|
431
|
+
const letters = `Bb${b[1]}`;
|
|
432
|
+
if (reads(letters))
|
|
433
|
+
return letters;
|
|
434
|
+
}
|
|
435
|
+
if (naming !== "solfege" && !solfegeLine && reads(token))
|
|
436
|
+
return null;
|
|
437
|
+
const solfege = new RegExp(`^${SYLLABLE}${SIGN}(.*)$`).exec(token);
|
|
438
|
+
if (solfege) {
|
|
439
|
+
for (const sign of [solfege[2] ?? "", ""].filter((s, i, all) => all.indexOf(s) === i)) {
|
|
440
|
+
const rest = token.slice(solfege[1].length + sign.length);
|
|
441
|
+
const letters = `${syllableLetter(solfege[1])}${sign}${rest}`;
|
|
442
|
+
if (AFTER_ROOT.test(rest) && reads(letters))
|
|
443
|
+
return letters;
|
|
396
444
|
}
|
|
397
|
-
previous = raw;
|
|
398
445
|
}
|
|
399
|
-
|
|
400
|
-
|
|
446
|
+
if (h) {
|
|
447
|
+
const hm = /^H(##|bb|#|b|♯|♭|x)?(.*)$/.exec(token);
|
|
448
|
+
if (hm && AFTER_ROOT.test(hm[2])) {
|
|
449
|
+
const letters = `B${hm[1] ?? ""}${hm[2]}`;
|
|
450
|
+
if (reads(letters))
|
|
451
|
+
return letters;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
return null;
|
|
401
455
|
}
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
456
|
+
var NOTE_ONLY = /^[A-G](?:##|bb|#|b|♯|♭|x)?$/;
|
|
457
|
+
function letterPiece(piece, naming, h, line = false) {
|
|
458
|
+
if (!piece)
|
|
459
|
+
return piece;
|
|
460
|
+
const lower = plain2(piece);
|
|
461
|
+
if (/^majeure?$/.test(lower))
|
|
462
|
+
return "major";
|
|
463
|
+
if (/^mineure?$/.test(lower))
|
|
464
|
+
return "minor";
|
|
465
|
+
const range = /^(.+\d)-(.+\d)$/.exec(piece);
|
|
466
|
+
if (range) {
|
|
467
|
+
const [from, to] = [range[1], range[2]].map((n) => rootToken(n, naming, h, line) ?? n);
|
|
468
|
+
return `${from}-${to}`;
|
|
469
|
+
}
|
|
470
|
+
const slash = piece.indexOf("/");
|
|
471
|
+
if (slash > 0) {
|
|
472
|
+
const head = piece.slice(0, slash);
|
|
473
|
+
const bass = piece.slice(slash + 1);
|
|
474
|
+
const bassLetters = rootToken(bass, naming, h, line) ?? (NOTE_ONLY.test(bass) ? bass : null);
|
|
475
|
+
if (bassLetters && NOTE_ONLY.test(bassLetters)) {
|
|
476
|
+
const headLetters = rootToken(head, naming, h, line) ?? head;
|
|
477
|
+
const whole = `${headLetters}/${bassLetters}`;
|
|
478
|
+
if (whole !== piece && !(naming === "letters" && !line && reads(piece)))
|
|
479
|
+
return whole;
|
|
480
|
+
return piece;
|
|
417
481
|
}
|
|
418
|
-
if (padded.some((l) => l[col] !== " "))
|
|
419
|
-
filled = true;
|
|
420
|
-
const { beat, skip, at } = beatAt(padded, col);
|
|
421
|
-
if (beat.length)
|
|
422
|
-
beats.push({ notes: beat, col: at ?? col });
|
|
423
|
-
col += skip;
|
|
424
482
|
}
|
|
425
|
-
|
|
426
|
-
bars.push({ beats, start, end: width });
|
|
427
|
-
return bars;
|
|
483
|
+
return rootToken(piece, naming, h, line) ?? piece;
|
|
428
484
|
}
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
for (let i = 0;i <
|
|
452
|
-
|
|
453
|
-
|
|
485
|
+
function letterWord(word, naming, h, changes, line = false) {
|
|
486
|
+
const out = word.split(/([,|;])/).map((piece, i) => i % 2 ? piece : letterPiece(piece, naming, h, line)).join("");
|
|
487
|
+
if (out !== word)
|
|
488
|
+
changes.push([word, out]);
|
|
489
|
+
return out;
|
|
490
|
+
}
|
|
491
|
+
var syllableOnly = (word) => new RegExp(`^${SYLLABLE}${SIGN}$`).test(word);
|
|
492
|
+
function read(text, naming, options, changes) {
|
|
493
|
+
const h = options.h ?? true;
|
|
494
|
+
let out = text.normalize("NFC").replace(new RegExp(`(^|[\\s,/|])${SYLLABLE}\\s+(dièse|diese|bémol|bemol)(?=$|[\\s,|])`, "g"), (_, before, syllable, sign) => `${before}${syllable}${/^d/.test(sign) ? "#" : "b"}`);
|
|
495
|
+
if (options.chord) {
|
|
496
|
+
const joined = new RegExp(`^\\s*${SYLLABLE}${SIGN}\\s+(\\S+)\\s*$`).exec(out);
|
|
497
|
+
if (joined && joinsAsQuality(joined[3])) {
|
|
498
|
+
const word = `${joined[1]}${joined[2] ?? ""}${joined[3]}`;
|
|
499
|
+
const letters = rootToken(word, naming, h) ?? letterPiece(word, naming, h);
|
|
500
|
+
if (letters !== word) {
|
|
501
|
+
changes.push([out.trim(), letters]);
|
|
502
|
+
return letters;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
const words = out.split(/(\s+)/);
|
|
507
|
+
for (let i = 0;i + 2 < words.length; i += 2) {
|
|
508
|
+
const head = words[i];
|
|
509
|
+
const next = words[i + 2];
|
|
510
|
+
if (!syllableOnly(head) || !joinsAsQuality(next))
|
|
454
511
|
continue;
|
|
512
|
+
if (naming !== "solfege" && reads(head))
|
|
513
|
+
continue;
|
|
514
|
+
const joined = `${head}${next}`;
|
|
515
|
+
const letters = letterPiece(joined, naming, h);
|
|
516
|
+
if (letters !== joined) {
|
|
517
|
+
words.splice(i, 3, joined);
|
|
518
|
+
i -= 2;
|
|
455
519
|
}
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
520
|
+
}
|
|
521
|
+
out = words.join("");
|
|
522
|
+
const line = out.split(/[\s,|;]+/).some((w) => w !== "" && !/^Do/.test(w) && !reads(w) && rootToken(w, "solfege", false) !== null);
|
|
523
|
+
return out.replace(/\S+/g, (word) => letterWord(word, naming, h, changes, line));
|
|
524
|
+
}
|
|
525
|
+
function toLetters(text, naming = "letters", options = {}) {
|
|
526
|
+
return read(text, naming, options, []);
|
|
527
|
+
}
|
|
528
|
+
var NOTE_KEYS = new Set([
|
|
529
|
+
"chord",
|
|
530
|
+
"chords",
|
|
531
|
+
"symbol",
|
|
532
|
+
"name",
|
|
533
|
+
"from",
|
|
534
|
+
"to",
|
|
535
|
+
"scale",
|
|
536
|
+
"notes",
|
|
537
|
+
"root",
|
|
538
|
+
"key",
|
|
539
|
+
"arpeggio",
|
|
540
|
+
"compare",
|
|
541
|
+
"scales-for",
|
|
542
|
+
"scales-for-notes",
|
|
543
|
+
"modes",
|
|
544
|
+
"progression",
|
|
545
|
+
"tuning",
|
|
546
|
+
"range",
|
|
547
|
+
"highlight",
|
|
548
|
+
"pitches",
|
|
549
|
+
"sounds",
|
|
550
|
+
"mode"
|
|
551
|
+
]);
|
|
552
|
+
var SINGLE_CHORD_KEYS = new Set(["chord", "symbol", "from", "to", "sounds"]);
|
|
553
|
+
var KEY_LINE = /^(\s*)([A-Za-z][A-Za-z-]*)(\s*:\s*)(.*)$/;
|
|
554
|
+
var NAMING_LINE = /^\s*naming\s*:\s*(.*)$/i;
|
|
555
|
+
var NAMING_DIRECTIVE = /^\s*\{\s*naming\s*:\s*([^}]*)\}\s*$/i;
|
|
556
|
+
var DIAGRAM_SHORTHAND = new Set(["chord", "keyboard", "fretboard", "circle"]);
|
|
557
|
+
function spacedTuning(value, naming) {
|
|
558
|
+
const compact = /^\s*((?:[A-Ha-h](?:#|b|♯|♭)?){4,})\s*$/.exec(value);
|
|
559
|
+
if (!compact || naming !== "german" && !/h/i.test(compact[1]))
|
|
560
|
+
return value;
|
|
561
|
+
return compact[1].match(/[A-Ha-h](?:#|b|♯|♭)?/g).map((n) => n[0].toUpperCase() + n.slice(1)).join(" ");
|
|
562
|
+
}
|
|
563
|
+
function lettersInBlock(language, text) {
|
|
564
|
+
const result = { text, naming: null, changes: [], titles: [], warning: null };
|
|
565
|
+
if (language === "tab" || language === "score")
|
|
566
|
+
return result;
|
|
567
|
+
const lines = [];
|
|
568
|
+
for (const line of text.split(`
|
|
569
|
+
`)) {
|
|
570
|
+
const own = (language === "chords" ? NAMING_DIRECTIVE : NAMING_LINE).exec(line);
|
|
571
|
+
if (!own) {
|
|
572
|
+
lines.push(line);
|
|
573
|
+
continue;
|
|
479
574
|
}
|
|
480
|
-
if (
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
575
|
+
if (language !== "chords")
|
|
576
|
+
result.naming = parseNaming(own[1]);
|
|
577
|
+
else {
|
|
578
|
+
const naming = namingOf(own[1]);
|
|
579
|
+
if (naming)
|
|
580
|
+
result.naming = naming;
|
|
581
|
+
else
|
|
582
|
+
result.warning = DIRECTIVE_ERROR;
|
|
484
583
|
}
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
584
|
+
}
|
|
585
|
+
const naming = result.naming ?? "letters";
|
|
586
|
+
const named = result.naming !== null;
|
|
587
|
+
const changes = result.changes;
|
|
588
|
+
if (language === "chords") {
|
|
589
|
+
if (!named) {
|
|
590
|
+
result.text = lines.join(`
|
|
591
|
+
`);
|
|
592
|
+
return result;
|
|
494
593
|
}
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
594
|
+
result.text = lines.map((line) => line.replace(/\[([^\]]+)\]/g, (whole, inside) => {
|
|
595
|
+
const letters = read(inside, naming, { chord: true }, changes);
|
|
596
|
+
return letters === inside ? whole : `[${letters}]`;
|
|
597
|
+
}).replace(/^(\s*\{\s*(?:key|define|chord)\s*:\s*)([^}]*?)(\s*\}\s*)$/i, (_, head, value, tail) => {
|
|
598
|
+
if (/^\s*\{\s*key/i.test(head))
|
|
599
|
+
return `${head}${read(value, naming, {}, changes)}${tail}`;
|
|
600
|
+
const [name, ...rest] = value.split(/(\s+)/);
|
|
601
|
+
return `${head}${read(name, naming, { chord: true }, changes)}${rest.join("")}${tail}`;
|
|
602
|
+
})).join(`
|
|
603
|
+
`);
|
|
604
|
+
return result;
|
|
498
605
|
}
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
606
|
+
const shorthand = DIAGRAM_SHORTHAND.has(language);
|
|
607
|
+
result.text = lines.map((line) => {
|
|
608
|
+
if (/^\s*-{3,}\s*$/.test(line) || !line.trim())
|
|
609
|
+
return line;
|
|
610
|
+
const kv = KEY_LINE.exec(line);
|
|
611
|
+
if (kv) {
|
|
612
|
+
const key = kv[2].toLowerCase();
|
|
613
|
+
if (key === "title") {
|
|
614
|
+
result.titles.push(kv[4].trim());
|
|
615
|
+
return line;
|
|
616
|
+
}
|
|
617
|
+
if (!NOTE_KEYS.has(key))
|
|
618
|
+
return line;
|
|
619
|
+
if (key === "name")
|
|
620
|
+
result.titles.push(kv[4].trim());
|
|
621
|
+
const value = key === "tuning" ? spacedTuning(kv[4], naming) : kv[4];
|
|
622
|
+
const letters = read(value, naming, { chord: SINGLE_CHORD_KEYS.has(key) }, changes);
|
|
623
|
+
if (letters !== kv[4])
|
|
624
|
+
changes.push([kv[4].trim(), letters.trim()]);
|
|
625
|
+
return `${kv[1]}${kv[2]}${kv[3]}${letters}`;
|
|
513
626
|
}
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
627
|
+
if (shorthand)
|
|
628
|
+
return read(line, naming, { chord: language === "chord", h: named }, changes);
|
|
629
|
+
if (language === "progression")
|
|
630
|
+
return read(line, naming, { h: named }, changes);
|
|
631
|
+
if (language === "strum" || language === "picking")
|
|
632
|
+
return line.replace(/\[([^\]]+)\]/g, (whole, inside) => {
|
|
633
|
+
const letters = read(inside, naming, { chord: true, h: named }, changes);
|
|
634
|
+
return letters === inside ? whole : `[${letters}]`;
|
|
635
|
+
});
|
|
636
|
+
return line;
|
|
637
|
+
}).join(`
|
|
638
|
+
`);
|
|
639
|
+
return result;
|
|
640
|
+
}
|
|
641
|
+
function quoteAsWritten(message, changes) {
|
|
642
|
+
let out = message;
|
|
643
|
+
for (const [written, letters] of [...changes].sort((a, b) => b[1].length - a[1].length)) {
|
|
644
|
+
if (written !== letters)
|
|
645
|
+
out = out.split(`"${letters}"`).join(`"${written}"`);
|
|
646
|
+
}
|
|
647
|
+
return out;
|
|
648
|
+
}
|
|
649
|
+
var LETTER_SYLLABLE = {
|
|
650
|
+
C: "Do",
|
|
651
|
+
D: "Ré",
|
|
652
|
+
E: "Mi",
|
|
653
|
+
F: "Fa",
|
|
654
|
+
G: "Sol",
|
|
655
|
+
A: "La",
|
|
656
|
+
B: "Si"
|
|
532
657
|
};
|
|
533
|
-
var
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
658
|
+
var SOLFEGE_SIGNS = {
|
|
659
|
+
"#": "♯",
|
|
660
|
+
"♯": "♯",
|
|
661
|
+
b: "♭",
|
|
662
|
+
"♭": "♭",
|
|
663
|
+
"##": "♯♯",
|
|
664
|
+
x: "♯♯",
|
|
665
|
+
bb: "♭♭",
|
|
666
|
+
"♭♭": "♭♭",
|
|
667
|
+
"♯♯": "♯♯"
|
|
539
668
|
};
|
|
540
|
-
var
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
if (
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
669
|
+
var ROOT = /^([A-G])(##|bb|♯♯|♭♭|#|b|♯|♭|x)?/;
|
|
670
|
+
function noteInNaming(name, naming) {
|
|
671
|
+
if (naming === "letters")
|
|
672
|
+
return name;
|
|
673
|
+
const m = /^([A-G])(##|bb|♯♯|♭♭|#|b|♯|♭|x)?$/.exec(name.trim());
|
|
674
|
+
if (!m)
|
|
675
|
+
return name;
|
|
676
|
+
const [, letter, sign = ""] = m;
|
|
677
|
+
if (naming === "solfege")
|
|
678
|
+
return `${LETTER_SYLLABLE[letter]}${SOLFEGE_SIGNS[sign] ?? ""}`;
|
|
679
|
+
if (letter !== "B")
|
|
680
|
+
return name.trim();
|
|
681
|
+
return sign === "b" || sign === "♭" ? "B" : `H${sign}`;
|
|
682
|
+
}
|
|
683
|
+
function chordInNaming(symbol, naming) {
|
|
684
|
+
if (naming === "letters")
|
|
685
|
+
return symbol;
|
|
686
|
+
const text = symbol.trim();
|
|
687
|
+
const root = ROOT.exec(text);
|
|
688
|
+
if (!root || !parseChord(text))
|
|
689
|
+
return symbol;
|
|
690
|
+
const rest = text.slice(root[0].length);
|
|
691
|
+
const slash = /^(.*)\/([A-G](?:##|bb|♯♯|♭♭|#|b|♯|♭|x)?)$/.exec(rest);
|
|
692
|
+
const suffix = slash ? slash[1] : rest;
|
|
693
|
+
const bass = slash ? `/${noteInNaming(slash[2], naming)}` : "";
|
|
694
|
+
const shownSuffix = naming === "solfege" && suffix ? ` ${suffix}` : suffix;
|
|
695
|
+
return `${noteInNaming(root[0], naming)}${shownSuffix}${bass}`;
|
|
696
|
+
}
|
|
697
|
+
var AFTER_A_NOTE = new Set([
|
|
698
|
+
"major",
|
|
699
|
+
"minor",
|
|
700
|
+
"pentatonic",
|
|
701
|
+
"blues",
|
|
702
|
+
"dorian",
|
|
703
|
+
"phrygian",
|
|
704
|
+
"lydian",
|
|
705
|
+
"mixolydian",
|
|
706
|
+
"aeolian",
|
|
707
|
+
"ionian",
|
|
708
|
+
"locrian",
|
|
709
|
+
"harmonic",
|
|
710
|
+
"melodic",
|
|
711
|
+
"chromatic",
|
|
712
|
+
"whole",
|
|
713
|
+
"augmented",
|
|
714
|
+
"diminished",
|
|
715
|
+
"bebop",
|
|
716
|
+
"arpeggio",
|
|
717
|
+
"chord",
|
|
718
|
+
"string",
|
|
719
|
+
"position",
|
|
720
|
+
"box",
|
|
721
|
+
"scale",
|
|
722
|
+
"mode"
|
|
723
|
+
]);
|
|
724
|
+
var OCTAVE = /^([A-G](?:##|bb|#|b|♯|♭|x)?)(-?\d)$/;
|
|
725
|
+
function shownText(text, naming) {
|
|
726
|
+
if (naming === "letters" || !text)
|
|
727
|
+
return text;
|
|
728
|
+
const parts = text.split(/(\s+|[,;:()])/);
|
|
729
|
+
const word = (i, step) => {
|
|
730
|
+
for (let j = i + step;j >= 0 && j < parts.length; j += step) {
|
|
731
|
+
const p = parts[j];
|
|
732
|
+
if (!p.trim())
|
|
733
|
+
continue;
|
|
734
|
+
return /^[,;:()]$/.test(p) ? null : p;
|
|
557
735
|
}
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
736
|
+
return null;
|
|
737
|
+
};
|
|
738
|
+
return parts.map((part, i) => {
|
|
739
|
+
if (!/^[A-G]/.test(part))
|
|
740
|
+
return part;
|
|
741
|
+
const next = word(i, 1);
|
|
742
|
+
if (next === "shape")
|
|
743
|
+
return part;
|
|
744
|
+
const octave = OCTAVE.exec(part);
|
|
745
|
+
if (octave) {
|
|
746
|
+
const amongNotes = [word(i, -1), next].some((w) => w !== null && OCTAVE.test(w));
|
|
747
|
+
if (amongNotes || !/^[5679]$/.test(octave[2]))
|
|
748
|
+
return `${noteInNaming(octave[1], naming)}${octave[2]}`;
|
|
561
749
|
}
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
750
|
+
if (part === "A" && next && /^[a-z]/.test(next) && !AFTER_A_NOTE.has(next))
|
|
751
|
+
return part;
|
|
752
|
+
if (parseChord(part))
|
|
753
|
+
return chordInNaming(part, naming);
|
|
754
|
+
const both = part.split("/");
|
|
755
|
+
if (both.length === 2 && both.every((p) => /^[A-G]/.test(p) && parseChord(p)))
|
|
756
|
+
return both.map((p) => chordInNaming(p, naming)).join("/");
|
|
757
|
+
return part;
|
|
758
|
+
}).join("");
|
|
759
|
+
}
|
|
760
|
+
var current = "letters";
|
|
761
|
+
var verbatim = [];
|
|
762
|
+
function withNaming(naming, draw, titles = []) {
|
|
763
|
+
const before = [current, verbatim];
|
|
764
|
+
current = naming;
|
|
765
|
+
verbatim = titles.filter(Boolean);
|
|
766
|
+
try {
|
|
767
|
+
return draw();
|
|
768
|
+
} finally {
|
|
769
|
+
[current, verbatim] = before;
|
|
565
770
|
}
|
|
566
|
-
return BY_COUNT[strings] ?? null;
|
|
567
771
|
}
|
|
568
|
-
function
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
772
|
+
function shown(text) {
|
|
773
|
+
if (current === "letters" || !text)
|
|
774
|
+
return text;
|
|
775
|
+
for (const title of verbatim) {
|
|
776
|
+
if (text === title)
|
|
777
|
+
return text;
|
|
778
|
+
if (text.startsWith(`${title},`))
|
|
779
|
+
return title + shownText(text.slice(title.length), current);
|
|
574
780
|
}
|
|
575
|
-
return
|
|
781
|
+
return shownText(text, current);
|
|
576
782
|
}
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
783
|
+
|
|
784
|
+
// src/render/dom.ts
|
|
785
|
+
var SVG_NS = "http://www.w3.org/2000/svg";
|
|
786
|
+
var apply = (el, attrs) => {
|
|
787
|
+
for (const [name, value] of Object.entries(attrs)) {
|
|
788
|
+
if (value !== undefined)
|
|
789
|
+
el.setAttribute(name, String(value));
|
|
581
790
|
}
|
|
582
|
-
const standard = BY_COUNT[6];
|
|
583
|
-
if (tuning.length > 5)
|
|
584
|
-
return null;
|
|
585
|
-
const at = tuning.map((m) => standard.indexOf(m));
|
|
586
|
-
if (at[0] < 0 || at.some((i, k) => i !== at[0] + k))
|
|
587
|
-
return null;
|
|
588
|
-
return { tuning: [...standard], strings: at.map((i) => i + 1) };
|
|
589
|
-
}
|
|
590
|
-
var drumBeatAt = (drums) => (padded, col) => {
|
|
591
|
-
const beat = [];
|
|
592
|
-
padded.forEach((line, i) => {
|
|
593
|
-
const hit = line[col];
|
|
594
|
-
if (!/[xXoOgfdb#@*+]/.test(hit))
|
|
595
|
-
return;
|
|
596
|
-
const name = articulationOf(drums[i], hit);
|
|
597
|
-
if (!beat.some((n) => n.tex === name))
|
|
598
|
-
beat.push({ tex: name, effects: effectOf(hit) });
|
|
599
|
-
});
|
|
600
|
-
return { beat, skip: 0 };
|
|
601
791
|
};
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
[3, 8, true],
|
|
610
|
-
[2, 8, false],
|
|
611
|
-
[1, 16, false]
|
|
612
|
-
];
|
|
613
|
-
function valuesOf(sixteenths) {
|
|
614
|
-
const out = [];
|
|
615
|
-
for (let left = sixteenths;left > 0; ) {
|
|
616
|
-
const [length, duration, dotted] = VALUES.find(([n]) => n <= left);
|
|
617
|
-
out.push({ duration, dotted });
|
|
618
|
-
left -= length;
|
|
619
|
-
}
|
|
620
|
-
return out;
|
|
792
|
+
function svg(doc, tag, attrs = {}, children = []) {
|
|
793
|
+
const el = doc.createElementNS(SVG_NS, tag);
|
|
794
|
+
apply(el, attrs);
|
|
795
|
+
for (const child of children)
|
|
796
|
+
if (child)
|
|
797
|
+
el.appendChild(child);
|
|
798
|
+
return el;
|
|
621
799
|
}
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
function keepsSpacing(cols, at) {
|
|
627
|
-
const lengths = new Map;
|
|
628
|
-
for (let i = 1;i < cols.length; i++) {
|
|
629
|
-
const gap = cols[i] - cols[i - 1];
|
|
630
|
-
const length = at[i] - at[i - 1];
|
|
631
|
-
if ((lengths.get(gap) ?? length) !== length)
|
|
632
|
-
return false;
|
|
633
|
-
lengths.set(gap, length);
|
|
634
|
-
}
|
|
635
|
-
const sorted = [...lengths].sort((a, b) => a[0] - b[0]);
|
|
636
|
-
return sorted.every(([, length], i) => i === 0 || length >= sorted[i - 1][1]);
|
|
800
|
+
function svgText(doc, text, attrs = {}) {
|
|
801
|
+
const el = svg(doc, "text", attrs);
|
|
802
|
+
el.textContent = text;
|
|
803
|
+
return el;
|
|
637
804
|
}
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
const k = Math.round(exact);
|
|
648
|
-
const off = Math.abs(exact - k) * step;
|
|
649
|
-
if (k < 0 || k >= n || off > slack + 0.000000001 || at.length && k * (bar / n) <= at.at(-1))
|
|
650
|
-
return null;
|
|
651
|
-
error = Math.max(error, off);
|
|
652
|
-
at.push(k * (bar / n));
|
|
805
|
+
function svgLabel(doc, text, [x, y], cls, anchor = "middle") {
|
|
806
|
+
return svgText(doc, text, { class: cls, x, y: y + 4, "text-anchor": anchor });
|
|
807
|
+
}
|
|
808
|
+
function dotLabel(doc, text, point, r) {
|
|
809
|
+
const label = svgLabel(doc, shown(text), point, "mn-dot-text");
|
|
810
|
+
if ([...shown(text)].length >= 3) {
|
|
811
|
+
label.classList.add("mn-dot-text-long");
|
|
812
|
+
label.setAttribute("textLength", String(2 * r - 2));
|
|
813
|
+
label.setAttribute("lengthAdjust", "spacingAndGlyphs");
|
|
653
814
|
}
|
|
654
|
-
|
|
655
|
-
return null;
|
|
656
|
-
return keepsSpacing(cols, at) ? { at, error } : null;
|
|
815
|
+
return label;
|
|
657
816
|
}
|
|
658
|
-
function
|
|
659
|
-
|
|
660
|
-
return [];
|
|
661
|
-
const spans = [
|
|
662
|
-
[pad, width - pad],
|
|
663
|
-
[pad, width]
|
|
664
|
-
];
|
|
665
|
-
for (let start = 1;start < pad; start++)
|
|
666
|
-
spans.push([start, width - start]);
|
|
667
|
-
if (cols[0] > pad)
|
|
668
|
-
spans.push([0, width]);
|
|
669
|
-
for (const [slack, ties] of [
|
|
670
|
-
[0.4, false],
|
|
671
|
-
[1, false],
|
|
672
|
-
[0.4, true]
|
|
673
|
-
])
|
|
674
|
-
for (const n of meter.grids) {
|
|
675
|
-
const fits = spans.map((span) => fit(cols, n, span, slack, ties, meter.length)).filter((f) => f !== null);
|
|
676
|
-
if (fits.length)
|
|
677
|
-
return fits.reduce((a, b) => b.error < a.error ? b : a).at;
|
|
678
|
-
}
|
|
679
|
-
return null;
|
|
817
|
+
function svgLine(doc, [x1, y1], [x2, y2], cls) {
|
|
818
|
+
return svg(doc, "line", { class: cls, x1, y1, x2, y2 });
|
|
680
819
|
}
|
|
681
|
-
function
|
|
682
|
-
const
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
820
|
+
function html(doc, tag, cls, text) {
|
|
821
|
+
const el = doc.createElement(tag);
|
|
822
|
+
if (cls)
|
|
823
|
+
el.className = cls;
|
|
824
|
+
if (text !== undefined)
|
|
825
|
+
el.textContent = text;
|
|
826
|
+
return el;
|
|
827
|
+
}
|
|
828
|
+
var NAME_PREFIX = `mn-name-${Math.random().toString(36).slice(2, 8)}-`;
|
|
829
|
+
var names = 0;
|
|
830
|
+
var uniqueId = () => `${NAME_PREFIX}${++names}`;
|
|
831
|
+
var SHOWN_NAMES = /\bmn-(guitar-chord|fretboard|keyboard|circle)\b/;
|
|
832
|
+
function svgRoot(doc, width, height, cls, label) {
|
|
833
|
+
const id = `${NAME_PREFIX}${++names}`;
|
|
834
|
+
const title = svg(doc, "title", { class: "mn-name", id });
|
|
835
|
+
title.textContent = SHOWN_NAMES.test(cls) ? shown(label) : label;
|
|
836
|
+
return svg(doc, "svg", {
|
|
837
|
+
xmlns: SVG_NS,
|
|
838
|
+
viewBox: `0 0 ${width} ${height}`,
|
|
839
|
+
width,
|
|
840
|
+
class: `mn-svg ${cls}`,
|
|
841
|
+
role: "img",
|
|
842
|
+
"aria-labelledby": id
|
|
843
|
+
}, [svg(doc, "defs", {}, [title])]);
|
|
844
|
+
}
|
|
845
|
+
var nameElement = (el) => {
|
|
846
|
+
const id = el.getAttribute("aria-labelledby");
|
|
847
|
+
if (!id)
|
|
848
|
+
return null;
|
|
849
|
+
for (const candidate of el.querySelectorAll("[id]")) {
|
|
850
|
+
if (candidate.getAttribute("id") === id)
|
|
851
|
+
return candidate;
|
|
690
852
|
}
|
|
691
|
-
return
|
|
853
|
+
return el.ownerDocument.getElementById(id);
|
|
854
|
+
};
|
|
855
|
+
function accessibleName(el) {
|
|
856
|
+
const named = nameElement(el);
|
|
857
|
+
if (named)
|
|
858
|
+
return named.textContent;
|
|
859
|
+
return el.getAttribute("aria-label");
|
|
692
860
|
}
|
|
693
|
-
function
|
|
694
|
-
const
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
for (const eighth of [2, 1]) {
|
|
700
|
-
const lengths = cols.map((_, i) => eighth * (i < gaps.length ? Math.max(1, Math.round(gaps[i] / unit)) : 1));
|
|
701
|
-
let total = lengths.reduce((a, b) => a + b, 0);
|
|
702
|
-
if (eighth === 2)
|
|
703
|
-
for (const i of legato) {
|
|
704
|
-
if (total <= meter.length)
|
|
705
|
-
break;
|
|
706
|
-
if (i + 1 >= lengths.length || lengths[i] !== 2)
|
|
707
|
-
continue;
|
|
708
|
-
const next = Math.max(1, lengths[i + 1] - 1);
|
|
709
|
-
total -= 1 + lengths[i + 1] - next;
|
|
710
|
-
lengths[i] = 1;
|
|
711
|
-
lengths[i + 1] = next;
|
|
712
|
-
}
|
|
713
|
-
if (total > meter.length)
|
|
714
|
-
continue;
|
|
715
|
-
return [
|
|
716
|
-
...lengths.map((sixteenths, beat) => ({ beat, sixteenths })),
|
|
717
|
-
...restsFrom(total, meter)
|
|
718
|
-
];
|
|
719
|
-
}
|
|
720
|
-
return cols.map((_, beat) => ({ beat, sixteenths: 1 }));
|
|
861
|
+
function setAccessibleName(el, name) {
|
|
862
|
+
const named = nameElement(el);
|
|
863
|
+
if (named)
|
|
864
|
+
named.textContent = name;
|
|
865
|
+
else
|
|
866
|
+
el.setAttribute("aria-label", name);
|
|
721
867
|
}
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
868
|
+
function playableMark(doc, area, ...children) {
|
|
869
|
+
const hit = svg(doc, "rect", {
|
|
870
|
+
class: "mn-hit",
|
|
871
|
+
x: area.x,
|
|
872
|
+
y: area.y,
|
|
873
|
+
width: area.width,
|
|
874
|
+
height: area.height,
|
|
875
|
+
fill: "transparent",
|
|
876
|
+
"pointer-events": "all"
|
|
877
|
+
});
|
|
878
|
+
return svg(doc, "g", { class: "mn-mark" }, [hit, ...children]);
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
// src/fretboard/tuning.ts
|
|
882
|
+
var NAMED = new Map(Object.entries({
|
|
883
|
+
standard: "E2 A2 D3 G3 B3 E4",
|
|
884
|
+
"drop d": "D2 A2 D3 G3 B3 E4",
|
|
885
|
+
"drop c": "C2 G2 C3 F3 A3 D4",
|
|
886
|
+
"drop b": "B1 F#2 B2 E3 G#3 C#4",
|
|
887
|
+
"drop a": "A1 E2 A2 D3 F#3 B3",
|
|
888
|
+
"double drop d": "D2 A2 D3 G3 B3 D4",
|
|
889
|
+
dadgad: "D2 A2 D3 G3 A3 D4",
|
|
890
|
+
"open g": "D2 G2 D3 G3 B3 D4",
|
|
891
|
+
"open d": "D2 A2 D3 F#3 A3 D4",
|
|
892
|
+
"open e": "E2 B2 E3 G#3 B3 E4",
|
|
893
|
+
"open c": "C2 G2 C3 G3 C4 E4",
|
|
894
|
+
"open a": "E2 A2 E3 A3 C#4 E4",
|
|
895
|
+
"half step down": "Eb2 Ab2 Db3 Gb3 Bb3 Eb4",
|
|
896
|
+
"whole step down": "D2 G2 C3 F3 A3 D4",
|
|
897
|
+
"modal c6": "C2 A2 C3 G3 C4 E4",
|
|
898
|
+
c6: "C2 A2 C3 G3 C4 E4",
|
|
899
|
+
bass: "E1 A1 D2 G2",
|
|
900
|
+
ukulele: "G4 C4 E4 A4"
|
|
901
|
+
}));
|
|
902
|
+
function parseTuning(text) {
|
|
903
|
+
const trimmed = text.trim();
|
|
904
|
+
const named = NAMED.get(trimmed.toLowerCase().replace(/\s*\(.*\)$/, ""));
|
|
905
|
+
if (named)
|
|
906
|
+
return parseTuning(named);
|
|
907
|
+
const spaced = trimmed.split(/[\s,]+/).filter(Boolean);
|
|
908
|
+
if (spaced.length > 1 && spaced.every((t) => midiOf(t) !== null)) {
|
|
909
|
+
return spaced.map((t) => midiOf(t));
|
|
910
|
+
}
|
|
911
|
+
const names = spaced.length > 1 ? spaced : trimmed.match(/[A-G][#♯b♭]?|[a-g][#♯♭]?/g) ?? [];
|
|
912
|
+
if (names.length < 2 || names.join("") !== spaced.join(""))
|
|
913
|
+
return null;
|
|
914
|
+
const midis = [];
|
|
915
|
+
for (const name of names) {
|
|
916
|
+
const chroma = chromaOf(name);
|
|
917
|
+
if (chroma === null)
|
|
918
|
+
return null;
|
|
919
|
+
const previous = midis[midis.length - 1];
|
|
920
|
+
if (previous === undefined) {
|
|
921
|
+
const candidates = [28, 40, 52].map((c) => c - c % 12 + chroma);
|
|
922
|
+
midis.push(candidates.reduce((a, b) => Math.abs(b - 40) < Math.abs(a - 40) ? b : a));
|
|
923
|
+
} else {
|
|
924
|
+
let midi = previous - previous % 12 + chroma;
|
|
925
|
+
while (midi <= previous)
|
|
926
|
+
midi += 12;
|
|
927
|
+
midis.push(midi);
|
|
736
928
|
}
|
|
737
929
|
}
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
930
|
+
return midis;
|
|
931
|
+
}
|
|
932
|
+
function tuningNames(text) {
|
|
933
|
+
const trimmed = text.trim();
|
|
934
|
+
const named = NAMED.get(trimmed.toLowerCase().replace(/\s*\(.*\)$/, ""));
|
|
935
|
+
if (named)
|
|
936
|
+
return tuningNames(named);
|
|
937
|
+
if (!parseTuning(trimmed))
|
|
938
|
+
return null;
|
|
939
|
+
const spaced = trimmed.split(/[\s,]+/).filter(Boolean);
|
|
940
|
+
const names = spaced.length > 1 ? spaced : trimmed.match(/[A-G][#♯b♭]?|[a-g][#♯♭]?/g) ?? [];
|
|
941
|
+
return names.map((n) => {
|
|
942
|
+
const letter = n.charAt(0).toUpperCase();
|
|
943
|
+
const accidental = n.slice(1).replace(/-?\d+$/, "").replace("♯", "#").replace("♭", "b");
|
|
944
|
+
return letter + accidental;
|
|
945
|
+
});
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
// src/convert/text-tab.ts
|
|
949
|
+
var STRING_PREFIX = /^\s*([A-Ga-g][#b]?|[1-8](?=\s*[|:]))?\s*[|:]?/;
|
|
950
|
+
var STRING_BODY = /^[-0-9xX|:hpbrsvt/\\~^().*<>\s]*$/;
|
|
951
|
+
var DRUM_LINE = /^\s*([A-Za-z][A-Za-z0-9. -]{0,14}?)\s*[|:]([-xXoOgfdb#@*+|:\s]*)$/;
|
|
952
|
+
var DRUM_NAMES = new Map(Object.entries({
|
|
953
|
+
hihat: "h hh hat hihat hihats",
|
|
954
|
+
"hihat-open": "oh openhat openhihat",
|
|
955
|
+
"hihat-foot": "hf fh hp ph pedal hihatfoot hihatpedal",
|
|
956
|
+
crash: "c c1 cc cr cy cym crash crash1 cymbal",
|
|
957
|
+
crash2: "c2 cr2 crash2",
|
|
958
|
+
ride: "r rd rc ride",
|
|
959
|
+
splash: "sp spl splash",
|
|
960
|
+
china: "ch cn chi china",
|
|
961
|
+
cowbell: "cb cow cowbell",
|
|
962
|
+
snare: "s sd sn sr snare snaredrum",
|
|
963
|
+
tom1: "t t1 ht tom1 hightom hitom",
|
|
964
|
+
tom2: "t2 mt tom2 midtom",
|
|
965
|
+
tom3: "t3 lt tom3 lowtom",
|
|
966
|
+
floor: "f ft fl t4 tom4 floor floortom",
|
|
967
|
+
kick: "b bd bs k kd bass kick bassdrum kickdrum"
|
|
968
|
+
}).flatMap(([drum, list]) => list.split(" ").map((name) => [name, drum])));
|
|
969
|
+
function articulationOf(drum, hit) {
|
|
970
|
+
const choke = hit === "#";
|
|
971
|
+
switch (drum) {
|
|
972
|
+
case "hihat":
|
|
973
|
+
return hit === "o" || hit === "O" ? "HiHatOpen" : "HiHatClosed";
|
|
974
|
+
case "hihat-open":
|
|
975
|
+
return "HiHatOpen";
|
|
976
|
+
case "hihat-foot":
|
|
977
|
+
return "PedalHiHatHit";
|
|
978
|
+
case "crash":
|
|
979
|
+
return choke ? "CrashHighChoke" : "CrashHighHit";
|
|
980
|
+
case "crash2":
|
|
981
|
+
return choke ? "CrashMediumChoke" : "CrashMediumHit";
|
|
982
|
+
case "ride":
|
|
983
|
+
return choke ? "RideChoke" : "RideMiddle";
|
|
984
|
+
case "splash":
|
|
985
|
+
return choke ? "SplashChoke" : "SplashHit";
|
|
986
|
+
case "china":
|
|
987
|
+
return choke ? "ChinaChoke" : "ChinaHit";
|
|
988
|
+
case "cowbell":
|
|
989
|
+
return "CowbellMediumHit";
|
|
990
|
+
case "snare":
|
|
991
|
+
return "SnareHit";
|
|
992
|
+
case "tom1":
|
|
993
|
+
return "HighTomHit";
|
|
994
|
+
case "tom2":
|
|
995
|
+
return "MidTomHit";
|
|
996
|
+
case "tom3":
|
|
997
|
+
return "LowTomHit";
|
|
998
|
+
case "floor":
|
|
999
|
+
return "VeryLowTomHit";
|
|
1000
|
+
case "kick":
|
|
1001
|
+
return "KickHit";
|
|
746
1002
|
}
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
1003
|
+
}
|
|
1004
|
+
var effectOf = (hit) => hit === "X" || hit === "O" ? ["ac"] : hit === "g" ? ["g"] : [];
|
|
1005
|
+
var NOT_TAB = /[^-0-9xXoOgfdbhprsvt/\\~^().*<>#@+|:\s]|<(?!\d)/;
|
|
1006
|
+
var COUNT = /^\s*(?:[xX]\s*\d{1,3}|\d{1,3}\s*[xX])\s*$/;
|
|
1007
|
+
function splitText(line) {
|
|
1008
|
+
const last = line.lastIndexOf("|");
|
|
1009
|
+
if (last < 0)
|
|
1010
|
+
return { line, text: null };
|
|
1011
|
+
const rest = line.slice(last + 1);
|
|
1012
|
+
const text = rest.trim();
|
|
1013
|
+
if (!text)
|
|
1014
|
+
return { line, text: null };
|
|
1015
|
+
const isText = NOT_TAB.test(text) || COUNT.test(text) || /^\s/.test(rest) && !text.includes("--");
|
|
1016
|
+
return isText ? { line: line.slice(0, last + 1), text } : { line, text: null };
|
|
1017
|
+
}
|
|
1018
|
+
function tabLineOf(raw) {
|
|
1019
|
+
const { line, text } = splitText(raw.trimEnd());
|
|
1020
|
+
let string = null;
|
|
1021
|
+
const m = STRING_PREFIX.exec(line);
|
|
1022
|
+
const body = line.slice(m[0].length);
|
|
1023
|
+
if (STRING_BODY.test(body) && (line.match(/-/g)?.length ?? 0) >= 4 && (line.includes("|") || /^\s*[A-Ga-g][#b]?\s*[-|:]/.test(line)))
|
|
1024
|
+
string = { name: m[1] ?? null, body, offset: m[0].length, barred: /[|:]$/.test(m[0]) };
|
|
1025
|
+
let drum = null;
|
|
1026
|
+
const d = DRUM_LINE.exec(line);
|
|
1027
|
+
const name = d ? d[1].toLowerCase().replace(/[ .-]/g, "") : "";
|
|
1028
|
+
const known = DRUM_NAMES.get(name);
|
|
1029
|
+
if (d && known && (d[2].match(/[^\s|:]/g)?.length ?? 0) >= 4)
|
|
1030
|
+
drum = { drum: known, name, body: d[2], lettered: /^[A-Ga-g]$/.test(d[1]) };
|
|
1031
|
+
return string || drum ? { string, drum, text } : null;
|
|
1032
|
+
}
|
|
1033
|
+
var textsOf = (run) => [
|
|
1034
|
+
...new Set(run.map((l) => l.text).filter((t) => t !== null))
|
|
1035
|
+
];
|
|
1036
|
+
function splitStrings(run) {
|
|
1037
|
+
const out = [];
|
|
1038
|
+
let start = 0;
|
|
1039
|
+
for (let i = 2;i < run.length - 1; i++) {
|
|
1040
|
+
const [a, b] = [run[start].string.name, run[start + 1].string.name];
|
|
1041
|
+
if (a !== null && run[i].string.name === a && run[i + 1].string.name === b && i - start >= 2) {
|
|
1042
|
+
out.push(run.slice(start, i));
|
|
1043
|
+
start = i;
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
out.push(run.slice(start));
|
|
750
1047
|
return out;
|
|
751
1048
|
}
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
}
|
|
1049
|
+
function splitDrums(run) {
|
|
1050
|
+
const out = [];
|
|
1051
|
+
let current = [];
|
|
1052
|
+
for (const line of run) {
|
|
1053
|
+
if (current.some((l) => l.drum.name === line.drum.name)) {
|
|
1054
|
+
out.push(current);
|
|
1055
|
+
current = [];
|
|
1056
|
+
}
|
|
1057
|
+
current.push(line);
|
|
1058
|
+
}
|
|
1059
|
+
out.push(current);
|
|
1060
|
+
return out;
|
|
762
1061
|
}
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
1062
|
+
var PM_LINE = /^[\sPpMm.\-_|=~]*$/;
|
|
1063
|
+
var PM_MARK = /P\.?M/i;
|
|
1064
|
+
function palmMutesOf(line) {
|
|
1065
|
+
if (!PM_LINE.test(line) || !PM_MARK.test(line))
|
|
1066
|
+
return [];
|
|
1067
|
+
const ranges = [];
|
|
1068
|
+
for (let i = 0;i < line.length; i++) {
|
|
1069
|
+
const c = line[i];
|
|
1070
|
+
const mark = (c === "P" || c === "p") && /^\.?[Mm]/.test(line.slice(i + 1, i + 3));
|
|
1071
|
+
if (mark)
|
|
1072
|
+
ranges.push([i, i]);
|
|
1073
|
+
else if (c !== " " && ranges.length)
|
|
1074
|
+
ranges[ranges.length - 1][1] = i;
|
|
1075
|
+
}
|
|
1076
|
+
return ranges;
|
|
775
1077
|
}
|
|
776
|
-
function
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
1078
|
+
function stringSystems(run, above = null) {
|
|
1079
|
+
return splitStrings(run).flatMap((part, index) => {
|
|
1080
|
+
const names = part.map((l) => l.string.name);
|
|
1081
|
+
if (part.length < 3 && names.some((n) => n === null))
|
|
1082
|
+
return [];
|
|
1083
|
+
const lines = part.map((l) => l.string.body);
|
|
1084
|
+
const offset = part[0].string.offset;
|
|
1085
|
+
const muted = new Set;
|
|
1086
|
+
if (index === 0 && above !== null)
|
|
1087
|
+
for (const [a, b] of palmMutesOf(above))
|
|
1088
|
+
for (let col = Math.max(a, offset);col <= b; col++)
|
|
1089
|
+
muted.add(col - offset);
|
|
1090
|
+
const openStart = part.some((l) => !l.string.barred);
|
|
1091
|
+
return [{ kind: "strings", names, lines, texts: textsOf(part), muted, openStart }];
|
|
1092
|
+
});
|
|
785
1093
|
}
|
|
786
|
-
function
|
|
787
|
-
if (
|
|
788
|
-
return
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
1094
|
+
function systemsOfRun(run, above) {
|
|
1095
|
+
if (!run.length)
|
|
1096
|
+
return [];
|
|
1097
|
+
if (run.every((l) => l.drum) && run.some((l) => !l.string || !l.drum.lettered || /[xXoOgfdb#@*+]/.test(l.drum.body)))
|
|
1098
|
+
return splitDrums(run).map((part) => ({
|
|
1099
|
+
kind: "drums",
|
|
1100
|
+
drums: part.map((l) => l.drum.drum),
|
|
1101
|
+
lines: part.map((l) => l.drum.body),
|
|
1102
|
+
texts: textsOf(part)
|
|
1103
|
+
}));
|
|
1104
|
+
if (run.every((l) => l.string))
|
|
1105
|
+
return stringSystems(run, above);
|
|
1106
|
+
const out = [];
|
|
1107
|
+
let stretch = [];
|
|
1108
|
+
for (const l of [...run, null]) {
|
|
1109
|
+
if (l?.string)
|
|
1110
|
+
stretch.push(l);
|
|
1111
|
+
else {
|
|
1112
|
+
if (stretch.length)
|
|
1113
|
+
out.push(...stringSystems(stretch, out.length ? null : above));
|
|
1114
|
+
stretch = [];
|
|
802
1115
|
}
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
const
|
|
808
|
-
let
|
|
809
|
-
let
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
1116
|
+
}
|
|
1117
|
+
return out;
|
|
1118
|
+
}
|
|
1119
|
+
function systemsOf(text) {
|
|
1120
|
+
const systems = [];
|
|
1121
|
+
let run = [];
|
|
1122
|
+
let above = null;
|
|
1123
|
+
let previous = null;
|
|
1124
|
+
for (const raw of text.split(/\r?\n/)) {
|
|
1125
|
+
const line = tabLineOf(raw);
|
|
1126
|
+
if (line) {
|
|
1127
|
+
if (!run.length)
|
|
1128
|
+
above = previous;
|
|
1129
|
+
run.push(line);
|
|
1130
|
+
} else {
|
|
1131
|
+
systems.push(...systemsOfRun(run, above));
|
|
1132
|
+
run = [];
|
|
815
1133
|
}
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
1134
|
+
previous = raw;
|
|
1135
|
+
}
|
|
1136
|
+
systems.push(...systemsOfRun(run, above));
|
|
1137
|
+
return systems;
|
|
1138
|
+
}
|
|
1139
|
+
function barsOf(lines, beatAt) {
|
|
1140
|
+
const width = Math.max(...lines.map((l) => l.length));
|
|
1141
|
+
const padded = lines.map((l) => l.padEnd(width, "-"));
|
|
1142
|
+
const bars = [];
|
|
1143
|
+
let beats = [];
|
|
1144
|
+
let filled = false;
|
|
1145
|
+
let start = 0;
|
|
1146
|
+
for (let col = 0;col < width; col++) {
|
|
1147
|
+
if (padded.every((l) => l[col] === "|" || l[col] === ":")) {
|
|
1148
|
+
if (filled)
|
|
1149
|
+
bars.push({ beats, start, end: col });
|
|
1150
|
+
beats = [];
|
|
1151
|
+
filled = false;
|
|
1152
|
+
start = col + 1;
|
|
820
1153
|
continue;
|
|
821
|
-
const lowest = bar.beats.reduce((low, b) => b.notes.reduce((l, n) => Math.max(l, n.string ?? 0), low), 0);
|
|
822
|
-
const bass = at.filter((_, i) => bar.beats[i].notes.some((n) => n.string === lowest));
|
|
823
|
-
for (const group of [at, bass.length < at.length ? bass : []]) {
|
|
824
|
-
if (group.some((u) => u !== 0 && u % 2 === 0) && group.every((u) => u % 2 === 0))
|
|
825
|
-
twos++;
|
|
826
|
-
else if (group.includes(3) && group.every((u) => u % 3 === 0))
|
|
827
|
-
threes++;
|
|
828
1154
|
}
|
|
1155
|
+
if (padded.some((l) => l[col] !== " "))
|
|
1156
|
+
filled = true;
|
|
1157
|
+
const { beat, skip, at } = beatAt(padded, col);
|
|
1158
|
+
if (beat.length)
|
|
1159
|
+
beats.push({ notes: beat, col: at ?? col });
|
|
1160
|
+
col += skip;
|
|
829
1161
|
}
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
if (most.value === 3)
|
|
834
|
-
return THREE_FOUR;
|
|
835
|
-
if (most.value === 6)
|
|
836
|
-
return twos > threes ? THREE_FOUR : SIX_EIGHT;
|
|
837
|
-
return most.value === 12 ? TWELVE_EIGHT : COMMON;
|
|
1162
|
+
if (filled)
|
|
1163
|
+
bars.push({ beats, start, end: width });
|
|
1164
|
+
return bars;
|
|
838
1165
|
}
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
m.pickup = first;
|
|
888
|
-
}
|
|
1166
|
+
var isDigit = (c) => c !== undefined && c >= "0" && c <= "9";
|
|
1167
|
+
var twoDigits = (a, b) => (a === "1" || a === "2") && isDigit(b) && Number(a + b) <= 24;
|
|
1168
|
+
function techniquesOf(body) {
|
|
1169
|
+
const frets = new Map;
|
|
1170
|
+
const effects = new Map;
|
|
1171
|
+
const hidden = new Set;
|
|
1172
|
+
const target = (at) => {
|
|
1173
|
+
let j = at;
|
|
1174
|
+
const open = body[j] === "(";
|
|
1175
|
+
if (open)
|
|
1176
|
+
j++;
|
|
1177
|
+
if (!isDigit(body[j]))
|
|
1178
|
+
return { fret: null, next: at };
|
|
1179
|
+
const width = twoDigits(body[j], body[j + 1]) ? 2 : 1;
|
|
1180
|
+
const fret = Number(body.slice(j, j + width));
|
|
1181
|
+
for (let w = 0;w < width; w++)
|
|
1182
|
+
hidden.add(j + w);
|
|
1183
|
+
j += width;
|
|
1184
|
+
if (open && body[j] === ")")
|
|
1185
|
+
j++;
|
|
1186
|
+
return { fret, next: j };
|
|
1187
|
+
};
|
|
1188
|
+
for (let i = 0;i < body.length; ) {
|
|
1189
|
+
if (!isDigit(body[i]) || hidden.has(i)) {
|
|
1190
|
+
i++;
|
|
1191
|
+
continue;
|
|
1192
|
+
}
|
|
1193
|
+
const width = twoDigits(body[i], body[i + 1]) ? 2 : 1;
|
|
1194
|
+
const fret = Number(body.slice(i, i + width));
|
|
1195
|
+
frets.set(i, { fret, width });
|
|
1196
|
+
const fx = [];
|
|
1197
|
+
const before = body[i - 1];
|
|
1198
|
+
let k = i + width;
|
|
1199
|
+
if (before === "<" && body[k] === ">") {
|
|
1200
|
+
fx.push("nh");
|
|
1201
|
+
k++;
|
|
1202
|
+
} else if ((before === "/" || before === "\\") && !/[\d)>]/.test(body[i - 2] ?? "-"))
|
|
1203
|
+
fx.push(before === "/" ? "sib" : "sia");
|
|
1204
|
+
if (body[k] === "b" || body[k] === "^") {
|
|
1205
|
+
const up = target(k + 1);
|
|
1206
|
+
k = up.next;
|
|
1207
|
+
const semitones = up.fret !== null && up.fret > fret ? Math.min(up.fret - fret, 4) : 2;
|
|
1208
|
+
const points = [0, semitones * 2];
|
|
1209
|
+
if (body[k] === "r") {
|
|
1210
|
+
const down = target(k + 1);
|
|
1211
|
+
k = down.next;
|
|
1212
|
+
const back = down.fret === null ? 0 : (down.fret - fret) * 2;
|
|
1213
|
+
points.push(Math.min(points[1], Math.max(0, back)));
|
|
889
1214
|
}
|
|
890
|
-
|
|
891
|
-
});
|
|
892
|
-
const target = carry ?? (out.length > before ? out.at(-1) : null);
|
|
893
|
-
if (row.texts.length && target) {
|
|
894
|
-
const text = row.texts.join(" / ");
|
|
895
|
-
target.text = target.text ? `${target.text} / ${text}` : text;
|
|
1215
|
+
fx.push(`b (${points.join(" ")})`);
|
|
896
1216
|
}
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
function splitUnbarred(measures, meter) {
|
|
901
|
-
return measures.flatMap((m) => {
|
|
902
|
-
if (m.part !== "whole" || m.beats.length < 2)
|
|
903
|
-
return [m];
|
|
904
|
-
const cols = m.beats.map((b) => b.col);
|
|
905
|
-
if (positionsOf(cols, m.width, m.pad, meter))
|
|
906
|
-
return [m];
|
|
907
|
-
const gaps = cols.slice(1).map((c, i) => c - cols[i]);
|
|
908
|
-
const unit = mostFrequent(gaps).value;
|
|
909
|
-
const eighths = gaps.reduce((sum, g) => sum + Math.max(1, Math.round(g / unit)), 1);
|
|
910
|
-
const perBar = meter.length / 2;
|
|
911
|
-
const span = unit * perBar;
|
|
912
|
-
if (eighths <= perBar || m.width - m.pad < span * 1.5)
|
|
913
|
-
return [m];
|
|
914
|
-
const count = Math.floor((cols.at(-1) - m.pad) / span) + 1;
|
|
915
|
-
const pieces = Array.from({ length: count }, () => []);
|
|
916
|
-
for (const b of m.beats) {
|
|
917
|
-
let k = Math.min(count - 1, Math.max(0, Math.floor((b.col - m.pad) / span)));
|
|
918
|
-
while (k < count - 1 && b.col >= m.pad + (k + 1) * span)
|
|
1217
|
+
if (body[k] === "~" || body[k] === "v") {
|
|
1218
|
+
fx.push("v");
|
|
1219
|
+
while (body[k] === "~" || body[k] === "v")
|
|
919
1220
|
k++;
|
|
920
|
-
while (k > 0 && b.col < m.pad + k * span)
|
|
921
|
-
k--;
|
|
922
|
-
pieces[k].push({ notes: b.notes, col: b.col - k * span });
|
|
923
1221
|
}
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
});
|
|
934
|
-
});
|
|
935
|
-
}
|
|
936
|
-
var quoted = (text) => `"${text.replace(/[\\"]/g, (c) => `\\${c}`)}"`;
|
|
937
|
-
var withEffects = (tex, effects) => effects.length ? `${tex}{${effects.join(" ")}}` : tex;
|
|
938
|
-
function beatTex(notes, effects) {
|
|
939
|
-
if (!notes.length)
|
|
940
|
-
return withEffects("r", effects);
|
|
941
|
-
if (notes.length === 1)
|
|
942
|
-
return withEffects(notes[0].tex, [...notes[0].effects, ...effects]);
|
|
943
|
-
return withEffects(`(${notes.map((n) => withEffects(n.tex, n.effects)).join(" ")})`, effects);
|
|
944
|
-
}
|
|
945
|
-
var LINKS = new Set(["h", "sl", "sou", "sod"]);
|
|
946
|
-
function tied(notes, pieces) {
|
|
947
|
-
if (pieces === 1)
|
|
948
|
-
return [notes];
|
|
949
|
-
const out = [notes.map((n) => ({ ...n, effects: n.effects.filter((e) => !LINKS.has(e)) }))];
|
|
950
|
-
for (let piece = 1;piece < pieces; piece++)
|
|
951
|
-
out.push(notes.filter((n) => n.string !== undefined).map((n) => ({
|
|
952
|
-
tex: `-.${n.string}`,
|
|
953
|
-
effects: n.effects.filter((e) => e === "pm" || piece === pieces - 1 && LINKS.has(e))
|
|
954
|
-
})));
|
|
955
|
-
return out;
|
|
956
|
-
}
|
|
957
|
-
function texOf(bars, meter) {
|
|
958
|
-
let duration = 0;
|
|
959
|
-
const out = bars.map(({ beats, rhythm, text, pickup }) => {
|
|
960
|
-
const items = [];
|
|
961
|
-
if (!beats.length)
|
|
962
|
-
for (const value of meter === COMMON ? [{ duration: 1, dotted: false }] : valuesOf(meter.length))
|
|
963
|
-
items.push({ notes: [], ...value });
|
|
964
|
-
for (const { beat, sixteenths } of rhythm) {
|
|
965
|
-
const values = valuesOf(sixteenths);
|
|
966
|
-
const notes = tied(beat >= 0 ? beats[beat] : [], values.length);
|
|
967
|
-
values.forEach((value, i) => items.push({ notes: notes[i], ...value }));
|
|
1222
|
+
const next = body[k];
|
|
1223
|
+
const onto = isDigit(body[k + 1]) || body[k + 1] === "(" && isDigit(body[k + 2]);
|
|
1224
|
+
if ((next === "h" || next === "p") && onto)
|
|
1225
|
+
fx.push("h");
|
|
1226
|
+
else if (next === "/" || next === "\\" || next === "s") {
|
|
1227
|
+
if (onto)
|
|
1228
|
+
fx.push("sl");
|
|
1229
|
+
else if (next !== "s")
|
|
1230
|
+
fx.push(next === "/" ? "sou" : "sod");
|
|
968
1231
|
}
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
const tex = items.map((item, i) => {
|
|
975
|
-
const effects = item.dotted ? ["d"] : [];
|
|
976
|
-
if (text && i === annotated)
|
|
977
|
-
effects.push(`txt ${quoted(text)}`);
|
|
978
|
-
const head = item.duration === duration ? "" : `:${item.duration} `;
|
|
979
|
-
duration = item.duration;
|
|
980
|
-
return head + beatTex(item.notes, effects);
|
|
981
|
-
}).join(" ");
|
|
982
|
-
return pickup ? `\\ac ${tex}` : tex;
|
|
983
|
-
});
|
|
984
|
-
return out.join(` |
|
|
985
|
-
`);
|
|
1232
|
+
if (fx.length)
|
|
1233
|
+
effects.set(i, fx);
|
|
1234
|
+
i += width;
|
|
1235
|
+
}
|
|
1236
|
+
return { frets, effects };
|
|
986
1237
|
}
|
|
987
|
-
|
|
988
|
-
const
|
|
989
|
-
const
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
if (s.kind === "drums")
|
|
1000
|
-
rows.push(rowOf(s.lines, barsOf(s.lines, drumBeatAt(s.drums)), s.texts, false));
|
|
1001
|
-
} else {
|
|
1002
|
-
const same = JSON.stringify(tuningOf(first.names));
|
|
1003
|
-
const strings = placed?.strings ?? [];
|
|
1004
|
-
for (const s of systems) {
|
|
1005
|
-
if (s.kind !== "strings" || JSON.stringify(tuningOf(s.names)) !== same)
|
|
1006
|
-
continue;
|
|
1007
|
-
const beatAt = stringBeatAt(s.lines.map(techniquesOf), s.muted, strings);
|
|
1008
|
-
rows.push(rowOf(s.lines, barsOf(s.lines, beatAt), s.texts, s.openStart));
|
|
1238
|
+
var stringBeatAt = (lines, muted, numbers = []) => (padded, col) => {
|
|
1239
|
+
const beat = [];
|
|
1240
|
+
const strings = new Set;
|
|
1241
|
+
let start = col;
|
|
1242
|
+
let wide = false;
|
|
1243
|
+
const read = (i, at) => {
|
|
1244
|
+
const c = padded[i][at];
|
|
1245
|
+
const pm = muted.has(at) ? ["pm"] : [];
|
|
1246
|
+
if (c === "x" || c === "X") {
|
|
1247
|
+
beat.push({ tex: `x.${numbers[i] ?? i + 1}`, effects: pm });
|
|
1248
|
+
strings.add(i);
|
|
1249
|
+
return;
|
|
1009
1250
|
}
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1251
|
+
const note = lines[i].frets.get(at);
|
|
1252
|
+
if (!note)
|
|
1253
|
+
return;
|
|
1254
|
+
if (note.width === 2 && at === col)
|
|
1255
|
+
wide = true;
|
|
1256
|
+
if (padded[i][at - 1] === "<")
|
|
1257
|
+
start = Math.min(start, at - 1);
|
|
1258
|
+
beat.push({
|
|
1259
|
+
tex: `${note.fret}.${numbers[i] ?? i + 1}`,
|
|
1260
|
+
effects: [...lines[i].effects.get(at) ?? [], ...pm],
|
|
1261
|
+
string: numbers[i] ?? i + 1
|
|
1262
|
+
});
|
|
1263
|
+
strings.add(i);
|
|
1264
|
+
};
|
|
1265
|
+
padded.forEach((_, i) => read(i, col));
|
|
1266
|
+
if (wide)
|
|
1267
|
+
padded.forEach((_, i) => strings.has(i) || read(i, col + 1));
|
|
1268
|
+
return { beat, skip: wide ? 1 : 0, at: start };
|
|
1269
|
+
};
|
|
1270
|
+
var BY_COUNT = {
|
|
1271
|
+
3: [64, 59, 55],
|
|
1272
|
+
4: [43, 38, 33, 28],
|
|
1273
|
+
5: [43, 38, 33, 28, 23],
|
|
1274
|
+
6: [64, 59, 55, 50, 45, 40],
|
|
1275
|
+
7: [64, 59, 55, 50, 45, 40, 35]
|
|
1276
|
+
};
|
|
1277
|
+
var BY_NUMBER = [64, 59, 55, 50, 45, 40, 35, 30];
|
|
1278
|
+
var GUITAR = { names: ["E", "A", "D", "G", "B", "E"], midis: [40, 45, 50, 55, 59, 64] };
|
|
1279
|
+
var BASS = ["E A D G", "B E A D G"];
|
|
1280
|
+
var upper = (name) => name[0].toUpperCase() + name.slice(1);
|
|
1281
|
+
function tuningOf(names) {
|
|
1282
|
+
const strings = names.length;
|
|
1283
|
+
if (names.every((n) => n !== null && /^\d$/.test(n)))
|
|
1284
|
+
return names.every((n) => BY_NUMBER[Number(n) - 1]) ? names.map((n) => BY_NUMBER[Number(n) - 1]) : null;
|
|
1285
|
+
if (names.every((n) => n !== null && /^[A-Ga-g]/.test(n))) {
|
|
1286
|
+
const lowFirst = [...names].reverse();
|
|
1287
|
+
const spelled = lowFirst.map(upper).join(" ");
|
|
1288
|
+
if (BASS.includes(spelled))
|
|
1289
|
+
return parseTuning(spelled).map((m) => m - 12).reverse();
|
|
1290
|
+
const starts = [...GUITAR.names.keys()].filter((start) => lowFirst.every((n, i) => GUITAR.names[start + i] === upper(n)));
|
|
1291
|
+
if (starts.length) {
|
|
1292
|
+
const start = starts.length > 1 && lowFirst[0] === "e" ? starts.at(-1) : starts[0];
|
|
1293
|
+
return GUITAR.midis.slice(start, start + strings).reverse();
|
|
1294
|
+
}
|
|
1295
|
+
if (strings === 1) {
|
|
1296
|
+
const chroma = chromaOf(upper(names[0]));
|
|
1297
|
+
return chroma === null ? null : [48 + (chroma - 48 + 120) % 12];
|
|
1298
|
+
}
|
|
1299
|
+
const tuning = parseTuning(spelled);
|
|
1300
|
+
if (tuning)
|
|
1301
|
+
return tuning.reverse();
|
|
1302
|
+
}
|
|
1303
|
+
return BY_COUNT[strings] ?? null;
|
|
1034
1304
|
}
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
[
|
|
1050
|
-
|
|
1051
|
-
["min7", "m7"],
|
|
1052
|
-
["-7", "m7"],
|
|
1053
|
-
["min9", "m9"],
|
|
1054
|
-
["-9", "m9"],
|
|
1055
|
-
["ø", "m7b5"],
|
|
1056
|
-
["ø7", "m7b5"],
|
|
1057
|
-
["m7-5", "m7b5"],
|
|
1058
|
-
["mmaj7", "mMaj7"],
|
|
1059
|
-
["mM7", "mMaj7"],
|
|
1060
|
-
["m(maj7)", "mMaj7"],
|
|
1061
|
-
["-(maj7)", "mMaj7"],
|
|
1062
|
-
["°", "dim"],
|
|
1063
|
-
["°7", "dim7"],
|
|
1064
|
-
["+", "aug"],
|
|
1065
|
-
["sus", "sus4"],
|
|
1066
|
-
["add2", "add9"],
|
|
1067
|
-
["69", "6/9"],
|
|
1068
|
-
["alt", "7alt"],
|
|
1069
|
-
["-5", "Mb5"],
|
|
1070
|
-
["#5", "aug"],
|
|
1071
|
-
["b5", "Mb5"],
|
|
1072
|
-
["maj7b5", "M7b5"],
|
|
1073
|
-
["mmaj9", "mMaj9"],
|
|
1074
|
-
["m6/9", "m69"],
|
|
1075
|
-
["m6add9", "m69"],
|
|
1076
|
-
["sus2sus4", "sus24"]
|
|
1077
|
-
]);
|
|
1078
|
-
function withoutParentheses(suffix) {
|
|
1079
|
-
if (!/[(),]/.test(suffix))
|
|
1080
|
-
return suffix;
|
|
1081
|
-
if (!/^[^(),]*(?:\([^(),]+(?:,[^(),]+)*\)[^(),]*)+$/.test(suffix))
|
|
1305
|
+
function onGuitar(midi) {
|
|
1306
|
+
const tuning = [...BY_COUNT[6]];
|
|
1307
|
+
let index = tuning.indexOf(midi);
|
|
1308
|
+
if (index < 0) {
|
|
1309
|
+
index = tuning.reduce((best, m, i) => Math.abs(m - midi) < Math.abs(tuning[best] - midi) ? i : best, 0);
|
|
1310
|
+
tuning[index] = midi;
|
|
1311
|
+
}
|
|
1312
|
+
return { tuning, string: index + 1 };
|
|
1313
|
+
}
|
|
1314
|
+
function placedOnGuitar(tuning) {
|
|
1315
|
+
if (tuning.length === 1) {
|
|
1316
|
+
const { tuning: six, string } = onGuitar(tuning[0]);
|
|
1317
|
+
return { tuning: six, strings: [string] };
|
|
1318
|
+
}
|
|
1319
|
+
const standard = BY_COUNT[6];
|
|
1320
|
+
if (tuning.length > 5)
|
|
1082
1321
|
return null;
|
|
1083
|
-
|
|
1322
|
+
const at = tuning.map((m) => standard.indexOf(m));
|
|
1323
|
+
if (at[0] < 0 || at.some((i, k) => i !== at[0] + k))
|
|
1324
|
+
return null;
|
|
1325
|
+
return { tuning: [...standard], strings: at.map((i) => i + 1) };
|
|
1084
1326
|
}
|
|
1085
|
-
|
|
1086
|
-
const
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1327
|
+
var drumBeatAt = (drums) => (padded, col) => {
|
|
1328
|
+
const beat = [];
|
|
1329
|
+
padded.forEach((line, i) => {
|
|
1330
|
+
const hit = line[col];
|
|
1331
|
+
if (!/[xXoOgfdb#@*+]/.test(hit))
|
|
1332
|
+
return;
|
|
1333
|
+
const name = articulationOf(drums[i], hit);
|
|
1334
|
+
if (!beat.some((n) => n.tex === name))
|
|
1335
|
+
beat.push({ tex: name, effects: effectOf(hit) });
|
|
1336
|
+
});
|
|
1337
|
+
return { beat, skip: 0 };
|
|
1338
|
+
};
|
|
1339
|
+
var VALUES = [
|
|
1340
|
+
[24, 1, true],
|
|
1341
|
+
[16, 1, false],
|
|
1342
|
+
[12, 2, true],
|
|
1343
|
+
[8, 2, false],
|
|
1344
|
+
[6, 4, true],
|
|
1345
|
+
[4, 4, false],
|
|
1346
|
+
[3, 8, true],
|
|
1347
|
+
[2, 8, false],
|
|
1348
|
+
[1, 16, false]
|
|
1349
|
+
];
|
|
1350
|
+
function valuesOf(sixteenths) {
|
|
1351
|
+
const out = [];
|
|
1352
|
+
for (let left = sixteenths;left > 0; ) {
|
|
1353
|
+
const [length, duration, dotted] = VALUES.find(([n]) => n <= left);
|
|
1354
|
+
out.push({ duration, dotted });
|
|
1355
|
+
left -= length;
|
|
1356
|
+
}
|
|
1357
|
+
return out;
|
|
1093
1358
|
}
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
var
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
const
|
|
1108
|
-
|
|
1109
|
-
return tonic ? `${tonic[0].toUpperCase()}${tonic.slice(1).replace("♯", "#").replace("♭", "b")} ${name}` : name;
|
|
1359
|
+
var COMMON = { ts: [4, 4], length: 16, beat: 4, grids: [1, 2, 4, 8, 16] };
|
|
1360
|
+
var THREE_FOUR = { ts: [3, 4], length: 12, beat: 4, grids: [1, 3, 6, 12] };
|
|
1361
|
+
var SIX_EIGHT = { ts: [6, 8], length: 12, beat: 6, grids: [1, 2, 6, 12] };
|
|
1362
|
+
var TWELVE_EIGHT = { ts: [12, 8], length: 24, beat: 6, grids: [1, 2, 4, 12, 24] };
|
|
1363
|
+
function keepsSpacing(cols, at) {
|
|
1364
|
+
const lengths = new Map;
|
|
1365
|
+
for (let i = 1;i < cols.length; i++) {
|
|
1366
|
+
const gap = cols[i] - cols[i - 1];
|
|
1367
|
+
const length = at[i] - at[i - 1];
|
|
1368
|
+
if ((lengths.get(gap) ?? length) !== length)
|
|
1369
|
+
return false;
|
|
1370
|
+
lengths.set(gap, length);
|
|
1371
|
+
}
|
|
1372
|
+
const sorted = [...lengths].sort((a, b) => a[0] - b[0]);
|
|
1373
|
+
return sorted.every(([, length], i) => i === 0 || length >= sorted[i - 1][1]);
|
|
1110
1374
|
}
|
|
1111
|
-
var
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
var CHARACTERISTIC = {
|
|
1116
|
-
lydian: ["4A"],
|
|
1117
|
-
dorian: ["6M"],
|
|
1118
|
-
mixolydian: ["7m"],
|
|
1119
|
-
phrygian: ["2m"],
|
|
1120
|
-
locrian: ["5d"],
|
|
1121
|
-
minor: ["6m"],
|
|
1122
|
-
"minor blues": ["5d"],
|
|
1123
|
-
"major blues": ["3m"],
|
|
1124
|
-
"harmonic minor": ["7M"],
|
|
1125
|
-
"melodic minor": ["6M", "7M"],
|
|
1126
|
-
"phrygian dominant": ["2m", "3M"]
|
|
1127
|
-
};
|
|
1128
|
-
var MODE_WORDS = /\b(dorian|phrygian|lydian|mixolydian|aeolian|locrian|blues)\b/i;
|
|
1129
|
-
var characteristicIntervals = (type) => CHARACTERISTIC[type] ?? [];
|
|
1130
|
-
var marksByDefault = (written) => MODE_WORDS.test(written);
|
|
1131
|
-
function modesOf(text) {
|
|
1132
|
-
const scale = Scale.get(scaleName(text));
|
|
1133
|
-
if (scale.empty || !scale.tonic)
|
|
1375
|
+
var PLAIN = new Set(VALUES.map(([n]) => n));
|
|
1376
|
+
function fit(cols, n, [origin, span], slack, ties, bar) {
|
|
1377
|
+
const step = span / n;
|
|
1378
|
+
if (step < 1 || ties && !Number.isInteger(step))
|
|
1134
1379
|
return null;
|
|
1135
|
-
const
|
|
1136
|
-
|
|
1380
|
+
const at = [];
|
|
1381
|
+
let error = 0;
|
|
1382
|
+
for (const col of cols) {
|
|
1383
|
+
const exact = (col - origin) / step;
|
|
1384
|
+
const k = Math.round(exact);
|
|
1385
|
+
const off = Math.abs(exact - k) * step;
|
|
1386
|
+
if (k < 0 || k >= n || off > slack + 0.000000001 || at.length && k * (bar / n) <= at.at(-1))
|
|
1387
|
+
return null;
|
|
1388
|
+
error = Math.max(error, off);
|
|
1389
|
+
at.push(k * (bar / n));
|
|
1390
|
+
}
|
|
1391
|
+
if (!ties && at.some((p, i) => !PLAIN.has((at[i + 1] ?? bar) - p)))
|
|
1137
1392
|
return null;
|
|
1138
|
-
return
|
|
1393
|
+
return keepsSpacing(cols, at) ? { at, error } : null;
|
|
1139
1394
|
}
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
const
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1395
|
+
function positionsOf(cols, width, pad, meter = COMMON) {
|
|
1396
|
+
if (!cols.length)
|
|
1397
|
+
return [];
|
|
1398
|
+
const spans = [
|
|
1399
|
+
[pad, width - pad],
|
|
1400
|
+
[pad, width]
|
|
1401
|
+
];
|
|
1402
|
+
for (let start = 1;start < pad; start++)
|
|
1403
|
+
spans.push([start, width - start]);
|
|
1404
|
+
if (cols[0] > pad)
|
|
1405
|
+
spans.push([0, width]);
|
|
1406
|
+
for (const [slack, ties] of [
|
|
1407
|
+
[0.4, false],
|
|
1408
|
+
[1, false],
|
|
1409
|
+
[0.4, true]
|
|
1410
|
+
])
|
|
1411
|
+
for (const n of meter.grids) {
|
|
1412
|
+
const fits = spans.map((span) => fit(cols, n, span, slack, ties, meter.length)).filter((f) => f !== null);
|
|
1413
|
+
if (fits.length)
|
|
1414
|
+
return fits.reduce((a, b) => b.error < a.error ? b : a).at;
|
|
1415
|
+
}
|
|
1416
|
+
return null;
|
|
1417
|
+
}
|
|
1418
|
+
function restsFrom(at, meter, end = meter.length) {
|
|
1419
|
+
const out = [];
|
|
1420
|
+
const { beat, length: bar } = meter;
|
|
1421
|
+
for (let p = at;p < end; ) {
|
|
1422
|
+
const half = bar === 4 * beat && p % (2 * beat) === 0 && p <= bar / 2 ? [2 * beat] : [];
|
|
1423
|
+
const lengths = p % 2 ? [1] : p % beat ? [2, 1] : [...half, beat, 2, 1];
|
|
1424
|
+
const length = lengths.find((n) => n <= end - p);
|
|
1425
|
+
out.push({ beat: -1, sixteenths: length });
|
|
1426
|
+
p += length;
|
|
1427
|
+
}
|
|
1428
|
+
return out;
|
|
1429
|
+
}
|
|
1430
|
+
function sketchRhythmOf(cols, meter = COMMON, legato = []) {
|
|
1431
|
+
const gaps = cols.slice(1).map((c, i) => c - cols[i]);
|
|
1432
|
+
const counts = new Map;
|
|
1433
|
+
for (const g of gaps)
|
|
1434
|
+
counts.set(g, (counts.get(g) ?? 0) + 1);
|
|
1435
|
+
const unit = [...counts].reduce((best, e) => !best || e[1] > best[1] || e[1] === best[1] && e[0] < best[0] ? e : best, null)?.[0];
|
|
1436
|
+
for (const eighth of [2, 1]) {
|
|
1437
|
+
const lengths = cols.map((_, i) => eighth * (i < gaps.length ? Math.max(1, Math.round(gaps[i] / unit)) : 1));
|
|
1438
|
+
let total = lengths.reduce((a, b) => a + b, 0);
|
|
1439
|
+
if (eighth === 2)
|
|
1440
|
+
for (const i of legato) {
|
|
1441
|
+
if (total <= meter.length)
|
|
1442
|
+
break;
|
|
1443
|
+
if (i + 1 >= lengths.length || lengths[i] !== 2)
|
|
1444
|
+
continue;
|
|
1445
|
+
const next = Math.max(1, lengths[i + 1] - 1);
|
|
1446
|
+
total -= 1 + lengths[i + 1] - next;
|
|
1447
|
+
lengths[i] = 1;
|
|
1448
|
+
lengths[i + 1] = next;
|
|
1449
|
+
}
|
|
1450
|
+
if (total > meter.length)
|
|
1451
|
+
continue;
|
|
1452
|
+
return [
|
|
1453
|
+
...lengths.map((sixteenths, beat) => ({ beat, sixteenths })),
|
|
1454
|
+
...restsFrom(total, meter)
|
|
1455
|
+
];
|
|
1150
1456
|
}
|
|
1151
|
-
return {
|
|
1457
|
+
return cols.map((_, beat) => ({ beat, sixteenths: 1 }));
|
|
1152
1458
|
}
|
|
1153
|
-
var
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
const
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1459
|
+
var LEGATO = new Set(["h", "sl"]);
|
|
1460
|
+
var legatoOf = (beats) => beats.flatMap((b, i) => b.notes.some((n) => n.effects.some((e) => LEGATO.has(e))) ? [i] : []);
|
|
1461
|
+
function rhythmOf(m, typical, meter) {
|
|
1462
|
+
const bar = meter.length;
|
|
1463
|
+
const span = m.part === "whole" ? m.width : typical;
|
|
1464
|
+
const shift = m.part === "end" ? typical - m.width : 0;
|
|
1465
|
+
const cols = m.beats.map((b) => b.col + shift);
|
|
1466
|
+
if (m.part === "start" && cols.length) {
|
|
1467
|
+
const at = positionsOf([...cols, m.width], span, m.pad, meter);
|
|
1468
|
+
if (at) {
|
|
1469
|
+
const end = at.pop();
|
|
1470
|
+
const out = at[0] > 0 ? [{ beat: -1, sixteenths: at[0] }] : [];
|
|
1471
|
+
at.forEach((p, beat) => out.push({ beat, sixteenths: (at[beat + 1] ?? end) - p }));
|
|
1472
|
+
return [...out, ...restsFrom(end, meter)];
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
const at = positionsOf(cols, span, m.pad, meter);
|
|
1476
|
+
if (!at) {
|
|
1477
|
+
const sketch = sketchRhythmOf(m.beats.map((b) => b.col), meter, legatoOf(m.beats));
|
|
1478
|
+
if (m.part !== "end")
|
|
1479
|
+
return sketch;
|
|
1480
|
+
const notes = sketch.filter((e) => e.beat >= 0);
|
|
1481
|
+
const total = notes.reduce((sum, e) => sum + e.sixteenths, 0);
|
|
1482
|
+
return m.pickup ? notes : [...restsFrom(0, meter, bar - total), ...notes];
|
|
1483
|
+
}
|
|
1484
|
+
const first = at[0];
|
|
1485
|
+
const out = first === 0 || m.pickup ? [] : m.part === "end" ? restsFrom(0, meter, first) : [{ beat: -1, sixteenths: first }];
|
|
1486
|
+
at.forEach((p, beat) => out.push({ beat, sixteenths: (at[beat + 1] ?? bar) - p }));
|
|
1487
|
+
return out;
|
|
1167
1488
|
}
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
const
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1489
|
+
var padOf = (bars) => bars.reduce((pad, b) => b.beats.length ? Math.min(pad, b.beats[0].col - b.start) : pad, 3);
|
|
1490
|
+
function rowOf(lines, bars, texts, openStart) {
|
|
1491
|
+
const width = Math.max(...lines.map((l) => l.length));
|
|
1492
|
+
return {
|
|
1493
|
+
bars,
|
|
1494
|
+
pad: padOf(bars),
|
|
1495
|
+
texts,
|
|
1496
|
+
openStart: openStart && bars[0]?.start === 0,
|
|
1497
|
+
openEnd: bars.at(-1)?.end === width
|
|
1498
|
+
};
|
|
1174
1499
|
}
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
if (quality === "m")
|
|
1188
|
-
return `b${number}`;
|
|
1189
|
-
if (quality.startsWith("A"))
|
|
1190
|
-
return `${"#".repeat(quality.length)}${number}`;
|
|
1191
|
-
return `${"b".repeat(quality.length + (perfect ? 0 : 1))}${number}`;
|
|
1500
|
+
function typicalWidth(rows) {
|
|
1501
|
+
const widths = [];
|
|
1502
|
+
for (const row of rows)
|
|
1503
|
+
row.bars.forEach((bar, i) => {
|
|
1504
|
+
const closed = (i > 0 || !row.openStart) && (i < row.bars.length - 1 || !row.openEnd);
|
|
1505
|
+
if (closed && bar.beats.length)
|
|
1506
|
+
widths.push(bar.end - bar.start);
|
|
1507
|
+
});
|
|
1508
|
+
if (widths.length < 2)
|
|
1509
|
+
return null;
|
|
1510
|
+
widths.sort((a, b) => a - b);
|
|
1511
|
+
return widths[widths.length >> 1];
|
|
1192
1512
|
}
|
|
1193
|
-
function
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1513
|
+
function mostFrequent(values) {
|
|
1514
|
+
const counts = new Map;
|
|
1515
|
+
for (const v of values)
|
|
1516
|
+
counts.set(v, (counts.get(v) ?? 0) + 1);
|
|
1517
|
+
let best;
|
|
1518
|
+
for (const [value, count] of counts)
|
|
1519
|
+
if (!best || count > best.count || count === best.count && value < best.value)
|
|
1520
|
+
best = { value, count };
|
|
1521
|
+
return best;
|
|
1522
|
+
}
|
|
1523
|
+
function meterOf(rows, typical) {
|
|
1524
|
+
if (typical === null)
|
|
1525
|
+
return COMMON;
|
|
1526
|
+
const bars = [];
|
|
1527
|
+
for (const row of rows)
|
|
1528
|
+
row.bars.forEach((bar, i) => {
|
|
1529
|
+
const closed = (i > 0 || !row.openStart) && (i < row.bars.length - 1 || !row.openEnd);
|
|
1530
|
+
const width = bar.end - bar.start;
|
|
1531
|
+
if (closed && bar.beats.length && Math.abs(width - typical) <= 1)
|
|
1532
|
+
bars.push({ bar, pad: row.pad });
|
|
1533
|
+
});
|
|
1534
|
+
const gaps = new Map;
|
|
1535
|
+
for (const { bar } of bars)
|
|
1536
|
+
for (let i = 1;i < bar.beats.length; i++) {
|
|
1537
|
+
const gap = bar.beats[i].col - bar.beats[i - 1].col;
|
|
1538
|
+
gaps.set(gap, (gaps.get(gap) ?? 0) + 1);
|
|
1539
|
+
}
|
|
1540
|
+
const top = Math.max(0, ...gaps.values());
|
|
1541
|
+
const unit = Math.min(...[...gaps].filter(([, n]) => n * 2 >= top).map(([gap]) => gap));
|
|
1542
|
+
if (bars.length < 2 || !Number.isFinite(unit))
|
|
1543
|
+
return COMMON;
|
|
1544
|
+
const counts = [];
|
|
1545
|
+
let twos = 0;
|
|
1546
|
+
let threes = 0;
|
|
1547
|
+
for (const { bar, pad } of bars) {
|
|
1548
|
+
const exact = bar.beats.map((b) => (b.col - bar.start - pad) / unit);
|
|
1549
|
+
if (exact.some((u) => Math.abs(u - Math.round(u)) * unit > 0.4 + 0.000000001)) {
|
|
1550
|
+
counts.push(0);
|
|
1551
|
+
continue;
|
|
1552
|
+
}
|
|
1553
|
+
const at = exact.map(Math.round);
|
|
1554
|
+
const count = Math.max(Math.ceil((bar.end - bar.start - pad) / unit - 0.5), at.at(-1) + 1);
|
|
1555
|
+
counts.push(count);
|
|
1556
|
+
if (count !== 6)
|
|
1557
|
+
continue;
|
|
1558
|
+
const lowest = bar.beats.reduce((low, b) => b.notes.reduce((l, n) => Math.max(l, n.string ?? 0), low), 0);
|
|
1559
|
+
const bass = at.filter((_, i) => bar.beats[i].notes.some((n) => n.string === lowest));
|
|
1560
|
+
for (const group of [at, bass.length < at.length ? bass : []]) {
|
|
1561
|
+
if (group.some((u) => u !== 0 && u % 2 === 0) && group.every((u) => u % 2 === 0))
|
|
1562
|
+
twos++;
|
|
1563
|
+
else if (group.includes(3) && group.every((u) => u % 3 === 0))
|
|
1564
|
+
threes++;
|
|
1565
|
+
}
|
|
1205
1566
|
}
|
|
1567
|
+
const most = mostFrequent(counts);
|
|
1568
|
+
if (most.count * 3 < bars.length * 2)
|
|
1569
|
+
return COMMON;
|
|
1570
|
+
if (most.value === 3)
|
|
1571
|
+
return THREE_FOUR;
|
|
1572
|
+
if (most.value === 6)
|
|
1573
|
+
return twos > threes ? THREE_FOUR : SIX_EIGHT;
|
|
1574
|
+
return most.value === 12 ? TWELVE_EIGHT : COMMON;
|
|
1206
1575
|
}
|
|
1207
|
-
|
|
1208
|
-
const
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1576
|
+
function measuresOf(rows, typical) {
|
|
1577
|
+
const short = (width) => typical !== null && width <= typical * 2 / 3;
|
|
1578
|
+
const out = [];
|
|
1579
|
+
let carry = null;
|
|
1580
|
+
rows.forEach((row, r) => {
|
|
1581
|
+
const before = out.length;
|
|
1582
|
+
const next = rows[r + 1];
|
|
1583
|
+
row.bars.forEach((bar, i) => {
|
|
1584
|
+
const beats = bar.beats.map((b) => ({ notes: b.notes, col: b.col - bar.start }));
|
|
1585
|
+
let m = {
|
|
1586
|
+
beats,
|
|
1587
|
+
width: bar.end - bar.start,
|
|
1588
|
+
pad: row.pad,
|
|
1589
|
+
part: "whole",
|
|
1590
|
+
pickup: false,
|
|
1591
|
+
text: null
|
|
1592
|
+
};
|
|
1593
|
+
const joined = i === 0 && carry !== null;
|
|
1594
|
+
if (carry && i === 0) {
|
|
1595
|
+
const shift = carry.width - row.pad;
|
|
1596
|
+
m = {
|
|
1597
|
+
...carry,
|
|
1598
|
+
beats: [
|
|
1599
|
+
...carry.beats,
|
|
1600
|
+
...beats.map((b) => ({ notes: b.notes, col: b.col + shift }))
|
|
1601
|
+
],
|
|
1602
|
+
width: carry.width + m.width - row.pad
|
|
1603
|
+
};
|
|
1604
|
+
carry = null;
|
|
1605
|
+
}
|
|
1606
|
+
if (i === row.bars.length - 1 && short(m.width)) {
|
|
1607
|
+
const after = next?.bars[0];
|
|
1608
|
+
const together = after ? m.width + after.end - after.start - next.pad : 0;
|
|
1609
|
+
if (after && (row.openEnd || short(after.end - after.start) && (next.openStart || together <= typical * 1.25))) {
|
|
1610
|
+
if (m.beats.length || !row.openEnd)
|
|
1611
|
+
carry = m;
|
|
1612
|
+
return;
|
|
1613
|
+
}
|
|
1614
|
+
if (row.openEnd && !joined) {
|
|
1615
|
+
if (!m.beats.length)
|
|
1616
|
+
return;
|
|
1617
|
+
m.part = "start";
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1620
|
+
const first = !out.length;
|
|
1621
|
+
if (i === 0 && !joined && m.part === "whole" && short(m.width) && m.beats.length) {
|
|
1622
|
+
if (first || row.openStart) {
|
|
1623
|
+
m.part = "end";
|
|
1624
|
+
m.pickup = first;
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1627
|
+
out.push(m);
|
|
1628
|
+
});
|
|
1629
|
+
const target = carry ?? (out.length > before ? out.at(-1) : null);
|
|
1630
|
+
if (row.texts.length && target) {
|
|
1631
|
+
const text = row.texts.join(" / ");
|
|
1632
|
+
target.text = target.text ? `${target.text} / ${text}` : text;
|
|
1633
|
+
}
|
|
1634
|
+
});
|
|
1635
|
+
return out;
|
|
1636
|
+
}
|
|
1637
|
+
function splitUnbarred(measures, meter) {
|
|
1638
|
+
return measures.flatMap((m) => {
|
|
1639
|
+
if (m.part !== "whole" || m.beats.length < 2)
|
|
1640
|
+
return [m];
|
|
1641
|
+
const cols = m.beats.map((b) => b.col);
|
|
1642
|
+
if (positionsOf(cols, m.width, m.pad, meter))
|
|
1643
|
+
return [m];
|
|
1644
|
+
const gaps = cols.slice(1).map((c, i) => c - cols[i]);
|
|
1645
|
+
const unit = mostFrequent(gaps).value;
|
|
1646
|
+
const eighths = gaps.reduce((sum, g) => sum + Math.max(1, Math.round(g / unit)), 1);
|
|
1647
|
+
const perBar = meter.length / 2;
|
|
1648
|
+
const span = unit * perBar;
|
|
1649
|
+
if (eighths <= perBar || m.width - m.pad < span * 1.5)
|
|
1650
|
+
return [m];
|
|
1651
|
+
const count = Math.floor((cols.at(-1) - m.pad) / span) + 1;
|
|
1652
|
+
const pieces = Array.from({ length: count }, () => []);
|
|
1653
|
+
for (const b of m.beats) {
|
|
1654
|
+
let k = Math.min(count - 1, Math.max(0, Math.floor((b.col - m.pad) / span)));
|
|
1655
|
+
while (k < count - 1 && b.col >= m.pad + (k + 1) * span)
|
|
1656
|
+
k++;
|
|
1657
|
+
while (k > 0 && b.col < m.pad + k * span)
|
|
1658
|
+
k--;
|
|
1659
|
+
pieces[k].push({ notes: b.notes, col: b.col - k * span });
|
|
1660
|
+
}
|
|
1661
|
+
return pieces.map((beats, k) => {
|
|
1662
|
+
return {
|
|
1663
|
+
beats,
|
|
1664
|
+
width: m.pad + span,
|
|
1665
|
+
pad: m.pad,
|
|
1666
|
+
part: "whole",
|
|
1667
|
+
pickup: false,
|
|
1668
|
+
text: k === count - 1 ? m.text : null
|
|
1669
|
+
};
|
|
1218
1670
|
});
|
|
1219
1671
|
});
|
|
1220
|
-
if (!members.length)
|
|
1221
|
-
return null;
|
|
1222
|
-
return {
|
|
1223
|
-
title,
|
|
1224
|
-
members,
|
|
1225
|
-
root: intervals ? members[0].chroma : null,
|
|
1226
|
-
pitches: null,
|
|
1227
|
-
preferFlats: names.some(isFlat)
|
|
1228
|
-
};
|
|
1229
|
-
};
|
|
1230
|
-
function chordNoteSet(symbol) {
|
|
1231
|
-
const parts = splitChordSymbol(symbol);
|
|
1232
|
-
if (!parts)
|
|
1233
|
-
return null;
|
|
1234
|
-
const chord = Chord.getChord(canonicalSuffix(parts.suffix), parts.root);
|
|
1235
|
-
if (chord.empty)
|
|
1236
|
-
return null;
|
|
1237
|
-
const bass = parts.bass;
|
|
1238
|
-
const set = fromNames(symbol.trim(), chord.notes, chord.intervals, true);
|
|
1239
|
-
const bassChroma = bass ? chromaOf(bass) : null;
|
|
1240
|
-
if (set && bass && bassChroma !== null && !memberFor(set, bassChroma)) {
|
|
1241
|
-
set.members.push({ chroma: bassChroma, name: bass, degree: null, interval: null });
|
|
1242
|
-
}
|
|
1243
|
-
return set;
|
|
1244
|
-
}
|
|
1245
|
-
function respell(set, chord) {
|
|
1246
|
-
set.root = chord.root;
|
|
1247
|
-
for (const member of set.members) {
|
|
1248
|
-
const own = memberFor(chord, member.chroma);
|
|
1249
|
-
if (own)
|
|
1250
|
-
member.name = own.name;
|
|
1251
|
-
}
|
|
1252
|
-
}
|
|
1253
|
-
function scaleNoteSet(name) {
|
|
1254
|
-
const scale = Scale2.get(scaleName(name));
|
|
1255
|
-
if (scale.empty || !scale.tonic)
|
|
1256
|
-
return null;
|
|
1257
|
-
const { notes, intervals } = scaleSpelling(scale);
|
|
1258
|
-
const set = fromNames(name.trim(), notes, intervals);
|
|
1259
|
-
if (set)
|
|
1260
|
-
set.scaleType = scale.type;
|
|
1261
|
-
return set;
|
|
1262
|
-
}
|
|
1263
|
-
function rootNameOf(text) {
|
|
1264
|
-
const name = text.trim().replace(/-?\d$/, "").replace(/♯/g, "#").replace(/♭/g, "b");
|
|
1265
|
-
if (chromaOf(name) === null)
|
|
1266
|
-
return null;
|
|
1267
|
-
return name[0].toUpperCase() + name.slice(1);
|
|
1268
1672
|
}
|
|
1269
|
-
var
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
return "1P";
|
|
1278
|
-
const spelled = Interval.distance(from, to);
|
|
1279
|
-
const m = /^(\d+)([PMmdA]+)$/.exec(spelled);
|
|
1280
|
-
return m && m[1] !== "1" && m[1] !== "8" ? spelled : PLAIN_INTERVALS[semitones];
|
|
1673
|
+
var quoted = (text) => `"${text.replace(/[\\"]/g, (c) => `\\${c}`)}"`;
|
|
1674
|
+
var withEffects = (tex, effects) => effects.length ? `${tex}{${effects.join(" ")}}` : tex;
|
|
1675
|
+
function beatTex(notes, effects) {
|
|
1676
|
+
if (!notes.length)
|
|
1677
|
+
return withEffects("r", effects);
|
|
1678
|
+
if (notes.length === 1)
|
|
1679
|
+
return withEffects(notes[0].tex, [...notes[0].effects, ...effects]);
|
|
1680
|
+
return withEffects(`(${notes.map((n) => withEffects(n.tex, n.effects)).join(" ")})`, effects);
|
|
1281
1681
|
}
|
|
1282
|
-
|
|
1283
|
-
|
|
1682
|
+
var LINKS = new Set(["h", "sl", "sou", "sod"]);
|
|
1683
|
+
function tied(notes, pieces) {
|
|
1684
|
+
if (pieces === 1)
|
|
1685
|
+
return [notes];
|
|
1686
|
+
const out = [notes.map((n) => ({ ...n, effects: n.effects.filter((e) => !LINKS.has(e)) }))];
|
|
1687
|
+
for (let piece = 1;piece < pieces; piece++)
|
|
1688
|
+
out.push(notes.filter((n) => n.string !== undefined).map((n) => ({
|
|
1689
|
+
tex: `-.${n.string}`,
|
|
1690
|
+
effects: n.effects.filter((e) => e === "pm" || piece === pieces - 1 && LINKS.has(e))
|
|
1691
|
+
})));
|
|
1692
|
+
return out;
|
|
1284
1693
|
}
|
|
1285
|
-
function
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1694
|
+
function texOf(bars, meter) {
|
|
1695
|
+
let duration = 0;
|
|
1696
|
+
const out = bars.map(({ beats, rhythm, text, pickup }) => {
|
|
1697
|
+
const items = [];
|
|
1698
|
+
if (!beats.length)
|
|
1699
|
+
for (const value of meter === COMMON ? [{ duration: 1, dotted: false }] : valuesOf(meter.length))
|
|
1700
|
+
items.push({ notes: [], ...value });
|
|
1701
|
+
for (const { beat, sixteenths } of rhythm) {
|
|
1702
|
+
const values = valuesOf(sixteenths);
|
|
1703
|
+
const notes = tied(beat >= 0 ? beats[beat] : [], values.length);
|
|
1704
|
+
values.forEach((value, i) => items.push({ notes: notes[i], ...value }));
|
|
1705
|
+
}
|
|
1706
|
+
let annotated = items.length - 1;
|
|
1707
|
+
while (annotated > 0 && !items[annotated].notes.length)
|
|
1708
|
+
annotated--;
|
|
1709
|
+
if (!items[annotated].notes.length)
|
|
1710
|
+
annotated = items.length - 1;
|
|
1711
|
+
const tex = items.map((item, i) => {
|
|
1712
|
+
const effects = item.dotted ? ["d"] : [];
|
|
1713
|
+
if (text && i === annotated)
|
|
1714
|
+
effects.push(`txt ${quoted(text)}`);
|
|
1715
|
+
const head = item.duration === duration ? "" : `:${item.duration} `;
|
|
1716
|
+
duration = item.duration;
|
|
1717
|
+
return head + beatTex(item.notes, effects);
|
|
1718
|
+
}).join(" ");
|
|
1719
|
+
return pickup ? `\\ac ${tex}` : tex;
|
|
1720
|
+
});
|
|
1721
|
+
return out.join(` |
|
|
1722
|
+
`);
|
|
1310
1723
|
}
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
[/^(dim7|°7)$/, "Diminished 7"],
|
|
1316
|
-
[/^(maj9|M9|Δ9)$/, "Major 9"],
|
|
1317
|
-
[/^(maj7|M7|Δ7?)$/, "Major 7"],
|
|
1318
|
-
[/^(7sus4)$/, "7sus4"],
|
|
1319
|
-
[/^(m9|min9|-9)$/, "Minor 9"],
|
|
1320
|
-
[/^(m7|min7|-7)$/, "Minor 7"],
|
|
1321
|
-
[/^(m6|min6|-6)$/, "Minor 6"],
|
|
1322
|
-
[/^(m|min|-)$/, "Minor"],
|
|
1323
|
-
[/^(dim|°)$/, "Diminished"],
|
|
1324
|
-
[/^(aug|\+|\+5|#5)$/, "Augmented"],
|
|
1325
|
-
[/^(sus2)$/, "Sus2"],
|
|
1326
|
-
[/^(sus4|sus)$/, "Sus4"],
|
|
1327
|
-
[/^(add9|add2)$/, "Add9"],
|
|
1328
|
-
[/^5$/, "5 (Power)"],
|
|
1329
|
-
[/^(6\/9|69)$/, "6/9"],
|
|
1330
|
-
[/^(m6\/9|m69|m6add9)$/, "Minor 6/9"],
|
|
1331
|
-
[/^(Mb5|b5|-5)$/, "Major flat 5"],
|
|
1332
|
-
[/^(mM7|mMaj7|mmaj7|m\(maj7\)|-\(maj7\))$/, "Minor major 7"],
|
|
1333
|
-
[/^(13|11|9|7|6)$/, "$1"],
|
|
1334
|
-
[/^(maj|M)?$/, "Major"]
|
|
1335
|
-
];
|
|
1336
|
-
var ACCIDENTAL_WORDS = {
|
|
1337
|
-
"#": " Sharp",
|
|
1338
|
-
"##": " Double Sharp",
|
|
1339
|
-
b: " Flat",
|
|
1340
|
-
bb: " Double Flat"
|
|
1341
|
-
};
|
|
1342
|
-
var spellNote = (note) => note[0] + (ACCIDENTAL_WORDS[note.slice(1)] ?? "");
|
|
1343
|
-
var plain = (quality) => quality.replace(/\s*\([^)]*\)/g, "").trim();
|
|
1344
|
-
function parseChord(symbol) {
|
|
1345
|
-
const parts = splitChordSymbol(symbol);
|
|
1346
|
-
if (!parts)
|
|
1724
|
+
function textTabToAlphaTex(text) {
|
|
1725
|
+
const systems = systemsOf(text);
|
|
1726
|
+
const first = systems[0];
|
|
1727
|
+
if (!first)
|
|
1347
1728
|
return null;
|
|
1348
|
-
|
|
1349
|
-
const
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
if (
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1729
|
+
let tuning = first.kind === "strings" ? tuningOf(first.names) : null;
|
|
1730
|
+
const placed = tuning ? placedOnGuitar(tuning) : null;
|
|
1731
|
+
if (placed)
|
|
1732
|
+
tuning = placed.tuning;
|
|
1733
|
+
const rows = [];
|
|
1734
|
+
if (first.kind === "drums") {
|
|
1735
|
+
for (const s of systems)
|
|
1736
|
+
if (s.kind === "drums")
|
|
1737
|
+
rows.push(rowOf(s.lines, barsOf(s.lines, drumBeatAt(s.drums)), s.texts, false));
|
|
1738
|
+
} else {
|
|
1739
|
+
const same = JSON.stringify(tuningOf(first.names));
|
|
1740
|
+
const strings = placed?.strings ?? [];
|
|
1741
|
+
for (const s of systems) {
|
|
1742
|
+
if (s.kind !== "strings" || JSON.stringify(tuningOf(s.names)) !== same)
|
|
1743
|
+
continue;
|
|
1744
|
+
const beatAt = stringBeatAt(s.lines.map(techniquesOf), s.muted, strings);
|
|
1745
|
+
rows.push(rowOf(s.lines, barsOf(s.lines, beatAt), s.texts, s.openStart));
|
|
1359
1746
|
}
|
|
1360
|
-
if (quality)
|
|
1361
|
-
break;
|
|
1362
1747
|
}
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1748
|
+
const typical = typicalWidth(rows);
|
|
1749
|
+
const meter = meterOf(rows, typical);
|
|
1750
|
+
const bars = splitUnbarred(measuresOf(rows, typical), meter).map((m) => ({
|
|
1751
|
+
beats: m.beats.map((b) => b.notes),
|
|
1752
|
+
rhythm: rhythmOf(m, typical ?? 0, meter),
|
|
1753
|
+
text: m.text,
|
|
1754
|
+
pickup: m.pickup
|
|
1755
|
+
}));
|
|
1756
|
+
if (!bars.length)
|
|
1368
1757
|
return null;
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1758
|
+
const ts = meter === COMMON ? [] : [`\\ts ${meter.ts.join(" ")}`];
|
|
1759
|
+
if (first.kind === "drums")
|
|
1760
|
+
return [
|
|
1761
|
+
"\\instrument percussion",
|
|
1762
|
+
"\\articulation defaults",
|
|
1763
|
+
...ts,
|
|
1764
|
+
texOf(bars, meter)
|
|
1765
|
+
].join(`
|
|
1766
|
+
`);
|
|
1767
|
+
const standard = tuning?.join(" ") === BY_COUNT[6].join(" ");
|
|
1768
|
+
const header = tuning && !standard ? [`\\tuning (${tuning.map((m) => noteOf(m)).join(" ")})`] : [];
|
|
1769
|
+
return [...header, ...ts, texOf(bars, meter)].join(`
|
|
1770
|
+
`);
|
|
1376
1771
|
}
|
|
1377
|
-
|
|
1378
1772
|
// src/convert/chord-sheet.ts
|
|
1379
1773
|
function chordsOf(line) {
|
|
1380
1774
|
const found = [];
|
|
@@ -1852,7 +2246,11 @@ function renderTab(language, source, host, options) {
|
|
|
1852
2246
|
staveProfile: "Default",
|
|
1853
2247
|
resources: colorsOf(el)
|
|
1854
2248
|
},
|
|
1855
|
-
player: {
|
|
2249
|
+
player: {
|
|
2250
|
+
playerMode: at.PlayerMode.Disabled,
|
|
2251
|
+
enableUserInteraction: true,
|
|
2252
|
+
scrollMode: at.ScrollMode.Off
|
|
2253
|
+
}
|
|
1856
2254
|
};
|
|
1857
2255
|
const current = new at.AlphaTabApi(surface, settings);
|
|
1858
2256
|
api = current;
|
|
@@ -1986,6 +2384,11 @@ function soundfontPlayer(alphaTab, api) {
|
|
|
1986
2384
|
stopped = true;
|
|
1987
2385
|
clearTimeout(timer);
|
|
1988
2386
|
player.stop();
|
|
2387
|
+
},
|
|
2388
|
+
setVolume(next) {
|
|
2389
|
+
if (stopped || !Number.isFinite(next))
|
|
2390
|
+
return;
|
|
2391
|
+
current.masterVolume = Math.min(1, Math.max(0, next));
|
|
1989
2392
|
}
|
|
1990
2393
|
};
|
|
1991
2394
|
}
|
|
@@ -2046,18 +2449,19 @@ function createSoundfontPlayer(alphaTab, assets, doc, fallback) {
|
|
|
2046
2449
|
play(events, options) {
|
|
2047
2450
|
let handle = null;
|
|
2048
2451
|
let stopped = false;
|
|
2452
|
+
let volume = options.volume;
|
|
2049
2453
|
start().then((ok) => {
|
|
2050
2454
|
if (stopped)
|
|
2051
2455
|
return;
|
|
2052
2456
|
try {
|
|
2053
2457
|
if (ok) {
|
|
2054
|
-
handle = inner.play(events, options);
|
|
2458
|
+
handle = inner.play(events, { ...options, volume });
|
|
2055
2459
|
return;
|
|
2056
2460
|
}
|
|
2057
2461
|
} catch {}
|
|
2058
2462
|
if (!fallback)
|
|
2059
2463
|
return;
|
|
2060
|
-
handle = fallback.play(events, options);
|
|
2464
|
+
handle = fallback.play(events, { ...options, volume });
|
|
2061
2465
|
if (!fallback.reportsStart)
|
|
2062
2466
|
options.onStart?.();
|
|
2063
2467
|
});
|
|
@@ -2065,6 +2469,10 @@ function createSoundfontPlayer(alphaTab, assets, doc, fallback) {
|
|
|
2065
2469
|
stop() {
|
|
2066
2470
|
stopped = true;
|
|
2067
2471
|
handle?.stop();
|
|
2472
|
+
},
|
|
2473
|
+
setVolume(next) {
|
|
2474
|
+
volume = next;
|
|
2475
|
+
handle?.setVolume?.(next);
|
|
2068
2476
|
}
|
|
2069
2477
|
};
|
|
2070
2478
|
},
|
|
@@ -2109,5 +2517,5 @@ export {
|
|
|
2109
2517
|
textTabToAlphaTex
|
|
2110
2518
|
};
|
|
2111
2519
|
|
|
2112
|
-
//# debugId=
|
|
2520
|
+
//# debugId=BC271816D895D2D864756E2164756E21
|
|
2113
2521
|
//# sourceMappingURL=index.js.map
|