@dsebastien/music-notation 0.23.1 → 0.25.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 +5 -2
- package/dist/chord/simplify.d.ts +56 -0
- package/dist/chords/chart.d.ts +55 -3
- package/dist/chords/chordpro.d.ts +4 -0
- package/dist/chords/easier.d.ts +39 -0
- package/dist/i18n/en/index.d.ts +11 -0
- package/dist/i18n/en/parse.d.ts +2 -0
- package/dist/i18n/en/play.d.ts +9 -0
- package/dist/i18n/fr/parse.d.ts +2 -0
- package/dist/i18n/fr/play.d.ts +9 -0
- package/dist/i18n/language.d.ts +12 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +532 -44
- package/dist/index.js.map +20 -16
- package/dist/music-notation.publish.min.js +37 -37
- package/dist/music-notation.tab.min.js +7 -7
- package/dist/playback/controls.d.ts +17 -0
- package/dist/playback/guitar-tone.d.ts +35 -0
- package/dist/playback/player.d.ts +12 -0
- package/dist/playback/progression-bar.d.ts +6 -1
- package/dist/playback/sound-menu.d.ts +21 -0
- package/dist/publish/index.js +504 -36
- package/dist/publish/index.js.map +19 -15
- package/dist/tab/index.js +104 -17
- package/dist/tab/index.js.map +9 -8
- package/dist/voicings/index.js +23 -1
- package/dist/voicings/index.js.map +6 -6
- package/package.json +2 -2
package/dist/publish/index.js
CHANGED
|
@@ -516,6 +516,7 @@ var enParse = {
|
|
|
516
516
|
"chords.chart.capo": "Capo {capo}",
|
|
517
517
|
"chords.chart.tempo": "{bpm} BPM",
|
|
518
518
|
"chords.chart.transposed": "Transposed {amount}",
|
|
519
|
+
"chords.chart.simplified": "Easier chords",
|
|
519
520
|
"chords.chart.sounds": "{title} (sounds {sounding})",
|
|
520
521
|
"chords.chart.moreNotDrawn": "{count} more chords not drawn (at most {max})",
|
|
521
522
|
"chords.chart.missing": "No diagram for {names}: give the shape with {how}",
|
|
@@ -530,6 +531,7 @@ var enParse = {
|
|
|
530
531
|
"chords.define.fingersCount": "{at}: fingers has {fingers} values for {strings} strings: give one per string (0 for none)",
|
|
531
532
|
"chords.define.reaches": "{at}: the shape reaches fret {top}: frets go up to {max}",
|
|
532
533
|
"chords.directive.diagrams": "{at}: use on, off, top or bottom",
|
|
534
|
+
"chords.directive.simplify": "{at}: use yes or no",
|
|
533
535
|
"chord.shape.open": "Open",
|
|
534
536
|
"chord.shape.caged": "{letter} shape",
|
|
535
537
|
"chord.shape.cagedStrings": "{letter} shape (strings {strings})",
|
|
@@ -569,7 +571,15 @@ var enPlay = {
|
|
|
569
571
|
"playback.click": "Click",
|
|
570
572
|
"playback.sound": "Sound",
|
|
571
573
|
"playback.guitar": "Guitar",
|
|
574
|
+
"playback.guitar.steel": "Guitar (steel)",
|
|
575
|
+
"playback.guitar.nylon": "Guitar (nylon)",
|
|
576
|
+
"playback.guitar.clean": "Guitar (clean)",
|
|
577
|
+
"playback.guitar.overdrive": "Guitar (overdrive)",
|
|
572
578
|
"playback.piano": "Piano",
|
|
579
|
+
"playback.simplify": "Simplify",
|
|
580
|
+
"playback.simplified": "Simplified",
|
|
581
|
+
"playback.simplify.hint": "Show easier chords",
|
|
582
|
+
"playback.simplified.hint": "Show the chords as written",
|
|
573
583
|
"playback.tempo": "Tempo (BPM)",
|
|
574
584
|
"playback.unit.bpm": "BPM",
|
|
575
585
|
"playback.unit.ms": "ms",
|
|
@@ -597,6 +607,7 @@ var enPlay = {
|
|
|
597
607
|
"playback.redraw.guitar": "{name}, drawn for guitar",
|
|
598
608
|
"playback.redraw.piano": "{name}, drawn for piano",
|
|
599
609
|
"playback.engine.invalid": 'engine: use generaluser, sonivox or light, got "{value}"',
|
|
610
|
+
"playback.guitar.invalid": 'guitar: use steel, nylon, clean or overdrive, got "{value}"',
|
|
600
611
|
"tab.source.staves": 'staves: use tab, score or both, got "{value}"',
|
|
601
612
|
"tab.source.layout": 'layout: use page or line, got "{value}"',
|
|
602
613
|
"tab.source.names": 'names: use on or off, got "{value}"',
|
|
@@ -1070,6 +1081,7 @@ var frParse = {
|
|
|
1070
1081
|
"chords.chart.capo": "Capodastre {capo}",
|
|
1071
1082
|
"chords.chart.tempo": "{bpm} BPM",
|
|
1072
1083
|
"chords.chart.transposed": "Transposé de {amount}",
|
|
1084
|
+
"chords.chart.simplified": "Accords simplifiés",
|
|
1073
1085
|
"chords.chart.sounds": "{title} (sonne {sounding})",
|
|
1074
1086
|
"chords.chart.moreNotDrawn": "{count} accords de plus non dessinés (au plus {max})",
|
|
1075
1087
|
"chords.chart.missing": "Pas de diagramme pour {names} : donnez la forme avec {how}",
|
|
@@ -1084,6 +1096,7 @@ var frParse = {
|
|
|
1084
1096
|
"chords.define.fingersCount": "{at} : fingers a {fingers} valeurs pour {strings} cordes : donnez-en une par corde (0 pour aucune)",
|
|
1085
1097
|
"chords.define.reaches": "{at} : la forme atteint la case {top} : les cases vont jusqu'à {max}",
|
|
1086
1098
|
"chords.directive.diagrams": "{at} : utilisez on, off, top ou bottom",
|
|
1099
|
+
"chords.directive.simplify": "{at} : utilisez yes ou no",
|
|
1087
1100
|
"chord.shape.open": "Accord ouvert",
|
|
1088
1101
|
"chord.shape.caged": "forme {letter}",
|
|
1089
1102
|
"chord.shape.cagedStrings": "forme {letter} (cordes {strings})",
|
|
@@ -1123,7 +1136,15 @@ var frPlay = {
|
|
|
1123
1136
|
"playback.click": "Clic",
|
|
1124
1137
|
"playback.sound": "Son",
|
|
1125
1138
|
"playback.guitar": "Guitare",
|
|
1139
|
+
"playback.guitar.steel": "Guitare (folk)",
|
|
1140
|
+
"playback.guitar.nylon": "Guitare (classique)",
|
|
1141
|
+
"playback.guitar.clean": "Guitare (son clair)",
|
|
1142
|
+
"playback.guitar.overdrive": "Guitare (son saturé)",
|
|
1126
1143
|
"playback.piano": "Piano",
|
|
1144
|
+
"playback.simplify": "Simplifier",
|
|
1145
|
+
"playback.simplified": "Simplifié",
|
|
1146
|
+
"playback.simplify.hint": "Afficher des accords plus faciles",
|
|
1147
|
+
"playback.simplified.hint": "Afficher les accords écrits",
|
|
1127
1148
|
"playback.tempo": "Tempo (BPM)",
|
|
1128
1149
|
"playback.unit.bpm": "BPM",
|
|
1129
1150
|
"playback.unit.ms": "ms",
|
|
@@ -1151,6 +1172,7 @@ var frPlay = {
|
|
|
1151
1172
|
"playback.redraw.guitar": "{name}, dessiné pour la guitare",
|
|
1152
1173
|
"playback.redraw.piano": "{name}, dessiné pour le piano",
|
|
1153
1174
|
"playback.engine.invalid": "engine: utilisez generaluser, sonivox ou light, reçu « {value} »",
|
|
1175
|
+
"playback.guitar.invalid": "guitar: utilisez steel, nylon, clean ou overdrive, reçu « {value} »",
|
|
1154
1176
|
"tab.source.staves": "staves: utilisez tab, score ou both, reçu « {value} »",
|
|
1155
1177
|
"tab.source.layout": "layout: utilisez page ou line, reçu « {value} »",
|
|
1156
1178
|
"tab.source.names": "names: utilisez on ou off, reçu « {value} »",
|
|
@@ -3735,6 +3757,17 @@ function parseDirective(line) {
|
|
|
3735
3757
|
return null;
|
|
3736
3758
|
return { name: m[0].toLowerCase(), value: rest.replace(/^\s*:?/, "").trim() };
|
|
3737
3759
|
}
|
|
3760
|
+
var SWITCHES = new Map([
|
|
3761
|
+
["", true],
|
|
3762
|
+
["yes", true],
|
|
3763
|
+
["on", true],
|
|
3764
|
+
["true", true],
|
|
3765
|
+
["1", true],
|
|
3766
|
+
["no", false],
|
|
3767
|
+
["off", false],
|
|
3768
|
+
["false", false],
|
|
3769
|
+
["0", false]
|
|
3770
|
+
]);
|
|
3738
3771
|
function parseChordPro(source) {
|
|
3739
3772
|
const song = {
|
|
3740
3773
|
title: null,
|
|
@@ -3749,6 +3782,8 @@ function parseChordPro(source) {
|
|
|
3749
3782
|
definitions: [],
|
|
3750
3783
|
diagrams: null,
|
|
3751
3784
|
instrument: null,
|
|
3785
|
+
simplify: false,
|
|
3786
|
+
capoAuto: false,
|
|
3752
3787
|
warnings: []
|
|
3753
3788
|
};
|
|
3754
3789
|
let section = { kind: "none", label: null, lines: [] };
|
|
@@ -3777,8 +3812,15 @@ function parseChordPro(source) {
|
|
|
3777
3812
|
} else if (key === "title" || key === "subtitle" || key === "artist" || key === "key" || key === "tempo" || key === "time") {
|
|
3778
3813
|
song[key] = value || null;
|
|
3779
3814
|
} else if (key === "capo") {
|
|
3815
|
+
song.capoAuto = value.trim().toLowerCase() === "auto";
|
|
3780
3816
|
const capo = Number(value);
|
|
3781
3817
|
song.capo = Number.isInteger(capo) && capo > 0 ? capo : null;
|
|
3818
|
+
} else if (key === "simplify") {
|
|
3819
|
+
const wish = SWITCHES.get(value.trim().toLowerCase());
|
|
3820
|
+
if (wish !== undefined)
|
|
3821
|
+
song.simplify = wish;
|
|
3822
|
+
else
|
|
3823
|
+
song.warnings.push(t("chords.directive.simplify", { at: `{simplify: ${value}}` }));
|
|
3782
3824
|
} else if (key === "transpose") {
|
|
3783
3825
|
const semitones = Number(value);
|
|
3784
3826
|
if (Number.isInteger(semitones))
|
|
@@ -5481,6 +5523,62 @@ function strumVoicing(chord, tuning = STANDARD_TUNING, voicings) {
|
|
|
5481
5523
|
return [...pitches];
|
|
5482
5524
|
}
|
|
5483
5525
|
|
|
5526
|
+
// src/playback/guitar-tone.ts
|
|
5527
|
+
var GUITAR_TONES = ["steel", "nylon", "clean", "overdrive"];
|
|
5528
|
+
var DEFAULT_GUITAR_TONE = "steel";
|
|
5529
|
+
var GUITAR_PROGRAMS = {
|
|
5530
|
+
steel: 25,
|
|
5531
|
+
nylon: 24,
|
|
5532
|
+
clean: 27,
|
|
5533
|
+
overdrive: 29
|
|
5534
|
+
};
|
|
5535
|
+
var ALIASES3 = {
|
|
5536
|
+
acoustic: "steel",
|
|
5537
|
+
"steel-string": "steel",
|
|
5538
|
+
classical: "nylon",
|
|
5539
|
+
"nylon-string": "nylon",
|
|
5540
|
+
electric: "clean",
|
|
5541
|
+
overdriven: "overdrive"
|
|
5542
|
+
};
|
|
5543
|
+
function guitarToneOf(value) {
|
|
5544
|
+
if (typeof value !== "string")
|
|
5545
|
+
return null;
|
|
5546
|
+
const name = value.trim().toLowerCase().replace(/\s+/g, "-");
|
|
5547
|
+
return GUITAR_TONES.find((tone) => tone === name) ?? ALIASES3[name] ?? null;
|
|
5548
|
+
}
|
|
5549
|
+
var LINE = /^[ \t]*guitar[ \t]*:[ \t]*(.*?)[ \t]*(?:\r?\n|$)/gim;
|
|
5550
|
+
var DIRECTIVE = /^[ \t]*\{[ \t]*guitar[ \t]*:[ \t]*(.*?)[ \t]*\}[ \t]*(?:\r?\n|$)/gim;
|
|
5551
|
+
function blockGuitar(source, chart = false) {
|
|
5552
|
+
let guitar = null;
|
|
5553
|
+
const rest = source.replace(chart ? DIRECTIVE : LINE, (_line, value) => {
|
|
5554
|
+
const read = guitarToneOf(value);
|
|
5555
|
+
if (!read) {
|
|
5556
|
+
throw new Error(t("playback.guitar.invalid", { value }));
|
|
5557
|
+
}
|
|
5558
|
+
guitar = read;
|
|
5559
|
+
return "";
|
|
5560
|
+
});
|
|
5561
|
+
return { guitar, source: rest };
|
|
5562
|
+
}
|
|
5563
|
+
function guitarWish(el) {
|
|
5564
|
+
return guitarToneOf(el?.closest("[data-mn-guitar]")?.getAttribute("data-mn-guitar"));
|
|
5565
|
+
}
|
|
5566
|
+
var CHOICE = "data-mn-guitar-choice";
|
|
5567
|
+
function guitarChoice(el) {
|
|
5568
|
+
return guitarToneOf(el?.closest(`[${CHOICE}]`)?.getAttribute(CHOICE));
|
|
5569
|
+
}
|
|
5570
|
+
function chooseGuitar(el, guitar) {
|
|
5571
|
+
(el.closest(".mn-block") ?? el).setAttribute(CHOICE, guitar);
|
|
5572
|
+
}
|
|
5573
|
+
function pageGuitar(options) {
|
|
5574
|
+
if (!options || typeof options !== "object" || !("play" in options))
|
|
5575
|
+
return;
|
|
5576
|
+
const play = options.play;
|
|
5577
|
+
if (!play || typeof play !== "object" || !("guitar" in play))
|
|
5578
|
+
return;
|
|
5579
|
+
return guitarToneOf(play.guitar) ?? undefined;
|
|
5580
|
+
}
|
|
5581
|
+
|
|
5484
5582
|
// src/playback/player.ts
|
|
5485
5583
|
var DEFAULT_SEQUENCE = { bpm: 90, strum: 12 };
|
|
5486
5584
|
var DEFAULT_STRUM = { guitar: 12, piano: 0 };
|
|
@@ -5574,8 +5672,21 @@ function pluckedString(midi, sampleRate, seconds, random = Math.random, options
|
|
|
5574
5672
|
out[i] = value * 0.5;
|
|
5575
5673
|
at = next;
|
|
5576
5674
|
}
|
|
5675
|
+
const drive = options.drive !== undefined && Number.isFinite(options.drive) ? Math.max(0, options.drive) : 0;
|
|
5676
|
+
if (drive > 0) {
|
|
5677
|
+
const push = 1 + drive;
|
|
5678
|
+
for (let i = 0;i < out.length; i++)
|
|
5679
|
+
out[i] = Math.tanh(out[i] * 2 * push) * OVERDRIVE_LEVEL;
|
|
5680
|
+
}
|
|
5577
5681
|
return out;
|
|
5578
5682
|
}
|
|
5683
|
+
var OVERDRIVE_LEVEL = 0.18;
|
|
5684
|
+
var TONE_PLUCKS = {
|
|
5685
|
+
steel: { brightness: [0.55, 0.95], pick: [0.08, 0.2], damping: [0.85, 1.15], drive: 0 },
|
|
5686
|
+
nylon: { brightness: [0.05, 0.25], pick: [0.2, 0.34], damping: [2.2, 2.8], drive: 0 },
|
|
5687
|
+
clean: { brightness: [0.7, 1], pick: [0.1, 0.18], damping: [0.55, 0.75], drive: 0 },
|
|
5688
|
+
overdrive: { brightness: [0.7, 1], pick: [0.1, 0.18], damping: [0.45, 0.6], drive: 5 }
|
|
5689
|
+
};
|
|
5579
5690
|
function pianoTone(midi, sampleRate, seconds) {
|
|
5580
5691
|
const out = new Float32Array(Math.round(sampleRate * seconds));
|
|
5581
5692
|
const f = frequency(midi);
|
|
@@ -5661,14 +5772,16 @@ function lightPlayer(win, random = Math.random) {
|
|
|
5661
5772
|
const strings = new Map;
|
|
5662
5773
|
const waves = new WeakMap;
|
|
5663
5774
|
const between = (lo, hi) => lo + (hi - lo) * random();
|
|
5664
|
-
const stringBuffer = (ctx, midi, pluck) => {
|
|
5665
|
-
const key = midi * PLUCKS + pluck
|
|
5775
|
+
const stringBuffer = (ctx, midi, pluck, tone) => {
|
|
5776
|
+
const key = `${tone}:${midi * PLUCKS + pluck}`;
|
|
5666
5777
|
let buffer = strings.get(key);
|
|
5667
5778
|
if (!buffer) {
|
|
5779
|
+
const ranges = TONE_PLUCKS[tone];
|
|
5668
5780
|
const data = pluckedString(midi, ctx.sampleRate, STRING_SECONDS, random, {
|
|
5669
|
-
brightness: between(0
|
|
5670
|
-
pick: between(0
|
|
5671
|
-
damping: between(0
|
|
5781
|
+
brightness: between(ranges.brightness[0], ranges.brightness[1]),
|
|
5782
|
+
pick: between(ranges.pick[0], ranges.pick[1]),
|
|
5783
|
+
damping: between(ranges.damping[0], ranges.damping[1]),
|
|
5784
|
+
...ranges.drive ? { drive: ranges.drive } : {}
|
|
5672
5785
|
});
|
|
5673
5786
|
buffer = ctx.createBuffer(1, data.length, ctx.sampleRate);
|
|
5674
5787
|
buffer.getChannelData(0).set(data);
|
|
@@ -5687,10 +5800,11 @@ function lightPlayer(win, random = Math.random) {
|
|
|
5687
5800
|
};
|
|
5688
5801
|
return {
|
|
5689
5802
|
reportsStart: true,
|
|
5690
|
-
play(events, { sound, volume, onEnd, onStart }) {
|
|
5803
|
+
play(events, { sound, volume, onEnd, onStart, guitar }) {
|
|
5691
5804
|
const ctx = contextFor(win);
|
|
5692
5805
|
if (!ctx || !events.length)
|
|
5693
5806
|
return { stop() {} };
|
|
5807
|
+
const tone = guitar ?? DEFAULT_GUITAR_TONE;
|
|
5694
5808
|
const resumed = ctx.resume();
|
|
5695
5809
|
const touches = events.map(() => ({
|
|
5696
5810
|
pluck: Math.min(PLUCKS - 1, Math.floor(random() * PLUCKS)),
|
|
@@ -5701,9 +5815,9 @@ function lightPlayer(win, random = Math.random) {
|
|
|
5701
5815
|
if (sound === "guitar")
|
|
5702
5816
|
events.forEach((e, i) => {
|
|
5703
5817
|
if (e.kind === "muted")
|
|
5704
|
-
stringBuffer(ctx, e.midi, 0);
|
|
5818
|
+
stringBuffer(ctx, e.midi, 0, tone);
|
|
5705
5819
|
else if (!e.kind)
|
|
5706
|
-
stringBuffer(ctx, e.midi, touches[i].pluck);
|
|
5820
|
+
stringBuffer(ctx, e.midi, touches[i].pluck, tone);
|
|
5707
5821
|
});
|
|
5708
5822
|
const gain = ctx.createGain();
|
|
5709
5823
|
gain.gain.value = Number.isFinite(volume) ? Math.min(1, Math.max(0, volume)) : 0.8;
|
|
@@ -5711,7 +5825,7 @@ function lightPlayer(win, random = Math.random) {
|
|
|
5711
5825
|
const start = ctx.currentTime + 0.05;
|
|
5712
5826
|
const sources = events.map((e, i) => {
|
|
5713
5827
|
if (e.kind)
|
|
5714
|
-
return percussive(ctx, gain, e, start, sound, (c, m) => stringBuffer(c, m, 0));
|
|
5828
|
+
return percussive(ctx, gain, e, start, sound, (c, m) => stringBuffer(c, m, 0, tone));
|
|
5715
5829
|
const touch = touches[i];
|
|
5716
5830
|
const at = start + e.time;
|
|
5717
5831
|
const end = at + e.duration;
|
|
@@ -5722,7 +5836,7 @@ function lightPlayer(win, random = Math.random) {
|
|
|
5722
5836
|
let source;
|
|
5723
5837
|
if (sound === "guitar") {
|
|
5724
5838
|
const buffer = ctx.createBufferSource();
|
|
5725
|
-
buffer.buffer = stringBuffer(ctx, e.midi, touch.pluck);
|
|
5839
|
+
buffer.buffer = stringBuffer(ctx, e.midi, touch.pluck, tone);
|
|
5726
5840
|
buffer.playbackRate.value = Math.pow(2, touch.cents / 1200);
|
|
5727
5841
|
source = buffer;
|
|
5728
5842
|
env.gain.setValueAtTime(level, at);
|
|
@@ -6730,11 +6844,11 @@ function chooseEngine(wish, has) {
|
|
|
6730
6844
|
}
|
|
6731
6845
|
return null;
|
|
6732
6846
|
}
|
|
6733
|
-
var
|
|
6734
|
-
var
|
|
6847
|
+
var LINE2 = /^[ \t]*engine[ \t]*:[ \t]*(.*?)[ \t]*(?:\r?\n|$)/gim;
|
|
6848
|
+
var DIRECTIVE2 = /^[ \t]*\{[ \t]*engine[ \t]*:[ \t]*(.*?)[ \t]*\}[ \t]*(?:\r?\n|$)/gim;
|
|
6735
6849
|
function blockEngine(source, chart = false) {
|
|
6736
6850
|
let engine = null;
|
|
6737
|
-
const rest = source.replace(chart ?
|
|
6851
|
+
const rest = source.replace(chart ? DIRECTIVE2 : LINE2, (_line, value) => {
|
|
6738
6852
|
const read = engineOf(value);
|
|
6739
6853
|
if (!read) {
|
|
6740
6854
|
throw new Error(t("playback.engine.invalid", { value }));
|
|
@@ -6887,6 +7001,44 @@ function volumeOf(volume) {
|
|
|
6887
7001
|
return typeof value === "number" && Number.isFinite(value) ? Math.min(1, Math.max(0, value)) : DEFAULT_VOLUME;
|
|
6888
7002
|
}
|
|
6889
7003
|
|
|
7004
|
+
// src/playback/sound-menu.ts
|
|
7005
|
+
function soundMenu(doc, tr, options, played, sound, set) {
|
|
7006
|
+
const el = html(doc, "select", "mn-play-sound");
|
|
7007
|
+
const label = tr("playback.sound");
|
|
7008
|
+
el.setAttribute("aria-label", label);
|
|
7009
|
+
el.title = label;
|
|
7010
|
+
const names = {
|
|
7011
|
+
steel: tr("playback.guitar.steel"),
|
|
7012
|
+
nylon: tr("playback.guitar.nylon"),
|
|
7013
|
+
clean: tr("playback.guitar.clean"),
|
|
7014
|
+
overdrive: tr("playback.guitar.overdrive"),
|
|
7015
|
+
piano: tr("playback.piano")
|
|
7016
|
+
};
|
|
7017
|
+
for (const value of [...GUITAR_TONES, "piano"]) {
|
|
7018
|
+
const option = html(doc, "option", undefined, names[value]);
|
|
7019
|
+
option.value = value;
|
|
7020
|
+
el.appendChild(option);
|
|
7021
|
+
}
|
|
7022
|
+
const show = () => {
|
|
7023
|
+
el.value = sound() === "piano" ? "piano" : guitarFor(options, played()[0]) ?? DEFAULT_GUITAR_TONE;
|
|
7024
|
+
};
|
|
7025
|
+
el.addEventListener("change", () => {
|
|
7026
|
+
const guitar = GUITAR_TONES.find((tone) => tone === el.value);
|
|
7027
|
+
if (!guitar && el.value !== "piano")
|
|
7028
|
+
return show();
|
|
7029
|
+
if (guitar)
|
|
7030
|
+
for (const element of played())
|
|
7031
|
+
chooseGuitar(element, guitar);
|
|
7032
|
+
const next = guitar ? "guitar" : "piano";
|
|
7033
|
+
if (next !== sound())
|
|
7034
|
+
set(next);
|
|
7035
|
+
});
|
|
7036
|
+
el.addEventListener("pointerdown", show);
|
|
7037
|
+
el.addEventListener("focus", show);
|
|
7038
|
+
show();
|
|
7039
|
+
return { el, show };
|
|
7040
|
+
}
|
|
7041
|
+
|
|
6890
7042
|
// src/playback/app-bar.ts
|
|
6891
7043
|
var NONE = { tempoChanged() {}, free() {} };
|
|
6892
7044
|
function handToApp(options, bar, info) {
|
|
@@ -7882,7 +8034,7 @@ function barPlayer(wrap, win, options) {
|
|
|
7882
8034
|
try {
|
|
7883
8035
|
return chosen.play(events, given);
|
|
7884
8036
|
} catch {
|
|
7885
|
-
return lightFor(here).play(events, opts);
|
|
8037
|
+
return toned(lightFor(here), options, wrap).play(events, opts);
|
|
7886
8038
|
}
|
|
7887
8039
|
}
|
|
7888
8040
|
};
|
|
@@ -7973,7 +8125,7 @@ function timedBarFor(doc, win, drawing, options, piece) {
|
|
|
7973
8125
|
settings.bpm = tempoOf(n);
|
|
7974
8126
|
app.tempoChanged(settings.bpm);
|
|
7975
8127
|
}, compound ? tr("playback.dotted") : undefined).field);
|
|
7976
|
-
bar.appendChild(
|
|
8128
|
+
bar.appendChild(soundMenu(doc, tr, options, () => [wrap], () => settings.sound, (value) => settings.sound = value).el);
|
|
7977
8129
|
if (options.copy !== false)
|
|
7978
8130
|
bar.append(...copyImageButton(doc, win, () => wrap.closest(".mn-block") ?? wrap));
|
|
7979
8131
|
const freeFull = addFullScreen(doc, bar, wrap.closest(".mn-block"), options.fullScreen);
|
|
@@ -8041,11 +8193,12 @@ var strumLabels = (tr) => ({
|
|
|
8041
8193
|
arpeggio: tr("playback.strum.arpeggio"),
|
|
8042
8194
|
pattern: tr("playback.strum.pattern")
|
|
8043
8195
|
});
|
|
8044
|
-
function progressionBarFor(doc, win, drawing, options, diagrams = null) {
|
|
8045
|
-
|
|
8196
|
+
function progressionBarFor(doc, win, drawing, options, diagrams = null, regroup) {
|
|
8197
|
+
let { bars, marks } = barsFromDrawing(drawing);
|
|
8046
8198
|
if (!bars.length)
|
|
8047
8199
|
return () => {};
|
|
8048
8200
|
const tr = translator();
|
|
8201
|
+
const language = currentLanguage();
|
|
8049
8202
|
const time = drawing.getAttribute("data-mn-time");
|
|
8050
8203
|
let beatsPerBar = 4;
|
|
8051
8204
|
let beatUnit = 4;
|
|
@@ -8083,14 +8236,17 @@ function progressionBarFor(doc, win, drawing, options, diagrams = null) {
|
|
|
8083
8236
|
playing = null;
|
|
8084
8237
|
show();
|
|
8085
8238
|
};
|
|
8086
|
-
|
|
8239
|
+
const wire = () => {
|
|
8240
|
+
if (!diagrams)
|
|
8241
|
+
return;
|
|
8087
8242
|
diagrams.onPlay = stop;
|
|
8088
8243
|
diagrams.stopOthers = () => {
|
|
8089
8244
|
const was = playing !== null;
|
|
8090
8245
|
stop();
|
|
8091
8246
|
return was;
|
|
8092
8247
|
};
|
|
8093
|
-
}
|
|
8248
|
+
};
|
|
8249
|
+
wire();
|
|
8094
8250
|
const start = () => {
|
|
8095
8251
|
stop();
|
|
8096
8252
|
if (!drawing.isConnected)
|
|
@@ -8131,10 +8287,49 @@ function progressionBarFor(doc, win, drawing, options, diagrams = null) {
|
|
|
8131
8287
|
if (playing)
|
|
8132
8288
|
start();
|
|
8133
8289
|
}));
|
|
8134
|
-
bar.appendChild(
|
|
8135
|
-
settings.sound = value
|
|
8290
|
+
bar.appendChild(soundMenu(doc, tr, options, () => [drawing], () => settings.sound, (value) => {
|
|
8291
|
+
settings.sound = value;
|
|
8136
8292
|
diagrams?.setSound(settings.sound);
|
|
8137
|
-
}));
|
|
8293
|
+
}).el);
|
|
8294
|
+
const redraw = chartRedrawOf(drawing);
|
|
8295
|
+
if (redraw) {
|
|
8296
|
+
const simplify = html(doc, "button", "mn-play-simplify");
|
|
8297
|
+
simplify.type = "button";
|
|
8298
|
+
const shown = () => {
|
|
8299
|
+
const on = drawing.hasAttribute("data-mn-simplified");
|
|
8300
|
+
simplify.textContent = tr(on ? "playback.simplified" : "playback.simplify");
|
|
8301
|
+
simplify.title = tr(on ? "playback.simplified.hint" : "playback.simplify.hint");
|
|
8302
|
+
simplify.setAttribute("aria-pressed", String(on));
|
|
8303
|
+
simplify.classList.toggle("mn-on", on);
|
|
8304
|
+
};
|
|
8305
|
+
simplify.addEventListener("click", () => {
|
|
8306
|
+
stop();
|
|
8307
|
+
diagrams?.stop();
|
|
8308
|
+
const on = !drawing.hasAttribute("data-mn-simplified");
|
|
8309
|
+
const naming = namingOf(drawing.closest("[data-mn-naming]")?.getAttribute("data-mn-naming"));
|
|
8310
|
+
let next;
|
|
8311
|
+
try {
|
|
8312
|
+
next = withLanguage(language, () => naming ? withNaming(naming, () => redraw(on)) : redraw(on));
|
|
8313
|
+
} catch {
|
|
8314
|
+
return;
|
|
8315
|
+
}
|
|
8316
|
+
for (const child of [...drawing.children])
|
|
8317
|
+
if (child !== bar)
|
|
8318
|
+
child.remove();
|
|
8319
|
+
bar.before(...next.children);
|
|
8320
|
+
drawing.toggleAttribute("data-mn-simplified", next.hasAttribute("data-mn-simplified"));
|
|
8321
|
+
({ bars, marks } = barsFromDrawing(drawing));
|
|
8322
|
+
if (regroup) {
|
|
8323
|
+
diagrams = regroup();
|
|
8324
|
+
wire();
|
|
8325
|
+
if (settings.sound !== (piano ? "piano" : "guitar"))
|
|
8326
|
+
diagrams?.setSound(settings.sound);
|
|
8327
|
+
}
|
|
8328
|
+
shown();
|
|
8329
|
+
});
|
|
8330
|
+
shown();
|
|
8331
|
+
bar.appendChild(simplify);
|
|
8332
|
+
}
|
|
8138
8333
|
if (options.copy !== false)
|
|
8139
8334
|
bar.append(...copyImageButton(doc, win, () => drawing.closest(".mn-block") ?? drawing));
|
|
8140
8335
|
const freeFull = addFullScreen(doc, bar, drawing.closest(".mn-block"), options.fullScreen);
|
|
@@ -8162,7 +8357,7 @@ var PICKING_PATTERNS = {
|
|
|
8162
8357
|
"alternate bass": { name: "Alternate bass", slots: "p i m i p' i m i" },
|
|
8163
8358
|
"1-2-3-4": { name: "1-2-3-4", slots: "p i m a p i m a" }
|
|
8164
8359
|
};
|
|
8165
|
-
var
|
|
8360
|
+
var ALIASES4 = {
|
|
8166
8361
|
"travis picking": "travis",
|
|
8167
8362
|
"alternating bass": "alternate bass",
|
|
8168
8363
|
"alternate-bass": "alternate bass",
|
|
@@ -8172,7 +8367,7 @@ var ALIASES3 = {
|
|
|
8172
8367
|
};
|
|
8173
8368
|
function namedPicking(text) {
|
|
8174
8369
|
const t = text.trim().toLowerCase().replace(/\s+/g, " ");
|
|
8175
|
-
const key =
|
|
8370
|
+
const key = ALIASES4[t] ?? t;
|
|
8176
8371
|
return PICKING_PATTERNS[key] ? key : null;
|
|
8177
8372
|
}
|
|
8178
8373
|
var KEYS2 = [
|
|
@@ -8817,7 +9012,7 @@ function diagramGroup(doc, win, diagrams, options, how) {
|
|
|
8817
9012
|
try {
|
|
8818
9013
|
return run(playerFor(here, options, item.wrap));
|
|
8819
9014
|
} catch {
|
|
8820
|
-
return run(lightFor(here));
|
|
9015
|
+
return run(toned(lightFor(here), options, item.wrap));
|
|
8821
9016
|
}
|
|
8822
9017
|
};
|
|
8823
9018
|
const select = (item) => {
|
|
@@ -9047,8 +9242,8 @@ function blockBarFor(doc, win, block, diagrams, options) {
|
|
|
9047
9242
|
bar.appendChild(tempo.field);
|
|
9048
9243
|
if (strum)
|
|
9049
9244
|
bar.appendChild(strum.field);
|
|
9050
|
-
const sound =
|
|
9051
|
-
bar.appendChild(sound);
|
|
9245
|
+
const sound = soundMenu(doc, tr, options, () => items.map((item) => item.wrap), () => made.sound, (value) => group.setSound(value));
|
|
9246
|
+
bar.appendChild(sound.el);
|
|
9052
9247
|
if (options.copy !== false)
|
|
9053
9248
|
bar.append(...copyImageButton(doc, win, (whole) => whole || !several ? block : diagramImage(made.selected.wrap)));
|
|
9054
9249
|
const freeFull = addFullScreen(doc, bar, block, options.fullScreen);
|
|
@@ -9069,7 +9264,7 @@ function blockBarFor(doc, win, block, diagrams, options) {
|
|
|
9069
9264
|
strum.field.hidden = !(several && item.data.kind === "chord");
|
|
9070
9265
|
strum.show(made.strumOf(made.sound));
|
|
9071
9266
|
}
|
|
9072
|
-
sound.
|
|
9267
|
+
sound.show();
|
|
9073
9268
|
}
|
|
9074
9269
|
});
|
|
9075
9270
|
return () => {
|
|
@@ -9097,6 +9292,42 @@ function lightFor(win) {
|
|
|
9097
9292
|
return player;
|
|
9098
9293
|
}
|
|
9099
9294
|
function playerFor(win, options, el) {
|
|
9295
|
+
return toned(enginePlayerFor(win, options, el), options, el);
|
|
9296
|
+
}
|
|
9297
|
+
function toned(player, options, el) {
|
|
9298
|
+
const tone = guitarFor(options, el);
|
|
9299
|
+
return tone ? withGuitar(player, tone) : player;
|
|
9300
|
+
}
|
|
9301
|
+
function guitarFor(options, el) {
|
|
9302
|
+
const wish = guitarChoice(el) ?? guitarWish(el);
|
|
9303
|
+
if (wish)
|
|
9304
|
+
return wish;
|
|
9305
|
+
try {
|
|
9306
|
+
return guitarToneOf(typeof options.guitar === "function" ? options.guitar() : options.guitar);
|
|
9307
|
+
} catch {
|
|
9308
|
+
return null;
|
|
9309
|
+
}
|
|
9310
|
+
}
|
|
9311
|
+
var guitarPlayers = new WeakMap;
|
|
9312
|
+
function withGuitar(player, guitar) {
|
|
9313
|
+
let twins = guitarPlayers.get(player);
|
|
9314
|
+
if (!twins) {
|
|
9315
|
+
twins = new Map;
|
|
9316
|
+
guitarPlayers.set(player, twins);
|
|
9317
|
+
}
|
|
9318
|
+
let twin = twins.get(guitar);
|
|
9319
|
+
if (!twin) {
|
|
9320
|
+
twin = {
|
|
9321
|
+
get reportsStart() {
|
|
9322
|
+
return player.reportsStart;
|
|
9323
|
+
},
|
|
9324
|
+
play: (events, options) => player.play(events, options.guitar ? options : { ...options, guitar })
|
|
9325
|
+
};
|
|
9326
|
+
twins.set(guitar, twin);
|
|
9327
|
+
}
|
|
9328
|
+
return twin;
|
|
9329
|
+
}
|
|
9330
|
+
function enginePlayerFor(win, options, el) {
|
|
9100
9331
|
const engines = options.engines;
|
|
9101
9332
|
if (engines) {
|
|
9102
9333
|
const chosen = chooseEngine(engineWish(el) ?? engineOf(options.engine), (engine) => {
|
|
@@ -9271,9 +9502,17 @@ function attachPlaybackIn(el, options) {
|
|
|
9271
9502
|
for (const [block, diagrams] of byBlock)
|
|
9272
9503
|
stops.push(blockBarFor(doc, win, block, diagrams, options));
|
|
9273
9504
|
for (const drawing of timed) {
|
|
9274
|
-
const
|
|
9275
|
-
|
|
9276
|
-
const
|
|
9505
|
+
const groupOf = (diagrams) => diagrams?.length ? diagramGroup(doc, win, diagrams, options, { bar: false }).group : null;
|
|
9506
|
+
let group = groupOf(byDrawing.get(drawing));
|
|
9507
|
+
const regroup = () => {
|
|
9508
|
+
group?.destroy();
|
|
9509
|
+
group = groupOf([...drawing.querySelectorAll("svg[data-mn-pitches]")].flatMap((diagram) => {
|
|
9510
|
+
const data = diagram.hasAttribute("data-mn-pick") ? null : dataOf(diagram);
|
|
9511
|
+
return data ? [{ diagram, data }] : [];
|
|
9512
|
+
}));
|
|
9513
|
+
return group;
|
|
9514
|
+
};
|
|
9515
|
+
const bar = progressionBarFor(doc, win, drawing, options, group, regroup);
|
|
9277
9516
|
stops.push(() => {
|
|
9278
9517
|
bar();
|
|
9279
9518
|
group?.destroy();
|
|
@@ -10070,6 +10309,186 @@ function renderChordsUsed(doc, song, options) {
|
|
|
10070
10309
|
return root;
|
|
10071
10310
|
}
|
|
10072
10311
|
|
|
10312
|
+
// src/chord/simplify.ts
|
|
10313
|
+
var easiest = new Map;
|
|
10314
|
+
var KEPT = 512;
|
|
10315
|
+
function easiestOf(symbol, options) {
|
|
10316
|
+
const key = `${options.tuning?.join(",") ?? ""}|${symbol}`;
|
|
10317
|
+
const known = easiest.get(key);
|
|
10318
|
+
if (known !== undefined)
|
|
10319
|
+
return known;
|
|
10320
|
+
const generation = options.tuning ? { tuning: options.tuning } : {};
|
|
10321
|
+
const first = generateVoicings(symbol, generation)[0];
|
|
10322
|
+
const found = first ? { frets: [...first.frets], difficulty: first.difficulty, open: first.shape === "Open" } : null;
|
|
10323
|
+
if (easiest.size >= KEPT)
|
|
10324
|
+
easiest.delete(easiest.keys().next().value);
|
|
10325
|
+
easiest.set(key, found);
|
|
10326
|
+
return found;
|
|
10327
|
+
}
|
|
10328
|
+
function plainerSuffixes(symbol) {
|
|
10329
|
+
const info = chordInfo(symbol);
|
|
10330
|
+
if (!info)
|
|
10331
|
+
return [];
|
|
10332
|
+
const has = (interval) => info.members.some((m) => m.interval === interval);
|
|
10333
|
+
const third = has("3M") ? "major" : has("3m") ? "minor" : null;
|
|
10334
|
+
const diminished = third === "minor" && has("5d");
|
|
10335
|
+
const pick = (...found) => found.find(([i]) => has(i))?.[1] ?? null;
|
|
10336
|
+
const seventh = third !== "minor" ? pick(["7M", "maj7"], ["7m", "7"]) : diminished ? pick(["7d", "dim7"], ["7m", "m7b5"]) : pick(["7m", "m7"]);
|
|
10337
|
+
const steps = [];
|
|
10338
|
+
if (seventh)
|
|
10339
|
+
steps.push(seventh);
|
|
10340
|
+
if (seventh === "m7b5")
|
|
10341
|
+
steps.push("m7");
|
|
10342
|
+
if (seventh === "dim7")
|
|
10343
|
+
steps.push("dim");
|
|
10344
|
+
else if (!(diminished && !seventh))
|
|
10345
|
+
steps.push(third === "minor" ? "m" : "");
|
|
10346
|
+
return steps.filter((suffix, i) => suffix !== info.suffix && steps.indexOf(suffix) === i);
|
|
10347
|
+
}
|
|
10348
|
+
function plainerChords(symbol) {
|
|
10349
|
+
const parts = splitChordSymbol(symbol);
|
|
10350
|
+
if (!parts)
|
|
10351
|
+
return [];
|
|
10352
|
+
const own = `${parts.root}${canonicalSuffix(parts.suffix)}`;
|
|
10353
|
+
const bass = parts.bass ? `/${parts.bass}` : "";
|
|
10354
|
+
const found = bass ? [`${parts.root}${parts.suffix}`] : [];
|
|
10355
|
+
for (const suffix of plainerSuffixes(symbol)) {
|
|
10356
|
+
if (bass)
|
|
10357
|
+
found.push(`${parts.root}${suffix}${bass}`);
|
|
10358
|
+
found.push(`${parts.root}${suffix}`);
|
|
10359
|
+
}
|
|
10360
|
+
return found.filter((chord, i) => chord !== own + bass && found.indexOf(chord) === i);
|
|
10361
|
+
}
|
|
10362
|
+
function simplifyChord(symbol, options = {}) {
|
|
10363
|
+
const own = easiestOf(symbol.trim(), options);
|
|
10364
|
+
const limit = own ? own.difficulty : Infinity;
|
|
10365
|
+
return plainerChords(symbol.trim()).map((chord, order) => ({ chord, order, voicing: easiestOf(chord, options) })).filter((c) => c.voicing !== null && c.voicing.difficulty < limit).sort((a, b) => a.voicing.difficulty - b.voicing.difficulty || a.order - b.order).map((c) => ({
|
|
10366
|
+
symbol: c.chord,
|
|
10367
|
+
frets: [...c.voicing.frets],
|
|
10368
|
+
difficulty: c.voicing.difficulty
|
|
10369
|
+
}));
|
|
10370
|
+
}
|
|
10371
|
+
function easierChord(symbol, options = {}) {
|
|
10372
|
+
return simplifyChord(symbol, options)[0]?.symbol ?? symbol.trim();
|
|
10373
|
+
}
|
|
10374
|
+
var UNPLAYABLE = 12;
|
|
10375
|
+
var CAPO_COST = 0.5;
|
|
10376
|
+
function shapeName(chord, capo) {
|
|
10377
|
+
if (!capo)
|
|
10378
|
+
return chord;
|
|
10379
|
+
const flat = transposeChord(chord, -capo, true);
|
|
10380
|
+
const sharp = transposeChord(chord, -capo, false);
|
|
10381
|
+
if (flat === sharp)
|
|
10382
|
+
return flat;
|
|
10383
|
+
return /^[A-G]b/.test(chord) ? flat : sharp;
|
|
10384
|
+
}
|
|
10385
|
+
function capoChoices(chords, options = {}) {
|
|
10386
|
+
const distinct = [...new Set(chords.map((c) => c.trim()))].filter((c) => chordInfo(c) !== null);
|
|
10387
|
+
if (!distinct.length)
|
|
10388
|
+
return [];
|
|
10389
|
+
const max = Math.min(12, Math.max(0, Math.round(options.maxCapo ?? 7) || 0));
|
|
10390
|
+
const choices = [];
|
|
10391
|
+
for (let capo = 0;capo <= max; capo++) {
|
|
10392
|
+
const shapes = distinct.map((chord) => {
|
|
10393
|
+
const shape = shapeName(chord, capo);
|
|
10394
|
+
const voicing = easiestOf(shape, options);
|
|
10395
|
+
return {
|
|
10396
|
+
chord,
|
|
10397
|
+
shape,
|
|
10398
|
+
frets: voicing ? [...voicing.frets] : null,
|
|
10399
|
+
open: voicing?.open ?? false,
|
|
10400
|
+
difficulty: voicing?.difficulty ?? UNPLAYABLE
|
|
10401
|
+
};
|
|
10402
|
+
});
|
|
10403
|
+
choices.push({
|
|
10404
|
+
capo,
|
|
10405
|
+
shapes,
|
|
10406
|
+
open: shapes.filter((s) => s.open).length,
|
|
10407
|
+
difficulty: shapes.reduce((sum, s) => sum + s.difficulty, 0)
|
|
10408
|
+
});
|
|
10409
|
+
}
|
|
10410
|
+
const effort = (c) => c.difficulty + CAPO_COST * c.capo;
|
|
10411
|
+
return choices.sort((a, b) => b.open - a.open || effort(a) - effort(b) || a.capo - b.capo);
|
|
10412
|
+
}
|
|
10413
|
+
function bestCapo(chords, options = {}) {
|
|
10414
|
+
return capoChoices(chords, options)[0] ?? null;
|
|
10415
|
+
}
|
|
10416
|
+
|
|
10417
|
+
// src/chords/easier.ts
|
|
10418
|
+
function withSuffixOf(written, easier) {
|
|
10419
|
+
const own = splitChordSymbol(written);
|
|
10420
|
+
const other = splitChordSymbol(easier);
|
|
10421
|
+
if (!own || !other)
|
|
10422
|
+
return written;
|
|
10423
|
+
return `${own.root}${other.suffix}${other.bass && own.bass ? `/${own.bass}` : ""}`;
|
|
10424
|
+
}
|
|
10425
|
+
function easierSong(song, shownOf, semitones, options) {
|
|
10426
|
+
const same = { song, easier: [], canSimplify: false, capo: null, choice: null };
|
|
10427
|
+
if (!options.guitar)
|
|
10428
|
+
return same;
|
|
10429
|
+
const names = chordsUsed(song);
|
|
10430
|
+
const found = names.filter((written) => !findDefinition(song.definitions, written)).map((written) => {
|
|
10431
|
+
const from = shownOf(written).trim();
|
|
10432
|
+
return { written, from, to: easierChord(from) };
|
|
10433
|
+
}).filter((c) => c.to !== c.from);
|
|
10434
|
+
const canSimplify = found.length > 0;
|
|
10435
|
+
const simpler = new Map;
|
|
10436
|
+
if (options.simplify)
|
|
10437
|
+
for (const c of found)
|
|
10438
|
+
simpler.set(c.written, withSuffixOf(c.written, c.to));
|
|
10439
|
+
const easier = options.simplify ? found.map(({ from, to }) => ({ from, to })) : [];
|
|
10440
|
+
const simplified = (name) => simpler.get(name.trim()) ?? name;
|
|
10441
|
+
const copy = (rename) => song.sections.map((section) => ({
|
|
10442
|
+
...section,
|
|
10443
|
+
lines: section.lines.map((l) => {
|
|
10444
|
+
if (l.kind === "lyrics")
|
|
10445
|
+
return {
|
|
10446
|
+
kind: "lyrics",
|
|
10447
|
+
segments: l.segments.map((s) => s.chord === null ? s : { ...s, chord: rename(s.chord, true) })
|
|
10448
|
+
};
|
|
10449
|
+
const d = l.kind === "chord" ? l.definition : null;
|
|
10450
|
+
if (d && !d.frets && !d.keys && !d.copy)
|
|
10451
|
+
return {
|
|
10452
|
+
kind: "chord",
|
|
10453
|
+
definition: { ...d, name: rename(d.name, d.transposable) }
|
|
10454
|
+
};
|
|
10455
|
+
return l;
|
|
10456
|
+
})
|
|
10457
|
+
}));
|
|
10458
|
+
const best = song.capoAuto ? bestCapo(names.map((written) => shownOf(simplified(written)).trim())) : null;
|
|
10459
|
+
if (!best || best.capo === 0) {
|
|
10460
|
+
if (!simpler.size)
|
|
10461
|
+
return { ...same, canSimplify, choice: best };
|
|
10462
|
+
return {
|
|
10463
|
+
song: { ...song, sections: copy(simplified) },
|
|
10464
|
+
easier,
|
|
10465
|
+
canSimplify,
|
|
10466
|
+
capo: null,
|
|
10467
|
+
choice: best
|
|
10468
|
+
};
|
|
10469
|
+
}
|
|
10470
|
+
const shapes = new Map(best.shapes.map((s) => [s.chord, s.shape]));
|
|
10471
|
+
const shape = (name, transposable) => {
|
|
10472
|
+
if (!/^[A-G]/.test(name.trim()))
|
|
10473
|
+
return name;
|
|
10474
|
+
const sounding = transposable ? shownOf(simplified(name)).trim() : simplified(name).trim();
|
|
10475
|
+
return shapes.get(sounding) ?? transposeChord(sounding, -best.capo);
|
|
10476
|
+
};
|
|
10477
|
+
return {
|
|
10478
|
+
song: {
|
|
10479
|
+
...song,
|
|
10480
|
+
capo: best.capo,
|
|
10481
|
+
transpose: song.transpose - semitones,
|
|
10482
|
+
key: song.key ? transposeKey(song.key, semitones) : null,
|
|
10483
|
+
sections: copy(shape)
|
|
10484
|
+
},
|
|
10485
|
+
easier,
|
|
10486
|
+
canSimplify,
|
|
10487
|
+
capo: best.capo,
|
|
10488
|
+
choice: best
|
|
10489
|
+
};
|
|
10490
|
+
}
|
|
10491
|
+
|
|
10073
10492
|
// src/chords/chart.ts
|
|
10074
10493
|
var PLACEMENTS = new Set(["top", "bottom", "off"]);
|
|
10075
10494
|
function lineBeats(segments, playable, beatsPerBar, perPulse) {
|
|
@@ -10168,6 +10587,36 @@ function transposerOf(song, extra) {
|
|
|
10168
10587
|
chord: (symbol) => transposeChord(symbol, semitones, spelling)
|
|
10169
10588
|
};
|
|
10170
10589
|
}
|
|
10590
|
+
function easierPlan(song, options, guitar) {
|
|
10591
|
+
const written = transposerOf(song, options.transpose);
|
|
10592
|
+
return easierSong(song, written.chord, written.semitones, {
|
|
10593
|
+
simplify: options.simplify ?? song.simplify ?? false,
|
|
10594
|
+
guitar
|
|
10595
|
+
});
|
|
10596
|
+
}
|
|
10597
|
+
function easierChart(given, options = {}) {
|
|
10598
|
+
const instrument = given.instrument ?? (options.instrument === "piano" ? "piano" : "guitar");
|
|
10599
|
+
const asked = { ...given, capoAuto: options.capo ?? given.capoAuto ?? false };
|
|
10600
|
+
const plan = easierPlan(asked, options, instrument === "guitar");
|
|
10601
|
+
const renames = new Map;
|
|
10602
|
+
asked.sections.forEach((section, i) => section.lines.forEach((line, j) => {
|
|
10603
|
+
const other = plan.song.sections[i]?.lines[j];
|
|
10604
|
+
if (line.kind !== "lyrics" || other?.kind !== "lyrics")
|
|
10605
|
+
return;
|
|
10606
|
+
line.segments.forEach((segment, k) => {
|
|
10607
|
+
const now = other.segments[k]?.chord;
|
|
10608
|
+
if (segment.chord !== null && now != null && now !== segment.chord)
|
|
10609
|
+
renames.set(segment.chord, now);
|
|
10610
|
+
});
|
|
10611
|
+
}));
|
|
10612
|
+
return {
|
|
10613
|
+
easier: plan.easier,
|
|
10614
|
+
capo: plan.choice,
|
|
10615
|
+
renames,
|
|
10616
|
+
transpose: plan.song.transpose,
|
|
10617
|
+
key: plan.song.key
|
|
10618
|
+
};
|
|
10619
|
+
}
|
|
10171
10620
|
function meterOf(song) {
|
|
10172
10621
|
let beatsPerBar = 4;
|
|
10173
10622
|
let beatUnit = 4;
|
|
@@ -10176,7 +10625,9 @@ function meterOf(song) {
|
|
|
10176
10625
|
({ beatsPerBar, beatUnit } = parseTime(time));
|
|
10177
10626
|
return { beatsPerBar, beatUnit, perPulse: isCompound(beatsPerBar, beatUnit) ? 3 : 1 };
|
|
10178
10627
|
}
|
|
10179
|
-
function chartChords(
|
|
10628
|
+
function chartChords(given, options = {}) {
|
|
10629
|
+
const instrument = given.instrument ?? (options.instrument === "piano" ? "piano" : "guitar");
|
|
10630
|
+
const { song } = easierPlan(given, options, instrument === "guitar");
|
|
10180
10631
|
const { chord } = transposerOf(song, options.transpose);
|
|
10181
10632
|
const { beatsPerBar, beatUnit, perPulse } = meterOf(song);
|
|
10182
10633
|
const playable = (written) => {
|
|
@@ -10220,11 +10671,19 @@ function chartChords(song, options = {}) {
|
|
|
10220
10671
|
tempo: song.tempo && Number.isFinite(tempo) && tempo >= 20 && tempo <= 240 ? tempo : null
|
|
10221
10672
|
};
|
|
10222
10673
|
}
|
|
10223
|
-
|
|
10674
|
+
var redraws = new WeakMap;
|
|
10675
|
+
function chartRedrawOf(chart) {
|
|
10676
|
+
return redraws.get(chart) ?? null;
|
|
10677
|
+
}
|
|
10678
|
+
function renderChart(doc, given, options = {}) {
|
|
10679
|
+
const instrument = given.instrument ?? (options.instrument === "piano" ? "piano" : "guitar");
|
|
10680
|
+
const plan = easierPlan(given, options, instrument === "guitar");
|
|
10681
|
+
const song = plan.song;
|
|
10224
10682
|
const { semitones, key, spelling, chord } = transposerOf(song, options.transpose);
|
|
10683
|
+
const transposed = transposerOf(given, options.transpose).semitones;
|
|
10225
10684
|
const meter = meterOf(song);
|
|
10226
10685
|
const drawing = {
|
|
10227
|
-
instrument
|
|
10686
|
+
instrument,
|
|
10228
10687
|
...options.voicings ? { voicings: options.voicings } : {},
|
|
10229
10688
|
...options.orientation ? { orientation: options.orientation } : {},
|
|
10230
10689
|
...options.hand ? { hand: options.hand } : {}
|
|
@@ -10237,6 +10696,10 @@ function renderChart(doc, song, options = {}) {
|
|
|
10237
10696
|
...spelling === undefined ? {} : { spelling }
|
|
10238
10697
|
});
|
|
10239
10698
|
const root = html(doc, "div", "mn-chart");
|
|
10699
|
+
if (plan.easier.length)
|
|
10700
|
+
root.setAttribute("data-mn-simplified", "");
|
|
10701
|
+
if (plan.canSimplify)
|
|
10702
|
+
redraws.set(root, (simplify) => renderChart(doc, given, { ...options, simplify }));
|
|
10240
10703
|
root.setAttribute("data-mn-progression-play", "");
|
|
10241
10704
|
root.setAttribute("data-mn-sound", drawing.instrument === "piano" ? "piano" : "guitar");
|
|
10242
10705
|
const time = timeOf(song.time);
|
|
@@ -10290,7 +10753,8 @@ function renderChart(doc, song, options = {}) {
|
|
|
10290
10753
|
song.capo ? t("chords.chart.capo", { capo: song.capo }) : null,
|
|
10291
10754
|
song.tempo ? t("chords.chart.tempo", { bpm: song.tempo }) : null,
|
|
10292
10755
|
song.time ? song.time : null,
|
|
10293
|
-
|
|
10756
|
+
transposed % 12 ? t("chords.chart.transposed", { amount: `${transposed > 0 ? "+" : ""}${transposed}` }) : null,
|
|
10757
|
+
plan.easier.length ? t("chords.chart.simplified") : null
|
|
10294
10758
|
].filter((m) => m !== null);
|
|
10295
10759
|
if (meta.length)
|
|
10296
10760
|
root.appendChild(html(doc, "div", "mn-chart-meta", meta.join(" · ")));
|
|
@@ -14198,6 +14662,10 @@ function drawBlock(language, source, host, given) {
|
|
|
14198
14662
|
text = wish.source;
|
|
14199
14663
|
if (wish.engine)
|
|
14200
14664
|
el.setAttribute("data-mn-engine", wish.engine);
|
|
14665
|
+
const tone = blockGuitar(text, language === "chords");
|
|
14666
|
+
text = tone.source;
|
|
14667
|
+
if (tone.guitar)
|
|
14668
|
+
el.setAttribute("data-mn-guitar", tone.guitar);
|
|
14201
14669
|
} catch (e) {
|
|
14202
14670
|
return failed(el, host, language, messageOf(e));
|
|
14203
14671
|
}
|
|
@@ -15137,5 +15605,5 @@ export {
|
|
|
15137
15605
|
renderAll
|
|
15138
15606
|
};
|
|
15139
15607
|
|
|
15140
|
-
//# debugId=
|
|
15608
|
+
//# debugId=054081EECF4A18AD64756E2164756E21
|
|
15141
15609
|
//# sourceMappingURL=index.js.map
|