@dsebastien/music-notation 0.15.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/blocks/renderers.d.ts +6 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1412 -964
- package/dist/index.js.map +19 -18
- package/dist/music-notation.publish.min.js +31 -27
- package/dist/music-notation.tab.min.js +6 -6
- package/dist/publish/auto.d.ts +3 -0
- package/dist/publish/index.js +1402 -964
- package/dist/publish/index.js.map +19 -18
- package/dist/render/dom.d.ts +0 -1
- package/dist/tab/index.js +1626 -1234
- package/dist/tab/index.js.map +7 -6
- package/dist/theory/naming.d.ts +64 -0
- package/dist/voicings/index.js +1209 -751
- package/dist/voicings/index.js.map +8 -6
- package/package.json +1 -1
package/dist/publish/index.js
CHANGED
|
@@ -1,886 +1,1344 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
// src/theory/pitch.ts
|
|
2
|
+
var SHARP_NAMES = [
|
|
3
|
+
"C",
|
|
4
|
+
"C#",
|
|
5
|
+
"D",
|
|
6
|
+
"D#",
|
|
7
|
+
"E",
|
|
8
|
+
"F",
|
|
9
|
+
"F#",
|
|
10
|
+
"G",
|
|
11
|
+
"G#",
|
|
12
|
+
"A",
|
|
13
|
+
"A#",
|
|
14
|
+
"B"
|
|
15
|
+
];
|
|
16
|
+
var FLAT_NAMES = ["C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab", "A", "Bb", "B"];
|
|
17
|
+
var LETTER_CHROMA = { C: 0, D: 2, E: 4, F: 5, G: 7, A: 9, B: 11 };
|
|
18
|
+
function chromaOf(name) {
|
|
19
|
+
const m = /^([A-Ga-g])([#♯b♭]*)$/.exec(name.trim());
|
|
20
|
+
if (!m)
|
|
21
|
+
return null;
|
|
22
|
+
let chroma = LETTER_CHROMA[m[1].toUpperCase()];
|
|
23
|
+
for (const accidental of m[2])
|
|
24
|
+
chroma += accidental === "#" || accidental === "♯" ? 1 : -1;
|
|
25
|
+
return (chroma % 12 + 12) % 12;
|
|
21
26
|
}
|
|
22
|
-
function
|
|
23
|
-
|
|
27
|
+
function midiOf(note) {
|
|
28
|
+
const m = /^([A-Ga-g][#♯b♭]*)(-?\d)$/.exec(note.trim());
|
|
29
|
+
if (!m)
|
|
30
|
+
return null;
|
|
31
|
+
const chroma = chromaOf(m[1]);
|
|
32
|
+
if (chroma === null)
|
|
33
|
+
return null;
|
|
34
|
+
const letter = LETTER_CHROMA[m[1][0].toUpperCase()];
|
|
35
|
+
const shift = Math.round((chroma - letter) / 12);
|
|
36
|
+
return (Number(m[2]) + 1) * 12 + chroma - shift * 12;
|
|
24
37
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
return label;
|
|
38
|
+
var nameOf = (chroma, preferFlats = false) => (preferFlats ? FLAT_NAMES : SHARP_NAMES)[((Math.round(chroma) || 0) % 12 + 12) % 12];
|
|
39
|
+
var doubleSharp = (name) => name.replace(/x$/, "##");
|
|
40
|
+
function splitChordSymbol(symbol) {
|
|
41
|
+
const normalized = symbol.trim().replace(/♯/g, "#").replace(/♭/g, "b").replace(/𝄪/g, "x").replace(/𝄫/g, "bb");
|
|
42
|
+
const m = /^([A-G](?:##|x(?!\d)|bb|#|b)?)(.*?)(?:\/([A-G](?:##|x|bb|#|b)?))?$/.exec(normalized);
|
|
43
|
+
return m ? { root: doubleSharp(m[1]), suffix: m[2], bass: m[3] ? doubleSharp(m[3]) : null } : null;
|
|
33
44
|
}
|
|
34
|
-
|
|
35
|
-
|
|
45
|
+
var noteOf = (midi, preferFlats = false) => `${nameOf(midi, preferFlats)}${Math.floor(midi / 12) - 1}`;
|
|
46
|
+
var isFlat = (name) => /^[A-Ga-g][b♭]/.test(name.trim());
|
|
47
|
+
|
|
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))
|
|
95
|
+
return null;
|
|
96
|
+
return suffix.replace(/[(),\s]/g, "");
|
|
36
97
|
}
|
|
37
|
-
function
|
|
38
|
-
const
|
|
39
|
-
if (
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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;
|
|
44
106
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
107
|
+
|
|
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;
|
|
60
123
|
}
|
|
61
|
-
var
|
|
62
|
-
const
|
|
63
|
-
|
|
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);
|
|
124
|
+
var isScaleWithoutRoot = (text) => {
|
|
125
|
+
const scale = Scale.get(scaleName(text));
|
|
126
|
+
return !scale.empty && !scale.tonic;
|
|
70
127
|
};
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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}`);
|
|
83
152
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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 };
|
|
163
|
+
}
|
|
164
|
+
return { notes: scale.notes, intervals: scale.intervals };
|
|
95
165
|
}
|
|
166
|
+
var scaleTypes = () => Scale.names();
|
|
96
167
|
|
|
97
|
-
// src/
|
|
98
|
-
function
|
|
99
|
-
const
|
|
100
|
-
if (
|
|
101
|
-
|
|
102
|
-
|
|
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(" ")}` : "";
|
|
103
180
|
}
|
|
104
|
-
function
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
function layoutDefaults(value) {
|
|
111
|
-
const result = {};
|
|
112
|
-
if (!value || typeof value !== "object")
|
|
113
|
-
return result;
|
|
114
|
-
const word = (v) => typeof v === "string" ? v.trim().toLowerCase() : undefined;
|
|
115
|
-
try {
|
|
116
|
-
const { orientation, hand } = value;
|
|
117
|
-
const h = word(hand);
|
|
118
|
-
if (h === "left" || h === "right")
|
|
119
|
-
result.hand = h;
|
|
120
|
-
if (orientation && typeof orientation === "object") {
|
|
121
|
-
for (const language of ["chord", "keyboard", "fretboard"]) {
|
|
122
|
-
const o = word(orientation[language]);
|
|
123
|
-
if (o === "vertical" || o === "horizontal")
|
|
124
|
-
(result.orientation ??= {})[language] = o;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
} catch {}
|
|
128
|
-
return result;
|
|
129
|
-
}
|
|
130
|
-
function titleWidth(title) {
|
|
131
|
-
if (!title)
|
|
132
|
-
return 0;
|
|
133
|
-
let width = 8;
|
|
134
|
-
for (const ch of title) {
|
|
135
|
-
width += ch.codePointAt(0) > 591 ? 15 : /[A-Z0-9#♯♭]/.test(ch) ? 10.5 : 8;
|
|
136
|
-
}
|
|
137
|
-
return Math.ceil(width);
|
|
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(" ")}` : "");
|
|
138
187
|
}
|
|
139
|
-
var
|
|
140
|
-
var
|
|
141
|
-
function
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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}`;
|
|
150
205
|
}
|
|
151
|
-
function
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
const next = line ? `${line} ${phrase}` : phrase;
|
|
164
|
-
if (!line || fits(next))
|
|
165
|
-
line = next;
|
|
166
|
-
else {
|
|
167
|
-
lines.push(line);
|
|
168
|
-
line = phrase;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
if (line)
|
|
172
|
-
lines.push(line);
|
|
173
|
-
if (lines.length > MAX_TITLE_LINES) {
|
|
174
|
-
const kept = lines.slice(0, MAX_TITLE_LINES - 1);
|
|
175
|
-
kept.push(lines.slice(MAX_TITLE_LINES - 1).join(" "));
|
|
176
|
-
return kept.map(squeeze);
|
|
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;
|
|
177
218
|
}
|
|
178
|
-
return lines.map(squeeze);
|
|
179
219
|
}
|
|
180
|
-
|
|
181
|
-
const
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
text.setAttribute("y", String(y));
|
|
186
|
-
text.setAttribute("text-anchor", "middle");
|
|
187
|
-
const squeeze = (el, line) => {
|
|
188
|
-
if (line.textLength === null)
|
|
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))
|
|
189
225
|
return;
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
squeeze(text, lines[0]);
|
|
196
|
-
} else {
|
|
197
|
-
lines.forEach((line, i) => {
|
|
198
|
-
const span = doc.createElementNS(NS, "tspan");
|
|
199
|
-
span.setAttribute("x", String(x));
|
|
200
|
-
if (i > 0)
|
|
201
|
-
span.setAttribute("dy", String(TITLE_LINE));
|
|
202
|
-
span.textContent = i > 0 ? ` ${line.text}` : line.text;
|
|
203
|
-
squeeze(span, line);
|
|
204
|
-
text.appendChild(span);
|
|
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
|
|
205
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 });
|
|
206
255
|
}
|
|
207
|
-
|
|
208
|
-
root.appendChild(text);
|
|
209
|
-
return text;
|
|
256
|
+
return set;
|
|
210
257
|
}
|
|
211
|
-
function
|
|
212
|
-
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
continue;
|
|
218
|
-
const shift = missing * TITLE_LINE;
|
|
219
|
-
const doc = d.ownerDocument;
|
|
220
|
-
const g = doc.createElementNS("http://www.w3.org/2000/svg", "g");
|
|
221
|
-
g.setAttribute("class", "mn-title-pad");
|
|
222
|
-
g.setAttribute("transform", `translate(0 ${shift})`);
|
|
223
|
-
for (const child of [...d.children]) {
|
|
224
|
-
if (child.tagName.toLowerCase() !== "defs")
|
|
225
|
-
g.appendChild(child);
|
|
226
|
-
}
|
|
227
|
-
d.appendChild(g);
|
|
228
|
-
const [x, y, w, h] = (d.getAttribute("viewBox") ?? "0 0 0 0").split(/\s+/).map(Number);
|
|
229
|
-
d.setAttribute("viewBox", `${x} ${y} ${w} ${h + shift}`);
|
|
230
|
-
if (d.hasAttribute("height"))
|
|
231
|
-
d.setAttribute("height", String(Number(d.getAttribute("height")) + shift));
|
|
232
|
-
d.setAttribute("data-mn-title-lines", String(most));
|
|
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;
|
|
233
264
|
}
|
|
234
265
|
}
|
|
235
|
-
function
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
const content = vertical ? n.low + n.across + n.high : n.before + n.along + n.after;
|
|
239
|
-
const shift = n.minWidth && n.minWidth > content ? (n.minWidth - content) / 2 : 0;
|
|
240
|
-
const height = n.top + (vertical ? n.before + n.along + n.after : n.high + n.across + n.low);
|
|
241
|
-
const at = (across, along) => {
|
|
242
|
-
if (vertical) {
|
|
243
|
-
const x = left ? n.high + (n.across - across) : n.low + across;
|
|
244
|
-
return [shift + x, n.top + n.before + along];
|
|
245
|
-
}
|
|
246
|
-
const x = left ? content - n.before - along : n.before + along;
|
|
247
|
-
return [shift + x, n.top + n.high + (n.across - across)];
|
|
248
|
-
};
|
|
249
|
-
const box = (a1, l1, a2, l2) => {
|
|
250
|
-
const [x1, y1] = at(a1, l1);
|
|
251
|
-
const [x2, y2] = at(a2, l2);
|
|
252
|
-
return {
|
|
253
|
-
x: Math.min(x1, x2),
|
|
254
|
-
y: Math.min(y1, y2),
|
|
255
|
-
width: Math.abs(x2 - x1),
|
|
256
|
-
height: Math.abs(y2 - y1)
|
|
257
|
-
};
|
|
258
|
-
};
|
|
259
|
-
return { width: content + 2 * shift, height, at, box };
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
// src/theory/pitch.ts
|
|
263
|
-
var SHARP_NAMES = [
|
|
264
|
-
"C",
|
|
265
|
-
"C#",
|
|
266
|
-
"D",
|
|
267
|
-
"D#",
|
|
268
|
-
"E",
|
|
269
|
-
"F",
|
|
270
|
-
"F#",
|
|
271
|
-
"G",
|
|
272
|
-
"G#",
|
|
273
|
-
"A",
|
|
274
|
-
"A#",
|
|
275
|
-
"B"
|
|
276
|
-
];
|
|
277
|
-
var FLAT_NAMES = ["C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab", "A", "Bb", "B"];
|
|
278
|
-
var LETTER_CHROMA = { C: 0, D: 2, E: 4, F: 5, G: 7, A: 9, B: 11 };
|
|
279
|
-
function chromaOf(name) {
|
|
280
|
-
const m = /^([A-Ga-g])([#♯b♭]*)$/.exec(name.trim());
|
|
281
|
-
if (!m)
|
|
266
|
+
function scaleNoteSet(name) {
|
|
267
|
+
const scale = Scale2.get(scaleName(name));
|
|
268
|
+
if (scale.empty || !scale.tonic)
|
|
282
269
|
return null;
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
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;
|
|
287
275
|
}
|
|
288
|
-
function
|
|
289
|
-
const
|
|
290
|
-
if (
|
|
276
|
+
function rootNameOf(text) {
|
|
277
|
+
const name = text.trim().replace(/-?\d$/, "").replace(/♯/g, "#").replace(/♭/g, "b");
|
|
278
|
+
if (chromaOf(name) === null)
|
|
291
279
|
return null;
|
|
292
|
-
|
|
293
|
-
|
|
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)
|
|
294
287
|
return null;
|
|
295
|
-
const
|
|
296
|
-
|
|
297
|
-
|
|
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];
|
|
298
294
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
const
|
|
304
|
-
|
|
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;
|
|
305
323
|
}
|
|
306
|
-
var noteOf = (midi, preferFlats = false) => `${nameOf(midi, preferFlats)}${Math.floor(midi / 12) - 1}`;
|
|
307
|
-
var isFlat = (name) => /^[A-Ga-g][b♭]/.test(name.trim());
|
|
308
324
|
|
|
309
|
-
// src/chord
|
|
310
|
-
var
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
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
|
+
}
|
|
372
|
+
}
|
|
373
|
+
if (quality)
|
|
374
|
+
break;
|
|
375
|
+
}
|
|
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
|
+
};
|
|
315
389
|
}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
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);
|
|
321
401
|
}
|
|
322
|
-
function
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
402
|
+
function namingOf(value) {
|
|
403
|
+
if (typeof value !== "string")
|
|
404
|
+
return null;
|
|
405
|
+
try {
|
|
406
|
+
return parseNaming(value);
|
|
407
|
+
} catch {
|
|
408
|
+
return null;
|
|
409
|
+
}
|
|
326
410
|
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
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 reads = (letters) => midiOf(letters) !== null || /^[A-G]/.test(letters) && parseChord(letters) !== null;
|
|
426
|
+
function rootToken(token, naming, h, solfegeLine = false) {
|
|
427
|
+
const b = naming === "german" ? /^B(?![#♯b♭x])(.*)$/.exec(token) : null;
|
|
428
|
+
if (b && AFTER_ROOT.test(b[1])) {
|
|
429
|
+
const letters = `Bb${b[1]}`;
|
|
430
|
+
if (reads(letters))
|
|
431
|
+
return letters;
|
|
432
|
+
}
|
|
433
|
+
if (naming !== "solfege" && !solfegeLine && reads(token))
|
|
434
|
+
return null;
|
|
435
|
+
const solfege = new RegExp(`^${SYLLABLE}${SIGN}(.*)$`).exec(token);
|
|
436
|
+
if (solfege) {
|
|
437
|
+
for (const sign of [solfege[2] ?? "", ""].filter((s, i, all) => all.indexOf(s) === i)) {
|
|
438
|
+
const rest = token.slice(solfege[1].length + sign.length);
|
|
439
|
+
const letters = `${syllableLetter(solfege[1])}${sign}${rest}`;
|
|
440
|
+
if (AFTER_ROOT.test(rest) && reads(letters))
|
|
441
|
+
return letters;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
if (h) {
|
|
445
|
+
const hm = /^H(##|bb|#|b|♯|♭|x)?(.*)$/.exec(token);
|
|
446
|
+
if (hm && AFTER_ROOT.test(hm[2])) {
|
|
447
|
+
const letters = `B${hm[1] ?? ""}${hm[2]}`;
|
|
448
|
+
if (reads(letters))
|
|
449
|
+
return letters;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
return null;
|
|
332
453
|
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
const
|
|
343
|
-
|
|
344
|
-
|
|
454
|
+
var NOTE_ONLY = /^[A-G](?:##|bb|#|b|♯|♭|x)?$/;
|
|
455
|
+
function letterPiece(piece, naming, h, line = false) {
|
|
456
|
+
if (!piece)
|
|
457
|
+
return piece;
|
|
458
|
+
const lower = plain2(piece);
|
|
459
|
+
if (/^majeure?$/.test(lower))
|
|
460
|
+
return "major";
|
|
461
|
+
if (/^mineure?$/.test(lower))
|
|
462
|
+
return "minor";
|
|
463
|
+
const range = /^(.+\d)-(.+\d)$/.exec(piece);
|
|
464
|
+
if (range) {
|
|
465
|
+
const [from, to] = [range[1], range[2]].map((n) => rootToken(n, naming, h, line) ?? n);
|
|
466
|
+
return `${from}-${to}`;
|
|
467
|
+
}
|
|
468
|
+
const slash = piece.indexOf("/");
|
|
469
|
+
if (slash > 0) {
|
|
470
|
+
const head = piece.slice(0, slash);
|
|
471
|
+
const bass = piece.slice(slash + 1);
|
|
472
|
+
const bassLetters = rootToken(bass, naming, h, line) ?? (NOTE_ONLY.test(bass) ? bass : null);
|
|
473
|
+
if (bassLetters && NOTE_ONLY.test(bassLetters)) {
|
|
474
|
+
const headLetters = rootToken(head, naming, h, line) ?? head;
|
|
475
|
+
const whole = `${headLetters}/${bassLetters}`;
|
|
476
|
+
if (whole !== piece && !(naming === "letters" && !line && reads(piece)))
|
|
477
|
+
return whole;
|
|
478
|
+
return piece;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
return rootToken(piece, naming, h, line) ?? piece;
|
|
482
|
+
}
|
|
483
|
+
function letterWord(word, naming, h, changes, line = false) {
|
|
484
|
+
const out = word.split(/([,|;])/).map((piece, i) => i % 2 ? piece : letterPiece(piece, naming, h, line)).join("");
|
|
485
|
+
if (out !== word)
|
|
486
|
+
changes.push([word, out]);
|
|
487
|
+
return out;
|
|
488
|
+
}
|
|
489
|
+
var syllableOnly = (word) => new RegExp(`^${SYLLABLE}${SIGN}$`).test(word);
|
|
490
|
+
function read(text, naming, options, changes) {
|
|
491
|
+
const h = options.h ?? true;
|
|
492
|
+
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"}`);
|
|
493
|
+
if (options.chord) {
|
|
494
|
+
const joined = new RegExp(`^\\s*${SYLLABLE}${SIGN}\\s+(\\S+)\\s*$`).exec(out);
|
|
495
|
+
if (joined && QUALITY_WORD.test(joined[3])) {
|
|
496
|
+
const word = `${joined[1]}${joined[2] ?? ""}${joined[3]}`;
|
|
497
|
+
const letters = rootToken(word, naming, h) ?? letterPiece(word, naming, h);
|
|
498
|
+
if (letters !== word) {
|
|
499
|
+
changes.push([out.trim(), letters]);
|
|
500
|
+
return letters;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
const words = out.split(/(\s+)/);
|
|
505
|
+
for (let i = 0;i + 2 < words.length; i += 2) {
|
|
506
|
+
const head = words[i];
|
|
507
|
+
const next = words[i + 2];
|
|
508
|
+
if (!syllableOnly(head) || !QUALITY_WORD.test(next))
|
|
345
509
|
continue;
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
const
|
|
349
|
-
const
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
if (!strings.includes(s) && f !== null && f !== undefined && f > fret)
|
|
354
|
-
under = true;
|
|
510
|
+
if (naming !== "solfege" && reads(head))
|
|
511
|
+
continue;
|
|
512
|
+
const joined = `${head}${next}`;
|
|
513
|
+
const letters = letterPiece(joined, naming, h);
|
|
514
|
+
if (letters !== joined) {
|
|
515
|
+
words.splice(i, 3, joined);
|
|
516
|
+
i -= 2;
|
|
355
517
|
}
|
|
356
|
-
barres.push({ fret, from, to, finger, strings, full: under || strings.length > 3 });
|
|
357
518
|
}
|
|
358
|
-
|
|
519
|
+
out = words.join("");
|
|
520
|
+
const line = out.split(/[\s,|;]+/).some((w) => w !== "" && !/^Do/.test(w) && !reads(w) && rootToken(w, "solfege", false) !== null);
|
|
521
|
+
return out.replace(/\S+/g, (word) => letterWord(word, naming, h, changes, line));
|
|
359
522
|
}
|
|
360
|
-
function
|
|
361
|
-
|
|
362
|
-
if (!barres.length)
|
|
363
|
-
return null;
|
|
364
|
-
return barres.some((b) => b.full) ? "full" : "partial";
|
|
523
|
+
function toLetters(text, naming = "letters", options = {}) {
|
|
524
|
+
return read(text, naming, options, []);
|
|
365
525
|
}
|
|
366
|
-
var
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
const
|
|
406
|
-
const
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
526
|
+
var NOTE_KEYS = new Set([
|
|
527
|
+
"chord",
|
|
528
|
+
"chords",
|
|
529
|
+
"symbol",
|
|
530
|
+
"name",
|
|
531
|
+
"from",
|
|
532
|
+
"to",
|
|
533
|
+
"scale",
|
|
534
|
+
"notes",
|
|
535
|
+
"root",
|
|
536
|
+
"key",
|
|
537
|
+
"arpeggio",
|
|
538
|
+
"compare",
|
|
539
|
+
"scales-for",
|
|
540
|
+
"scales-for-notes",
|
|
541
|
+
"modes",
|
|
542
|
+
"progression",
|
|
543
|
+
"tuning",
|
|
544
|
+
"range",
|
|
545
|
+
"highlight",
|
|
546
|
+
"pitches",
|
|
547
|
+
"sounds",
|
|
548
|
+
"mode"
|
|
549
|
+
]);
|
|
550
|
+
var SINGLE_CHORD_KEYS = new Set(["chord", "symbol", "from", "to", "sounds"]);
|
|
551
|
+
var KEY_LINE = /^(\s*)([A-Za-z][A-Za-z-]*)(\s*:\s*)(.*)$/;
|
|
552
|
+
var NAMING_LINE = /^\s*naming\s*:\s*(.*)$/i;
|
|
553
|
+
var NAMING_DIRECTIVE = /^\s*\{\s*naming\s*:\s*([^}]*)\}\s*$/i;
|
|
554
|
+
var DIAGRAM_SHORTHAND = new Set(["chord", "keyboard", "fretboard", "circle"]);
|
|
555
|
+
function spacedTuning(value, naming) {
|
|
556
|
+
const compact = /^\s*((?:[A-Ha-h](?:#|b|♯|♭)?){4,})\s*$/.exec(value);
|
|
557
|
+
if (!compact || naming !== "german" && !/h/i.test(compact[1]))
|
|
558
|
+
return value;
|
|
559
|
+
return compact[1].match(/[A-Ha-h](?:#|b|♯|♭)?/g).map((n) => n[0].toUpperCase() + n.slice(1)).join(" ");
|
|
560
|
+
}
|
|
561
|
+
function lettersInBlock(language, text) {
|
|
562
|
+
const result = { text, naming: null, changes: [], titles: [], warning: null };
|
|
563
|
+
if (language === "tab" || language === "score")
|
|
564
|
+
return result;
|
|
565
|
+
const lines = [];
|
|
566
|
+
for (const line of text.split(`
|
|
567
|
+
`)) {
|
|
568
|
+
const own = (language === "chords" ? NAMING_DIRECTIVE : NAMING_LINE).exec(line);
|
|
569
|
+
if (!own) {
|
|
570
|
+
lines.push(line);
|
|
571
|
+
continue;
|
|
572
|
+
}
|
|
573
|
+
if (language !== "chords")
|
|
574
|
+
result.naming = parseNaming(own[1]);
|
|
575
|
+
else {
|
|
576
|
+
const naming = namingOf(own[1]);
|
|
577
|
+
if (naming)
|
|
578
|
+
result.naming = naming;
|
|
579
|
+
else
|
|
580
|
+
result.warning = DIRECTIVE_ERROR;
|
|
581
|
+
}
|
|
419
582
|
}
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
}
|
|
441
|
-
if (base > 1) {
|
|
442
|
-
const label = `${base}fr`;
|
|
443
|
-
root.appendChild(vertical ? svgLabel(doc, label, frame.at(-10, along(0.5)), "mn-base-fret", options.hand === "left" ? "start" : "end") : svgLabel(doc, label, frame.at(-16, along(0.5)), "mn-base-fret"));
|
|
444
|
-
}
|
|
445
|
-
const textOf = (s) => (options.labels ? options.labels[s] : voicing.fingers[s]) ?? null;
|
|
446
|
-
const quiet = new Set;
|
|
447
|
-
const fingered = voicing.fingers.some((f) => f);
|
|
448
|
-
const barres = fingered ? barresOf(voicing, capoFret) : options.barreFingers ? barresOf({ frets: voicing.frets, fingers: [...options.barreFingers] }, capoFret).filter((b) => b.full) : [];
|
|
449
|
-
for (const barre of barres) {
|
|
450
|
-
const texts = new Set(barre.strings.map(textOf));
|
|
451
|
-
if (texts.size === 1) {
|
|
452
|
-
for (const s of barre.strings)
|
|
453
|
-
if (s !== barre.from)
|
|
454
|
-
quiet.add(s);
|
|
455
|
-
} else if (!barre.full) {
|
|
456
|
-
continue;
|
|
457
|
-
}
|
|
458
|
-
const middle = along(barre.fret - base + 0.5);
|
|
459
|
-
root.appendChild(svg(doc, "rect", {
|
|
460
|
-
class: "mn-barre",
|
|
461
|
-
...frame.box(across(barre.from) - 7, middle - 7, across(barre.to) + 7, middle + 7),
|
|
462
|
-
rx: 7,
|
|
463
|
-
"data-mn-fret": barre.fret,
|
|
464
|
-
"data-mn-finger": barre.finger,
|
|
465
|
-
"data-mn-from": strings - barre.from,
|
|
466
|
-
"data-mn-to": strings - barre.to
|
|
467
|
-
}));
|
|
583
|
+
const naming = result.naming ?? "letters";
|
|
584
|
+
const named = result.naming !== null;
|
|
585
|
+
const changes = result.changes;
|
|
586
|
+
if (language === "chords") {
|
|
587
|
+
if (!named) {
|
|
588
|
+
result.text = lines.join(`
|
|
589
|
+
`);
|
|
590
|
+
return result;
|
|
591
|
+
}
|
|
592
|
+
result.text = lines.map((line) => line.replace(/\[([^\]]+)\]/g, (whole, inside) => {
|
|
593
|
+
const letters = read(inside, naming, { chord: true }, changes);
|
|
594
|
+
return letters === inside ? whole : `[${letters}]`;
|
|
595
|
+
}).replace(/^(\s*\{\s*(?:key|define|chord)\s*:\s*)([^}]*?)(\s*\}\s*)$/i, (_, head, value, tail) => {
|
|
596
|
+
if (/^\s*\{\s*key/i.test(head))
|
|
597
|
+
return `${head}${read(value, naming, {}, changes)}${tail}`;
|
|
598
|
+
const [name, ...rest] = value.split(/(\s+)/);
|
|
599
|
+
return `${head}${read(name, naming, { chord: true }, changes)}${rest.join("")}${tail}`;
|
|
600
|
+
})).join(`
|
|
601
|
+
`);
|
|
602
|
+
return result;
|
|
468
603
|
}
|
|
469
|
-
const
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
const
|
|
474
|
-
if (
|
|
475
|
-
const
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
d: `M${x - d} ${y - d}L${x + d} ${y + d}M${x + d} ${y - d}L${x - d} ${y + d}`,
|
|
480
|
-
"data-mn-string": string
|
|
481
|
-
}));
|
|
482
|
-
return;
|
|
483
|
-
}
|
|
484
|
-
const openString = tuning?.[s];
|
|
485
|
-
const open = openString === undefined ? undefined : openString + (fromNut ? 0 : capo);
|
|
486
|
-
const isRoot = options.root !== undefined && options.root !== null && open !== undefined && (open + fret) % 12 === options.root;
|
|
487
|
-
const midi = {
|
|
488
|
-
"data-mn-string": string,
|
|
489
|
-
"data-mn-fret": fret,
|
|
490
|
-
...open !== undefined ? { "data-midi": open + fret } : {}
|
|
491
|
-
};
|
|
492
|
-
const place = (markAt, ...els) => {
|
|
493
|
-
if (open === undefined) {
|
|
494
|
-
for (const el of els)
|
|
495
|
-
root.appendChild(el);
|
|
496
|
-
return;
|
|
604
|
+
const shorthand = DIAGRAM_SHORTHAND.has(language);
|
|
605
|
+
result.text = lines.map((line) => {
|
|
606
|
+
if (/^\s*-{3,}\s*$/.test(line) || !line.trim())
|
|
607
|
+
return line;
|
|
608
|
+
const kv = KEY_LINE.exec(line);
|
|
609
|
+
if (kv) {
|
|
610
|
+
const key = kv[2].toLowerCase();
|
|
611
|
+
if (key === "title") {
|
|
612
|
+
result.titles.push(kv[4].trim());
|
|
613
|
+
return line;
|
|
497
614
|
}
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
const [
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
})
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
class: `mn-dot${isRoot ? " mn-root" : ""}${options.marks?.[s] ? ` mn-${options.marks[s]}` : ""}`,
|
|
528
|
-
cx,
|
|
529
|
-
cy,
|
|
530
|
-
r: 7,
|
|
531
|
-
...midi
|
|
532
|
-
}), ...text ? [dotLabel(doc, text, center, 7)] : []);
|
|
533
|
-
});
|
|
534
|
-
if (tuning) {
|
|
535
|
-
const shift = fromNut ? 0 : capo;
|
|
536
|
-
const pitches = voicing.frets.flatMap((f, s) => f === null ? [] : [tuning[s] + shift + f]);
|
|
537
|
-
root.setAttribute("data-mn-pitches", pitches.join(" "));
|
|
538
|
-
root.setAttribute("data-mn-play", "chord");
|
|
539
|
-
root.setAttribute("data-mn-sound", "guitar");
|
|
615
|
+
if (!NOTE_KEYS.has(key))
|
|
616
|
+
return line;
|
|
617
|
+
if (key === "name")
|
|
618
|
+
result.titles.push(kv[4].trim());
|
|
619
|
+
const value = key === "tuning" ? spacedTuning(kv[4], naming) : kv[4];
|
|
620
|
+
const letters = read(value, naming, { chord: SINGLE_CHORD_KEYS.has(key) }, changes);
|
|
621
|
+
if (letters !== kv[4])
|
|
622
|
+
changes.push([kv[4].trim(), letters.trim()]);
|
|
623
|
+
return `${kv[1]}${kv[2]}${kv[3]}${letters}`;
|
|
624
|
+
}
|
|
625
|
+
if (shorthand)
|
|
626
|
+
return read(line, naming, { chord: language === "chord", h: named }, changes);
|
|
627
|
+
if (language === "progression")
|
|
628
|
+
return read(line, naming, { h: named }, changes);
|
|
629
|
+
if (language === "strum" || language === "picking")
|
|
630
|
+
return line.replace(/\[([^\]]+)\]/g, (whole, inside) => {
|
|
631
|
+
const letters = read(inside, naming, { chord: true, h: named }, changes);
|
|
632
|
+
return letters === inside ? whole : `[${letters}]`;
|
|
633
|
+
});
|
|
634
|
+
return line;
|
|
635
|
+
}).join(`
|
|
636
|
+
`);
|
|
637
|
+
return result;
|
|
638
|
+
}
|
|
639
|
+
function quoteAsWritten(message, changes) {
|
|
640
|
+
let out = message;
|
|
641
|
+
for (const [written, letters] of [...changes].sort((a, b) => b[1].length - a[1].length)) {
|
|
642
|
+
if (written !== letters)
|
|
643
|
+
out = out.split(`"${letters}"`).join(`"${written}"`);
|
|
540
644
|
}
|
|
541
|
-
return
|
|
645
|
+
return out;
|
|
542
646
|
}
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
647
|
+
var LETTER_SYLLABLE = {
|
|
648
|
+
C: "Do",
|
|
649
|
+
D: "Ré",
|
|
650
|
+
E: "Mi",
|
|
651
|
+
F: "Fa",
|
|
652
|
+
G: "Sol",
|
|
653
|
+
A: "La",
|
|
654
|
+
B: "Si"
|
|
655
|
+
};
|
|
656
|
+
var SOLFEGE_SIGNS = {
|
|
657
|
+
"#": "♯",
|
|
658
|
+
"♯": "♯",
|
|
659
|
+
b: "♭",
|
|
660
|
+
"♭": "♭",
|
|
661
|
+
"##": "♯♯",
|
|
662
|
+
x: "♯♯",
|
|
663
|
+
bb: "♭♭",
|
|
664
|
+
"♭♭": "♭♭",
|
|
665
|
+
"♯♯": "♯♯"
|
|
666
|
+
};
|
|
667
|
+
var ROOT = /^([A-G])(##|bb|♯♯|♭♭|#|b|♯|♭|x)?/;
|
|
668
|
+
function noteInNaming(name, naming) {
|
|
669
|
+
if (naming === "letters")
|
|
670
|
+
return name;
|
|
671
|
+
const m = /^([A-G])(##|bb|♯♯|♭♭|#|b|♯|♭|x)?$/.exec(name.trim());
|
|
550
672
|
if (!m)
|
|
551
|
-
return
|
|
552
|
-
|
|
673
|
+
return name;
|
|
674
|
+
const [, letter, sign = ""] = m;
|
|
675
|
+
if (naming === "solfege")
|
|
676
|
+
return `${LETTER_SYLLABLE[letter]}${SOLFEGE_SIGNS[sign] ?? ""}`;
|
|
677
|
+
if (letter !== "B")
|
|
678
|
+
return name.trim();
|
|
679
|
+
return sign === "b" || sign === "♭" ? "B" : `H${sign}`;
|
|
680
|
+
}
|
|
681
|
+
function chordInNaming(symbol, naming) {
|
|
682
|
+
if (naming === "letters")
|
|
683
|
+
return symbol;
|
|
684
|
+
const text = symbol.trim();
|
|
685
|
+
const root = ROOT.exec(text);
|
|
686
|
+
if (!root || !parseChord(text))
|
|
687
|
+
return symbol;
|
|
688
|
+
const rest = text.slice(root[0].length);
|
|
689
|
+
const slash = /^(.*)\/([A-G](?:##|bb|♯♯|♭♭|#|b|♯|♭|x)?)$/.exec(rest);
|
|
690
|
+
const suffix = slash ? slash[1] : rest;
|
|
691
|
+
const bass = slash ? `/${noteInNaming(slash[2], naming)}` : "";
|
|
692
|
+
const shownSuffix = naming === "solfege" && suffix ? ` ${suffix}` : suffix;
|
|
693
|
+
return `${noteInNaming(root[0], naming)}${shownSuffix}${bass}`;
|
|
694
|
+
}
|
|
695
|
+
var AFTER_A_NOTE = new Set([
|
|
696
|
+
"major",
|
|
697
|
+
"minor",
|
|
698
|
+
"pentatonic",
|
|
699
|
+
"blues",
|
|
700
|
+
"dorian",
|
|
701
|
+
"phrygian",
|
|
702
|
+
"lydian",
|
|
703
|
+
"mixolydian",
|
|
704
|
+
"aeolian",
|
|
705
|
+
"ionian",
|
|
706
|
+
"locrian",
|
|
707
|
+
"harmonic",
|
|
708
|
+
"melodic",
|
|
709
|
+
"chromatic",
|
|
710
|
+
"whole",
|
|
711
|
+
"augmented",
|
|
712
|
+
"diminished",
|
|
713
|
+
"bebop",
|
|
714
|
+
"arpeggio",
|
|
715
|
+
"chord",
|
|
716
|
+
"string",
|
|
717
|
+
"position",
|
|
718
|
+
"box",
|
|
719
|
+
"scale",
|
|
720
|
+
"mode"
|
|
721
|
+
]);
|
|
722
|
+
var OCTAVE = /^([A-G](?:##|bb|#|b|♯|♭|x)?)(-?\d)$/;
|
|
723
|
+
function shownText(text, naming) {
|
|
724
|
+
if (naming === "letters" || !text)
|
|
725
|
+
return text;
|
|
726
|
+
const parts = text.split(/(\s+|[,;:()])/);
|
|
727
|
+
const word = (i, step) => {
|
|
728
|
+
for (let j = i + step;j >= 0 && j < parts.length; j += step) {
|
|
729
|
+
const p = parts[j];
|
|
730
|
+
if (!p.trim())
|
|
731
|
+
continue;
|
|
732
|
+
return /^[,;:()]$/.test(p) ? null : p;
|
|
733
|
+
}
|
|
734
|
+
return null;
|
|
735
|
+
};
|
|
736
|
+
return parts.map((part, i) => {
|
|
737
|
+
if (!/^[A-G]/.test(part))
|
|
738
|
+
return part;
|
|
739
|
+
const next = word(i, 1);
|
|
740
|
+
if (next === "shape")
|
|
741
|
+
return part;
|
|
742
|
+
const octave = OCTAVE.exec(part);
|
|
743
|
+
if (octave) {
|
|
744
|
+
const amongNotes = [word(i, -1), next].some((w) => w !== null && OCTAVE.test(w));
|
|
745
|
+
if (amongNotes || !/^[5679]$/.test(octave[2]))
|
|
746
|
+
return `${noteInNaming(octave[1], naming)}${octave[2]}`;
|
|
747
|
+
}
|
|
748
|
+
if (part === "A" && next && /^[a-z]/.test(next) && !AFTER_A_NOTE.has(next))
|
|
749
|
+
return part;
|
|
750
|
+
if (parseChord(part))
|
|
751
|
+
return chordInNaming(part, naming);
|
|
752
|
+
const both = part.split("/");
|
|
753
|
+
if (both.length === 2 && both.every((p) => /^[A-G]/.test(p) && parseChord(p)))
|
|
754
|
+
return both.map((p) => chordInNaming(p, naming)).join("/");
|
|
755
|
+
return part;
|
|
756
|
+
}).join("");
|
|
757
|
+
}
|
|
758
|
+
var current = "letters";
|
|
759
|
+
var verbatim = [];
|
|
760
|
+
function withNaming(naming, draw, titles = []) {
|
|
761
|
+
const before = [current, verbatim];
|
|
762
|
+
current = naming;
|
|
763
|
+
verbatim = titles.filter(Boolean);
|
|
764
|
+
try {
|
|
765
|
+
return draw();
|
|
766
|
+
} finally {
|
|
767
|
+
[current, verbatim] = before;
|
|
768
|
+
}
|
|
553
769
|
}
|
|
554
|
-
function
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
return
|
|
770
|
+
function shown(text) {
|
|
771
|
+
if (current === "letters" || !text)
|
|
772
|
+
return text;
|
|
773
|
+
for (const title of verbatim) {
|
|
774
|
+
if (text === title)
|
|
775
|
+
return text;
|
|
776
|
+
if (text.startsWith(`${title},`))
|
|
777
|
+
return title + shownText(text.slice(title.length), current);
|
|
778
|
+
}
|
|
779
|
+
return shownText(text, current);
|
|
564
780
|
}
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
781
|
+
|
|
782
|
+
// src/render/dom.ts
|
|
783
|
+
var SVG_NS = "http://www.w3.org/2000/svg";
|
|
784
|
+
var apply = (el, attrs) => {
|
|
785
|
+
for (const [name, value] of Object.entries(attrs)) {
|
|
786
|
+
if (value !== undefined)
|
|
787
|
+
el.setAttribute(name, String(value));
|
|
788
|
+
}
|
|
568
789
|
};
|
|
569
|
-
function
|
|
570
|
-
const
|
|
571
|
-
|
|
790
|
+
function svg(doc, tag, attrs = {}, children = []) {
|
|
791
|
+
const el = doc.createElementNS(SVG_NS, tag);
|
|
792
|
+
apply(el, attrs);
|
|
793
|
+
for (const child of children)
|
|
794
|
+
if (child)
|
|
795
|
+
el.appendChild(child);
|
|
796
|
+
return el;
|
|
572
797
|
}
|
|
573
|
-
function
|
|
574
|
-
const
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
798
|
+
function svgText(doc, text, attrs = {}) {
|
|
799
|
+
const el = svg(doc, "text", attrs);
|
|
800
|
+
el.textContent = text;
|
|
801
|
+
return el;
|
|
802
|
+
}
|
|
803
|
+
function svgLabel(doc, text, [x, y], cls, anchor = "middle") {
|
|
804
|
+
return svgText(doc, text, { class: cls, x, y: y + 4, "text-anchor": anchor });
|
|
805
|
+
}
|
|
806
|
+
function dotLabel(doc, text, point, r) {
|
|
807
|
+
const label = svgLabel(doc, shown(text), point, "mn-dot-text");
|
|
808
|
+
if ([...shown(text)].length >= 3) {
|
|
809
|
+
label.classList.add("mn-dot-text-long");
|
|
810
|
+
label.setAttribute("textLength", String(2 * r - 2));
|
|
811
|
+
label.setAttribute("lengthAdjust", "spacingAndGlyphs");
|
|
587
812
|
}
|
|
588
|
-
|
|
589
|
-
const bass = parts.bass ? `/${shift(parts.bass, steps, flats)}` : "";
|
|
590
|
-
return `${shift(parts.root, steps, flats)}${parts.suffix}${bass}`;
|
|
813
|
+
return label;
|
|
591
814
|
}
|
|
592
|
-
function
|
|
593
|
-
|
|
594
|
-
const chroma = m ? chromaOf(m[1]) : null;
|
|
595
|
-
const steps = Math.round(semitones) || 0;
|
|
596
|
-
if (!m || chroma === null || steps % 12 === 0)
|
|
597
|
-
return key.trim();
|
|
598
|
-
const target = ((chroma + steps) % 12 + 12) % 12;
|
|
599
|
-
const minor = /^\s*(m|min|minor)\b/.test(m[2]);
|
|
600
|
-
const flats = minor ? FLAT_MINOR_KEYS.has(target) : FLAT_KEYS.has(target);
|
|
601
|
-
return `${nameOf(target, flats)}${m[2]}`;
|
|
815
|
+
function svgLine(doc, [x1, y1], [x2, y2], cls) {
|
|
816
|
+
return svg(doc, "line", { class: cls, x1, y1, x2, y2 });
|
|
602
817
|
}
|
|
603
|
-
function
|
|
604
|
-
const
|
|
605
|
-
|
|
606
|
-
|
|
818
|
+
function html(doc, tag, cls, text) {
|
|
819
|
+
const el = doc.createElement(tag);
|
|
820
|
+
if (cls)
|
|
821
|
+
el.className = cls;
|
|
822
|
+
if (text !== undefined)
|
|
823
|
+
el.textContent = text;
|
|
824
|
+
return el;
|
|
607
825
|
}
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
["
|
|
624
|
-
["-6", "m6"],
|
|
625
|
-
["min7", "m7"],
|
|
626
|
-
["-7", "m7"],
|
|
627
|
-
["min9", "m9"],
|
|
628
|
-
["-9", "m9"],
|
|
629
|
-
["ø", "m7b5"],
|
|
630
|
-
["ø7", "m7b5"],
|
|
631
|
-
["m7-5", "m7b5"],
|
|
632
|
-
["mmaj7", "mMaj7"],
|
|
633
|
-
["mM7", "mMaj7"],
|
|
634
|
-
["m(maj7)", "mMaj7"],
|
|
635
|
-
["-(maj7)", "mMaj7"],
|
|
636
|
-
["°", "dim"],
|
|
637
|
-
["°7", "dim7"],
|
|
638
|
-
["+", "aug"],
|
|
639
|
-
["sus", "sus4"],
|
|
640
|
-
["add2", "add9"],
|
|
641
|
-
["69", "6/9"],
|
|
642
|
-
["alt", "7alt"],
|
|
643
|
-
["-5", "Mb5"],
|
|
644
|
-
["#5", "aug"],
|
|
645
|
-
["b5", "Mb5"],
|
|
646
|
-
["maj7b5", "M7b5"],
|
|
647
|
-
["mmaj9", "mMaj9"],
|
|
648
|
-
["m6/9", "m69"],
|
|
649
|
-
["m6add9", "m69"],
|
|
650
|
-
["sus2sus4", "sus24"]
|
|
651
|
-
]);
|
|
652
|
-
function withoutParentheses(suffix) {
|
|
653
|
-
if (!/[(),]/.test(suffix))
|
|
654
|
-
return suffix;
|
|
655
|
-
if (!/^[^(),]*(?:\([^(),]+(?:,[^(),]+)*\)[^(),]*)+$/.test(suffix))
|
|
656
|
-
return null;
|
|
657
|
-
return suffix.replace(/[(),\s]/g, "");
|
|
658
|
-
}
|
|
659
|
-
function canonicalSuffix(suffix) {
|
|
660
|
-
const direct = CANONICAL.get(suffix);
|
|
661
|
-
if (direct !== undefined)
|
|
662
|
-
return direct;
|
|
663
|
-
const flat = withoutParentheses(suffix);
|
|
664
|
-
if (flat === null || flat === suffix)
|
|
665
|
-
return suffix;
|
|
666
|
-
return CANONICAL.get(flat) ?? flat;
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
// src/theory/scales.ts
|
|
670
|
-
import { Note as Note2, Scale } from "tonal";
|
|
671
|
-
var ALIASES = new Map([
|
|
672
|
-
["natural minor", "minor"],
|
|
673
|
-
["blues", "minor blues"],
|
|
674
|
-
["whole-tone", "whole tone"],
|
|
675
|
-
["pentatonic major", "major pentatonic"],
|
|
676
|
-
["pentatonic minor", "minor pentatonic"]
|
|
677
|
-
]);
|
|
678
|
-
function scaleName(text) {
|
|
679
|
-
const m = /^\s*([A-Ga-g](?:#|b|♯|♭)?)\s+(.+?)\s*$/.exec(text);
|
|
680
|
-
const [tonic, type] = m ? [m[1], m[2]] : ["", text.trim()];
|
|
681
|
-
const lower = type.toLowerCase().replace(/\s+/g, " ");
|
|
682
|
-
const name = ALIASES.get(lower) ?? lower;
|
|
683
|
-
return tonic ? `${tonic[0].toUpperCase()}${tonic.slice(1).replace("♯", "#").replace("♭", "b")} ${name}` : name;
|
|
826
|
+
var NAME_PREFIX = `mn-name-${Math.random().toString(36).slice(2, 8)}-`;
|
|
827
|
+
var names = 0;
|
|
828
|
+
var uniqueId = () => `${NAME_PREFIX}${++names}`;
|
|
829
|
+
var SHOWN_NAMES = /\bmn-(guitar-chord|fretboard|keyboard|circle)\b/;
|
|
830
|
+
function svgRoot(doc, width, height, cls, label) {
|
|
831
|
+
const id = `${NAME_PREFIX}${++names}`;
|
|
832
|
+
const title = svg(doc, "title", { class: "mn-name", id });
|
|
833
|
+
title.textContent = SHOWN_NAMES.test(cls) ? shown(label) : label;
|
|
834
|
+
return svg(doc, "svg", {
|
|
835
|
+
xmlns: SVG_NS,
|
|
836
|
+
viewBox: `0 0 ${width} ${height}`,
|
|
837
|
+
width,
|
|
838
|
+
class: `mn-svg ${cls}`,
|
|
839
|
+
role: "img",
|
|
840
|
+
"aria-labelledby": id
|
|
841
|
+
}, [svg(doc, "defs", {}, [title])]);
|
|
684
842
|
}
|
|
685
|
-
var
|
|
686
|
-
const
|
|
687
|
-
|
|
688
|
-
};
|
|
689
|
-
var CHARACTERISTIC = {
|
|
690
|
-
lydian: ["4A"],
|
|
691
|
-
dorian: ["6M"],
|
|
692
|
-
mixolydian: ["7m"],
|
|
693
|
-
phrygian: ["2m"],
|
|
694
|
-
locrian: ["5d"],
|
|
695
|
-
minor: ["6m"],
|
|
696
|
-
"minor blues": ["5d"],
|
|
697
|
-
"major blues": ["3m"],
|
|
698
|
-
"harmonic minor": ["7M"],
|
|
699
|
-
"melodic minor": ["6M", "7M"],
|
|
700
|
-
"phrygian dominant": ["2m", "3M"]
|
|
701
|
-
};
|
|
702
|
-
var MODE_WORDS = /\b(dorian|phrygian|lydian|mixolydian|aeolian|locrian|blues)\b/i;
|
|
703
|
-
var characteristicIntervals = (type) => CHARACTERISTIC[type] ?? [];
|
|
704
|
-
var marksByDefault = (written) => MODE_WORDS.test(written);
|
|
705
|
-
function modesOf(text) {
|
|
706
|
-
const scale = Scale.get(scaleName(text));
|
|
707
|
-
if (scale.empty || !scale.tonic)
|
|
708
|
-
return null;
|
|
709
|
-
const modes = Scale.modeNames(scale.name);
|
|
710
|
-
if (new Set(modes.map(([, mode]) => mode)).size < 2)
|
|
843
|
+
var nameElement = (el) => {
|
|
844
|
+
const id = el.getAttribute("aria-labelledby");
|
|
845
|
+
if (!id)
|
|
711
846
|
return null;
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
var SUPERLOCRIAN = ["1P", "2m", "3m", "4d", "5d", "6m", "7m"];
|
|
716
|
-
function scaleSpelling(scale) {
|
|
717
|
-
const hasDouble = (notes) => notes.some((n) => DOUBLE_ACCIDENTAL.test(n));
|
|
718
|
-
if (!hasDouble(scale.notes))
|
|
719
|
-
return { notes: scale.notes, intervals: scale.intervals };
|
|
720
|
-
if (scale.type === "altered" && scale.tonic) {
|
|
721
|
-
const notes = SUPERLOCRIAN.map((interval) => Note2.transpose(scale.tonic, interval));
|
|
722
|
-
if (!hasDouble(notes))
|
|
723
|
-
return { notes, intervals: SUPERLOCRIAN };
|
|
847
|
+
for (const candidate of el.querySelectorAll("[id]")) {
|
|
848
|
+
if (candidate.getAttribute("id") === id)
|
|
849
|
+
return candidate;
|
|
724
850
|
}
|
|
725
|
-
return
|
|
851
|
+
return el.ownerDocument.getElementById(id);
|
|
852
|
+
};
|
|
853
|
+
function accessibleName(el) {
|
|
854
|
+
const named = nameElement(el);
|
|
855
|
+
if (named)
|
|
856
|
+
return named.textContent;
|
|
857
|
+
return el.getAttribute("aria-label");
|
|
858
|
+
}
|
|
859
|
+
function setAccessibleName(el, name) {
|
|
860
|
+
const named = nameElement(el);
|
|
861
|
+
if (named)
|
|
862
|
+
named.textContent = name;
|
|
863
|
+
else
|
|
864
|
+
el.setAttribute("aria-label", name);
|
|
865
|
+
}
|
|
866
|
+
function playableMark(doc, area, ...children) {
|
|
867
|
+
const hit = svg(doc, "rect", {
|
|
868
|
+
class: "mn-hit",
|
|
869
|
+
x: area.x,
|
|
870
|
+
y: area.y,
|
|
871
|
+
width: area.width,
|
|
872
|
+
height: area.height,
|
|
873
|
+
fill: "transparent",
|
|
874
|
+
"pointer-events": "all"
|
|
875
|
+
});
|
|
876
|
+
return svg(doc, "g", { class: "mn-mark" }, [hit, ...children]);
|
|
726
877
|
}
|
|
727
|
-
var scaleTypes = () => Scale.names();
|
|
728
878
|
|
|
729
|
-
// src/
|
|
730
|
-
function
|
|
731
|
-
const
|
|
732
|
-
if (
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
classes.push("mn-char");
|
|
736
|
-
if (marks.different?.has(chroma))
|
|
737
|
-
classes.push("mn-diff");
|
|
738
|
-
if (marks.chordTones)
|
|
739
|
-
classes.push(marks.chordTones.has(chroma) ? "mn-tone" : "mn-passing");
|
|
740
|
-
return classes.length ? ` ${classes.join(" ")}` : "";
|
|
879
|
+
// src/render/layout.ts
|
|
880
|
+
function parseOrientation(text) {
|
|
881
|
+
const value = text.trim().toLowerCase();
|
|
882
|
+
if (value === "vertical" || value === "horizontal")
|
|
883
|
+
return value;
|
|
884
|
+
throw new Error(`Unknown orientation "${text}": use vertical or horizontal`);
|
|
741
885
|
}
|
|
742
|
-
function
|
|
743
|
-
const
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
return (characteristic.length ? `, characteristic notes: ${characteristic.join(" ")}` : "") + (different.length ? `, different from the compared scale: ${different.join(" ")}` : "") + (tones.length ? `, chord tones: ${tones.join(" ")}` : "");
|
|
886
|
+
function parseHand(text) {
|
|
887
|
+
const value = text.trim().toLowerCase();
|
|
888
|
+
if (value === "left" || value === "right")
|
|
889
|
+
return value;
|
|
890
|
+
throw new Error(`Unknown hand "${text}": use left or right`);
|
|
748
891
|
}
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
892
|
+
function layoutDefaults(value) {
|
|
893
|
+
const result = {};
|
|
894
|
+
if (!value || typeof value !== "object")
|
|
895
|
+
return result;
|
|
896
|
+
const word = (v) => typeof v === "string" ? v.trim().toLowerCase() : undefined;
|
|
897
|
+
try {
|
|
898
|
+
const { orientation, hand } = value;
|
|
899
|
+
const h = word(hand);
|
|
900
|
+
if (h === "left" || h === "right")
|
|
901
|
+
result.hand = h;
|
|
902
|
+
if (orientation && typeof orientation === "object") {
|
|
903
|
+
for (const language of ["chord", "keyboard", "fretboard"]) {
|
|
904
|
+
const o = word(orientation[language]);
|
|
905
|
+
if (o === "vertical" || o === "horizontal")
|
|
906
|
+
(result.orientation ??= {})[language] = o;
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
} catch {}
|
|
910
|
+
return result;
|
|
766
911
|
}
|
|
767
|
-
function
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
case "intervals":
|
|
774
|
-
return member.interval === null ? member.name : intervalLabel(member.interval);
|
|
775
|
-
case "fingers":
|
|
776
|
-
return finger ?? "";
|
|
777
|
-
default:
|
|
778
|
-
return member.name;
|
|
912
|
+
function titleWidth(title) {
|
|
913
|
+
if (!title)
|
|
914
|
+
return 0;
|
|
915
|
+
let width = 8;
|
|
916
|
+
for (const ch of title) {
|
|
917
|
+
width += ch.codePointAt(0) > 591 ? 15 : /[A-Z0-9#♯♭]/.test(ch) ? 10.5 : 8;
|
|
779
918
|
}
|
|
919
|
+
return Math.ceil(width);
|
|
780
920
|
}
|
|
781
|
-
var
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
921
|
+
var MAX_TITLE_LINES = 3;
|
|
922
|
+
var TITLE_LINE = 17;
|
|
923
|
+
function titleLineWidth(text) {
|
|
924
|
+
if (!text)
|
|
925
|
+
return 0;
|
|
926
|
+
let width = 8;
|
|
927
|
+
for (const ch of text) {
|
|
928
|
+
const code = ch.codePointAt(0);
|
|
929
|
+
width += code > 591 ? 15 : ch === " " || ".,:;'!|".includes(ch) ? 4 : "()[]-/".includes(ch) || "iljfrt".includes(ch) ? 5 : "mwMW".includes(ch) ? 12 : /[A-Z0-9#♯♭]/.test(ch) ? 9.5 : 7.8;
|
|
930
|
+
}
|
|
931
|
+
return Math.ceil(width);
|
|
932
|
+
}
|
|
933
|
+
function titleLines(title, width) {
|
|
934
|
+
const fits = (text) => titleLineWidth(text) <= width;
|
|
935
|
+
const squeeze = (text) => ({
|
|
936
|
+
text,
|
|
937
|
+
textLength: fits(text) ? null : Math.max(1, width - 8)
|
|
938
|
+
});
|
|
939
|
+
if (fits(title))
|
|
940
|
+
return [{ text: title, textLength: null }];
|
|
941
|
+
const phrases = title.split(/(?<=,)\s+|\s+(?=\()/).flatMap((phrase) => fits(phrase) ? [phrase] : phrase.split(/\s+/)).filter(Boolean);
|
|
942
|
+
const lines = [];
|
|
943
|
+
let line = "";
|
|
944
|
+
for (const phrase of phrases) {
|
|
945
|
+
const next = line ? `${line} ${phrase}` : phrase;
|
|
946
|
+
if (!line || fits(next))
|
|
947
|
+
line = next;
|
|
948
|
+
else {
|
|
949
|
+
lines.push(line);
|
|
950
|
+
line = phrase;
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
if (line)
|
|
954
|
+
lines.push(line);
|
|
955
|
+
if (lines.length > MAX_TITLE_LINES) {
|
|
956
|
+
const kept = lines.slice(0, MAX_TITLE_LINES - 1);
|
|
957
|
+
kept.push(lines.slice(MAX_TITLE_LINES - 1).join(" "));
|
|
958
|
+
return kept.map(squeeze);
|
|
959
|
+
}
|
|
960
|
+
return lines.map(squeeze);
|
|
961
|
+
}
|
|
962
|
+
function drawTitle(doc, root, lines, x, y) {
|
|
963
|
+
const NS = "http://www.w3.org/2000/svg";
|
|
964
|
+
const text = doc.createElementNS(NS, "text");
|
|
965
|
+
text.setAttribute("class", "mn-title");
|
|
966
|
+
text.setAttribute("x", String(x));
|
|
967
|
+
text.setAttribute("y", String(y));
|
|
968
|
+
text.setAttribute("text-anchor", "middle");
|
|
969
|
+
const squeeze = (el, line) => {
|
|
970
|
+
if (line.textLength === null)
|
|
971
|
+
return;
|
|
972
|
+
el.setAttribute("textLength", String(line.textLength));
|
|
973
|
+
el.setAttribute("lengthAdjust", "spacingAndGlyphs");
|
|
974
|
+
};
|
|
975
|
+
if (lines.length === 1) {
|
|
976
|
+
text.textContent = lines[0].text;
|
|
977
|
+
squeeze(text, lines[0]);
|
|
978
|
+
} else {
|
|
979
|
+
lines.forEach((line, i) => {
|
|
980
|
+
const span = doc.createElementNS(NS, "tspan");
|
|
981
|
+
span.setAttribute("x", String(x));
|
|
982
|
+
if (i > 0)
|
|
983
|
+
span.setAttribute("dy", String(TITLE_LINE));
|
|
984
|
+
span.textContent = i > 0 ? ` ${line.text}` : line.text;
|
|
985
|
+
squeeze(span, line);
|
|
986
|
+
text.appendChild(span);
|
|
987
|
+
});
|
|
988
|
+
}
|
|
989
|
+
root.setAttribute("data-mn-title-lines", String(lines.length));
|
|
990
|
+
root.appendChild(text);
|
|
991
|
+
return text;
|
|
992
|
+
}
|
|
993
|
+
function alignTitleLines(diagrams) {
|
|
994
|
+
const list = [...diagrams].filter((d) => d.hasAttribute("data-mn-title-lines"));
|
|
995
|
+
const most = Math.max(0, ...list.map((d) => Number(d.getAttribute("data-mn-title-lines"))));
|
|
996
|
+
for (const d of list) {
|
|
997
|
+
const missing = most - Number(d.getAttribute("data-mn-title-lines"));
|
|
998
|
+
if (missing <= 0)
|
|
999
|
+
continue;
|
|
1000
|
+
const shift = missing * TITLE_LINE;
|
|
1001
|
+
const doc = d.ownerDocument;
|
|
1002
|
+
const g = doc.createElementNS("http://www.w3.org/2000/svg", "g");
|
|
1003
|
+
g.setAttribute("class", "mn-title-pad");
|
|
1004
|
+
g.setAttribute("transform", `translate(0 ${shift})`);
|
|
1005
|
+
for (const child of [...d.children]) {
|
|
1006
|
+
if (child.tagName.toLowerCase() !== "defs")
|
|
1007
|
+
g.appendChild(child);
|
|
1008
|
+
}
|
|
1009
|
+
d.appendChild(g);
|
|
1010
|
+
const [x, y, w, h] = (d.getAttribute("viewBox") ?? "0 0 0 0").split(/\s+/).map(Number);
|
|
1011
|
+
d.setAttribute("viewBox", `${x} ${y} ${w} ${h + shift}`);
|
|
1012
|
+
if (d.hasAttribute("height"))
|
|
1013
|
+
d.setAttribute("height", String(Number(d.getAttribute("height")) + shift));
|
|
1014
|
+
d.setAttribute("data-mn-title-lines", String(most));
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
function neckFrame(n) {
|
|
1018
|
+
const vertical = n.orientation === "vertical";
|
|
1019
|
+
const left = n.hand === "left";
|
|
1020
|
+
const content = vertical ? n.low + n.across + n.high : n.before + n.along + n.after;
|
|
1021
|
+
const shift = n.minWidth && n.minWidth > content ? (n.minWidth - content) / 2 : 0;
|
|
1022
|
+
const height = n.top + (vertical ? n.before + n.along + n.after : n.high + n.across + n.low);
|
|
1023
|
+
const at = (across, along) => {
|
|
1024
|
+
if (vertical) {
|
|
1025
|
+
const x = left ? n.high + (n.across - across) : n.low + across;
|
|
1026
|
+
return [shift + x, n.top + n.before + along];
|
|
1027
|
+
}
|
|
1028
|
+
const x = left ? content - n.before - along : n.before + along;
|
|
1029
|
+
return [shift + x, n.top + n.high + (n.across - across)];
|
|
1030
|
+
};
|
|
1031
|
+
const box = (a1, l1, a2, l2) => {
|
|
1032
|
+
const [x1, y1] = at(a1, l1);
|
|
1033
|
+
const [x2, y2] = at(a2, l2);
|
|
1034
|
+
return {
|
|
1035
|
+
x: Math.min(x1, x2),
|
|
1036
|
+
y: Math.min(y1, y2),
|
|
1037
|
+
width: Math.abs(x2 - x1),
|
|
1038
|
+
height: Math.abs(y2 - y1)
|
|
1039
|
+
};
|
|
1040
|
+
};
|
|
1041
|
+
return { width: content + 2 * shift, height, at, box };
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
// src/chord/guitar.ts
|
|
1045
|
+
var STANDARD_TUNING = [40, 45, 50, 55, 59, 64];
|
|
1046
|
+
function chartNoteName(name) {
|
|
1047
|
+
if (!/^[A-G](##|bb)$/.test(name))
|
|
1048
|
+
return name;
|
|
1049
|
+
return nameOf(chromaOf(name), name.endsWith("b"));
|
|
1050
|
+
}
|
|
1051
|
+
function parseFrets(text) {
|
|
1052
|
+
const trimmed = text.trim();
|
|
1053
|
+
const tokens = /[\s,-]/.test(trimmed) ? trimmed.split(/[\s,-]+/) : [...trimmed];
|
|
1054
|
+
const frets = tokens.filter(Boolean).map((t) => /^[xX]$/.test(t) ? null : /^\d+$/.test(t) ? Number(t) : NaN);
|
|
1055
|
+
return frets.length >= 2 && frets.every((f) => f === null || Number.isInteger(f) && f <= 36) ? frets : null;
|
|
1056
|
+
}
|
|
1057
|
+
function parseFingers(text) {
|
|
1058
|
+
const trimmed = text.trim();
|
|
1059
|
+
const tokens = /[\s,]/.test(trimmed) || trimmed.includes("-", 1) ? trimmed.split(/[\s,-]+/) : [...trimmed];
|
|
1060
|
+
return tokens.filter(Boolean).map((t) => /^[0xX]$/.test(t) ? null : t.toUpperCase());
|
|
1061
|
+
}
|
|
1062
|
+
function baseFretOf(frets) {
|
|
1063
|
+
const fretted = frets.filter((f) => f !== null && f > 0);
|
|
1064
|
+
if (!fretted.length || Math.max(...fretted) <= 4)
|
|
1065
|
+
return 1;
|
|
1066
|
+
return Math.min(...fretted);
|
|
1067
|
+
}
|
|
1068
|
+
function barresOf(voicing, capoFret) {
|
|
1069
|
+
const byKey = new Map;
|
|
1070
|
+
voicing.frets.forEach((fret, string) => {
|
|
1071
|
+
const finger = voicing.fingers[string];
|
|
1072
|
+
if (fret === null || fret === 0 || fret === capoFret || !finger)
|
|
1073
|
+
return;
|
|
1074
|
+
const key = `${finger}@${fret}`;
|
|
1075
|
+
byKey.set(key, [...byKey.get(key) ?? [], string]);
|
|
1076
|
+
});
|
|
1077
|
+
const barres = [];
|
|
1078
|
+
for (const [key, strings] of byKey) {
|
|
1079
|
+
if (strings.length < 2)
|
|
1080
|
+
continue;
|
|
1081
|
+
const [finger, fretText] = key.split("@");
|
|
1082
|
+
const fret = Number(fretText);
|
|
1083
|
+
const from = Math.min(...strings);
|
|
1084
|
+
const to = Math.max(...strings);
|
|
1085
|
+
let under = false;
|
|
1086
|
+
for (let s = from + 1;s < to; s++) {
|
|
1087
|
+
const f = voicing.frets[s];
|
|
1088
|
+
if (!strings.includes(s) && f !== null && f !== undefined && f > fret)
|
|
1089
|
+
under = true;
|
|
1090
|
+
}
|
|
1091
|
+
barres.push({ fret, from, to, finger, strings, full: under || strings.length > 3 });
|
|
1092
|
+
}
|
|
1093
|
+
return barres;
|
|
1094
|
+
}
|
|
1095
|
+
function barreKind(voicing) {
|
|
1096
|
+
const barres = barresOf(voicing, null);
|
|
1097
|
+
if (!barres.length)
|
|
1098
|
+
return null;
|
|
1099
|
+
return barres.some((b) => b.full) ? "full" : "partial";
|
|
1100
|
+
}
|
|
1101
|
+
var isBarreVoicing = (voicing) => barreKind(voicing) !== null;
|
|
1102
|
+
var SPACING = 18;
|
|
1103
|
+
var ROW = 20;
|
|
1104
|
+
var MARKERS = 16;
|
|
1105
|
+
var HIT_ALONG = 44;
|
|
1106
|
+
var BASE = 30;
|
|
1107
|
+
var TITLE = 22;
|
|
1108
|
+
var CAPTION = 18;
|
|
1109
|
+
var capoCaption = (capo, sounds) => `Capo ${capo}${sounds ? `, sounds ${sounds}` : ""}`;
|
|
1110
|
+
function renderGuitarDiagram(doc, voicing, options = {}) {
|
|
1111
|
+
const strings = voicing.frets.length;
|
|
1112
|
+
const base = voicing.baseFret ?? baseFretOf(voicing.frets);
|
|
1113
|
+
const fretted = voicing.frets.filter((f) => f !== null && f > 0);
|
|
1114
|
+
const rows = Math.max(4, fretted.length ? Math.max(...fretted) - base + 1 : 0);
|
|
1115
|
+
const orientation = options.orientation ?? "vertical";
|
|
1116
|
+
const vertical = orientation === "vertical";
|
|
1117
|
+
const capo = options.capo && options.capo > 0 ? options.capo : 0;
|
|
1118
|
+
const fromNut = capo > 0 && options.fretsFrom === "nut";
|
|
1119
|
+
const capoFret = fromNut ? capo : null;
|
|
1120
|
+
const caption = capo && options.caption !== false ? shown(capoCaption(capo, options.sounds)) : undefined;
|
|
1121
|
+
const layout = {
|
|
1122
|
+
orientation,
|
|
1123
|
+
hand: options.hand ?? "right",
|
|
1124
|
+
across: (strings - 1) * SPACING,
|
|
1125
|
+
along: rows * ROW,
|
|
1126
|
+
before: MARKERS,
|
|
1127
|
+
after: 10,
|
|
1128
|
+
low: vertical || base > 1 ? BASE : 10,
|
|
1129
|
+
high: vertical ? 14 : 10,
|
|
1130
|
+
top: 4,
|
|
1131
|
+
minWidth: titleWidth(caption)
|
|
1132
|
+
};
|
|
1133
|
+
const lines = options.title ? titleLines(shown(options.title), neckFrame(layout).width) : [];
|
|
1134
|
+
const frame = neckFrame({
|
|
1135
|
+
...layout,
|
|
1136
|
+
top: lines.length ? TITLE + (lines.length - 1) * TITLE_LINE : 4
|
|
1137
|
+
});
|
|
1138
|
+
const across = (string) => string * SPACING;
|
|
1139
|
+
const along = (row) => row * ROW;
|
|
1140
|
+
const at = (string, row) => frame.at(across(string), along(row));
|
|
1141
|
+
const label = `${options.title ? `${options.title} chord diagram` : "Chord diagram"}${capo ? `, ${capoCaption(capo, options.sounds).replace(/^Capo/, "capo")}` : ""}`;
|
|
1142
|
+
const height = frame.height + (caption ? CAPTION : 0);
|
|
1143
|
+
const root = svgRoot(doc, frame.width, height, "mn-guitar-chord", label);
|
|
1144
|
+
root.setAttribute("data-mn-hand", options.hand ?? "right");
|
|
1145
|
+
const fretText = voicing.frets.map((f) => f === null ? "x" : String(f));
|
|
1146
|
+
root.setAttribute("data-mn-voicing", fretText.some((f) => f.length > 1) ? fretText.join("-") : fretText.join(""));
|
|
1147
|
+
if (caption) {
|
|
1148
|
+
root.appendChild(svgText(doc, caption, {
|
|
1149
|
+
class: "mn-caption",
|
|
1150
|
+
x: frame.width / 2,
|
|
1151
|
+
y: height - 6,
|
|
1152
|
+
"text-anchor": "middle"
|
|
1153
|
+
}));
|
|
1154
|
+
}
|
|
1155
|
+
if (capo) {
|
|
1156
|
+
root.setAttribute("data-mn-capo", String(capo));
|
|
1157
|
+
root.setAttribute("data-mn-frets-from", fromNut ? "nut" : "capo");
|
|
1158
|
+
}
|
|
1159
|
+
if (lines.length)
|
|
1160
|
+
drawTitle(doc, root, lines, frame.width / 2, 15);
|
|
1161
|
+
for (let row = 0;row <= rows; row++) {
|
|
1162
|
+
const cls = row === 0 && base === 1 && (!capo || fromNut) ? "mn-nut" : "mn-fret";
|
|
1163
|
+
root.appendChild(svgLine(doc, at(0, row), at(strings - 1, row), cls));
|
|
1164
|
+
}
|
|
1165
|
+
const capoRow = fromNut ? capo - base + 0.5 : base === 1 ? 0 : null;
|
|
1166
|
+
if (capo && capoRow !== null && capoRow >= 0 && capoRow <= rows) {
|
|
1167
|
+
root.appendChild(svg(doc, "rect", {
|
|
1168
|
+
class: "mn-capo",
|
|
1169
|
+
...frame.box(across(0) - 8, along(capoRow) - 3, across(strings - 1) + 8, along(capoRow) + 3),
|
|
1170
|
+
rx: 3
|
|
1171
|
+
}));
|
|
1172
|
+
}
|
|
1173
|
+
for (let s = 0;s < strings; s++) {
|
|
1174
|
+
root.appendChild(svgLine(doc, at(s, 0), at(s, rows), "mn-string"));
|
|
1175
|
+
}
|
|
1176
|
+
if (base > 1) {
|
|
1177
|
+
const label = `${base}fr`;
|
|
1178
|
+
root.appendChild(vertical ? svgLabel(doc, label, frame.at(-10, along(0.5)), "mn-base-fret", options.hand === "left" ? "start" : "end") : svgLabel(doc, label, frame.at(-16, along(0.5)), "mn-base-fret"));
|
|
1179
|
+
}
|
|
1180
|
+
const textOf = (s) => (options.labels ? options.labels[s] : voicing.fingers[s]) ?? null;
|
|
1181
|
+
const quiet = new Set;
|
|
1182
|
+
const fingered = voicing.fingers.some((f) => f);
|
|
1183
|
+
const barres = fingered ? barresOf(voicing, capoFret) : options.barreFingers ? barresOf({ frets: voicing.frets, fingers: [...options.barreFingers] }, capoFret).filter((b) => b.full) : [];
|
|
1184
|
+
for (const barre of barres) {
|
|
1185
|
+
const texts = new Set(barre.strings.map(textOf));
|
|
1186
|
+
if (texts.size === 1) {
|
|
1187
|
+
for (const s of barre.strings)
|
|
1188
|
+
if (s !== barre.from)
|
|
1189
|
+
quiet.add(s);
|
|
1190
|
+
} else if (!barre.full) {
|
|
1191
|
+
continue;
|
|
1192
|
+
}
|
|
1193
|
+
const middle = along(barre.fret - base + 0.5);
|
|
1194
|
+
root.appendChild(svg(doc, "rect", {
|
|
1195
|
+
class: "mn-barre",
|
|
1196
|
+
...frame.box(across(barre.from) - 7, middle - 7, across(barre.to) + 7, middle + 7),
|
|
1197
|
+
rx: 7,
|
|
1198
|
+
"data-mn-fret": barre.fret,
|
|
1199
|
+
"data-mn-finger": barre.finger,
|
|
1200
|
+
"data-mn-from": strings - barre.from,
|
|
1201
|
+
"data-mn-to": strings - barre.to
|
|
1202
|
+
}));
|
|
1203
|
+
}
|
|
1204
|
+
const tuning = options.tuning ?? (strings === 6 ? STANDARD_TUNING : undefined);
|
|
1205
|
+
voicing.frets.forEach((fret, s) => {
|
|
1206
|
+
const markAlong = -8;
|
|
1207
|
+
const mark = frame.at(across(s), markAlong);
|
|
1208
|
+
const string = strings - s;
|
|
1209
|
+
if (fret === null) {
|
|
1210
|
+
const [x, y] = mark;
|
|
1211
|
+
const d = 3.5;
|
|
1212
|
+
root.appendChild(svg(doc, "path", {
|
|
1213
|
+
class: "mn-muted",
|
|
1214
|
+
d: `M${x - d} ${y - d}L${x + d} ${y + d}M${x + d} ${y - d}L${x - d} ${y + d}`,
|
|
1215
|
+
"data-mn-string": string
|
|
1216
|
+
}));
|
|
1217
|
+
return;
|
|
1218
|
+
}
|
|
1219
|
+
const openString = tuning?.[s];
|
|
1220
|
+
const open = openString === undefined ? undefined : openString + (fromNut ? 0 : capo);
|
|
1221
|
+
const isRoot = options.root !== undefined && options.root !== null && open !== undefined && (open + fret) % 12 === options.root;
|
|
1222
|
+
const midi = {
|
|
1223
|
+
"data-mn-string": string,
|
|
1224
|
+
"data-mn-fret": fret,
|
|
1225
|
+
...open !== undefined ? { "data-midi": open + fret } : {}
|
|
1226
|
+
};
|
|
1227
|
+
const place = (markAt, ...els) => {
|
|
1228
|
+
if (open === undefined) {
|
|
1229
|
+
for (const el of els)
|
|
1230
|
+
root.appendChild(el);
|
|
1231
|
+
return;
|
|
1232
|
+
}
|
|
1233
|
+
const area = frame.box(across(s) - SPACING / 2, markAt - HIT_ALONG / 2, across(s) + SPACING / 2, markAt + HIT_ALONG / 2);
|
|
1234
|
+
root.appendChild(playableMark(doc, area, ...els));
|
|
1235
|
+
};
|
|
1236
|
+
if (fret === 0) {
|
|
1237
|
+
const [cx, cy] = mark;
|
|
1238
|
+
place(markAlong, svg(doc, "circle", {
|
|
1239
|
+
class: `mn-open${isRoot ? " mn-root" : ""}`,
|
|
1240
|
+
cx,
|
|
1241
|
+
cy,
|
|
1242
|
+
r: 4,
|
|
1243
|
+
...midi
|
|
1244
|
+
}));
|
|
1245
|
+
return;
|
|
1246
|
+
}
|
|
1247
|
+
const row = along(fret - base + 0.5);
|
|
1248
|
+
const center = at(s, fret - base + 0.5);
|
|
1249
|
+
const [cx, cy] = center;
|
|
1250
|
+
if (fret === capoFret) {
|
|
1251
|
+
place(row, svg(doc, "circle", {
|
|
1252
|
+
class: `mn-capo-open${isRoot ? " mn-root" : ""}`,
|
|
1253
|
+
cx,
|
|
1254
|
+
cy,
|
|
1255
|
+
r: 4,
|
|
1256
|
+
...midi
|
|
1257
|
+
}));
|
|
1258
|
+
return;
|
|
1259
|
+
}
|
|
1260
|
+
const text = quiet.has(s) ? null : textOf(s);
|
|
1261
|
+
place(row, svg(doc, "circle", {
|
|
1262
|
+
class: `mn-dot${isRoot ? " mn-root" : ""}${options.marks?.[s] ? ` mn-${options.marks[s]}` : ""}`,
|
|
1263
|
+
cx,
|
|
1264
|
+
cy,
|
|
1265
|
+
r: 7,
|
|
1266
|
+
...midi
|
|
1267
|
+
}), ...text ? [dotLabel(doc, text, center, 7)] : []);
|
|
793
1268
|
});
|
|
794
|
-
if (
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
root
|
|
800
|
-
pitches: null,
|
|
801
|
-
preferFlats: names.some(isFlat)
|
|
802
|
-
};
|
|
803
|
-
};
|
|
804
|
-
function chordNoteSet(symbol) {
|
|
805
|
-
const parts = splitChordSymbol(symbol);
|
|
806
|
-
if (!parts)
|
|
807
|
-
return null;
|
|
808
|
-
const chord = Chord.getChord(canonicalSuffix(parts.suffix), parts.root);
|
|
809
|
-
if (chord.empty)
|
|
810
|
-
return null;
|
|
811
|
-
const bass = parts.bass;
|
|
812
|
-
const set = fromNames(symbol.trim(), chord.notes, chord.intervals, true);
|
|
813
|
-
const bassChroma = bass ? chromaOf(bass) : null;
|
|
814
|
-
if (set && bass && bassChroma !== null && !memberFor(set, bassChroma)) {
|
|
815
|
-
set.members.push({ chroma: bassChroma, name: bass, degree: null, interval: null });
|
|
816
|
-
}
|
|
817
|
-
return set;
|
|
818
|
-
}
|
|
819
|
-
function respell(set, chord) {
|
|
820
|
-
set.root = chord.root;
|
|
821
|
-
for (const member of set.members) {
|
|
822
|
-
const own = memberFor(chord, member.chroma);
|
|
823
|
-
if (own)
|
|
824
|
-
member.name = own.name;
|
|
1269
|
+
if (tuning) {
|
|
1270
|
+
const shift = fromNut ? 0 : capo;
|
|
1271
|
+
const pitches = voicing.frets.flatMap((f, s) => f === null ? [] : [tuning[s] + shift + f]);
|
|
1272
|
+
root.setAttribute("data-mn-pitches", pitches.join(" "));
|
|
1273
|
+
root.setAttribute("data-mn-play", "chord");
|
|
1274
|
+
root.setAttribute("data-mn-sound", "guitar");
|
|
825
1275
|
}
|
|
1276
|
+
return root;
|
|
826
1277
|
}
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
return set;
|
|
836
|
-
}
|
|
837
|
-
function rootNameOf(text) {
|
|
838
|
-
const name = text.trim().replace(/-?\d$/, "").replace(/♯/g, "#").replace(/♭/g, "b");
|
|
839
|
-
if (chromaOf(name) === null)
|
|
1278
|
+
|
|
1279
|
+
// src/theory/transpose.ts
|
|
1280
|
+
import { Interval as Interval2, Note as Note2 } from "tonal";
|
|
1281
|
+
var FLAT_KEYS = new Set([5, 10, 3, 8, 1]);
|
|
1282
|
+
var FLAT_MINOR_KEYS = new Set([2, 7, 0, 5, 10, 3]);
|
|
1283
|
+
function tonicOf(key) {
|
|
1284
|
+
const m = /^([A-G][#♯b♭]?)\s*(.*)$/.exec(key.trim());
|
|
1285
|
+
if (!m)
|
|
840
1286
|
return null;
|
|
841
|
-
return
|
|
1287
|
+
return { tonic: m[1], minor: /^(m|min|minor)(?![a-z])/i.test(m[2]) && !/^maj/i.test(m[2]) };
|
|
842
1288
|
}
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
const
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
if (
|
|
851
|
-
return
|
|
852
|
-
|
|
853
|
-
const m = /^(\d+)([PMmdA]+)$/.exec(spelled);
|
|
854
|
-
return m && m[1] !== "1" && m[1] !== "8" ? spelled : PLAIN_INTERVALS[semitones];
|
|
1289
|
+
function keyPrefersFlats(key) {
|
|
1290
|
+
const parts = tonicOf(key);
|
|
1291
|
+
const chroma = parts ? chromaOf(parts.tonic) : null;
|
|
1292
|
+
if (!parts || chroma === null)
|
|
1293
|
+
return false;
|
|
1294
|
+
if (isFlat(parts.tonic))
|
|
1295
|
+
return true;
|
|
1296
|
+
if (/[#♯]/.test(parts.tonic))
|
|
1297
|
+
return false;
|
|
1298
|
+
return parts.minor ? FLAT_MINOR_KEYS.has(chroma) : FLAT_KEYS.has(chroma);
|
|
855
1299
|
}
|
|
856
|
-
|
|
857
|
-
|
|
1300
|
+
var shift = (note, semitones, preferFlats) => {
|
|
1301
|
+
const chroma = chromaOf(note);
|
|
1302
|
+
return chroma === null ? note : nameOf(chroma + semitones, preferFlats);
|
|
1303
|
+
};
|
|
1304
|
+
function moveByLetter(note, interval) {
|
|
1305
|
+
const moved = Note2.transpose(note, interval);
|
|
1306
|
+
return /^[A-G](#{3,}|b{3,})$/.test(moved) ? Note2.simplify(moved) : moved;
|
|
858
1307
|
}
|
|
859
|
-
function
|
|
860
|
-
const
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
if (
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
if (root === undefined)
|
|
874
|
-
return set;
|
|
875
|
-
const rootName = rootNameOf(root);
|
|
876
|
-
if (rootName === null)
|
|
877
|
-
return null;
|
|
878
|
-
set.root = chromaOf(rootName);
|
|
879
|
-
for (const member of set.members) {
|
|
880
|
-
member.interval = intervalFrom(rootName, member.name);
|
|
881
|
-
member.degree = Number(/^\d+/.exec(member.interval ?? "")?.[0] ?? 1);
|
|
1308
|
+
function transposeChord(symbol, semitones, spelling) {
|
|
1309
|
+
const trimmed = symbol.trim();
|
|
1310
|
+
const parts = splitChordSymbol(trimmed);
|
|
1311
|
+
const steps = Math.round(semitones) || 0;
|
|
1312
|
+
if (!parts || steps % 12 === 0)
|
|
1313
|
+
return trimmed;
|
|
1314
|
+
if (typeof spelling === "object") {
|
|
1315
|
+
const interval = Interval2.distance(spelling.from.replace("♯", "#").replace("♭", "b"), spelling.to.replace("♯", "#").replace("♭", "b"));
|
|
1316
|
+
const moves = Interval2.semitones(interval);
|
|
1317
|
+
if (moves !== undefined && ((moves - steps) % 12 + 12) % 12 === 0) {
|
|
1318
|
+
const bass = parts.bass ? `/${moveByLetter(parts.bass, interval)}` : "";
|
|
1319
|
+
return `${moveByLetter(parts.root, interval)}${parts.suffix}${bass}`;
|
|
1320
|
+
}
|
|
1321
|
+
spelling = keyPrefersFlats(spelling.to);
|
|
882
1322
|
}
|
|
883
|
-
|
|
1323
|
+
const flats = spelling ?? isFlat(parts.root);
|
|
1324
|
+
const bass = parts.bass ? `/${shift(parts.bass, steps, flats)}` : "";
|
|
1325
|
+
return `${shift(parts.root, steps, flats)}${parts.suffix}${bass}`;
|
|
1326
|
+
}
|
|
1327
|
+
function transposeKey(key, semitones) {
|
|
1328
|
+
const m = /^([A-G][#♯b♭]?)(.*)$/.exec(key.trim());
|
|
1329
|
+
const chroma = m ? chromaOf(m[1]) : null;
|
|
1330
|
+
const steps = Math.round(semitones) || 0;
|
|
1331
|
+
if (!m || chroma === null || steps % 12 === 0)
|
|
1332
|
+
return key.trim();
|
|
1333
|
+
const target = ((chroma + steps) % 12 + 12) % 12;
|
|
1334
|
+
const minor = /^\s*(m|min|minor)\b/.test(m[2]);
|
|
1335
|
+
const flats = minor ? FLAT_MINOR_KEYS.has(target) : FLAT_KEYS.has(target);
|
|
1336
|
+
return `${nameOf(target, flats)}${m[2]}`;
|
|
1337
|
+
}
|
|
1338
|
+
function keyMove(key, semitones) {
|
|
1339
|
+
const from = tonicOf(key);
|
|
1340
|
+
const to = tonicOf(transposeKey(key, semitones));
|
|
1341
|
+
return from && to && chromaOf(from.tonic) !== null ? { from: from.tonic, to: to.tonic } : null;
|
|
884
1342
|
}
|
|
885
1343
|
|
|
886
1344
|
// src/chord/capo.ts
|
|
@@ -1269,72 +1727,6 @@ function parseChordPro(source) {
|
|
|
1269
1727
|
// src/theory/find.ts
|
|
1270
1728
|
import { Interval as Interval4, ScaleType, Scale as Scale4 } from "tonal";
|
|
1271
1729
|
|
|
1272
|
-
// src/theory/chord-symbol.ts
|
|
1273
|
-
var QUALITY_SUFFIXES = [
|
|
1274
|
-
[/^(m7b5|m7-5|ø7?)$/, "Minor 7 flat 5"],
|
|
1275
|
-
[/^(dim7|°7)$/, "Diminished 7"],
|
|
1276
|
-
[/^(maj9|M9|Δ9)$/, "Major 9"],
|
|
1277
|
-
[/^(maj7|M7|Δ7?)$/, "Major 7"],
|
|
1278
|
-
[/^(7sus4)$/, "7sus4"],
|
|
1279
|
-
[/^(m9|min9|-9)$/, "Minor 9"],
|
|
1280
|
-
[/^(m7|min7|-7)$/, "Minor 7"],
|
|
1281
|
-
[/^(m6|min6|-6)$/, "Minor 6"],
|
|
1282
|
-
[/^(m|min|-)$/, "Minor"],
|
|
1283
|
-
[/^(dim|°)$/, "Diminished"],
|
|
1284
|
-
[/^(aug|\+|\+5|#5)$/, "Augmented"],
|
|
1285
|
-
[/^(sus2)$/, "Sus2"],
|
|
1286
|
-
[/^(sus4|sus)$/, "Sus4"],
|
|
1287
|
-
[/^(add9|add2)$/, "Add9"],
|
|
1288
|
-
[/^5$/, "5 (Power)"],
|
|
1289
|
-
[/^(6\/9|69)$/, "6/9"],
|
|
1290
|
-
[/^(m6\/9|m69|m6add9)$/, "Minor 6/9"],
|
|
1291
|
-
[/^(Mb5|b5|-5)$/, "Major flat 5"],
|
|
1292
|
-
[/^(mM7|mMaj7|mmaj7|m\(maj7\)|-\(maj7\))$/, "Minor major 7"],
|
|
1293
|
-
[/^(13|11|9|7|6)$/, "$1"],
|
|
1294
|
-
[/^(maj|M)?$/, "Major"]
|
|
1295
|
-
];
|
|
1296
|
-
var ACCIDENTAL_WORDS = {
|
|
1297
|
-
"#": " Sharp",
|
|
1298
|
-
"##": " Double Sharp",
|
|
1299
|
-
b: " Flat",
|
|
1300
|
-
bb: " Double Flat"
|
|
1301
|
-
};
|
|
1302
|
-
var spellNote = (note) => note[0] + (ACCIDENTAL_WORDS[note.slice(1)] ?? "");
|
|
1303
|
-
var plain = (quality) => quality.replace(/\s*\([^)]*\)/g, "").trim();
|
|
1304
|
-
function parseChord(symbol) {
|
|
1305
|
-
const parts = splitChordSymbol(symbol);
|
|
1306
|
-
if (!parts)
|
|
1307
|
-
return null;
|
|
1308
|
-
const trimmed = symbol.trim();
|
|
1309
|
-
const { root, bass } = parts;
|
|
1310
|
-
const suffix = withoutParentheses(parts.suffix);
|
|
1311
|
-
let quality = null;
|
|
1312
|
-
for (const written of suffix === null || suffix === parts.suffix ? [parts.suffix] : [parts.suffix, suffix]) {
|
|
1313
|
-
for (const [re, label] of QUALITY_SUFFIXES) {
|
|
1314
|
-
const hit = re.exec(written);
|
|
1315
|
-
if (hit) {
|
|
1316
|
-
quality = label.replace("$1", hit[1] ?? "");
|
|
1317
|
-
break;
|
|
1318
|
-
}
|
|
1319
|
-
}
|
|
1320
|
-
if (quality)
|
|
1321
|
-
break;
|
|
1322
|
-
}
|
|
1323
|
-
if (suffix === null && !quality)
|
|
1324
|
-
return null;
|
|
1325
|
-
if (!quality && suffix !== null && chordNoteSet(trimmed))
|
|
1326
|
-
quality = suffix;
|
|
1327
|
-
if (!quality)
|
|
1328
|
-
return null;
|
|
1329
|
-
return {
|
|
1330
|
-
symbol: trimmed,
|
|
1331
|
-
root,
|
|
1332
|
-
quality,
|
|
1333
|
-
bass,
|
|
1334
|
-
name: `${spellNote(root)} ${plain(quality)}${bass ? ` over ${spellNote(bass)}` : ""}`
|
|
1335
|
-
};
|
|
1336
|
-
}
|
|
1337
|
-
|
|
1338
1730
|
// src/theory/keys.ts
|
|
1339
1731
|
import { Interval as Interval3, Key, Note as Note3, Scale as Scale3 } from "tonal";
|
|
1340
1732
|
var MODES = [
|
|
@@ -4570,7 +4962,7 @@ function renderFretboard(doc, set, options = {}) {
|
|
|
4570
4962
|
top: 0,
|
|
4571
4963
|
minWidth: titleWidth(caption)
|
|
4572
4964
|
};
|
|
4573
|
-
const lines = options.title ? titleLines(options.title, neckFrame(layout).width) : [];
|
|
4965
|
+
const lines = options.title ? titleLines(shown(options.title), neckFrame(layout).width) : [];
|
|
4574
4966
|
const frame = neckFrame({
|
|
4575
4967
|
...layout,
|
|
4576
4968
|
top: lines.length ? TITLE2 + (lines.length - 1) * TITLE_LINE : 0
|
|
@@ -4636,7 +5028,7 @@ function renderFretboard(doc, set, options = {}) {
|
|
|
4636
5028
|
for (let s = strings - 1;s >= 0; s--) {
|
|
4637
5029
|
const open = tuning[s];
|
|
4638
5030
|
root.appendChild(svgLine(doc, frame.at(across(s), 0), frame.at(across(s), wire(to)), "mn-string"));
|
|
4639
|
-
const name = nameOf(names[s], set.preferFlats);
|
|
5031
|
+
const name = shown(nameOf(names[s], set.preferFlats));
|
|
4640
5032
|
root.appendChild(vertical ? svgLabel(doc, name, frame.at(across(s), -10), "mn-string-name") : svgLabel(doc, name, frame.at(across(s), -8), "mn-string-name", options.hand === "left" ? "start" : "end"));
|
|
4641
5033
|
for (let fret = from;fret <= to; fret++) {
|
|
4642
5034
|
const point = frame.at(across(s), center(fret));
|
|
@@ -6138,6 +6530,18 @@ function spelledNote(name, midi) {
|
|
|
6138
6530
|
return `${nameOf(midi)}${octave}`;
|
|
6139
6531
|
}
|
|
6140
6532
|
function redrawFor(doc, diagram, data, pageHand = "right") {
|
|
6533
|
+
const naming = namingOf(diagram.closest("[data-mn-naming]")?.getAttribute("data-mn-naming"));
|
|
6534
|
+
if (!naming)
|
|
6535
|
+
return redrawLetters(doc, diagram, data, pageHand);
|
|
6536
|
+
const title = diagram.querySelector(".mn-title")?.textContent ?? "";
|
|
6537
|
+
const name = accessibleName(diagram) ?? "";
|
|
6538
|
+
return withNaming(naming, () => redrawLetters(doc, diagram, data, pageHand), [
|
|
6539
|
+
title,
|
|
6540
|
+
title.replace(/,\s*(left|right) hand$/, ""),
|
|
6541
|
+
name
|
|
6542
|
+
]);
|
|
6543
|
+
}
|
|
6544
|
+
function redrawLetters(doc, diagram, data, pageHand) {
|
|
6141
6545
|
const own = diagram.getAttribute("data-mn-hand");
|
|
6142
6546
|
const hand = own === "left" || own === "right" ? own : pageHand;
|
|
6143
6547
|
const toGuitar = data.sound === "piano";
|
|
@@ -6673,7 +7077,7 @@ function renderKeyboard(doc, set, options = {}) {
|
|
|
6673
7077
|
const handRow = [...options.hands?.keys() ?? []].some((midi) => midi >= from && midi <= to) ? HAND_ROW : 0;
|
|
6674
7078
|
const depth = WHITE_H + fingerRow + handRow;
|
|
6675
7079
|
const content = (vertical ? depth : length) + 2;
|
|
6676
|
-
const width = Math.max(content, titleWidth(options.title));
|
|
7080
|
+
const width = Math.max(content, titleWidth(options.title && shown(options.title)));
|
|
6677
7081
|
const shift = (width - content) / 2;
|
|
6678
7082
|
const height = top + (vertical ? length : depth) + 2;
|
|
6679
7083
|
const at = (along, depth) => vertical ? [shift + 1 + depth, top + 1 + length - along] : [shift + 1 + along, top + 1 + depth];
|
|
@@ -6693,7 +7097,7 @@ function renderKeyboard(doc, set, options = {}) {
|
|
|
6693
7097
|
}).filter(Boolean).join(", ");
|
|
6694
7098
|
const root = svgRoot(doc, width, height, "mn-keyboard", `${options.title ?? `Keyboard: ${set.title}`}${handWords ? `, ${handWords}` : ""}${describeMarks(set, options.marks)}`);
|
|
6695
7099
|
if (options.title) {
|
|
6696
|
-
root.appendChild(svgText(doc, options.title, {
|
|
7100
|
+
root.appendChild(svgText(doc, shown(options.title), {
|
|
6697
7101
|
class: "mn-title",
|
|
6698
7102
|
x: width / 2,
|
|
6699
7103
|
y: 15,
|
|
@@ -6717,7 +7121,13 @@ function renderKeyboard(doc, set, options = {}) {
|
|
|
6717
7121
|
const text = labelOf(member, label, options.fingers?.get(midi));
|
|
6718
7122
|
if (!text)
|
|
6719
7123
|
return;
|
|
6720
|
-
|
|
7124
|
+
const words = shown(text);
|
|
7125
|
+
const el = svgLabel(doc, words, point, black ? "mn-key-label mn-key-label-black" : "mn-key-label");
|
|
7126
|
+
if (words !== text && [...words].length >= 3) {
|
|
7127
|
+
el.setAttribute("textLength", String((black ? BLACK_W : WHITE_W) - 2));
|
|
7128
|
+
el.setAttribute("lengthAdjust", "spacingAndGlyphs");
|
|
7129
|
+
}
|
|
7130
|
+
root.appendChild(el);
|
|
6721
7131
|
};
|
|
6722
7132
|
whites.forEach((midi, i) => {
|
|
6723
7133
|
const along = i * WHITE_W;
|
|
@@ -7206,7 +7616,7 @@ function renderChart(doc, song, options = {}) {
|
|
|
7206
7616
|
root.appendChild(header);
|
|
7207
7617
|
}
|
|
7208
7618
|
const meta = [
|
|
7209
|
-
key ? `Key ${key}` : null,
|
|
7619
|
+
key ? shown(`Key ${key}`) : null,
|
|
7210
7620
|
song.capo ? `Capo ${song.capo}` : null,
|
|
7211
7621
|
song.tempo ? `${song.tempo} BPM` : null,
|
|
7212
7622
|
song.time ? song.time : null,
|
|
@@ -7265,7 +7675,7 @@ function renderChart(doc, song, options = {}) {
|
|
|
7265
7675
|
rests.set(step.segment, step.rest);
|
|
7266
7676
|
line.segments.forEach((segment, index) => {
|
|
7267
7677
|
const seg = html(doc, "span", "mn-seg");
|
|
7268
|
-
const mark = html(doc, "span", "mn-chord", segment.chord === null ? "" : chord(segment.chord));
|
|
7678
|
+
const mark = html(doc, "span", "mn-chord", segment.chord === null ? "" : shown(chord(segment.chord)));
|
|
7269
7679
|
if (segment.chord !== null) {
|
|
7270
7680
|
const shown = chord(segment.chord);
|
|
7271
7681
|
const voicing = soundOf(segment.chord, shown);
|
|
@@ -9387,9 +9797,9 @@ function renderSection(doc, section, options, renderChord) {
|
|
|
9387
9797
|
const el = html(doc, "div", "mn-progression-section");
|
|
9388
9798
|
const others = section.others.length ? ` (or ${section.others.join(", ")})` : "";
|
|
9389
9799
|
const blues = section.blues ? " (blues)" : "";
|
|
9390
|
-
el.appendChild(html(doc, "div", "mn-progression-key", `Key: ${section.name ?? section.key.name}${blues}${others}`));
|
|
9800
|
+
el.appendChild(html(doc, "div", "mn-progression-key", shown(`Key: ${section.name ?? section.key.name}${blues}${others}`)));
|
|
9391
9801
|
if (section.note)
|
|
9392
|
-
el.appendChild(html(doc, "div", "mn-progression-note", section.note));
|
|
9802
|
+
el.appendChild(html(doc, "div", "mn-progression-note", shown(section.note)));
|
|
9393
9803
|
const instrument = (field(block, "instrument") ?? options.instrument ?? "guitar").toLowerCase();
|
|
9394
9804
|
if (!["guitar", "piano", "keyboard"].includes(instrument)) {
|
|
9395
9805
|
throw new Error(`Unknown instrument "${instrument}": use guitar or piano`);
|
|
@@ -9487,11 +9897,11 @@ function renderSection(doc, section, options, renderChord) {
|
|
|
9487
9897
|
}
|
|
9488
9898
|
cell.appendChild(renderChord(doc, diagramBlock(block, lines), options));
|
|
9489
9899
|
} catch (e) {
|
|
9490
|
-
cell.appendChild(html(doc, "div", "mn-progression-name", chord.symbol));
|
|
9900
|
+
cell.appendChild(html(doc, "div", "mn-progression-name", shown(chord.symbol)));
|
|
9491
9901
|
cell.appendChild(html(doc, "div", "mn-error-message", e instanceof Error ? e.message : String(e)));
|
|
9492
9902
|
}
|
|
9493
9903
|
} else
|
|
9494
|
-
cell.appendChild(html(doc, "div", "mn-progression-name", chord.symbol));
|
|
9904
|
+
cell.appendChild(html(doc, "div", "mn-progression-name", shown(chord.symbol)));
|
|
9495
9905
|
if (functions) {
|
|
9496
9906
|
cell.appendChild(html(doc, "div", "mn-progression-function", chord.function));
|
|
9497
9907
|
}
|
|
@@ -9619,7 +10029,7 @@ function renderCircle(doc, options = {}) {
|
|
|
9619
10029
|
const chords = placed(key, options.sevenths ?? false, minor && options.dominant !== "minor");
|
|
9620
10030
|
const neighbours = options.neighbours ?? true;
|
|
9621
10031
|
const top = options.title ? TITLE4 : 0;
|
|
9622
|
-
const width = Math.max(SIZE, titleWidth(options.title));
|
|
10032
|
+
const width = Math.max(SIZE, titleWidth(options.title && shown(options.title)));
|
|
9623
10033
|
const chipsTop = top + SIZE + 8;
|
|
9624
10034
|
const height = chipsTop + CHIP_H + 2;
|
|
9625
10035
|
const signature = keySignature(key);
|
|
@@ -9628,7 +10038,7 @@ function renderCircle(doc, options = {}) {
|
|
|
9628
10038
|
const shift = (width - SIZE) / 2;
|
|
9629
10039
|
const g = svg(doc, "g", shift ? { transform: `translate(${shift} 0)` } : {});
|
|
9630
10040
|
if (options.title) {
|
|
9631
|
-
root.appendChild(svgText(doc, options.title, {
|
|
10041
|
+
root.appendChild(svgText(doc, shown(options.title), {
|
|
9632
10042
|
class: "mn-title",
|
|
9633
10043
|
x: width / 2,
|
|
9634
10044
|
y: 16,
|
|
@@ -9671,7 +10081,7 @@ function renderCircle(doc, options = {}) {
|
|
|
9671
10081
|
"data-mn-strum": pitches.join(" "),
|
|
9672
10082
|
"data-mn-chroma": chord && pitches.length ? pitches[0] % 12 : undefined
|
|
9673
10083
|
});
|
|
9674
|
-
const name = chord ? pretty(chord.symbol) : pretty(defaults[ring][position]);
|
|
10084
|
+
const name = shown(chord ? pretty(chord.symbol) : pretty(defaults[ring][position]));
|
|
9675
10085
|
const title = svg(doc, "title");
|
|
9676
10086
|
title.textContent = chord ? `${chord.numeral}: ${name}` : name.replace("/", " or ");
|
|
9677
10087
|
cell.appendChild(title);
|
|
@@ -9710,11 +10120,14 @@ function renderCircle(doc, options = {}) {
|
|
|
9710
10120
|
}
|
|
9711
10121
|
const centerY = top + CENTER2;
|
|
9712
10122
|
const centerLines = [
|
|
9713
|
-
[pretty(key.tonic) + ` ${key.mode}
|
|
10123
|
+
[shown(pretty(key.tonic) + ` ${key.mode}`), "mn-circle-key"],
|
|
9714
10124
|
[signatureText(signature.count), "mn-circle-key-sig"]
|
|
9715
10125
|
];
|
|
9716
10126
|
if (signature.accidentals.length && signature.accidentals.length <= 7) {
|
|
9717
|
-
centerLines.push([
|
|
10127
|
+
centerLines.push([
|
|
10128
|
+
shown(signature.accidentals.map(pretty).join(" ")),
|
|
10129
|
+
"mn-circle-key-notes"
|
|
10130
|
+
]);
|
|
9718
10131
|
}
|
|
9719
10132
|
centerLines.forEach(([text, cls], i) => {
|
|
9720
10133
|
g.appendChild(svgText(doc, text, {
|
|
@@ -9741,7 +10154,7 @@ function renderCircle(doc, options = {}) {
|
|
|
9741
10154
|
"data-mn-chroma": pitches.length ? pitches[0] % 12 : undefined
|
|
9742
10155
|
});
|
|
9743
10156
|
const tip = svg(doc, "title");
|
|
9744
|
-
tip.textContent = `${chord.numeral}: ${pretty(chord.symbol)}`;
|
|
10157
|
+
tip.textContent = `${chord.numeral}: ${shown(pretty(chord.symbol))}`;
|
|
9745
10158
|
chip.appendChild(tip);
|
|
9746
10159
|
g.appendChild(chip);
|
|
9747
10160
|
const solid = chord.degree === 1 || neighbours && (chord.degree === 4 || chord.degree === 5);
|
|
@@ -9752,7 +10165,7 @@ function renderCircle(doc, options = {}) {
|
|
|
9752
10165
|
y: chipsTop + 15,
|
|
9753
10166
|
"text-anchor": "middle"
|
|
9754
10167
|
}));
|
|
9755
|
-
g.appendChild(svgText(doc, pretty(chord.symbol), {
|
|
10168
|
+
g.appendChild(svgText(doc, shown(pretty(chord.symbol)), {
|
|
9756
10169
|
class: `mn-circle-label${on}`,
|
|
9757
10170
|
x: x + chipW / 2,
|
|
9758
10171
|
y: chipsTop + 31,
|
|
@@ -9970,7 +10383,7 @@ function renderStrum(doc, pattern, options = {}) {
|
|
|
9970
10383
|
g.appendChild(svgLabel(doc, countOf(i, slotsPerBeat, slotsPerBar), [x, countY], onBeat ? "mn-strum-count mn-strum-count-beat" : "mn-strum-count"));
|
|
9971
10384
|
const chord = slot.chord ?? (i === 0 ? pattern.chord : null);
|
|
9972
10385
|
if (chord) {
|
|
9973
|
-
const label = svgLabel(doc, chord, [x - width / 2 + 3, chordY], "mn-strum-chord", "start");
|
|
10386
|
+
const label = svgLabel(doc, shown(chord), [x - width / 2 + 3, chordY], "mn-strum-chord", "start");
|
|
9974
10387
|
g.appendChild(label);
|
|
9975
10388
|
g.setAttribute("data-mn-chord", chord);
|
|
9976
10389
|
if (options.voicing && slot.chord)
|
|
@@ -10108,7 +10521,7 @@ function renderPicking(doc, pattern, options = {}) {
|
|
|
10108
10521
|
const chord = score.chords[bar];
|
|
10109
10522
|
const starts = i % slotsPerBar === 0 && chord && (bar === 0 || score.chords[bar - 1] !== chord);
|
|
10110
10523
|
if (starts) {
|
|
10111
|
-
g.appendChild(svgLabel(doc, chord, [x - width / 2 + 3, chordY], "mn-strum-chord", "start"));
|
|
10524
|
+
g.appendChild(svgLabel(doc, shown(chord), [x - width / 2 + 3, chordY], "mn-strum-chord", "start"));
|
|
10112
10525
|
g.setAttribute("data-mn-chord", chord);
|
|
10113
10526
|
}
|
|
10114
10527
|
if (i % slotsPerBar === 0)
|
|
@@ -11049,78 +11462,103 @@ function renderBlock(language, source, host, given = {}) {
|
|
|
11049
11462
|
el.classList.add("mn-from-properties");
|
|
11050
11463
|
}
|
|
11051
11464
|
}
|
|
11052
|
-
let
|
|
11465
|
+
let reading;
|
|
11053
11466
|
try {
|
|
11054
|
-
|
|
11055
|
-
text = resolveScalesFor(text);
|
|
11056
|
-
parts = isDiagramLanguage(language) ? splitParts(text) ?? modeParts(language, text) ?? positionParts(language, text) ?? handParts(language, text) ?? transitionParts(language, text, options.voicings) ?? triadParts(language, text) ?? voicingParts(language, text) : null;
|
|
11467
|
+
reading = lettersInBlock(language, text);
|
|
11057
11468
|
} catch (e) {
|
|
11058
11469
|
return failed(el, host, language, messageOf(e));
|
|
11059
11470
|
}
|
|
11060
|
-
|
|
11061
|
-
|
|
11062
|
-
|
|
11063
|
-
|
|
11064
|
-
|
|
11065
|
-
|
|
11066
|
-
|
|
11067
|
-
|
|
11068
|
-
|
|
11069
|
-
|
|
11070
|
-
|
|
11071
|
-
|
|
11072
|
-
|
|
11073
|
-
if (warnings.length)
|
|
11074
|
-
error = warnings.map((w) => w.textContent ?? "").join("; ");
|
|
11471
|
+
text = reading.text;
|
|
11472
|
+
const naming = reading.naming ?? namingOf(options.naming) ?? "letters";
|
|
11473
|
+
if (naming !== "letters")
|
|
11474
|
+
el.setAttribute("data-mn-naming", naming);
|
|
11475
|
+
const quoted = (e) => quoteAsWritten(messageOf(e), reading.changes);
|
|
11476
|
+
const draw = () => {
|
|
11477
|
+
let parts = null;
|
|
11478
|
+
try {
|
|
11479
|
+
if ((language === "fretboard" || language === "keyboard") && !splitParts(text))
|
|
11480
|
+
text = resolveScalesFor(text);
|
|
11481
|
+
parts = isDiagramLanguage(language) ? splitParts(text) ?? modeParts(language, text) ?? positionParts(language, text) ?? handParts(language, text) ?? transitionParts(language, text, options.voicings) ?? triadParts(language, text) ?? voicingParts(language, text) : null;
|
|
11482
|
+
} catch (e) {
|
|
11483
|
+
return failed(el, host, language, quoted(e));
|
|
11075
11484
|
}
|
|
11076
|
-
|
|
11077
|
-
|
|
11078
|
-
|
|
11079
|
-
|
|
11080
|
-
|
|
11081
|
-
|
|
11082
|
-
|
|
11083
|
-
|
|
11084
|
-
|
|
11085
|
-
|
|
11086
|
-
|
|
11087
|
-
|
|
11485
|
+
if (!text.trim() || parts?.length === 0) {
|
|
11486
|
+
el.classList.add("mn-empty");
|
|
11487
|
+
host.appendChild(el);
|
|
11488
|
+
return { ok: true, el, error: null, picks: [], destroy: () => el.remove() };
|
|
11489
|
+
}
|
|
11490
|
+
try {
|
|
11491
|
+
if (parts && isDiagramLanguage(language)) {
|
|
11492
|
+
error = renderRow(doc, language, parts, el, options);
|
|
11493
|
+
if (error !== null && reading.changes.length) {
|
|
11494
|
+
error = quoteAsWritten(error, reading.changes);
|
|
11495
|
+
for (const m of el.querySelectorAll(".mn-error-message"))
|
|
11496
|
+
m.textContent = quoteAsWritten(m.textContent ?? "", reading.changes);
|
|
11497
|
+
}
|
|
11498
|
+
} else {
|
|
11499
|
+
el.appendChild(RENDERERS[language](doc, text, options));
|
|
11500
|
+
const warnings = [
|
|
11501
|
+
...el.querySelectorAll(".mn-chart > .mn-error-message, .mn-chart-chord > .mn-error-message")
|
|
11502
|
+
];
|
|
11503
|
+
if (reading.warning) {
|
|
11504
|
+
const chart = el.querySelector(".mn-chart");
|
|
11505
|
+
chart?.insertBefore(html(doc, "div", "mn-error-message", reading.warning), chart.firstChild);
|
|
11506
|
+
if (chart)
|
|
11507
|
+
warnings.unshift(chart.firstElementChild);
|
|
11508
|
+
}
|
|
11509
|
+
if (warnings.length)
|
|
11510
|
+
error = warnings.map((w) => w.textContent ?? "").join("; ");
|
|
11088
11511
|
}
|
|
11089
|
-
|
|
11090
|
-
|
|
11091
|
-
|
|
11092
|
-
|
|
11093
|
-
|
|
11094
|
-
|
|
11095
|
-
|
|
11512
|
+
} catch (e) {
|
|
11513
|
+
return failed(el, host, language, quoted(e));
|
|
11514
|
+
}
|
|
11515
|
+
alignTitleLines(el.querySelectorAll("svg.mn-guitar-chord, svg.mn-fretboard"));
|
|
11516
|
+
host.appendChild(el);
|
|
11517
|
+
const freeTabs = [];
|
|
11518
|
+
if (options.tab) {
|
|
11519
|
+
for (const pre of el.querySelectorAll("pre.mn-exercise")) {
|
|
11520
|
+
const holder = html(doc, "div", "mn-exercise-tab");
|
|
11521
|
+
for (const { name, value } of [...pre.attributes]) {
|
|
11522
|
+
if (name.startsWith("data-mn-"))
|
|
11523
|
+
holder.setAttribute(name, value);
|
|
11524
|
+
}
|
|
11525
|
+
pre.replaceWith(holder);
|
|
11526
|
+
try {
|
|
11527
|
+
const free = options.tab(pre.textContent ?? "", holder);
|
|
11528
|
+
if (typeof free === "function")
|
|
11529
|
+
freeTabs.push(free);
|
|
11530
|
+
} catch {
|
|
11531
|
+
holder.replaceWith(pre);
|
|
11532
|
+
}
|
|
11096
11533
|
}
|
|
11097
11534
|
}
|
|
11535
|
+
const picks = options.pick ? [...el.querySelectorAll("svg[data-mn-pick]")].map((svg) => attachPick(svg, pickOptions(options))) : [];
|
|
11536
|
+
const stopPlayback = options.play ? attachPlayback(el, {
|
|
11537
|
+
hand: options.hand,
|
|
11538
|
+
...typeof options.play === "object" ? options.play : {}
|
|
11539
|
+
}) : null;
|
|
11540
|
+
return {
|
|
11541
|
+
ok: error === null,
|
|
11542
|
+
el,
|
|
11543
|
+
error,
|
|
11544
|
+
picks,
|
|
11545
|
+
destroy: () => {
|
|
11546
|
+
stopPlayback?.();
|
|
11547
|
+
for (const layer of picks)
|
|
11548
|
+
layer.destroy();
|
|
11549
|
+
for (const free of freeTabs)
|
|
11550
|
+
free();
|
|
11551
|
+
el.remove();
|
|
11552
|
+
}
|
|
11553
|
+
};
|
|
11554
|
+
};
|
|
11555
|
+
function pickOptions(options) {
|
|
11556
|
+
const pick = typeof options.pick === "object" ? options.pick : {};
|
|
11557
|
+
if (pick.play !== true)
|
|
11558
|
+
return pick;
|
|
11559
|
+
return { ...pick, play: typeof options.play === "object" ? options.play : true };
|
|
11098
11560
|
}
|
|
11099
|
-
|
|
11100
|
-
const stopPlayback = options.play ? attachPlayback(el, {
|
|
11101
|
-
hand: options.hand,
|
|
11102
|
-
...typeof options.play === "object" ? options.play : {}
|
|
11103
|
-
}) : null;
|
|
11104
|
-
return {
|
|
11105
|
-
ok: error === null,
|
|
11106
|
-
el,
|
|
11107
|
-
error,
|
|
11108
|
-
picks,
|
|
11109
|
-
destroy: () => {
|
|
11110
|
-
stopPlayback?.();
|
|
11111
|
-
for (const layer of picks)
|
|
11112
|
-
layer.destroy();
|
|
11113
|
-
for (const free of freeTabs)
|
|
11114
|
-
free();
|
|
11115
|
-
el.remove();
|
|
11116
|
-
}
|
|
11117
|
-
};
|
|
11118
|
-
}
|
|
11119
|
-
function pickOptions(options) {
|
|
11120
|
-
const pick = typeof options.pick === "object" ? options.pick : {};
|
|
11121
|
-
if (pick.play !== true)
|
|
11122
|
-
return pick;
|
|
11123
|
-
return { ...pick, play: typeof options.play === "object" ? options.play : true };
|
|
11561
|
+
return withNaming(naming, draw, reading.titles);
|
|
11124
11562
|
}
|
|
11125
11563
|
function failed(el, host, language, error) {
|
|
11126
11564
|
el.replaceChildren();
|
|
@@ -11913,5 +12351,5 @@ export {
|
|
|
11913
12351
|
renderAll
|
|
11914
12352
|
};
|
|
11915
12353
|
|
|
11916
|
-
//# debugId=
|
|
12354
|
+
//# debugId=45178CB1E7CD5EC664756E2164756E21
|
|
11917
12355
|
//# sourceMappingURL=index.js.map
|