@dsebastien/music-notation 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Loads alphaTab's script for the tab bundle (#38). alphaTab's UMD build registers with an AMD
3
+ * loader instead of setting `window.alphaTab` when one is on the page, so an AMD `define` is hidden
4
+ * while the script runs. A load that fails (a network error, or a script that sets no
5
+ * `window.alphaTab`: a blocked or partial download) is forgotten, so the next page change tries
6
+ * again; before, only a network error was.
7
+ */
8
+ import { type AlphaTabModule } from './index.js';
9
+ /** alphaTab from the page, else from `src` (jsDelivr by default), one load at a time. */
10
+ export declare function alphaTabLoader(src?: () => string): (doc: Document) => Promise<AlphaTabModule>;
@@ -15,3 +15,10 @@ export declare function voicingProblem(symbol: string, frets: readonly (number |
15
15
  * fingers never on lower frets.
16
16
  */
17
17
  export declare function fingeringProblem(frets: readonly (number | null)[], fingers: readonly (string | null)[]): string | null;
18
+ /**
19
+ * Whether a strummed hand sounds only the voicing's notes: no muted string between two sounding
20
+ * ones (Bdim x20x01 can't be strummed cleanly), except the jazz grips that mute the A string under
21
+ * a root on the low E (F#6 2x132x, Fm6 1x0111, F#m7b5 2x221x), which players damp with the
22
+ * fretting hand (#72).
23
+ */
24
+ export declare function strummable(frets: readonly (number | null)[]): boolean;
@@ -31,6 +31,15 @@ function svgText(doc, text, attrs = {}) {
31
31
  function svgLabel(doc, text, [x, y], cls, anchor = "middle") {
32
32
  return svgText(doc, text, { class: cls, x, y: y + 4, "text-anchor": anchor });
33
33
  }
34
+ function dotLabel(doc, text, point, r) {
35
+ const label = svgLabel(doc, text, point, "mn-dot-text");
36
+ if ([...text].length >= 3) {
37
+ label.classList.add("mn-dot-text-long");
38
+ label.setAttribute("textLength", String(2 * r - 2));
39
+ label.setAttribute("lengthAdjust", "spacingAndGlyphs");
40
+ }
41
+ return label;
42
+ }
34
43
  function svgLine(doc, [x1, y1], [x2, y2], cls) {
35
44
  return svg(doc, "line", { class: cls, x1, y1, x2, y2 });
36
45
  }
@@ -304,6 +313,9 @@ function renderGuitarDiagram(doc, voicing, options = {}) {
304
313
  const label = `${options.title ? `${options.title} chord diagram` : "Chord diagram"}${capo ? `, ${capoCaption(capo, options.sounds).replace(/^Capo/, "capo")}` : ""}`;
305
314
  const height = frame.height + (caption ? CAPTION : 0);
306
315
  const root = svgRoot(doc, frame.width, height, "mn-guitar-chord", label);
316
+ root.setAttribute("data-mn-hand", options.hand ?? "right");
317
+ const fretText = voicing.frets.map((f) => f === null ? "x" : String(f));
318
+ root.setAttribute("data-mn-voicing", fretText.some((f) => f.length > 1) ? fretText.join("-") : fretText.join(""));
307
319
  if (caption) {
308
320
  root.appendChild(svgText(doc, caption, {
309
321
  class: "mn-caption",
@@ -345,7 +357,9 @@ function renderGuitarDiagram(doc, voicing, options = {}) {
345
357
  }
346
358
  const textOf = (s) => (options.labels ? options.labels[s] : voicing.fingers[s]) ?? null;
347
359
  const quiet = new Set;
348
- for (const barre of barresOf(voicing, capoFret)) {
360
+ const fingered = voicing.fingers.some((f) => f);
361
+ const barres = fingered ? barresOf(voicing, capoFret) : options.barreFingers ? barresOf({ frets: voicing.frets, fingers: [...options.barreFingers] }, capoFret).filter((b) => b.full) : [];
362
+ for (const barre of barres) {
349
363
  const texts = new Set(barre.strings.map(textOf));
350
364
  if (texts.size === 1) {
351
365
  for (const s of barre.strings)
@@ -428,7 +442,7 @@ function renderGuitarDiagram(doc, voicing, options = {}) {
428
442
  cy,
429
443
  r: 7,
430
444
  ...midi
431
- }), ...text ? [svgLabel(doc, text, center, "mn-dot-text")] : []);
445
+ }), ...text ? [dotLabel(doc, text, center, 7)] : []);
432
446
  });
433
447
  if (tuning) {
434
448
  const shift = fromNut ? 0 : capo;
@@ -927,7 +941,8 @@ function shapeOf(frets, info, targets, tuning) {
927
941
  if (info.members.length === 2 && info.tones.every((t) => t.number === 1 || t.number === 5)) {
928
942
  return "Power chord";
929
943
  }
930
- const shell = sounding.length <= 4 && info.tones.some((t) => t.number === 7 || t.number === 6) && [...chromas].every((c) => info.tones.some((t) => t.chroma === c && [1, 3, 6, 7].includes(t.number)));
944
+ const lowest = (tuning[sounding[0]] + frets[sounding[0]]) % 12;
945
+ const shell = sounding.length === 3 && chromas.size === 3 && lowest === info.root && info.tones.some((t) => t.number === 7 || t.number === 6) && [...chromas].every((c) => info.tones.some((t) => t.chroma === c && [1, 3, 6, 7].includes(t.number)));
931
946
  if (shell)
932
947
  return "Shell";
933
948
  const adjacent = sounding[sounding.length - 1] - sounding[0] === sounding.length - 1;
@@ -974,6 +989,36 @@ var KNOWN_SHAPES = new Set([
974
989
  "D shape",
975
990
  "Power chord"
976
991
  ]);
992
+ var JAZZ_GRIPS = [
993
+ { rootString: 1, offsets: [null, 0, -1, 0, 1, null] },
994
+ { rootString: 0, offsets: [0, null, 0, 0, -1, null] },
995
+ { rootString: 0, offsets: [0, null, -1, 0, -1, null] },
996
+ { rootString: 0, offsets: [0, null, 0, 1, 2, null] }
997
+ ];
998
+ function distinctShapes(voicings, count = voicings.length) {
999
+ const sounding = (v) => v.frets.flatMap((f, s) => f === null ? [] : [s]);
1000
+ const copyOf = (v, w) => {
1001
+ const mine = sounding(v);
1002
+ const theirs = sounding(w);
1003
+ return mine.length < theirs.length && v.frets.length === w.frets.length && mine.every((s, i) => theirs[i] === s && w.frets[s] === v.frets[s]);
1004
+ };
1005
+ const kept = voicings.filter((v) => !voicings.some((w) => w !== v && copyOf(v, w)));
1006
+ const lowest = (v) => {
1007
+ const fretted = v.frets.filter((f) => f !== null && f > 0);
1008
+ return fretted.length ? Math.min(...fretted) : 0;
1009
+ };
1010
+ return kept.slice(0, count).map((v, rank) => ({ v, rank })).sort((a, b) => lowest(a.v) - lowest(b.v) || a.rank - b.rank).map(({ v }) => v);
1011
+ }
1012
+ function isJazzGrip(frets) {
1013
+ if (frets.length !== 6)
1014
+ return false;
1015
+ return JAZZ_GRIPS.some(({ rootString, offsets }) => {
1016
+ const root = frets[rootString];
1017
+ if (root === null || root === undefined || root < 1)
1018
+ return false;
1019
+ return offsets.every((o, s) => o === null ? frets[s] === null : frets[s] === root + o);
1020
+ });
1021
+ }
977
1022
  var indexOf = (number, count) => count - number;
978
1023
  var bits = (n) => {
979
1024
  let count = 0;
@@ -1099,8 +1144,15 @@ function generateVoicings(symbol, options = {}) {
1099
1144
  difficulty += 0.5;
1100
1145
  reasons.push("no fifth");
1101
1146
  }
1147
+ const jazz = standard && isJazzGrip(candidate);
1148
+ if (jazz) {
1149
+ difficulty -= 2 * inner + strings.filter((s) => s > last).length * 1.5;
1150
+ reasons.push("jazz grip");
1151
+ }
1102
1152
  if (usual)
1103
1153
  difficulty -= 3;
1154
+ else if (jazz)
1155
+ difficulty -= 1.5;
1104
1156
  else if (isBarreShape(shape) && barre)
1105
1157
  difficulty -= 2;
1106
1158
  else if (shape && KNOWN_SHAPES.has(shape))
@@ -1151,6 +1203,27 @@ function generateVoicings(symbol, options = {}) {
1151
1203
  frets[s] = null;
1152
1204
  };
1153
1205
  visit(0, Infinity, -Infinity, 0, 0, false);
1206
+ if (standard && !options.gaps) {
1207
+ for (const { rootString, offsets } of JAZZ_GRIPS) {
1208
+ if (!allowed.has(rootString))
1209
+ continue;
1210
+ const rootFret = ((info.root - tuning[rootString]) % 12 + 12) % 12;
1211
+ for (const at of [rootFret, rootFret + 12]) {
1212
+ const candidate = offsets.map((o) => o === null ? null : at + o);
1213
+ if (candidate.some((f, s) => f !== null && (f < 1 || !choices[s].includes(f))))
1214
+ continue;
1215
+ const have = candidate.reduce((mask, f, s) => f === null ? mask : mask | 1 << (tuning[s] + f) % 12, 0);
1216
+ if ((required & ~have) !== 0)
1217
+ continue;
1218
+ const key = candidate.join(",");
1219
+ if (results.has(key))
1220
+ continue;
1221
+ const voicing = evaluate(candidate);
1222
+ if (voicing)
1223
+ results.set(key, voicing);
1224
+ }
1225
+ }
1226
+ }
1154
1227
  const sounding = (v) => v.frets.filter((f) => f !== null).length;
1155
1228
  return [...results.values()].sort((a, b) => a.difficulty - b.difficulty || sounding(b) - sounding(a) || a.baseFret - b.baseFret || a.frets.join(",").localeCompare(b.frets.join(",")));
1156
1229
  }
@@ -1239,6 +1312,18 @@ function fingeringProblem(frets, fingers) {
1239
1312
  }
1240
1313
  return null;
1241
1314
  }
1315
+ function strummable(frets) {
1316
+ const sounding = frets.flatMap((f, s) => f === null ? [] : [s]);
1317
+ if (sounding.length < 2)
1318
+ return true;
1319
+ const inside = [];
1320
+ for (let s = sounding[0];s <= sounding[sounding.length - 1]; s++)
1321
+ if (frets[s] === null)
1322
+ inside.push(s);
1323
+ if (!inside.length)
1324
+ return true;
1325
+ return frets.length === 6 && sounding[0] === 0 && inside.length === 1 && inside[0] === 1;
1326
+ }
1242
1327
 
1243
1328
  // src/voicings/curated.ts
1244
1329
  var HENDRIX = {
@@ -1411,8 +1496,11 @@ function checked(key, chord) {
1411
1496
  add({ frets: v.frets, fingers: v.fingers, baseFret: v.baseFret });
1412
1497
  }
1413
1498
  }
1414
- checkedCache.set(key, list);
1415
- return list;
1499
+ const curated = new Set((CURATED[key] ?? []).map((e) => compact2(parseFrets2(e.split(" ")[0]))));
1500
+ const first = (v) => curated.has(compact2(v.frets)) || strummable(v.frets);
1501
+ const ordered = [...list.filter(first), ...list.filter((v) => !first(v))];
1502
+ checkedCache.set(key, ordered);
1503
+ return ordered;
1416
1504
  }
1417
1505
  var generatedCache = new Map;
1418
1506
  function generated(symbol) {
@@ -1436,5 +1524,5 @@ export {
1436
1524
  voicingCount
1437
1525
  };
1438
1526
 
1439
- //# debugId=CB5AD4C94F1007E464756E2164756E21
1527
+ //# debugId=085B9BAB5D2BA40664756E2164756E21
1440
1528
  //# sourceMappingURL=index.js.map