jpfun 0.6.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.
- package/Bravura-LICENSE.txt +93 -0
- package/README.md +49 -146
- package/dist/Bravura-LICENSE.txt +93 -0
- package/dist/converter/midi/convert.d.ts +3 -11
- package/dist/converter/midi/convert.js +89 -67
- package/dist/converter/musicxml/features.d.ts +34 -12
- package/dist/converter/musicxml/features.js +131 -24
- package/dist/converter/musicxml/index.js +221 -54
- package/dist/converter/musicxml/model.d.ts +24 -0
- package/dist/core.d.ts +1 -0
- package/dist/core.js +1 -0
- package/dist/diagnostic.d.ts +7 -1
- package/dist/diagnostic.js +40 -88
- package/dist/fraction.js +3 -2
- package/dist/functions/ASTtypes.d.ts +2 -18
- package/dist/functions/ASTtypes.js +0 -16
- package/dist/functions/arpeggio/index.js +17 -22
- package/dist/functions/arpeggio/shape.d.ts +1 -1
- package/dist/functions/arpeggio/shape.js +27 -21
- package/dist/functions/bar/index.d.ts +8 -0
- package/dist/functions/bar/index.js +139 -36
- package/dist/functions/beam/auto.d.ts +1 -2
- package/dist/functions/beam/auto.js +44 -27
- package/dist/functions/beam/index.js +2 -3
- package/dist/functions/beam/layout.d.ts +1 -1
- package/dist/functions/beam/layout.js +16 -24
- package/dist/functions/br/index.d.ts +34 -2
- package/dist/functions/br/index.js +8 -8
- package/dist/functions/dash/index.js +6 -6
- package/dist/functions/default.js +10 -5
- package/dist/functions/div/index.d.ts +1 -0
- package/dist/functions/div/index.js +8 -4
- package/dist/functions/dot/index.js +2 -2
- package/dist/functions/dyn/index.js +49 -31
- package/dist/functions/gliss/index.d.ts +2 -0
- package/dist/functions/gliss/index.js +202 -0
- package/dist/functions/grace/index.d.ts +1 -7
- package/dist/functions/grace/index.js +11 -19
- package/dist/functions/head/index.js +41 -60
- package/dist/functions/key/index.js +8 -10
- package/dist/functions/meter/index.d.ts +56 -1
- package/dist/functions/meter/index.js +30 -24
- package/dist/functions/note/accidentals.js +10 -16
- package/dist/functions/note/index.js +18 -8
- package/dist/functions/note/noteName.d.ts +16 -0
- package/dist/functions/note/noteName.js +88 -0
- package/dist/functions/note/source-transform.js +6 -5
- package/dist/functions/ottava/index.d.ts +2 -0
- package/dist/functions/ottava/index.js +233 -0
- package/dist/functions/page/index.d.ts +1 -0
- package/dist/functions/page/index.js +22 -13
- package/dist/functions/pagebreak/index.d.ts +2 -0
- package/dist/functions/pagebreak/index.js +36 -0
- package/dist/functions/rest/index.js +15 -15
- package/dist/functions/set/index.js +4 -4
- package/dist/functions/slide/index.d.ts +2 -0
- package/dist/functions/slide/index.js +132 -0
- package/dist/functions/stack/index.js +8 -15
- package/dist/functions/symbol/index.d.ts +30 -2
- package/dist/functions/symbol/index.js +93 -19
- package/dist/functions/symbol/ornament.d.ts +1 -2
- package/dist/functions/symbol/ornament.js +14 -19
- package/dist/functions/symbol/shape.d.ts +6 -0
- package/dist/functions/symbol/shape.js +20 -4
- package/dist/functions/symbol/symbols/coda.d.ts +4 -0
- package/dist/functions/symbol/symbols/coda.js +56 -0
- package/dist/functions/symbol/symbols/dynamics.d.ts +1 -1
- package/dist/functions/symbol/symbols/dynamics.js +18 -8
- package/dist/functions/symbol/symbols/fine.js +1 -1
- package/dist/functions/symbol/symbols/harmonic.d.ts +2 -0
- package/dist/functions/symbol/symbols/harmonic.js +11 -0
- package/dist/functions/symbol/symbols/marcato.d.ts +2 -0
- package/dist/functions/symbol/symbols/marcato.js +22 -0
- package/dist/functions/symbol/symbols/staccato.d.ts +2 -0
- package/dist/functions/symbol/symbols/staccato.js +24 -0
- package/dist/functions/symbol/symbols/tenuto.d.ts +2 -0
- package/dist/functions/symbol/symbols/tenuto.js +11 -0
- package/dist/functions/symbol/symbols/tocoda.d.ts +2 -0
- package/dist/functions/symbol/symbols/tocoda.js +16 -0
- package/dist/functions/symbol/symbols/tr.js +46 -1
- package/dist/functions/symbol/symbols/turn.d.ts +3 -0
- package/dist/functions/symbol/symbols/turn.js +50 -0
- package/dist/functions/symbol/symbols/wheel.d.ts +2 -0
- package/dist/functions/symbol/symbols/wheel.js +36 -0
- package/dist/functions/temporal.d.ts +17 -6
- package/dist/functions/temporal.js +17 -6
- package/dist/functions/text/index.js +15 -6
- package/dist/functions/tie/index.js +64 -30
- package/dist/functions/tremolo/index.d.ts +2 -0
- package/dist/functions/tremolo/index.js +319 -0
- package/dist/functions/tuplet/index.js +4 -8
- package/dist/functions/up/index.js +7 -9
- package/dist/functions/voice/connections.js +7 -5
- package/dist/functions/voice/index.js +19 -11
- package/dist/functions/volta/index.js +41 -21
- package/dist/jpfun.core.min.js +64 -80
- package/dist/jpfun.from-midi.min.js +5 -5
- package/dist/jpfun.from-musicxml.min.js +8 -8
- package/dist/jpfun.min.js +69 -85
- package/dist/layout/default.d.ts +0 -1
- package/dist/layout/default.js +0 -1
- package/dist/layout/engine.d.ts +1 -0
- package/dist/layout/engine.js +42 -11
- package/dist/layout/page.d.ts +3 -2
- package/dist/layout/page.js +6 -5
- package/dist/layout/types.d.ts +4 -0
- package/dist/lowering/loweringContext.d.ts +11 -13
- package/dist/lowering/loweringContext.js +30 -197
- package/dist/lowering/types.d.ts +1 -3
- package/dist/parser/parse-utils/note-utils.d.ts +1 -1
- package/dist/parser/parse-utils/note-utils.js +8 -9
- package/dist/parser/parse-utils/string-utils.d.ts +3 -2
- package/dist/parser/parse-utils/string-utils.js +16 -3
- package/dist/parser/parserContext.d.ts +2 -0
- package/dist/parser/parserContext.js +36 -8
- package/dist/pipeline.js +0 -1
- package/dist/playback/compile.js +131 -72
- package/dist/playback/event.d.ts +1 -1
- package/dist/playback/event.js +9 -9
- package/dist/playback/time.js +42 -31
- package/dist/playback/types.d.ts +7 -3
- package/dist/render/canvas.d.ts +2 -0
- package/dist/render/canvas.js +25 -22
- package/dist/render/recording.js +1 -4
- package/dist/render/svg.js +1 -0
- package/dist/render/text.d.ts +1 -1
- package/dist/render/text.js +3 -2
- package/dist/render/translate.d.ts +0 -1
- package/dist/render/translate.js +6 -23
- package/dist/render/types.d.ts +1 -0
- package/grammar.md +52 -25
- package/package.json +3 -3
- package/dist/functions/note/noteNameFSM.d.ts +0 -8
- package/dist/functions/note/noteNameFSM.js +0 -181
|
@@ -1,7 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MIDI JSON -> jpFun 的转换流水线:
|
|
3
|
+
* 1. 校验输入,选择足以表达原时值的二进制精度;
|
|
4
|
+
* 2. 在原始 tick 上识别 3:2 三连音,再把其余音符量化到二进制网格;
|
|
5
|
+
* 3. 合并同起止音为和弦,把重叠内容拆到不同 lane;
|
|
6
|
+
* 4. 生成单行源码,以真实自然排版宽度选择换行点;
|
|
7
|
+
* 5. 重新生成最终源码,并用 tie 表达跨小节或不足一拍的持续音。
|
|
8
|
+
*
|
|
9
|
+
* MIDI 字节解析不属于 core;这里接收的是 midi.js 已解析好的 JSON。
|
|
10
|
+
*/
|
|
11
|
+
import { DEFAULT_BPM } from "../../functions/temporal.js";
|
|
1
12
|
import { identifyTriplets } from "./triplet.js";
|
|
2
13
|
import { attachAbove, quote, renderHead, renderPitch, renderSystems } from "../source.js";
|
|
3
14
|
import { SHARP_NOTE_NAMES as ABSOLUTE_NAMES } from "../../parser/parse-utils/note-utils.js";
|
|
4
|
-
const DEFAULT_BPM = 120;
|
|
5
15
|
const DEFAULT_TIME_SIGNATURE = [4, 4];
|
|
6
16
|
const AUTO_LINE_TARGET_RATIO = 1.03;
|
|
7
17
|
const AUTO_LINE_LIMIT_RATIO = 1.25;
|
|
@@ -263,12 +273,12 @@ function automaticLineBreaks(source, bars, scale, capability) {
|
|
|
263
273
|
// 超宽页面关闭自动换行,从真实布局对象取得每个小节的自然宽度
|
|
264
274
|
const naturalWidth = Math.max(1_000_000, source.length * 64);
|
|
265
275
|
const naturalSource = `@page(width=${naturalWidth}px, height=0px, top=0px, bottom=0px, left=0px, right=0px)\n${source}`;
|
|
266
|
-
const layout = capability.compileScore(naturalSource).layout;
|
|
267
|
-
const bodyLine = Math.max(...layout.objects.filter(node => !node.T.isZero()).map(node => node.layoutLine));
|
|
268
|
-
const bodyObjects = layout.objects.filter(node => node.layoutLine === bodyLine && node.box.w > 0);
|
|
276
|
+
const layout = capability.compileScore(naturalSource, { horizontalOnly: true }).layout;
|
|
269
277
|
const measureBounds = bars.map(() => ({ left: Infinity, right: -Infinity }));
|
|
270
|
-
//
|
|
271
|
-
for (const node of
|
|
278
|
+
// 测宽候选不含 head,所有正文可见对象均位于第 0 行;按起点归入小节,小节线归入左侧刚结束的小节
|
|
279
|
+
for (const node of layout.objects) {
|
|
280
|
+
if (node.box.w <= 0)
|
|
281
|
+
continue;
|
|
272
282
|
const at = Math.round(node.t.toNumber() * scale);
|
|
273
283
|
let low = 0;
|
|
274
284
|
let high = bars.length;
|
|
@@ -340,20 +350,22 @@ function itemHead(item, pitchMode, suffix = "", labels) {
|
|
|
340
350
|
* dash 只允许延续本小节内已经出现的音;跨小节或不足一拍时重写同音,
|
|
341
351
|
* 每个和弦成员分别收集完整标签链,音结束时一次输出 @tie(x, y, ...)。
|
|
342
352
|
*/
|
|
343
|
-
function renderLane(lane, rangeStart, rangeEnd, rhythmScale, timeFactor, pitchMode, bars, lineBreaks, adjustments, programs, nextTieLabel) {
|
|
353
|
+
function renderLane(lane, rangeStart, rangeEnd, lineSpan, rhythmScale, timeFactor, pitchMode, bars, regionBars, lineBreaks, adjustments, programs, nextTieLabel) {
|
|
344
354
|
// 事件边界与所有控制点共同切分时间线,保证每个片段内语义不变
|
|
345
355
|
const points = new Set([rangeStart, rangeEnd]);
|
|
346
356
|
for (const item of lane.items) {
|
|
347
357
|
points.add(item.start);
|
|
348
358
|
points.add(item.end);
|
|
349
359
|
}
|
|
350
|
-
for (const at of
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
360
|
+
for (const at of regionBars)
|
|
361
|
+
points.add(at);
|
|
362
|
+
if (adjustments) {
|
|
363
|
+
for (const at of adjustments.keys()) {
|
|
364
|
+
if (at >= rangeStart && at < rangeEnd)
|
|
365
|
+
points.add(at);
|
|
366
|
+
}
|
|
356
367
|
}
|
|
368
|
+
// 测宽也保留 program 控制点,避免持续音的切分与完整源码不同。
|
|
357
369
|
for (const at of programs.keys()) {
|
|
358
370
|
if (at >= rangeStart && at < rangeEnd)
|
|
359
371
|
points.add(at);
|
|
@@ -368,28 +380,33 @@ function renderLane(lane, rangeStart, rangeEnd, rhythmScale, timeFactor, pitchMo
|
|
|
368
380
|
return label;
|
|
369
381
|
});
|
|
370
382
|
// 预扫描找出不能只用 dash 延续的音符,提前为其建立逐音高标签链
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
383
|
+
if (nextTieLabel) {
|
|
384
|
+
for (const item of lane.items) {
|
|
385
|
+
if ("members" in item)
|
|
386
|
+
continue;
|
|
387
|
+
const startIndex = timelineIndex.get(item.start);
|
|
388
|
+
for (let index = startIndex; timeline[index] < item.end; index++) {
|
|
389
|
+
const suffixes = rhythmSuffixes((timeline[index + 1] - timeline[index]) / timeFactor, rhythmScale);
|
|
390
|
+
if ((timeline[index] > item.start && bars.has(timeline[index]))
|
|
391
|
+
|| suffixes.some((suffix, suffixIndex) => (timeline[index] > item.start || suffixIndex > 0) && suffix.includes("/"))) {
|
|
392
|
+
tieChains.set(item, item.notes.map(() => []));
|
|
393
|
+
break;
|
|
394
|
+
}
|
|
381
395
|
}
|
|
382
396
|
}
|
|
383
397
|
}
|
|
384
|
-
const outputs = Array.from({ length:
|
|
385
|
-
let outputIndex =
|
|
398
|
+
const outputs = Array.from({ length: lineSpan }, () => []);
|
|
399
|
+
let outputIndex = 0;
|
|
386
400
|
let itemIndex = 0;
|
|
387
|
-
let initialProgram
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
401
|
+
let initialProgram;
|
|
402
|
+
if (nextTieLabel && programs.size) {
|
|
403
|
+
initialProgram = 0;
|
|
404
|
+
let programStart = -Infinity;
|
|
405
|
+
for (const [at, program] of programs) {
|
|
406
|
+
if (at <= rangeStart && at >= programStart) {
|
|
407
|
+
initialProgram = program;
|
|
408
|
+
programStart = at;
|
|
409
|
+
}
|
|
393
410
|
}
|
|
394
411
|
}
|
|
395
412
|
// 沿时间片单向推进当前事件,依次输出控制项、音符或补齐休止
|
|
@@ -404,9 +421,11 @@ function renderLane(lane, rangeStart, rangeEnd, rhythmScale, timeFactor, pitchMo
|
|
|
404
421
|
const next = timeline[index + 1];
|
|
405
422
|
if (next === undefined)
|
|
406
423
|
continue;
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
424
|
+
if (nextTieLabel) {
|
|
425
|
+
const program = at === rangeStart ? initialProgram : programs.get(at);
|
|
426
|
+
if (program !== undefined)
|
|
427
|
+
outputs[outputIndex].push(`@program(${program})`);
|
|
428
|
+
}
|
|
410
429
|
const changes = adjustments?.get(at) ?? [];
|
|
411
430
|
const item = lane.items[itemIndex];
|
|
412
431
|
if (item && item.start <= at && item.end >= next) {
|
|
@@ -426,25 +445,11 @@ function renderLane(lane, rangeStart, rangeEnd, rhythmScale, timeFactor, pitchMo
|
|
|
426
445
|
for (let suffixIndex = 0; suffixIndex < suffixes.length; suffixIndex++) {
|
|
427
446
|
const suffix = suffixes[suffixIndex];
|
|
428
447
|
const continuation = at > item.start || suffixIndex > 0;
|
|
429
|
-
let token;
|
|
430
448
|
const chains = tieChains.get(item);
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
else {
|
|
436
|
-
token = itemHead(item, pitchMode, suffix);
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
else if ((suffixIndex === 0 && bars.has(at)) || suffix.includes("/")) {
|
|
440
|
-
token = itemHead(item, pitchMode, suffix, extendTieChains(chains));
|
|
441
|
-
}
|
|
442
|
-
else {
|
|
443
|
-
token = `-${suffix}`;
|
|
444
|
-
}
|
|
445
|
-
if (suffixIndex === 0)
|
|
446
|
-
token = attachAbove(token, changes);
|
|
447
|
-
outputs[outputIndex].push(token);
|
|
449
|
+
const token = !continuation || (suffixIndex === 0 && bars.has(at)) || suffix.includes("/")
|
|
450
|
+
? itemHead(item, pitchMode, suffix, chains && extendTieChains(chains))
|
|
451
|
+
: `-${suffix}`;
|
|
452
|
+
outputs[outputIndex].push(suffixIndex === 0 ? attachAbove(token, changes) : token);
|
|
448
453
|
if (chains && next === item.end && suffixIndex === suffixes.length - 1) {
|
|
449
454
|
outputs[outputIndex].push(...chains.map(labels => `@tie(${labels.join(", ")})`));
|
|
450
455
|
}
|
|
@@ -458,7 +463,7 @@ function renderLane(lane, rangeStart, rangeEnd, rhythmScale, timeFactor, pitchMo
|
|
|
458
463
|
}
|
|
459
464
|
return outputs.map(output => output.join(" "));
|
|
460
465
|
}
|
|
461
|
-
function renderTrack(track, scoreEnd, bars, lineBreaks, render, showName) {
|
|
466
|
+
function renderTrack(track, scoreEnd, bars, orderedBars, lineBreaks, render, showName) {
|
|
462
467
|
const lineCount = lineBreaks.size + 1;
|
|
463
468
|
const outputs = Array.from({ length: lineCount }, () => []);
|
|
464
469
|
const segments = [];
|
|
@@ -472,21 +477,36 @@ function renderTrack(track, scoreEnd, bars, lineBreaks, render, showName) {
|
|
|
472
477
|
}
|
|
473
478
|
if (cursor < scoreEnd)
|
|
474
479
|
segments.push({ start: cursor, end: scoreEnd, lanes: [{ items: [] }] });
|
|
475
|
-
//
|
|
480
|
+
// segments 按时间递增且连续,小节线与行号可沿游标单向推进
|
|
481
|
+
let barCursor = 0;
|
|
482
|
+
let lineCursor = 0;
|
|
476
483
|
for (const region of segments) {
|
|
477
484
|
if (region.start > 0 && bars.has(region.start)) {
|
|
478
|
-
|
|
479
|
-
|
|
485
|
+
outputs[lineCursor].push("|");
|
|
486
|
+
if (lineBreaks.has(region.start))
|
|
487
|
+
lineCursor++;
|
|
488
|
+
}
|
|
489
|
+
while (barCursor < orderedBars.length && orderedBars[barCursor] <= region.start)
|
|
490
|
+
barCursor++;
|
|
491
|
+
const barStart = barCursor;
|
|
492
|
+
let lineEnd = lineCursor;
|
|
493
|
+
while (barCursor < orderedBars.length && orderedBars[barCursor] < region.end) {
|
|
494
|
+
if (lineBreaks.has(orderedBars[barCursor]))
|
|
495
|
+
lineEnd++;
|
|
496
|
+
barCursor++;
|
|
480
497
|
}
|
|
481
|
-
const
|
|
482
|
-
|
|
483
|
-
|
|
498
|
+
const regionBars = orderedBars.slice(barStart, barCursor);
|
|
499
|
+
const lineSpan = lineEnd - lineCursor + 1;
|
|
500
|
+
const lanes = region.lanes.map(lane => render(region, lane, regionBars, lineSpan));
|
|
501
|
+
for (let offset = 0; offset < lineSpan; offset++) {
|
|
502
|
+
if (!lanes.some(lines => lines[offset]))
|
|
484
503
|
continue;
|
|
485
504
|
const content = lanes.length === 1
|
|
486
|
-
? lanes[0][
|
|
487
|
-
: `@stack(${lanes.map(lines => `{ ${lines[
|
|
488
|
-
outputs[
|
|
505
|
+
? lanes[0][offset]
|
|
506
|
+
: `@stack(${lanes.map(lines => `{ ${lines[offset]} }`).join(", ")})`;
|
|
507
|
+
outputs[lineCursor + offset].push(content);
|
|
489
508
|
}
|
|
509
|
+
lineCursor = lineEnd;
|
|
490
510
|
}
|
|
491
511
|
if (bars.has(scoreEnd))
|
|
492
512
|
outputs[lineCount - 1].push("|");
|
|
@@ -693,15 +713,17 @@ export function convertMidiJsonToJpFun(input, options = {}, layoutCapability) {
|
|
|
693
713
|
});
|
|
694
714
|
if (convertedTracks.length === 0)
|
|
695
715
|
return head;
|
|
696
|
-
//
|
|
716
|
+
// 第六阶段:先用不含 head/tie/program 的单行候选测自然宽度,再用选出的断点生成完整源码
|
|
697
717
|
const renderScore = (lineBreaks) => {
|
|
698
718
|
let tieIndex = 0;
|
|
699
|
-
|
|
700
|
-
const
|
|
701
|
-
|
|
719
|
+
const nextTieLabel = lineBreaks ? () => `mt${tieIndex++}` : undefined;
|
|
720
|
+
const breaks = lineBreaks ?? new Set();
|
|
721
|
+
const tracks = convertedTracks.map((track, trackIndex) => renderTrack(track, scoreEnd, bars, orderedBars, breaks, (region, lane, regionBars, lineSpan) => renderLane(lane, region.start, region.end, lineSpan, rhythmScale, timeFactor, pitchMode, bars, regionBars, breaks, trackIndex === 0 && lane === region.lanes.at(-1) ? scoreAdjustments : undefined, track.programs, nextTieLabel), convertedTracks.length > 1));
|
|
722
|
+
const body = renderSystems(tracks);
|
|
723
|
+
return lineBreaks ? `${head}\n\n${body}` : body;
|
|
702
724
|
};
|
|
703
725
|
const lineBreaks = barsPerLine <= 0
|
|
704
|
-
? automaticLineBreaks(renderScore(
|
|
726
|
+
? automaticLineBreaks(renderScore(), orderedBars, scale, layoutCapability)
|
|
705
727
|
: new Set(orderedBars.filter((at, index) => (index + 1) % barsPerLine === 0 && at < scoreEnd));
|
|
706
728
|
return renderScore(lineBreaks);
|
|
707
729
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { type MusicXmlElement } from "./dom.js";
|
|
2
|
-
import type { MusicXmlArpeggio, MusicXmlDiagnostic, MusicXmlEvent, MusicXmlPitch, ParsedMusicXmlScore } from "./model.js";
|
|
2
|
+
import type { MusicXmlArpeggio, MusicXmlDiagnostic, MusicXmlEvent, MusicXmlPitch, MusicXmlRepeatPoint, MusicXmlRepeatSymbol, ParsedMusicXmlScore } from "./model.js";
|
|
3
3
|
/** 统一两种 MusicXML 根结构中的小节内容与外层小节容器 */
|
|
4
4
|
export interface MusicXmlMeasureSource {
|
|
5
5
|
body: MusicXmlElement;
|
|
6
6
|
container: MusicXmlElement;
|
|
7
7
|
}
|
|
8
|
+
/** 识别 <words> 中的标准反复跳转与终止术语 */
|
|
9
|
+
export declare function repeatWordSymbol(value: string): MusicXmlRepeatSymbol | undefined;
|
|
8
10
|
declare const DIAGNOSTICS: {
|
|
9
11
|
readonly percussion: readonly ["PERCUSSION_SKIPPED", "MIDI channel 10 percussion note was omitted."];
|
|
10
12
|
readonly displayPitch: readonly ["APPROXIMATED", "Unpitched note was converted to a melodic note using its display pitch."];
|
|
@@ -17,6 +19,7 @@ declare const DIAGNOSTICS: {
|
|
|
17
19
|
readonly directionOutput: readonly ["UNATTACHED_CONTENT", "Direction mark has no generated output position and was omitted."];
|
|
18
20
|
readonly tempoReplaced: readonly ["UNATTACHED_CONTENT", "Tempo {value} was replaced by a different tempo at the same time and was omitted."];
|
|
19
21
|
readonly arpeggioOutput: readonly ["UNSUPPORTED_ELEMENT", "Arpeggiate mark requires at least two pitches in one event and was omitted."];
|
|
22
|
+
readonly multipleRest: readonly ["APPROXIMATED", "Multiple-rest grouping could not be preserved without discarding musical content; individual rests were retained."];
|
|
20
23
|
readonly textHost: readonly ["UNATTACHED_CONTENT", "Text {value} has no target event and was omitted."];
|
|
21
24
|
readonly wedgeStart: readonly ["UNRESOLVED_RELATION", "Wedge stop has no matching start and was omitted."];
|
|
22
25
|
readonly wedgeReplaced: readonly ["UNRESOLVED_RELATION", "Wedge start was replaced before a matching stop and was omitted."];
|
|
@@ -29,6 +32,12 @@ declare const DIAGNOSTICS: {
|
|
|
29
32
|
readonly endingEndpoints: readonly ["UNRESOLVED_RELATION", "Ending has no event endpoints in its interval and was omitted."];
|
|
30
33
|
readonly tieStart: readonly ["UNRESOLVED_RELATION", "Tie stop has no matching start and was omitted."];
|
|
31
34
|
readonly tieStop: readonly ["UNRESOLVED_RELATION", "Tie start has no matching stop in any ending branch and was omitted."];
|
|
35
|
+
readonly glissStart: readonly ["UNRESOLVED_RELATION", "Glissando stop has no matching start and was omitted."];
|
|
36
|
+
readonly glissStop: readonly ["UNRESOLVED_RELATION", "Glissando start has no matching stop and was omitted."];
|
|
37
|
+
readonly glissReplaced: readonly ["UNRESOLVED_RELATION", "Glissando start was replaced before a matching stop and was omitted."];
|
|
38
|
+
readonly glissEndpoints: readonly ["UNRESOLVED_RELATION", "Glissando endpoints are simultaneous or cross a score line and were omitted."];
|
|
39
|
+
readonly glissStyle: readonly ["APPROXIMATED", "MusicXML <{value}> was converted to a straight glissando arrow."];
|
|
40
|
+
readonly symbolStyle: readonly ["APPROXIMATED", "MusicXML <{value}> was mapped to the default symbol shape."];
|
|
32
41
|
};
|
|
33
42
|
export declare function reportDiagnostic(diagnostics: MusicXmlDiagnostic[], issue: keyof typeof DIAGNOSTICS, location: MusicXmlDiagnostic["location"], value?: string | number): void;
|
|
34
43
|
/** 查询不改变覆盖状态;解析结果写入语义模型后显式确认,未确认项按 XML 顺序报告 */
|
|
@@ -53,14 +62,22 @@ export declare function scoreMetadata(root: MusicXmlElement): Pick<ParsedMusicXm
|
|
|
53
62
|
/** 解析书面音高及该和弦成员自己的 tie 起止标记 */
|
|
54
63
|
export declare function parsePitch(note: MusicXmlElement, location: MusicXmlPitch["location"], notations?: MusicXmlReader): MusicXmlPitch | null;
|
|
55
64
|
export declare function transposePitch(pitch: MusicXmlPitch, chromatic: number, diatonic: number | undefined, octaves: number): void;
|
|
56
|
-
/**
|
|
65
|
+
/** 将支持的延长、奏法与装饰音记号转成 jpFun 修饰符 */
|
|
57
66
|
export declare function noteModifiers(notations: MusicXmlReader | undefined, diagnostics: MusicXmlDiagnostic[], location: MusicXmlDiagnostic["location"]): {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
67
|
+
modifiers: {
|
|
68
|
+
name: string;
|
|
69
|
+
placement: "above" | "below";
|
|
70
|
+
}[];
|
|
71
|
+
slides: {
|
|
72
|
+
side: "pre" | "post";
|
|
73
|
+
direction: "up" | "down";
|
|
74
|
+
}[];
|
|
75
|
+
};
|
|
76
|
+
/** 双音 slide 与 glissando 均是标签关系;与 articulations 下的单音滑音区别处理 */
|
|
77
|
+
export declare function noteGlissandi(notations: MusicXmlReader | undefined, pitch: MusicXmlPitch | null, diagnostics: MusicXmlDiagnostic[]): void;
|
|
78
|
+
/** 无箭头不覆盖显式方向,两个相反的显式方向不能属于同一和弦 */
|
|
62
79
|
export declare function mergeArpeggio(current?: MusicXmlArpeggio, next?: MusicXmlArpeggio): MusicXmlArpeggio | undefined;
|
|
63
|
-
/** 读取和弦成员上的琶音方向;none
|
|
80
|
+
/** 读取和弦成员上的琶音方向;none 表示无箭头但仍按自下而上演奏 */
|
|
64
81
|
export declare function noteArpeggio(notations: MusicXmlReader | undefined, location: MusicXmlPitch["location"]): MusicXmlArpeggio | undefined;
|
|
65
82
|
/** 解析 tuplet 的实际音数与正常音数,并保留显式组边界 */
|
|
66
83
|
export declare function timeModification(note: MusicXmlElement, tuplets: readonly MusicXmlElement[] | undefined): {
|
|
@@ -75,11 +92,16 @@ export declare function acceptTuplets(notations: MusicXmlReader | undefined, tup
|
|
|
75
92
|
export declare function noteLyrics(note: MusicXmlElement): Map<string, string>;
|
|
76
93
|
/** 返回 dynamics 中首个受支持的力度记号 */
|
|
77
94
|
export declare function directionDynamic(dynamics: MusicXmlElement | undefined, diagnostics: MusicXmlDiagnostic[], location: MusicXmlDiagnostic["location"]): string | undefined;
|
|
78
|
-
/**
|
|
79
|
-
export declare function directionTexts(direction: MusicXmlReader): {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
95
|
+
/** 收集排练标记、反复记号与普通文字,排练标记保留方框语义;空白文字视为空内容 */
|
|
96
|
+
export declare function directionTexts(direction: MusicXmlReader, defaultPlacement?: "above" | "below", location?: MusicXmlDiagnostic["location"]): {
|
|
97
|
+
texts: {
|
|
98
|
+
text: string;
|
|
99
|
+
boxed: boolean;
|
|
100
|
+
}[];
|
|
101
|
+
repeats: Omit<MusicXmlRepeatPoint, "at">[];
|
|
102
|
+
};
|
|
103
|
+
/** 读取 <sound> 上的反复与跳转属性 */
|
|
104
|
+
export declare function soundRepeats(sound: MusicXmlElement | undefined, placement: "above" | "below", location: MusicXmlDiagnostic["location"]): Omit<MusicXmlRepeatPoint, "at">[];
|
|
83
105
|
/** 将 metronome 的拍单位和附点折算成四分音符 BPM */
|
|
84
106
|
export declare function metronomeBpm(metronome: MusicXmlElement | undefined): number | undefined;
|
|
85
107
|
/** 将单一或复合拍号归一成一个等值分数 */
|
|
@@ -1,7 +1,28 @@
|
|
|
1
1
|
import { child, children, descendant, descendants, nameOf, number, text, } from "./dom.js";
|
|
2
2
|
import { NoteNameMap, SHARP_NOTE_NAMES } from "../../parser/parse-utils/note-utils.js";
|
|
3
|
-
const
|
|
3
|
+
const DYNAMIC_NAME = /^(?:p+|f+|mp|mf)$/;
|
|
4
4
|
const MAX_ENDING_PASS = 256;
|
|
5
|
+
const SOUND_REPEATS = [
|
|
6
|
+
["segno", "segno"],
|
|
7
|
+
["coda", "coda"],
|
|
8
|
+
["dacapo", "dc"],
|
|
9
|
+
["dalsegno", "ds"],
|
|
10
|
+
["fine", "fine"],
|
|
11
|
+
["tocoda", "tocoda"],
|
|
12
|
+
];
|
|
13
|
+
/** 识别 <words> 中的标准反复跳转与终止术语 */
|
|
14
|
+
export function repeatWordSymbol(value) {
|
|
15
|
+
const normalized = value.trim().replace(/\s+/g, " ");
|
|
16
|
+
if (/^(?:d\.\s*c\.?|da\s+capo)(?:\s+al\s+(?:fine|coda)\.?)?$/i.test(normalized))
|
|
17
|
+
return "dc";
|
|
18
|
+
if (/^(?:d\.\s*s\.?|dal\s+segno)(?:\s+al\s+(?:fine|coda)\.?)?$/i.test(normalized))
|
|
19
|
+
return "ds";
|
|
20
|
+
if (/^fine\.?$/i.test(normalized))
|
|
21
|
+
return "fine";
|
|
22
|
+
if (/^(?:to\s+coda|al\s+coda)\.?$/i.test(normalized))
|
|
23
|
+
return "tocoda";
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
5
26
|
const DIAGNOSTICS = {
|
|
6
27
|
percussion: ["PERCUSSION_SKIPPED", "MIDI channel 10 percussion note was omitted."],
|
|
7
28
|
displayPitch: ["APPROXIMATED", "Unpitched note was converted to a melodic note using its display pitch."],
|
|
@@ -14,6 +35,7 @@ const DIAGNOSTICS = {
|
|
|
14
35
|
directionOutput: ["UNATTACHED_CONTENT", "Direction mark has no generated output position and was omitted."],
|
|
15
36
|
tempoReplaced: ["UNATTACHED_CONTENT", "Tempo {value} was replaced by a different tempo at the same time and was omitted."],
|
|
16
37
|
arpeggioOutput: ["UNSUPPORTED_ELEMENT", "Arpeggiate mark requires at least two pitches in one event and was omitted."],
|
|
38
|
+
multipleRest: ["APPROXIMATED", "Multiple-rest grouping could not be preserved without discarding musical content; individual rests were retained."],
|
|
17
39
|
textHost: ["UNATTACHED_CONTENT", "Text {value} has no target event and was omitted."],
|
|
18
40
|
wedgeStart: ["UNRESOLVED_RELATION", "Wedge stop has no matching start and was omitted."],
|
|
19
41
|
wedgeReplaced: ["UNRESOLVED_RELATION", "Wedge start was replaced before a matching stop and was omitted."],
|
|
@@ -26,6 +48,12 @@ const DIAGNOSTICS = {
|
|
|
26
48
|
endingEndpoints: ["UNRESOLVED_RELATION", "Ending has no event endpoints in its interval and was omitted."],
|
|
27
49
|
tieStart: ["UNRESOLVED_RELATION", "Tie stop has no matching start and was omitted."],
|
|
28
50
|
tieStop: ["UNRESOLVED_RELATION", "Tie start has no matching stop in any ending branch and was omitted."],
|
|
51
|
+
glissStart: ["UNRESOLVED_RELATION", "Glissando stop has no matching start and was omitted."],
|
|
52
|
+
glissStop: ["UNRESOLVED_RELATION", "Glissando start has no matching stop and was omitted."],
|
|
53
|
+
glissReplaced: ["UNRESOLVED_RELATION", "Glissando start was replaced before a matching stop and was omitted."],
|
|
54
|
+
glissEndpoints: ["UNRESOLVED_RELATION", "Glissando endpoints are simultaneous or cross a score line and were omitted."],
|
|
55
|
+
glissStyle: ["APPROXIMATED", "MusicXML <{value}> was converted to a straight glissando arrow."],
|
|
56
|
+
symbolStyle: ["APPROXIMATED", "MusicXML <{value}> was mapped to the default symbol shape."],
|
|
29
57
|
};
|
|
30
58
|
export function reportDiagnostic(diagnostics, issue, location, value = "") {
|
|
31
59
|
const [kind, message] = DIAGNOSTICS[issue];
|
|
@@ -195,46 +223,90 @@ export function transposePitch(pitch, chromatic, diatonic, octaves) {
|
|
|
195
223
|
pitch.alter = midi - (pitch.octave + 1) * 12 - NoteNameMap[pitch.step];
|
|
196
224
|
}
|
|
197
225
|
}
|
|
198
|
-
/**
|
|
226
|
+
/** 将支持的延长、奏法与装饰音记号转成 jpFun 修饰符 */
|
|
199
227
|
export function noteModifiers(notations, diagnostics, location) {
|
|
200
|
-
const
|
|
228
|
+
const modifiers = [];
|
|
229
|
+
const slides = [];
|
|
201
230
|
if (!notations)
|
|
202
|
-
return
|
|
231
|
+
return { modifiers, slides };
|
|
203
232
|
const fermata = notations.read("fermata");
|
|
204
233
|
if (fermata) {
|
|
205
|
-
|
|
234
|
+
modifiers.push({ name: "fermata", placement: placementOf(fermata, fermata.getAttribute("type") === "inverted" ? "below" : "above") });
|
|
206
235
|
notations.accept(fermata);
|
|
207
236
|
}
|
|
208
237
|
const articulations = notations.read("articulations");
|
|
209
238
|
if (articulations) {
|
|
210
|
-
const
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
239
|
+
for (const [tag, name] of [
|
|
240
|
+
["accent", "accent"], ["staccato", "staccato"], ["tenuto", "tenuto"],
|
|
241
|
+
["strong-accent", "marcato"], ["staccatissimo", "staccato"],
|
|
242
|
+
]) {
|
|
243
|
+
const articulation = notations.read(tag, false, articulations);
|
|
244
|
+
if (!articulation)
|
|
245
|
+
continue;
|
|
246
|
+
modifiers.push({ name, placement: placementOf(articulation, "above") });
|
|
247
|
+
notations.accept(articulation);
|
|
248
|
+
if (tag === "strong-accent" && articulation.getAttribute("type") === "down") {
|
|
249
|
+
reportDiagnostic(diagnostics, "symbolStyle", { ...location, element: tag }, tag);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
for (const [tag, side, direction] of [
|
|
253
|
+
["scoop", "pre", "up"], ["plop", "pre", "down"],
|
|
254
|
+
["doit", "post", "up"], ["falloff", "post", "down"],
|
|
255
|
+
]) {
|
|
256
|
+
for (const articulation of children(articulations, tag)) {
|
|
257
|
+
slides.push({ side, direction });
|
|
258
|
+
notations.accept(articulation);
|
|
259
|
+
if (articulation.getAttribute("line-shape") === "curved"
|
|
260
|
+
|| articulation.getAttribute("line-type") === "wavy") {
|
|
261
|
+
reportDiagnostic(diagnostics, "glissStyle", { ...location, element: tag }, tag);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
214
264
|
}
|
|
215
265
|
notations.report(diagnostics, location, articulations);
|
|
216
266
|
notations.accept(articulations);
|
|
217
267
|
}
|
|
218
268
|
const ornaments = notations.read("ornaments");
|
|
219
269
|
if (ornaments) {
|
|
220
|
-
const
|
|
270
|
+
for (const [tag, name] of [
|
|
221
271
|
["trill-mark", "tr"],
|
|
222
272
|
["mordent", "mordent"],
|
|
223
273
|
["inverted-mordent", "prall"],
|
|
224
|
-
|
|
225
|
-
|
|
274
|
+
["turn", "turn"],
|
|
275
|
+
["inverted-turn", "iturn"],
|
|
276
|
+
]) {
|
|
226
277
|
const ornament = notations.read(tag, false, ornaments);
|
|
227
|
-
if (ornament)
|
|
228
|
-
|
|
229
|
-
|
|
278
|
+
if (!ornament)
|
|
279
|
+
continue;
|
|
280
|
+
modifiers.push({ name, placement: placementOf(ornament, "above") });
|
|
281
|
+
notations.accept(ornament);
|
|
282
|
+
if ((tag === "turn" || tag === "inverted-turn") && ornament.getAttribute("slash") === "yes") {
|
|
283
|
+
reportDiagnostic(diagnostics, "symbolStyle", { ...location, element: tag }, tag);
|
|
230
284
|
}
|
|
231
285
|
}
|
|
232
286
|
notations.report(diagnostics, location, ornaments);
|
|
233
287
|
notations.accept(ornaments);
|
|
234
288
|
}
|
|
235
|
-
return
|
|
289
|
+
return { modifiers, slides };
|
|
236
290
|
}
|
|
237
|
-
/**
|
|
291
|
+
/** 双音 slide 与 glissando 均是标签关系;与 articulations 下的单音滑音区别处理 */
|
|
292
|
+
export function noteGlissandi(notations, pitch, diagnostics) {
|
|
293
|
+
if (!notations || !pitch)
|
|
294
|
+
return;
|
|
295
|
+
for (const kind of ["slide", "glissando"]) {
|
|
296
|
+
for (const element of notations.readAll(kind)) {
|
|
297
|
+
const type = element.getAttribute("type");
|
|
298
|
+
if (type !== "start" && type !== "stop")
|
|
299
|
+
continue;
|
|
300
|
+
(pitch.glissandi ??= []).push({ kind, type, number: element.getAttribute("number") || "1" });
|
|
301
|
+
notations.accept(element);
|
|
302
|
+
if (type === "start" && (kind === "glissando" && element.getAttribute("line-type") !== "solid"
|
|
303
|
+
|| element.getAttribute("line-type") === "wavy" || text(element))) {
|
|
304
|
+
reportDiagnostic(diagnostics, "glissStyle", { ...pitch.location, element: kind }, kind);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
/** 无箭头不覆盖显式方向,两个相反的显式方向不能属于同一和弦 */
|
|
238
310
|
export function mergeArpeggio(current, next) {
|
|
239
311
|
if (!next || next.direction === "none")
|
|
240
312
|
return current ?? next;
|
|
@@ -243,7 +315,7 @@ export function mergeArpeggio(current, next) {
|
|
|
243
315
|
}
|
|
244
316
|
return next;
|
|
245
317
|
}
|
|
246
|
-
/** 读取和弦成员上的琶音方向;none
|
|
318
|
+
/** 读取和弦成员上的琶音方向;none 表示无箭头但仍按自下而上演奏 */
|
|
247
319
|
export function noteArpeggio(notations, location) {
|
|
248
320
|
if (!notations)
|
|
249
321
|
return undefined;
|
|
@@ -306,24 +378,59 @@ export function directionDynamic(dynamics, diagnostics, location) {
|
|
|
306
378
|
let dynamic;
|
|
307
379
|
for (const element of children(dynamics)) {
|
|
308
380
|
const name = nameOf(element);
|
|
309
|
-
if (!dynamic &&
|
|
381
|
+
if (!dynamic && DYNAMIC_NAME.test(name))
|
|
310
382
|
dynamic = name;
|
|
311
383
|
else
|
|
312
384
|
reportDiagnostic(diagnostics, "unsupported", { ...location, element: name }, name);
|
|
313
385
|
}
|
|
314
386
|
return dynamic;
|
|
315
387
|
}
|
|
316
|
-
/**
|
|
317
|
-
export function directionTexts(direction) {
|
|
318
|
-
const
|
|
388
|
+
/** 收集排练标记、反复记号与普通文字,排练标记保留方框语义;空白文字视为空内容 */
|
|
389
|
+
export function directionTexts(direction, defaultPlacement = "above", location) {
|
|
390
|
+
const texts = [];
|
|
391
|
+
const repeats = [];
|
|
392
|
+
for (const tag of ["segno", "coda"]) {
|
|
393
|
+
for (const node of direction.readAll(tag, true)) {
|
|
394
|
+
repeats.push({
|
|
395
|
+
symbol: tag,
|
|
396
|
+
placement: placementOf(node, defaultPlacement),
|
|
397
|
+
location: { ...(location ?? { element: tag }), element: tag },
|
|
398
|
+
});
|
|
399
|
+
direction.accept(node);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
319
402
|
for (const name of ["rehearsal", "words"]) {
|
|
320
403
|
for (const node of direction.readAll(name, true)) {
|
|
321
404
|
const value = node.textContent?.trim();
|
|
322
|
-
if (value)
|
|
323
|
-
|
|
405
|
+
if (value) {
|
|
406
|
+
const symbol = name === "words" ? repeatWordSymbol(value) : undefined;
|
|
407
|
+
if (symbol) {
|
|
408
|
+
repeats.push({
|
|
409
|
+
symbol,
|
|
410
|
+
placement: placementOf(node, defaultPlacement),
|
|
411
|
+
location: { ...(location ?? { element: name }), element: name },
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
else {
|
|
415
|
+
texts.push({ text: value, boxed: name === "rehearsal" });
|
|
416
|
+
}
|
|
417
|
+
}
|
|
324
418
|
direction.accept(node);
|
|
325
419
|
}
|
|
326
420
|
}
|
|
421
|
+
return { texts, repeats };
|
|
422
|
+
}
|
|
423
|
+
/** 读取 <sound> 上的反复与跳转属性 */
|
|
424
|
+
export function soundRepeats(sound, placement, location) {
|
|
425
|
+
if (!sound)
|
|
426
|
+
return [];
|
|
427
|
+
const result = [];
|
|
428
|
+
for (const [attr, symbol] of SOUND_REPEATS) {
|
|
429
|
+
const value = sound.getAttribute(attr)?.trim().toLowerCase();
|
|
430
|
+
if (value && value !== "no") {
|
|
431
|
+
result.push({ symbol, placement, location: { ...location, element: "sound" } });
|
|
432
|
+
}
|
|
433
|
+
}
|
|
327
434
|
return result;
|
|
328
435
|
}
|
|
329
436
|
/** 将 metronome 的拍单位和附点折算成四分音符 BPM */
|