@dsebastien/music-notation 0.24.0 → 0.26.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/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",
@@ -1071,6 +1081,7 @@ var frParse = {
1071
1081
  "chords.chart.capo": "Capodastre {capo}",
1072
1082
  "chords.chart.tempo": "{bpm} BPM",
1073
1083
  "chords.chart.transposed": "Transposé de {amount}",
1084
+ "chords.chart.simplified": "Accords simplifiés",
1074
1085
  "chords.chart.sounds": "{title} (sonne {sounding})",
1075
1086
  "chords.chart.moreNotDrawn": "{count} accords de plus non dessinés (au plus {max})",
1076
1087
  "chords.chart.missing": "Pas de diagramme pour {names} : donnez la forme avec {how}",
@@ -1085,6 +1096,7 @@ var frParse = {
1085
1096
  "chords.define.fingersCount": "{at} : fingers a {fingers} valeurs pour {strings} cordes : donnez-en une par corde (0 pour aucune)",
1086
1097
  "chords.define.reaches": "{at} : la forme atteint la case {top} : les cases vont jusqu'à {max}",
1087
1098
  "chords.directive.diagrams": "{at} : utilisez on, off, top ou bottom",
1099
+ "chords.directive.simplify": "{at} : utilisez yes ou no",
1088
1100
  "chord.shape.open": "Accord ouvert",
1089
1101
  "chord.shape.caged": "forme {letter}",
1090
1102
  "chord.shape.cagedStrings": "forme {letter} (cordes {strings})",
@@ -1124,7 +1136,15 @@ var frPlay = {
1124
1136
  "playback.click": "Clic",
1125
1137
  "playback.sound": "Son",
1126
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é)",
1127
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",
1128
1148
  "playback.tempo": "Tempo (BPM)",
1129
1149
  "playback.unit.bpm": "BPM",
1130
1150
  "playback.unit.ms": "ms",
@@ -3737,6 +3757,17 @@ function parseDirective(line) {
3737
3757
  return null;
3738
3758
  return { name: m[0].toLowerCase(), value: rest.replace(/^\s*:?/, "").trim() };
3739
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
+ ]);
3740
3771
  function parseChordPro(source) {
3741
3772
  const song = {
3742
3773
  title: null,
@@ -3751,6 +3782,8 @@ function parseChordPro(source) {
3751
3782
  definitions: [],
3752
3783
  diagrams: null,
3753
3784
  instrument: null,
3785
+ simplify: false,
3786
+ capoAuto: false,
3754
3787
  warnings: []
3755
3788
  };
3756
3789
  let section = { kind: "none", label: null, lines: [] };
@@ -3779,8 +3812,15 @@ function parseChordPro(source) {
3779
3812
  } else if (key === "title" || key === "subtitle" || key === "artist" || key === "key" || key === "tempo" || key === "time") {
3780
3813
  song[key] = value || null;
3781
3814
  } else if (key === "capo") {
3815
+ song.capoAuto = value.trim().toLowerCase() === "auto";
3782
3816
  const capo = Number(value);
3783
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}}` }));
3784
3824
  } else if (key === "transpose") {
3785
3825
  const semitones = Number(value);
3786
3826
  if (Number.isInteger(semitones))
@@ -5523,6 +5563,13 @@ function blockGuitar(source, chart = false) {
5523
5563
  function guitarWish(el) {
5524
5564
  return guitarToneOf(el?.closest("[data-mn-guitar]")?.getAttribute("data-mn-guitar"));
5525
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
+ }
5526
5573
  function pageGuitar(options) {
5527
5574
  if (!options || typeof options !== "object" || !("play" in options))
5528
5575
  return;
@@ -5532,6 +5579,289 @@ function pageGuitar(options) {
5532
5579
  return guitarToneOf(play.guitar) ?? undefined;
5533
5580
  }
5534
5581
 
5582
+ // src/playback/effects.ts
5583
+ var DEFAULT_REVERB = 0.125;
5584
+ var ROOM_SECONDS = 1.2;
5585
+ var ROOM_RANGE = [0.2, 3];
5586
+ function roomSeconds(value) {
5587
+ return typeof value === "number" && Number.isFinite(value) ? Math.min(ROOM_RANGE[1], Math.max(ROOM_RANGE[0], value)) : ROOM_SECONDS;
5588
+ }
5589
+ function reverbLevel(value) {
5590
+ return typeof value === "number" && Number.isFinite(value) ? Math.min(1, Math.max(0, value)) : DEFAULT_REVERB;
5591
+ }
5592
+ function pageEffects(options) {
5593
+ if (!options || typeof options !== "object" || !("play" in options))
5594
+ return null;
5595
+ const play = options.play;
5596
+ if (!play || typeof play !== "object")
5597
+ return null;
5598
+ const read = (key) => {
5599
+ const value = play[key];
5600
+ if (typeof value !== "function")
5601
+ return value;
5602
+ try {
5603
+ return value();
5604
+ } catch {
5605
+ return;
5606
+ }
5607
+ };
5608
+ const reverb = read("reverb");
5609
+ const room = read("room");
5610
+ const amp = read("amp");
5611
+ const drive = amp && typeof amp === "object" ? amp["drive"] : null;
5612
+ const cabinet = amp && typeof amp === "object" && amp["cabinet"];
5613
+ const effects = {
5614
+ ...typeof reverb === "number" && Number.isFinite(reverb) ? { reverb: Math.min(1, Math.max(0, reverb)) } : {},
5615
+ ...typeof room === "number" && Number.isFinite(room) ? { room: roomSeconds(room) } : {},
5616
+ ...read("dry") === true ? { dry: true } : {},
5617
+ ...cabinet === true || typeof drive === "number" && Number.isFinite(drive) ? {
5618
+ amp: {
5619
+ ...typeof drive === "number" && Number.isFinite(drive) ? { drive: Math.min(1, Math.max(0, drive)) } : {},
5620
+ ...cabinet === true ? { cabinet: true } : {}
5621
+ }
5622
+ } : {}
5623
+ };
5624
+ return Object.keys(effects).length ? effects : null;
5625
+ }
5626
+ function seeded(seed) {
5627
+ let a = seed >>> 0;
5628
+ return () => {
5629
+ a = a + 1831565813 >>> 0;
5630
+ let t = a;
5631
+ t = Math.imul(t ^ t >>> 15, t | 1);
5632
+ t ^= t + Math.imul(t ^ t >>> 7, t | 61);
5633
+ return ((t ^ t >>> 14) >>> 0) / 4294967296;
5634
+ };
5635
+ }
5636
+ var ROOM_SHAPE = { bright: 4000, dark: 800, rise: 0.02, width: 0.5 };
5637
+ var ROOM_BAND = [300, 3000];
5638
+ var ROOM_WIDE_FROM = 400;
5639
+ var ROOM_SLOPE = 3;
5640
+ function roomImpulse(sampleRate, seconds = ROOM_SECONDS, shape = {}) {
5641
+ const { bright, dark, rise: riseSeconds, width } = { ...ROOM_SHAPE, ...shape };
5642
+ const length = Math.max(1, Math.round(sampleRate * seconds));
5643
+ const start = Math.min(length, Math.round(sampleRate * 0.012));
5644
+ const fade = Math.max(1, Math.round(length * 0.1));
5645
+ const fall = Math.pow(10, -3 / (sampleRate * seconds));
5646
+ const darker = Math.pow(dark / bright, 1 / (sampleRate * seconds));
5647
+ const rise = Math.max(1, Math.round(sampleRate * Math.max(0, riseSeconds)));
5648
+ const keepAt = (cutoff) => Math.exp(-2 * Math.PI * Math.min(cutoff, sampleRate * 0.45) / sampleRate);
5649
+ const shapeAt = (i) => (i - start < rise ? (i - start) / rise : 1) * (i > length - fade ? (length - i) / fade : 1);
5650
+ const make = (seed) => {
5651
+ const random = seeded(seed);
5652
+ const data = new Float32Array(length);
5653
+ let level = Math.pow(fall, start);
5654
+ let cutoff = bright * Math.pow(darker, start);
5655
+ let keep = 0;
5656
+ const lows = new Float64Array(ROOM_SLOPE);
5657
+ for (let i = start;i < length; i++) {
5658
+ if ((i - start) % 64 === 0)
5659
+ keep = keepAt(cutoff);
5660
+ let value = random() * 2 - 1;
5661
+ for (let pole = 0;pole < ROOM_SLOPE; pole++) {
5662
+ value = keep * lows[pole] + (1 - keep) * value;
5663
+ lows[pole] = value;
5664
+ }
5665
+ data[i] = value * level * shapeAt(i);
5666
+ level *= fall;
5667
+ cutoff *= darker;
5668
+ }
5669
+ return data;
5670
+ };
5671
+ let power = 0;
5672
+ const pitches = 8;
5673
+ for (let p = 0;p < pitches; p++) {
5674
+ const hz = ROOM_BAND[0] * Math.pow(ROOM_BAND[1] / ROOM_BAND[0], (p + 0.5) / pitches);
5675
+ const cos = Math.cos(2 * Math.PI * hz / sampleRate);
5676
+ let level = Math.pow(fall, start);
5677
+ let cutoff = bright * Math.pow(darker, start);
5678
+ const step = Math.pow(fall, 64);
5679
+ const darkerStep = Math.pow(darker, 64);
5680
+ for (let i = start;i < length; i += 64) {
5681
+ const keep = keepAt(cutoff);
5682
+ const pole = (1 - keep) * (1 - keep) / (1 - 2 * keep * cos + keep * keep);
5683
+ const size = Math.min(64, length - i);
5684
+ const here = level * shapeAt(i + (size >> 1));
5685
+ power += size * here * here * Math.pow(pole, ROOM_SLOPE) / 3;
5686
+ level *= step;
5687
+ cutoff *= darkerStep;
5688
+ }
5689
+ }
5690
+ const scale = power > 0 ? 1 / Math.sqrt(power / pitches) : 0;
5691
+ const middle = make(625341585);
5692
+ const apart = make(1374496523);
5693
+ const pass = Math.exp(-2 * Math.PI * ROOM_WIDE_FROM / sampleRate);
5694
+ for (let turn = 0;turn < 2; turn++) {
5695
+ let low = 0;
5696
+ for (let i = 0;i < length; i++) {
5697
+ low = pass * low + (1 - pass) * apart[i];
5698
+ apart[i] = apart[i] - low;
5699
+ }
5700
+ }
5701
+ const angle = Math.min(1, Math.max(0, width)) * Math.PI / 4;
5702
+ const left = new Float32Array(length);
5703
+ const right = new Float32Array(length);
5704
+ for (let i = 0;i < length; i++) {
5705
+ const m = middle[i] * Math.cos(angle) * scale;
5706
+ const a = apart[i] * Math.sin(angle) * scale;
5707
+ left[i] = m + a;
5708
+ right[i] = m - a;
5709
+ }
5710
+ return [left, right];
5711
+ }
5712
+ var CEILING = { knee: 0.9, range: 2 };
5713
+ function ceilingCurve(points = 4097) {
5714
+ const { knee, range } = CEILING;
5715
+ const curve = new Float32Array(points);
5716
+ for (let i = 0;i < points; i++) {
5717
+ const level = (i / (points - 1) * 2 - 1) * range;
5718
+ const size = Math.abs(level);
5719
+ curve[i] = Math.sign(level) * (size <= knee ? size : knee + (1 - knee) * Math.tanh((size - knee) / (1 - knee)));
5720
+ }
5721
+ return curve;
5722
+ }
5723
+ var ROOM_LOW_CUT = 180;
5724
+ var chains = new WeakMap;
5725
+ var canBuild = (ctx) => typeof ctx.createConvolver === "function" && typeof ctx.createBuffer === "function";
5726
+ var rooms = new Map;
5727
+ function roomBuffer(ctx, seconds) {
5728
+ const key = `${ctx.sampleRate}:${seconds}`;
5729
+ let sides = rooms.get(key);
5730
+ if (!sides) {
5731
+ sides = roomImpulse(ctx.sampleRate, seconds);
5732
+ if (rooms.size >= 3)
5733
+ rooms.delete(rooms.keys().next().value);
5734
+ rooms.set(key, sides);
5735
+ }
5736
+ const [left, right] = sides;
5737
+ const impulse = ctx.createBuffer(2, left.length, ctx.sampleRate);
5738
+ impulse.getChannelData(0).set(left);
5739
+ impulse.getChannelData(1).set(right);
5740
+ return impulse;
5741
+ }
5742
+ function build(ctx, speakers, seconds) {
5743
+ const input = ctx.createGain();
5744
+ const wet = ctx.createGain();
5745
+ wet.gain.value = 0;
5746
+ const room = ctx.createConvolver();
5747
+ room.normalize = false;
5748
+ room.buffer = roomBuffer(ctx, seconds);
5749
+ const sum = ctx.createGain();
5750
+ input.connect(sum);
5751
+ input.connect(room);
5752
+ if (typeof ctx.createBiquadFilter === "function") {
5753
+ const lowCut = ctx.createBiquadFilter();
5754
+ lowCut.type = "highpass";
5755
+ lowCut.frequency.value = ROOM_LOW_CUT;
5756
+ lowCut.Q.value = 0.7;
5757
+ room.connect(lowCut);
5758
+ lowCut.connect(wet);
5759
+ } else
5760
+ room.connect(wet);
5761
+ wet.connect(sum);
5762
+ if (typeof ctx.createWaveShaper === "function") {
5763
+ const ceiling = ctx.createWaveShaper();
5764
+ ceiling.curve = ceilingCurve();
5765
+ sum.gain.value = 1 / CEILING.range;
5766
+ sum.connect(ceiling);
5767
+ ceiling.connect(speakers);
5768
+ } else
5769
+ sum.connect(speakers);
5770
+ return { input, wet, room, seconds };
5771
+ }
5772
+ function outputFor(ctx, effects, speakers = ctx.destination) {
5773
+ if (effects?.dry || !canBuild(ctx))
5774
+ return speakers;
5775
+ const seconds = roomSeconds(effects?.room);
5776
+ let chain = chains.get(ctx);
5777
+ if (!chain) {
5778
+ try {
5779
+ chain = build(ctx, speakers, seconds);
5780
+ } catch {
5781
+ return speakers;
5782
+ }
5783
+ chains.set(ctx, chain);
5784
+ } else if (chain.seconds !== seconds) {
5785
+ try {
5786
+ chain.room.buffer = roomBuffer(ctx, seconds);
5787
+ chain.seconds = seconds;
5788
+ } catch {}
5789
+ }
5790
+ const level = reverbLevel(effects?.reverb);
5791
+ if (typeof chain.wet.gain.setTargetAtTime === "function")
5792
+ chain.wet.gain.setTargetAtTime(level, ctx.currentTime, 0.02);
5793
+ else
5794
+ chain.wet.gain.value = level;
5795
+ return chain.input;
5796
+ }
5797
+ var driveAmount = (drive) => 1 + 14 * Math.min(1, Math.max(0, drive));
5798
+ function driveCurve(drive, points = 2048) {
5799
+ const amount = driveAmount(drive);
5800
+ const curve = new Float32Array(points);
5801
+ const ceiling = Math.tanh(amount);
5802
+ for (let i = 0;i < points; i++) {
5803
+ const x = i / (points - 1) * 2 - 1;
5804
+ curve[i] = Math.tanh(amount * x) / ceiling;
5805
+ }
5806
+ return curve;
5807
+ }
5808
+ var DRIVE_REFERENCE = 0.2;
5809
+ function driveLevel(drive, reference = DRIVE_REFERENCE) {
5810
+ const amount = driveAmount(drive);
5811
+ const ceiling = Math.tanh(amount);
5812
+ let before = 0;
5813
+ let after = 0;
5814
+ for (let i = 0;i < 256; i++) {
5815
+ const x = reference * Math.sin(2 * Math.PI * i / 256);
5816
+ const y = Math.tanh(amount * x) / ceiling;
5817
+ before += x * x;
5818
+ after += y * y;
5819
+ }
5820
+ return after > 0 ? Math.sqrt(before / after) : 1;
5821
+ }
5822
+ var CABINET_TRIM_DB = -2;
5823
+ function ampFor(ctx, amp) {
5824
+ const drive = typeof amp?.drive === "number" ? Math.min(1, Math.max(0, amp.drive)) : 0;
5825
+ const cabinet = amp?.cabinet === true;
5826
+ if (!drive && !cabinet)
5827
+ return null;
5828
+ if (typeof ctx.createWaveShaper !== "function" || typeof ctx.createBiquadFilter !== "function")
5829
+ return null;
5830
+ const input = ctx.createGain();
5831
+ let last = input;
5832
+ const filter = (type, frequency, q, gain = 0) => {
5833
+ const node = ctx.createBiquadFilter();
5834
+ node.type = type;
5835
+ node.frequency.value = frequency;
5836
+ node.Q.value = q;
5837
+ node.gain.value = gain;
5838
+ last.connect(node);
5839
+ last = node;
5840
+ };
5841
+ if (drive) {
5842
+ filter("highpass", 120, 0.7);
5843
+ const shaper = ctx.createWaveShaper();
5844
+ shaper.curve = driveCurve(drive);
5845
+ shaper.oversample = "4x";
5846
+ const level = ctx.createGain();
5847
+ level.gain.value = driveLevel(drive);
5848
+ last.connect(shaper);
5849
+ shaper.connect(level);
5850
+ last = level;
5851
+ }
5852
+ if (cabinet) {
5853
+ filter("highpass", 90, 0.7);
5854
+ filter("peaking", 2200, 1, 4);
5855
+ filter("lowpass", 4800, 0.7);
5856
+ filter("lowpass", 6500, 0.7);
5857
+ const level = ctx.createGain();
5858
+ level.gain.value = Math.pow(10, CABINET_TRIM_DB / 20);
5859
+ last.connect(level);
5860
+ last = level;
5861
+ }
5862
+ return { input, output: last };
5863
+ }
5864
+
5535
5865
  // src/playback/player.ts
5536
5866
  var DEFAULT_SEQUENCE = { bpm: 90, strum: 12 };
5537
5867
  var DEFAULT_STRUM = { guitar: 12, piano: 0 };
@@ -5721,6 +6051,25 @@ var PLUCKS = 4;
5721
6051
  var RELEASE = { guitar: 0.15, piano: 0.3 };
5722
6052
  var releaseOf = (sound, duration) => Math.min(RELEASE[sound], Math.max(0.03, duration / 2));
5723
6053
  var pianoDecay = (midi) => Math.min(2.5, Math.max(0.35, Math.pow(2, (60 - midi) / 24)));
6054
+ function sendOut(ctx, from, guitar, effects) {
6055
+ const out = outputFor(ctx, effects);
6056
+ const amp = !effects?.dry && (guitar === "clean" || guitar === "overdrive") ? ampFor(ctx, effects?.amp) : null;
6057
+ const cut = (node) => {
6058
+ try {
6059
+ node.disconnect();
6060
+ } catch {}
6061
+ };
6062
+ if (!amp) {
6063
+ from.connect(out);
6064
+ return () => cut(from);
6065
+ }
6066
+ from.connect(amp.input);
6067
+ amp.output.connect(out);
6068
+ return () => {
6069
+ cut(from);
6070
+ cut(amp.output);
6071
+ };
6072
+ }
5724
6073
  function lightPlayer(win, random = Math.random) {
5725
6074
  const strings = new Map;
5726
6075
  const waves = new WeakMap;
@@ -5753,7 +6102,7 @@ function lightPlayer(win, random = Math.random) {
5753
6102
  };
5754
6103
  return {
5755
6104
  reportsStart: true,
5756
- play(events, { sound, volume, onEnd, onStart, guitar }) {
6105
+ play(events, { sound, volume, onEnd, onStart, guitar, effects }) {
5757
6106
  const ctx = contextFor(win);
5758
6107
  if (!ctx || !events.length)
5759
6108
  return { stop() {} };
@@ -5774,7 +6123,7 @@ function lightPlayer(win, random = Math.random) {
5774
6123
  });
5775
6124
  const gain = ctx.createGain();
5776
6125
  gain.gain.value = Number.isFinite(volume) ? Math.min(1, Math.max(0, volume)) : 0.8;
5777
- gain.connect(ctx.destination);
6126
+ const letGo = sendOut(ctx, gain, sound === "guitar" ? tone : null, effects);
5778
6127
  const start = ctx.currentTime + 0.05;
5779
6128
  const sources = events.map((e, i) => {
5780
6129
  if (e.kind)
@@ -5810,7 +6159,7 @@ function lightPlayer(win, random = Math.random) {
5810
6159
  source.stop(Math.max(at + 0.006, end) + release);
5811
6160
  return source;
5812
6161
  });
5813
- const finish = () => gain.disconnect();
6162
+ const finish = () => letGo();
5814
6163
  let stopped = false;
5815
6164
  let heard;
5816
6165
  const announce = () => {
@@ -6954,6 +7303,44 @@ function volumeOf(volume) {
6954
7303
  return typeof value === "number" && Number.isFinite(value) ? Math.min(1, Math.max(0, value)) : DEFAULT_VOLUME;
6955
7304
  }
6956
7305
 
7306
+ // src/playback/sound-menu.ts
7307
+ function soundMenu(doc, tr, options, played, sound, set) {
7308
+ const el = html(doc, "select", "mn-play-sound");
7309
+ const label = tr("playback.sound");
7310
+ el.setAttribute("aria-label", label);
7311
+ el.title = label;
7312
+ const names = {
7313
+ steel: tr("playback.guitar.steel"),
7314
+ nylon: tr("playback.guitar.nylon"),
7315
+ clean: tr("playback.guitar.clean"),
7316
+ overdrive: tr("playback.guitar.overdrive"),
7317
+ piano: tr("playback.piano")
7318
+ };
7319
+ for (const value of [...GUITAR_TONES, "piano"]) {
7320
+ const option = html(doc, "option", undefined, names[value]);
7321
+ option.value = value;
7322
+ el.appendChild(option);
7323
+ }
7324
+ const show = () => {
7325
+ el.value = sound() === "piano" ? "piano" : guitarFor(options, played()[0]) ?? DEFAULT_GUITAR_TONE;
7326
+ };
7327
+ el.addEventListener("change", () => {
7328
+ const guitar = GUITAR_TONES.find((tone) => tone === el.value);
7329
+ if (!guitar && el.value !== "piano")
7330
+ return show();
7331
+ if (guitar)
7332
+ for (const element of played())
7333
+ chooseGuitar(element, guitar);
7334
+ const next = guitar ? "guitar" : "piano";
7335
+ if (next !== sound())
7336
+ set(next);
7337
+ });
7338
+ el.addEventListener("pointerdown", show);
7339
+ el.addEventListener("focus", show);
7340
+ show();
7341
+ return { el, show };
7342
+ }
7343
+
6957
7344
  // src/playback/app-bar.ts
6958
7345
  var NONE = { tempoChanged() {}, free() {} };
6959
7346
  function handToApp(options, bar, info) {
@@ -8040,7 +8427,7 @@ function timedBarFor(doc, win, drawing, options, piece) {
8040
8427
  settings.bpm = tempoOf(n);
8041
8428
  app.tempoChanged(settings.bpm);
8042
8429
  }, compound ? tr("playback.dotted") : undefined).field);
8043
- bar.appendChild(choice(doc, "mn-play-sound", tr("playback.sound"), ["guitar", "piano"], settings.sound, { guitar: tr("playback.guitar"), piano: tr("playback.piano") }, (value) => settings.sound = value === "piano" ? "piano" : "guitar"));
8430
+ bar.appendChild(soundMenu(doc, tr, options, () => [wrap], () => settings.sound, (value) => settings.sound = value).el);
8044
8431
  if (options.copy !== false)
8045
8432
  bar.append(...copyImageButton(doc, win, () => wrap.closest(".mn-block") ?? wrap));
8046
8433
  const freeFull = addFullScreen(doc, bar, wrap.closest(".mn-block"), options.fullScreen);
@@ -8108,11 +8495,12 @@ var strumLabels = (tr) => ({
8108
8495
  arpeggio: tr("playback.strum.arpeggio"),
8109
8496
  pattern: tr("playback.strum.pattern")
8110
8497
  });
8111
- function progressionBarFor(doc, win, drawing, options, diagrams = null) {
8112
- const { bars, marks } = barsFromDrawing(drawing);
8498
+ function progressionBarFor(doc, win, drawing, options, diagrams = null, regroup) {
8499
+ let { bars, marks } = barsFromDrawing(drawing);
8113
8500
  if (!bars.length)
8114
8501
  return () => {};
8115
8502
  const tr = translator();
8503
+ const language = currentLanguage();
8116
8504
  const time = drawing.getAttribute("data-mn-time");
8117
8505
  let beatsPerBar = 4;
8118
8506
  let beatUnit = 4;
@@ -8150,14 +8538,17 @@ function progressionBarFor(doc, win, drawing, options, diagrams = null) {
8150
8538
  playing = null;
8151
8539
  show();
8152
8540
  };
8153
- if (diagrams) {
8541
+ const wire = () => {
8542
+ if (!diagrams)
8543
+ return;
8154
8544
  diagrams.onPlay = stop;
8155
8545
  diagrams.stopOthers = () => {
8156
8546
  const was = playing !== null;
8157
8547
  stop();
8158
8548
  return was;
8159
8549
  };
8160
- }
8550
+ };
8551
+ wire();
8161
8552
  const start = () => {
8162
8553
  stop();
8163
8554
  if (!drawing.isConnected)
@@ -8198,10 +8589,49 @@ function progressionBarFor(doc, win, drawing, options, diagrams = null) {
8198
8589
  if (playing)
8199
8590
  start();
8200
8591
  }));
8201
- bar.appendChild(choice(doc, "mn-play-sound", tr("playback.sound"), ["guitar", "piano"], settings.sound, { guitar: tr("playback.guitar"), piano: tr("playback.piano") }, (value) => {
8202
- settings.sound = value === "piano" ? "piano" : "guitar";
8592
+ bar.appendChild(soundMenu(doc, tr, options, () => [drawing], () => settings.sound, (value) => {
8593
+ settings.sound = value;
8203
8594
  diagrams?.setSound(settings.sound);
8204
- }));
8595
+ }).el);
8596
+ const redraw = chartRedrawOf(drawing);
8597
+ if (redraw) {
8598
+ const simplify = html(doc, "button", "mn-play-simplify");
8599
+ simplify.type = "button";
8600
+ const shown = () => {
8601
+ const on = drawing.hasAttribute("data-mn-simplified");
8602
+ simplify.textContent = tr(on ? "playback.simplified" : "playback.simplify");
8603
+ simplify.title = tr(on ? "playback.simplified.hint" : "playback.simplify.hint");
8604
+ simplify.setAttribute("aria-pressed", String(on));
8605
+ simplify.classList.toggle("mn-on", on);
8606
+ };
8607
+ simplify.addEventListener("click", () => {
8608
+ stop();
8609
+ diagrams?.stop();
8610
+ const on = !drawing.hasAttribute("data-mn-simplified");
8611
+ const naming = namingOf(drawing.closest("[data-mn-naming]")?.getAttribute("data-mn-naming"));
8612
+ let next;
8613
+ try {
8614
+ next = withLanguage(language, () => naming ? withNaming(naming, () => redraw(on)) : redraw(on));
8615
+ } catch {
8616
+ return;
8617
+ }
8618
+ for (const child of [...drawing.children])
8619
+ if (child !== bar)
8620
+ child.remove();
8621
+ bar.before(...next.children);
8622
+ drawing.toggleAttribute("data-mn-simplified", next.hasAttribute("data-mn-simplified"));
8623
+ ({ bars, marks } = barsFromDrawing(drawing));
8624
+ if (regroup) {
8625
+ diagrams = regroup();
8626
+ wire();
8627
+ if (settings.sound !== (piano ? "piano" : "guitar"))
8628
+ diagrams?.setSound(settings.sound);
8629
+ }
8630
+ shown();
8631
+ });
8632
+ shown();
8633
+ bar.appendChild(simplify);
8634
+ }
8205
8635
  if (options.copy !== false)
8206
8636
  bar.append(...copyImageButton(doc, win, () => drawing.closest(".mn-block") ?? drawing));
8207
8637
  const freeFull = addFullScreen(doc, bar, drawing.closest(".mn-block"), options.fullScreen);
@@ -9114,8 +9544,8 @@ function blockBarFor(doc, win, block, diagrams, options) {
9114
9544
  bar.appendChild(tempo.field);
9115
9545
  if (strum)
9116
9546
  bar.appendChild(strum.field);
9117
- const sound = choice(doc, "mn-play-sound", tr("playback.sound"), ["guitar", "piano"], made.sound, { guitar: tr("playback.guitar"), piano: tr("playback.piano") }, (value) => group.setSound(value === "piano" ? "piano" : "guitar"));
9118
- bar.appendChild(sound);
9547
+ const sound = soundMenu(doc, tr, options, () => items.map((item) => item.wrap), () => made.sound, (value) => group.setSound(value));
9548
+ bar.appendChild(sound.el);
9119
9549
  if (options.copy !== false)
9120
9550
  bar.append(...copyImageButton(doc, win, (whole) => whole || !several ? block : diagramImage(made.selected.wrap)));
9121
9551
  const freeFull = addFullScreen(doc, bar, block, options.fullScreen);
@@ -9136,7 +9566,7 @@ function blockBarFor(doc, win, block, diagrams, options) {
9136
9566
  strum.field.hidden = !(several && item.data.kind === "chord");
9137
9567
  strum.show(made.strumOf(made.sound));
9138
9568
  }
9139
- sound.value = made.sound;
9569
+ sound.show();
9140
9570
  }
9141
9571
  });
9142
9572
  return () => {
@@ -9168,10 +9598,35 @@ function playerFor(win, options, el) {
9168
9598
  }
9169
9599
  function toned(player, options, el) {
9170
9600
  const tone = guitarFor(options, el);
9171
- return tone ? withGuitar(player, tone) : player;
9601
+ const effects = effectsOf(options);
9602
+ return tone || effects ? withPlay(player, tone, effects) : player;
9603
+ }
9604
+ function effectsOf(options) {
9605
+ const read = (value) => {
9606
+ try {
9607
+ return (typeof value === "function" ? value() : value) ?? null;
9608
+ } catch {
9609
+ return null;
9610
+ }
9611
+ };
9612
+ const reverb = read(options.reverb);
9613
+ const room = read(options.room);
9614
+ const amp = read(options.amp);
9615
+ const effects = {
9616
+ ...typeof reverb === "number" && Number.isFinite(reverb) ? { reverb: Math.round(Math.min(1, Math.max(0, reverb)) * 1000) / 1000 } : {},
9617
+ ...typeof room === "number" && Number.isFinite(room) ? { room: Math.round(roomSeconds(room) * 100) / 100 } : {},
9618
+ ...read(options.dry) === true ? { dry: true } : {},
9619
+ ...amp && typeof amp === "object" && (amp.cabinet === true || typeof amp.drive === "number") ? {
9620
+ amp: {
9621
+ ...amp.cabinet === true ? { cabinet: true } : {},
9622
+ ...typeof amp.drive === "number" && Number.isFinite(amp.drive) ? { drive: Math.round(Math.min(1, Math.max(0, amp.drive)) * 100) / 100 } : {}
9623
+ }
9624
+ } : {}
9625
+ };
9626
+ return Object.keys(effects).length ? effects : null;
9172
9627
  }
9173
9628
  function guitarFor(options, el) {
9174
- const wish = guitarWish(el);
9629
+ const wish = guitarChoice(el) ?? guitarWish(el);
9175
9630
  if (wish)
9176
9631
  return wish;
9177
9632
  try {
@@ -9180,22 +9635,30 @@ function guitarFor(options, el) {
9180
9635
  return null;
9181
9636
  }
9182
9637
  }
9183
- var guitarPlayers = new WeakMap;
9184
- function withGuitar(player, guitar) {
9185
- let twins = guitarPlayers.get(player);
9638
+ var twinPlayers = new WeakMap;
9639
+ var TWINS_KEPT = 32;
9640
+ function withPlay(player, guitar, effects) {
9641
+ let twins = twinPlayers.get(player);
9186
9642
  if (!twins) {
9187
9643
  twins = new Map;
9188
- guitarPlayers.set(player, twins);
9644
+ twinPlayers.set(player, twins);
9189
9645
  }
9190
- let twin = twins.get(guitar);
9646
+ const key = `${guitar ?? ""}|${effects ? JSON.stringify(effects) : ""}`;
9647
+ let twin = twins.get(key);
9191
9648
  if (!twin) {
9192
9649
  twin = {
9193
9650
  get reportsStart() {
9194
9651
  return player.reportsStart;
9195
9652
  },
9196
- play: (events, options) => player.play(events, options.guitar ? options : { ...options, guitar })
9653
+ play: (events, options) => player.play(events, {
9654
+ ...options,
9655
+ ...guitar && !options.guitar ? { guitar } : {},
9656
+ ...effects && !options.effects ? { effects } : {}
9657
+ })
9197
9658
  };
9198
- twins.set(guitar, twin);
9659
+ if (twins.size >= TWINS_KEPT)
9660
+ twins.delete(twins.keys().next().value);
9661
+ twins.set(key, twin);
9199
9662
  }
9200
9663
  return twin;
9201
9664
  }
@@ -9374,9 +9837,17 @@ function attachPlaybackIn(el, options) {
9374
9837
  for (const [block, diagrams] of byBlock)
9375
9838
  stops.push(blockBarFor(doc, win, block, diagrams, options));
9376
9839
  for (const drawing of timed) {
9377
- const diagrams = byDrawing.get(drawing);
9378
- const group = diagrams?.length ? diagramGroup(doc, win, diagrams, options, { bar: false }).group : null;
9379
- const bar = progressionBarFor(doc, win, drawing, options, group);
9840
+ const groupOf = (diagrams) => diagrams?.length ? diagramGroup(doc, win, diagrams, options, { bar: false }).group : null;
9841
+ let group = groupOf(byDrawing.get(drawing));
9842
+ const regroup = () => {
9843
+ group?.destroy();
9844
+ group = groupOf([...drawing.querySelectorAll("svg[data-mn-pitches]")].flatMap((diagram) => {
9845
+ const data = diagram.hasAttribute("data-mn-pick") ? null : dataOf(diagram);
9846
+ return data ? [{ diagram, data }] : [];
9847
+ }));
9848
+ return group;
9849
+ };
9850
+ const bar = progressionBarFor(doc, win, drawing, options, group, regroup);
9380
9851
  stops.push(() => {
9381
9852
  bar();
9382
9853
  group?.destroy();
@@ -10173,6 +10644,186 @@ function renderChordsUsed(doc, song, options) {
10173
10644
  return root;
10174
10645
  }
10175
10646
 
10647
+ // src/chord/simplify.ts
10648
+ var easiest = new Map;
10649
+ var KEPT = 512;
10650
+ function easiestOf(symbol, options) {
10651
+ const key = `${options.tuning?.join(",") ?? ""}|${symbol}`;
10652
+ const known = easiest.get(key);
10653
+ if (known !== undefined)
10654
+ return known;
10655
+ const generation = options.tuning ? { tuning: options.tuning } : {};
10656
+ const first = generateVoicings(symbol, generation)[0];
10657
+ const found = first ? { frets: [...first.frets], difficulty: first.difficulty, open: first.shape === "Open" } : null;
10658
+ if (easiest.size >= KEPT)
10659
+ easiest.delete(easiest.keys().next().value);
10660
+ easiest.set(key, found);
10661
+ return found;
10662
+ }
10663
+ function plainerSuffixes(symbol) {
10664
+ const info = chordInfo(symbol);
10665
+ if (!info)
10666
+ return [];
10667
+ const has = (interval) => info.members.some((m) => m.interval === interval);
10668
+ const third = has("3M") ? "major" : has("3m") ? "minor" : null;
10669
+ const diminished = third === "minor" && has("5d");
10670
+ const pick = (...found) => found.find(([i]) => has(i))?.[1] ?? null;
10671
+ const seventh = third !== "minor" ? pick(["7M", "maj7"], ["7m", "7"]) : diminished ? pick(["7d", "dim7"], ["7m", "m7b5"]) : pick(["7m", "m7"]);
10672
+ const steps = [];
10673
+ if (seventh)
10674
+ steps.push(seventh);
10675
+ if (seventh === "m7b5")
10676
+ steps.push("m7");
10677
+ if (seventh === "dim7")
10678
+ steps.push("dim");
10679
+ else if (!(diminished && !seventh))
10680
+ steps.push(third === "minor" ? "m" : "");
10681
+ return steps.filter((suffix, i) => suffix !== info.suffix && steps.indexOf(suffix) === i);
10682
+ }
10683
+ function plainerChords(symbol) {
10684
+ const parts = splitChordSymbol(symbol);
10685
+ if (!parts)
10686
+ return [];
10687
+ const own = `${parts.root}${canonicalSuffix(parts.suffix)}`;
10688
+ const bass = parts.bass ? `/${parts.bass}` : "";
10689
+ const found = bass ? [`${parts.root}${parts.suffix}`] : [];
10690
+ for (const suffix of plainerSuffixes(symbol)) {
10691
+ if (bass)
10692
+ found.push(`${parts.root}${suffix}${bass}`);
10693
+ found.push(`${parts.root}${suffix}`);
10694
+ }
10695
+ return found.filter((chord, i) => chord !== own + bass && found.indexOf(chord) === i);
10696
+ }
10697
+ function simplifyChord(symbol, options = {}) {
10698
+ const own = easiestOf(symbol.trim(), options);
10699
+ const limit = own ? own.difficulty : Infinity;
10700
+ 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) => ({
10701
+ symbol: c.chord,
10702
+ frets: [...c.voicing.frets],
10703
+ difficulty: c.voicing.difficulty
10704
+ }));
10705
+ }
10706
+ function easierChord(symbol, options = {}) {
10707
+ return simplifyChord(symbol, options)[0]?.symbol ?? symbol.trim();
10708
+ }
10709
+ var UNPLAYABLE = 12;
10710
+ var CAPO_COST = 0.5;
10711
+ function shapeName(chord, capo) {
10712
+ if (!capo)
10713
+ return chord;
10714
+ const flat = transposeChord(chord, -capo, true);
10715
+ const sharp = transposeChord(chord, -capo, false);
10716
+ if (flat === sharp)
10717
+ return flat;
10718
+ return /^[A-G]b/.test(chord) ? flat : sharp;
10719
+ }
10720
+ function capoChoices(chords, options = {}) {
10721
+ const distinct = [...new Set(chords.map((c) => c.trim()))].filter((c) => chordInfo(c) !== null);
10722
+ if (!distinct.length)
10723
+ return [];
10724
+ const max = Math.min(12, Math.max(0, Math.round(options.maxCapo ?? 7) || 0));
10725
+ const choices = [];
10726
+ for (let capo = 0;capo <= max; capo++) {
10727
+ const shapes = distinct.map((chord) => {
10728
+ const shape = shapeName(chord, capo);
10729
+ const voicing = easiestOf(shape, options);
10730
+ return {
10731
+ chord,
10732
+ shape,
10733
+ frets: voicing ? [...voicing.frets] : null,
10734
+ open: voicing?.open ?? false,
10735
+ difficulty: voicing?.difficulty ?? UNPLAYABLE
10736
+ };
10737
+ });
10738
+ choices.push({
10739
+ capo,
10740
+ shapes,
10741
+ open: shapes.filter((s) => s.open).length,
10742
+ difficulty: shapes.reduce((sum, s) => sum + s.difficulty, 0)
10743
+ });
10744
+ }
10745
+ const effort = (c) => c.difficulty + CAPO_COST * c.capo;
10746
+ return choices.sort((a, b) => b.open - a.open || effort(a) - effort(b) || a.capo - b.capo);
10747
+ }
10748
+ function bestCapo(chords, options = {}) {
10749
+ return capoChoices(chords, options)[0] ?? null;
10750
+ }
10751
+
10752
+ // src/chords/easier.ts
10753
+ function withSuffixOf(written, easier) {
10754
+ const own = splitChordSymbol(written);
10755
+ const other = splitChordSymbol(easier);
10756
+ if (!own || !other)
10757
+ return written;
10758
+ return `${own.root}${other.suffix}${other.bass && own.bass ? `/${own.bass}` : ""}`;
10759
+ }
10760
+ function easierSong(song, shownOf, semitones, options) {
10761
+ const same = { song, easier: [], canSimplify: false, capo: null, choice: null };
10762
+ if (!options.guitar)
10763
+ return same;
10764
+ const names = chordsUsed(song);
10765
+ const found = names.filter((written) => !findDefinition(song.definitions, written)).map((written) => {
10766
+ const from = shownOf(written).trim();
10767
+ return { written, from, to: easierChord(from) };
10768
+ }).filter((c) => c.to !== c.from);
10769
+ const canSimplify = found.length > 0;
10770
+ const simpler = new Map;
10771
+ if (options.simplify)
10772
+ for (const c of found)
10773
+ simpler.set(c.written, withSuffixOf(c.written, c.to));
10774
+ const easier = options.simplify ? found.map(({ from, to }) => ({ from, to })) : [];
10775
+ const simplified = (name) => simpler.get(name.trim()) ?? name;
10776
+ const copy = (rename) => song.sections.map((section) => ({
10777
+ ...section,
10778
+ lines: section.lines.map((l) => {
10779
+ if (l.kind === "lyrics")
10780
+ return {
10781
+ kind: "lyrics",
10782
+ segments: l.segments.map((s) => s.chord === null ? s : { ...s, chord: rename(s.chord, true) })
10783
+ };
10784
+ const d = l.kind === "chord" ? l.definition : null;
10785
+ if (d && !d.frets && !d.keys && !d.copy)
10786
+ return {
10787
+ kind: "chord",
10788
+ definition: { ...d, name: rename(d.name, d.transposable) }
10789
+ };
10790
+ return l;
10791
+ })
10792
+ }));
10793
+ const best = song.capoAuto ? bestCapo(names.map((written) => shownOf(simplified(written)).trim())) : null;
10794
+ if (!best || best.capo === 0) {
10795
+ if (!simpler.size)
10796
+ return { ...same, canSimplify, choice: best };
10797
+ return {
10798
+ song: { ...song, sections: copy(simplified) },
10799
+ easier,
10800
+ canSimplify,
10801
+ capo: null,
10802
+ choice: best
10803
+ };
10804
+ }
10805
+ const shapes = new Map(best.shapes.map((s) => [s.chord, s.shape]));
10806
+ const shape = (name, transposable) => {
10807
+ if (!/^[A-G]/.test(name.trim()))
10808
+ return name;
10809
+ const sounding = transposable ? shownOf(simplified(name)).trim() : simplified(name).trim();
10810
+ return shapes.get(sounding) ?? transposeChord(sounding, -best.capo);
10811
+ };
10812
+ return {
10813
+ song: {
10814
+ ...song,
10815
+ capo: best.capo,
10816
+ transpose: song.transpose - semitones,
10817
+ key: song.key ? transposeKey(song.key, semitones) : null,
10818
+ sections: copy(shape)
10819
+ },
10820
+ easier,
10821
+ canSimplify,
10822
+ capo: best.capo,
10823
+ choice: best
10824
+ };
10825
+ }
10826
+
10176
10827
  // src/chords/chart.ts
10177
10828
  var PLACEMENTS = new Set(["top", "bottom", "off"]);
10178
10829
  function lineBeats(segments, playable, beatsPerBar, perPulse) {
@@ -10271,6 +10922,36 @@ function transposerOf(song, extra) {
10271
10922
  chord: (symbol) => transposeChord(symbol, semitones, spelling)
10272
10923
  };
10273
10924
  }
10925
+ function easierPlan(song, options, guitar) {
10926
+ const written = transposerOf(song, options.transpose);
10927
+ return easierSong(song, written.chord, written.semitones, {
10928
+ simplify: options.simplify ?? song.simplify ?? false,
10929
+ guitar
10930
+ });
10931
+ }
10932
+ function easierChart(given, options = {}) {
10933
+ const instrument = given.instrument ?? (options.instrument === "piano" ? "piano" : "guitar");
10934
+ const asked = { ...given, capoAuto: options.capo ?? given.capoAuto ?? false };
10935
+ const plan = easierPlan(asked, options, instrument === "guitar");
10936
+ const renames = new Map;
10937
+ asked.sections.forEach((section, i) => section.lines.forEach((line, j) => {
10938
+ const other = plan.song.sections[i]?.lines[j];
10939
+ if (line.kind !== "lyrics" || other?.kind !== "lyrics")
10940
+ return;
10941
+ line.segments.forEach((segment, k) => {
10942
+ const now = other.segments[k]?.chord;
10943
+ if (segment.chord !== null && now != null && now !== segment.chord)
10944
+ renames.set(segment.chord, now);
10945
+ });
10946
+ }));
10947
+ return {
10948
+ easier: plan.easier,
10949
+ capo: plan.choice,
10950
+ renames,
10951
+ transpose: plan.song.transpose,
10952
+ key: plan.song.key
10953
+ };
10954
+ }
10274
10955
  function meterOf(song) {
10275
10956
  let beatsPerBar = 4;
10276
10957
  let beatUnit = 4;
@@ -10279,7 +10960,9 @@ function meterOf(song) {
10279
10960
  ({ beatsPerBar, beatUnit } = parseTime(time));
10280
10961
  return { beatsPerBar, beatUnit, perPulse: isCompound(beatsPerBar, beatUnit) ? 3 : 1 };
10281
10962
  }
10282
- function chartChords(song, options = {}) {
10963
+ function chartChords(given, options = {}) {
10964
+ const instrument = given.instrument ?? (options.instrument === "piano" ? "piano" : "guitar");
10965
+ const { song } = easierPlan(given, options, instrument === "guitar");
10283
10966
  const { chord } = transposerOf(song, options.transpose);
10284
10967
  const { beatsPerBar, beatUnit, perPulse } = meterOf(song);
10285
10968
  const playable = (written) => {
@@ -10323,11 +11006,19 @@ function chartChords(song, options = {}) {
10323
11006
  tempo: song.tempo && Number.isFinite(tempo) && tempo >= 20 && tempo <= 240 ? tempo : null
10324
11007
  };
10325
11008
  }
10326
- function renderChart(doc, song, options = {}) {
11009
+ var redraws = new WeakMap;
11010
+ function chartRedrawOf(chart) {
11011
+ return redraws.get(chart) ?? null;
11012
+ }
11013
+ function renderChart(doc, given, options = {}) {
11014
+ const instrument = given.instrument ?? (options.instrument === "piano" ? "piano" : "guitar");
11015
+ const plan = easierPlan(given, options, instrument === "guitar");
11016
+ const song = plan.song;
10327
11017
  const { semitones, key, spelling, chord } = transposerOf(song, options.transpose);
11018
+ const transposed = transposerOf(given, options.transpose).semitones;
10328
11019
  const meter = meterOf(song);
10329
11020
  const drawing = {
10330
- instrument: song.instrument ?? (options.instrument === "piano" ? "piano" : "guitar"),
11021
+ instrument,
10331
11022
  ...options.voicings ? { voicings: options.voicings } : {},
10332
11023
  ...options.orientation ? { orientation: options.orientation } : {},
10333
11024
  ...options.hand ? { hand: options.hand } : {}
@@ -10340,6 +11031,10 @@ function renderChart(doc, song, options = {}) {
10340
11031
  ...spelling === undefined ? {} : { spelling }
10341
11032
  });
10342
11033
  const root = html(doc, "div", "mn-chart");
11034
+ if (plan.easier.length)
11035
+ root.setAttribute("data-mn-simplified", "");
11036
+ if (plan.canSimplify)
11037
+ redraws.set(root, (simplify) => renderChart(doc, given, { ...options, simplify }));
10343
11038
  root.setAttribute("data-mn-progression-play", "");
10344
11039
  root.setAttribute("data-mn-sound", drawing.instrument === "piano" ? "piano" : "guitar");
10345
11040
  const time = timeOf(song.time);
@@ -10393,7 +11088,8 @@ function renderChart(doc, song, options = {}) {
10393
11088
  song.capo ? t("chords.chart.capo", { capo: song.capo }) : null,
10394
11089
  song.tempo ? t("chords.chart.tempo", { bpm: song.tempo }) : null,
10395
11090
  song.time ? song.time : null,
10396
- semitones % 12 ? t("chords.chart.transposed", { amount: `${semitones > 0 ? "+" : ""}${semitones}` }) : null
11091
+ transposed % 12 ? t("chords.chart.transposed", { amount: `${transposed > 0 ? "+" : ""}${transposed}` }) : null,
11092
+ plan.easier.length ? t("chords.chart.simplified") : null
10397
11093
  ].filter((m) => m !== null);
10398
11094
  if (meta.length)
10399
11095
  root.appendChild(html(doc, "div", "mn-chart-meta", meta.join(" · ")));
@@ -16980,10 +17676,10 @@ function sampledPlayer(win, source, fallback, options = {}) {
16980
17676
  };
16981
17677
  return {
16982
17678
  reportsStart: true,
16983
- play(events, { sound: instrument, volume, onEnd, onStart, guitar }) {
17679
+ play(events, { sound: instrument, volume, onEnd, onStart, guitar, effects }) {
16984
17680
  const ctx = contextOf();
16985
17681
  const tone = guitar ?? DEFAULT_GUITAR_TONE;
16986
- const same = guitar ? { guitar } : {};
17682
+ const same = { ...guitar ? { guitar } : {}, ...effects ? { effects } : {} };
16987
17683
  if (!ctx)
16988
17684
  return fallback.play(events, {
16989
17685
  sound: instrument,
@@ -17015,7 +17711,7 @@ function sampledPlayer(win, source, fallback, options = {}) {
17015
17711
  const byKind = new Map(kinds.map((kind, i) => [kind, loaded[i]]));
17016
17712
  const master = ctx.createGain();
17017
17713
  master.gain.value = level;
17018
- master.connect(ctx.destination);
17714
+ const letGo = sendOut(ctx, master, instrument === "guitar" ? tone : null, effects);
17019
17715
  const start = ctx.currentTime + 0.05;
17020
17716
  const sources = [];
17021
17717
  let tail = 0;
@@ -17033,7 +17729,7 @@ function sampledPlayer(win, source, fallback, options = {}) {
17033
17729
  tail = Math.max(tail, made.over - start);
17034
17730
  }
17035
17731
  }
17036
- const finish = () => master.disconnect();
17732
+ const finish = () => letGo();
17037
17733
  let heard;
17038
17734
  const announce = () => {
17039
17735
  if (stopped || !onStart)
@@ -17975,6 +18671,7 @@ export {
17975
18671
  DEFAULT_EXERCISE_TEMPO,
17976
18672
  DEFAULT_GUITAR_TONE,
17977
18673
  DEFAULT_PROPERTY_NAMES,
18674
+ DEFAULT_REVERB,
17978
18675
  DEFAULT_SEQUENCE,
17979
18676
  DEFAULT_STRUM,
17980
18677
  DEFAULT_STRUM_CHORD,
@@ -18014,9 +18711,11 @@ export {
18014
18711
  attachPlayback,
18015
18712
  barreKind,
18016
18713
  baseFretOf,
18714
+ bestCapo,
18017
18715
  blockFromProperties,
18018
18716
  bluesTonic,
18019
18717
  capoCaption,
18718
+ capoChoices,
18020
18719
  capoTuning,
18021
18720
  characteristicIntervals,
18022
18721
  chartChords,
@@ -18032,6 +18731,8 @@ export {
18032
18731
  descriptionOf,
18033
18732
  detectChordFromFrets,
18034
18733
  detectChordFromPitches,
18734
+ easierChart,
18735
+ easierChord,
18035
18736
  emptyNoteSet,
18036
18737
  engineOf,
18037
18738
  engineOrder,
@@ -18090,6 +18791,8 @@ export {
18090
18791
  noteOf,
18091
18792
  noteTargets,
18092
18793
  numeralOf,
18794
+ outputFor,
18795
+ pageEffects,
18093
18796
  pageEngine,
18094
18797
  pageGuitar,
18095
18798
  pageInstruments,
@@ -18163,6 +18866,7 @@ export {
18163
18866
  sequenceOf,
18164
18867
  shownText,
18165
18868
  signatureText,
18869
+ simplifyChord,
18166
18870
  smoothProgression,
18167
18871
  soundingChord,
18168
18872
  soundsLike,
@@ -18194,5 +18898,5 @@ export {
18194
18898
  withTonicizations
18195
18899
  };
18196
18900
 
18197
- //# debugId=3A1E1BEF24D884B064756E2164756E21
18901
+ //# debugId=47E914BB1589446C64756E2164756E21
18198
18902
  //# sourceMappingURL=index.js.map