@dsebastien/music-notation 0.17.0 → 0.18.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 CHANGED
@@ -186,7 +186,7 @@ Add this to your site's `publish.js`. It loads the bundle only on pages that hav
186
186
 
187
187
  ```js
188
188
  ;(() => {
189
- const VERSION = '0.14.0'
189
+ const VERSION = '0.17.0'
190
190
  const CDN = `https://cdn.jsdelivr.net/npm/@dsebastien/music-notation@${VERSION}/dist`
191
191
  const selector = (languages) => languages.map((l) => `pre > code.language-${l}`).join(', ')
192
192
  const BLOCKS = selector([
@@ -22,6 +22,13 @@ export interface PianoFingering {
22
22
  /** Spelling per pitch class (C# or Db), as the chord spells its notes; sharps when absent. */
23
23
  names?: ReadonlyMap<number, string>;
24
24
  }
25
+ /**
26
+ * What players call each string. When every name is different, or only the two outer strings share
27
+ * one (low E and high E), by name: "the A string", "the low E string". Otherwise (drop D, DADGAD,
28
+ * open tunings) two strings could read alike, so every string is named by its number and note:
29
+ * "the 4th string (D)". Without a tuning, numbers only.
30
+ */
31
+ export declare function stringNames(tuning: readonly number[] | null, count: number, spelled?: readonly string[]): string[];
25
32
  /**
26
33
  * The fingering of a chord in plain sentences, in the order a player sets the hand: for a fretted
27
34
  * chord the capo, the strings to strum, barres and fingers (low string first), muted strings
@@ -25,6 +25,9 @@ export interface TransitionOptions {
25
25
  fromFingers?: (string | null)[];
26
26
  /** How many of the next chord's easiest voicings to consider (30 by default). */
27
27
  candidates?: number;
28
+ /** The open strings' names as the tuning is written (Eb Ab Db…, see `tuningNames`): tips
29
+ * spell them so; else from the pitches, with sharps. */
30
+ tuningNames?: readonly string[];
28
31
  }
29
32
  /**
30
33
  * The next chord's voicings, ranked by how easily the hand gets there from the one it holds:
@@ -41,6 +44,8 @@ export interface ProgressionOptions {
41
44
  tuning?: number[];
42
45
  /** How many of each chord's easiest voicings to weigh (12 by default). */
43
46
  candidates?: number;
47
+ /** The open strings' names as the tuning is written (see `TransitionOptions`). */
48
+ tuningNames?: readonly string[];
44
49
  /** The voicing database (see `/voicings`): its voicings of each chord are weighed too, and
45
50
  * preferred. Only used in standard tuning. */
46
51
  voicings?: VoicingLookup;
package/dist/index.js CHANGED
@@ -1820,10 +1820,10 @@ var STACKED = {
1820
1820
  "3M 5P 7M": "maj7",
1821
1821
  "3M 5P 7m": "7",
1822
1822
  "3m 5P 7m": "m7",
1823
- "3m 5P 7M": "mMaj7",
1823
+ "3m 5P 7M": "m(maj7)",
1824
1824
  "3m 5d 7m": "m7b5",
1825
1825
  "3m 5d 7d": "dim7",
1826
- "3M 5A 7M": "maj7#5",
1826
+ "3M 5A 7M": "+maj7",
1827
1827
  "3M 5A 7m": "7#5",
1828
1828
  "3M 5d 7m": "7b5"
1829
1829
  };
@@ -1852,14 +1852,18 @@ function numeralQuality(suffix) {
1852
1852
  case "aug":
1853
1853
  return { lower: false, mark: "+" };
1854
1854
  case "mMaj7":
1855
- return { lower: true, mark: "maj7" };
1855
+ case "m(maj7)":
1856
+ return { lower: true, mark: "(maj7)" };
1857
+ case "maj7#5":
1858
+ case "+maj7":
1859
+ return { lower: false, mark: "+maj7" };
1856
1860
  }
1857
1861
  if (/^m(?!aj)/.test(suffix))
1858
1862
  return { lower: true, mark: suffix.slice(1) };
1859
1863
  return { lower: false, mark: suffix };
1860
1864
  }
1861
1865
  function nashvilleQuality(suffix) {
1862
- return { dim: "°", dim7: "°7", m7b5: "ø7", aug: "+" }[suffix] ?? (suffix === "mMaj7" ? "mmaj7" : suffix);
1866
+ return { dim: "°", dim7: "°7", m7b5: "ø7", aug: "+" }[suffix] ?? (suffix === "mMaj7" ? "m(maj7)" : suffix === "maj7#5" ? "+maj7" : suffix);
1863
1867
  }
1864
1868
  function degreeOf(tonic, note, minorKey = false) {
1865
1869
  if (chromaOf(note) === null || chromaOf(tonic) === null)
@@ -5141,6 +5145,7 @@ function renderFretboard(doc, set, options = {}) {
5141
5145
  // src/playback/bar-parts.ts
5142
5146
  var ICONS = {
5143
5147
  play: "M4 2.5v11l9-5.5z",
5148
+ pause: "M4 3h3v10H4zM9 3h3v10H9z",
5144
5149
  stop: "M4 4h8v8H4z",
5145
5150
  all: "M1.5 2.5v11l6.5-5.5zM8 2.5v11l6.5-5.5z",
5146
5151
  loop: "M3 8a5 5 0 0 1 8.5-3.5L13 6V2.5M13 8a5 5 0 0 1-8.5 3.5L3 10v3.5",
@@ -8660,21 +8665,12 @@ var FINGER_NAMES = {
8660
8665
  };
8661
8666
  var ordinal2 = (n) => `${n}${n % 100 >= 11 && n % 100 <= 13 ? "th" : ["th", "st", "nd", "rd"][n % 10] ?? "th"}`;
8662
8667
  var MAX_SLIDE = 3;
8663
- function stringName(tuning, s) {
8664
- const name = noteOf(tuning[s]).replace(/-?\d+$/, "");
8665
- const same = tuning.filter((p) => noteOf(p).replace(/-?\d+$/, "") === name).length;
8666
- if (same < 2)
8667
- return `the ${name} string`;
8668
- if (same > 2)
8669
- return `the ${ordinal2(tuning.length - s)} string (${name})`;
8670
- const lowest = tuning.findIndex((p) => noteOf(p).replace(/-?\d+$/, "") === name);
8671
- return `the ${s === lowest ? "low" : "high"} ${name} string`;
8672
- }
8668
+ var namesOf2 = (tuning, spelled) => stringNames(tuning, tuning.length, spelled?.length === tuning.length ? spelled : undefined);
8673
8669
  var lowestFret2 = (frets) => {
8674
8670
  const fretted = frets.filter((f) => f !== null && f > 0);
8675
8671
  return fretted.length ? Math.min(...fretted) : 0;
8676
8672
  };
8677
- function move(from, fromFingers, to, tuning) {
8673
+ function move(from, fromFingers, to, names) {
8678
8674
  const anchors = [];
8679
8675
  const guides = [];
8680
8676
  let movement = 0;
@@ -8707,14 +8703,14 @@ function move(from, fromFingers, to, tuning) {
8707
8703
  if (seen.has(f))
8708
8704
  continue;
8709
8705
  seen.add(f);
8710
- tips.push(`Keep your ${fingerName(f)} on ${stringName(tuning, s)}'s ${ordinal2(to.frets[s])} fret.`);
8706
+ tips.push(`Keep your ${fingerName(f)} on ${names[s]}'s ${ordinal2(to.frets[s])} fret.`);
8711
8707
  }
8712
8708
  for (const s of guides) {
8713
8709
  const f = to.fingers[s];
8714
8710
  if (seen.has(f))
8715
8711
  continue;
8716
8712
  seen.add(f);
8717
- tips.push(`Slide your ${fingerName(f)} along ${stringName(tuning, s)} from fret ${from[s]} to ${to.frets[s]}.`);
8713
+ tips.push(`Slide your ${fingerName(f)} along ${names[s]} from fret ${from[s]} to ${to.frets[s]}.`);
8718
8714
  }
8719
8715
  if (shift >= 2) {
8720
8716
  const up = lowestFret2(to.frets) > lowestFret2(from);
@@ -8731,8 +8727,9 @@ function transition(from, toChord, options = {}) {
8731
8727
  if (from.length !== tuning.length)
8732
8728
  return [];
8733
8729
  const fromFingers = options.fromFingers ?? fingerVoicing(from) ?? from.map(() => null);
8730
+ const names = namesOf2(tuning, options.tuningNames);
8734
8731
  const candidates = generateVoicings(toChord, { tuning }).slice(0, options.candidates ?? 30);
8735
- return candidates.map((voicing) => ({ voicing, ...move(from, fromFingers, voicing, tuning) })).sort((a, b) => score(a, a.voicing) - score(b, b.voicing));
8732
+ return candidates.map((voicing) => ({ voicing, ...move(from, fromFingers, voicing, names) })).sort((a, b) => score(a, a.voicing) - score(b, b.voicing));
8736
8733
  }
8737
8734
  var DATABASE_VOICINGS = 6;
8738
8735
  var HIGH_POSITION = 5;
@@ -8784,6 +8781,7 @@ function candidatesOf(symbol, tuning, count, voicings) {
8784
8781
  var sameTuning4 = (a, b) => a.length === b.length && a.every((p, i) => p === b[i]);
8785
8782
  function smoothProgression(chords, options = {}) {
8786
8783
  const tuning = options.tuning ?? STANDARD_TUNING;
8784
+ const names = namesOf2(tuning, options.tuningNames);
8787
8785
  const count = options.candidates ?? 12;
8788
8786
  const cache = new Map;
8789
8787
  const lists = chords.map((c) => {
@@ -8804,7 +8802,7 @@ function smoothProgression(chords, options = {}) {
8804
8802
  let best = Infinity;
8805
8803
  let from = 0;
8806
8804
  prev.forEach((p, j) => {
8807
- const step = move(p.voicing.frets, p.voicing.fingers, voicing, tuning);
8805
+ const step = move(p.voicing.frets, p.voicing.fingers, voicing, names);
8808
8806
  const total = costs[j] + step.movement + SHAPE_WEIGHT * cost;
8809
8807
  if (total < best) {
8810
8808
  best = total;
@@ -8827,7 +8825,7 @@ function smoothProgression(chords, options = {}) {
8827
8825
  return {
8828
8826
  chord: chords[i],
8829
8827
  voicing,
8830
- ...move(previous.frets, previous.fingers, voicing, tuning)
8828
+ ...move(previous.frets, previous.fingers, voicing, names)
8831
8829
  };
8832
8830
  });
8833
8831
  }
@@ -9061,6 +9059,8 @@ function noteOn(key, degree, accidental, diminished) {
9061
9059
  function suffixOf(mark, lower) {
9062
9060
  let s = mark.replace(/♭/g, "b").replace(/♯/g, "#");
9063
9061
  s = s.replace(/^o/, "°").replace(/^Δ7?$/, "maj7").replace(/^M7$/, "maj7");
9062
+ if (lower)
9063
+ s = s.replace(/^\((maj\d*)\)$/, "$1").replace(/^m(?=[Mm]aj)/, "").replace(/^Maj/, "maj");
9064
9064
  if (s === "°" || s === "dim")
9065
9065
  return "dim";
9066
9066
  if (s === "°7" || s === "dim7")
@@ -9082,8 +9082,10 @@ function suffixOf(mark, lower) {
9082
9082
  return `m${s}`;
9083
9083
  }
9084
9084
  var isDiminished = (suffix) => /^(dim|m7b5)/.test(suffix);
9085
+ var USUAL = { mMaj7: "m(maj7)", "maj7#5": "+maj7" };
9085
9086
  function chordFrom(root, suffix) {
9086
- const symbol = `${root}${canonicalSuffix(suffix)}`;
9087
+ const canonical = canonicalSuffix(suffix);
9088
+ const symbol = `${root}${USUAL[canonical] ?? canonical}`;
9087
9089
  return parseChord(symbol) && chordNoteSet(symbol) ? symbol : null;
9088
9090
  }
9089
9091
  function bassOf(key, text) {
@@ -9576,7 +9578,8 @@ var SHARED = [
9576
9578
  "tempo",
9577
9579
  "bpm",
9578
9580
  "strum",
9579
- "harmonize"
9581
+ "harmonize",
9582
+ "caption"
9580
9583
  ];
9581
9584
  var KIND_WORDS = {
9582
9585
  triad: "triads",
@@ -9796,7 +9799,7 @@ function guitarVoicings(symbols, tuningText, voicings) {
9796
9799
  var fretsText = (list) => list.some((f) => f !== null && f > 9) ? list.map((f) => f === null ? "x" : f).join("-") : list.map((f) => f === null ? "x" : f).join("");
9797
9800
  function diagramBlock(block, lines) {
9798
9801
  const fields = new Map(lines);
9799
- for (const key of ["orientation", "hand", "labels", "tuning"]) {
9802
+ for (const key of ["orientation", "hand", "labels", "tuning", "caption"]) {
9800
9803
  const value = field(block, key);
9801
9804
  if (value !== undefined)
9802
9805
  fields.set(key, value);
@@ -9862,6 +9865,10 @@ function renderSection(doc, section, options, renderChord) {
9862
9865
  }
9863
9866
  const piano = instrument !== "guitar";
9864
9867
  const diagrams = yes(field(block, "diagrams"), "diagrams", true);
9868
+ const caption = field(block, "caption")?.trim();
9869
+ if (caption && !["fingering", "none", "no", "off", "false"].includes(caption.toLowerCase())) {
9870
+ throw new Error(`caption: use fingering (the fingering in words) or none, got "${caption}"`);
9871
+ }
9865
9872
  const functions = yes(field(block, "functions"), "functions", false);
9866
9873
  const leading = field(block, "voice-leading");
9867
9874
  const led = yes(leading, "voice-leading", false);
@@ -12695,26 +12702,14 @@ var styles_default = `/* Music notation. Colors follow Obsidian's theme variable
12695
12702
  pointer-events: none;
12696
12703
  }
12697
12704
 
12698
- /* Tabs and scores: the player bar stays at the bottom of the screen while the score scrolls. */
12705
+ /* Tabs and scores: the player bar is a bar like the others (#82), below the score and always
12706
+ shown; it also stays at the bottom of the screen while a long score scrolls. */
12699
12707
  .mn-tab {
12700
12708
  position: relative;
12701
12709
  }
12702
12710
 
12703
- .mn-tab .mn-tab-bar {
12704
- position: sticky;
12705
- left: auto;
12706
- right: auto;
12711
+ .mn-tab .mn-play.mn-play-static.mn-tab-bar {
12707
12712
  bottom: 6px;
12708
- width: fit-content;
12709
- max-width: 100%;
12710
- margin: 4px auto 0;
12711
- }
12712
-
12713
- .mn-tab:hover .mn-tab-bar,
12714
- .mn-tab:focus-within .mn-tab-bar,
12715
- .mn-tab.mn-play-open .mn-tab-bar {
12716
- opacity: 1;
12717
- pointer-events: auto;
12718
12713
  }
12719
12714
 
12720
12715
  /* alphaTab's cursor (the bar that plays, the beat line) and the notes of the beat that sounds, in
@@ -14628,5 +14623,5 @@ export {
14628
14623
  withTonicizations
14629
14624
  };
14630
14625
 
14631
- //# debugId=B41A5636C218CAD964756E2164756E21
14626
+ //# debugId=618A7E58A09A035164756E2164756E21
14632
14627
  //# sourceMappingURL=index.js.map