@dsebastien/music-notation 0.5.3 → 0.6.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 +12 -2
- package/dist/THIRD_PARTY_LICENSES.md +256 -0
- package/dist/blocks/note-set-field.d.ts +4 -1
- package/dist/cli.js +70 -0
- package/dist/fretboard/positions.d.ts +34 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +195 -37
- package/dist/index.js.map +10 -10
- package/dist/music-notation.publish.min.js +17 -17
- package/dist/music-notation.tab.min.js +1 -1
- package/dist/publish/index.js +193 -37
- package/dist/publish/index.js.map +10 -10
- package/dist/tab/index.js +36 -4
- package/dist/tab/index.js.map +3 -3
- package/dist/theory/note-set.d.ts +19 -5
- package/dist/voicings/index.js +45 -6
- package/dist/voicings/index.js.map +4 -4
- package/package.json +5 -1
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
* come the D, C, A and G shapes.
|
|
9
9
|
* - 3NPS: 3 notes per string, starting from the n-th scale degree.
|
|
10
10
|
* Scales with no pentatonic inside (locrian, harmonic minor…) use 3NPS for their CAGED positions.
|
|
11
|
+
* Major pentatonic positions can be numbered from the relative minor (`numbering: minor`), as many
|
|
12
|
+
* courses do: position 1 is then the relative minor's box 1.
|
|
11
13
|
*/
|
|
12
14
|
import type { NoteSet } from '../theory/note-set.js';
|
|
13
15
|
export type PositionSystem = 'box' | 'caged' | '3nps';
|
|
@@ -19,8 +21,38 @@ export interface Cell {
|
|
|
19
21
|
export declare const CAGED_SHAPES: readonly ["E", "D", "C", "A", "G"];
|
|
20
22
|
/** How many positions a scale has in a system. */
|
|
21
23
|
export declare function positionCount(set: NoteSet, system: PositionSystem): number;
|
|
22
|
-
/** The
|
|
23
|
-
export declare
|
|
24
|
+
/** The highest fret a fretboard can show. */
|
|
25
|
+
export declare const MAX_FRET = 36;
|
|
26
|
+
/** How positions are numbered: from the scale's root (default), or from the relative minor. */
|
|
27
|
+
export type Numbering = 'root' | 'minor';
|
|
28
|
+
/**
|
|
29
|
+
* Where to draw a position and how it's numbered: `within` picks the lowest octave inside those
|
|
30
|
+
* frets (else the lowest); `numbering: 'minor'` counts a major pentatonic's positions from its
|
|
31
|
+
* relative minor.
|
|
32
|
+
*/
|
|
33
|
+
export interface PositionOptions {
|
|
34
|
+
within?: [number, number];
|
|
35
|
+
numbering?: Numbering;
|
|
36
|
+
}
|
|
37
|
+
/** The relative minor's root, as the scale spells it (its 5th note: the 6th degree). */
|
|
38
|
+
export declare const relativeMinorOf: (set: NoteSet) => string | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Reads `numbering:` for a scale's positions. `minor` (or `relative minor`) only applies to major
|
|
41
|
+
* pentatonic boxes and 3NPS positions; anywhere else it's an error that says where it applies.
|
|
42
|
+
*/
|
|
43
|
+
export declare function numberingOf(text: string | undefined, set: NoteSet, system: PositionSystem): Numbering;
|
|
44
|
+
/**
|
|
45
|
+
* The notes of position `n` (1-based), in the lowest octave where every note is on the neck (or
|
|
46
|
+
* the lowest one inside `within`); null when the scale or position doesn't fit the system.
|
|
47
|
+
*/
|
|
48
|
+
export declare function scalePosition(set: NoteSet, tuning: number[], system: PositionSystem, n: number, options?: PositionOptions): Cell[] | null;
|
|
49
|
+
/**
|
|
50
|
+
* Every position in neck order, position 1 first: the first in its lowest octave, each next one in
|
|
51
|
+
* the lowest octave at or above the previous one (by their lowest frets), or in its own lowest
|
|
52
|
+
* octave when that would go past fret 36. Null for a position that doesn't fit the system.
|
|
53
|
+
* With `numbering: 'minor'`, a major pentatonic starts from its relative minor's box 1.
|
|
54
|
+
*/
|
|
55
|
+
export declare function neckPositions(set: NoteSet, tuning: number[], system: PositionSystem, numbering?: Numbering): (Cell[] | null)[];
|
|
24
56
|
/** Parses `position:` and `shape:` for a scale: the system and the position number. */
|
|
25
57
|
export declare function positionOf(positionText: string | undefined, shapeText: string | undefined): {
|
|
26
58
|
system: PositionSystem;
|
package/dist/index.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export type { VoicingLookup } from './voicings/index.js';
|
|
|
21
21
|
export { parseChordName, readChord, suggestChords } from './theory/chord-name.js';
|
|
22
22
|
export { detectChordFromFrets, detectChordFromPitches, type DetectedChord } from './theory/detect.js';
|
|
23
23
|
export { scaleName, modesOf, scaleTypes, characteristicIntervals, isScaleWithoutRoot } from './theory/scales.js';
|
|
24
|
-
export { scalePosition, positionCount, CAGED_SHAPES, type Cell, type PositionSystem } from './fretboard/positions.js';
|
|
24
|
+
export { scalePosition, neckPositions, positionCount, CAGED_SHAPES, MAX_FRET, type Cell, type Numbering, type PositionOptions, type PositionSystem } from './fretboard/positions.js';
|
|
25
25
|
export { blockFromProperties, instrumentOf, DEFAULT_PROPERTY_NAMES, type PropertyNames, type Instrument } from './blocks/properties.js';
|
|
26
26
|
export { textTabToAlphaTex } from './convert/text-tab.js';
|
|
27
27
|
export { chordSheetToChordPro } from './convert/chord-sheet.js';
|
package/dist/index.js
CHANGED
|
@@ -214,13 +214,20 @@ function renderGuitarDiagram(doc, voicing, options = {}) {
|
|
|
214
214
|
const tuning = options.tuning ?? (strings === 6 ? STANDARD_TUNING : undefined);
|
|
215
215
|
voicing.frets.forEach((fret, s) => {
|
|
216
216
|
const mark = frame.at(across(s), -8);
|
|
217
|
+
const string = strings - s;
|
|
217
218
|
if (fret === null) {
|
|
218
|
-
|
|
219
|
+
const muted = svgLabel(doc, "×", mark, "mn-muted");
|
|
220
|
+
muted.setAttribute("data-mn-string", String(string));
|
|
221
|
+
root.appendChild(muted);
|
|
219
222
|
return;
|
|
220
223
|
}
|
|
221
224
|
const open = tuning?.[s];
|
|
222
225
|
const isRoot = options.root !== undefined && options.root !== null && open !== undefined && (open + fret) % 12 === options.root;
|
|
223
|
-
const midi =
|
|
226
|
+
const midi = {
|
|
227
|
+
"data-mn-string": string,
|
|
228
|
+
"data-mn-fret": fret,
|
|
229
|
+
...open !== undefined ? { "data-midi": open + fret } : {}
|
|
230
|
+
};
|
|
224
231
|
if (fret === 0) {
|
|
225
232
|
const [cx, cy] = mark;
|
|
226
233
|
root.appendChild(svg(doc, "circle", {
|
|
@@ -522,7 +529,7 @@ function renderChart(doc, song, options = {}) {
|
|
|
522
529
|
}
|
|
523
530
|
|
|
524
531
|
// src/theory/note-set.ts
|
|
525
|
-
import { Chord, Scale as Scale2 } from "tonal";
|
|
532
|
+
import { Chord, Interval, Scale as Scale2 } from "tonal";
|
|
526
533
|
|
|
527
534
|
// src/theory/suffix.ts
|
|
528
535
|
var CANONICAL = new Map([
|
|
@@ -738,7 +745,26 @@ function scaleNoteSet(name) {
|
|
|
738
745
|
set.scaleType = scale.type;
|
|
739
746
|
return set;
|
|
740
747
|
}
|
|
741
|
-
function
|
|
748
|
+
function rootNameOf(text) {
|
|
749
|
+
const name = text.trim().replace(/-?\d$/, "").replace(/♯/g, "#").replace(/♭/g, "b");
|
|
750
|
+
if (chromaOf(name) === null)
|
|
751
|
+
return null;
|
|
752
|
+
return name[0].toUpperCase() + name.slice(1);
|
|
753
|
+
}
|
|
754
|
+
var PLAIN_INTERVALS = ["1P", "2m", "2M", "3m", "3M", "4P", "5d", "5P", "6m", "6M", "7m", "7M"];
|
|
755
|
+
function intervalFrom(root, name) {
|
|
756
|
+
const from = rootNameOf(root);
|
|
757
|
+
const to = rootNameOf(name);
|
|
758
|
+
if (from === null || to === null)
|
|
759
|
+
return null;
|
|
760
|
+
const semitones = (chromaOf(to) - chromaOf(from) + 12) % 12;
|
|
761
|
+
if (semitones === 0)
|
|
762
|
+
return "1P";
|
|
763
|
+
const spelled = Interval.distance(from, to);
|
|
764
|
+
const m = /^(\d+)([PMmdA]+)$/.exec(spelled);
|
|
765
|
+
return m && m[1] !== "1" && m[1] !== "8" ? spelled : PLAIN_INTERVALS[semitones];
|
|
766
|
+
}
|
|
767
|
+
function listNoteSet(text, root) {
|
|
742
768
|
const tokens = text.split(/[\s,]+/).filter(Boolean);
|
|
743
769
|
if (!tokens.length)
|
|
744
770
|
return null;
|
|
@@ -747,8 +773,21 @@ function listNoteSet(text) {
|
|
|
747
773
|
if (!withOctaves && names.some((n) => chromaOf(n) === null))
|
|
748
774
|
return null;
|
|
749
775
|
const set = fromNames(tokens.join(" "), names, null);
|
|
750
|
-
if (set
|
|
776
|
+
if (!set)
|
|
777
|
+
return null;
|
|
778
|
+
set.list = true;
|
|
779
|
+
if (withOctaves)
|
|
751
780
|
set.pitches = tokens.map((t) => midiOf(t));
|
|
781
|
+
if (root === undefined)
|
|
782
|
+
return set;
|
|
783
|
+
const rootName = rootNameOf(root);
|
|
784
|
+
if (rootName === null)
|
|
785
|
+
return null;
|
|
786
|
+
set.root = chromaOf(rootName);
|
|
787
|
+
for (const member of set.members) {
|
|
788
|
+
member.interval = intervalFrom(rootName, member.name);
|
|
789
|
+
member.degree = Number(/^\d+/.exec(member.interval ?? "")?.[0] ?? 1);
|
|
790
|
+
}
|
|
752
791
|
return set;
|
|
753
792
|
}
|
|
754
793
|
|
|
@@ -827,12 +866,30 @@ function renderFretboard(doc, set, options = {}) {
|
|
|
827
866
|
const hidden = options.strings !== undefined && !options.strings.includes(s);
|
|
828
867
|
if (!member || hidden || played && !played.has(`${s}:${fret}`)) {
|
|
829
868
|
if (!member && !hidden && options.marks?.ghosts?.has(chroma)) {
|
|
830
|
-
root.appendChild(svg(doc, "circle", {
|
|
869
|
+
root.appendChild(svg(doc, "circle", {
|
|
870
|
+
class: "mn-ghost",
|
|
871
|
+
cx,
|
|
872
|
+
cy,
|
|
873
|
+
r: 7,
|
|
874
|
+
"data-mn-ghost-string": strings - s,
|
|
875
|
+
"data-mn-fret": fret,
|
|
876
|
+
"data-mn-note": options.marks?.ghostNames?.get(chroma) ?? nameOf(chroma, set.preferFlats),
|
|
877
|
+
"data-mn-pitch": open + fret
|
|
878
|
+
}));
|
|
831
879
|
}
|
|
832
880
|
continue;
|
|
833
881
|
}
|
|
834
882
|
const cls = `mn-dot${markClasses(set, member.chroma, options.marks)}`;
|
|
835
|
-
root.appendChild(svg(doc, "circle", {
|
|
883
|
+
root.appendChild(svg(doc, "circle", {
|
|
884
|
+
class: cls,
|
|
885
|
+
cx,
|
|
886
|
+
cy,
|
|
887
|
+
r: 8,
|
|
888
|
+
"data-midi": open + fret,
|
|
889
|
+
"data-mn-string": strings - s,
|
|
890
|
+
"data-mn-fret": fret,
|
|
891
|
+
"data-mn-note": member.name
|
|
892
|
+
}));
|
|
836
893
|
sounding.add(open + fret);
|
|
837
894
|
const text = labelOf(member, label);
|
|
838
895
|
if (text)
|
|
@@ -842,7 +899,9 @@ function renderFretboard(doc, set, options = {}) {
|
|
|
842
899
|
root.setAttribute("data-mn-pitches", [...sounding].sort((a, b) => a - b).join(" "));
|
|
843
900
|
root.setAttribute("data-mn-play", "scale");
|
|
844
901
|
root.setAttribute("data-mn-sound", "guitar");
|
|
845
|
-
|
|
902
|
+
root.setAttribute("data-mn-set", set.title);
|
|
903
|
+
root.setAttribute("data-mn-frets", `${from}-${to}`);
|
|
904
|
+
if (set.root !== null && !set.list)
|
|
846
905
|
root.setAttribute("data-mn-root", String(set.root));
|
|
847
906
|
return root;
|
|
848
907
|
}
|
|
@@ -976,7 +1035,8 @@ function renderKeyboard(doc, set, options = {}) {
|
|
|
976
1035
|
class: keyClass(midi, false),
|
|
977
1036
|
...key(along, WHITE_W, WHITE_H),
|
|
978
1037
|
rx: 2,
|
|
979
|
-
"data-midi": midi
|
|
1038
|
+
"data-midi": midi,
|
|
1039
|
+
"data-mn-note": memberOf(set, midi)?.name ?? (options.marks?.ghosts?.has((midi % 12 + 12) % 12) ? options.marks?.ghostNames?.get((midi % 12 + 12) % 12) ?? nameOf(midi, set.preferFlats) : undefined)
|
|
980
1040
|
}));
|
|
981
1041
|
caption(midi, at(along + WHITE_W / 2, WHITE_H - 13), false);
|
|
982
1042
|
});
|
|
@@ -989,7 +1049,8 @@ function renderKeyboard(doc, set, options = {}) {
|
|
|
989
1049
|
class: keyClass(black, true),
|
|
990
1050
|
...key(along, BLACK_W, BLACK_H),
|
|
991
1051
|
rx: 2,
|
|
992
|
-
"data-midi": black
|
|
1052
|
+
"data-midi": black,
|
|
1053
|
+
"data-mn-note": memberOf(set, black)?.name ?? (options.marks?.ghosts?.has((black % 12 + 12) % 12) ? options.marks?.ghostNames?.get((black % 12 + 12) % 12) ?? nameOf(black, set.preferFlats) : undefined)
|
|
993
1054
|
}));
|
|
994
1055
|
caption(black, at(along + BLACK_W / 2, BLACK_H - 13), true);
|
|
995
1056
|
});
|
|
@@ -999,7 +1060,9 @@ function renderKeyboard(doc, set, options = {}) {
|
|
|
999
1060
|
continue;
|
|
1000
1061
|
const whitesBelow = whites.filter((w) => w < midi).length;
|
|
1001
1062
|
const along = isBlack(midi) ? whitesBelow * WHITE_W : whitesBelow * WHITE_W + WHITE_W / 2;
|
|
1002
|
-
|
|
1063
|
+
const label = svgLabel(doc, finger, at(along, WHITE_H + FINGER_ROW / 2 - 1), "mn-key-finger");
|
|
1064
|
+
label.setAttribute("data-mn-key", String(midi));
|
|
1065
|
+
root.appendChild(label);
|
|
1003
1066
|
}
|
|
1004
1067
|
}
|
|
1005
1068
|
const played = [];
|
|
@@ -1009,7 +1072,8 @@ function renderKeyboard(doc, set, options = {}) {
|
|
|
1009
1072
|
root.setAttribute("data-mn-pitches", played.join(" "));
|
|
1010
1073
|
root.setAttribute("data-mn-play", options.playAs ?? "scale");
|
|
1011
1074
|
root.setAttribute("data-mn-sound", "piano");
|
|
1012
|
-
|
|
1075
|
+
root.setAttribute("data-mn-set", set.title);
|
|
1076
|
+
if (set.root !== null && !set.list)
|
|
1013
1077
|
root.setAttribute("data-mn-root", String(set.root));
|
|
1014
1078
|
return root;
|
|
1015
1079
|
}
|
|
@@ -1366,6 +1430,29 @@ function noteSetOf(block) {
|
|
|
1366
1430
|
const scale = block.fields.get("scale");
|
|
1367
1431
|
const chord = block.fields.get("chord");
|
|
1368
1432
|
const notes = block.fields.get("notes");
|
|
1433
|
+
const root = block.fields.get("root")?.trim() || undefined;
|
|
1434
|
+
if (root !== undefined) {
|
|
1435
|
+
if (scale !== undefined)
|
|
1436
|
+
throw rootNotForList("a scale");
|
|
1437
|
+
if (chord !== undefined)
|
|
1438
|
+
throw rootNotForList("a chord");
|
|
1439
|
+
if (rootNameOf(root) === null) {
|
|
1440
|
+
throw new Error(`Invalid root "${root}": use a note name, e.g. root: C`);
|
|
1441
|
+
}
|
|
1442
|
+
if (notes !== undefined)
|
|
1443
|
+
return orFail(listNoteSet(notes, root), `Invalid notes "${notes}"`);
|
|
1444
|
+
if (block.head) {
|
|
1445
|
+
const list = listNoteSet(block.head, root);
|
|
1446
|
+
if (list)
|
|
1447
|
+
return list;
|
|
1448
|
+
if (scaleNoteSet(block.head))
|
|
1449
|
+
throw rootNotForList("a scale");
|
|
1450
|
+
if (chordNoteSet(block.head))
|
|
1451
|
+
throw rootNotForList("a chord");
|
|
1452
|
+
throw new Error(`"${block.head}" is not a list of notes: use e.g. notes: C Eb G`);
|
|
1453
|
+
}
|
|
1454
|
+
throw new Error("Add the notes for the root: e.g. notes: C Eb G");
|
|
1455
|
+
}
|
|
1369
1456
|
if (scale !== undefined) {
|
|
1370
1457
|
if (isScaleWithoutRoot(scale))
|
|
1371
1458
|
throw new Error(`Add a root note: C ${scale.trim()}`);
|
|
@@ -1385,6 +1472,7 @@ function noteSetOf(block) {
|
|
|
1385
1472
|
}
|
|
1386
1473
|
throw new Error('Add "scale:", "chord:" or "notes:"');
|
|
1387
1474
|
}
|
|
1475
|
+
var rootNotForList = (what) => new Error(`root only applies to lists of notes (notes: C E G): ${what} has its own root`);
|
|
1388
1476
|
function labelField(block, fallback, fingers = false) {
|
|
1389
1477
|
const value = block.fields.get("labels")?.toLowerCase();
|
|
1390
1478
|
if (value === undefined)
|
|
@@ -1412,7 +1500,7 @@ function marksOf(block, set) {
|
|
|
1412
1500
|
}
|
|
1413
1501
|
} else if (highlight.toLowerCase() !== "none" && highlight !== "") {
|
|
1414
1502
|
if (set.members.every((m) => m.interval === null)) {
|
|
1415
|
-
throw new Error("highlight needs a scale or a
|
|
1503
|
+
throw new Error("highlight needs a scale, a chord or a root: a list of notes has no intervals (add e.g. root: C)");
|
|
1416
1504
|
}
|
|
1417
1505
|
const labels = highlight.replace(/♭/g, "b").replace(/♯/g, "#").split(/[\s,]+/).filter(Boolean);
|
|
1418
1506
|
for (const label of labels) {
|
|
@@ -1428,12 +1516,13 @@ function marksOf(block, set) {
|
|
|
1428
1516
|
const compare = block.fields.get("compare")?.trim();
|
|
1429
1517
|
if (compare) {
|
|
1430
1518
|
const tonic = Scale3.get(scaleName(compare)).tonic;
|
|
1431
|
-
const root = set.members[0]?.name ?? "";
|
|
1519
|
+
const root = rootNameOf(block.fields.get("root") ?? "") ?? set.members[0]?.name ?? "";
|
|
1432
1520
|
const parent = orFail(scaleNoteSet(tonic ? compare : `${root} ${compare}`), `Unknown scale "${compare}" to compare with: use e.g. compare: major`);
|
|
1433
1521
|
const own = new Set(set.members.map((m) => m.chroma));
|
|
1434
1522
|
const theirs = new Set(parent.members.map((m) => m.chroma));
|
|
1435
1523
|
marks.different = new Set([...own].filter((c) => !theirs.has(c)));
|
|
1436
1524
|
marks.ghosts = new Set([...theirs].filter((c) => !own.has(c)));
|
|
1525
|
+
marks.ghostNames = new Map(parent.members.filter((m) => !own.has(m.chroma)).map((m) => [m.chroma, m.name]));
|
|
1437
1526
|
}
|
|
1438
1527
|
return marks;
|
|
1439
1528
|
}
|
|
@@ -1481,23 +1570,61 @@ function pentatonicOf(set) {
|
|
|
1481
1570
|
}
|
|
1482
1571
|
return null;
|
|
1483
1572
|
}
|
|
1484
|
-
|
|
1573
|
+
var MAX_FRET = 36;
|
|
1574
|
+
var isMajorPentatonic = (set) => set.members.map((m) => m.interval).join(" ") === MAJOR_PENTATONIC.join(" ");
|
|
1575
|
+
var relativeMinorOf = (set) => isMajorPentatonic(set) ? set.members[4].name : undefined;
|
|
1576
|
+
function numberingOf(text, set, system) {
|
|
1577
|
+
const value = text?.trim().toLowerCase().replace(/\s+/g, " ");
|
|
1578
|
+
if (!value)
|
|
1579
|
+
return "root";
|
|
1580
|
+
if (value !== "minor" && value !== "relative minor") {
|
|
1581
|
+
throw new Error(`numbering: use minor (positions from the relative minor), got "${text}"`);
|
|
1582
|
+
}
|
|
1583
|
+
if (!isMajorPentatonic(set)) {
|
|
1584
|
+
throw new Error(`numbering: minor is for major pentatonic positions (e.g. A major pentatonic), not ${set.title}`);
|
|
1585
|
+
}
|
|
1586
|
+
if (system === "caged") {
|
|
1587
|
+
throw new Error("numbering: minor numbers boxes and 3nps positions, not CAGED shapes");
|
|
1588
|
+
}
|
|
1589
|
+
return "minor";
|
|
1590
|
+
}
|
|
1591
|
+
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;
|
|
1592
|
+
var lowestFret = (cells) => Math.min(...cells.map((c) => c.fret));
|
|
1593
|
+
var highestFret = (cells) => Math.max(...cells.map((c) => c.fret));
|
|
1594
|
+
function scalePosition(set, tuning, system, n, options = {}) {
|
|
1595
|
+
const octaves = octavesOf(set, tuning, system, fromRoot(set, system, n, options.numbering));
|
|
1596
|
+
const within = options.within;
|
|
1597
|
+
const inside = within ? octaves.find((cells) => lowestFret(cells) >= within[0] && highestFret(cells) <= within[1]) : undefined;
|
|
1598
|
+
return inside ?? octaves[0] ?? null;
|
|
1599
|
+
}
|
|
1600
|
+
function neckPositions(set, tuning, system, numbering = "root") {
|
|
1601
|
+
let floor = 0;
|
|
1602
|
+
return Array.from({ length: positionCount(set, system) }, (_, i) => {
|
|
1603
|
+
const octaves = octavesOf(set, tuning, system, fromRoot(set, system, i + 1, numbering));
|
|
1604
|
+
const cells = octaves.find((c) => lowestFret(c) >= floor && highestFret(c) <= MAX_FRET) ?? octaves[0] ?? null;
|
|
1605
|
+
if (cells)
|
|
1606
|
+
floor = lowestFret(cells);
|
|
1607
|
+
return cells;
|
|
1608
|
+
});
|
|
1609
|
+
}
|
|
1610
|
+
function octavesOf(set, tuning, system, n) {
|
|
1485
1611
|
if (set.root === null || n < 1 || n > positionCount(set, system))
|
|
1486
|
-
return
|
|
1612
|
+
return [];
|
|
1487
1613
|
const open = tuning[0];
|
|
1488
1614
|
const chromas = chromasOf(set);
|
|
1489
1615
|
const notes = tuning.length * 3;
|
|
1490
1616
|
const nps = system === "3nps" || system === "caged" && chromas.length !== 5 && !pentatonicOf(set);
|
|
1491
1617
|
const pentatonic = chromas.length === 5 ? chromas : pentatonicOf(set);
|
|
1492
1618
|
if (!nps && !pentatonic)
|
|
1493
|
-
return
|
|
1619
|
+
return [];
|
|
1494
1620
|
const startChroma = nps ? chromas[(n - 1) % chromas.length] : pentatonic[(n - 1) % 5];
|
|
1495
|
-
|
|
1621
|
+
const out = [];
|
|
1622
|
+
for (let start = fretOn(open, startChroma, 0);start <= MAX_FRET; start += 12) {
|
|
1496
1623
|
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);
|
|
1497
1624
|
if (cells && cells.every((c) => c.fret >= 0))
|
|
1498
|
-
|
|
1625
|
+
out.push(cells);
|
|
1499
1626
|
}
|
|
1500
|
-
return
|
|
1627
|
+
return out;
|
|
1501
1628
|
}
|
|
1502
1629
|
function withOther(box, chromas, tuning) {
|
|
1503
1630
|
if (box.length < tuning.length * 2)
|
|
@@ -1555,6 +1682,7 @@ var SHARED_KEYS = {
|
|
|
1555
1682
|
"compare",
|
|
1556
1683
|
"position",
|
|
1557
1684
|
"shape",
|
|
1685
|
+
"numbering",
|
|
1558
1686
|
"strings"
|
|
1559
1687
|
]
|
|
1560
1688
|
};
|
|
@@ -1681,14 +1809,14 @@ var renderChord = (doc, block, options) => {
|
|
|
1681
1809
|
const fingers = fingering ? fingersFor(set.pitches, fingering) : new Map;
|
|
1682
1810
|
const range = field(block, "range");
|
|
1683
1811
|
handOf(block, options);
|
|
1684
|
-
return renderKeyboard(doc, set, {
|
|
1812
|
+
return named(renderKeyboard(doc, set, {
|
|
1685
1813
|
playAs: "chord",
|
|
1686
1814
|
title,
|
|
1687
1815
|
label: labelField(block, fingers.size ? "fingers" : "notes", fingers.size > 0),
|
|
1688
1816
|
fingers,
|
|
1689
1817
|
range: keyRange(range ? rangeOf(range) : keyRangeOf(set)),
|
|
1690
1818
|
orientation: orientationOf(block, options.orientation?.keyboard)
|
|
1691
|
-
});
|
|
1819
|
+
}), symbol);
|
|
1692
1820
|
}
|
|
1693
1821
|
if (instrument && instrument !== "guitar" && !field(block, "tuning")) {
|
|
1694
1822
|
throw new Error(`Unknown instrument "${instrument}": use guitar or piano, or give a tuning`);
|
|
@@ -1746,7 +1874,7 @@ var renderChord = (doc, block, options) => {
|
|
|
1746
1874
|
const anchors = marked("anchors");
|
|
1747
1875
|
const guides = marked("guides");
|
|
1748
1876
|
const marks = voicing.frets.map((_, s) => anchors.includes(s) ? "anchor" : guides.includes(s) ? "guide" : null);
|
|
1749
|
-
return renderGuitarDiagram(doc, voicing, {
|
|
1877
|
+
return named(renderGuitarDiagram(doc, voicing, {
|
|
1750
1878
|
title,
|
|
1751
1879
|
root,
|
|
1752
1880
|
tuning,
|
|
@@ -1754,8 +1882,13 @@ var renderChord = (doc, block, options) => {
|
|
|
1754
1882
|
...anchors.length || guides.length ? { marks } : {},
|
|
1755
1883
|
orientation: orientationOf(block, options.orientation?.chord),
|
|
1756
1884
|
hand: handOf(block, options)
|
|
1757
|
-
});
|
|
1885
|
+
}), symbol);
|
|
1758
1886
|
};
|
|
1887
|
+
function named(el, symbol) {
|
|
1888
|
+
if (symbol)
|
|
1889
|
+
el.setAttribute("data-mn-chord", symbol);
|
|
1890
|
+
return el;
|
|
1891
|
+
}
|
|
1759
1892
|
function dotLabels(text, symbol, voicing, tuning) {
|
|
1760
1893
|
const value = text?.toLowerCase();
|
|
1761
1894
|
if (value === undefined || value === "fingers")
|
|
@@ -1794,7 +1927,7 @@ var renderKeyboardBlock = (doc, block, options) => {
|
|
|
1794
1927
|
const fingering = field(block, "fingering");
|
|
1795
1928
|
const keys = range ? rangeOf(range) : undefined;
|
|
1796
1929
|
let fingers;
|
|
1797
|
-
if (fingering && set.root !== null && !set.pitches) {
|
|
1930
|
+
if (fingering && set.root !== null && !set.list && !set.pitches) {
|
|
1798
1931
|
let start = 60 + set.root;
|
|
1799
1932
|
if (keys) {
|
|
1800
1933
|
const first = keys[0] + ((set.root - keys[0]) % 12 + 12) % 12;
|
|
@@ -1809,7 +1942,7 @@ var renderKeyboardBlock = (doc, block, options) => {
|
|
|
1809
1942
|
set.pitches = octave;
|
|
1810
1943
|
}
|
|
1811
1944
|
return renderKeyboard(doc, set, {
|
|
1812
|
-
playAs: !set.scaleType && set.root !== null ? "chord" : "scale",
|
|
1945
|
+
playAs: !set.scaleType && !set.list && set.root !== null ? "chord" : "scale",
|
|
1813
1946
|
title: field(block, "title"),
|
|
1814
1947
|
label: labelField(block, fingers ? "fingers" : "notes", fingers !== undefined),
|
|
1815
1948
|
fingers,
|
|
@@ -1823,19 +1956,30 @@ var renderFretboardBlock = (doc, block, options) => {
|
|
|
1823
1956
|
const at = positionOf(field(block, "position"), field(block, "shape"));
|
|
1824
1957
|
const fretsText = field(block, "frets");
|
|
1825
1958
|
const frets = fretsText ? orFail(parseRange(fretsText), `Invalid frets "${fretsText}": use e.g. 5-8`) : undefined;
|
|
1826
|
-
if (frets && frets[1] >
|
|
1827
|
-
throw new Error(
|
|
1959
|
+
if (frets && frets[1] > MAX_FRET)
|
|
1960
|
+
throw new Error(`Frets go up to ${MAX_FRET}`);
|
|
1828
1961
|
const tuningText = field(block, "tuning");
|
|
1829
1962
|
const tuning = tuningText ? tuningOf(tuningText) : undefined;
|
|
1830
1963
|
let cells;
|
|
1964
|
+
if (!at && field(block, "numbering")) {
|
|
1965
|
+
throw new Error("numbering goes with a position: e.g. position: 1 or positions: all");
|
|
1966
|
+
}
|
|
1831
1967
|
if (at) {
|
|
1832
|
-
if (set.root === null)
|
|
1968
|
+
if (set.root === null || set.list) {
|
|
1833
1969
|
throw new Error("Positions need a scale: e.g. scale: A minor");
|
|
1970
|
+
}
|
|
1834
1971
|
if (at.system === "box" && set.members.length !== 5)
|
|
1835
1972
|
at.system = "caged";
|
|
1836
1973
|
const count = positionCount(set, at.system);
|
|
1837
1974
|
const named = { box: "box", caged: "CAGED", "3nps": "3nps" }[at.system];
|
|
1838
|
-
|
|
1975
|
+
const numbering = numberingOf(field(block, "numbering"), set, at.system);
|
|
1976
|
+
cells = orFail(scalePosition(set, tuning ?? STANDARD_TUNING, at.system, at.n, {
|
|
1977
|
+
within: frets,
|
|
1978
|
+
numbering
|
|
1979
|
+
}), `${set.title} has ${count} ${named} positions: use position 1 to ${count}`);
|
|
1980
|
+
if (frets && cells.some((cell) => cell.fret < frets[0] || cell.fret > frets[1])) {
|
|
1981
|
+
throw new Error(`${set.title}, position ${at.n} doesn't fit in frets ${frets[0]}-${frets[1]}: widen frets: or leave it out`);
|
|
1982
|
+
}
|
|
1839
1983
|
}
|
|
1840
1984
|
const stringsText = field(block, "strings");
|
|
1841
1985
|
const count = (tuning ?? STANDARD_TUNING).length;
|
|
@@ -2755,7 +2899,7 @@ function stringName(tuning, s) {
|
|
|
2755
2899
|
const lowest = tuning.findIndex((p) => noteOf(p).replace(/-?\d+$/, "") === name);
|
|
2756
2900
|
return `the ${s === lowest ? "low" : "high"} ${name} string`;
|
|
2757
2901
|
}
|
|
2758
|
-
var
|
|
2902
|
+
var lowestFret2 = (frets) => {
|
|
2759
2903
|
const fretted = frets.filter((f) => f !== null && f > 0);
|
|
2760
2904
|
return fretted.length ? Math.min(...fretted) : 0;
|
|
2761
2905
|
};
|
|
@@ -2783,7 +2927,7 @@ function move(from, fromFingers, to, tuning) {
|
|
|
2783
2927
|
const placed = new Set(to.frets.flatMap((f, s) => f && to.fingers[s] && !anchors.includes(s) && !guides.includes(s) ? [to.fingers[s]] : []));
|
|
2784
2928
|
const strings = new Set(to.frets.flatMap((f, s) => f && to.fingers[s] && !anchors.includes(s) && !guides.includes(s) ? [s] : []));
|
|
2785
2929
|
movement -= strings.size - placed.size;
|
|
2786
|
-
const shift = Math.abs(
|
|
2930
|
+
const shift = Math.abs(lowestFret2(to.frets) - lowestFret2(from));
|
|
2787
2931
|
movement += 0.3 * shift;
|
|
2788
2932
|
const fingerName = (f) => FINGER_NAMES[f ?? ""] ?? "finger";
|
|
2789
2933
|
const seen = new Set;
|
|
@@ -2802,7 +2946,7 @@ function move(from, fromFingers, to, tuning) {
|
|
|
2802
2946
|
tips.push(`Slide your ${fingerName(f)} along ${stringName(tuning, s)} from fret ${from[s]} to ${to.frets[s]}.`);
|
|
2803
2947
|
}
|
|
2804
2948
|
if (shift >= 2) {
|
|
2805
|
-
const up =
|
|
2949
|
+
const up = lowestFret2(to.frets) > lowestFret2(from);
|
|
2806
2950
|
tips.push(`Move your hand ${up ? "up" : "down"} ${shift} frets.`);
|
|
2807
2951
|
}
|
|
2808
2952
|
if (!anchors.length && !guides.length && shift < 2) {
|
|
@@ -3049,16 +3193,28 @@ function positionParts(language, source) {
|
|
|
3049
3193
|
if (bad !== undefined) {
|
|
3050
3194
|
throw new Error(`positions: use all, or numbers from 1 to ${count} for ${set.title}`);
|
|
3051
3195
|
}
|
|
3196
|
+
const tuningText = block.fields.get("tuning");
|
|
3197
|
+
const numbering = numberingOf(block.fields.get("numbering"), set, system);
|
|
3198
|
+
const neck = neckPositions(set, tuningText && parseTuning(tuningText) || STANDARD_TUNING, system, numbering);
|
|
3199
|
+
const numbered = numbering === "minor" ? ["numbering: minor"] : [];
|
|
3200
|
+
const from = numbering === "minor" ? ` (from ${relativeMinorOf(set)}m)` : "";
|
|
3201
|
+
const fretsOf = (n) => {
|
|
3202
|
+
const cells = neck[n - 1];
|
|
3203
|
+
if (!cells?.length)
|
|
3204
|
+
return [];
|
|
3205
|
+
const frets = cells.map((c) => c.fret);
|
|
3206
|
+
return [`frets: ${Math.min(...frets)}-${Math.max(...frets)}`];
|
|
3207
|
+
};
|
|
3052
3208
|
const shared = SHARED_KEYS.fretboard;
|
|
3053
|
-
const others = [...block.fields].filter(([key]) => !["positions", "scale", "shape", "position", "title"].includes(key));
|
|
3209
|
+
const others = [...block.fields].filter(([key]) => !["positions", "scale", "shape", "position", "numbering", "title", "frets"].includes(key));
|
|
3054
3210
|
const header = others.filter(([key]) => key === "columns" || shared.includes(key)).map(([key, v]) => `${key}: ${v}`);
|
|
3055
3211
|
const own = others.filter(([key]) => key !== "columns" && !shared.includes(key)).map(([key, v]) => `${key}: ${v}`);
|
|
3056
3212
|
const diagrams = wanted.map((n) => {
|
|
3057
3213
|
const at = system === "caged" ? [
|
|
3058
3214
|
`shape: ${CAGED_SHAPES[n - 1]}`,
|
|
3059
3215
|
`title: ${set.title}, ${CAGED_SHAPES[n - 1]} shape`
|
|
3060
|
-
] : system === "3nps" ? ["shape: 3nps", `position: ${n}`, `title: ${set.title}, 3nps ${n}`] : [`position: ${n}`, `title: ${set.title}, box ${n}`];
|
|
3061
|
-
return [`scale: ${scale}`, ...at, ...own].join(`
|
|
3216
|
+
] : system === "3nps" ? ["shape: 3nps", `position: ${n}`, `title: ${set.title}, 3nps ${n}${from}`] : [`position: ${n}`, `title: ${set.title}, box ${n}${from}`];
|
|
3217
|
+
return [`scale: ${scale}`, ...at, ...numbered, ...fretsOf(n), ...own].join(`
|
|
3062
3218
|
`);
|
|
3063
3219
|
});
|
|
3064
3220
|
return [...header.length ? [header.join(`
|
|
@@ -4310,6 +4466,7 @@ export {
|
|
|
4310
4466
|
FLAT_NAMES,
|
|
4311
4467
|
LANGUAGES,
|
|
4312
4468
|
MAX_DIAGRAMS,
|
|
4469
|
+
MAX_FRET,
|
|
4313
4470
|
MAX_GENERATED_STRINGS,
|
|
4314
4471
|
SHARP_NAMES,
|
|
4315
4472
|
STANDARD_TUNING,
|
|
@@ -4344,6 +4501,7 @@ export {
|
|
|
4344
4501
|
midiOf,
|
|
4345
4502
|
modesOf,
|
|
4346
4503
|
nameOf,
|
|
4504
|
+
neckPositions,
|
|
4347
4505
|
noteOf,
|
|
4348
4506
|
parseChord,
|
|
4349
4507
|
parseChordName,
|
|
@@ -4380,5 +4538,5 @@ export {
|
|
|
4380
4538
|
voicingShape
|
|
4381
4539
|
};
|
|
4382
4540
|
|
|
4383
|
-
//# debugId=
|
|
4541
|
+
//# debugId=2CB6D3742D816A1464756E2164756E21
|
|
4384
4542
|
//# sourceMappingURL=index.js.map
|