@dsebastien/music-notation 0.5.2 → 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 +244 -51
- package/dist/index.js.map +15 -15
- package/dist/music-notation.publish.min.js +17 -17
- package/dist/music-notation.tab.min.js +1 -1
- package/dist/publish/index.js +242 -51
- package/dist/publish/index.js.map +15 -15
- package/dist/tab/index.js +79 -15
- package/dist/tab/index.js.map +5 -5
- package/dist/theory/note-set.d.ts +19 -5
- package/dist/theory/suffix.d.ts +8 -1
- package/dist/voicings/index.d.ts +3 -2
- package/dist/voicings/index.js +945 -4
- package/dist/voicings/index.js.map +11 -5
- 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([
|
|
@@ -554,9 +561,32 @@ var CANONICAL = new Map([
|
|
|
554
561
|
["sus", "sus4"],
|
|
555
562
|
["add2", "add9"],
|
|
556
563
|
["69", "6/9"],
|
|
557
|
-
["alt", "7alt"]
|
|
564
|
+
["alt", "7alt"],
|
|
565
|
+
["-5", "Mb5"],
|
|
566
|
+
["#5", "aug"],
|
|
567
|
+
["b5", "Mb5"],
|
|
568
|
+
["maj7b5", "M7b5"],
|
|
569
|
+
["mmaj9", "mMaj9"],
|
|
570
|
+
["m6/9", "m69"],
|
|
571
|
+
["m6add9", "m69"],
|
|
572
|
+
["sus2sus4", "sus24"]
|
|
558
573
|
]);
|
|
559
|
-
|
|
574
|
+
function withoutParentheses(suffix) {
|
|
575
|
+
if (!/[(),]/.test(suffix))
|
|
576
|
+
return suffix;
|
|
577
|
+
if (!/^[^(),]*(?:\([^(),]+(?:,[^(),]+)*\)[^(),]*)+$/.test(suffix))
|
|
578
|
+
return null;
|
|
579
|
+
return suffix.replace(/[(),\s]/g, "");
|
|
580
|
+
}
|
|
581
|
+
function canonicalSuffix(suffix) {
|
|
582
|
+
const direct = CANONICAL.get(suffix);
|
|
583
|
+
if (direct !== undefined)
|
|
584
|
+
return direct;
|
|
585
|
+
const flat = withoutParentheses(suffix);
|
|
586
|
+
if (flat === null || flat === suffix)
|
|
587
|
+
return suffix;
|
|
588
|
+
return CANONICAL.get(flat) ?? flat;
|
|
589
|
+
}
|
|
560
590
|
|
|
561
591
|
// src/theory/scales.ts
|
|
562
592
|
import { Note, Scale } from "tonal";
|
|
@@ -694,7 +724,7 @@ function chordNoteSet(symbol) {
|
|
|
694
724
|
const parts = splitChordSymbol(symbol);
|
|
695
725
|
if (!parts)
|
|
696
726
|
return null;
|
|
697
|
-
const chord = Chord.
|
|
727
|
+
const chord = Chord.getChord(canonicalSuffix(parts.suffix), parts.root);
|
|
698
728
|
if (chord.empty)
|
|
699
729
|
return null;
|
|
700
730
|
const bass = parts.bass;
|
|
@@ -715,7 +745,26 @@ function scaleNoteSet(name) {
|
|
|
715
745
|
set.scaleType = scale.type;
|
|
716
746
|
return set;
|
|
717
747
|
}
|
|
718
|
-
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) {
|
|
719
768
|
const tokens = text.split(/[\s,]+/).filter(Boolean);
|
|
720
769
|
if (!tokens.length)
|
|
721
770
|
return null;
|
|
@@ -724,8 +773,21 @@ function listNoteSet(text) {
|
|
|
724
773
|
if (!withOctaves && names.some((n) => chromaOf(n) === null))
|
|
725
774
|
return null;
|
|
726
775
|
const set = fromNames(tokens.join(" "), names, null);
|
|
727
|
-
if (set
|
|
776
|
+
if (!set)
|
|
777
|
+
return null;
|
|
778
|
+
set.list = true;
|
|
779
|
+
if (withOctaves)
|
|
728
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
|
+
}
|
|
729
791
|
return set;
|
|
730
792
|
}
|
|
731
793
|
|
|
@@ -804,12 +866,30 @@ function renderFretboard(doc, set, options = {}) {
|
|
|
804
866
|
const hidden = options.strings !== undefined && !options.strings.includes(s);
|
|
805
867
|
if (!member || hidden || played && !played.has(`${s}:${fret}`)) {
|
|
806
868
|
if (!member && !hidden && options.marks?.ghosts?.has(chroma)) {
|
|
807
|
-
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
|
+
}));
|
|
808
879
|
}
|
|
809
880
|
continue;
|
|
810
881
|
}
|
|
811
882
|
const cls = `mn-dot${markClasses(set, member.chroma, options.marks)}`;
|
|
812
|
-
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
|
+
}));
|
|
813
893
|
sounding.add(open + fret);
|
|
814
894
|
const text = labelOf(member, label);
|
|
815
895
|
if (text)
|
|
@@ -819,7 +899,9 @@ function renderFretboard(doc, set, options = {}) {
|
|
|
819
899
|
root.setAttribute("data-mn-pitches", [...sounding].sort((a, b) => a - b).join(" "));
|
|
820
900
|
root.setAttribute("data-mn-play", "scale");
|
|
821
901
|
root.setAttribute("data-mn-sound", "guitar");
|
|
822
|
-
|
|
902
|
+
root.setAttribute("data-mn-set", set.title);
|
|
903
|
+
root.setAttribute("data-mn-frets", `${from}-${to}`);
|
|
904
|
+
if (set.root !== null && !set.list)
|
|
823
905
|
root.setAttribute("data-mn-root", String(set.root));
|
|
824
906
|
return root;
|
|
825
907
|
}
|
|
@@ -953,7 +1035,8 @@ function renderKeyboard(doc, set, options = {}) {
|
|
|
953
1035
|
class: keyClass(midi, false),
|
|
954
1036
|
...key(along, WHITE_W, WHITE_H),
|
|
955
1037
|
rx: 2,
|
|
956
|
-
"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)
|
|
957
1040
|
}));
|
|
958
1041
|
caption(midi, at(along + WHITE_W / 2, WHITE_H - 13), false);
|
|
959
1042
|
});
|
|
@@ -966,7 +1049,8 @@ function renderKeyboard(doc, set, options = {}) {
|
|
|
966
1049
|
class: keyClass(black, true),
|
|
967
1050
|
...key(along, BLACK_W, BLACK_H),
|
|
968
1051
|
rx: 2,
|
|
969
|
-
"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)
|
|
970
1054
|
}));
|
|
971
1055
|
caption(black, at(along + BLACK_W / 2, BLACK_H - 13), true);
|
|
972
1056
|
});
|
|
@@ -976,7 +1060,9 @@ function renderKeyboard(doc, set, options = {}) {
|
|
|
976
1060
|
continue;
|
|
977
1061
|
const whitesBelow = whites.filter((w) => w < midi).length;
|
|
978
1062
|
const along = isBlack(midi) ? whitesBelow * WHITE_W : whitesBelow * WHITE_W + WHITE_W / 2;
|
|
979
|
-
|
|
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);
|
|
980
1066
|
}
|
|
981
1067
|
}
|
|
982
1068
|
const played = [];
|
|
@@ -986,7 +1072,8 @@ function renderKeyboard(doc, set, options = {}) {
|
|
|
986
1072
|
root.setAttribute("data-mn-pitches", played.join(" "));
|
|
987
1073
|
root.setAttribute("data-mn-play", options.playAs ?? "scale");
|
|
988
1074
|
root.setAttribute("data-mn-sound", "piano");
|
|
989
|
-
|
|
1075
|
+
root.setAttribute("data-mn-set", set.title);
|
|
1076
|
+
if (set.root !== null && !set.list)
|
|
990
1077
|
root.setAttribute("data-mn-root", String(set.root));
|
|
991
1078
|
return root;
|
|
992
1079
|
}
|
|
@@ -1003,12 +1090,14 @@ var QUALITY_SUFFIXES = [
|
|
|
1003
1090
|
[/^(m6|min6|-6)$/, "Minor 6"],
|
|
1004
1091
|
[/^(m|min|-)$/, "Minor"],
|
|
1005
1092
|
[/^(dim|°)$/, "Diminished"],
|
|
1006
|
-
[/^(aug
|
|
1093
|
+
[/^(aug|\+|\+5|#5)$/, "Augmented"],
|
|
1007
1094
|
[/^(sus2)$/, "Sus2"],
|
|
1008
1095
|
[/^(sus4|sus)$/, "Sus4"],
|
|
1009
1096
|
[/^(add9|add2)$/, "Add9"],
|
|
1010
1097
|
[/^5$/, "5 (Power)"],
|
|
1011
1098
|
[/^(6\/9|69)$/, "6/9"],
|
|
1099
|
+
[/^(m6\/9|m69|m6add9)$/, "Minor 6/9"],
|
|
1100
|
+
[/^(Mb5|b5|-5)$/, "Major flat 5"],
|
|
1012
1101
|
[/^(mM7|mMaj7|mmaj7|m\(maj7\)|-\(maj7\))$/, "Minor major 7"],
|
|
1013
1102
|
[/^(13|11|9|7|6)$/, "$1"],
|
|
1014
1103
|
[/^(maj|M)?$/, "Major"]
|
|
@@ -1020,16 +1109,23 @@ function parseChord(symbol) {
|
|
|
1020
1109
|
if (!parts)
|
|
1021
1110
|
return null;
|
|
1022
1111
|
const trimmed = symbol.trim();
|
|
1023
|
-
const { root,
|
|
1112
|
+
const { root, bass } = parts;
|
|
1113
|
+
const suffix = withoutParentheses(parts.suffix);
|
|
1024
1114
|
let quality = null;
|
|
1025
|
-
for (const [
|
|
1026
|
-
const
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1115
|
+
for (const written of suffix === null || suffix === parts.suffix ? [parts.suffix] : [parts.suffix, suffix]) {
|
|
1116
|
+
for (const [re, label] of QUALITY_SUFFIXES) {
|
|
1117
|
+
const hit = re.exec(written);
|
|
1118
|
+
if (hit) {
|
|
1119
|
+
quality = label.replace("$1", hit[1] ?? "");
|
|
1120
|
+
break;
|
|
1121
|
+
}
|
|
1030
1122
|
}
|
|
1123
|
+
if (quality)
|
|
1124
|
+
break;
|
|
1031
1125
|
}
|
|
1032
|
-
if (
|
|
1126
|
+
if (suffix === null && !quality)
|
|
1127
|
+
return null;
|
|
1128
|
+
if (!quality && suffix !== null && chordNoteSet(trimmed))
|
|
1033
1129
|
quality = suffix;
|
|
1034
1130
|
if (!quality)
|
|
1035
1131
|
return null;
|
|
@@ -1070,6 +1166,8 @@ var QUALITY_WORDS = new Map([
|
|
|
1070
1166
|
["5", "5"],
|
|
1071
1167
|
["power", "5"],
|
|
1072
1168
|
["6/9", "6/9"],
|
|
1169
|
+
["minor 6/9", "m6/9"],
|
|
1170
|
+
["major flat 5", "Mb5"],
|
|
1073
1171
|
["minor major 7", "mMaj7"],
|
|
1074
1172
|
["dominant 7", "7"],
|
|
1075
1173
|
["13", "13"],
|
|
@@ -1225,7 +1323,7 @@ function bassCost(root, quality, bass) {
|
|
|
1225
1323
|
if (!bass)
|
|
1226
1324
|
return 0;
|
|
1227
1325
|
const chroma = chromaOf(bass);
|
|
1228
|
-
const tone = Chord2.
|
|
1326
|
+
const tone = Chord2.getChord(quality, root).notes.find((note) => chromaOf(note) === chroma);
|
|
1229
1327
|
if (tone)
|
|
1230
1328
|
return tone === bass ? 0 : 1;
|
|
1231
1329
|
const flats = keyPrefersFlats(`${root}${quality.startsWith("m") && !quality.startsWith("maj") ? "m" : ""}`);
|
|
@@ -1332,6 +1430,29 @@ function noteSetOf(block) {
|
|
|
1332
1430
|
const scale = block.fields.get("scale");
|
|
1333
1431
|
const chord = block.fields.get("chord");
|
|
1334
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
|
+
}
|
|
1335
1456
|
if (scale !== undefined) {
|
|
1336
1457
|
if (isScaleWithoutRoot(scale))
|
|
1337
1458
|
throw new Error(`Add a root note: C ${scale.trim()}`);
|
|
@@ -1351,6 +1472,7 @@ function noteSetOf(block) {
|
|
|
1351
1472
|
}
|
|
1352
1473
|
throw new Error('Add "scale:", "chord:" or "notes:"');
|
|
1353
1474
|
}
|
|
1475
|
+
var rootNotForList = (what) => new Error(`root only applies to lists of notes (notes: C E G): ${what} has its own root`);
|
|
1354
1476
|
function labelField(block, fallback, fingers = false) {
|
|
1355
1477
|
const value = block.fields.get("labels")?.toLowerCase();
|
|
1356
1478
|
if (value === undefined)
|
|
@@ -1378,7 +1500,7 @@ function marksOf(block, set) {
|
|
|
1378
1500
|
}
|
|
1379
1501
|
} else if (highlight.toLowerCase() !== "none" && highlight !== "") {
|
|
1380
1502
|
if (set.members.every((m) => m.interval === null)) {
|
|
1381
|
-
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)");
|
|
1382
1504
|
}
|
|
1383
1505
|
const labels = highlight.replace(/♭/g, "b").replace(/♯/g, "#").split(/[\s,]+/).filter(Boolean);
|
|
1384
1506
|
for (const label of labels) {
|
|
@@ -1394,12 +1516,13 @@ function marksOf(block, set) {
|
|
|
1394
1516
|
const compare = block.fields.get("compare")?.trim();
|
|
1395
1517
|
if (compare) {
|
|
1396
1518
|
const tonic = Scale3.get(scaleName(compare)).tonic;
|
|
1397
|
-
const root = set.members[0]?.name ?? "";
|
|
1519
|
+
const root = rootNameOf(block.fields.get("root") ?? "") ?? set.members[0]?.name ?? "";
|
|
1398
1520
|
const parent = orFail(scaleNoteSet(tonic ? compare : `${root} ${compare}`), `Unknown scale "${compare}" to compare with: use e.g. compare: major`);
|
|
1399
1521
|
const own = new Set(set.members.map((m) => m.chroma));
|
|
1400
1522
|
const theirs = new Set(parent.members.map((m) => m.chroma));
|
|
1401
1523
|
marks.different = new Set([...own].filter((c) => !theirs.has(c)));
|
|
1402
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]));
|
|
1403
1526
|
}
|
|
1404
1527
|
return marks;
|
|
1405
1528
|
}
|
|
@@ -1447,23 +1570,61 @@ function pentatonicOf(set) {
|
|
|
1447
1570
|
}
|
|
1448
1571
|
return null;
|
|
1449
1572
|
}
|
|
1450
|
-
|
|
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) {
|
|
1451
1611
|
if (set.root === null || n < 1 || n > positionCount(set, system))
|
|
1452
|
-
return
|
|
1612
|
+
return [];
|
|
1453
1613
|
const open = tuning[0];
|
|
1454
1614
|
const chromas = chromasOf(set);
|
|
1455
1615
|
const notes = tuning.length * 3;
|
|
1456
1616
|
const nps = system === "3nps" || system === "caged" && chromas.length !== 5 && !pentatonicOf(set);
|
|
1457
1617
|
const pentatonic = chromas.length === 5 ? chromas : pentatonicOf(set);
|
|
1458
1618
|
if (!nps && !pentatonic)
|
|
1459
|
-
return
|
|
1619
|
+
return [];
|
|
1460
1620
|
const startChroma = nps ? chromas[(n - 1) % chromas.length] : pentatonic[(n - 1) % 5];
|
|
1461
|
-
|
|
1621
|
+
const out = [];
|
|
1622
|
+
for (let start = fretOn(open, startChroma, 0);start <= MAX_FRET; start += 12) {
|
|
1462
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);
|
|
1463
1624
|
if (cells && cells.every((c) => c.fret >= 0))
|
|
1464
|
-
|
|
1625
|
+
out.push(cells);
|
|
1465
1626
|
}
|
|
1466
|
-
return
|
|
1627
|
+
return out;
|
|
1467
1628
|
}
|
|
1468
1629
|
function withOther(box, chromas, tuning) {
|
|
1469
1630
|
if (box.length < tuning.length * 2)
|
|
@@ -1521,6 +1682,7 @@ var SHARED_KEYS = {
|
|
|
1521
1682
|
"compare",
|
|
1522
1683
|
"position",
|
|
1523
1684
|
"shape",
|
|
1685
|
+
"numbering",
|
|
1524
1686
|
"strings"
|
|
1525
1687
|
]
|
|
1526
1688
|
};
|
|
@@ -1647,14 +1809,14 @@ var renderChord = (doc, block, options) => {
|
|
|
1647
1809
|
const fingers = fingering ? fingersFor(set.pitches, fingering) : new Map;
|
|
1648
1810
|
const range = field(block, "range");
|
|
1649
1811
|
handOf(block, options);
|
|
1650
|
-
return renderKeyboard(doc, set, {
|
|
1812
|
+
return named(renderKeyboard(doc, set, {
|
|
1651
1813
|
playAs: "chord",
|
|
1652
1814
|
title,
|
|
1653
1815
|
label: labelField(block, fingers.size ? "fingers" : "notes", fingers.size > 0),
|
|
1654
1816
|
fingers,
|
|
1655
1817
|
range: keyRange(range ? rangeOf(range) : keyRangeOf(set)),
|
|
1656
1818
|
orientation: orientationOf(block, options.orientation?.keyboard)
|
|
1657
|
-
});
|
|
1819
|
+
}), symbol);
|
|
1658
1820
|
}
|
|
1659
1821
|
if (instrument && instrument !== "guitar" && !field(block, "tuning")) {
|
|
1660
1822
|
throw new Error(`Unknown instrument "${instrument}": use guitar or piano, or give a tuning`);
|
|
@@ -1712,7 +1874,7 @@ var renderChord = (doc, block, options) => {
|
|
|
1712
1874
|
const anchors = marked("anchors");
|
|
1713
1875
|
const guides = marked("guides");
|
|
1714
1876
|
const marks = voicing.frets.map((_, s) => anchors.includes(s) ? "anchor" : guides.includes(s) ? "guide" : null);
|
|
1715
|
-
return renderGuitarDiagram(doc, voicing, {
|
|
1877
|
+
return named(renderGuitarDiagram(doc, voicing, {
|
|
1716
1878
|
title,
|
|
1717
1879
|
root,
|
|
1718
1880
|
tuning,
|
|
@@ -1720,8 +1882,13 @@ var renderChord = (doc, block, options) => {
|
|
|
1720
1882
|
...anchors.length || guides.length ? { marks } : {},
|
|
1721
1883
|
orientation: orientationOf(block, options.orientation?.chord),
|
|
1722
1884
|
hand: handOf(block, options)
|
|
1723
|
-
});
|
|
1885
|
+
}), symbol);
|
|
1724
1886
|
};
|
|
1887
|
+
function named(el, symbol) {
|
|
1888
|
+
if (symbol)
|
|
1889
|
+
el.setAttribute("data-mn-chord", symbol);
|
|
1890
|
+
return el;
|
|
1891
|
+
}
|
|
1725
1892
|
function dotLabels(text, symbol, voicing, tuning) {
|
|
1726
1893
|
const value = text?.toLowerCase();
|
|
1727
1894
|
if (value === undefined || value === "fingers")
|
|
@@ -1760,7 +1927,7 @@ var renderKeyboardBlock = (doc, block, options) => {
|
|
|
1760
1927
|
const fingering = field(block, "fingering");
|
|
1761
1928
|
const keys = range ? rangeOf(range) : undefined;
|
|
1762
1929
|
let fingers;
|
|
1763
|
-
if (fingering && set.root !== null && !set.pitches) {
|
|
1930
|
+
if (fingering && set.root !== null && !set.list && !set.pitches) {
|
|
1764
1931
|
let start = 60 + set.root;
|
|
1765
1932
|
if (keys) {
|
|
1766
1933
|
const first = keys[0] + ((set.root - keys[0]) % 12 + 12) % 12;
|
|
@@ -1775,7 +1942,7 @@ var renderKeyboardBlock = (doc, block, options) => {
|
|
|
1775
1942
|
set.pitches = octave;
|
|
1776
1943
|
}
|
|
1777
1944
|
return renderKeyboard(doc, set, {
|
|
1778
|
-
playAs: !set.scaleType && set.root !== null ? "chord" : "scale",
|
|
1945
|
+
playAs: !set.scaleType && !set.list && set.root !== null ? "chord" : "scale",
|
|
1779
1946
|
title: field(block, "title"),
|
|
1780
1947
|
label: labelField(block, fingers ? "fingers" : "notes", fingers !== undefined),
|
|
1781
1948
|
fingers,
|
|
@@ -1789,19 +1956,30 @@ var renderFretboardBlock = (doc, block, options) => {
|
|
|
1789
1956
|
const at = positionOf(field(block, "position"), field(block, "shape"));
|
|
1790
1957
|
const fretsText = field(block, "frets");
|
|
1791
1958
|
const frets = fretsText ? orFail(parseRange(fretsText), `Invalid frets "${fretsText}": use e.g. 5-8`) : undefined;
|
|
1792
|
-
if (frets && frets[1] >
|
|
1793
|
-
throw new Error(
|
|
1959
|
+
if (frets && frets[1] > MAX_FRET)
|
|
1960
|
+
throw new Error(`Frets go up to ${MAX_FRET}`);
|
|
1794
1961
|
const tuningText = field(block, "tuning");
|
|
1795
1962
|
const tuning = tuningText ? tuningOf(tuningText) : undefined;
|
|
1796
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
|
+
}
|
|
1797
1967
|
if (at) {
|
|
1798
|
-
if (set.root === null)
|
|
1968
|
+
if (set.root === null || set.list) {
|
|
1799
1969
|
throw new Error("Positions need a scale: e.g. scale: A minor");
|
|
1970
|
+
}
|
|
1800
1971
|
if (at.system === "box" && set.members.length !== 5)
|
|
1801
1972
|
at.system = "caged";
|
|
1802
1973
|
const count = positionCount(set, at.system);
|
|
1803
1974
|
const named = { box: "box", caged: "CAGED", "3nps": "3nps" }[at.system];
|
|
1804
|
-
|
|
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
|
+
}
|
|
1805
1983
|
}
|
|
1806
1984
|
const stringsText = field(block, "strings");
|
|
1807
1985
|
const count = (tuning ?? STANDARD_TUNING).length;
|
|
@@ -2078,10 +2256,11 @@ function barFor(doc, win, diagram, data, options) {
|
|
|
2078
2256
|
};
|
|
2079
2257
|
const play = (events, onEnd) => {
|
|
2080
2258
|
const options_ = { sound: settings.sound, volume: settings.volume, onEnd };
|
|
2259
|
+
const here = wrap.ownerDocument.defaultView ?? win;
|
|
2081
2260
|
try {
|
|
2082
|
-
return playerFor(
|
|
2261
|
+
return playerFor(here, options).play(events, options_);
|
|
2083
2262
|
} catch {
|
|
2084
|
-
return lightFor(
|
|
2263
|
+
return lightFor(here).play(events, options_);
|
|
2085
2264
|
}
|
|
2086
2265
|
};
|
|
2087
2266
|
const start = () => {
|
|
@@ -2720,7 +2899,7 @@ function stringName(tuning, s) {
|
|
|
2720
2899
|
const lowest = tuning.findIndex((p) => noteOf(p).replace(/-?\d+$/, "") === name);
|
|
2721
2900
|
return `the ${s === lowest ? "low" : "high"} ${name} string`;
|
|
2722
2901
|
}
|
|
2723
|
-
var
|
|
2902
|
+
var lowestFret2 = (frets) => {
|
|
2724
2903
|
const fretted = frets.filter((f) => f !== null && f > 0);
|
|
2725
2904
|
return fretted.length ? Math.min(...fretted) : 0;
|
|
2726
2905
|
};
|
|
@@ -2748,7 +2927,7 @@ function move(from, fromFingers, to, tuning) {
|
|
|
2748
2927
|
const placed = new Set(to.frets.flatMap((f, s) => f && to.fingers[s] && !anchors.includes(s) && !guides.includes(s) ? [to.fingers[s]] : []));
|
|
2749
2928
|
const strings = new Set(to.frets.flatMap((f, s) => f && to.fingers[s] && !anchors.includes(s) && !guides.includes(s) ? [s] : []));
|
|
2750
2929
|
movement -= strings.size - placed.size;
|
|
2751
|
-
const shift = Math.abs(
|
|
2930
|
+
const shift = Math.abs(lowestFret2(to.frets) - lowestFret2(from));
|
|
2752
2931
|
movement += 0.3 * shift;
|
|
2753
2932
|
const fingerName = (f) => FINGER_NAMES[f ?? ""] ?? "finger";
|
|
2754
2933
|
const seen = new Set;
|
|
@@ -2767,7 +2946,7 @@ function move(from, fromFingers, to, tuning) {
|
|
|
2767
2946
|
tips.push(`Slide your ${fingerName(f)} along ${stringName(tuning, s)} from fret ${from[s]} to ${to.frets[s]}.`);
|
|
2768
2947
|
}
|
|
2769
2948
|
if (shift >= 2) {
|
|
2770
|
-
const up =
|
|
2949
|
+
const up = lowestFret2(to.frets) > lowestFret2(from);
|
|
2771
2950
|
tips.push(`Move your hand ${up ? "up" : "down"} ${shift} frets.`);
|
|
2772
2951
|
}
|
|
2773
2952
|
if (!anchors.length && !guides.length && shift < 2) {
|
|
@@ -3014,16 +3193,28 @@ function positionParts(language, source) {
|
|
|
3014
3193
|
if (bad !== undefined) {
|
|
3015
3194
|
throw new Error(`positions: use all, or numbers from 1 to ${count} for ${set.title}`);
|
|
3016
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
|
+
};
|
|
3017
3208
|
const shared = SHARED_KEYS.fretboard;
|
|
3018
|
-
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));
|
|
3019
3210
|
const header = others.filter(([key]) => key === "columns" || shared.includes(key)).map(([key, v]) => `${key}: ${v}`);
|
|
3020
3211
|
const own = others.filter(([key]) => key !== "columns" && !shared.includes(key)).map(([key, v]) => `${key}: ${v}`);
|
|
3021
3212
|
const diagrams = wanted.map((n) => {
|
|
3022
3213
|
const at = system === "caged" ? [
|
|
3023
3214
|
`shape: ${CAGED_SHAPES[n - 1]}`,
|
|
3024
3215
|
`title: ${set.title}, ${CAGED_SHAPES[n - 1]} shape`
|
|
3025
|
-
] : system === "3nps" ? ["shape: 3nps", `position: ${n}`, `title: ${set.title}, 3nps ${n}`] : [`position: ${n}`, `title: ${set.title}, box ${n}`];
|
|
3026
|
-
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(`
|
|
3027
3218
|
`);
|
|
3028
3219
|
});
|
|
3029
3220
|
return [...header.length ? [header.join(`
|
|
@@ -4275,6 +4466,7 @@ export {
|
|
|
4275
4466
|
FLAT_NAMES,
|
|
4276
4467
|
LANGUAGES,
|
|
4277
4468
|
MAX_DIAGRAMS,
|
|
4469
|
+
MAX_FRET,
|
|
4278
4470
|
MAX_GENERATED_STRINGS,
|
|
4279
4471
|
SHARP_NAMES,
|
|
4280
4472
|
STANDARD_TUNING,
|
|
@@ -4309,6 +4501,7 @@ export {
|
|
|
4309
4501
|
midiOf,
|
|
4310
4502
|
modesOf,
|
|
4311
4503
|
nameOf,
|
|
4504
|
+
neckPositions,
|
|
4312
4505
|
noteOf,
|
|
4313
4506
|
parseChord,
|
|
4314
4507
|
parseChordName,
|
|
@@ -4345,5 +4538,5 @@ export {
|
|
|
4345
4538
|
voicingShape
|
|
4346
4539
|
};
|
|
4347
4540
|
|
|
4348
|
-
//# debugId=
|
|
4541
|
+
//# debugId=2CB6D3742D816A1464756E2164756E21
|
|
4349
4542
|
//# sourceMappingURL=index.js.map
|