jpfun 0.7.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/Bravura-LICENSE.txt +93 -0
- package/README.md +49 -146
- package/dist/Bravura-LICENSE.txt +93 -0
- package/dist/converter/midi/convert.d.ts +0 -10
- package/dist/converter/midi/convert.js +19 -56
- package/dist/converter/musicxml/features.d.ts +16 -8
- package/dist/converter/musicxml/features.js +88 -19
- package/dist/converter/musicxml/index.js +88 -50
- package/dist/converter/musicxml/model.d.ts +9 -0
- package/dist/converter/source.d.ts +4 -7
- package/dist/converter/source.js +11 -9
- 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 +3 -32
- package/dist/functions/ASTtypes.js +5 -52
- package/dist/functions/adjust/index.js +45 -33
- package/dist/functions/arpeggio/index.js +50 -55
- package/dist/functions/arpeggio/shape.d.ts +2 -3
- package/dist/functions/arpeggio/shape.js +20 -50
- package/dist/functions/bar/index.d.ts +8 -0
- package/dist/functions/bar/index.js +105 -8
- package/dist/functions/beam/auto.d.ts +1 -2
- package/dist/functions/beam/auto.js +80 -135
- package/dist/functions/beam/index.js +6 -12
- package/dist/functions/beam/layout.d.ts +1 -1
- package/dist/functions/beam/layout.js +1 -1
- package/dist/functions/box/index.js +0 -6
- package/dist/functions/br/index.d.ts +34 -2
- package/dist/functions/br/index.js +5 -4
- package/dist/functions/dash/index.js +9 -10
- package/dist/functions/default.js +2 -1
- package/dist/functions/div/index.d.ts +3 -4
- package/dist/functions/div/index.js +18 -14
- package/dist/functions/dot/index.js +5 -11
- package/dist/functions/dyn/index.js +55 -57
- package/dist/functions/gliss/index.js +131 -103
- package/dist/functions/grace/index.d.ts +3 -12
- package/dist/functions/grace/index.js +52 -102
- package/dist/functions/head/index.js +10 -7
- package/dist/functions/key/index.js +13 -15
- package/dist/functions/meter/index.d.ts +56 -1
- package/dist/functions/meter/index.js +15 -10
- package/dist/functions/note/index.js +6 -6
- package/dist/functions/note/noteName.d.ts +16 -0
- package/dist/functions/note/noteName.js +88 -0
- package/dist/functions/note/source-transform.js +8 -10
- package/dist/functions/ottava/index.js +35 -40
- package/dist/functions/page/index.d.ts +1 -0
- package/dist/functions/page/index.js +27 -21
- package/dist/functions/pagebreak/index.js +2 -2
- package/dist/functions/rest/index.js +5 -5
- package/dist/functions/set/index.js +4 -4
- package/dist/functions/slide/index.js +0 -1
- package/dist/functions/stack/index.js +8 -57
- package/dist/functions/symbol/index.d.ts +21 -2
- package/dist/functions/symbol/index.js +69 -24
- package/dist/functions/symbol/ornament.d.ts +1 -2
- package/dist/functions/symbol/shape.d.ts +6 -0
- package/dist/functions/symbol/shape.js +16 -3
- 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/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/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 +3 -2
- package/dist/functions/temporal.js +8 -0
- package/dist/functions/text/index.js +38 -35
- package/dist/functions/tie/index.js +44 -43
- package/dist/functions/tremolo/index.d.ts +2 -0
- package/dist/functions/tremolo/index.js +318 -0
- package/dist/functions/tuplet/index.js +4 -14
- package/dist/functions/up/index.js +81 -85
- package/dist/functions/voice/connections.d.ts +2 -1
- package/dist/functions/voice/connections.js +48 -10
- package/dist/functions/voice/index.d.ts +2 -3
- package/dist/functions/voice/index.js +2 -963
- package/dist/functions/voice/lyrics.d.ts +30 -0
- package/dist/functions/voice/lyrics.js +289 -0
- package/dist/functions/voice/voice.d.ts +63 -0
- package/dist/functions/voice/voice.js +373 -0
- package/dist/functions/voice/voices.d.ts +106 -0
- package/dist/functions/voice/voices.js +423 -0
- package/dist/functions/volta/index.js +5 -23
- package/dist/jpfun.core.min.js +76 -59
- package/dist/jpfun.from-midi.min.js +5 -5
- package/dist/jpfun.from-musicxml.min.js +8 -8
- package/dist/jpfun.min.js +81 -64
- package/dist/layout/default.d.ts +0 -1
- package/dist/layout/default.js +0 -1
- package/dist/layout/engine.js +30 -18
- package/dist/layout/model.d.ts +0 -1
- package/dist/layout/model.js +1 -4
- package/dist/layout/page.d.ts +2 -1
- package/dist/layout/page.js +14 -14
- package/dist/layout/range.d.ts +7 -6
- package/dist/layout/range.js +23 -14
- package/dist/layout/types.d.ts +9 -28
- package/dist/lowering/loweringContext.d.ts +18 -23
- package/dist/lowering/loweringContext.js +33 -46
- package/dist/lowering/track.d.ts +8 -1
- package/dist/lowering/types.d.ts +13 -11
- package/dist/parser/parse-utils/call-utils.d.ts +1 -2
- package/dist/parser/parse-utils/call-utils.js +6 -34
- package/dist/parser/parse-utils/note-utils.d.ts +3 -3
- package/dist/parser/parse-utils/note-utils.js +21 -33
- package/dist/parser/parse-utils/string-utils.d.ts +3 -2
- package/dist/parser/parse-utils/string-utils.js +20 -5
- package/dist/parser/parserContext.d.ts +9 -9
- package/dist/parser/parserContext.js +62 -11
- package/dist/pipeline.js +2 -3
- package/dist/playback/compile.js +131 -82
- package/dist/playback/event.d.ts +6 -6
- package/dist/playback/event.js +13 -49
- package/dist/playback/time.js +42 -31
- package/dist/playback/types.d.ts +3 -1
- package/dist/render/canvas.js +4 -22
- package/dist/render/recording.js +1 -4
- package/dist/render/svg.d.ts +0 -1
- package/dist/render/svg.js +33 -31
- package/dist/render/text.d.ts +36 -1
- package/dist/render/text.js +134 -0
- package/dist/render/translate.d.ts +0 -1
- package/dist/render/translate.js +6 -23
- package/dist/render/types.d.ts +0 -2
- package/grammar.md +39 -30
- package/package.json +3 -3
- package/dist/functions/note/noteNameFSM.d.ts +0 -8
- package/dist/functions/note/noteNameFSM.js +0 -181
- package/dist/iife/core.d.ts +0 -1
- package/dist/iife/core.js +0 -3
- package/dist/iife/from-midi.d.ts +0 -1
- package/dist/iife/from-midi.js +0 -15
- package/dist/iife/from-musicxml.d.ts +0 -1
- package/dist/iife/from-musicxml.js +0 -3
- package/dist/iife/full.d.ts +0 -1
- package/dist/iife/full.js +0 -3
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ASTFunctionNode } from "../ASTtypes.js";
|
|
2
2
|
import { ErrorDiagnostic } from "../../diagnostic.js";
|
|
3
|
-
import { findClosingQuote, quote
|
|
3
|
+
import { findClosingQuote, quote } from "../../parser/parse-utils/string-utils.js";
|
|
4
4
|
import { DEFAULT_KEY, TemporalNodeBase } from "../temporal.js";
|
|
5
|
+
import { paintRichLine, parseRichText, prepareRichLine } from "../../render/text.js";
|
|
5
6
|
class TextFunction extends ASTFunctionNode {
|
|
6
7
|
static def = {
|
|
7
8
|
name: ["text"],
|
|
@@ -10,7 +11,9 @@ class TextFunction extends ASTFunctionNode {
|
|
|
10
11
|
~~~jpfun
|
|
11
12
|
@text(进入主题, size=0.8em, align=center)
|
|
12
13
|
~~~
|
|
13
|
-
**简写**:直接写双引号文本,如 \`"进入主题"
|
|
14
|
+
**简写**:直接写双引号文本,如 \`"进入主题"\`;可跨行,双引号须配对。
|
|
15
|
+
|
|
16
|
+
支持 \`*斜体*\`、\`**粗体**\`、\`_下划线_\`、\`^上标^\`(再次出现即关闭,不关闭则一直生效;写 \`\\*\`、\`\\_\`、\`\\^\` 显示原字符)。支持 \`\\uE050\` 形式的 Unicode 转义;反斜杠写 \`\\\\\`。`,
|
|
14
17
|
allowExtraArgs: false,
|
|
15
18
|
args: [
|
|
16
19
|
{
|
|
@@ -54,18 +57,25 @@ class TextFunction extends ASTFunctionNode {
|
|
|
54
57
|
if (close < 0)
|
|
55
58
|
return null; // 未闭合就不去糖,与预处理“配对才算字符串”一致
|
|
56
59
|
const node = {
|
|
57
|
-
kind: "
|
|
58
|
-
|
|
59
|
-
name: "text",
|
|
60
|
-
args: new Map([[0, removeQuote(source.slice(start, close + 1))]]),
|
|
60
|
+
kind: "sugar",
|
|
61
|
+
data: TextFunction,
|
|
61
62
|
span: { start, end: close + 1 },
|
|
62
63
|
syntaxKind: "string",
|
|
63
64
|
};
|
|
64
65
|
return { next: close + 1, node };
|
|
65
66
|
}
|
|
66
|
-
|
|
67
|
+
static deSugarRelation(ctx, nodes, at) {
|
|
68
|
+
const node = nodes[at];
|
|
69
|
+
if (node.data !== TextFunction)
|
|
70
|
+
return null;
|
|
71
|
+
// 之所以不在 deSugarAtom 里直接解码返回 typed call,是因为字符串转义可能产生诊断(如非法 \u 转义):
|
|
72
|
+
// 第一轮 deSugarAtom 没有 ctx(抛异常则会中断词法扫描),放到第二轮才能复用 parseArgWithType 记录警告并回退原文
|
|
73
|
+
ctx.pushNode(new TextFunction(node.span, new Map([[0, ctx.parseArgWithType(node.span, "string")]]), ctx, null));
|
|
74
|
+
return at + 1;
|
|
75
|
+
}
|
|
76
|
+
text;
|
|
67
77
|
size;
|
|
68
|
-
|
|
78
|
+
lineHeight;
|
|
69
79
|
align;
|
|
70
80
|
font;
|
|
71
81
|
constructor(sourceSpan, args, ctx, parent = null) {
|
|
@@ -75,58 +85,51 @@ class TextFunction extends ASTFunctionNode {
|
|
|
75
85
|
if (align !== "left" && align !== "center" && align !== "right") {
|
|
76
86
|
throw new ErrorDiagnostic("E_TEXT_INVALID_ALIGN", "@text 的 align 参数必须是 'left'、'center' 或 'right'", sourceSpan);
|
|
77
87
|
}
|
|
78
|
-
this.
|
|
88
|
+
this.text = text.replace(/\r?\n/g, "\n");
|
|
79
89
|
this.size = ctx.length2px(size);
|
|
80
|
-
this.
|
|
90
|
+
this.lineHeight = lineHeight;
|
|
81
91
|
this.align = align;
|
|
82
92
|
}
|
|
83
93
|
loweringEnter() { return [new TextTemporalNode(this)]; }
|
|
84
94
|
toString() {
|
|
85
|
-
|
|
86
|
-
return `@text(${quote(this.lines.join("\n"))}, size=${this.size}px, lineheight=${lineHeight}, align=${this.align}, font=${quote(this.font)})`;
|
|
95
|
+
return `@text(${quote(this.text)}, size=${this.size}px, lineheight=${this.lineHeight}, align=${this.align}, font=${quote(this.font)})`;
|
|
87
96
|
}
|
|
88
97
|
}
|
|
89
98
|
export const TextNode = TextFunction;
|
|
90
99
|
class TextTemporalNode extends TemporalNodeBase {
|
|
91
|
-
|
|
92
|
-
textBaselineY = 0;
|
|
100
|
+
preparedLines = [];
|
|
93
101
|
constructor(ast) {
|
|
94
102
|
super();
|
|
95
103
|
this.ast = ast;
|
|
96
104
|
this.mergeKey = DEFAULT_KEY;
|
|
97
|
-
this.style = { fontSize: ast.size, fontFamily: ast.font, fill: "#000", textAlign: ast.align };
|
|
98
105
|
this.initLayoutBox();
|
|
99
106
|
}
|
|
100
107
|
prepareLayout(context) {
|
|
101
|
-
const {
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
width = Math.max(width, measure(lines[i]).w);
|
|
108
|
+
const { text, align, size, font, lineHeight } = this.ast;
|
|
109
|
+
const style = { fontSize: size, fontFamily: font, fill: "#000", textAlign: align };
|
|
110
|
+
this.preparedLines = parseRichText(text).map(runs => prepareRichLine(runs, style, context.textMeasurer));
|
|
111
|
+
const first = this.preparedLines[0];
|
|
112
|
+
const width = Math.max(...this.preparedLines.map(l => l.w));
|
|
107
113
|
this.box.w = width;
|
|
108
|
-
this.box.h = (
|
|
114
|
+
this.box.h = (this.preparedLines.length - 1) * lineHeight * size + first.h;
|
|
109
115
|
this.box.visualAxis = this.box.h / 2;
|
|
110
|
-
this.textBaselineY = first.baseline;
|
|
111
116
|
if (align === "center")
|
|
112
117
|
this.box.anchor = width / 2;
|
|
113
|
-
else if (align === "right") {
|
|
114
|
-
const lastChar = [...lines[0]].at(-1);
|
|
115
|
-
this.box.anchor = width - (lastChar ? measure(lastChar).w / 2 : 0);
|
|
116
|
-
}
|
|
117
118
|
else {
|
|
118
|
-
//
|
|
119
|
-
const
|
|
120
|
-
|
|
119
|
+
// 左/右对齐时锚点落在首行首/末字符中心,单字标记才能像音符一样对准宿主
|
|
120
|
+
const edgeIdx = align === "right" ? -1 : 0;
|
|
121
|
+
const edgeRun = first.runs.at(edgeIdx);
|
|
122
|
+
const half = edgeRun ? context.textMeasurer.measureText([...edgeRun.text].at(edgeIdx), edgeRun.style).w / 2 : 0;
|
|
123
|
+
this.box.anchor = align === "right" ? width - half : half;
|
|
121
124
|
}
|
|
122
125
|
}
|
|
123
126
|
paint(painter) {
|
|
124
|
-
const {
|
|
127
|
+
const { align, lineHeight, size } = this.ast;
|
|
125
128
|
const x = this.box.x + (align === "center" ? this.box.w / 2 : align === "right" ? this.box.w : 0);
|
|
126
|
-
let y = this.box.y + this.
|
|
127
|
-
for (const line of
|
|
128
|
-
painter
|
|
129
|
-
y +=
|
|
129
|
+
let y = this.box.y + this.preparedLines[0].baseline;
|
|
130
|
+
for (const line of this.preparedLines) {
|
|
131
|
+
paintRichLine(painter, line, x, y);
|
|
132
|
+
y += lineHeight * size;
|
|
130
133
|
}
|
|
131
134
|
}
|
|
132
135
|
}
|
|
@@ -3,6 +3,29 @@ import { Diagnostic, ErrorDiagnostic } from "../../diagnostic.js";
|
|
|
3
3
|
import { isVisualTemporalNode, } from "../temporal.js";
|
|
4
4
|
import { pathBounds } from "../../layout/path.js";
|
|
5
5
|
import { getLayoutBounds } from "../../layout/engine.js";
|
|
6
|
+
import { lineEntryX, lineRightX } from "../../layout/range.js";
|
|
7
|
+
/** 仅索引被 @tie 引用过的端点,避免为全谱无关音符分配数组与 Map 节点 */
|
|
8
|
+
const tieEndpoints = new WeakSet();
|
|
9
|
+
const notesByOriginNode = new WeakMap();
|
|
10
|
+
function endpointNotes(notes, endpoint) {
|
|
11
|
+
let index = notesByOriginNode.get(notes);
|
|
12
|
+
if (!index) {
|
|
13
|
+
index = new Map();
|
|
14
|
+
for (const note of notes) {
|
|
15
|
+
for (const { node } of note.origins) {
|
|
16
|
+
if (!tieEndpoints.has(node))
|
|
17
|
+
continue;
|
|
18
|
+
const group = index.get(node);
|
|
19
|
+
if (group)
|
|
20
|
+
group.push(note);
|
|
21
|
+
else
|
|
22
|
+
index.set(node, [note]);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
notesByOriginNode.set(notes, index);
|
|
26
|
+
}
|
|
27
|
+
return index.get(endpoint) ?? [];
|
|
28
|
+
}
|
|
6
29
|
/** 三次贝塞尔控制点的抬高系数:两个控制点同高时,实际弧高恰好是抬高的 3/4 */
|
|
7
30
|
const CUBIC_LIFT = 4 / 3;
|
|
8
31
|
/** 弧带中部最大厚度与字号之比 */
|
|
@@ -22,7 +45,7 @@ class TieFunction extends ASTFunctionNode {
|
|
|
22
45
|
- **位置参数**:端点标签,可传多个,按顺序连接;省略时查找最近的可标记对象,包括增时线
|
|
23
46
|
- **height**:仅命名的弧线高度参数,默认 \`0\`(自动);非正数按水平跨度自动调整,在 \`2.5em\` 跨度处平滑达到 \`0.5em\` 上限,正数指定固定弧高。em 相对调用处字号;可用 \`@set(tie.height=0.8em)\` 设置局部默认值,显式传参优先
|
|
24
47
|
|
|
25
|
-
同行端点用一条弧线连接,自动高度按水平跨度计算;跨行时自动拆成多段,自动模式下各段统一使用 \`0.45em\`
|
|
48
|
+
同行端点用一条弧线连接,自动高度按水平跨度计算;跨行时自动拆成多段,自动模式下各段统一使用 \`0.45em\` 高度。同轨同音且时间连续的音段建立播放连接:未另加修饰的后继音段并入前段共同展开(如 \`1 ^ $tr 1 @tie()\` 全程颤音),带独立修饰的后继音段从自身起点生效(如 \`1 1 ^ $tr @tie()\` 从第二拍开始颤音)。涉及增时线的连接仅绘制,不合并播放音符。`,
|
|
26
49
|
allowExtraArgs: true,
|
|
27
50
|
extraArgType: "label",
|
|
28
51
|
args: [{
|
|
@@ -35,19 +58,13 @@ class TieFunction extends ASTFunctionNode {
|
|
|
35
58
|
};
|
|
36
59
|
endPoints = [];
|
|
37
60
|
height;
|
|
38
|
-
fontSize;
|
|
39
61
|
constructor(sourceSpan, args, ctx, parent = null) {
|
|
40
62
|
super(sourceSpan, parent);
|
|
41
63
|
// 命名选项统一解析默认值,位置参数仍全部作为端点
|
|
42
64
|
const [height] = this.getArgValue(args, ctx);
|
|
43
65
|
for (const [key, value] of args) {
|
|
44
|
-
if (key === "
|
|
45
|
-
|
|
46
|
-
const v = value instanceof ASTFunctionNode
|
|
47
|
-
? value
|
|
48
|
-
: ctx.parseArgWithType(value.valueSpan, "label", sourceSpan.start);
|
|
49
|
-
if (v !== null)
|
|
50
|
-
this.endPoints.push(v);
|
|
66
|
+
if (typeof key === "number")
|
|
67
|
+
this.endPoints.push(value);
|
|
51
68
|
}
|
|
52
69
|
// 数目不足,则找最近的;用 unshift 而不是按下标赋值,否则空洞会让 length 虚高、骗过下面的校验
|
|
53
70
|
let k = ctx.labelableNodes.length - 1;
|
|
@@ -57,10 +74,10 @@ class TieFunction extends ASTFunctionNode {
|
|
|
57
74
|
continue;
|
|
58
75
|
this.endPoints.unshift(candidate);
|
|
59
76
|
}
|
|
60
|
-
if (this.endPoints.length < 2)
|
|
61
|
-
throw new ErrorDiagnostic("E_NOT_ENOUGH_ARGS", "@
|
|
77
|
+
if (this.endPoints.length < 2) {
|
|
78
|
+
throw new ErrorDiagnostic("E_NOT_ENOUGH_ARGS", "@{fn} 连音线需要至少两个端点", sourceSpan, { fn: "tie" });
|
|
79
|
+
}
|
|
62
80
|
this.height = Math.max(0, ctx.length2px(height));
|
|
63
|
-
this.fontSize = ctx.variables.fontsize;
|
|
64
81
|
}
|
|
65
82
|
/**
|
|
66
83
|
* tie 不推进时间
|
|
@@ -78,7 +95,7 @@ class TieFunction extends ASTFunctionNode {
|
|
|
78
95
|
ctx.diagnostics.push(Diagnostic.warning.UnresolvedEndpoint("tie", this.sourceSpan));
|
|
79
96
|
return [];
|
|
80
97
|
}
|
|
81
|
-
ctx.addAttachment(new TieLayoutAttachment(endPoints, this.height, this.
|
|
98
|
+
ctx.addAttachment(new TieLayoutAttachment(endPoints, this.height, this.sourceSpan));
|
|
82
99
|
return [];
|
|
83
100
|
}
|
|
84
101
|
toString(source) {
|
|
@@ -94,16 +111,17 @@ class TieLayoutAttachment {
|
|
|
94
111
|
sourceSpan;
|
|
95
112
|
endPoints;
|
|
96
113
|
height;
|
|
97
|
-
|
|
114
|
+
size;
|
|
98
115
|
/** 弧带中部厚度;两端收尖到 0。端点字号不随布局变化,可以一次算定 */
|
|
99
116
|
thickness;
|
|
100
|
-
constructor(endPoints, height,
|
|
117
|
+
constructor(endPoints, height, sourceSpan) {
|
|
101
118
|
this.endPoints = endPoints;
|
|
119
|
+
for (const endpoint of endPoints)
|
|
120
|
+
tieEndpoints.add(endpoint);
|
|
102
121
|
this.height = height;
|
|
103
|
-
this.fontSize = fontSize;
|
|
104
122
|
this.sourceSpan = sourceSpan;
|
|
105
|
-
|
|
106
|
-
this.thickness = Math.max(1.2, size * THICKNESS_RATIO);
|
|
123
|
+
this.size = endPoints.reduce((current, endpoint) => Math.max(current, endpoint.ast.size), 0);
|
|
124
|
+
this.thickness = Math.max(1.2, this.size * THICKNESS_RATIO);
|
|
107
125
|
}
|
|
108
126
|
/**
|
|
109
127
|
* 为同轨、同音且时间相接的逻辑音段建立连接,各次反复及各段装饰保持独立
|
|
@@ -111,13 +129,12 @@ class TieLayoutAttachment {
|
|
|
111
129
|
*/
|
|
112
130
|
applyPlayback(context) {
|
|
113
131
|
// 整体端点可能包含和弦多个成员或多遍访问,每个首段分别寻找自己的连接链。
|
|
114
|
-
for (const head of context.notes
|
|
132
|
+
for (const head of endpointNotes(context.notes, this.endPoints[0])) {
|
|
115
133
|
let previous = head;
|
|
116
134
|
// 按显式端点顺序延续;某一端点没有相接音段就停止,不能跨过缺口连接。
|
|
117
135
|
for (let index = 1; index < this.endPoints.length; index++) {
|
|
118
136
|
// connect 同时认领候选:配对冲突时继续找其他成员,重复声明可复用原配对。
|
|
119
|
-
const next = context.notes.find(note => note !== previous
|
|
120
|
-
&& note.origins.some(origin => origin.node === this.endPoints[index])
|
|
137
|
+
const next = endpointNotes(context.notes, this.endPoints[index]).find(note => note !== previous
|
|
121
138
|
&& note.track === previous.track
|
|
122
139
|
&& note.midi === previous.midi
|
|
123
140
|
&& note.percussion === previous.percussion
|
|
@@ -189,39 +206,23 @@ class TieLayoutAttachment {
|
|
|
189
206
|
segments.push(this.arcSegment(start, end, startNode.layoutLine, startTop <= endTop ? startNode.track : endNode.track));
|
|
190
207
|
continue;
|
|
191
208
|
}
|
|
192
|
-
const height = this.height > 0 ? this.height : this.
|
|
209
|
+
const height = this.height > 0 ? this.height : this.size * CROSS_LINE_HEIGHT_RATIO;
|
|
193
210
|
// 首行先起弧,再沿水平段延伸到当前谱面行最右侧
|
|
194
|
-
segments.push(this.openingSegment(start,
|
|
211
|
+
segments.push(this.openingSegment(start, lineRightX(context, startNode.layoutLine), height, startNode.layoutLine, startNode.track));
|
|
195
212
|
// 中间行可能没有任何可见对象,仍然需要逐行补一段水平线
|
|
196
213
|
for (let line = startNode.layoutLine + 1; line < endNode.layoutLine; line++) {
|
|
197
|
-
segments.push(this.horizontalSegment(
|
|
214
|
+
segments.push(this.horizontalSegment(lineEntryX(context, line, startNode.track), lineRightX(context, line), this.hostTop(context, line, startNode.track) - height, line, startNode.track));
|
|
198
215
|
}
|
|
199
216
|
// 跳过声部名、大括号等位于端点列之前的系统前缀,再落弧到终点
|
|
200
|
-
segments.push(this.closingSegment(
|
|
217
|
+
segments.push(this.closingSegment(lineEntryX(context, endNode.layoutLine, endNode.track), end, height, endNode.layoutLine, endNode.track));
|
|
201
218
|
}
|
|
202
219
|
return segments;
|
|
203
220
|
}
|
|
204
221
|
resolveHeight(span) {
|
|
205
222
|
if (this.height > 0)
|
|
206
223
|
return this.height;
|
|
207
|
-
const ratio = Math.min(1, span / (this.
|
|
208
|
-
return this.
|
|
209
|
-
}
|
|
210
|
-
lineEntryX(context, lineIndex, track) {
|
|
211
|
-
const line = context.lines[lineIndex];
|
|
212
|
-
const host = line.trackRuns.get(track)?.find(host => !host.T.isZero());
|
|
213
|
-
return host?.box.x ?? context.originX;
|
|
214
|
-
}
|
|
215
|
-
lineRightX(context, lineIndex) {
|
|
216
|
-
const runs = context.lines[lineIndex].trackRuns;
|
|
217
|
-
if (runs.size === 0)
|
|
218
|
-
return context.originX + context.width;
|
|
219
|
-
let right = context.originX;
|
|
220
|
-
for (const run of runs.values()) {
|
|
221
|
-
for (const host of run)
|
|
222
|
-
right = Math.max(right, host.box.x + host.box.w);
|
|
223
|
-
}
|
|
224
|
-
return right;
|
|
224
|
+
const ratio = Math.min(1, span / (this.size * AUTO_SPAN_RATIO));
|
|
225
|
+
return this.size * AUTO_HEIGHT_RATIO * ratio * (2 - ratio);
|
|
225
226
|
}
|
|
226
227
|
hostTop(context, line, track) {
|
|
227
228
|
return context.getVisualAxis(line, track) + (context.getHostExtent(line, track)?.top ?? 0);
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import { ErrorDiagnostic } from "../../diagnostic.js";
|
|
2
|
+
import { pathBounds } from "../../layout/path.js";
|
|
3
|
+
import { ASTFunctionNode, } from "../ASTtypes.js";
|
|
4
|
+
import { isVisualTemporalNode } from "../temporal.js";
|
|
5
|
+
const MAX_SUBNOTES = 256;
|
|
6
|
+
function isDash(node) {
|
|
7
|
+
return node.ast instanceof ASTFunctionNode && node.ast.callName === "dash";
|
|
8
|
+
}
|
|
9
|
+
function isAudibleNote(item) {
|
|
10
|
+
return "midi" in item;
|
|
11
|
+
}
|
|
12
|
+
function collectNoteAxes(node, axes = []) {
|
|
13
|
+
if ("host" in node && isVisualTemporalNode(node.host)) {
|
|
14
|
+
return collectNoteAxes(node.host, axes);
|
|
15
|
+
}
|
|
16
|
+
if ("members" in node && Array.isArray(node.members)) {
|
|
17
|
+
for (const member of node.members)
|
|
18
|
+
collectNoteAxes(member, axes);
|
|
19
|
+
return axes;
|
|
20
|
+
}
|
|
21
|
+
if (typeof node.resolvedMidi === "number"
|
|
22
|
+
|| node.ast.name === "9") {
|
|
23
|
+
axes.push(node.box.y + node.box.visualAxis);
|
|
24
|
+
}
|
|
25
|
+
return axes;
|
|
26
|
+
}
|
|
27
|
+
function visualCenterY(node) {
|
|
28
|
+
const axes = collectNoteAxes(node);
|
|
29
|
+
return (Math.min(...axes) + Math.max(...axes)) / 2;
|
|
30
|
+
}
|
|
31
|
+
function collectVisitSpans(list, target, endAt) {
|
|
32
|
+
let targetOrigin;
|
|
33
|
+
const matched = [];
|
|
34
|
+
for (let i = list.length - 1; i >= 0; i--) {
|
|
35
|
+
const item = list[i];
|
|
36
|
+
if (item.origins.at(-1).node.track !== target.track)
|
|
37
|
+
continue;
|
|
38
|
+
const origin = item.origins.find(entry => entry.node === target);
|
|
39
|
+
if (!targetOrigin) {
|
|
40
|
+
if (!origin)
|
|
41
|
+
continue;
|
|
42
|
+
if (endAt && !item.end.equals(endAt))
|
|
43
|
+
return [];
|
|
44
|
+
targetOrigin = origin;
|
|
45
|
+
}
|
|
46
|
+
else if (origin !== targetOrigin) {
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
if (endAt && !item.end.equals(endAt))
|
|
50
|
+
return [];
|
|
51
|
+
matched.push(item);
|
|
52
|
+
}
|
|
53
|
+
return matched;
|
|
54
|
+
}
|
|
55
|
+
function singleTremoloTransform(n) {
|
|
56
|
+
const rate = 1 << n;
|
|
57
|
+
return (_context, owned) => {
|
|
58
|
+
const result = [];
|
|
59
|
+
for (const note of owned) {
|
|
60
|
+
const duration = note.end.clone().sub(note.start);
|
|
61
|
+
const count = Math.min(MAX_SUBNOTES, Math.max(2, Math.round(duration.toNumber() * rate)));
|
|
62
|
+
const step = duration.div(count);
|
|
63
|
+
for (let i = 0; i < count; i++) {
|
|
64
|
+
const start = step.clone().mul(i).add(note.start);
|
|
65
|
+
result.push({
|
|
66
|
+
...note,
|
|
67
|
+
start,
|
|
68
|
+
end: start.clone().add(step),
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return result;
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
class TremoloFunction extends ASTFunctionNode {
|
|
76
|
+
static def = {
|
|
77
|
+
name: ["tremolo"],
|
|
78
|
+
description: "震音(同音震音与双音交替震音)",
|
|
79
|
+
details: `\
|
|
80
|
+
~~~jpfun
|
|
81
|
+
@tremolo(5, n=3)
|
|
82
|
+
@tremolo({#5,^7, 2^4}, n=3)
|
|
83
|
+
~~~
|
|
84
|
+
- **单音震音**:内容为单个音符或和弦(后可接增时线 \`-\`),斜杠记在最末元素右下角,播放时按 \`1 / 2^n\` 四分音符时值同音重复。
|
|
85
|
+
- **双音震音**:内容为两个同轨、等时值的相邻音符或和弦,斜杠记在两音之间,播放时在两音总时值内按 \`1 / 2^n\` 四分音符时值交替发声。`,
|
|
86
|
+
allowExtraArgs: false,
|
|
87
|
+
args: [
|
|
88
|
+
{ type: "content", default: null, description: "单个音符(可带增时线)或两个等时值的音符/和弦" },
|
|
89
|
+
{ name: "n", type: "number", default: 3, description: "斜杠数量,取 1..3 的整数" },
|
|
90
|
+
],
|
|
91
|
+
};
|
|
92
|
+
content;
|
|
93
|
+
n;
|
|
94
|
+
get children() { return [this.content]; }
|
|
95
|
+
constructor(span, args, ctx, parent = null) {
|
|
96
|
+
super(span, parent);
|
|
97
|
+
const [content, n] = this.getArgValue(args, ctx);
|
|
98
|
+
if (!Number.isSafeInteger(n) || n < 1 || n > 3) {
|
|
99
|
+
throw new ErrorDiagnostic("E_TREMOLO_INVALID_N", "@tremolo 的斜杠数 n 必须是 1 到 3 的整数", span);
|
|
100
|
+
}
|
|
101
|
+
this.content = content;
|
|
102
|
+
this.n = n;
|
|
103
|
+
content.parent = this;
|
|
104
|
+
}
|
|
105
|
+
loweringEnter(ctx) {
|
|
106
|
+
for (let ancestor = this.parent; ancestor; ancestor = ancestor.parent) {
|
|
107
|
+
if (ancestor instanceof TremoloFunction) {
|
|
108
|
+
throw new ErrorDiagnostic("E_TREMOLO_CONTENT", "@tremolo 不能嵌套 @tremolo", this.sourceSpan);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const group = {
|
|
112
|
+
nodes: [],
|
|
113
|
+
onTemporal(node) { if (isVisualTemporalNode(node))
|
|
114
|
+
group.nodes.push(node); },
|
|
115
|
+
};
|
|
116
|
+
ctx.beginLoweringGroup(this, group);
|
|
117
|
+
return [];
|
|
118
|
+
}
|
|
119
|
+
loweringExit(ctx) {
|
|
120
|
+
const { nodes } = ctx.endLoweringGroup(this);
|
|
121
|
+
const isSingle = nodes.length >= 1 && !isDash(nodes[0]) && nodes.slice(1).every(isDash);
|
|
122
|
+
const isPair = nodes.length === 2 && !isDash(nodes[0]) && !isDash(nodes[1]);
|
|
123
|
+
if ((!isSingle && !isPair) || nodes.some(node => node.T.compare(0) <= 0)) {
|
|
124
|
+
throw new ErrorDiagnostic("E_TREMOLO_CONTENT", "@tremolo 的内容必须是单个音符(可带增时线)或两个等时值的音符/和弦", this.sourceSpan);
|
|
125
|
+
}
|
|
126
|
+
if (nodes.some(node => node.track !== nodes[0].track)) {
|
|
127
|
+
throw new ErrorDiagnostic("E_TREMOLO_CROSS_TRACK", "@tremolo 的内容必须位于同一音轨", this.sourceSpan);
|
|
128
|
+
}
|
|
129
|
+
const attachment = new TremoloAttachment(nodes, this);
|
|
130
|
+
ctx.addAttachment(attachment);
|
|
131
|
+
ctx.deferFinalize(() => attachment.finalize());
|
|
132
|
+
const anchorHost = isSingle ? nodes.at(-1) : nodes[0];
|
|
133
|
+
const prepare = anchorHost.prepareHorizontal;
|
|
134
|
+
anchorHost.prepareHorizontal = line => {
|
|
135
|
+
prepare?.call(anchorHost, line);
|
|
136
|
+
attachment.registerHorizontal(line);
|
|
137
|
+
};
|
|
138
|
+
return [];
|
|
139
|
+
}
|
|
140
|
+
toString(source) {
|
|
141
|
+
return `@tremolo(${this.content.toString(source)}, n=${this.n})`;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
export const TremoloNode = TremoloFunction;
|
|
145
|
+
class TremoloAttachment {
|
|
146
|
+
nodes;
|
|
147
|
+
owner;
|
|
148
|
+
layer = "foreground";
|
|
149
|
+
endPoints;
|
|
150
|
+
get sourceSpan() { return this.owner.sourceSpan; }
|
|
151
|
+
constructor(nodes, owner) {
|
|
152
|
+
this.nodes = nodes;
|
|
153
|
+
this.owner = owner;
|
|
154
|
+
const isSingle = nodes.length === 1 || isDash(nodes[1]);
|
|
155
|
+
this.endPoints = isSingle ? [nodes.at(-1)] : [nodes[0], nodes[1]];
|
|
156
|
+
}
|
|
157
|
+
finalize() {
|
|
158
|
+
const { nodes, owner, endPoints } = this;
|
|
159
|
+
const single = endPoints.length === 1;
|
|
160
|
+
const line = nodes[0].layoutLine;
|
|
161
|
+
if (nodes.some(node => node.layoutLine !== line)) {
|
|
162
|
+
throw new ErrorDiagnostic("E_TREMOLO_CROSS_LINE", "@tremolo 不支持跨谱面行", owner.sourceSpan);
|
|
163
|
+
}
|
|
164
|
+
if (collectNoteAxes(nodes[0]).length === 0 || (!single && collectNoteAxes(nodes[1]).length === 0)) {
|
|
165
|
+
throw new ErrorDiagnostic("E_TREMOLO_CONTENT", "@tremolo 的目标必须包含发声音符", owner.sourceSpan);
|
|
166
|
+
}
|
|
167
|
+
if (single) {
|
|
168
|
+
const target = nodes[0];
|
|
169
|
+
const transform = singleTremoloTransform(owner.n);
|
|
170
|
+
const emit = target.emitPlayback;
|
|
171
|
+
target.emitPlayback = emitter => {
|
|
172
|
+
emit?.call(target, emitter);
|
|
173
|
+
emitter.defer(context => {
|
|
174
|
+
for (const span of collectVisitSpans(context.spans, target)) {
|
|
175
|
+
if (isAudibleNote(span))
|
|
176
|
+
context.transform(span, transform);
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
const [first, second] = nodes;
|
|
183
|
+
if (!first.T.equals(second.T))
|
|
184
|
+
throw new ErrorDiagnostic("E_TREMOLO_DURATION_MISMATCH", "@tremolo 双音震音的两个目标时值必须相等", owner.sourceSpan);
|
|
185
|
+
const emitSecond = second.emitPlayback;
|
|
186
|
+
second.emitPlayback = emitter => {
|
|
187
|
+
emitSecond?.call(second, emitter);
|
|
188
|
+
const { start: secondStart, end: t2 } = emitter;
|
|
189
|
+
emitter.defer(context => {
|
|
190
|
+
const firstSpans = collectVisitSpans(context.spans, first, secondStart);
|
|
191
|
+
const secondSpans = collectVisitSpans(context.spans, second);
|
|
192
|
+
if (firstSpans.length === 0 || secondSpans.length === 0)
|
|
193
|
+
return;
|
|
194
|
+
const t0 = firstSpans.reduce((min, s) => s.start.compare(min) < 0 ? s.start : min, firstSpans[0].start).clone();
|
|
195
|
+
const total = t2.clone().sub(t0);
|
|
196
|
+
const pairs = Math.min(MAX_SUBNOTES / 2, Math.max(2, Math.round(total.toNumber() * (1 << (owner.n - 1)))));
|
|
197
|
+
const step = total.clone().div(pairs * 2);
|
|
198
|
+
const slice = (divisor, extendTail) => (_ctx, owned) => owned.flatMap(item => {
|
|
199
|
+
const baseEnd = item.end.compare(t2) > 0 ? t2 : item.end;
|
|
200
|
+
const sliceStep = baseEnd.clone().sub(item.start).div(divisor);
|
|
201
|
+
const out = [];
|
|
202
|
+
for (let k = 0; k < pairs; k++) {
|
|
203
|
+
const start = sliceStep.clone().mul(2 * k).add(item.start);
|
|
204
|
+
const end = extendTail && k === pairs - 1 && item.end.compare(t2) > 0
|
|
205
|
+
? item.end.clone()
|
|
206
|
+
: start.clone().add(sliceStep);
|
|
207
|
+
out.push({ ...item, start, end });
|
|
208
|
+
}
|
|
209
|
+
return out;
|
|
210
|
+
});
|
|
211
|
+
const evenTransform = slice(pairs * 2, false);
|
|
212
|
+
const oddTransform = slice(pairs * 2 - 1, true);
|
|
213
|
+
for (const span of firstSpans) {
|
|
214
|
+
span.start.copyFrom(t0);
|
|
215
|
+
span.end.copyFrom(t2);
|
|
216
|
+
if (isAudibleNote(span))
|
|
217
|
+
context.transform(span, evenTransform);
|
|
218
|
+
}
|
|
219
|
+
for (const span of secondSpans) {
|
|
220
|
+
span.start.copyFrom(t0).add(step);
|
|
221
|
+
span.end.copyFrom(t2);
|
|
222
|
+
if (isAudibleNote(span))
|
|
223
|
+
context.transform(span, oddTransform);
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
registerHorizontal(line) {
|
|
229
|
+
if (this.endPoints.length === 1) {
|
|
230
|
+
const host = this.endPoints[0];
|
|
231
|
+
if (line.columnOf(host) < 0)
|
|
232
|
+
return;
|
|
233
|
+
const size = host.ast.size;
|
|
234
|
+
const space = host.box.w - host.box.anchor + size * 0.6;
|
|
235
|
+
line.registerHorizontalLayoutHook(host, host, ({ columns, start }) => {
|
|
236
|
+
for (const element of columns[start]) {
|
|
237
|
+
if (element.box !== host.box)
|
|
238
|
+
continue;
|
|
239
|
+
element.WR = Math.max(element.WR, space);
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
const [from, to] = this.endPoints;
|
|
245
|
+
const start = line.columnOf(from);
|
|
246
|
+
const end = line.columnOf(to);
|
|
247
|
+
if (start < 0 || end < 0)
|
|
248
|
+
return;
|
|
249
|
+
if (end <= start || line.trackIndexOf(to) !== line.trackIndexOf(from) + 1) {
|
|
250
|
+
throw new ErrorDiagnostic("E_TREMOLO_ADJACENT", "@tremolo 双音震音的两个端点必须在同一谱面行相邻", this.owner.sourceSpan);
|
|
251
|
+
}
|
|
252
|
+
const size = Math.max(from.ast.size, to.ast.size);
|
|
253
|
+
const right = from.box.w - from.box.anchor + size * 0.84;
|
|
254
|
+
line.registerHorizontalLayoutHook(from, to, ({ columns }) => {
|
|
255
|
+
for (const element of columns[start])
|
|
256
|
+
element.WR = Math.max(element.WR, right);
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
createGeometry() {
|
|
260
|
+
const { n } = this.owner;
|
|
261
|
+
const host = this.endPoints[0];
|
|
262
|
+
let size = host.ast.size;
|
|
263
|
+
let left;
|
|
264
|
+
let right;
|
|
265
|
+
let centerY;
|
|
266
|
+
let rise;
|
|
267
|
+
let stepY;
|
|
268
|
+
if (this.endPoints.length === 1) {
|
|
269
|
+
left = host.box.x + host.box.w + size * 0.1;
|
|
270
|
+
right = left + size * 0.34;
|
|
271
|
+
centerY = host.box.y + host.box.visualAxis + size * 0.14;
|
|
272
|
+
rise = size * 0.18;
|
|
273
|
+
stepY = size * 0.12;
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
const [from, to] = this.endPoints;
|
|
277
|
+
size = Math.max(from.ast.size, to.ast.size);
|
|
278
|
+
const gap = size * 0.12;
|
|
279
|
+
const availLeft = from.box.x + from.box.w + gap;
|
|
280
|
+
const availRight = to.box.x - gap;
|
|
281
|
+
if (availRight <= availLeft) {
|
|
282
|
+
throw new ErrorDiagnostic("E_TREMOLO_SPACE", "@tremolo 的端点之间没有可用的水平绘制空间", this.owner.sourceSpan);
|
|
283
|
+
}
|
|
284
|
+
const spanX = Math.min(availRight - availLeft, size * 1.2);
|
|
285
|
+
const midX = (availLeft + availRight) / 2;
|
|
286
|
+
left = midX - spanX / 2;
|
|
287
|
+
right = midX + spanX / 2;
|
|
288
|
+
centerY = (visualCenterY(from) + visualCenterY(to)) / 2;
|
|
289
|
+
rise = Math.min(size * 0.26, Math.max(size * 0.16, spanX * 0.32));
|
|
290
|
+
stepY = size * 0.13;
|
|
291
|
+
}
|
|
292
|
+
const strokeWidth = Math.max(1, size * 0.06);
|
|
293
|
+
const commands = buildSlashCommands(n, left, right, centerY, rise, stepY);
|
|
294
|
+
const bounds = pathBounds(commands);
|
|
295
|
+
const region = {
|
|
296
|
+
x: bounds.x - strokeWidth / 2,
|
|
297
|
+
y: bounds.y - strokeWidth / 2,
|
|
298
|
+
w: bounds.w + strokeWidth,
|
|
299
|
+
h: bounds.h + strokeWidth,
|
|
300
|
+
line: host.layoutLine,
|
|
301
|
+
track: host.track,
|
|
302
|
+
};
|
|
303
|
+
return {
|
|
304
|
+
regions: [region],
|
|
305
|
+
paint(painter) {
|
|
306
|
+
painter.drawPath(commands, { fill: "none", stroke: "#000", strokeWidth });
|
|
307
|
+
},
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
function buildSlashCommands(n, left, right, centerY, rise, stepY) {
|
|
312
|
+
const commands = [];
|
|
313
|
+
for (let i = 0; i < n; i++) {
|
|
314
|
+
const midY = centerY + (i - (n - 1) / 2) * stepY;
|
|
315
|
+
commands.push({ op: "M", x: left, y: midY + rise / 2 }, { op: "L", x: right, y: midY - rise / 2 });
|
|
316
|
+
}
|
|
317
|
+
return commands;
|
|
318
|
+
}
|
|
@@ -31,22 +31,10 @@ class TupletFunction extends ASTFunctionNode {
|
|
|
31
31
|
},
|
|
32
32
|
],
|
|
33
33
|
};
|
|
34
|
-
static loweringFinalize = (result) => {
|
|
35
|
-
for (const attachment of result.attachments) {
|
|
36
|
-
if (attachment instanceof TupletLayoutAttachment)
|
|
37
|
-
attachment.validate();
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
34
|
content;
|
|
41
35
|
normal;
|
|
42
36
|
font;
|
|
43
37
|
get children() { return [this.content]; }
|
|
44
|
-
timeFlowModel() {
|
|
45
|
-
return {
|
|
46
|
-
mode: "sequence",
|
|
47
|
-
children: [this.content],
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
38
|
loweringEnter(ctx) {
|
|
51
39
|
const group = {
|
|
52
40
|
nodes: [],
|
|
@@ -83,7 +71,7 @@ class TupletFunction extends ASTFunctionNode {
|
|
|
83
71
|
throw new ErrorDiagnostic("E_TUPLET_NON_INTEGRAL_UNITS", "@tuplet 的总时值必须是最短正时值的整数倍,且至少包含2个单位", this.sourceSpan);
|
|
84
72
|
}
|
|
85
73
|
if (this.normal === actual) {
|
|
86
|
-
throw new ErrorDiagnostic("E_TUPLET_INVALID_RATIO",
|
|
74
|
+
throw new ErrorDiagnostic("E_TUPLET_INVALID_RATIO", "@tuplet 的 normal 不能等于推导出的 actual ({actual})", this.sourceSpan, { actual });
|
|
87
75
|
}
|
|
88
76
|
// 以作用域最早时间为仿射缩放原点,不能直接缩放绝对 t,否则嵌套位置会漂移。
|
|
89
77
|
let start = content.nodes[0].t;
|
|
@@ -103,7 +91,9 @@ class TupletFunction extends ASTFunctionNode {
|
|
|
103
91
|
// 括线只依附可见主体;时值缩放本身仍覆盖所有收集到的事件。
|
|
104
92
|
const visible = positive.filter(isVisualTemporalNode);
|
|
105
93
|
if (visible.length >= 2) {
|
|
106
|
-
|
|
94
|
+
const attachment = new TupletLayoutAttachment(visible, actual, this.sourceSpan, this.font, content);
|
|
95
|
+
ctx.addAttachment(attachment);
|
|
96
|
+
ctx.deferFinalize(() => attachment.validate());
|
|
107
97
|
}
|
|
108
98
|
return [];
|
|
109
99
|
}
|