@dsebastien/music-notation 0.8.0 → 0.9.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 +37 -5
- package/dist/chord/generate.d.ts +34 -9
- package/dist/chord/guitar.d.ts +18 -0
- package/dist/circle/circle.d.ts +8 -2
- package/dist/cli.js +1 -1
- package/dist/convert/text-tab.d.ts +56 -0
- package/dist/index.d.ts +9 -8
- package/dist/index.js +6599 -4673
- package/dist/index.js.map +32 -30
- package/dist/keyboard/keyboard.d.ts +17 -2
- package/dist/keyboard/piano-chord.d.ts +28 -3
- package/dist/keyboard/play-voicing.d.ts +10 -0
- package/dist/keyboard/scale-fingering.d.ts +41 -0
- package/dist/keyboard/voice-leading.d.ts +55 -4
- package/dist/music-notation.css +68 -5
- package/dist/music-notation.publish.min.js +91 -28
- package/dist/music-notation.tab.min.js +72 -9
- package/dist/playback/controls.d.ts +13 -2
- package/dist/playback/player.d.ts +69 -5
- package/dist/publish/index.js +5306 -3909
- package/dist/publish/index.js.map +31 -29
- package/dist/render/dom.d.ts +25 -1
- package/dist/strum/pattern.d.ts +25 -0
- package/dist/strum/play.d.ts +46 -5
- package/dist/strum/render.d.ts +4 -1
- package/dist/tab/index.d.ts +39 -0
- package/dist/tab/index.js +683 -75
- package/dist/tab/index.js.map +6 -6
- package/dist/theory/detect.d.ts +6 -2
- package/dist/theory/find.d.ts +35 -7
- package/dist/theory/keys.d.ts +8 -2
- package/dist/theory/note-set.d.ts +5 -0
- package/dist/theory/numerals.d.ts +34 -7
- package/dist/voicings/check.d.ts +17 -0
- package/dist/voicings/curated.d.ts +10 -0
- package/dist/voicings/index.d.ts +1 -1
- package/dist/voicings/index.js +429 -109
- package/dist/voicings/index.js.map +10 -8
- package/package.json +1 -1
package/dist/tab/index.js
CHANGED
|
@@ -33,15 +33,55 @@ function html(doc, tag, cls, text) {
|
|
|
33
33
|
el.textContent = text;
|
|
34
34
|
return el;
|
|
35
35
|
}
|
|
36
|
+
var NAME_PREFIX = `mn-name-${Math.random().toString(36).slice(2, 8)}-`;
|
|
37
|
+
var names = 0;
|
|
36
38
|
function svgRoot(doc, width, height, cls, label) {
|
|
39
|
+
const id = `${NAME_PREFIX}${++names}`;
|
|
40
|
+
const title = svg(doc, "title", { class: "mn-name", id });
|
|
41
|
+
title.textContent = label;
|
|
37
42
|
return svg(doc, "svg", {
|
|
38
43
|
xmlns: SVG_NS,
|
|
39
44
|
viewBox: `0 0 ${width} ${height}`,
|
|
40
45
|
width,
|
|
41
46
|
class: `mn-svg ${cls}`,
|
|
42
47
|
role: "img",
|
|
43
|
-
"aria-
|
|
48
|
+
"aria-labelledby": id
|
|
49
|
+
}, [svg(doc, "defs", {}, [title])]);
|
|
50
|
+
}
|
|
51
|
+
var nameElement = (el) => {
|
|
52
|
+
const id = el.getAttribute("aria-labelledby");
|
|
53
|
+
if (!id)
|
|
54
|
+
return null;
|
|
55
|
+
for (const candidate of el.querySelectorAll("[id]")) {
|
|
56
|
+
if (candidate.getAttribute("id") === id)
|
|
57
|
+
return candidate;
|
|
58
|
+
}
|
|
59
|
+
return el.ownerDocument.getElementById(id);
|
|
60
|
+
};
|
|
61
|
+
function accessibleName(el) {
|
|
62
|
+
const named = nameElement(el);
|
|
63
|
+
if (named)
|
|
64
|
+
return named.textContent;
|
|
65
|
+
return el.getAttribute("aria-label");
|
|
66
|
+
}
|
|
67
|
+
function setAccessibleName(el, name) {
|
|
68
|
+
const named = nameElement(el);
|
|
69
|
+
if (named)
|
|
70
|
+
named.textContent = name;
|
|
71
|
+
else
|
|
72
|
+
el.setAttribute("aria-label", name);
|
|
73
|
+
}
|
|
74
|
+
function playableMark(doc, area, ...children) {
|
|
75
|
+
const hit = svg(doc, "rect", {
|
|
76
|
+
class: "mn-hit",
|
|
77
|
+
x: area.x,
|
|
78
|
+
y: area.y,
|
|
79
|
+
width: area.width,
|
|
80
|
+
height: area.height,
|
|
81
|
+
fill: "transparent",
|
|
82
|
+
"pointer-events": "all"
|
|
44
83
|
});
|
|
84
|
+
return svg(doc, "g", { class: "mn-mark" }, [hit, ...children]);
|
|
45
85
|
}
|
|
46
86
|
|
|
47
87
|
// src/theory/pitch.ts
|
|
@@ -190,7 +230,7 @@ function articulationOf(drum, hit) {
|
|
|
190
230
|
return "KickHit";
|
|
191
231
|
}
|
|
192
232
|
}
|
|
193
|
-
var effectOf = (hit) => hit === "X" || hit === "O" ? "
|
|
233
|
+
var effectOf = (hit) => hit === "X" || hit === "O" ? ["ac"] : hit === "g" ? ["g"] : [];
|
|
194
234
|
var NOT_TAB = /[^-0-9xXoOgfdbhprsvt/\\~^().*<>#@+|:\s]|<(?!\d)/;
|
|
195
235
|
var COUNT = /^\s*(?:[xX]\s*\d{1,3}|\d{1,3}\s*[xX])\s*$/;
|
|
196
236
|
function splitText(line) {
|
|
@@ -210,7 +250,7 @@ function tabLineOf(raw) {
|
|
|
210
250
|
const m = STRING_PREFIX.exec(line);
|
|
211
251
|
const body = line.slice(m[0].length);
|
|
212
252
|
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 };
|
|
253
|
+
string = { name: m[1] ?? null, body, offset: m[0].length, barred: /[|:]$/.test(m[0]) };
|
|
214
254
|
let drum = null;
|
|
215
255
|
const d = DRUM_LINE.exec(line);
|
|
216
256
|
const name = d ? d[1].toLowerCase().replace(/[ .-]/g, "") : "";
|
|
@@ -248,16 +288,39 @@ function splitDrums(run) {
|
|
|
248
288
|
out.push(current);
|
|
249
289
|
return out;
|
|
250
290
|
}
|
|
251
|
-
|
|
252
|
-
|
|
291
|
+
var PM_LINE = /^[\sPpMm.\-_|=~]*$/;
|
|
292
|
+
var PM_MARK = /P\.?M/i;
|
|
293
|
+
function palmMutesOf(line) {
|
|
294
|
+
if (!PM_LINE.test(line) || !PM_MARK.test(line))
|
|
295
|
+
return [];
|
|
296
|
+
const ranges = [];
|
|
297
|
+
for (let i = 0;i < line.length; i++) {
|
|
298
|
+
const c = line[i];
|
|
299
|
+
const mark = (c === "P" || c === "p") && /^\.?[Mm]/.test(line.slice(i + 1, i + 3));
|
|
300
|
+
if (mark)
|
|
301
|
+
ranges.push([i, i]);
|
|
302
|
+
else if (c !== " " && ranges.length)
|
|
303
|
+
ranges[ranges.length - 1][1] = i;
|
|
304
|
+
}
|
|
305
|
+
return ranges;
|
|
306
|
+
}
|
|
307
|
+
function stringSystems(run, above = null) {
|
|
308
|
+
return splitStrings(run).flatMap((part, index) => {
|
|
253
309
|
const names = part.map((l) => l.string.name);
|
|
254
310
|
if (part.length < 3 && names.some((n) => n === null))
|
|
255
311
|
return [];
|
|
256
312
|
const lines = part.map((l) => l.string.body);
|
|
257
|
-
|
|
313
|
+
const offset = part[0].string.offset;
|
|
314
|
+
const muted = new Set;
|
|
315
|
+
if (index === 0 && above !== null)
|
|
316
|
+
for (const [a, b] of palmMutesOf(above))
|
|
317
|
+
for (let col = Math.max(a, offset);col <= b; col++)
|
|
318
|
+
muted.add(col - offset);
|
|
319
|
+
const openStart = part.some((l) => !l.string.barred);
|
|
320
|
+
return [{ kind: "strings", names, lines, texts: textsOf(part), muted, openStart }];
|
|
258
321
|
});
|
|
259
322
|
}
|
|
260
|
-
function systemsOfRun(run) {
|
|
323
|
+
function systemsOfRun(run, above) {
|
|
261
324
|
if (!run.length)
|
|
262
325
|
return [];
|
|
263
326
|
if (run.every((l) => l.drum) && run.some((l) => !l.string || !l.drum.lettered || /[xXoOgfdb#@*+]/.test(l.drum.body)))
|
|
@@ -268,7 +331,7 @@ function systemsOfRun(run) {
|
|
|
268
331
|
texts: textsOf(part)
|
|
269
332
|
}));
|
|
270
333
|
if (run.every((l) => l.string))
|
|
271
|
-
return stringSystems(run);
|
|
334
|
+
return stringSystems(run, above);
|
|
272
335
|
const out = [];
|
|
273
336
|
let stretch = [];
|
|
274
337
|
for (const l of [...run, null]) {
|
|
@@ -276,7 +339,7 @@ function systemsOfRun(run) {
|
|
|
276
339
|
stretch.push(l);
|
|
277
340
|
else {
|
|
278
341
|
if (stretch.length)
|
|
279
|
-
out.push(...stringSystems(stretch));
|
|
342
|
+
out.push(...stringSystems(stretch, out.length ? null : above));
|
|
280
343
|
stretch = [];
|
|
281
344
|
}
|
|
282
345
|
}
|
|
@@ -285,16 +348,21 @@ function systemsOfRun(run) {
|
|
|
285
348
|
function systemsOf(text) {
|
|
286
349
|
const systems = [];
|
|
287
350
|
let run = [];
|
|
351
|
+
let above = null;
|
|
352
|
+
let previous = null;
|
|
288
353
|
for (const raw of text.split(/\r?\n/)) {
|
|
289
354
|
const line = tabLineOf(raw);
|
|
290
|
-
if (line)
|
|
355
|
+
if (line) {
|
|
356
|
+
if (!run.length)
|
|
357
|
+
above = previous;
|
|
291
358
|
run.push(line);
|
|
292
|
-
else {
|
|
293
|
-
systems.push(...systemsOfRun(run));
|
|
359
|
+
} else {
|
|
360
|
+
systems.push(...systemsOfRun(run, above));
|
|
294
361
|
run = [];
|
|
295
362
|
}
|
|
363
|
+
previous = raw;
|
|
296
364
|
}
|
|
297
|
-
systems.push(...systemsOfRun(run));
|
|
365
|
+
systems.push(...systemsOfRun(run, above));
|
|
298
366
|
return systems;
|
|
299
367
|
}
|
|
300
368
|
function barsOf(lines, beatAt) {
|
|
@@ -303,49 +371,131 @@ function barsOf(lines, beatAt) {
|
|
|
303
371
|
const bars = [];
|
|
304
372
|
let beats = [];
|
|
305
373
|
let filled = false;
|
|
374
|
+
let start = 0;
|
|
306
375
|
for (let col = 0;col < width; col++) {
|
|
307
376
|
if (padded.every((l) => l[col] === "|" || l[col] === ":")) {
|
|
308
377
|
if (filled)
|
|
309
|
-
bars.push(beats);
|
|
378
|
+
bars.push({ beats, start, end: col });
|
|
310
379
|
beats = [];
|
|
311
380
|
filled = false;
|
|
381
|
+
start = col + 1;
|
|
312
382
|
continue;
|
|
313
383
|
}
|
|
314
384
|
if (padded.some((l) => l[col] !== " "))
|
|
315
385
|
filled = true;
|
|
316
|
-
const { beat, skip } = beatAt(padded, col);
|
|
386
|
+
const { beat, skip, at } = beatAt(padded, col);
|
|
317
387
|
if (beat.length)
|
|
318
|
-
beats.push(beat);
|
|
388
|
+
beats.push({ notes: beat, col: at ?? col });
|
|
319
389
|
col += skip;
|
|
320
390
|
}
|
|
321
391
|
if (filled)
|
|
322
|
-
bars.push(beats);
|
|
392
|
+
bars.push({ beats, start, end: width });
|
|
323
393
|
return bars;
|
|
324
394
|
}
|
|
325
|
-
|
|
395
|
+
var isDigit = (c) => c !== undefined && c >= "0" && c <= "9";
|
|
396
|
+
var twoDigits = (a, b) => (a === "1" || a === "2") && isDigit(b) && Number(a + b) <= 24;
|
|
397
|
+
function techniquesOf(body) {
|
|
398
|
+
const frets = new Map;
|
|
399
|
+
const effects = new Map;
|
|
400
|
+
const hidden = new Set;
|
|
401
|
+
const target = (at) => {
|
|
402
|
+
let j = at;
|
|
403
|
+
const open = body[j] === "(";
|
|
404
|
+
if (open)
|
|
405
|
+
j++;
|
|
406
|
+
if (!isDigit(body[j]))
|
|
407
|
+
return { fret: null, next: at };
|
|
408
|
+
const width = twoDigits(body[j], body[j + 1]) ? 2 : 1;
|
|
409
|
+
const fret = Number(body.slice(j, j + width));
|
|
410
|
+
for (let w = 0;w < width; w++)
|
|
411
|
+
hidden.add(j + w);
|
|
412
|
+
j += width;
|
|
413
|
+
if (open && body[j] === ")")
|
|
414
|
+
j++;
|
|
415
|
+
return { fret, next: j };
|
|
416
|
+
};
|
|
417
|
+
for (let i = 0;i < body.length; ) {
|
|
418
|
+
if (!isDigit(body[i]) || hidden.has(i)) {
|
|
419
|
+
i++;
|
|
420
|
+
continue;
|
|
421
|
+
}
|
|
422
|
+
const width = twoDigits(body[i], body[i + 1]) ? 2 : 1;
|
|
423
|
+
const fret = Number(body.slice(i, i + width));
|
|
424
|
+
frets.set(i, { fret, width });
|
|
425
|
+
const fx = [];
|
|
426
|
+
const before = body[i - 1];
|
|
427
|
+
let k = i + width;
|
|
428
|
+
if (before === "<" && body[k] === ">") {
|
|
429
|
+
fx.push("nh");
|
|
430
|
+
k++;
|
|
431
|
+
} else if ((before === "/" || before === "\\") && !/[\d)>]/.test(body[i - 2] ?? "-"))
|
|
432
|
+
fx.push(before === "/" ? "sib" : "sia");
|
|
433
|
+
if (body[k] === "b" || body[k] === "^") {
|
|
434
|
+
const up = target(k + 1);
|
|
435
|
+
k = up.next;
|
|
436
|
+
const semitones = up.fret !== null && up.fret > fret ? Math.min(up.fret - fret, 4) : 2;
|
|
437
|
+
const points = [0, semitones * 2];
|
|
438
|
+
if (body[k] === "r") {
|
|
439
|
+
const down = target(k + 1);
|
|
440
|
+
k = down.next;
|
|
441
|
+
const back = down.fret === null ? 0 : (down.fret - fret) * 2;
|
|
442
|
+
points.push(Math.min(points[1], Math.max(0, back)));
|
|
443
|
+
}
|
|
444
|
+
fx.push(`b (${points.join(" ")})`);
|
|
445
|
+
}
|
|
446
|
+
if (body[k] === "~" || body[k] === "v") {
|
|
447
|
+
fx.push("v");
|
|
448
|
+
while (body[k] === "~" || body[k] === "v")
|
|
449
|
+
k++;
|
|
450
|
+
}
|
|
451
|
+
const next = body[k];
|
|
452
|
+
const onto = isDigit(body[k + 1]) || body[k + 1] === "(" && isDigit(body[k + 2]);
|
|
453
|
+
if ((next === "h" || next === "p") && onto)
|
|
454
|
+
fx.push("h");
|
|
455
|
+
else if (next === "/" || next === "\\" || next === "s") {
|
|
456
|
+
if (onto)
|
|
457
|
+
fx.push("sl");
|
|
458
|
+
else if (next !== "s")
|
|
459
|
+
fx.push(next === "/" ? "sou" : "sod");
|
|
460
|
+
}
|
|
461
|
+
if (fx.length)
|
|
462
|
+
effects.set(i, fx);
|
|
463
|
+
i += width;
|
|
464
|
+
}
|
|
465
|
+
return { frets, effects };
|
|
466
|
+
}
|
|
467
|
+
var stringBeatAt = (lines, muted, numbers = []) => (padded, col) => {
|
|
326
468
|
const beat = [];
|
|
469
|
+
const strings = new Set;
|
|
470
|
+
let start = col;
|
|
327
471
|
let wide = false;
|
|
328
|
-
|
|
329
|
-
const c =
|
|
330
|
-
|
|
472
|
+
const read = (i, at) => {
|
|
473
|
+
const c = padded[i][at];
|
|
474
|
+
const pm = muted.has(at) ? ["pm"] : [];
|
|
475
|
+
if (c === "x" || c === "X") {
|
|
476
|
+
beat.push({ tex: `x.${numbers[i] ?? i + 1}`, effects: pm });
|
|
477
|
+
strings.add(i);
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
const note = lines[i].frets.get(at);
|
|
481
|
+
if (!note)
|
|
331
482
|
return;
|
|
332
|
-
|
|
333
|
-
if (two.length === 2)
|
|
483
|
+
if (note.width === 2 && at === col)
|
|
334
484
|
wide = true;
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
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;
|
|
345
|
-
beat.push({ fret: Number(two), string: i + 1 });
|
|
485
|
+
if (padded[i][at - 1] === "<")
|
|
486
|
+
start = Math.min(start, at - 1);
|
|
487
|
+
beat.push({
|
|
488
|
+
tex: `${note.fret}.${numbers[i] ?? i + 1}`,
|
|
489
|
+
effects: [...lines[i].effects.get(at) ?? [], ...pm],
|
|
490
|
+
string: numbers[i] ?? i + 1
|
|
346
491
|
});
|
|
347
|
-
|
|
348
|
-
}
|
|
492
|
+
strings.add(i);
|
|
493
|
+
};
|
|
494
|
+
padded.forEach((_, i) => read(i, col));
|
|
495
|
+
if (wide)
|
|
496
|
+
padded.forEach((_, i) => strings.has(i) || read(i, col + 1));
|
|
497
|
+
return { beat, skip: wide ? 1 : 0, at: start };
|
|
498
|
+
};
|
|
349
499
|
var BY_COUNT = {
|
|
350
500
|
3: [64, 59, 55],
|
|
351
501
|
4: [43, 38, 33, 28],
|
|
@@ -381,6 +531,15 @@ function tuningOf(names) {
|
|
|
381
531
|
}
|
|
382
532
|
return BY_COUNT[strings] ?? null;
|
|
383
533
|
}
|
|
534
|
+
function onGuitar(midi) {
|
|
535
|
+
const tuning = [...BY_COUNT[6]];
|
|
536
|
+
let index = tuning.indexOf(midi);
|
|
537
|
+
if (index < 0) {
|
|
538
|
+
index = tuning.reduce((best, m, i) => Math.abs(m - midi) < Math.abs(tuning[best] - midi) ? i : best, 0);
|
|
539
|
+
tuning[index] = midi;
|
|
540
|
+
}
|
|
541
|
+
return { tuning, string: index + 1 };
|
|
542
|
+
}
|
|
384
543
|
var drumBeatAt = (drums) => (padded, col) => {
|
|
385
544
|
const beat = [];
|
|
386
545
|
padded.forEach((line, i) => {
|
|
@@ -388,22 +547,341 @@ var drumBeatAt = (drums) => (padded, col) => {
|
|
|
388
547
|
if (!/[xXoOgfdb#@*+]/.test(hit))
|
|
389
548
|
return;
|
|
390
549
|
const name = articulationOf(drums[i], hit);
|
|
391
|
-
if (!beat.some((n) => n.
|
|
392
|
-
beat.push(name
|
|
550
|
+
if (!beat.some((n) => n.tex === name))
|
|
551
|
+
beat.push({ tex: name, effects: effectOf(hit) });
|
|
393
552
|
});
|
|
394
553
|
return { beat, skip: 0 };
|
|
395
554
|
};
|
|
555
|
+
var VALUES = [
|
|
556
|
+
[24, 1, true],
|
|
557
|
+
[16, 1, false],
|
|
558
|
+
[12, 2, true],
|
|
559
|
+
[8, 2, false],
|
|
560
|
+
[6, 4, true],
|
|
561
|
+
[4, 4, false],
|
|
562
|
+
[3, 8, true],
|
|
563
|
+
[2, 8, false],
|
|
564
|
+
[1, 16, false]
|
|
565
|
+
];
|
|
566
|
+
function valuesOf(sixteenths) {
|
|
567
|
+
const out = [];
|
|
568
|
+
for (let left = sixteenths;left > 0; ) {
|
|
569
|
+
const [length, duration, dotted] = VALUES.find(([n]) => n <= left);
|
|
570
|
+
out.push({ duration, dotted });
|
|
571
|
+
left -= length;
|
|
572
|
+
}
|
|
573
|
+
return out;
|
|
574
|
+
}
|
|
575
|
+
var COMMON = { ts: [4, 4], length: 16, beat: 4, grids: [1, 2, 4, 8, 16] };
|
|
576
|
+
var THREE_FOUR = { ts: [3, 4], length: 12, beat: 4, grids: [1, 3, 6, 12] };
|
|
577
|
+
var SIX_EIGHT = { ts: [6, 8], length: 12, beat: 6, grids: [1, 2, 6, 12] };
|
|
578
|
+
var TWELVE_EIGHT = { ts: [12, 8], length: 24, beat: 6, grids: [1, 2, 4, 12, 24] };
|
|
579
|
+
function keepsSpacing(cols, at) {
|
|
580
|
+
const lengths = new Map;
|
|
581
|
+
for (let i = 1;i < cols.length; i++) {
|
|
582
|
+
const gap = cols[i] - cols[i - 1];
|
|
583
|
+
const length = at[i] - at[i - 1];
|
|
584
|
+
if ((lengths.get(gap) ?? length) !== length)
|
|
585
|
+
return false;
|
|
586
|
+
lengths.set(gap, length);
|
|
587
|
+
}
|
|
588
|
+
const sorted = [...lengths].sort((a, b) => a[0] - b[0]);
|
|
589
|
+
return sorted.every(([, length], i) => i === 0 || length >= sorted[i - 1][1]);
|
|
590
|
+
}
|
|
591
|
+
var PLAIN = new Set(VALUES.map(([n]) => n));
|
|
592
|
+
function fit(cols, n, [origin, span], slack, ties, bar) {
|
|
593
|
+
const step = span / n;
|
|
594
|
+
if (step < 1 || ties && !Number.isInteger(step))
|
|
595
|
+
return null;
|
|
596
|
+
const at = [];
|
|
597
|
+
let error = 0;
|
|
598
|
+
for (const col of cols) {
|
|
599
|
+
const exact = (col - origin) / step;
|
|
600
|
+
const k = Math.round(exact);
|
|
601
|
+
const off = Math.abs(exact - k) * step;
|
|
602
|
+
if (k < 0 || k >= n || off > slack + 0.000000001 || at.length && k * (bar / n) <= at.at(-1))
|
|
603
|
+
return null;
|
|
604
|
+
error = Math.max(error, off);
|
|
605
|
+
at.push(k * (bar / n));
|
|
606
|
+
}
|
|
607
|
+
if (!ties && at.some((p, i) => !PLAIN.has((at[i + 1] ?? bar) - p)))
|
|
608
|
+
return null;
|
|
609
|
+
return keepsSpacing(cols, at) ? { at, error } : null;
|
|
610
|
+
}
|
|
611
|
+
function positionsOf(cols, width, pad, meter = COMMON) {
|
|
612
|
+
if (!cols.length)
|
|
613
|
+
return [];
|
|
614
|
+
const spans = [
|
|
615
|
+
[pad, width - pad],
|
|
616
|
+
[pad, width]
|
|
617
|
+
];
|
|
618
|
+
if (cols[0] > pad)
|
|
619
|
+
spans.push([0, width]);
|
|
620
|
+
for (const [slack, ties] of [
|
|
621
|
+
[0.4, false],
|
|
622
|
+
[1, false],
|
|
623
|
+
[0.4, true]
|
|
624
|
+
])
|
|
625
|
+
for (const n of meter.grids) {
|
|
626
|
+
const fits = spans.map((span) => fit(cols, n, span, slack, ties, meter.length)).filter((f) => f !== null);
|
|
627
|
+
if (fits.length)
|
|
628
|
+
return fits.reduce((a, b) => b.error < a.error ? b : a).at;
|
|
629
|
+
}
|
|
630
|
+
return null;
|
|
631
|
+
}
|
|
632
|
+
function restsFrom(at, meter, end = meter.length) {
|
|
633
|
+
const out = [];
|
|
634
|
+
const { beat, length: bar } = meter;
|
|
635
|
+
for (let p = at;p < end; ) {
|
|
636
|
+
const half = bar === 4 * beat && p % (2 * beat) === 0 && p <= bar / 2 ? [2 * beat] : [];
|
|
637
|
+
const lengths = p % 2 ? [1] : p % beat ? [2, 1] : [...half, beat, 2, 1];
|
|
638
|
+
const length = lengths.find((n) => n <= end - p);
|
|
639
|
+
out.push({ beat: -1, sixteenths: length });
|
|
640
|
+
p += length;
|
|
641
|
+
}
|
|
642
|
+
return out;
|
|
643
|
+
}
|
|
644
|
+
function sketchRhythmOf(cols, meter = COMMON) {
|
|
645
|
+
const gaps = cols.slice(1).map((c, i) => c - cols[i]);
|
|
646
|
+
const counts = new Map;
|
|
647
|
+
for (const g of gaps)
|
|
648
|
+
counts.set(g, (counts.get(g) ?? 0) + 1);
|
|
649
|
+
const unit = [...counts].reduce((best, e) => !best || e[1] > best[1] || e[1] === best[1] && e[0] < best[0] ? e : best, null)?.[0];
|
|
650
|
+
for (const eighth of [2, 1]) {
|
|
651
|
+
const lengths = cols.map((_, i) => eighth * (i < gaps.length ? Math.max(1, Math.round(gaps[i] / unit)) : 1));
|
|
652
|
+
const total = lengths.reduce((a, b) => a + b, 0);
|
|
653
|
+
if (total > meter.length)
|
|
654
|
+
continue;
|
|
655
|
+
return [
|
|
656
|
+
...lengths.map((sixteenths, beat) => ({ beat, sixteenths })),
|
|
657
|
+
...restsFrom(total, meter)
|
|
658
|
+
];
|
|
659
|
+
}
|
|
660
|
+
return cols.map((_, beat) => ({ beat, sixteenths: 1 }));
|
|
661
|
+
}
|
|
662
|
+
function rhythmOf(m, typical, meter) {
|
|
663
|
+
const bar = meter.length;
|
|
664
|
+
const span = m.part === "whole" ? m.width : typical;
|
|
665
|
+
const shift = m.part === "end" ? typical - m.width : 0;
|
|
666
|
+
const cols = m.beats.map((b) => b.col + shift);
|
|
667
|
+
if (m.part === "start" && cols.length) {
|
|
668
|
+
const at = positionsOf([...cols, m.width], span, m.pad, meter);
|
|
669
|
+
if (at) {
|
|
670
|
+
const end = at.pop();
|
|
671
|
+
const out = at[0] > 0 ? [{ beat: -1, sixteenths: at[0] }] : [];
|
|
672
|
+
at.forEach((p, beat) => out.push({ beat, sixteenths: (at[beat + 1] ?? end) - p }));
|
|
673
|
+
return [...out, ...restsFrom(end, meter)];
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
const at = positionsOf(cols, span, m.pad, meter);
|
|
677
|
+
if (!at) {
|
|
678
|
+
const sketch = sketchRhythmOf(m.beats.map((b) => b.col), meter);
|
|
679
|
+
if (m.part !== "end")
|
|
680
|
+
return sketch;
|
|
681
|
+
const notes = sketch.filter((e) => e.beat >= 0);
|
|
682
|
+
const total = notes.reduce((sum, e) => sum + e.sixteenths, 0);
|
|
683
|
+
return m.pickup ? notes : [...restsFrom(0, meter, bar - total), ...notes];
|
|
684
|
+
}
|
|
685
|
+
const first = at[0];
|
|
686
|
+
const out = first === 0 || m.pickup ? [] : m.part === "end" ? restsFrom(0, meter, first) : [{ beat: -1, sixteenths: first }];
|
|
687
|
+
at.forEach((p, beat) => out.push({ beat, sixteenths: (at[beat + 1] ?? bar) - p }));
|
|
688
|
+
return out;
|
|
689
|
+
}
|
|
690
|
+
var padOf = (bars) => bars.reduce((pad, b) => b.beats.length ? Math.min(pad, b.beats[0].col - b.start) : pad, 3);
|
|
691
|
+
function rowOf(lines, bars, texts, openStart) {
|
|
692
|
+
const width = Math.max(...lines.map((l) => l.length));
|
|
693
|
+
return {
|
|
694
|
+
bars,
|
|
695
|
+
pad: padOf(bars),
|
|
696
|
+
texts,
|
|
697
|
+
openStart: openStart && bars[0]?.start === 0,
|
|
698
|
+
openEnd: bars.at(-1)?.end === width
|
|
699
|
+
};
|
|
700
|
+
}
|
|
701
|
+
function typicalWidth(rows) {
|
|
702
|
+
const widths = [];
|
|
703
|
+
for (const row of rows)
|
|
704
|
+
row.bars.forEach((bar, i) => {
|
|
705
|
+
const closed = (i > 0 || !row.openStart) && (i < row.bars.length - 1 || !row.openEnd);
|
|
706
|
+
if (closed && bar.beats.length)
|
|
707
|
+
widths.push(bar.end - bar.start);
|
|
708
|
+
});
|
|
709
|
+
if (widths.length < 2)
|
|
710
|
+
return null;
|
|
711
|
+
widths.sort((a, b) => a - b);
|
|
712
|
+
return widths[widths.length >> 1];
|
|
713
|
+
}
|
|
714
|
+
function mostFrequent(values) {
|
|
715
|
+
const counts = new Map;
|
|
716
|
+
for (const v of values)
|
|
717
|
+
counts.set(v, (counts.get(v) ?? 0) + 1);
|
|
718
|
+
let best;
|
|
719
|
+
for (const [value, count] of counts)
|
|
720
|
+
if (!best || count > best.count || count === best.count && value < best.value)
|
|
721
|
+
best = { value, count };
|
|
722
|
+
return best;
|
|
723
|
+
}
|
|
724
|
+
function meterOf(rows, typical) {
|
|
725
|
+
if (typical === null)
|
|
726
|
+
return COMMON;
|
|
727
|
+
const bars = [];
|
|
728
|
+
for (const row of rows)
|
|
729
|
+
row.bars.forEach((bar, i) => {
|
|
730
|
+
const closed = (i > 0 || !row.openStart) && (i < row.bars.length - 1 || !row.openEnd);
|
|
731
|
+
const width = bar.end - bar.start;
|
|
732
|
+
if (closed && bar.beats.length && Math.abs(width - typical) <= 1)
|
|
733
|
+
bars.push({ bar, pad: row.pad });
|
|
734
|
+
});
|
|
735
|
+
const gaps = new Map;
|
|
736
|
+
for (const { bar } of bars)
|
|
737
|
+
for (let i = 1;i < bar.beats.length; i++) {
|
|
738
|
+
const gap = bar.beats[i].col - bar.beats[i - 1].col;
|
|
739
|
+
gaps.set(gap, (gaps.get(gap) ?? 0) + 1);
|
|
740
|
+
}
|
|
741
|
+
const top = Math.max(0, ...gaps.values());
|
|
742
|
+
const unit = Math.min(...[...gaps].filter(([, n]) => n * 2 >= top).map(([gap]) => gap));
|
|
743
|
+
if (bars.length < 2 || !Number.isFinite(unit))
|
|
744
|
+
return COMMON;
|
|
745
|
+
const counts = [];
|
|
746
|
+
let twos = 0;
|
|
747
|
+
let threes = 0;
|
|
748
|
+
for (const { bar, pad } of bars) {
|
|
749
|
+
const exact = bar.beats.map((b) => (b.col - bar.start - pad) / unit);
|
|
750
|
+
if (exact.some((u) => Math.abs(u - Math.round(u)) * unit > 0.4 + 0.000000001)) {
|
|
751
|
+
counts.push(0);
|
|
752
|
+
continue;
|
|
753
|
+
}
|
|
754
|
+
const at = exact.map(Math.round);
|
|
755
|
+
const count = Math.max(Math.ceil((bar.end - bar.start - pad) / unit - 0.5), at.at(-1) + 1);
|
|
756
|
+
counts.push(count);
|
|
757
|
+
if (count !== 6)
|
|
758
|
+
continue;
|
|
759
|
+
const lowest = bar.beats.reduce((low, b) => b.notes.reduce((l, n) => Math.max(l, n.string ?? 0), low), 0);
|
|
760
|
+
const bass = at.filter((_, i) => bar.beats[i].notes.some((n) => n.string === lowest));
|
|
761
|
+
for (const group of [at, bass.length < at.length ? bass : []]) {
|
|
762
|
+
if (group.some((u) => u !== 0 && u % 2 === 0) && group.every((u) => u % 2 === 0))
|
|
763
|
+
twos++;
|
|
764
|
+
else if (group.includes(3) && group.every((u) => u % 3 === 0))
|
|
765
|
+
threes++;
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
const most = mostFrequent(counts);
|
|
769
|
+
if (most.count * 3 < bars.length * 2)
|
|
770
|
+
return COMMON;
|
|
771
|
+
if (most.value === 3)
|
|
772
|
+
return THREE_FOUR;
|
|
773
|
+
if (most.value === 6)
|
|
774
|
+
return twos > threes ? THREE_FOUR : SIX_EIGHT;
|
|
775
|
+
return most.value === 12 ? TWELVE_EIGHT : COMMON;
|
|
776
|
+
}
|
|
777
|
+
function measuresOf(rows, typical) {
|
|
778
|
+
const short = (width) => typical !== null && width <= typical * 2 / 3;
|
|
779
|
+
const out = [];
|
|
780
|
+
let carry = null;
|
|
781
|
+
rows.forEach((row, r) => {
|
|
782
|
+
const before = out.length;
|
|
783
|
+
const next = rows[r + 1];
|
|
784
|
+
row.bars.forEach((bar, i) => {
|
|
785
|
+
const beats = bar.beats.map((b) => ({ notes: b.notes, col: b.col - bar.start }));
|
|
786
|
+
let m = {
|
|
787
|
+
beats,
|
|
788
|
+
width: bar.end - bar.start,
|
|
789
|
+
pad: row.pad,
|
|
790
|
+
part: "whole",
|
|
791
|
+
pickup: false,
|
|
792
|
+
text: null
|
|
793
|
+
};
|
|
794
|
+
const joined = i === 0 && carry !== null;
|
|
795
|
+
if (carry && i === 0) {
|
|
796
|
+
const shift = carry.width - row.pad;
|
|
797
|
+
m = {
|
|
798
|
+
...carry,
|
|
799
|
+
beats: [
|
|
800
|
+
...carry.beats,
|
|
801
|
+
...beats.map((b) => ({ notes: b.notes, col: b.col + shift }))
|
|
802
|
+
],
|
|
803
|
+
width: carry.width + m.width - row.pad
|
|
804
|
+
};
|
|
805
|
+
carry = null;
|
|
806
|
+
}
|
|
807
|
+
if (i === row.bars.length - 1 && short(m.width)) {
|
|
808
|
+
const after = next?.bars[0];
|
|
809
|
+
const together = after ? m.width + after.end - after.start - next.pad : 0;
|
|
810
|
+
if (after && (row.openEnd || short(after.end - after.start) && (next.openStart || together <= typical * 1.25))) {
|
|
811
|
+
if (m.beats.length || !row.openEnd)
|
|
812
|
+
carry = m;
|
|
813
|
+
return;
|
|
814
|
+
}
|
|
815
|
+
if (row.openEnd && !joined) {
|
|
816
|
+
if (!m.beats.length)
|
|
817
|
+
return;
|
|
818
|
+
m.part = "start";
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
const first = !out.length;
|
|
822
|
+
if (i === 0 && !joined && m.part === "whole" && short(m.width) && m.beats.length) {
|
|
823
|
+
if (first || row.openStart) {
|
|
824
|
+
m.part = "end";
|
|
825
|
+
m.pickup = first;
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
out.push(m);
|
|
829
|
+
});
|
|
830
|
+
const target = carry ?? (out.length > before ? out.at(-1) : null);
|
|
831
|
+
if (row.texts.length && target) {
|
|
832
|
+
const text = row.texts.join(" / ");
|
|
833
|
+
target.text = target.text ? `${target.text} / ${text}` : text;
|
|
834
|
+
}
|
|
835
|
+
});
|
|
836
|
+
return out;
|
|
837
|
+
}
|
|
396
838
|
var quoted = (text) => `"${text.replace(/[\\"]/g, (c) => `\\${c}`)}"`;
|
|
397
|
-
|
|
839
|
+
var withEffects = (tex, effects) => effects.length ? `${tex}{${effects.join(" ")}}` : tex;
|
|
840
|
+
function beatTex(notes, effects) {
|
|
841
|
+
if (!notes.length)
|
|
842
|
+
return withEffects("r", effects);
|
|
843
|
+
if (notes.length === 1)
|
|
844
|
+
return withEffects(notes[0].tex, [...notes[0].effects, ...effects]);
|
|
845
|
+
return withEffects(`(${notes.map((n) => withEffects(n.tex, n.effects)).join(" ")})`, effects);
|
|
846
|
+
}
|
|
847
|
+
var LINKS = new Set(["h", "sl", "sou", "sod"]);
|
|
848
|
+
function tied(notes, pieces) {
|
|
849
|
+
if (pieces === 1)
|
|
850
|
+
return [notes];
|
|
851
|
+
const out = [notes.map((n) => ({ ...n, effects: n.effects.filter((e) => !LINKS.has(e)) }))];
|
|
852
|
+
for (let piece = 1;piece < pieces; piece++)
|
|
853
|
+
out.push(notes.filter((n) => n.string !== undefined).map((n) => ({
|
|
854
|
+
tex: `-.${n.string}`,
|
|
855
|
+
effects: n.effects.filter((e) => e === "pm" || piece === pieces - 1 && LINKS.has(e))
|
|
856
|
+
})));
|
|
857
|
+
return out;
|
|
858
|
+
}
|
|
859
|
+
function texOf(bars, meter) {
|
|
398
860
|
let duration = 0;
|
|
399
|
-
const out = bars.map(({ beats, text }) => {
|
|
400
|
-
const
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
const
|
|
405
|
-
|
|
406
|
-
|
|
861
|
+
const out = bars.map(({ beats, rhythm, text, pickup }) => {
|
|
862
|
+
const items = [];
|
|
863
|
+
if (!beats.length)
|
|
864
|
+
for (const value of meter === COMMON ? [{ duration: 1, dotted: false }] : valuesOf(meter.length))
|
|
865
|
+
items.push({ notes: [], ...value });
|
|
866
|
+
for (const { beat, sixteenths } of rhythm) {
|
|
867
|
+
const values = valuesOf(sixteenths);
|
|
868
|
+
const notes = tied(beat >= 0 ? beats[beat] : [], values.length);
|
|
869
|
+
values.forEach((value, i) => items.push({ notes: notes[i], ...value }));
|
|
870
|
+
}
|
|
871
|
+
let annotated = items.length - 1;
|
|
872
|
+
while (annotated > 0 && !items[annotated].notes.length)
|
|
873
|
+
annotated--;
|
|
874
|
+
if (!items[annotated].notes.length)
|
|
875
|
+
annotated = items.length - 1;
|
|
876
|
+
const tex = items.map((item, i) => {
|
|
877
|
+
const effects = item.dotted ? ["d"] : [];
|
|
878
|
+
if (text && i === annotated)
|
|
879
|
+
effects.push(`txt ${quoted(text)}`);
|
|
880
|
+
const head = item.duration === duration ? "" : `:${item.duration} `;
|
|
881
|
+
duration = item.duration;
|
|
882
|
+
return head + beatTex(item.notes, effects);
|
|
883
|
+
}).join(" ");
|
|
884
|
+
return pickup ? `\\ac ${tex}` : tex;
|
|
407
885
|
});
|
|
408
886
|
return out.join(` |
|
|
409
887
|
`);
|
|
@@ -413,36 +891,47 @@ function textTabToAlphaTex(text) {
|
|
|
413
891
|
const first = systems[0];
|
|
414
892
|
if (!first)
|
|
415
893
|
return null;
|
|
416
|
-
|
|
417
|
-
const
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
bars[bars.length - 1].text = texts.join(" / ");
|
|
422
|
-
};
|
|
423
|
-
const chord = (notes) => notes.length === 1 ? notes[0] : `(${notes.join(" ")})`;
|
|
894
|
+
let tuning = first.kind === "strings" ? tuningOf(first.names) : null;
|
|
895
|
+
const lone = tuning?.length === 1 ? onGuitar(tuning[0]) : null;
|
|
896
|
+
if (lone)
|
|
897
|
+
tuning = lone.tuning;
|
|
898
|
+
const rows = [];
|
|
424
899
|
if (first.kind === "drums") {
|
|
425
900
|
for (const s of systems)
|
|
426
901
|
if (s.kind === "drums")
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
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);
|
|
902
|
+
rows.push(rowOf(s.lines, barsOf(s.lines, drumBeatAt(s.drums)), s.texts, false));
|
|
903
|
+
} else {
|
|
904
|
+
const same = JSON.stringify(tuningOf(first.names));
|
|
905
|
+
const strings = lone ? [lone.string] : [];
|
|
906
|
+
for (const s of systems) {
|
|
907
|
+
if (s.kind !== "strings" || JSON.stringify(tuningOf(s.names)) !== same)
|
|
908
|
+
continue;
|
|
909
|
+
const beatAt = stringBeatAt(s.lines.map(techniquesOf), s.muted, strings);
|
|
910
|
+
rows.push(rowOf(s.lines, barsOf(s.lines, beatAt), s.texts, s.openStart));
|
|
911
|
+
}
|
|
440
912
|
}
|
|
913
|
+
const typical = typicalWidth(rows);
|
|
914
|
+
const meter = meterOf(rows, typical);
|
|
915
|
+
const bars = measuresOf(rows, typical).map((m) => ({
|
|
916
|
+
beats: m.beats.map((b) => b.notes),
|
|
917
|
+
rhythm: rhythmOf(m, typical ?? 0, meter),
|
|
918
|
+
text: m.text,
|
|
919
|
+
pickup: m.pickup
|
|
920
|
+
}));
|
|
441
921
|
if (!bars.length)
|
|
442
922
|
return null;
|
|
923
|
+
const ts = meter === COMMON ? [] : [`\\ts ${meter.ts.join(" ")}`];
|
|
924
|
+
if (first.kind === "drums")
|
|
925
|
+
return [
|
|
926
|
+
"\\instrument percussion",
|
|
927
|
+
"\\articulation defaults",
|
|
928
|
+
...ts,
|
|
929
|
+
texOf(bars, meter)
|
|
930
|
+
].join(`
|
|
931
|
+
`);
|
|
443
932
|
const standard = tuning?.join(" ") === BY_COUNT[6].join(" ");
|
|
444
933
|
const header = tuning && !standard ? [`\\tuning (${tuning.map((m) => noteOf(m)).join(" ")})`] : [];
|
|
445
|
-
return [...header, texOf(bars)].join(`
|
|
934
|
+
return [...header, ...ts, texOf(bars, meter)].join(`
|
|
446
935
|
`);
|
|
447
936
|
}
|
|
448
937
|
// src/theory/note-set.ts
|
|
@@ -655,6 +1144,14 @@ function chordNoteSet(symbol) {
|
|
|
655
1144
|
}
|
|
656
1145
|
return set;
|
|
657
1146
|
}
|
|
1147
|
+
function respell(set, chord) {
|
|
1148
|
+
set.root = chord.root;
|
|
1149
|
+
for (const member of set.members) {
|
|
1150
|
+
const own = memberFor(chord, member.chroma);
|
|
1151
|
+
if (own)
|
|
1152
|
+
member.name = own.name;
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
658
1155
|
function scaleNoteSet(name) {
|
|
659
1156
|
const scale = Scale2.get(scaleName(name));
|
|
660
1157
|
if (scale.empty || !scale.tonic)
|
|
@@ -852,7 +1349,14 @@ var alphaTabCdn = (version = ALPHATAB_VERSION) => {
|
|
|
852
1349
|
var SETTING = /^\s*(staves|file|tracks?)\s*:\s*(.*)$/i;
|
|
853
1350
|
function parseTabSource(language, source) {
|
|
854
1351
|
const lines = source.split(/\r?\n/);
|
|
855
|
-
const out = {
|
|
1352
|
+
const out = {
|
|
1353
|
+
staves: language,
|
|
1354
|
+
stavesWritten: false,
|
|
1355
|
+
file: null,
|
|
1356
|
+
tracks: null,
|
|
1357
|
+
tex: "",
|
|
1358
|
+
texLine: 0
|
|
1359
|
+
};
|
|
856
1360
|
let i = 0;
|
|
857
1361
|
for (;i < lines.length; i++) {
|
|
858
1362
|
const line = lines[i];
|
|
@@ -869,6 +1373,7 @@ function parseTabSource(language, source) {
|
|
|
869
1373
|
throw new Error(`staves: use tab, score or both, got "${value}"`);
|
|
870
1374
|
}
|
|
871
1375
|
out.staves = v;
|
|
1376
|
+
out.stavesWritten = true;
|
|
872
1377
|
} else if (key === "file") {
|
|
873
1378
|
out.file = value.replace(/^!?\[\[|\]\]$/g, "").split(/[|#]/)[0].trim() || null;
|
|
874
1379
|
} else {
|
|
@@ -922,6 +1427,26 @@ function chooseStaves(staves, score) {
|
|
|
922
1427
|
}
|
|
923
1428
|
}
|
|
924
1429
|
}
|
|
1430
|
+
var DEFAULT_DYNAMIC = 5;
|
|
1431
|
+
function hideDefaultDynamics(score, tex) {
|
|
1432
|
+
if (tex !== null && /\bdy\b|\\showdynamics/i.test(tex))
|
|
1433
|
+
return;
|
|
1434
|
+
const written = score.tracks.some((track) => track.staves.some((staff) => staff.bars.some((bar) => bar.voices.some((voice) => voice.beats.some((beat) => !beat.isRest && beat.dynamics !== DEFAULT_DYNAMIC)))));
|
|
1435
|
+
if (!written)
|
|
1436
|
+
score.stylesheet.hideDynamics = true;
|
|
1437
|
+
}
|
|
1438
|
+
var CREDIT = "rendered by alphaTab";
|
|
1439
|
+
function hideCredit(api, surface) {
|
|
1440
|
+
const renderer = api.renderer;
|
|
1441
|
+
renderer?.partialRenderFinished?.on((e) => {
|
|
1442
|
+
for (const part of surface.querySelectorAll(".at-surface > div")) {
|
|
1443
|
+
if (part.layoutResultId !== e.id)
|
|
1444
|
+
continue;
|
|
1445
|
+
const credit = typeof e.renderResult === "string" && e.renderResult.includes(CREDIT);
|
|
1446
|
+
part.style.visibility = credit ? "hidden" : "";
|
|
1447
|
+
}
|
|
1448
|
+
});
|
|
1449
|
+
}
|
|
925
1450
|
function rgbaOf(doc, color, alpha = 1) {
|
|
926
1451
|
const canvas = doc.createElement("canvas");
|
|
927
1452
|
canvas.width = 1;
|
|
@@ -1002,6 +1527,7 @@ var time = (ms) => {
|
|
|
1002
1527
|
};
|
|
1003
1528
|
function playerBar(doc, api, alphaTab, assets) {
|
|
1004
1529
|
const bar = html(doc, "div", "mn-play mn-tab-bar");
|
|
1530
|
+
bar.addEventListener("mousedown", (event) => event.stopPropagation());
|
|
1005
1531
|
bar.setAttribute("role", "group");
|
|
1006
1532
|
bar.setAttribute("aria-label", "Playback");
|
|
1007
1533
|
const state = { loop: false, metronome: false, countIn: false, speed: 1, volume: 1 };
|
|
@@ -1115,6 +1641,55 @@ function playerBar(doc, api, alphaTab, assets) {
|
|
|
1115
1641
|
}
|
|
1116
1642
|
};
|
|
1117
1643
|
}
|
|
1644
|
+
function hasTablature(score, tracks) {
|
|
1645
|
+
return score.tracks.some((track, i) => (!tracks || tracks.includes(i + 1)) && track.staves.some((staff) => !staff.isPercussion && staff.tuning.length > 0));
|
|
1646
|
+
}
|
|
1647
|
+
var VIEWS = [
|
|
1648
|
+
{ staves: "tab", label: "Tab", what: "tablature" },
|
|
1649
|
+
{ staves: "score", label: "Score", what: "standard notation" },
|
|
1650
|
+
{ staves: "both", label: "Both", what: "standard notation and tablature" }
|
|
1651
|
+
];
|
|
1652
|
+
function viewControl(doc, own, choose, keep) {
|
|
1653
|
+
const group = html(doc, "span", "mn-tab-views");
|
|
1654
|
+
group.setAttribute("role", "group");
|
|
1655
|
+
group.setAttribute("aria-label", "View");
|
|
1656
|
+
let current = own.staves;
|
|
1657
|
+
const keepButton = keep ? html(doc, "button", "mn-tab-keep", "Keep this view") : null;
|
|
1658
|
+
const buttons = VIEWS.map(({ staves, label, what }) => {
|
|
1659
|
+
const b = html(doc, "button", "mn-tab-view", label);
|
|
1660
|
+
b.type = "button";
|
|
1661
|
+
b.dataset["staves"] = staves;
|
|
1662
|
+
const mine = staves !== own.staves ? "" : own.written ? ` (this block's staves: line)` : " (the default: the block has no staves: line)";
|
|
1663
|
+
b.title = `Draw as ${what}${mine}`;
|
|
1664
|
+
b.addEventListener("click", () => {
|
|
1665
|
+
if (staves === current)
|
|
1666
|
+
return;
|
|
1667
|
+
current = staves;
|
|
1668
|
+
show();
|
|
1669
|
+
choose(staves);
|
|
1670
|
+
});
|
|
1671
|
+
group.appendChild(b);
|
|
1672
|
+
return b;
|
|
1673
|
+
});
|
|
1674
|
+
const show = () => {
|
|
1675
|
+
for (const b of buttons) {
|
|
1676
|
+
const on = b.dataset["staves"] === current;
|
|
1677
|
+
b.classList.toggle("mn-on", on);
|
|
1678
|
+
b.setAttribute("aria-pressed", String(on));
|
|
1679
|
+
}
|
|
1680
|
+
if (keepButton) {
|
|
1681
|
+
keepButton.hidden = current === own.staves;
|
|
1682
|
+
keepButton.title = `Write staves: ${current} at the top of the block`;
|
|
1683
|
+
}
|
|
1684
|
+
};
|
|
1685
|
+
if (keepButton && keep) {
|
|
1686
|
+
keepButton.type = "button";
|
|
1687
|
+
keepButton.addEventListener("click", () => keep(current));
|
|
1688
|
+
group.appendChild(keepButton);
|
|
1689
|
+
}
|
|
1690
|
+
show();
|
|
1691
|
+
return group;
|
|
1692
|
+
}
|
|
1118
1693
|
function renderTab(language, source, host, options) {
|
|
1119
1694
|
const doc = host.ownerDocument;
|
|
1120
1695
|
const el = html(doc, "div", `mn-block mn-block-${language} mn-tab`);
|
|
@@ -1143,6 +1718,12 @@ function renderTab(language, source, host, options) {
|
|
|
1143
1718
|
(async () => {
|
|
1144
1719
|
await Promise.resolve();
|
|
1145
1720
|
const parsed = parseTabSource(language, source);
|
|
1721
|
+
const own = {
|
|
1722
|
+
staves: parsed.stavesWritten ? parsed.staves : options.defaultStaves ?? parsed.staves,
|
|
1723
|
+
written: parsed.stavesWritten
|
|
1724
|
+
};
|
|
1725
|
+
let view = own.staves;
|
|
1726
|
+
let tablature = false;
|
|
1146
1727
|
const at = options.alphaTab;
|
|
1147
1728
|
if (!at?.AlphaTabApi)
|
|
1148
1729
|
throw new Error("alphaTab isn't loaded");
|
|
@@ -1155,7 +1736,8 @@ function renderTab(language, source, host, options) {
|
|
|
1155
1736
|
useWorkers: Boolean(assets.scriptFile),
|
|
1156
1737
|
...assets.scriptFile ? { scriptFile: assets.scriptFile } : {},
|
|
1157
1738
|
smuflFontSources: made.map([[at.FontFileFormat.Woff2, assets.font]]),
|
|
1158
|
-
logLevel: at.LogLevel.Warning
|
|
1739
|
+
logLevel: at.LogLevel.Warning,
|
|
1740
|
+
enableLazyLoading: false
|
|
1159
1741
|
},
|
|
1160
1742
|
display: {
|
|
1161
1743
|
staveProfile: "Default",
|
|
@@ -1170,9 +1752,14 @@ function renderTab(language, source, host, options) {
|
|
|
1170
1752
|
return;
|
|
1171
1753
|
}
|
|
1172
1754
|
options.onApi?.(current);
|
|
1755
|
+
let written = [];
|
|
1173
1756
|
current.scoreLoaded.on((score) => {
|
|
1174
|
-
|
|
1757
|
+
written = score.tracks.flatMap((t) => t.staves.map((s) => ({ showSlash: s.showSlash, showNumbered: s.showNumbered })));
|
|
1758
|
+
chooseStaves(view, score);
|
|
1759
|
+
tablature = hasTablature(score, parsed.tracks);
|
|
1760
|
+
hideDefaultDynamics(score, parsed.file ? null : parsed.tex);
|
|
1175
1761
|
});
|
|
1762
|
+
hideCredit(current, surface);
|
|
1176
1763
|
let bar = null;
|
|
1177
1764
|
current.renderFinished.on(() => {
|
|
1178
1765
|
if (settled || gone)
|
|
@@ -1180,6 +1767,17 @@ function renderTab(language, source, host, options) {
|
|
|
1180
1767
|
if (options.player !== false) {
|
|
1181
1768
|
bar = playerBar(doc, current, at, assets);
|
|
1182
1769
|
el.appendChild(bar.bar);
|
|
1770
|
+
if (options.views !== false && tablature)
|
|
1771
|
+
bar.bar.appendChild(viewControl(doc, own, (staves) => {
|
|
1772
|
+
view = staves;
|
|
1773
|
+
const score = current.score;
|
|
1774
|
+
if (gone || !score)
|
|
1775
|
+
return;
|
|
1776
|
+
const all = score.tracks.flatMap((t) => t.staves);
|
|
1777
|
+
all.forEach((staff, i) => Object.assign(staff, written[i]));
|
|
1778
|
+
chooseStaves(staves, score);
|
|
1779
|
+
current.render();
|
|
1780
|
+
}, options.onKeepView));
|
|
1183
1781
|
el.addEventListener("pointerdown", (event) => {
|
|
1184
1782
|
if (event.pointerType !== "touch" || bar?.bar.contains(event.target))
|
|
1185
1783
|
return;
|
|
@@ -1235,6 +1833,9 @@ function renderTab(language, source, host, options) {
|
|
|
1235
1833
|
};
|
|
1236
1834
|
}
|
|
1237
1835
|
var PROGRAMS = { guitar: 25, piano: 0 };
|
|
1836
|
+
var MUTED = { channel: 1, program: 28 };
|
|
1837
|
+
var CLICK = { channel: 9, key: 33 };
|
|
1838
|
+
var SOUNDFONT_TAIL = 0.5;
|
|
1238
1839
|
function soundfontPlayer(alphaTab, api) {
|
|
1239
1840
|
return {
|
|
1240
1841
|
reportsStart: true,
|
|
@@ -1248,13 +1849,19 @@ function soundfontPlayer(alphaTab, api) {
|
|
|
1248
1849
|
const ticks = (seconds) => Math.round(seconds * midi.division);
|
|
1249
1850
|
handler.addTempo(0, 60);
|
|
1250
1851
|
handler.addProgramChange(0, 0, 0, PROGRAMS[sound]);
|
|
1852
|
+
if (sound === "guitar" && events.some((e) => e.kind === "muted"))
|
|
1853
|
+
handler.addProgramChange(0, 0, MUTED.channel, MUTED.program);
|
|
1854
|
+
if (events.some((e) => e.kind === "click"))
|
|
1855
|
+
handler.addProgramChange(0, 0, CLICK.channel, 0);
|
|
1251
1856
|
const level = Number.isFinite(volume) ? Math.min(1, Math.max(0, volume)) : 0.8;
|
|
1252
1857
|
current.masterVolume = level;
|
|
1253
1858
|
for (const e of events) {
|
|
1254
1859
|
const velocity = e.velocity === undefined || !Number.isFinite(e.velocity) ? 100 : Math.round(Math.min(127, Math.max(1, e.velocity)));
|
|
1255
|
-
|
|
1860
|
+
const channel = e.kind === "click" ? CLICK.channel : e.kind === "muted" && sound === "guitar" ? MUTED.channel : 0;
|
|
1861
|
+
handler.addNote(0, ticks(e.time), Math.max(1, ticks(e.duration)), e.kind === "click" ? CLICK.key : e.midi, velocity, channel);
|
|
1256
1862
|
}
|
|
1257
1863
|
const end = Math.max(...events.map((e) => e.time + e.duration), 0);
|
|
1864
|
+
handler.addControlChange(0, ticks(end + SOUNDFONT_TAIL), 0, alphaTab.midi.ControllerType.HoldPedal, 0);
|
|
1258
1865
|
current.playbackSpeed = 1;
|
|
1259
1866
|
player.playOneTimeMidiFile(midi);
|
|
1260
1867
|
let stopped = false;
|
|
@@ -1319,7 +1926,7 @@ function createSoundfontPlayer(alphaTab, assets, doc, fallback) {
|
|
|
1319
1926
|
});
|
|
1320
1927
|
if (assets.soundFont instanceof Uint8Array)
|
|
1321
1928
|
current.loadSoundFont(made.bytes(assets.soundFont), false);
|
|
1322
|
-
current.tex(`\\track "Guitar" \\instrument ${PROGRAMS.guitar} r \\track "Piano" \\instrument ${PROGRAMS.piano} r`);
|
|
1929
|
+
current.tex(`\\track "Guitar" \\instrument ${PROGRAMS.guitar} r \\track "Piano" \\instrument ${PROGRAMS.piano} r \\track "Muted" \\instrument ${MUTED.program} r`);
|
|
1323
1930
|
return ready;
|
|
1324
1931
|
};
|
|
1325
1932
|
const inner = soundfontPlayer(alphaTab, () => api);
|
|
@@ -1382,6 +1989,7 @@ export {
|
|
|
1382
1989
|
createSoundfontPlayer,
|
|
1383
1990
|
exportGp7,
|
|
1384
1991
|
exportMidi,
|
|
1992
|
+
hideDefaultDynamics,
|
|
1385
1993
|
parseTabSource,
|
|
1386
1994
|
printTab,
|
|
1387
1995
|
renderTab,
|
|
@@ -1390,5 +1998,5 @@ export {
|
|
|
1390
1998
|
textTabToAlphaTex
|
|
1391
1999
|
};
|
|
1392
2000
|
|
|
1393
|
-
//# debugId=
|
|
2001
|
+
//# debugId=64A5A150256EB96064756E2164756E21
|
|
1394
2002
|
//# sourceMappingURL=index.js.map
|