@dsebastien/music-notation 0.7.0 → 0.8.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.
Files changed (48) hide show
  1. package/README.md +28 -2
  2. package/dist/blocks/note-set-field.d.ts +3 -1
  3. package/dist/blocks/progression.d.ts +6 -0
  4. package/dist/blocks/renderers.d.ts +10 -1
  5. package/dist/blocks/scales-for.d.ts +16 -0
  6. package/dist/chord/capo.d.ts +26 -0
  7. package/dist/chord/guitar.d.ts +20 -0
  8. package/dist/chord/transitions.d.ts +15 -7
  9. package/dist/chords/chart-diagrams.d.ts +46 -0
  10. package/dist/chords/chart.d.ts +16 -0
  11. package/dist/chords/chordpro.d.ts +17 -1
  12. package/dist/chords/defines.d.ts +38 -0
  13. package/dist/circle/circle.d.ts +21 -0
  14. package/dist/cli.js +2 -2
  15. package/dist/convert/text-tab.d.ts +4 -2
  16. package/dist/fretboard/fretboard.d.ts +11 -0
  17. package/dist/fretboard/positions.d.ts +12 -5
  18. package/dist/index.d.ts +20 -5
  19. package/dist/index.js +5946 -1923
  20. package/dist/index.js.map +39 -22
  21. package/dist/keyboard/keyboard.d.ts +2 -0
  22. package/dist/keyboard/piano-chord.d.ts +44 -0
  23. package/dist/keyboard/voice-leading.d.ts +6 -0
  24. package/dist/music-notation.css +339 -0
  25. package/dist/music-notation.publish.min.js +362 -21
  26. package/dist/music-notation.tab.min.js +343 -4
  27. package/dist/playback/controls.d.ts +10 -1
  28. package/dist/playback/follow.d.ts +45 -0
  29. package/dist/playback/player.d.ts +13 -1
  30. package/dist/playback/strum-bar.d.ts +5 -0
  31. package/dist/publish/index.js +5271 -1852
  32. package/dist/publish/index.js.map +38 -21
  33. package/dist/strum/pattern.d.ts +49 -0
  34. package/dist/strum/play.d.ts +106 -0
  35. package/dist/strum/render.d.ts +17 -0
  36. package/dist/strum/voicing.d.ts +10 -0
  37. package/dist/tab/index.js +334 -78
  38. package/dist/tab/index.js.map +7 -7
  39. package/dist/theory/chord-symbol.d.ts +2 -0
  40. package/dist/theory/find.d.ts +82 -0
  41. package/dist/theory/keys.d.ts +79 -0
  42. package/dist/theory/note-set.d.ts +2 -0
  43. package/dist/theory/numerals.d.ts +40 -0
  44. package/dist/theory/pitch.d.ts +4 -1
  45. package/dist/theory/transpose.d.ts +16 -4
  46. package/dist/voicings/index.js +58 -14
  47. package/dist/voicings/index.js.map +5 -5
  48. package/package.json +1 -1
package/dist/tab/index.js CHANGED
@@ -82,10 +82,11 @@ function midiOf(note) {
82
82
  return (Number(m[2]) + 1) * 12 + chroma - shift * 12;
83
83
  }
84
84
  var nameOf = (chroma, preferFlats = false) => (preferFlats ? FLAT_NAMES : SHARP_NAMES)[((Math.round(chroma) || 0) % 12 + 12) % 12];
85
+ var doubleSharp = (name) => name.replace(/x$/, "##");
85
86
  function splitChordSymbol(symbol) {
86
- const normalized = symbol.trim().replace(/♯/g, "#").replace(/♭/g, "b");
87
- const m = /^([A-G][#b]?)(.*?)(?:\/([A-G][#b]?))?$/.exec(normalized);
88
- return m ? { root: m[1], suffix: m[2], bass: m[3] ?? null } : null;
87
+ const normalized = symbol.trim().replace(/♯/g, "#").replace(/♭/g, "b").replace(/𝄪/g, "x").replace(/𝄫/g, "bb");
88
+ const m = /^([A-G](?:##|x(?!\d)|bb|#|b)?)(.*?)(?:\/([A-G](?:##|x|bb|#|b)?))?$/.exec(normalized);
89
+ return m ? { root: doubleSharp(m[1]), suffix: m[2], bass: m[3] ? doubleSharp(m[3]) : null } : null;
89
90
  }
90
91
  var noteOf = (midi, preferFlats = false) => `${nameOf(midi, preferFlats)}${Math.floor(midi / 12) - 1}`;
91
92
  var isFlat = (name) => /^[A-Ga-g][b♭]/.test(name.trim());
@@ -134,102 +135,314 @@ function parseTuning(text) {
134
135
  }
135
136
 
136
137
  // src/convert/text-tab.ts
137
- var STRING_LINE = /^\s*([A-Ga-g][#b]?)?\s*[|:]?[-0-9xX|:hpbrsvt/\\~^().*<>\s]*$/;
138
- var isStringLine = (line) => STRING_LINE.test(line) && (line.match(/-/g)?.length ?? 0) >= 4 && (line.includes("|") || /^\s*[A-Ga-g][#b]?\s*[-|:]/.test(line));
138
+ var STRING_PREFIX = /^\s*([A-Ga-g][#b]?|[1-8](?=\s*[|:]))?\s*[|:]?/;
139
+ var STRING_BODY = /^[-0-9xX|:hpbrsvt/\\~^().*<>\s]*$/;
140
+ var DRUM_LINE = /^\s*([A-Za-z][A-Za-z0-9. -]{0,14}?)\s*[|:]([-xXoOgfdb#@*+|:\s]*)$/;
141
+ var DRUM_NAMES = new Map(Object.entries({
142
+ hihat: "h hh hat hihat hihats",
143
+ "hihat-open": "oh openhat openhihat",
144
+ "hihat-foot": "hf fh hp ph pedal hihatfoot hihatpedal",
145
+ crash: "c c1 cc cr cy cym crash crash1 cymbal",
146
+ crash2: "c2 cr2 crash2",
147
+ ride: "r rd rc ride",
148
+ splash: "sp spl splash",
149
+ china: "ch cn chi china",
150
+ cowbell: "cb cow cowbell",
151
+ snare: "s sd sn sr snare snaredrum",
152
+ tom1: "t t1 ht tom1 hightom hitom",
153
+ tom2: "t2 mt tom2 midtom",
154
+ tom3: "t3 lt tom3 lowtom",
155
+ floor: "f ft fl t4 tom4 floor floortom",
156
+ kick: "b bd bs k kd bass kick bassdrum kickdrum"
157
+ }).flatMap(([drum, list]) => list.split(" ").map((name) => [name, drum])));
158
+ function articulationOf(drum, hit) {
159
+ const choke = hit === "#";
160
+ switch (drum) {
161
+ case "hihat":
162
+ return hit === "o" || hit === "O" ? "HiHatOpen" : "HiHatClosed";
163
+ case "hihat-open":
164
+ return "HiHatOpen";
165
+ case "hihat-foot":
166
+ return "PedalHiHatHit";
167
+ case "crash":
168
+ return choke ? "CrashHighChoke" : "CrashHighHit";
169
+ case "crash2":
170
+ return choke ? "CrashMediumChoke" : "CrashMediumHit";
171
+ case "ride":
172
+ return choke ? "RideChoke" : "RideMiddle";
173
+ case "splash":
174
+ return choke ? "SplashChoke" : "SplashHit";
175
+ case "china":
176
+ return choke ? "ChinaChoke" : "ChinaHit";
177
+ case "cowbell":
178
+ return "CowbellMediumHit";
179
+ case "snare":
180
+ return "SnareHit";
181
+ case "tom1":
182
+ return "HighTomHit";
183
+ case "tom2":
184
+ return "MidTomHit";
185
+ case "tom3":
186
+ return "LowTomHit";
187
+ case "floor":
188
+ return "VeryLowTomHit";
189
+ case "kick":
190
+ return "KickHit";
191
+ }
192
+ }
193
+ var effectOf = (hit) => hit === "X" || hit === "O" ? "{ac}" : hit === "g" ? "{g}" : "";
194
+ var NOT_TAB = /[^-0-9xXoOgfdbhprsvt/\\~^().*<>#@+|:\s]|<(?!\d)/;
195
+ var COUNT = /^\s*(?:[xX]\s*\d{1,3}|\d{1,3}\s*[xX])\s*$/;
196
+ function splitText(line) {
197
+ const last = line.lastIndexOf("|");
198
+ if (last < 0)
199
+ return { line, text: null };
200
+ const rest = line.slice(last + 1);
201
+ const text = rest.trim();
202
+ if (!text)
203
+ return { line, text: null };
204
+ const isText = NOT_TAB.test(text) || COUNT.test(text) || /^\s/.test(rest) && !text.includes("--");
205
+ return isText ? { line: line.slice(0, last + 1), text } : { line, text: null };
206
+ }
207
+ function tabLineOf(raw) {
208
+ const { line, text } = splitText(raw.trimEnd());
209
+ let string = null;
210
+ const m = STRING_PREFIX.exec(line);
211
+ const body = line.slice(m[0].length);
212
+ if (STRING_BODY.test(body) && (line.match(/-/g)?.length ?? 0) >= 4 && (line.includes("|") || /^\s*[A-Ga-g][#b]?\s*[-|:]/.test(line)))
213
+ string = { name: m[1] ?? null, body };
214
+ let drum = null;
215
+ const d = DRUM_LINE.exec(line);
216
+ const name = d ? d[1].toLowerCase().replace(/[ .-]/g, "") : "";
217
+ const known = DRUM_NAMES.get(name);
218
+ if (d && known && (d[2].match(/[^\s|:]/g)?.length ?? 0) >= 4)
219
+ drum = { drum: known, name, body: d[2], lettered: /^[A-Ga-g]$/.test(d[1]) };
220
+ return string || drum ? { string, drum, text } : null;
221
+ }
222
+ var textsOf = (run) => [
223
+ ...new Set(run.map((l) => l.text).filter((t) => t !== null))
224
+ ];
225
+ function splitStrings(run) {
226
+ const out = [];
227
+ let start = 0;
228
+ for (let i = 2;i < run.length - 1; i++) {
229
+ const [a, b] = [run[start].string.name, run[start + 1].string.name];
230
+ if (a !== null && run[i].string.name === a && run[i + 1].string.name === b && i - start >= 2) {
231
+ out.push(run.slice(start, i));
232
+ start = i;
233
+ }
234
+ }
235
+ out.push(run.slice(start));
236
+ return out;
237
+ }
238
+ function splitDrums(run) {
239
+ const out = [];
240
+ let current = [];
241
+ for (const line of run) {
242
+ if (current.some((l) => l.drum.name === line.drum.name)) {
243
+ out.push(current);
244
+ current = [];
245
+ }
246
+ current.push(line);
247
+ }
248
+ out.push(current);
249
+ return out;
250
+ }
251
+ function stringSystems(run) {
252
+ return splitStrings(run).flatMap((part) => {
253
+ const names = part.map((l) => l.string.name);
254
+ if (part.length < 3 && names.some((n) => n === null))
255
+ return [];
256
+ const lines = part.map((l) => l.string.body);
257
+ return [{ kind: "strings", names, lines, texts: textsOf(part) }];
258
+ });
259
+ }
260
+ function systemsOfRun(run) {
261
+ if (!run.length)
262
+ return [];
263
+ if (run.every((l) => l.drum) && run.some((l) => !l.string || !l.drum.lettered || /[xXoOgfdb#@*+]/.test(l.drum.body)))
264
+ return splitDrums(run).map((part) => ({
265
+ kind: "drums",
266
+ drums: part.map((l) => l.drum.drum),
267
+ lines: part.map((l) => l.drum.body),
268
+ texts: textsOf(part)
269
+ }));
270
+ if (run.every((l) => l.string))
271
+ return stringSystems(run);
272
+ const out = [];
273
+ let stretch = [];
274
+ for (const l of [...run, null]) {
275
+ if (l?.string)
276
+ stretch.push(l);
277
+ else {
278
+ if (stretch.length)
279
+ out.push(...stringSystems(stretch));
280
+ stretch = [];
281
+ }
282
+ }
283
+ return out;
284
+ }
139
285
  function systemsOf(text) {
140
286
  const systems = [];
141
- let current = null;
287
+ let run = [];
142
288
  for (const raw of text.split(/\r?\n/)) {
143
- if (isStringLine(raw)) {
144
- const m = /^\s*([A-Ga-g][#b]?)?\s*[|:]?/.exec(raw);
145
- current ??= { names: [], lines: [] };
146
- current.names.push(m[1] ?? null);
147
- current.lines.push(raw.slice(m[0].length));
148
- } else if (current) {
149
- if (current.lines.length >= 4)
150
- systems.push(current);
151
- current = null;
289
+ const line = tabLineOf(raw);
290
+ if (line)
291
+ run.push(line);
292
+ else {
293
+ systems.push(...systemsOfRun(run));
294
+ run = [];
152
295
  }
153
296
  }
154
- if (current && current.lines.length >= 4)
155
- systems.push(current);
297
+ systems.push(...systemsOfRun(run));
156
298
  return systems;
157
299
  }
158
- function barsOf(lines) {
300
+ function barsOf(lines, beatAt) {
159
301
  const width = Math.max(...lines.map((l) => l.length));
160
302
  const padded = lines.map((l) => l.padEnd(width, "-"));
161
- const bars = [[]];
303
+ const bars = [];
304
+ let beats = [];
305
+ let filled = false;
162
306
  for (let col = 0;col < width; col++) {
163
307
  if (padded.every((l) => l[col] === "|" || l[col] === ":")) {
164
- if (bars[bars.length - 1].length)
165
- bars.push([]);
308
+ if (filled)
309
+ bars.push(beats);
310
+ beats = [];
311
+ filled = false;
166
312
  continue;
167
313
  }
168
- const beat = [];
169
- let wide = false;
314
+ if (padded.some((l) => l[col] !== " "))
315
+ filled = true;
316
+ const { beat, skip } = beatAt(padded, col);
317
+ if (beat.length)
318
+ beats.push(beat);
319
+ col += skip;
320
+ }
321
+ if (filled)
322
+ bars.push(beats);
323
+ return bars;
324
+ }
325
+ function stringBeatAt(padded, col) {
326
+ const beat = [];
327
+ let wide = false;
328
+ padded.forEach((line, i) => {
329
+ const c = line[col];
330
+ if (!/\d/.test(c) || /\d/.test(line[col - 1] ?? ""))
331
+ return;
332
+ const two = /\d/.test(line[col + 1] ?? "") ? line.slice(col, col + 2) : c;
333
+ if (two.length === 2)
334
+ wide = true;
335
+ beat.push({ fret: Number(two), string: i + 1 });
336
+ });
337
+ if (wide)
170
338
  padded.forEach((line, i) => {
171
- const c = line[col];
172
- if (!/\d/.test(c) || /\d/.test(line[col - 1] ?? ""))
339
+ if (beat.some((n) => n.string === i + 1))
173
340
  return;
174
- const two = /\d/.test(line[col + 1] ?? "") ? line.slice(col, col + 2) : c;
175
- if (two.length === 2)
176
- wide = true;
341
+ const c = line[col + 1] ?? "";
342
+ if (!/\d/.test(c) || /\d/.test(line[col] ?? ""))
343
+ return;
344
+ const two = /\d/.test(line[col + 2] ?? "") ? line.slice(col + 1, col + 3) : c;
177
345
  beat.push({ fret: Number(two), string: i + 1 });
178
346
  });
179
- if (wide)
180
- padded.forEach((line, i) => {
181
- if (beat.some((n) => n.string === i + 1))
182
- return;
183
- const c = line[col + 1] ?? "";
184
- if (!/\d/.test(c) || /\d/.test(line[col] ?? ""))
185
- return;
186
- const two = /\d/.test(line[col + 2] ?? "") ? line.slice(col + 1, col + 3) : c;
187
- beat.push({ fret: Number(two), string: i + 1 });
188
- });
189
- if (beat.length)
190
- bars[bars.length - 1].push(beat);
191
- if (wide)
192
- col++;
193
- }
194
- return bars.filter((b) => b.length);
347
+ return { beat, skip: wide ? 1 : 0 };
195
348
  }
196
349
  var BY_COUNT = {
197
- 4: [28, 33, 38, 43],
198
- 5: [23, 28, 33, 38, 43],
199
- 7: [35, 40, 45, 50, 55, 59, 64]
350
+ 3: [64, 59, 55],
351
+ 4: [43, 38, 33, 28],
352
+ 5: [43, 38, 33, 28, 23],
353
+ 6: [64, 59, 55, 50, 45, 40],
354
+ 7: [64, 59, 55, 50, 45, 40, 35]
200
355
  };
356
+ var BY_NUMBER = [64, 59, 55, 50, 45, 40, 35, 30];
357
+ var GUITAR = { names: ["E", "A", "D", "G", "B", "E"], midis: [40, 45, 50, 55, 59, 64] };
201
358
  var BASS = ["E A D G", "B E A D G"];
359
+ var upper = (name) => name[0].toUpperCase() + name.slice(1);
202
360
  function tuningOf(names) {
203
361
  const strings = names.length;
204
- if (names.every((n) => n !== null)) {
362
+ if (names.every((n) => n !== null && /^\d$/.test(n)))
363
+ return names.every((n) => BY_NUMBER[Number(n) - 1]) ? names.map((n) => BY_NUMBER[Number(n) - 1]) : null;
364
+ if (names.every((n) => n !== null && /^[A-Ga-g]/.test(n))) {
205
365
  const lowFirst = [...names].reverse();
206
- if (strings === 6 && lowFirst.join(" ").toLowerCase() === "e a d g b e")
207
- return null;
208
- const tuning = parseTuning(lowFirst.join(" "));
209
- if (!tuning)
210
- return BY_COUNT[strings] ?? null;
211
- const bass = BASS.includes(lowFirst.map((n) => n.toUpperCase()).join(" "));
212
- return bass ? tuning.map((m) => m - 12) : tuning;
366
+ const spelled = lowFirst.map(upper).join(" ");
367
+ if (BASS.includes(spelled))
368
+ return parseTuning(spelled).map((m) => m - 12).reverse();
369
+ const starts = [...GUITAR.names.keys()].filter((start) => lowFirst.every((n, i) => GUITAR.names[start + i] === upper(n)));
370
+ if (starts.length) {
371
+ const start = starts.length > 1 && lowFirst[0] === "e" ? starts.at(-1) : starts[0];
372
+ return GUITAR.midis.slice(start, start + strings).reverse();
373
+ }
374
+ if (strings === 1) {
375
+ const chroma = chromaOf(upper(names[0]));
376
+ return chroma === null ? null : [48 + (chroma - 48 + 120) % 12];
377
+ }
378
+ const tuning = parseTuning(spelled);
379
+ if (tuning)
380
+ return tuning.reverse();
213
381
  }
214
- return strings === 6 ? null : BY_COUNT[strings] ?? null;
382
+ return BY_COUNT[strings] ?? null;
383
+ }
384
+ var drumBeatAt = (drums) => (padded, col) => {
385
+ const beat = [];
386
+ padded.forEach((line, i) => {
387
+ const hit = line[col];
388
+ if (!/[xXoOgfdb#@*+]/.test(hit))
389
+ return;
390
+ const name = articulationOf(drums[i], hit);
391
+ if (!beat.some((n) => n.startsWith(name + "{") || n === name))
392
+ beat.push(name + effectOf(hit));
393
+ });
394
+ return { beat, skip: 0 };
395
+ };
396
+ var quoted = (text) => `"${text.replace(/[\\"]/g, (c) => `\\${c}`)}"`;
397
+ function texOf(bars) {
398
+ let duration = 0;
399
+ const out = bars.map(({ beats, text }) => {
400
+ const wanted = beats.length ? 8 : 1;
401
+ const items = beats.length ? [...beats] : ["r"];
402
+ if (text)
403
+ items[items.length - 1] += `{txt ${quoted(text)}}`;
404
+ const head = wanted === duration ? "" : `:${wanted} `;
405
+ duration = wanted;
406
+ return head + items.join(" ");
407
+ });
408
+ return out.join(` |
409
+ `);
215
410
  }
216
411
  function textTabToAlphaTex(text) {
217
412
  const systems = systemsOf(text);
218
- if (!systems.length)
413
+ const first = systems[0];
414
+ if (!first)
219
415
  return null;
220
- const strings = systems[0].lines.length;
221
- const names = systems[0].names;
222
- const bars = systems.flatMap((s) => s.lines.length === strings ? barsOf(s.lines) : []);
416
+ const bars = [];
417
+ const add = (systemBars, texts) => {
418
+ const at = bars.length;
419
+ bars.push(...systemBars.map((b) => ({ beats: b.map(chord), text: null })));
420
+ if (texts.length && bars.length > at)
421
+ bars[bars.length - 1].text = texts.join(" / ");
422
+ };
423
+ const chord = (notes) => notes.length === 1 ? notes[0] : `(${notes.join(" ")})`;
424
+ if (first.kind === "drums") {
425
+ for (const s of systems)
426
+ if (s.kind === "drums")
427
+ add(barsOf(s.lines, drumBeatAt(s.drums)), s.texts);
428
+ if (!bars.length)
429
+ return null;
430
+ return ["\\instrument percussion", "\\articulation defaults", texOf(bars)].join(`
431
+ `);
432
+ }
433
+ const tuning = tuningOf(first.names);
434
+ const same = JSON.stringify(tuning);
435
+ for (const s of systems) {
436
+ if (s.kind !== "strings" || JSON.stringify(tuningOf(s.names)) !== same)
437
+ continue;
438
+ const noteBars = barsOf(s.lines, stringBeatAt);
439
+ add(noteBars.map((bar) => bar.map((beat) => beat.map((n) => `${n.fret}.${n.string}`))), s.texts);
440
+ }
223
441
  if (!bars.length)
224
442
  return null;
225
- const header = [];
226
- const tuning = tuningOf(names);
227
- if (tuning)
228
- header.push(`\\tuning (${[...tuning].reverse().map((m) => noteOf(m)).join(" ")})`);
229
- const beat = (notes) => notes.length === 1 ? `${notes[0].fret}.${notes[0].string}` : `(${notes.map((n) => `${n.fret}.${n.string}`).join(" ")})`;
230
- const body = bars.map((bar) => bar.map(beat).join(" ")).join(` |
231
- `);
232
- return [...header, `:8 ${body}`].join(`
443
+ const standard = tuning?.join(" ") === BY_COUNT[6].join(" ");
444
+ const header = tuning && !standard ? [`\\tuning (${tuning.map((m) => noteOf(m)).join(" ")})`] : [];
445
+ return [...header, texOf(bars)].join(`
233
446
  `);
234
447
  }
235
448
  // src/theory/note-set.ts
@@ -361,13 +574,16 @@ function markClasses(set, chroma, marks = {}) {
361
574
  classes.push("mn-char");
362
575
  if (marks.different?.has(chroma))
363
576
  classes.push("mn-diff");
577
+ if (marks.chordTones)
578
+ classes.push(marks.chordTones.has(chroma) ? "mn-tone" : "mn-passing");
364
579
  return classes.length ? ` ${classes.join(" ")}` : "";
365
580
  }
366
581
  function describeMarks(set, marks = {}) {
367
582
  const names = (chromas) => set.members.filter((m) => chromas?.has(m.chroma)).map((m) => m.name);
368
583
  const characteristic = names(marks.characteristic);
369
584
  const different = names(marks.different);
370
- return (characteristic.length ? `, characteristic notes: ${characteristic.join(" ")}` : "") + (different.length ? `, different from the compared scale: ${different.join(" ")}` : "");
585
+ const tones = names(marks.chordTones);
586
+ return (characteristic.length ? `, characteristic notes: ${characteristic.join(" ")}` : "") + (different.length ? `, different from the compared scale: ${different.join(" ")}` : "") + (tones.length ? `, chord tones: ${tones.join(" ")}` : "");
371
587
  }
372
588
  var memberFor = (set, chroma) => set.members.find((m) => m.chroma === chroma);
373
589
  var memberOf = (set, midi) => set.pitches && !set.pitches.includes(midi) ? undefined : memberFor(set, (midi % 12 + 12) % 12);
@@ -519,7 +735,13 @@ var QUALITY_SUFFIXES = [
519
735
  [/^(13|11|9|7|6)$/, "$1"],
520
736
  [/^(maj|M)?$/, "Major"]
521
737
  ];
522
- var spell = (note) => note[0] + (note[1] === "#" ? " Sharp" : note[1] === "b" ? " Flat" : "");
738
+ var ACCIDENTAL_WORDS = {
739
+ "#": " Sharp",
740
+ "##": " Double Sharp",
741
+ b: " Flat",
742
+ bb: " Double Flat"
743
+ };
744
+ var spellNote = (note) => note[0] + (ACCIDENTAL_WORDS[note.slice(1)] ?? "");
523
745
  var plain = (quality) => quality.replace(/\s*\([^)]*\)/g, "").trim();
524
746
  function parseChord(symbol) {
525
747
  const parts = splitChordSymbol(symbol);
@@ -551,7 +773,7 @@ function parseChord(symbol) {
551
773
  root,
552
774
  quality,
553
775
  bass,
554
- name: `${spell(root)} ${plain(quality)}${bass ? ` over ${spell(bass)}` : ""}`
776
+ name: `${spellNote(root)} ${plain(quality)}${bass ? ` over ${spellNote(bass)}` : ""}`
555
777
  };
556
778
  }
557
779
 
@@ -680,7 +902,26 @@ function messageOf(error, lineOffset) {
680
902
  }
681
903
  return error instanceof Error ? error.message : String(error);
682
904
  }
683
- var PROFILE = { tab: "Tab", score: "Score", both: "ScoreTab" };
905
+ var NEUTRAL_CLEF = 0;
906
+ function chooseStaves(staves, score) {
907
+ for (const track of score.tracks) {
908
+ for (const staff of track.staves) {
909
+ if (staff.isPercussion)
910
+ for (const bar of staff.bars ?? [])
911
+ bar.clef = NEUTRAL_CLEF;
912
+ const stringed = !staff.isPercussion && staff.tuning.length > 0;
913
+ if (staves === "both") {
914
+ staff.showStandardNotation = true;
915
+ staff.showTablature = stringed;
916
+ continue;
917
+ }
918
+ staff.showSlash = false;
919
+ staff.showNumbered = false;
920
+ staff.showTablature = staves === "tab" && stringed;
921
+ staff.showStandardNotation = !staff.showTablature;
922
+ }
923
+ }
924
+ }
684
925
  function rgbaOf(doc, color, alpha = 1) {
685
926
  const canvas = doc.createElement("canvas");
686
927
  canvas.width = 1;
@@ -917,7 +1158,7 @@ function renderTab(language, source, host, options) {
917
1158
  logLevel: at.LogLevel.Warning
918
1159
  },
919
1160
  display: {
920
- staveProfile: PROFILE[parsed.staves],
1161
+ staveProfile: "Default",
921
1162
  resources: colorsOf(el)
922
1163
  },
923
1164
  player: { playerMode: at.PlayerMode.Disabled, enableUserInteraction: true }
@@ -929,6 +1170,9 @@ function renderTab(language, source, host, options) {
929
1170
  return;
930
1171
  }
931
1172
  options.onApi?.(current);
1173
+ current.scoreLoaded.on((score) => {
1174
+ chooseStaves(parsed.staves, score);
1175
+ });
932
1176
  let bar = null;
933
1177
  current.renderFinished.on(() => {
934
1178
  if (settled || gone)
@@ -993,7 +1237,8 @@ function renderTab(language, source, host, options) {
993
1237
  var PROGRAMS = { guitar: 25, piano: 0 };
994
1238
  function soundfontPlayer(alphaTab, api) {
995
1239
  return {
996
- play(events, { sound, volume, onEnd }) {
1240
+ reportsStart: true,
1241
+ play(events, { sound, volume, onEnd, onStart }) {
997
1242
  const current = api();
998
1243
  const player = current?.player;
999
1244
  if (!current || !player)
@@ -1006,14 +1251,21 @@ function soundfontPlayer(alphaTab, api) {
1006
1251
  const level = Number.isFinite(volume) ? Math.min(1, Math.max(0, volume)) : 0.8;
1007
1252
  current.masterVolume = level;
1008
1253
  for (const e of events) {
1009
- handler.addNote(0, ticks(e.time), Math.max(1, ticks(e.duration)), e.midi, 100, 0);
1254
+ const velocity = e.velocity === undefined || !Number.isFinite(e.velocity) ? 100 : Math.round(Math.min(127, Math.max(1, e.velocity)));
1255
+ handler.addNote(0, ticks(e.time), Math.max(1, ticks(e.duration)), e.midi, velocity, 0);
1010
1256
  }
1011
1257
  const end = Math.max(...events.map((e) => e.time + e.duration), 0);
1012
1258
  current.playbackSpeed = 1;
1013
1259
  player.playOneTimeMidiFile(midi);
1260
+ let stopped = false;
1261
+ queueMicrotask(() => {
1262
+ if (!stopped)
1263
+ onStart?.();
1264
+ });
1014
1265
  const timer = setTimeout(() => onEnd?.(), (end + 0.2) * 1000);
1015
1266
  return {
1016
1267
  stop() {
1268
+ stopped = true;
1017
1269
  clearTimeout(timer);
1018
1270
  player.stop();
1019
1271
  }
@@ -1072,6 +1324,7 @@ function createSoundfontPlayer(alphaTab, assets, doc, fallback) {
1072
1324
  };
1073
1325
  const inner = soundfontPlayer(alphaTab, () => api);
1074
1326
  return {
1327
+ reportsStart: true,
1075
1328
  play(events, options) {
1076
1329
  let handle = null;
1077
1330
  let stopped = false;
@@ -1084,8 +1337,11 @@ function createSoundfontPlayer(alphaTab, assets, doc, fallback) {
1084
1337
  return;
1085
1338
  }
1086
1339
  } catch {}
1087
- if (fallback)
1088
- handle = fallback.play(events, options);
1340
+ if (!fallback)
1341
+ return;
1342
+ handle = fallback.play(events, options);
1343
+ if (!fallback.reportsStart)
1344
+ options.onStart?.();
1089
1345
  });
1090
1346
  return {
1091
1347
  stop() {
@@ -1134,5 +1390,5 @@ export {
1134
1390
  textTabToAlphaTex
1135
1391
  };
1136
1392
 
1137
- //# debugId=0CEA415E0C9C098764756E2164756E21
1393
+ //# debugId=38E7EB39910B180864756E2164756E21
1138
1394
  //# sourceMappingURL=index.js.map