@dsebastien/music-notation 0.9.0 → 0.10.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/dist/chord/generate.d.ts +11 -0
- package/dist/chord/guitar.d.ts +5 -0
- package/dist/convert/text-tab.d.ts +9 -4
- package/dist/index.js +505 -320
- package/dist/index.js.map +14 -14
- package/dist/music-notation.css +10 -0
- package/dist/music-notation.publish.min.js +33 -23
- package/dist/music-notation.tab.min.js +17 -4
- package/dist/playback/controls.d.ts +6 -0
- package/dist/publish/index.js +430 -312
- package/dist/publish/index.js.map +13 -13
- package/dist/render/dom.d.ts +5 -0
- package/dist/strum/pattern.d.ts +6 -0
- package/dist/strum/render.d.ts +1 -1
- package/dist/tab/index.d.ts +8 -2
- package/dist/tab/index.js +93 -12
- package/dist/tab/index.js.map +6 -6
- package/dist/tab/load.d.ts +10 -0
- package/dist/voicings/check.d.ts +7 -0
- package/dist/voicings/index.js +94 -6
- package/dist/voicings/index.js.map +7 -7
- package/package.json +1 -1
package/dist/publish/index.js
CHANGED
|
@@ -22,6 +22,15 @@ function svgText(doc, text, attrs = {}) {
|
|
|
22
22
|
function svgLabel(doc, text, [x, y], cls, anchor = "middle") {
|
|
23
23
|
return svgText(doc, text, { class: cls, x, y: y + 4, "text-anchor": anchor });
|
|
24
24
|
}
|
|
25
|
+
function dotLabel(doc, text, point, r) {
|
|
26
|
+
const label = svgLabel(doc, text, point, "mn-dot-text");
|
|
27
|
+
if ([...text].length >= 3) {
|
|
28
|
+
label.classList.add("mn-dot-text-long");
|
|
29
|
+
label.setAttribute("textLength", String(2 * r - 2));
|
|
30
|
+
label.setAttribute("lengthAdjust", "spacingAndGlyphs");
|
|
31
|
+
}
|
|
32
|
+
return label;
|
|
33
|
+
}
|
|
25
34
|
function svgLine(doc, [x1, y1], [x2, y2], cls) {
|
|
26
35
|
return svg(doc, "line", { class: cls, x1, y1, x2, y2 });
|
|
27
36
|
}
|
|
@@ -295,6 +304,9 @@ function renderGuitarDiagram(doc, voicing, options = {}) {
|
|
|
295
304
|
const label = `${options.title ? `${options.title} chord diagram` : "Chord diagram"}${capo ? `, ${capoCaption(capo, options.sounds).replace(/^Capo/, "capo")}` : ""}`;
|
|
296
305
|
const height = frame.height + (caption ? CAPTION : 0);
|
|
297
306
|
const root = svgRoot(doc, frame.width, height, "mn-guitar-chord", label);
|
|
307
|
+
root.setAttribute("data-mn-hand", options.hand ?? "right");
|
|
308
|
+
const fretText = voicing.frets.map((f) => f === null ? "x" : String(f));
|
|
309
|
+
root.setAttribute("data-mn-voicing", fretText.some((f) => f.length > 1) ? fretText.join("-") : fretText.join(""));
|
|
298
310
|
if (caption) {
|
|
299
311
|
root.appendChild(svgText(doc, caption, {
|
|
300
312
|
class: "mn-caption",
|
|
@@ -336,7 +348,9 @@ function renderGuitarDiagram(doc, voicing, options = {}) {
|
|
|
336
348
|
}
|
|
337
349
|
const textOf = (s) => (options.labels ? options.labels[s] : voicing.fingers[s]) ?? null;
|
|
338
350
|
const quiet = new Set;
|
|
339
|
-
|
|
351
|
+
const fingered = voicing.fingers.some((f) => f);
|
|
352
|
+
const barres = fingered ? barresOf(voicing, capoFret) : options.barreFingers ? barresOf({ frets: voicing.frets, fingers: [...options.barreFingers] }, capoFret).filter((b) => b.full) : [];
|
|
353
|
+
for (const barre of barres) {
|
|
340
354
|
const texts = new Set(barre.strings.map(textOf));
|
|
341
355
|
if (texts.size === 1) {
|
|
342
356
|
for (const s of barre.strings)
|
|
@@ -419,7 +433,7 @@ function renderGuitarDiagram(doc, voicing, options = {}) {
|
|
|
419
433
|
cy,
|
|
420
434
|
r: 7,
|
|
421
435
|
...midi
|
|
422
|
-
}), ...text ? [
|
|
436
|
+
}), ...text ? [dotLabel(doc, text, center, 7)] : []);
|
|
423
437
|
});
|
|
424
438
|
if (tuning) {
|
|
425
439
|
const shift = fromNut ? 0 : capo;
|
|
@@ -2861,7 +2875,7 @@ function renderFretboard(doc, set, options = {}) {
|
|
|
2861
2875
|
"data-mn-string": strings - s,
|
|
2862
2876
|
"data-mn-fret": fret,
|
|
2863
2877
|
"data-mn-note": member.name
|
|
2864
|
-
}), ...text ? [
|
|
2878
|
+
}), ...text ? [dotLabel(doc, text, point, DOT_R)] : []));
|
|
2865
2879
|
sounding.add(open + fret);
|
|
2866
2880
|
}
|
|
2867
2881
|
}
|
|
@@ -2871,6 +2885,7 @@ function renderFretboard(doc, set, options = {}) {
|
|
|
2871
2885
|
root.setAttribute("data-mn-set", set.title);
|
|
2872
2886
|
root.setAttribute("data-mn-labels", label);
|
|
2873
2887
|
root.setAttribute("data-mn-orientation", orientation);
|
|
2888
|
+
root.setAttribute("data-mn-hand", options.hand ?? "right");
|
|
2874
2889
|
root.setAttribute("data-mn-frets", `${from}-${to}`);
|
|
2875
2890
|
return root;
|
|
2876
2891
|
}
|
|
@@ -2879,11 +2894,20 @@ function renderFretboard(doc, set, options = {}) {
|
|
|
2879
2894
|
var NAMED = new Map(Object.entries({
|
|
2880
2895
|
standard: "E2 A2 D3 G3 B3 E4",
|
|
2881
2896
|
"drop d": "D2 A2 D3 G3 B3 E4",
|
|
2897
|
+
"drop c": "C2 G2 C3 F3 A3 D4",
|
|
2898
|
+
"drop b": "B1 F#2 B2 E3 G#3 C#4",
|
|
2899
|
+
"drop a": "A1 E2 A2 D3 F#3 B3",
|
|
2900
|
+
"double drop d": "D2 A2 D3 G3 B3 D4",
|
|
2882
2901
|
dadgad: "D2 A2 D3 G3 A3 D4",
|
|
2883
2902
|
"open g": "D2 G2 D3 G3 B3 D4",
|
|
2884
2903
|
"open d": "D2 A2 D3 F#3 A3 D4",
|
|
2885
2904
|
"open e": "E2 B2 E3 G#3 B3 E4",
|
|
2905
|
+
"open c": "C2 G2 C3 G3 C4 E4",
|
|
2906
|
+
"open a": "E2 A2 E3 A3 C#4 E4",
|
|
2886
2907
|
"half step down": "Eb2 Ab2 Db3 Gb3 Bb3 Eb4",
|
|
2908
|
+
"whole step down": "D2 G2 C3 F3 A3 D4",
|
|
2909
|
+
"modal c6": "C2 A2 C3 G3 C4 E4",
|
|
2910
|
+
c6: "C2 A2 C3 G3 C4 E4",
|
|
2887
2911
|
bass: "E1 A1 D2 G2",
|
|
2888
2912
|
ukulele: "G4 C4 E4 A4"
|
|
2889
2913
|
}));
|
|
@@ -3328,283 +3352,6 @@ function detectChordFromFrets(frets, tuning = STANDARD) {
|
|
|
3328
3352
|
return detectChordFromPitches(pitches);
|
|
3329
3353
|
}
|
|
3330
3354
|
|
|
3331
|
-
// src/blocks/block-source.ts
|
|
3332
|
-
var FIELD = /^([A-Za-z][\w-]*)\s*:\s*(.*)$/;
|
|
3333
|
-
function parseBlockSource(source) {
|
|
3334
|
-
const fields = new Map;
|
|
3335
|
-
let head = null;
|
|
3336
|
-
source.split(/\r?\n/).map((line) => line.trim()).filter(Boolean).forEach((line, i) => {
|
|
3337
|
-
const m = FIELD.exec(line);
|
|
3338
|
-
if (m)
|
|
3339
|
-
fields.set(m[1].toLowerCase(), m[2].trim());
|
|
3340
|
-
else if (i === 0)
|
|
3341
|
-
head = line;
|
|
3342
|
-
else
|
|
3343
|
-
throw new Error(`Expected "key: value", got "${line}"`);
|
|
3344
|
-
});
|
|
3345
|
-
return { head, fields };
|
|
3346
|
-
}
|
|
3347
|
-
function parseRange(text) {
|
|
3348
|
-
const m = /^(\d+)\s*(?:-\s*(\d+))?$/.exec(text.trim());
|
|
3349
|
-
if (!m)
|
|
3350
|
-
return null;
|
|
3351
|
-
const from = Number(m[1]);
|
|
3352
|
-
const to = m[2] === undefined ? from : Number(m[2]);
|
|
3353
|
-
return from <= to ? [from, to] : null;
|
|
3354
|
-
}
|
|
3355
|
-
function parseStrings(text, count) {
|
|
3356
|
-
const range = parseRange(text);
|
|
3357
|
-
const numbers = range ? Array.from({ length: range[1] - range[0] + 1 }, (_, i) => range[0] + i) : text.split(/[\s,]+/).filter(Boolean).map(Number);
|
|
3358
|
-
if (!numbers.length || numbers.some((n) => !Number.isInteger(n) || n < 1 || n > count)) {
|
|
3359
|
-
throw new Error(`strings: use string numbers from 1 (the highest) to ${count}, e.g. 1-4`);
|
|
3360
|
-
}
|
|
3361
|
-
return numbers;
|
|
3362
|
-
}
|
|
3363
|
-
var SEPARATOR = /^\s*-{3,}\s*$/;
|
|
3364
|
-
function splitParts(source) {
|
|
3365
|
-
const lines = source.split(/\r?\n/);
|
|
3366
|
-
if (!lines.some((line) => SEPARATOR.test(line)))
|
|
3367
|
-
return null;
|
|
3368
|
-
const parts = [[]];
|
|
3369
|
-
for (const line of lines) {
|
|
3370
|
-
if (SEPARATOR.test(line))
|
|
3371
|
-
parts.push([]);
|
|
3372
|
-
else
|
|
3373
|
-
parts[parts.length - 1].push(line);
|
|
3374
|
-
}
|
|
3375
|
-
return parts.map((part) => part.join(`
|
|
3376
|
-
`)).filter((part) => part.trim() !== "");
|
|
3377
|
-
}
|
|
3378
|
-
|
|
3379
|
-
// src/fretboard/positions.ts
|
|
3380
|
-
var CAGED_SHAPES = ["E", "D", "C", "A", "G"];
|
|
3381
|
-
var MAJOR_PENTATONIC = ["1P", "2M", "3M", "5P", "6M"];
|
|
3382
|
-
var MINOR_PENTATONIC = ["1P", "3m", "4P", "5P", "7m"];
|
|
3383
|
-
var chromasOf = (set) => set.members.map((m) => m.chroma);
|
|
3384
|
-
function ascending(chromas, start, count) {
|
|
3385
|
-
const out = [];
|
|
3386
|
-
for (let midi = start;out.length < count && midi < start + 12 * 8; midi++) {
|
|
3387
|
-
if (chromas.includes((midi % 12 + 12) % 12))
|
|
3388
|
-
out.push(midi);
|
|
3389
|
-
}
|
|
3390
|
-
return out;
|
|
3391
|
-
}
|
|
3392
|
-
var fretOn = (open, chroma, from) => {
|
|
3393
|
-
let fret = from;
|
|
3394
|
-
while ((open + fret) % 12 !== chroma)
|
|
3395
|
-
fret++;
|
|
3396
|
-
return fret;
|
|
3397
|
-
};
|
|
3398
|
-
function fill(sequence, tuning, perString) {
|
|
3399
|
-
const cells = [];
|
|
3400
|
-
tuning.forEach((open, string) => {
|
|
3401
|
-
for (const midi of sequence.slice(string * perString, (string + 1) * perString)) {
|
|
3402
|
-
if (midi - open >= 0)
|
|
3403
|
-
cells.push({ string, fret: midi - open });
|
|
3404
|
-
}
|
|
3405
|
-
});
|
|
3406
|
-
return cells;
|
|
3407
|
-
}
|
|
3408
|
-
var isArpeggio = (set) => set.root !== null && !set.scaleType && !set.list;
|
|
3409
|
-
var chordTones = (set) => set.members.filter((m) => m.interval !== null).map((m) => m.chroma);
|
|
3410
|
-
function positionCount(set, system) {
|
|
3411
|
-
if (isArpeggio(set))
|
|
3412
|
-
return 5;
|
|
3413
|
-
if (system === "3nps")
|
|
3414
|
-
return set.members.length;
|
|
3415
|
-
return 5;
|
|
3416
|
-
}
|
|
3417
|
-
function pentatonicOf(set) {
|
|
3418
|
-
const intervals = set.members.map((m) => m.interval ?? "");
|
|
3419
|
-
for (const pentatonic of [MAJOR_PENTATONIC, MINOR_PENTATONIC]) {
|
|
3420
|
-
if (pentatonic.every((i) => intervals.includes(i))) {
|
|
3421
|
-
return set.members.filter((m) => pentatonic.includes(m.interval ?? "")).map((m) => m.chroma);
|
|
3422
|
-
}
|
|
3423
|
-
}
|
|
3424
|
-
return null;
|
|
3425
|
-
}
|
|
3426
|
-
var MAX_FRET2 = 36;
|
|
3427
|
-
var isMajorPentatonic = (set) => set.members.map((m) => m.interval).join(" ") === MAJOR_PENTATONIC.join(" ");
|
|
3428
|
-
var relativeMinorOf = (set) => isMajorPentatonic(set) ? set.members[4].name : undefined;
|
|
3429
|
-
function numberingOf(text, set, system) {
|
|
3430
|
-
const value = text?.trim().toLowerCase().replace(/\s+/g, " ");
|
|
3431
|
-
if (!value)
|
|
3432
|
-
return "root";
|
|
3433
|
-
if (value !== "minor" && value !== "relative minor") {
|
|
3434
|
-
throw new Error(`numbering: use minor (positions from the relative minor), got "${text}"`);
|
|
3435
|
-
}
|
|
3436
|
-
if (!isMajorPentatonic(set)) {
|
|
3437
|
-
throw new Error(`numbering: minor is for major pentatonic positions (e.g. A major pentatonic), not ${set.title}`);
|
|
3438
|
-
}
|
|
3439
|
-
if (system === "caged") {
|
|
3440
|
-
throw new Error("numbering: minor numbers boxes and 3nps positions, not CAGED shapes");
|
|
3441
|
-
}
|
|
3442
|
-
return "minor";
|
|
3443
|
-
}
|
|
3444
|
-
var fromRoot = (set, system, n, numbering) => numbering === "minor" && system !== "caged" && isMajorPentatonic(set) && n >= 1 && n <= positionCount(set, system) ? (n + 3) % positionCount(set, system) + 1 : n;
|
|
3445
|
-
var lowestFret = (cells) => Math.min(...cells.map((c) => c.fret));
|
|
3446
|
-
var highestFret = (cells) => Math.max(...cells.map((c) => c.fret));
|
|
3447
|
-
function scalePosition(set, tuning, system, n, options = {}) {
|
|
3448
|
-
const octaves = octavesOf(set, tuning, system, fromRoot(set, system, n, options.numbering));
|
|
3449
|
-
const within = options.within;
|
|
3450
|
-
const inside = within ? octaves.find((cells) => lowestFret(cells) >= within[0] && highestFret(cells) <= within[1]) : undefined;
|
|
3451
|
-
return inside ?? octaves[0] ?? null;
|
|
3452
|
-
}
|
|
3453
|
-
function neckPositions(set, tuning, system, numbering = "root", maxFret = MAX_FRET2) {
|
|
3454
|
-
let floor = 0;
|
|
3455
|
-
return Array.from({ length: positionCount(set, system) }, (_, i) => {
|
|
3456
|
-
const octaves = octavesOf(set, tuning, system, fromRoot(set, system, i + 1, numbering));
|
|
3457
|
-
const cells = octaves.find((c) => lowestFret(c) >= floor && highestFret(c) <= maxFret) ?? octaves[0] ?? null;
|
|
3458
|
-
if (cells)
|
|
3459
|
-
floor = lowestFret(cells);
|
|
3460
|
-
return cells;
|
|
3461
|
-
});
|
|
3462
|
-
}
|
|
3463
|
-
function octavesOf(set, tuning, system, n) {
|
|
3464
|
-
if (set.root === null || n < 1 || n > positionCount(set, system))
|
|
3465
|
-
return [];
|
|
3466
|
-
if (isArpeggio(set))
|
|
3467
|
-
return arpeggioOctaves(set, tuning, system, n);
|
|
3468
|
-
const open = tuning[0];
|
|
3469
|
-
const chromas = chromasOf(set);
|
|
3470
|
-
const notes = tuning.length * 3;
|
|
3471
|
-
const nps = system === "3nps" || system === "caged" && chromas.length !== 5 && !pentatonicOf(set);
|
|
3472
|
-
const pentatonic = chromas.length === 5 ? chromas : pentatonicOf(set);
|
|
3473
|
-
if (!nps && !pentatonic)
|
|
3474
|
-
return [];
|
|
3475
|
-
const startChroma = nps ? chromas[(n - 1) % chromas.length] : pentatonic[(n - 1) % 5];
|
|
3476
|
-
const out = [];
|
|
3477
|
-
for (let start = fretOn(open, startChroma, 0);start <= MAX_FRET2; start += 12) {
|
|
3478
|
-
const cells = nps ? fill(ascending(chromas, open + start, notes), tuning, 3) : withOther(fill(ascending(pentatonic, open + start, tuning.length * 2), tuning, 2), system === "caged" && chromas.length !== 5 ? chromas : null, tuning);
|
|
3479
|
-
if (cells && cells.every((c) => c.fret >= 0))
|
|
3480
|
-
out.push(cells);
|
|
3481
|
-
}
|
|
3482
|
-
return out;
|
|
3483
|
-
}
|
|
3484
|
-
function arpeggioOctaves(set, tuning, system, n) {
|
|
3485
|
-
const tones = chordTones(set);
|
|
3486
|
-
if (system === "3nps")
|
|
3487
|
-
return [];
|
|
3488
|
-
const minor = set.members.some((m) => m.interval === "3m");
|
|
3489
|
-
const parent = scaleNoteSet(`${set.members[0].name} ${minor ? "minor" : "major"}`);
|
|
3490
|
-
if (!parent)
|
|
3491
|
-
return [];
|
|
3492
|
-
const inScale = new Set(parent.members.map((m) => m.chroma));
|
|
3493
|
-
const outside = tones.filter((c) => !inScale.has(c));
|
|
3494
|
-
const pitch = (c) => tuning[c.string] + c.fret;
|
|
3495
|
-
return octavesOf(parent, tuning, "caged", n).map((cells) => (outside.length ? withOtherNotes(cells, outside, tuning) : cells).filter((c) => tones.includes(pitch(c) % 12))).filter((cells) => cells.length > 0);
|
|
3496
|
-
}
|
|
3497
|
-
function withOther(box, chromas, tuning) {
|
|
3498
|
-
if (box.length < tuning.length * 2)
|
|
3499
|
-
return null;
|
|
3500
|
-
return chromas ? withOtherNotes(box, chromas, tuning) : box;
|
|
3501
|
-
}
|
|
3502
|
-
function withOtherNotes(box, chromas, tuning) {
|
|
3503
|
-
const pitch = (c) => tuning[c.string] + c.fret;
|
|
3504
|
-
const min = Math.min(...box.map((c) => c.fret));
|
|
3505
|
-
const max = Math.max(...box.map((c) => c.fret));
|
|
3506
|
-
const out = [...box];
|
|
3507
|
-
const ordered = [...box].sort((a, b) => pitch(a) - pitch(b));
|
|
3508
|
-
const outside = (fret) => fret < min ? min - fret : fret > max ? fret - max : 0;
|
|
3509
|
-
for (let i = 0;i + 1 < ordered.length; i++) {
|
|
3510
|
-
const below = ordered[i];
|
|
3511
|
-
const above = ordered[i + 1];
|
|
3512
|
-
for (let midi = pitch(below) + 1;midi < pitch(above); midi++) {
|
|
3513
|
-
if (!chromas.includes(midi % 12))
|
|
3514
|
-
continue;
|
|
3515
|
-
const onBelow = midi - tuning[below.string];
|
|
3516
|
-
const onAbove = midi - tuning[above.string];
|
|
3517
|
-
const string = below.string === above.string || onAbove < 0 || outside(onBelow) <= outside(onAbove) ? below.string : above.string;
|
|
3518
|
-
out.push({ string, fret: midi - tuning[string] });
|
|
3519
|
-
}
|
|
3520
|
-
}
|
|
3521
|
-
const low = 0;
|
|
3522
|
-
const high = tuning.length - 1;
|
|
3523
|
-
const lowest = pitch(ordered[0]);
|
|
3524
|
-
const highest = pitch(ordered[ordered.length - 1]);
|
|
3525
|
-
const from = Math.min(...out.map((c) => c.fret));
|
|
3526
|
-
const to = Math.max(...out.map((c) => c.fret));
|
|
3527
|
-
const extra = [];
|
|
3528
|
-
for (let fret = from;fret <= to; fret++) {
|
|
3529
|
-
const below = tuning[low] + fret;
|
|
3530
|
-
if (below < lowest && chromas.includes(below % 12))
|
|
3531
|
-
extra.push({ string: low, fret });
|
|
3532
|
-
const above = tuning[high] + fret;
|
|
3533
|
-
if (above > highest && chromas.includes(above % 12))
|
|
3534
|
-
extra.push({ string: high, fret });
|
|
3535
|
-
}
|
|
3536
|
-
return [...out, ...extra];
|
|
3537
|
-
}
|
|
3538
|
-
function positionOf(positionText, shapeText) {
|
|
3539
|
-
const shape = shapeText?.trim().toLowerCase();
|
|
3540
|
-
const n = positionText === undefined ? null : Number(positionText);
|
|
3541
|
-
if (positionText !== undefined && (!Number.isInteger(n) || n < 1)) {
|
|
3542
|
-
throw new Error(`position must be a whole number from 1, got "${positionText}"`);
|
|
3543
|
-
}
|
|
3544
|
-
if (shape === undefined || shape === "")
|
|
3545
|
-
return n === null ? null : { system: "box", n };
|
|
3546
|
-
if (shape === "3nps")
|
|
3547
|
-
return { system: "3nps", n: n ?? 1 };
|
|
3548
|
-
const letter = shape.replace(/^caged\s*/, "").replace(/[\s-]*shape$/, "");
|
|
3549
|
-
const caged = CAGED_SHAPES.findIndex((s) => s.toLowerCase() === letter);
|
|
3550
|
-
if (caged >= 0)
|
|
3551
|
-
return { system: "caged", n: caged + 1 };
|
|
3552
|
-
throw new Error(`Unknown shape "${shapeText}": use C, A, G, E, D or 3nps`);
|
|
3553
|
-
}
|
|
3554
|
-
|
|
3555
|
-
// src/blocks/scales-for.ts
|
|
3556
|
-
var OWN_NOTES = ["scale", "chord", "notes", "root", "modes"];
|
|
3557
|
-
var TITLE_ITEMS = 6;
|
|
3558
|
-
function scalesForBlock(block) {
|
|
3559
|
-
const chords = block.fields.get("scales-for")?.trim();
|
|
3560
|
-
const notes = block.fields.get("scales-for-notes")?.trim();
|
|
3561
|
-
if (chords === undefined && notes === undefined)
|
|
3562
|
-
return block;
|
|
3563
|
-
if (chords !== undefined && notes !== undefined) {
|
|
3564
|
-
throw new Error("Use scales-for (chords) or scales-for-notes, not both");
|
|
3565
|
-
}
|
|
3566
|
-
const key = chords !== undefined ? "scales-for" : "scales-for-notes";
|
|
3567
|
-
const own = OWN_NOTES.find((k) => block.fields.has(k));
|
|
3568
|
-
if (own || block.head) {
|
|
3569
|
-
throw new Error(`${key} finds the scale itself: remove "${own ?? block.head}"`);
|
|
3570
|
-
}
|
|
3571
|
-
const text = chords ?? notes;
|
|
3572
|
-
const items = text.split(/[\s,|]+/).filter(Boolean);
|
|
3573
|
-
if (!items.length) {
|
|
3574
|
-
throw new Error(chords !== undefined ? "Add the chords: e.g. scales-for: G D Em C" : "Add the notes: e.g. scales-for-notes: C D E G A");
|
|
3575
|
-
}
|
|
3576
|
-
const [best] = findScales(items, { as: chords !== undefined ? "chords" : "notes" });
|
|
3577
|
-
if (!best) {
|
|
3578
|
-
throw new Error(chords !== undefined ? `Didn't read the chords "${text}": use chord symbols, e.g. scales-for: G D Em C` : `Didn't read the notes "${text}": use note names, e.g. scales-for-notes: C D E G A`);
|
|
3579
|
-
}
|
|
3580
|
-
const listed = items.slice(0, TITLE_ITEMS).join(" ") + (items.length > TITLE_ITEMS ? "…" : "");
|
|
3581
|
-
const outside = best.outside.length ? `, ${best.outside.join(" ")} outside` : "";
|
|
3582
|
-
const fields = new Map([...block.fields].filter(([k]) => k !== key));
|
|
3583
|
-
fields.set("scale", best.name);
|
|
3584
|
-
const blues = chords !== undefined ? bluesTonic(items) : null;
|
|
3585
|
-
const title = blues && best.type === "minor blues" ? `${best.tonic} blues scale for ${listed} (or ${best.tonic} minor pentatonic, ${best.tonic} mixolydian)` : `${best.name} for ${listed}${outside}`;
|
|
3586
|
-
if (!fields.get("title"))
|
|
3587
|
-
fields.set("title", title);
|
|
3588
|
-
return { head: null, fields };
|
|
3589
|
-
}
|
|
3590
|
-
function resolveScalesFor(source) {
|
|
3591
|
-
let block;
|
|
3592
|
-
try {
|
|
3593
|
-
block = parseBlockSource(source);
|
|
3594
|
-
} catch {
|
|
3595
|
-
return source;
|
|
3596
|
-
}
|
|
3597
|
-
const { fields } = block;
|
|
3598
|
-
if (!fields.has("scales-for") && !fields.has("scales-for-notes"))
|
|
3599
|
-
return source;
|
|
3600
|
-
if (!fields.has("positions") && !fields.has("modes"))
|
|
3601
|
-
return source;
|
|
3602
|
-
const resolved = scalesForBlock(block);
|
|
3603
|
-
return [...resolved.fields].map(([key, value]) => `${key}: ${value}`).join(`
|
|
3604
|
-
`);
|
|
3605
|
-
}
|
|
3606
|
-
var withScalesFor = (render) => (doc, block, options) => render(doc, scalesForBlock(block), options);
|
|
3607
|
-
|
|
3608
3355
|
// src/chord/generate.ts
|
|
3609
3356
|
var isBarreShape = (shape) => shape === "E shape" || shape === "A shape";
|
|
3610
3357
|
var MAX_GENERATED_STRINGS = 8;
|
|
@@ -3818,7 +3565,8 @@ function shapeOf(frets, info, targets, tuning) {
|
|
|
3818
3565
|
if (info.members.length === 2 && info.tones.every((t) => t.number === 1 || t.number === 5)) {
|
|
3819
3566
|
return "Power chord";
|
|
3820
3567
|
}
|
|
3821
|
-
const
|
|
3568
|
+
const lowest = (tuning[sounding[0]] + frets[sounding[0]]) % 12;
|
|
3569
|
+
const shell = sounding.length === 3 && chromas.size === 3 && lowest === info.root && info.tones.some((t) => t.number === 7 || t.number === 6) && [...chromas].every((c) => info.tones.some((t) => t.chroma === c && [1, 3, 6, 7].includes(t.number)));
|
|
3822
3570
|
if (shell)
|
|
3823
3571
|
return "Shell";
|
|
3824
3572
|
const adjacent = sounding[sounding.length - 1] - sounding[0] === sounding.length - 1;
|
|
@@ -3865,6 +3613,36 @@ var KNOWN_SHAPES = new Set([
|
|
|
3865
3613
|
"D shape",
|
|
3866
3614
|
"Power chord"
|
|
3867
3615
|
]);
|
|
3616
|
+
var JAZZ_GRIPS = [
|
|
3617
|
+
{ rootString: 1, offsets: [null, 0, -1, 0, 1, null] },
|
|
3618
|
+
{ rootString: 0, offsets: [0, null, 0, 0, -1, null] },
|
|
3619
|
+
{ rootString: 0, offsets: [0, null, -1, 0, -1, null] },
|
|
3620
|
+
{ rootString: 0, offsets: [0, null, 0, 1, 2, null] }
|
|
3621
|
+
];
|
|
3622
|
+
function distinctShapes(voicings, count = voicings.length) {
|
|
3623
|
+
const sounding = (v) => v.frets.flatMap((f, s) => f === null ? [] : [s]);
|
|
3624
|
+
const copyOf = (v, w) => {
|
|
3625
|
+
const mine = sounding(v);
|
|
3626
|
+
const theirs = sounding(w);
|
|
3627
|
+
return mine.length < theirs.length && v.frets.length === w.frets.length && mine.every((s, i) => theirs[i] === s && w.frets[s] === v.frets[s]);
|
|
3628
|
+
};
|
|
3629
|
+
const kept = voicings.filter((v) => !voicings.some((w) => w !== v && copyOf(v, w)));
|
|
3630
|
+
const lowest = (v) => {
|
|
3631
|
+
const fretted = v.frets.filter((f) => f !== null && f > 0);
|
|
3632
|
+
return fretted.length ? Math.min(...fretted) : 0;
|
|
3633
|
+
};
|
|
3634
|
+
return kept.slice(0, count).map((v, rank) => ({ v, rank })).sort((a, b) => lowest(a.v) - lowest(b.v) || a.rank - b.rank).map(({ v }) => v);
|
|
3635
|
+
}
|
|
3636
|
+
function isJazzGrip(frets) {
|
|
3637
|
+
if (frets.length !== 6)
|
|
3638
|
+
return false;
|
|
3639
|
+
return JAZZ_GRIPS.some(({ rootString, offsets }) => {
|
|
3640
|
+
const root = frets[rootString];
|
|
3641
|
+
if (root === null || root === undefined || root < 1)
|
|
3642
|
+
return false;
|
|
3643
|
+
return offsets.every((o, s) => o === null ? frets[s] === null : frets[s] === root + o);
|
|
3644
|
+
});
|
|
3645
|
+
}
|
|
3868
3646
|
var indexOf = (number, count) => count - number;
|
|
3869
3647
|
var bits = (n) => {
|
|
3870
3648
|
let count = 0;
|
|
@@ -3990,8 +3768,15 @@ function generateVoicings(symbol, options = {}) {
|
|
|
3990
3768
|
difficulty += 0.5;
|
|
3991
3769
|
reasons.push("no fifth");
|
|
3992
3770
|
}
|
|
3771
|
+
const jazz = standard && isJazzGrip(candidate);
|
|
3772
|
+
if (jazz) {
|
|
3773
|
+
difficulty -= 2 * inner + strings.filter((s) => s > last).length * 1.5;
|
|
3774
|
+
reasons.push("jazz grip");
|
|
3775
|
+
}
|
|
3993
3776
|
if (usual)
|
|
3994
3777
|
difficulty -= 3;
|
|
3778
|
+
else if (jazz)
|
|
3779
|
+
difficulty -= 1.5;
|
|
3995
3780
|
else if (isBarreShape(shape) && barre)
|
|
3996
3781
|
difficulty -= 2;
|
|
3997
3782
|
else if (shape && KNOWN_SHAPES.has(shape))
|
|
@@ -4020,31 +3805,329 @@ function generateVoicings(symbol, options = {}) {
|
|
|
4020
3805
|
results.set(frets.join(","), voicing);
|
|
4021
3806
|
return;
|
|
4022
3807
|
}
|
|
4023
|
-
const left = closed ? 0 : (allowed.has(s) ? 1 : 0) + allowedAfter[s];
|
|
4024
|
-
if (bits(required & ~have) > left || sounded + left < minStrings)
|
|
4025
|
-
return;
|
|
4026
|
-
for (const fret of choices[s]) {
|
|
4027
|
-
if (fret === null) {
|
|
4028
|
-
frets[s] = null;
|
|
4029
|
-
visit(s + 1, min, max, have, sounded, closed || sounded > 0 && !options.gaps);
|
|
4030
|
-
continue;
|
|
4031
|
-
}
|
|
4032
|
-
if (closed)
|
|
4033
|
-
continue;
|
|
4034
|
-
const fretted = fret > 0;
|
|
4035
|
-
const nextMin = fretted ? Math.min(min, fret) : min;
|
|
4036
|
-
const nextMax = fretted ? Math.max(max, fret) : max;
|
|
4037
|
-
if (fretted && nextMax - nextMin + 1 > maxSpan)
|
|
3808
|
+
const left = closed ? 0 : (allowed.has(s) ? 1 : 0) + allowedAfter[s];
|
|
3809
|
+
if (bits(required & ~have) > left || sounded + left < minStrings)
|
|
3810
|
+
return;
|
|
3811
|
+
for (const fret of choices[s]) {
|
|
3812
|
+
if (fret === null) {
|
|
3813
|
+
frets[s] = null;
|
|
3814
|
+
visit(s + 1, min, max, have, sounded, closed || sounded > 0 && !options.gaps);
|
|
3815
|
+
continue;
|
|
3816
|
+
}
|
|
3817
|
+
if (closed)
|
|
3818
|
+
continue;
|
|
3819
|
+
const fretted = fret > 0;
|
|
3820
|
+
const nextMin = fretted ? Math.min(min, fret) : min;
|
|
3821
|
+
const nextMax = fretted ? Math.max(max, fret) : max;
|
|
3822
|
+
if (fretted && nextMax - nextMin + 1 > maxSpan)
|
|
3823
|
+
continue;
|
|
3824
|
+
frets[s] = fret;
|
|
3825
|
+
visit(s + 1, nextMin, nextMax, have | 1 << (tuning[s] + fret) % 12, sounded + 1, false);
|
|
3826
|
+
}
|
|
3827
|
+
frets[s] = null;
|
|
3828
|
+
};
|
|
3829
|
+
visit(0, Infinity, -Infinity, 0, 0, false);
|
|
3830
|
+
if (standard && !options.gaps) {
|
|
3831
|
+
for (const { rootString, offsets } of JAZZ_GRIPS) {
|
|
3832
|
+
if (!allowed.has(rootString))
|
|
3833
|
+
continue;
|
|
3834
|
+
const rootFret = ((info.root - tuning[rootString]) % 12 + 12) % 12;
|
|
3835
|
+
for (const at of [rootFret, rootFret + 12]) {
|
|
3836
|
+
const candidate = offsets.map((o) => o === null ? null : at + o);
|
|
3837
|
+
if (candidate.some((f, s) => f !== null && (f < 1 || !choices[s].includes(f))))
|
|
3838
|
+
continue;
|
|
3839
|
+
const have = candidate.reduce((mask, f, s) => f === null ? mask : mask | 1 << (tuning[s] + f) % 12, 0);
|
|
3840
|
+
if ((required & ~have) !== 0)
|
|
3841
|
+
continue;
|
|
3842
|
+
const key = candidate.join(",");
|
|
3843
|
+
if (results.has(key))
|
|
3844
|
+
continue;
|
|
3845
|
+
const voicing = evaluate(candidate);
|
|
3846
|
+
if (voicing)
|
|
3847
|
+
results.set(key, voicing);
|
|
3848
|
+
}
|
|
3849
|
+
}
|
|
3850
|
+
}
|
|
3851
|
+
const sounding = (v) => v.frets.filter((f) => f !== null).length;
|
|
3852
|
+
return [...results.values()].sort((a, b) => a.difficulty - b.difficulty || sounding(b) - sounding(a) || a.baseFret - b.baseFret || a.frets.join(",").localeCompare(b.frets.join(",")));
|
|
3853
|
+
}
|
|
3854
|
+
|
|
3855
|
+
// src/blocks/block-source.ts
|
|
3856
|
+
var FIELD = /^([A-Za-z][\w-]*)\s*:\s*(.*)$/;
|
|
3857
|
+
function parseBlockSource(source) {
|
|
3858
|
+
const fields = new Map;
|
|
3859
|
+
let head = null;
|
|
3860
|
+
source.split(/\r?\n/).map((line) => line.trim()).filter(Boolean).forEach((line, i) => {
|
|
3861
|
+
const m = FIELD.exec(line);
|
|
3862
|
+
if (m)
|
|
3863
|
+
fields.set(m[1].toLowerCase(), m[2].trim());
|
|
3864
|
+
else if (i === 0)
|
|
3865
|
+
head = line;
|
|
3866
|
+
else
|
|
3867
|
+
throw new Error(`Expected "key: value", got "${line}"`);
|
|
3868
|
+
});
|
|
3869
|
+
return { head, fields };
|
|
3870
|
+
}
|
|
3871
|
+
function parseRange(text) {
|
|
3872
|
+
const m = /^(\d+)\s*(?:-\s*(\d+))?$/.exec(text.trim());
|
|
3873
|
+
if (!m)
|
|
3874
|
+
return null;
|
|
3875
|
+
const from = Number(m[1]);
|
|
3876
|
+
const to = m[2] === undefined ? from : Number(m[2]);
|
|
3877
|
+
return from <= to ? [from, to] : null;
|
|
3878
|
+
}
|
|
3879
|
+
function parseStrings(text, count) {
|
|
3880
|
+
const range = parseRange(text);
|
|
3881
|
+
const numbers = range ? Array.from({ length: range[1] - range[0] + 1 }, (_, i) => range[0] + i) : text.split(/[\s,]+/).filter(Boolean).map(Number);
|
|
3882
|
+
if (!numbers.length || numbers.some((n) => !Number.isInteger(n) || n < 1 || n > count)) {
|
|
3883
|
+
throw new Error(`strings: use string numbers from 1 (the highest) to ${count}, e.g. 1-4`);
|
|
3884
|
+
}
|
|
3885
|
+
return numbers;
|
|
3886
|
+
}
|
|
3887
|
+
var SEPARATOR = /^\s*-{3,}\s*$/;
|
|
3888
|
+
function splitParts(source) {
|
|
3889
|
+
const lines = source.split(/\r?\n/);
|
|
3890
|
+
if (!lines.some((line) => SEPARATOR.test(line)))
|
|
3891
|
+
return null;
|
|
3892
|
+
const parts = [[]];
|
|
3893
|
+
for (const line of lines) {
|
|
3894
|
+
if (SEPARATOR.test(line))
|
|
3895
|
+
parts.push([]);
|
|
3896
|
+
else
|
|
3897
|
+
parts[parts.length - 1].push(line);
|
|
3898
|
+
}
|
|
3899
|
+
return parts.map((part) => part.join(`
|
|
3900
|
+
`)).filter((part) => part.trim() !== "");
|
|
3901
|
+
}
|
|
3902
|
+
|
|
3903
|
+
// src/fretboard/positions.ts
|
|
3904
|
+
var CAGED_SHAPES = ["E", "D", "C", "A", "G"];
|
|
3905
|
+
var MAJOR_PENTATONIC = ["1P", "2M", "3M", "5P", "6M"];
|
|
3906
|
+
var MINOR_PENTATONIC = ["1P", "3m", "4P", "5P", "7m"];
|
|
3907
|
+
var chromasOf = (set) => set.members.map((m) => m.chroma);
|
|
3908
|
+
function ascending(chromas, start, count) {
|
|
3909
|
+
const out = [];
|
|
3910
|
+
for (let midi = start;out.length < count && midi < start + 12 * 8; midi++) {
|
|
3911
|
+
if (chromas.includes((midi % 12 + 12) % 12))
|
|
3912
|
+
out.push(midi);
|
|
3913
|
+
}
|
|
3914
|
+
return out;
|
|
3915
|
+
}
|
|
3916
|
+
var fretOn = (open, chroma, from) => {
|
|
3917
|
+
let fret = from;
|
|
3918
|
+
while ((open + fret) % 12 !== chroma)
|
|
3919
|
+
fret++;
|
|
3920
|
+
return fret;
|
|
3921
|
+
};
|
|
3922
|
+
function fill(sequence, tuning, perString) {
|
|
3923
|
+
const cells = [];
|
|
3924
|
+
tuning.forEach((open, string) => {
|
|
3925
|
+
for (const midi of sequence.slice(string * perString, (string + 1) * perString)) {
|
|
3926
|
+
if (midi - open >= 0)
|
|
3927
|
+
cells.push({ string, fret: midi - open });
|
|
3928
|
+
}
|
|
3929
|
+
});
|
|
3930
|
+
return cells;
|
|
3931
|
+
}
|
|
3932
|
+
var isArpeggio = (set) => set.root !== null && !set.scaleType && !set.list;
|
|
3933
|
+
var chordTones = (set) => set.members.filter((m) => m.interval !== null).map((m) => m.chroma);
|
|
3934
|
+
function positionCount(set, system) {
|
|
3935
|
+
if (isArpeggio(set))
|
|
3936
|
+
return 5;
|
|
3937
|
+
if (system === "3nps")
|
|
3938
|
+
return set.members.length;
|
|
3939
|
+
return 5;
|
|
3940
|
+
}
|
|
3941
|
+
function pentatonicOf(set) {
|
|
3942
|
+
const intervals = set.members.map((m) => m.interval ?? "");
|
|
3943
|
+
for (const pentatonic of [MAJOR_PENTATONIC, MINOR_PENTATONIC]) {
|
|
3944
|
+
if (pentatonic.every((i) => intervals.includes(i))) {
|
|
3945
|
+
return set.members.filter((m) => pentatonic.includes(m.interval ?? "")).map((m) => m.chroma);
|
|
3946
|
+
}
|
|
3947
|
+
}
|
|
3948
|
+
return null;
|
|
3949
|
+
}
|
|
3950
|
+
var MAX_FRET2 = 36;
|
|
3951
|
+
var isMajorPentatonic = (set) => set.members.map((m) => m.interval).join(" ") === MAJOR_PENTATONIC.join(" ");
|
|
3952
|
+
var relativeMinorOf = (set) => isMajorPentatonic(set) ? set.members[4].name : undefined;
|
|
3953
|
+
function numberingOf(text, set, system) {
|
|
3954
|
+
const value = text?.trim().toLowerCase().replace(/\s+/g, " ");
|
|
3955
|
+
if (!value)
|
|
3956
|
+
return "root";
|
|
3957
|
+
if (value !== "minor" && value !== "relative minor") {
|
|
3958
|
+
throw new Error(`numbering: use minor (positions from the relative minor), got "${text}"`);
|
|
3959
|
+
}
|
|
3960
|
+
if (!isMajorPentatonic(set)) {
|
|
3961
|
+
throw new Error(`numbering: minor is for major pentatonic positions (e.g. A major pentatonic), not ${set.title}`);
|
|
3962
|
+
}
|
|
3963
|
+
if (system === "caged") {
|
|
3964
|
+
throw new Error("numbering: minor numbers boxes and 3nps positions, not CAGED shapes");
|
|
3965
|
+
}
|
|
3966
|
+
return "minor";
|
|
3967
|
+
}
|
|
3968
|
+
var fromRoot = (set, system, n, numbering) => numbering === "minor" && system !== "caged" && isMajorPentatonic(set) && n >= 1 && n <= positionCount(set, system) ? (n + 3) % positionCount(set, system) + 1 : n;
|
|
3969
|
+
var lowestFret = (cells) => Math.min(...cells.map((c) => c.fret));
|
|
3970
|
+
var highestFret = (cells) => Math.max(...cells.map((c) => c.fret));
|
|
3971
|
+
function scalePosition(set, tuning, system, n, options = {}) {
|
|
3972
|
+
const octaves = octavesOf(set, tuning, system, fromRoot(set, system, n, options.numbering));
|
|
3973
|
+
const within = options.within;
|
|
3974
|
+
const inside = within ? octaves.find((cells) => lowestFret(cells) >= within[0] && highestFret(cells) <= within[1]) : undefined;
|
|
3975
|
+
return inside ?? octaves[0] ?? null;
|
|
3976
|
+
}
|
|
3977
|
+
function neckPositions(set, tuning, system, numbering = "root", maxFret = MAX_FRET2) {
|
|
3978
|
+
let floor = 0;
|
|
3979
|
+
return Array.from({ length: positionCount(set, system) }, (_, i) => {
|
|
3980
|
+
const octaves = octavesOf(set, tuning, system, fromRoot(set, system, i + 1, numbering));
|
|
3981
|
+
const cells = octaves.find((c) => lowestFret(c) >= floor && highestFret(c) <= maxFret) ?? octaves[0] ?? null;
|
|
3982
|
+
if (cells)
|
|
3983
|
+
floor = lowestFret(cells);
|
|
3984
|
+
return cells;
|
|
3985
|
+
});
|
|
3986
|
+
}
|
|
3987
|
+
function octavesOf(set, tuning, system, n) {
|
|
3988
|
+
if (set.root === null || n < 1 || n > positionCount(set, system))
|
|
3989
|
+
return [];
|
|
3990
|
+
if (isArpeggio(set))
|
|
3991
|
+
return arpeggioOctaves(set, tuning, system, n);
|
|
3992
|
+
const open = tuning[0];
|
|
3993
|
+
const chromas = chromasOf(set);
|
|
3994
|
+
const notes = tuning.length * 3;
|
|
3995
|
+
const nps = system === "3nps" || system === "caged" && chromas.length !== 5 && !pentatonicOf(set);
|
|
3996
|
+
const pentatonic = chromas.length === 5 ? chromas : pentatonicOf(set);
|
|
3997
|
+
if (!nps && !pentatonic)
|
|
3998
|
+
return [];
|
|
3999
|
+
const startChroma = nps ? chromas[(n - 1) % chromas.length] : pentatonic[(n - 1) % 5];
|
|
4000
|
+
const out = [];
|
|
4001
|
+
for (let start = fretOn(open, startChroma, 0);start <= MAX_FRET2; start += 12) {
|
|
4002
|
+
const cells = nps ? fill(ascending(chromas, open + start, notes), tuning, 3) : withOther(fill(ascending(pentatonic, open + start, tuning.length * 2), tuning, 2), system === "caged" && chromas.length !== 5 ? chromas : null, tuning);
|
|
4003
|
+
if (cells && cells.every((c) => c.fret >= 0))
|
|
4004
|
+
out.push(cells);
|
|
4005
|
+
}
|
|
4006
|
+
return out;
|
|
4007
|
+
}
|
|
4008
|
+
function arpeggioOctaves(set, tuning, system, n) {
|
|
4009
|
+
const tones = chordTones(set);
|
|
4010
|
+
if (system === "3nps")
|
|
4011
|
+
return [];
|
|
4012
|
+
const minor = set.members.some((m) => m.interval === "3m");
|
|
4013
|
+
const parent = scaleNoteSet(`${set.members[0].name} ${minor ? "minor" : "major"}`);
|
|
4014
|
+
if (!parent)
|
|
4015
|
+
return [];
|
|
4016
|
+
const inScale = new Set(parent.members.map((m) => m.chroma));
|
|
4017
|
+
const outside = tones.filter((c) => !inScale.has(c));
|
|
4018
|
+
const pitch = (c) => tuning[c.string] + c.fret;
|
|
4019
|
+
return octavesOf(parent, tuning, "caged", n).map((cells) => (outside.length ? withOtherNotes(cells, outside, tuning) : cells).filter((c) => tones.includes(pitch(c) % 12))).filter((cells) => cells.length > 0);
|
|
4020
|
+
}
|
|
4021
|
+
function withOther(box, chromas, tuning) {
|
|
4022
|
+
if (box.length < tuning.length * 2)
|
|
4023
|
+
return null;
|
|
4024
|
+
return chromas ? withOtherNotes(box, chromas, tuning) : box;
|
|
4025
|
+
}
|
|
4026
|
+
function withOtherNotes(box, chromas, tuning) {
|
|
4027
|
+
const pitch = (c) => tuning[c.string] + c.fret;
|
|
4028
|
+
const min = Math.min(...box.map((c) => c.fret));
|
|
4029
|
+
const max = Math.max(...box.map((c) => c.fret));
|
|
4030
|
+
const out = [...box];
|
|
4031
|
+
const ordered = [...box].sort((a, b) => pitch(a) - pitch(b));
|
|
4032
|
+
const outside = (fret) => fret < min ? min - fret : fret > max ? fret - max : 0;
|
|
4033
|
+
for (let i = 0;i + 1 < ordered.length; i++) {
|
|
4034
|
+
const below = ordered[i];
|
|
4035
|
+
const above = ordered[i + 1];
|
|
4036
|
+
for (let midi = pitch(below) + 1;midi < pitch(above); midi++) {
|
|
4037
|
+
if (!chromas.includes(midi % 12))
|
|
4038
4038
|
continue;
|
|
4039
|
-
|
|
4040
|
-
|
|
4039
|
+
const onBelow = midi - tuning[below.string];
|
|
4040
|
+
const onAbove = midi - tuning[above.string];
|
|
4041
|
+
const string = below.string === above.string || onAbove < 0 || outside(onBelow) <= outside(onAbove) ? below.string : above.string;
|
|
4042
|
+
out.push({ string, fret: midi - tuning[string] });
|
|
4041
4043
|
}
|
|
4042
|
-
|
|
4043
|
-
|
|
4044
|
-
|
|
4045
|
-
const
|
|
4046
|
-
|
|
4044
|
+
}
|
|
4045
|
+
const low = 0;
|
|
4046
|
+
const high = tuning.length - 1;
|
|
4047
|
+
const lowest = pitch(ordered[0]);
|
|
4048
|
+
const highest = pitch(ordered[ordered.length - 1]);
|
|
4049
|
+
const from = Math.min(...out.map((c) => c.fret));
|
|
4050
|
+
const to = Math.max(...out.map((c) => c.fret));
|
|
4051
|
+
const extra = [];
|
|
4052
|
+
for (let fret = from;fret <= to; fret++) {
|
|
4053
|
+
const below = tuning[low] + fret;
|
|
4054
|
+
if (below < lowest && chromas.includes(below % 12))
|
|
4055
|
+
extra.push({ string: low, fret });
|
|
4056
|
+
const above = tuning[high] + fret;
|
|
4057
|
+
if (above > highest && chromas.includes(above % 12))
|
|
4058
|
+
extra.push({ string: high, fret });
|
|
4059
|
+
}
|
|
4060
|
+
return [...out, ...extra];
|
|
4061
|
+
}
|
|
4062
|
+
function positionOf(positionText, shapeText) {
|
|
4063
|
+
const shape = shapeText?.trim().toLowerCase();
|
|
4064
|
+
const n = positionText === undefined ? null : Number(positionText);
|
|
4065
|
+
if (positionText !== undefined && (!Number.isInteger(n) || n < 1)) {
|
|
4066
|
+
throw new Error(`position must be a whole number from 1, got "${positionText}"`);
|
|
4067
|
+
}
|
|
4068
|
+
if (shape === undefined || shape === "")
|
|
4069
|
+
return n === null ? null : { system: "box", n };
|
|
4070
|
+
if (shape === "3nps")
|
|
4071
|
+
return { system: "3nps", n: n ?? 1 };
|
|
4072
|
+
const letter = shape.replace(/^caged\s*/, "").replace(/[\s-]*shape$/, "");
|
|
4073
|
+
const caged = CAGED_SHAPES.findIndex((s) => s.toLowerCase() === letter);
|
|
4074
|
+
if (caged >= 0)
|
|
4075
|
+
return { system: "caged", n: caged + 1 };
|
|
4076
|
+
throw new Error(`Unknown shape "${shapeText}": use C, A, G, E, D or 3nps`);
|
|
4077
|
+
}
|
|
4078
|
+
|
|
4079
|
+
// src/blocks/scales-for.ts
|
|
4080
|
+
var OWN_NOTES = ["scale", "chord", "notes", "root", "modes"];
|
|
4081
|
+
var TITLE_ITEMS = 6;
|
|
4082
|
+
function scalesForBlock(block) {
|
|
4083
|
+
const chords = block.fields.get("scales-for")?.trim();
|
|
4084
|
+
const notes = block.fields.get("scales-for-notes")?.trim();
|
|
4085
|
+
if (chords === undefined && notes === undefined)
|
|
4086
|
+
return block;
|
|
4087
|
+
if (chords !== undefined && notes !== undefined) {
|
|
4088
|
+
throw new Error("Use scales-for (chords) or scales-for-notes, not both");
|
|
4089
|
+
}
|
|
4090
|
+
const key = chords !== undefined ? "scales-for" : "scales-for-notes";
|
|
4091
|
+
const own = OWN_NOTES.find((k) => block.fields.has(k));
|
|
4092
|
+
if (own || block.head) {
|
|
4093
|
+
throw new Error(`${key} finds the scale itself: remove "${own ?? block.head}"`);
|
|
4094
|
+
}
|
|
4095
|
+
const text = chords ?? notes;
|
|
4096
|
+
const items = text.split(/[\s,|]+/).filter(Boolean);
|
|
4097
|
+
if (!items.length) {
|
|
4098
|
+
throw new Error(chords !== undefined ? "Add the chords: e.g. scales-for: G D Em C" : "Add the notes: e.g. scales-for-notes: C D E G A");
|
|
4099
|
+
}
|
|
4100
|
+
const [best] = findScales(items, { as: chords !== undefined ? "chords" : "notes" });
|
|
4101
|
+
if (!best) {
|
|
4102
|
+
throw new Error(chords !== undefined ? `Didn't read the chords "${text}": use chord symbols, e.g. scales-for: G D Em C` : `Didn't read the notes "${text}": use note names, e.g. scales-for-notes: C D E G A`);
|
|
4103
|
+
}
|
|
4104
|
+
const listed = items.slice(0, TITLE_ITEMS).join(" ") + (items.length > TITLE_ITEMS ? "…" : "");
|
|
4105
|
+
const outside = best.outside.length ? `, ${best.outside.join(" ")} outside` : "";
|
|
4106
|
+
const fields = new Map([...block.fields].filter(([k]) => k !== key));
|
|
4107
|
+
fields.set("scale", best.name);
|
|
4108
|
+
const blues = chords !== undefined ? bluesTonic(items) : null;
|
|
4109
|
+
const title = blues && best.type === "minor blues" ? `${best.tonic} blues scale for ${listed} (or ${best.tonic} minor pentatonic, ${best.tonic} mixolydian)` : `${best.name} for ${listed}${outside}`;
|
|
4110
|
+
if (!fields.get("title"))
|
|
4111
|
+
fields.set("title", title);
|
|
4112
|
+
return { head: null, fields };
|
|
4113
|
+
}
|
|
4114
|
+
function resolveScalesFor(source) {
|
|
4115
|
+
let block;
|
|
4116
|
+
try {
|
|
4117
|
+
block = parseBlockSource(source);
|
|
4118
|
+
} catch {
|
|
4119
|
+
return source;
|
|
4120
|
+
}
|
|
4121
|
+
const { fields } = block;
|
|
4122
|
+
if (!fields.has("scales-for") && !fields.has("scales-for-notes"))
|
|
4123
|
+
return source;
|
|
4124
|
+
if (!fields.has("positions") && !fields.has("modes"))
|
|
4125
|
+
return source;
|
|
4126
|
+
const resolved = scalesForBlock(block);
|
|
4127
|
+
return [...resolved.fields].map(([key, value]) => `${key}: ${value}`).join(`
|
|
4128
|
+
`);
|
|
4047
4129
|
}
|
|
4130
|
+
var withScalesFor = (render) => (doc, block, options) => render(doc, scalesForBlock(block), options);
|
|
4048
4131
|
|
|
4049
4132
|
// src/chord/transitions.ts
|
|
4050
4133
|
var FINGER_NAMES = {
|
|
@@ -5754,7 +5837,7 @@ function parseStrum(source) {
|
|
|
5754
5837
|
throw countError(segment.units, beatsPerBar, beatUnit, subdivision);
|
|
5755
5838
|
if ("spill" in here)
|
|
5756
5839
|
throw spillError(segment.units, here.spill, beatsPerBar, beatUnit, subdivision);
|
|
5757
|
-
placed.push({ ...here, line: segment.line });
|
|
5840
|
+
placed.push({ ...here, line: segment.line, start: total });
|
|
5758
5841
|
total = here.end;
|
|
5759
5842
|
if (total > perBar * MAX_STRUM_BARS)
|
|
5760
5843
|
break;
|
|
@@ -5789,7 +5872,20 @@ function parseStrum(source) {
|
|
|
5789
5872
|
slots[slot].chord = name;
|
|
5790
5873
|
}
|
|
5791
5874
|
}
|
|
5875
|
+
let note = null;
|
|
5876
|
+
for (const p of placed) {
|
|
5877
|
+
if (!p.gaps.some(Boolean) || !p.slots.length)
|
|
5878
|
+
continue;
|
|
5879
|
+
const last = Math.max(...p.slots);
|
|
5880
|
+
const empty = Math.floor((p.end - last - 1) / slotsPerBeat);
|
|
5881
|
+
if (empty < 1)
|
|
5882
|
+
continue;
|
|
5883
|
+
const read = slots.slice(p.start, last + 1).map((s) => symbolOf(s)).join(" ");
|
|
5884
|
+
note = `Read as ${read}, then ${empty} beat${empty === 1 ? "" : "s"} with no strum: write a symbol for every slot (- for no strum) to place the strums yourself.`;
|
|
5885
|
+
break;
|
|
5886
|
+
}
|
|
5792
5887
|
return {
|
|
5888
|
+
note,
|
|
5793
5889
|
slots,
|
|
5794
5890
|
beatsPerBar,
|
|
5795
5891
|
beatUnit,
|
|
@@ -6703,10 +6799,15 @@ function renderStrumBlock(doc, source, options) {
|
|
|
6703
6799
|
if (tuning && tuning.length > 12)
|
|
6704
6800
|
throw new Error("At most 12 strings");
|
|
6705
6801
|
const bpm = countedTempoOf(typeof options.play === "object" ? options.play.bpm : undefined, pattern.compound, pattern.beatUnit);
|
|
6706
|
-
|
|
6802
|
+
const drawn = renderStrum(doc, pattern, {
|
|
6707
6803
|
voicing: (chord) => strumVoicing(chord, tuning, options.voicings),
|
|
6708
6804
|
...bpm !== undefined && Number.isFinite(bpm) ? { bpm } : {}
|
|
6709
6805
|
});
|
|
6806
|
+
if (!pattern.note)
|
|
6807
|
+
return drawn;
|
|
6808
|
+
const wrap = html(doc, "div", "mn-strum-block");
|
|
6809
|
+
wrap.append(drawn, html(doc, "p", "mn-strum-note", pattern.note));
|
|
6810
|
+
return wrap;
|
|
6710
6811
|
}
|
|
6711
6812
|
|
|
6712
6813
|
// src/blocks/renderers.ts
|
|
@@ -6975,7 +7076,8 @@ var renderChord = (doc, block, options) => {
|
|
|
6975
7076
|
...capo ? { capo, fretsFrom: fromNut ? "nut" : "capo" } : {},
|
|
6976
7077
|
...capo && sounds ? { sounds } : {},
|
|
6977
7078
|
orientation: orientationOf(block, options.orientation?.chord),
|
|
6978
|
-
hand: handOf(block, options)
|
|
7079
|
+
hand: handOf(block, options),
|
|
7080
|
+
...voicing.fingers.some((f) => f) ? {} : { barreFingers: fingerVoicing(voicing.frets) }
|
|
6979
7081
|
}), symbol);
|
|
6980
7082
|
if (capo && sounding && sounding !== symbol)
|
|
6981
7083
|
diagram.setAttribute("data-mn-sounds", sounding);
|
|
@@ -7180,7 +7282,7 @@ var renderFretboardBlock = (doc, block, options) => {
|
|
|
7180
7282
|
const stringsText = field2(block, "strings");
|
|
7181
7283
|
const count = (tuning ?? STANDARD_TUNING).length;
|
|
7182
7284
|
const strings = stringsText ? parseStrings(stringsText, count).map((n) => count - n) : undefined;
|
|
7183
|
-
const shapeTitle =
|
|
7285
|
+
const shapeTitle = at ? positionTitle(set, at, arpeggio, field2(block, "numbering")) : undefined;
|
|
7184
7286
|
return renderFretboard(doc, set, {
|
|
7185
7287
|
title: field2(block, "title") ?? shapeTitle,
|
|
7186
7288
|
...strings ? { strings } : {},
|
|
@@ -7194,6 +7296,15 @@ var renderFretboardBlock = (doc, block, options) => {
|
|
|
7194
7296
|
hand: handOf(block, options)
|
|
7195
7297
|
});
|
|
7196
7298
|
};
|
|
7299
|
+
function positionTitle(set, at, arpeggio, numbering) {
|
|
7300
|
+
const name = arpeggio ? `${set.title} arpeggio` : set.title;
|
|
7301
|
+
const from = numberingOf(numbering, set, at.system) === "minor" ? ` (from ${relativeMinorOf(set)}m)` : "";
|
|
7302
|
+
if (at.system === "caged")
|
|
7303
|
+
return `${name}, ${CAGED_SHAPES[at.n - 1]} shape`;
|
|
7304
|
+
if (at.system === "3nps")
|
|
7305
|
+
return `${name}, 3nps ${at.n}${from}`;
|
|
7306
|
+
return `${name}, box ${at.n}${from}`;
|
|
7307
|
+
}
|
|
7197
7308
|
var DIAGRAMS2 = {
|
|
7198
7309
|
chord: renderChord,
|
|
7199
7310
|
keyboard: withScalesFor(renderKeyboardBlock),
|
|
@@ -7473,7 +7584,9 @@ function spelledNote(name, midi) {
|
|
|
7473
7584
|
return `${name}${o}`;
|
|
7474
7585
|
return `${nameOf(midi)}${octave}`;
|
|
7475
7586
|
}
|
|
7476
|
-
function redrawFor(doc, diagram, data) {
|
|
7587
|
+
function redrawFor(doc, diagram, data, pageHand = "right") {
|
|
7588
|
+
const own = diagram.getAttribute("data-mn-hand");
|
|
7589
|
+
const hand = own === "left" || own === "right" ? own : pageHand;
|
|
7477
7590
|
const toGuitar = data.sound === "piano";
|
|
7478
7591
|
const pitches = [...new Set(data.pitches)].sort((a, b) => a - b).filter((midi) => !toGuitar || midi >= 40 && midi <= 88);
|
|
7479
7592
|
if (!pitches.length)
|
|
@@ -7519,6 +7632,7 @@ function redrawFor(doc, diagram, data) {
|
|
|
7519
7632
|
return label === "notes" || member.interval === null ? chartNoteName(member.name) : intervalLabel(member.interval);
|
|
7520
7633
|
}) : label === "none" ? grip.frets.map(() => null) : null;
|
|
7521
7634
|
const drawn = renderGuitarDiagram(doc, grip, {
|
|
7635
|
+
hand,
|
|
7522
7636
|
...title ? { title } : {},
|
|
7523
7637
|
root: chordSet.root,
|
|
7524
7638
|
...labels ? { labels } : {}
|
|
@@ -7533,6 +7647,7 @@ function redrawFor(doc, diagram, data) {
|
|
|
7533
7647
|
const orientation = diagram.getAttribute("data-mn-orientation") === "vertical" ? "vertical" : undefined;
|
|
7534
7648
|
const drawn = toGuitar ? renderFretboard(doc, set, {
|
|
7535
7649
|
label,
|
|
7650
|
+
hand,
|
|
7536
7651
|
...title ? { title } : {},
|
|
7537
7652
|
...orientation ? { orientation } : {},
|
|
7538
7653
|
frets: [0, Math.max(12, Math.min(24, pitches[pitches.length - 1] - 64))]
|
|
@@ -7714,7 +7829,7 @@ function barFor(doc, win, diagram, data, options) {
|
|
|
7714
7829
|
if (!redraws)
|
|
7715
7830
|
return;
|
|
7716
7831
|
if (settings.sound !== data.sound)
|
|
7717
|
-
other ??= redrawFor(doc, diagram, data);
|
|
7832
|
+
other ??= redrawFor(doc, diagram, data, options.hand);
|
|
7718
7833
|
const next = settings.sound === data.sound ? diagram : other ?? diagram;
|
|
7719
7834
|
if (next !== shown && shown.parentNode === wrap) {
|
|
7720
7835
|
wrap.replaceChild(next, shown);
|
|
@@ -7988,7 +8103,10 @@ function renderBlock(language, source, host, given = {}) {
|
|
|
7988
8103
|
return failed(el, host, language, messageOf(e));
|
|
7989
8104
|
}
|
|
7990
8105
|
host.appendChild(el);
|
|
7991
|
-
const stopPlayback = options.play ? attachPlayback(el,
|
|
8106
|
+
const stopPlayback = options.play ? attachPlayback(el, {
|
|
8107
|
+
hand: options.hand,
|
|
8108
|
+
...typeof options.play === "object" ? options.play : {}
|
|
8109
|
+
}) : null;
|
|
7992
8110
|
return {
|
|
7993
8111
|
ok: error === null,
|
|
7994
8112
|
el,
|
|
@@ -8267,7 +8385,7 @@ function voicingParts(language, source) {
|
|
|
8267
8385
|
throw new Error(`On ${count} strings, use one of ${wide.join(", ")} at a time`);
|
|
8268
8386
|
}
|
|
8269
8387
|
}
|
|
8270
|
-
const voicings = cachedVoicings(chord.symbol, options)
|
|
8388
|
+
const voicings = distinctShapes(cachedVoicings(chord.symbol, options), wanted);
|
|
8271
8389
|
if (!voicings.length)
|
|
8272
8390
|
throw new Error(noVoicing(written, chord.symbol, options));
|
|
8273
8391
|
const shared = SHARED_KEYS.chord;
|
|
@@ -8751,5 +8869,5 @@ export {
|
|
|
8751
8869
|
renderAll
|
|
8752
8870
|
};
|
|
8753
8871
|
|
|
8754
|
-
//# debugId=
|
|
8872
|
+
//# debugId=5A5F5CC236DAC1A064756E2164756E21
|
|
8755
8873
|
//# sourceMappingURL=index.js.map
|