@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/render/dom.d.ts
CHANGED
|
@@ -7,6 +7,11 @@ export declare function svg(doc: Document, tag: string, attrs?: Attributes, chil
|
|
|
7
7
|
export declare function svgText(doc: Document, text: string, attrs?: Attributes): SVGElement;
|
|
8
8
|
/** A <text> vertically centered on (x, y), for the 10–11px labels of diagrams. */
|
|
9
9
|
export declare function svgLabel(doc: Document, text: string, [x, y]: [number, number], cls: string, anchor?: 'start' | 'middle' | 'end'): SVGElement;
|
|
10
|
+
/**
|
|
11
|
+
* The text in a note dot of radius `r`: a label of three characters or more (bb7, #11, b13) is
|
|
12
|
+
* smaller and squeezed to the dot's inner width, so it never passes the dot's edge (#73).
|
|
13
|
+
*/
|
|
14
|
+
export declare function dotLabel(doc: Document, text: string, point: [number, number], r: number): SVGElement;
|
|
10
15
|
/** A <line> between two points. */
|
|
11
16
|
export declare function svgLine(doc: Document, [x1, y1]: [number, number], [x2, y2]: [number, number], cls: string): SVGElement;
|
|
12
17
|
/** An HTML element with a class and optional text. */
|
package/dist/strum/pattern.d.ts
CHANGED
|
@@ -38,6 +38,12 @@ export interface StrumPattern {
|
|
|
38
38
|
/** Open strings for playback (`tuning:`), as written; null for standard guitar. */
|
|
39
39
|
tuning: string | null;
|
|
40
40
|
title: string | null;
|
|
41
|
+
/**
|
|
42
|
+
* How strums written alone were read when the hand's motion placed them and the bar ends with
|
|
43
|
+
* whole beats of no strum (`D U D U` in triplets: `D - U D - U` and 2 empty beats), with what
|
|
44
|
+
* to write instead; null otherwise (#73).
|
|
45
|
+
*/
|
|
46
|
+
note: string | null;
|
|
41
47
|
}
|
|
42
48
|
/** Bounds that keep a pattern quick to draw and to hear. */
|
|
43
49
|
export declare const MAX_STRUM_BARS = 16;
|
package/dist/strum/render.d.ts
CHANGED
|
@@ -17,4 +17,4 @@ export declare function renderStrum(doc: Document, pattern: StrumPattern, option
|
|
|
17
17
|
* option's on a standard guitar, else generated ones, for the block's `tuning:`). Throws a
|
|
18
18
|
* message for the user.
|
|
19
19
|
*/
|
|
20
|
-
export declare function renderStrumBlock(doc: Document, source: string, options: RenderOptions):
|
|
20
|
+
export declare function renderStrumBlock(doc: Document, source: string, options: RenderOptions): Element;
|
package/dist/tab/index.d.ts
CHANGED
|
@@ -60,11 +60,17 @@ export interface TabSource {
|
|
|
60
60
|
tex: string;
|
|
61
61
|
/** Lines of the block before the alphaTex (settings, blank lines), for error positions. */
|
|
62
62
|
texLine: number;
|
|
63
|
+
/**
|
|
64
|
+
* Whether `tex` was converted from a plain-text tab written in the block (a tab pasted from
|
|
65
|
+
* the web, #71): `textTabToAlphaTex`, in memory, the block's text unchanged.
|
|
66
|
+
*/
|
|
67
|
+
fromText: boolean;
|
|
63
68
|
}
|
|
64
69
|
/**
|
|
65
70
|
* A tab block's own settings (lines `staves:`, `file:`, `tracks:` at the top, `//` comments
|
|
66
|
-
* allowed among them), then its alphaTex
|
|
67
|
-
* notation, unless `staves:` says otherwise. Throws a message
|
|
71
|
+
* allowed among them), then its alphaTex, or a plain-text tab, converted (#71). ```tab blocks show
|
|
72
|
+
* tablature, ```score blocks standard notation, unless `staves:` says otherwise. Throws a message
|
|
73
|
+
* for the user.
|
|
68
74
|
*/
|
|
69
75
|
export declare function parseTabSource(language: 'tab' | 'score', source: string): TabSource;
|
|
70
76
|
/** The part of alphaTab's score read and set to hide its default dynamics. */
|
package/dist/tab/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
|
}
|
|
@@ -135,11 +144,20 @@ var isFlat = (name) => /^[A-Ga-g][b♭]/.test(name.trim());
|
|
|
135
144
|
var NAMED = new Map(Object.entries({
|
|
136
145
|
standard: "E2 A2 D3 G3 B3 E4",
|
|
137
146
|
"drop d": "D2 A2 D3 G3 B3 E4",
|
|
147
|
+
"drop c": "C2 G2 C3 F3 A3 D4",
|
|
148
|
+
"drop b": "B1 F#2 B2 E3 G#3 C#4",
|
|
149
|
+
"drop a": "A1 E2 A2 D3 F#3 B3",
|
|
150
|
+
"double drop d": "D2 A2 D3 G3 B3 D4",
|
|
138
151
|
dadgad: "D2 A2 D3 G3 A3 D4",
|
|
139
152
|
"open g": "D2 G2 D3 G3 B3 D4",
|
|
140
153
|
"open d": "D2 A2 D3 F#3 A3 D4",
|
|
141
154
|
"open e": "E2 B2 E3 G#3 B3 E4",
|
|
155
|
+
"open c": "C2 G2 C3 G3 C4 E4",
|
|
156
|
+
"open a": "E2 A2 E3 A3 C#4 E4",
|
|
142
157
|
"half step down": "Eb2 Ab2 Db3 Gb3 Bb3 Eb4",
|
|
158
|
+
"whole step down": "D2 G2 C3 F3 A3 D4",
|
|
159
|
+
"modal c6": "C2 A2 C3 G3 C4 E4",
|
|
160
|
+
c6: "C2 A2 C3 G3 C4 E4",
|
|
143
161
|
bass: "E1 A1 D2 G2",
|
|
144
162
|
ukulele: "G4 C4 E4 A4"
|
|
145
163
|
}));
|
|
@@ -540,6 +558,19 @@ function onGuitar(midi) {
|
|
|
540
558
|
}
|
|
541
559
|
return { tuning, string: index + 1 };
|
|
542
560
|
}
|
|
561
|
+
function placedOnGuitar(tuning) {
|
|
562
|
+
if (tuning.length === 1) {
|
|
563
|
+
const { tuning: six, string } = onGuitar(tuning[0]);
|
|
564
|
+
return { tuning: six, strings: [string] };
|
|
565
|
+
}
|
|
566
|
+
const standard = BY_COUNT[6];
|
|
567
|
+
if (tuning.length > 5)
|
|
568
|
+
return null;
|
|
569
|
+
const at = tuning.map((m) => standard.indexOf(m));
|
|
570
|
+
if (at[0] < 0 || at.some((i, k) => i !== at[0] + k))
|
|
571
|
+
return null;
|
|
572
|
+
return { tuning: [...standard], strings: at.map((i) => i + 1) };
|
|
573
|
+
}
|
|
543
574
|
var drumBeatAt = (drums) => (padded, col) => {
|
|
544
575
|
const beat = [];
|
|
545
576
|
padded.forEach((line, i) => {
|
|
@@ -615,6 +646,8 @@ function positionsOf(cols, width, pad, meter = COMMON) {
|
|
|
615
646
|
[pad, width - pad],
|
|
616
647
|
[pad, width]
|
|
617
648
|
];
|
|
649
|
+
for (let start = 1;start < pad; start++)
|
|
650
|
+
spans.push([start, width - start]);
|
|
618
651
|
if (cols[0] > pad)
|
|
619
652
|
spans.push([0, width]);
|
|
620
653
|
for (const [slack, ties] of [
|
|
@@ -641,7 +674,7 @@ function restsFrom(at, meter, end = meter.length) {
|
|
|
641
674
|
}
|
|
642
675
|
return out;
|
|
643
676
|
}
|
|
644
|
-
function sketchRhythmOf(cols, meter = COMMON) {
|
|
677
|
+
function sketchRhythmOf(cols, meter = COMMON, legato = []) {
|
|
645
678
|
const gaps = cols.slice(1).map((c, i) => c - cols[i]);
|
|
646
679
|
const counts = new Map;
|
|
647
680
|
for (const g of gaps)
|
|
@@ -649,7 +682,18 @@ function sketchRhythmOf(cols, meter = COMMON) {
|
|
|
649
682
|
const unit = [...counts].reduce((best, e) => !best || e[1] > best[1] || e[1] === best[1] && e[0] < best[0] ? e : best, null)?.[0];
|
|
650
683
|
for (const eighth of [2, 1]) {
|
|
651
684
|
const lengths = cols.map((_, i) => eighth * (i < gaps.length ? Math.max(1, Math.round(gaps[i] / unit)) : 1));
|
|
652
|
-
|
|
685
|
+
let total = lengths.reduce((a, b) => a + b, 0);
|
|
686
|
+
if (eighth === 2)
|
|
687
|
+
for (const i of legato) {
|
|
688
|
+
if (total <= meter.length)
|
|
689
|
+
break;
|
|
690
|
+
if (i + 1 >= lengths.length || lengths[i] !== 2)
|
|
691
|
+
continue;
|
|
692
|
+
const next = Math.max(1, lengths[i + 1] - 1);
|
|
693
|
+
total -= 1 + lengths[i + 1] - next;
|
|
694
|
+
lengths[i] = 1;
|
|
695
|
+
lengths[i + 1] = next;
|
|
696
|
+
}
|
|
653
697
|
if (total > meter.length)
|
|
654
698
|
continue;
|
|
655
699
|
return [
|
|
@@ -659,6 +703,8 @@ function sketchRhythmOf(cols, meter = COMMON) {
|
|
|
659
703
|
}
|
|
660
704
|
return cols.map((_, beat) => ({ beat, sixteenths: 1 }));
|
|
661
705
|
}
|
|
706
|
+
var LEGATO = new Set(["h", "sl"]);
|
|
707
|
+
var legatoOf = (beats) => beats.flatMap((b, i) => b.notes.some((n) => n.effects.some((e) => LEGATO.has(e))) ? [i] : []);
|
|
662
708
|
function rhythmOf(m, typical, meter) {
|
|
663
709
|
const bar = meter.length;
|
|
664
710
|
const span = m.part === "whole" ? m.width : typical;
|
|
@@ -675,7 +721,7 @@ function rhythmOf(m, typical, meter) {
|
|
|
675
721
|
}
|
|
676
722
|
const at = positionsOf(cols, span, m.pad, meter);
|
|
677
723
|
if (!at) {
|
|
678
|
-
const sketch = sketchRhythmOf(m.beats.map((b) => b.col), meter);
|
|
724
|
+
const sketch = sketchRhythmOf(m.beats.map((b) => b.col), meter, legatoOf(m.beats));
|
|
679
725
|
if (m.part !== "end")
|
|
680
726
|
return sketch;
|
|
681
727
|
const notes = sketch.filter((e) => e.beat >= 0);
|
|
@@ -835,6 +881,35 @@ function measuresOf(rows, typical) {
|
|
|
835
881
|
});
|
|
836
882
|
return out;
|
|
837
883
|
}
|
|
884
|
+
function splitUnbarred(measures, meter) {
|
|
885
|
+
return measures.flatMap((m) => {
|
|
886
|
+
if (m.part !== "whole" || m.beats.length < 2)
|
|
887
|
+
return [m];
|
|
888
|
+
const cols = m.beats.map((b) => b.col);
|
|
889
|
+
if (positionsOf(cols, m.width, m.pad, meter))
|
|
890
|
+
return [m];
|
|
891
|
+
const gaps = cols.slice(1).map((c, i) => c - cols[i]);
|
|
892
|
+
const unit = mostFrequent(gaps).value;
|
|
893
|
+
const eighths = gaps.reduce((sum, g) => sum + Math.max(1, Math.round(g / unit)), 1);
|
|
894
|
+
const perBar = meter.length / 2;
|
|
895
|
+
const span = unit * perBar;
|
|
896
|
+
if (eighths <= perBar || m.width - m.pad < span * 1.5)
|
|
897
|
+
return [m];
|
|
898
|
+
const count = Math.floor((cols.at(-1) - m.pad) / span) + 1;
|
|
899
|
+
return Array.from({ length: count }, (_, k) => {
|
|
900
|
+
const from = m.pad + k * span;
|
|
901
|
+
const beats = m.beats.filter((b) => (k === 0 || b.col >= from) && (k === count - 1 || b.col < from + span)).map((b) => ({ notes: b.notes, col: b.col - k * span }));
|
|
902
|
+
return {
|
|
903
|
+
beats,
|
|
904
|
+
width: m.pad + span,
|
|
905
|
+
pad: m.pad,
|
|
906
|
+
part: "whole",
|
|
907
|
+
pickup: false,
|
|
908
|
+
text: k === count - 1 ? m.text : null
|
|
909
|
+
};
|
|
910
|
+
});
|
|
911
|
+
});
|
|
912
|
+
}
|
|
838
913
|
var quoted = (text) => `"${text.replace(/[\\"]/g, (c) => `\\${c}`)}"`;
|
|
839
914
|
var withEffects = (tex, effects) => effects.length ? `${tex}{${effects.join(" ")}}` : tex;
|
|
840
915
|
function beatTex(notes, effects) {
|
|
@@ -892,9 +967,9 @@ function textTabToAlphaTex(text) {
|
|
|
892
967
|
if (!first)
|
|
893
968
|
return null;
|
|
894
969
|
let tuning = first.kind === "strings" ? tuningOf(first.names) : null;
|
|
895
|
-
const
|
|
896
|
-
if (
|
|
897
|
-
tuning =
|
|
970
|
+
const placed = tuning ? placedOnGuitar(tuning) : null;
|
|
971
|
+
if (placed)
|
|
972
|
+
tuning = placed.tuning;
|
|
898
973
|
const rows = [];
|
|
899
974
|
if (first.kind === "drums") {
|
|
900
975
|
for (const s of systems)
|
|
@@ -902,7 +977,7 @@ function textTabToAlphaTex(text) {
|
|
|
902
977
|
rows.push(rowOf(s.lines, barsOf(s.lines, drumBeatAt(s.drums)), s.texts, false));
|
|
903
978
|
} else {
|
|
904
979
|
const same = JSON.stringify(tuningOf(first.names));
|
|
905
|
-
const strings =
|
|
980
|
+
const strings = placed?.strings ?? [];
|
|
906
981
|
for (const s of systems) {
|
|
907
982
|
if (s.kind !== "strings" || JSON.stringify(tuningOf(s.names)) !== same)
|
|
908
983
|
continue;
|
|
@@ -912,7 +987,7 @@ function textTabToAlphaTex(text) {
|
|
|
912
987
|
}
|
|
913
988
|
const typical = typicalWidth(rows);
|
|
914
989
|
const meter = meterOf(rows, typical);
|
|
915
|
-
const bars = measuresOf(rows, typical).map((m) => ({
|
|
990
|
+
const bars = splitUnbarred(measuresOf(rows, typical), meter).map((m) => ({
|
|
916
991
|
beats: m.beats.map((b) => b.notes),
|
|
917
992
|
rhythm: rhythmOf(m, typical ?? 0, meter),
|
|
918
993
|
text: m.text,
|
|
@@ -1355,7 +1430,8 @@ function parseTabSource(language, source) {
|
|
|
1355
1430
|
file: null,
|
|
1356
1431
|
tracks: null,
|
|
1357
1432
|
tex: "",
|
|
1358
|
-
texLine: 0
|
|
1433
|
+
texLine: 0,
|
|
1434
|
+
fromText: false
|
|
1359
1435
|
};
|
|
1360
1436
|
let i = 0;
|
|
1361
1437
|
for (;i < lines.length; i++) {
|
|
@@ -1391,6 +1467,11 @@ function parseTabSource(language, source) {
|
|
|
1391
1467
|
`).trimEnd();
|
|
1392
1468
|
if (!out.file && !out.tex)
|
|
1393
1469
|
throw new Error("Write the music in alphaTex, or give a file: [[Song.gp]]");
|
|
1470
|
+
const converted = out.file ? null : textTabToAlphaTex(out.tex);
|
|
1471
|
+
if (converted !== null) {
|
|
1472
|
+
out.tex = converted;
|
|
1473
|
+
out.fromText = true;
|
|
1474
|
+
}
|
|
1394
1475
|
return out;
|
|
1395
1476
|
}
|
|
1396
1477
|
function messageOf(error, lineOffset) {
|
|
@@ -1401,7 +1482,7 @@ function messageOf(error, lineOffset) {
|
|
|
1401
1482
|
continue;
|
|
1402
1483
|
const first = items.find((d) => d.severity === 2 && d.message);
|
|
1403
1484
|
if (first) {
|
|
1404
|
-
const at = first.start ? `line ${first.start.line + lineOffset}, column ${first.start.col}: ` : "";
|
|
1485
|
+
const at = first.start && lineOffset !== null ? `line ${first.start.line + lineOffset}, column ${first.start.col}: ` : "";
|
|
1405
1486
|
return `${at}${first.message}`;
|
|
1406
1487
|
}
|
|
1407
1488
|
}
|
|
@@ -1787,7 +1868,7 @@ function renderTab(language, source, host, options) {
|
|
|
1787
1868
|
settle({ ok: true, error: null });
|
|
1788
1869
|
});
|
|
1789
1870
|
current.error.on((e) => {
|
|
1790
|
-
const message = messageOf(e, parsed.texLine);
|
|
1871
|
+
const message = parsed.fromText ? `Couldn't draw this text tab: ${messageOf(e, null)}` : messageOf(e, parsed.texLine);
|
|
1791
1872
|
if (settled)
|
|
1792
1873
|
bar?.failed(message);
|
|
1793
1874
|
else
|
|
@@ -1998,5 +2079,5 @@ export {
|
|
|
1998
2079
|
textTabToAlphaTex
|
|
1999
2080
|
};
|
|
2000
2081
|
|
|
2001
|
-
//# debugId=
|
|
2082
|
+
//# debugId=676F0DA21BF6D94464756E2164756E21
|
|
2002
2083
|
//# sourceMappingURL=index.js.map
|