jpfun 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/dist/converter/midi/convert.js +8 -55
- package/dist/converter/musicxml/features.d.ts +1 -1
- package/dist/converter/musicxml/features.js +1 -1
- package/dist/converter/musicxml/index.js +8 -18
- package/dist/converter/source.d.ts +4 -7
- package/dist/converter/source.js +11 -9
- package/dist/functions/ASTtypes.d.ts +1 -14
- package/dist/functions/ASTtypes.js +5 -36
- package/dist/functions/adjust/index.js +45 -33
- package/dist/functions/arpeggio/index.js +42 -45
- package/dist/functions/arpeggio/shape.d.ts +2 -3
- package/dist/functions/arpeggio/shape.js +20 -50
- package/dist/functions/bar/index.js +3 -8
- package/dist/functions/beam/auto.js +54 -123
- package/dist/functions/beam/index.js +4 -9
- package/dist/functions/box/index.js +0 -6
- package/dist/functions/dash/index.js +3 -4
- package/dist/functions/div/index.d.ts +2 -4
- package/dist/functions/div/index.js +10 -10
- package/dist/functions/dot/index.js +3 -9
- package/dist/functions/dyn/index.js +6 -26
- package/dist/functions/gliss/index.js +95 -89
- package/dist/functions/grace/index.d.ts +2 -5
- package/dist/functions/grace/index.js +44 -89
- package/dist/functions/head/index.js +9 -6
- package/dist/functions/key/index.js +6 -6
- package/dist/functions/meter/index.js +3 -3
- package/dist/functions/note/index.js +1 -1
- package/dist/functions/note/source-transform.js +2 -5
- package/dist/functions/ottava/index.js +11 -32
- package/dist/functions/page/index.js +13 -16
- package/dist/functions/rest/index.js +2 -4
- package/dist/functions/slide/index.js +0 -1
- package/dist/functions/stack/index.js +8 -57
- package/dist/functions/temporal.d.ts +2 -2
- package/dist/functions/temporal.js +7 -0
- package/dist/functions/text/index.js +24 -30
- package/dist/functions/tie/index.js +14 -37
- package/dist/functions/tremolo/index.js +0 -1
- package/dist/functions/tuplet/index.js +0 -6
- package/dist/functions/up/index.js +79 -83
- 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 -970
- 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 +65 -56
- package/dist/jpfun.from-midi.min.js +5 -5
- package/dist/jpfun.from-musicxml.min.js +7 -7
- package/dist/jpfun.min.js +68 -59
- 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 +8 -11
- package/dist/lowering/loweringContext.js +7 -13
- package/dist/lowering/track.d.ts +8 -1
- package/dist/lowering/types.d.ts +12 -8
- 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 +17 -28
- package/dist/parser/parse-utils/string-utils.d.ts +1 -1
- package/dist/parser/parse-utils/string-utils.js +8 -6
- package/dist/parser/parserContext.d.ts +9 -9
- package/dist/parser/parserContext.js +54 -10
- package/dist/pipeline.js +2 -2
- package/dist/playback/compile.js +13 -14
- package/dist/playback/event.d.ts +6 -6
- package/dist/playback/event.js +13 -49
- package/dist/render/canvas.d.ts +0 -2
- package/dist/render/canvas.js +0 -21
- 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/types.d.ts +0 -2
- package/grammar.md +16 -13
- package/package.json +1 -1
- 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
|
@@ -3,6 +3,10 @@ import { WarningDiagnostic } from "../../diagnostic.js";
|
|
|
3
3
|
import { createAutomaticBeamAttachments } from "../beam/auto.js";
|
|
4
4
|
const DIV_FUNC_NAME = "div";
|
|
5
5
|
export const DIV_ADDON_KEY = functionAddonKey(DIV_FUNC_NAME);
|
|
6
|
+
const DIV_OWNER_KEY = Symbol("div.owner");
|
|
7
|
+
export function getDivOwner(node) {
|
|
8
|
+
return node.addon?.[DIV_OWNER_KEY];
|
|
9
|
+
}
|
|
6
10
|
/** div 暴露自己的线段端口,不依赖任何关系函数 */
|
|
7
11
|
export function divLinePortName(level, edge) {
|
|
8
12
|
return `div.${level}.${edge}`;
|
|
@@ -101,24 +105,24 @@ class DivFunction extends ASTFunctionNode {
|
|
|
101
105
|
const n = nodes[at++];
|
|
102
106
|
if (n.data?.class !== DivFunction)
|
|
103
107
|
return null;
|
|
104
|
-
const prevIndex =
|
|
108
|
+
const prevIndex = ctx.findLastOperandIndex();
|
|
105
109
|
if (prevIndex < 0)
|
|
106
110
|
return at; // 没有了 直接当作无效文本跳过
|
|
107
111
|
const prev = ctx.nodes[prevIndex];
|
|
108
112
|
if (prev instanceof DivFunction) {
|
|
109
113
|
// 已经是div了 继续加深
|
|
110
114
|
prev.n += n.data.n;
|
|
115
|
+
prev.sourceSpan.end = Math.max(prev.sourceSpan.end, n.span.end);
|
|
111
116
|
return at;
|
|
112
117
|
}
|
|
113
118
|
const argMap = new Map();
|
|
114
119
|
argMap.set(0, prev);
|
|
115
120
|
argMap.set("n", n.data.n);
|
|
116
121
|
const spanPrev = prev.sourceSpan;
|
|
117
|
-
|
|
122
|
+
ctx.nodes[prevIndex] = new DivFunction({
|
|
118
123
|
start: Math.min(spanPrev.start, n.span.start),
|
|
119
124
|
end: Math.max(spanPrev.end, n.span.end),
|
|
120
125
|
}, argMap, ctx, null);
|
|
121
|
-
ctx.nodes[prevIndex] = node;
|
|
122
126
|
return at;
|
|
123
127
|
}
|
|
124
128
|
/**
|
|
@@ -177,11 +181,13 @@ class DivFunction extends ASTFunctionNode {
|
|
|
177
181
|
const count = this.n;
|
|
178
182
|
if (count === 0)
|
|
179
183
|
return [];
|
|
184
|
+
const self = this;
|
|
180
185
|
ctx.deferFinalize(DivFunction.loweringFinalize, -5);
|
|
181
186
|
ctx.beginLoweringGroup(this, {
|
|
182
187
|
onTemporal(node) {
|
|
183
|
-
const addon = node.addon ??= {};
|
|
188
|
+
const addon = (node.addon ??= {});
|
|
184
189
|
addon[DIV_ADDON_KEY] = (Number(addon[DIV_ADDON_KEY]) || 0) + count;
|
|
190
|
+
addon[DIV_OWNER_KEY] = self;
|
|
185
191
|
node.T.divPow2(count);
|
|
186
192
|
},
|
|
187
193
|
});
|
|
@@ -198,12 +204,6 @@ class DivFunction extends ASTFunctionNode {
|
|
|
198
204
|
/** parse 时冻结;只控制不同 div 之间的自动连接,不影响当前 div 内部连接 */
|
|
199
205
|
autoBeamEnabled;
|
|
200
206
|
get children() { return [this.content]; }
|
|
201
|
-
timeFlowModel() {
|
|
202
|
-
return {
|
|
203
|
-
children: [this.content],
|
|
204
|
-
mode: "sequence",
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
207
|
constructor(sourceSpan, args, ctx, parent = null) {
|
|
208
208
|
super(sourceSpan, parent);
|
|
209
209
|
[this.content, this.n, this.autoBeamEnabled] = this.getArgValue(args, ctx);
|
|
@@ -58,13 +58,14 @@ class DotFunction extends ASTFunctionNode {
|
|
|
58
58
|
const n = nodes[at++];
|
|
59
59
|
if (n.data?.class !== DotFunction)
|
|
60
60
|
return null;
|
|
61
|
-
const prevIndex =
|
|
61
|
+
const prevIndex = ctx.findLastOperandIndex();
|
|
62
62
|
if (prevIndex < 0)
|
|
63
63
|
return at; // 没有了 直接当作无效文本跳过
|
|
64
64
|
const prev = ctx.nodes[prevIndex];
|
|
65
65
|
if (prev instanceof DotFunction) {
|
|
66
66
|
// 已经是dot了 继续加深
|
|
67
67
|
prev.n += n.data.n;
|
|
68
|
+
prev.sourceSpan.end = Math.max(prev.sourceSpan.end, n.span.end);
|
|
68
69
|
return at;
|
|
69
70
|
}
|
|
70
71
|
// 参数数量不校验 在构造函数里写
|
|
@@ -72,11 +73,10 @@ class DotFunction extends ASTFunctionNode {
|
|
|
72
73
|
argMap.set(0, prev);
|
|
73
74
|
argMap.set("n", n.data.n);
|
|
74
75
|
const spanPrev = prev.sourceSpan;
|
|
75
|
-
|
|
76
|
+
ctx.nodes[prevIndex] = new DotFunction({
|
|
76
77
|
start: Math.min(spanPrev.start, n.span.start),
|
|
77
78
|
end: Math.max(spanPrev.end, n.span.end),
|
|
78
79
|
}, argMap, ctx, null);
|
|
79
|
-
ctx.nodes[prevIndex] = node;
|
|
80
80
|
return at;
|
|
81
81
|
}
|
|
82
82
|
/**
|
|
@@ -134,12 +134,6 @@ class DotFunction extends ASTFunctionNode {
|
|
|
134
134
|
}
|
|
135
135
|
return [];
|
|
136
136
|
}
|
|
137
|
-
timeFlowModel() {
|
|
138
|
-
return {
|
|
139
|
-
children: [this.content],
|
|
140
|
-
mode: "sequence",
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
137
|
content;
|
|
144
138
|
n;
|
|
145
139
|
get children() { return [this.content]; }
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Diagnostic, ErrorDiagnostic, WarningDiagnostic } from "../../diagnostic.js";
|
|
2
|
+
import { lineEntryX, lineRightX } from "../../layout/range.js";
|
|
2
3
|
import { isVisualTemporalNode, } from "../temporal.js";
|
|
3
4
|
import { ASTFunctionNode, } from "../ASTtypes.js";
|
|
4
5
|
function findRecordBoundary(records, time, after = false) {
|
|
@@ -44,9 +45,7 @@ class DynFunction extends ASTFunctionNode {
|
|
|
44
45
|
const velocity = node.playbackState?.velocity;
|
|
45
46
|
if (velocity === undefined)
|
|
46
47
|
continue;
|
|
47
|
-
|
|
48
|
-
while (host.foldedInto)
|
|
49
|
-
host = host.foldedInto;
|
|
48
|
+
const host = node.rootHost;
|
|
50
49
|
recordsByTrack.get(host.track)?.push({ node, host, velocity, increment: 0 });
|
|
51
50
|
}
|
|
52
51
|
}
|
|
@@ -104,12 +103,8 @@ class DynFunction extends ASTFunctionNode {
|
|
|
104
103
|
ctx.diagnostics.push(Diagnostic.warning.UnresolvedEndpoint("dyn", this.sourceSpan));
|
|
105
104
|
return [];
|
|
106
105
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
while (fromHost.foldedInto)
|
|
110
|
-
fromHost = fromHost.foldedInto;
|
|
111
|
-
while (toHost.foldedInto)
|
|
112
|
-
toHost = toHost.foldedInto;
|
|
106
|
+
const fromHost = from.rootHost;
|
|
107
|
+
const toHost = to.rootHost;
|
|
113
108
|
if (!isVisualTemporalNode(fromHost) || !isVisualTemporalNode(toHost)) {
|
|
114
109
|
ctx.diagnostics.push(Diagnostic.warning.UnresolvedEndpoint("dyn", this.sourceSpan));
|
|
115
110
|
return [];
|
|
@@ -184,10 +179,10 @@ class DynAttachment {
|
|
|
184
179
|
}
|
|
185
180
|
ranges.push({
|
|
186
181
|
line,
|
|
187
|
-
startX: line === fromLine ? this.fromHost.box.x :
|
|
182
|
+
startX: line === fromLine ? this.fromHost.box.x : lineEntryX(context, line, this.track),
|
|
188
183
|
endX: line === toLine
|
|
189
184
|
? this.toHost.box.x + this.toHost.box.w
|
|
190
|
-
:
|
|
185
|
+
: lineRightX(context, line),
|
|
191
186
|
});
|
|
192
187
|
}
|
|
193
188
|
// 允许左边超出一点
|
|
@@ -238,19 +233,4 @@ class DynAttachment {
|
|
|
238
233
|
},
|
|
239
234
|
};
|
|
240
235
|
}
|
|
241
|
-
lineEntryX(context, line) {
|
|
242
|
-
const host = context.lines[line].trackRuns.get(this.track)?.find(item => !item.T.isZero());
|
|
243
|
-
return host?.box.x ?? context.originX;
|
|
244
|
-
}
|
|
245
|
-
lineRightX(context, line) {
|
|
246
|
-
const runs = context.lines[line].trackRuns;
|
|
247
|
-
if (runs.size === 0)
|
|
248
|
-
return context.originX + context.width;
|
|
249
|
-
let right = context.originX;
|
|
250
|
-
for (const run of runs.values()) {
|
|
251
|
-
for (const host of run)
|
|
252
|
-
right = Math.max(right, host.box.x + host.box.w);
|
|
253
|
-
}
|
|
254
|
-
return right;
|
|
255
|
-
}
|
|
256
236
|
}
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import { ErrorDiagnostic, WarningDiagnostic } from "../../diagnostic.js";
|
|
2
2
|
import { pathBounds } from "../../layout/path.js";
|
|
3
|
+
import { lineEntryX, lineRightX } from "../../layout/range.js";
|
|
3
4
|
import { ASTFunctionNode, } from "../ASTtypes.js";
|
|
4
5
|
import { isVisualTemporalNode } from "../temporal.js";
|
|
5
6
|
// gliss 判断音高的准则是 resolvedMidi 属性
|
|
6
|
-
function
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
function findPitchNode(columns, node) {
|
|
7
|
+
function findPitchNode(columns, node, host) {
|
|
8
|
+
const check = (item) => typeof item?.resolvedMidi === "number"
|
|
9
|
+
? item
|
|
10
|
+
: undefined;
|
|
11
11
|
if ("resolvedMidi" in node)
|
|
12
|
-
return
|
|
13
|
-
const host = layoutHost(node);
|
|
12
|
+
return check(node);
|
|
14
13
|
for (let i = columns.findIndex(col => col.includes(host)) - 1; i >= 0; i--) {
|
|
15
14
|
const previous = columns[i].find(item => item.track === host.track && "resolvedMidi" in item);
|
|
16
15
|
if (previous)
|
|
17
|
-
return
|
|
16
|
+
return check(previous);
|
|
18
17
|
}
|
|
19
18
|
}
|
|
20
19
|
class GlissFunction extends ASTFunctionNode {
|
|
@@ -28,16 +27,8 @@ class GlissFunction extends ASTFunctionNode {
|
|
|
28
27
|
若附属对象无音高,将使用前面最近的同轨有音高对象的音高;播放时从起点音段按半音阶离散过渡至终点音高。`,
|
|
29
28
|
allowExtraArgs: false,
|
|
30
29
|
args: [
|
|
31
|
-
{
|
|
32
|
-
|
|
33
|
-
default: null,
|
|
34
|
-
description: "一个端点的标签,先后按谱面时间确定"
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
type: "label",
|
|
38
|
-
default: null,
|
|
39
|
-
description: "另一个端点的标签"
|
|
40
|
-
},
|
|
30
|
+
{ type: "label", default: null, description: "一个端点的标签,先后按谱面时间确定" },
|
|
31
|
+
{ type: "label", default: null, description: "另一个端点的标签" },
|
|
41
32
|
],
|
|
42
33
|
};
|
|
43
34
|
from;
|
|
@@ -81,26 +72,25 @@ class GlissAttachment {
|
|
|
81
72
|
}
|
|
82
73
|
finalize({ columns, diagnostics }) {
|
|
83
74
|
const [a, b] = this.endPoints;
|
|
84
|
-
|
|
85
|
-
|
|
75
|
+
let fromHost = layoutHost(a);
|
|
76
|
+
let toHost = layoutHost(b);
|
|
86
77
|
if (fromHost.t.equals(toHost.t)) {
|
|
87
78
|
throw new ErrorDiagnostic("E_GLISS_ORDER", "@gliss 两个端点不能位于同一时刻", this.sourceSpan);
|
|
88
79
|
}
|
|
89
|
-
if (fromHost.
|
|
90
|
-
throw new ErrorDiagnostic("E_GLISS_CROSS_LINE", "@gliss 不支持跨谱面行", this.sourceSpan);
|
|
91
|
-
}
|
|
92
|
-
if (fromHost.t.compare(toHost.t) > 0)
|
|
80
|
+
if (fromHost.t.compare(toHost.t) > 0) {
|
|
93
81
|
this.endPoints = [b, a];
|
|
82
|
+
[fromHost, toHost] = [toHost, fromHost];
|
|
83
|
+
}
|
|
94
84
|
const [endpoint, target] = this.endPoints;
|
|
95
|
-
const sourcePitchNode = findPitchNode(columns, endpoint);
|
|
96
|
-
const targetPitchNode = findPitchNode(columns, target);
|
|
85
|
+
const sourcePitchNode = findPitchNode(columns, endpoint, fromHost);
|
|
86
|
+
const targetPitchNode = findPitchNode(columns, target, toHost);
|
|
97
87
|
if (!sourcePitchNode || !targetPitchNode) {
|
|
98
88
|
diagnostics.push(new WarningDiagnostic("W_GLISS_NO_PITCH", "@gliss 端点没有可用音高", this.sourceSpan));
|
|
99
89
|
return;
|
|
100
90
|
}
|
|
101
|
-
this.direction = Math.sign(
|
|
91
|
+
this.direction = Math.sign(targetPitchNode.resolvedMidi - sourcePitchNode.resolvedMidi);
|
|
102
92
|
const emit = endpoint.emitPlayback;
|
|
103
|
-
const targetMidi =
|
|
93
|
+
const targetMidi = targetPitchNode.resolvedMidi + (targetPitchNode.playbackState?.pitchShift ?? 0);
|
|
104
94
|
endpoint.emitPlayback = emitter => {
|
|
105
95
|
emit?.call(endpoint, emitter);
|
|
106
96
|
const { start: glissStart, end: glissEnd } = emitter;
|
|
@@ -109,29 +99,27 @@ class GlissAttachment {
|
|
|
109
99
|
const note = context.notes[i];
|
|
110
100
|
if (note.track !== emitter.track)
|
|
111
101
|
continue;
|
|
112
|
-
if (note.end.equals(glissEnd))
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
break;
|
|
102
|
+
if (!note.end.equals(glissEnd))
|
|
103
|
+
return;
|
|
104
|
+
context.transform(note, (_ctx, owned) => {
|
|
105
|
+
const item = owned.at(-1);
|
|
106
|
+
const startFrom = glissStart.compare(item.start) > 0 ? glissStart : item.start;
|
|
107
|
+
const steps = Math.abs(targetMidi - item.midi);
|
|
108
|
+
if (item.end.compare(startFrom) <= 0 || steps <= 1)
|
|
109
|
+
return;
|
|
110
|
+
const dir = Math.sign(targetMidi - item.midi);
|
|
111
|
+
const step = item.end.clone().sub(startFrom).div(steps);
|
|
112
|
+
return [
|
|
113
|
+
...owned.slice(0, -1),
|
|
114
|
+
...Array.from({ length: steps }, (_, k) => ({
|
|
115
|
+
...item,
|
|
116
|
+
start: k === 0 ? item.start.clone() : step.clone().mul(k).add(startFrom),
|
|
117
|
+
end: step.clone().mul(k + 1).add(startFrom),
|
|
118
|
+
midi: item.midi + k * dir,
|
|
119
|
+
})),
|
|
120
|
+
];
|
|
121
|
+
});
|
|
122
|
+
return;
|
|
135
123
|
}
|
|
136
124
|
});
|
|
137
125
|
};
|
|
@@ -139,61 +127,79 @@ class GlissAttachment {
|
|
|
139
127
|
/** 定位端点所在时间列,并为箭头登记水平留白 */
|
|
140
128
|
prepareHorizontal(lines) {
|
|
141
129
|
const [endpoint, target] = this.endPoints;
|
|
142
|
-
const
|
|
143
|
-
const
|
|
144
|
-
const
|
|
145
|
-
const
|
|
146
|
-
const
|
|
147
|
-
|
|
130
|
+
const fromLine = lines[endpoint.layoutLine];
|
|
131
|
+
const toLine = lines[target.layoutLine];
|
|
132
|
+
const from = fromLine && layoutHost(endpoint, fromLine);
|
|
133
|
+
const to = toLine && layoutHost(target, toLine);
|
|
134
|
+
const start = from ? fromLine.columnOf(from) : -1;
|
|
135
|
+
const end = to ? toLine.columnOf(to) : -1;
|
|
136
|
+
if (!fromLine || !toLine || start < 0 || end < 0 || (fromLine === toLine && end <= start)) {
|
|
148
137
|
throw new ErrorDiagnostic("E_GLISS_DOMAIN", "@gliss 的端点必须位于同一排版域的不同时间列", this.sourceSpan);
|
|
149
138
|
}
|
|
150
|
-
const
|
|
139
|
+
const span = Math.max(endpoint.ast.size, target.ast.size) * 1.4;
|
|
140
|
+
const right = from.box.w - from.box.anchor + span;
|
|
151
141
|
// 只扩张求解器占位,不改变端点图形、附点位置或下一轮的 box
|
|
152
|
-
|
|
142
|
+
fromLine.registerHorizontalLayoutHook(from, from, ({ columns }) => {
|
|
153
143
|
// 留白作用于起点整列;取最大值,避免多条关系重复累加占位。
|
|
154
144
|
for (const element of columns[start])
|
|
155
145
|
element.WR = Math.max(element.WR, right);
|
|
156
146
|
});
|
|
147
|
+
if (fromLine !== toLine) {
|
|
148
|
+
const left = to.box.anchor + span;
|
|
149
|
+
toLine.registerHorizontalLayoutHook(to, to, ({ columns }) => {
|
|
150
|
+
for (const element of columns[end])
|
|
151
|
+
element.WL = Math.max(element.WL, left);
|
|
152
|
+
});
|
|
153
|
+
}
|
|
157
154
|
}
|
|
158
|
-
createGeometry() {
|
|
155
|
+
createGeometry(context) {
|
|
159
156
|
const [from, to] = this.endPoints;
|
|
160
157
|
const size = Math.max(from.ast.size, to.ast.size);
|
|
161
158
|
const gap = size * 0.12;
|
|
162
|
-
const
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
159
|
+
const dy = from.track === to.track ? (this.direction ?? 0) * size * 0.24 : 0;
|
|
160
|
+
const start = { x: from.box.x + from.box.w + gap, y: from.box.y + from.box.visualAxis + dy };
|
|
161
|
+
const end = {
|
|
162
|
+
x: to.box.x - gap,
|
|
163
|
+
y: from.track === to.track && this.direction === undefined && from.layoutLine === to.layoutLine
|
|
164
|
+
? start.y
|
|
165
|
+
: to.box.y + to.box.visualAxis - dy,
|
|
166
|
+
};
|
|
167
|
+
const pairs = [[start, end, from.layoutLine, from.track]];
|
|
168
|
+
if (from.layoutLine !== to.layoutLine) {
|
|
169
|
+
const end1X = Math.max(start.x + size, lineRightX(context, from.layoutLine));
|
|
170
|
+
const start2X = Math.min(end.x - size, lineEntryX(context, to.layoutLine, to.track, end.x));
|
|
171
|
+
const w1 = end1X - start.x;
|
|
172
|
+
const cut = dy * (1 - 2 * w1 / (w1 + end.x - start2X));
|
|
173
|
+
pairs[0] = [start, { x: end1X, y: start.y - dy + cut }, from.layoutLine, from.track];
|
|
174
|
+
pairs.push([{ x: start2X, y: end.y + dy + cut }, end, to.layoutLine, to.track]);
|
|
172
175
|
}
|
|
173
|
-
if (end.x <= start.x) {
|
|
176
|
+
else if (end.x <= start.x) {
|
|
174
177
|
throw new ErrorDiagnostic("E_GLISS_SPACE", "@gliss 的端点之间没有可用的水平绘制空间", this.sourceSpan);
|
|
175
178
|
}
|
|
176
|
-
const angle = Math.atan2(end.y - start.y, end.x - start.x);
|
|
177
|
-
const length = Math.min(size * 0.3, Math.hypot(end.x - start.x, end.y - start.y) * 0.35);
|
|
178
|
-
const wing = (offset) => ({
|
|
179
|
-
x: end.x - length * Math.cos(angle + offset),
|
|
180
|
-
y: end.y - length * Math.sin(angle + offset),
|
|
181
|
-
});
|
|
182
|
-
const commands = [
|
|
183
|
-
{ op: "M", ...start }, { op: "L", ...end },
|
|
184
|
-
{ op: "M", ...wing(-Math.PI / 6) }, { op: "L", ...end },
|
|
185
|
-
{ op: "L", ...wing(Math.PI / 6) },
|
|
186
|
-
];
|
|
187
179
|
const strokeWidth = size * 0.05;
|
|
188
|
-
const
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
180
|
+
const commands = [];
|
|
181
|
+
const regions = pairs.map(([s, e, line, track], i) => {
|
|
182
|
+
const part = [{ op: "M", ...s }, { op: "L", ...e }];
|
|
183
|
+
if (i === pairs.length - 1) {
|
|
184
|
+
const angle = Math.atan2(e.y - s.y, e.x - s.x);
|
|
185
|
+
const length = Math.min(size * 0.3, Math.hypot(e.x - s.x, e.y - s.y) * 0.35);
|
|
186
|
+
const wing = (offset) => ({
|
|
187
|
+
x: e.x - length * Math.cos(angle + offset),
|
|
188
|
+
y: e.y - length * Math.sin(angle + offset),
|
|
189
|
+
});
|
|
190
|
+
part.push({ op: "M", ...wing(-Math.PI / 6) }, { op: "L", ...e }, { op: "L", ...wing(Math.PI / 6) });
|
|
191
|
+
}
|
|
192
|
+
commands.push(...part);
|
|
193
|
+
const bounds = pathBounds(part);
|
|
194
|
+
return {
|
|
195
|
+
x: bounds.x - strokeWidth / 2, y: bounds.y - strokeWidth / 2,
|
|
196
|
+
w: bounds.w + strokeWidth, h: bounds.h + strokeWidth, line, track,
|
|
197
|
+
};
|
|
198
|
+
});
|
|
193
199
|
return {
|
|
194
|
-
regions
|
|
200
|
+
regions,
|
|
195
201
|
// 跨轨连线不把整段高度算到起点轨,否则纵向求解会反复撑开两轨
|
|
196
|
-
occupancy: from.track === to.track ?
|
|
202
|
+
occupancy: from.track === to.track ? regions : [],
|
|
197
203
|
paint: (painter) => {
|
|
198
204
|
painter.drawPath(commands, { fill: "none", stroke: "#000", strokeWidth });
|
|
199
205
|
},
|
|
@@ -28,8 +28,8 @@ declare class GraceFunction extends ASTFunctionNode {
|
|
|
28
28
|
*/
|
|
29
29
|
private static attachPre;
|
|
30
30
|
private static create;
|
|
31
|
-
/** 宿主在前:findActiveDivs 下潜子树时要先命中宿主的 @div,而不是倚音的 */
|
|
32
31
|
get children(): ASTNodeBase[];
|
|
32
|
+
timeFlowModel(): null;
|
|
33
33
|
constructor(span: SourceSpan, args: FunctionArgs, ctx: ParserContext, parent?: ASTNodeBase | null, scale?: number);
|
|
34
34
|
setGrace(node: ASTNodeBase, factor?: number): void;
|
|
35
35
|
private adopt;
|
|
@@ -47,9 +47,6 @@ export declare class GraceTemporal extends TemporalNodeBase {
|
|
|
47
47
|
readonly graceColumns: readonly (readonly VisualTemporalNode[])[];
|
|
48
48
|
/** graceColumns 按列展开 */
|
|
49
49
|
readonly graces: readonly VisualTemporalNode[];
|
|
50
|
-
/** 承担节奏的倚音成员,按声部与零时长标记切段;同段视觉上首尾相接,无条件连成一束减时线 */
|
|
51
|
-
readonly graceRuns: readonly (readonly VisualTemporalNode[])[];
|
|
52
|
-
readonly side: GraceSide;
|
|
53
50
|
/** 倚音子域的根轨:由宿主轨分出,不挂进它的分组,子域之外不可见 */
|
|
54
51
|
private readonly root;
|
|
55
52
|
/** 倚音内容里声明的附件,随子域排版 */
|
|
@@ -63,7 +60,7 @@ export declare class GraceTemporal extends TemporalNodeBase {
|
|
|
63
60
|
private graceOffsets;
|
|
64
61
|
/** 倚音线起点,同样是局部偏移 */
|
|
65
62
|
private hookOrigin;
|
|
66
|
-
constructor(ast: GraceFunction, host: VisualTemporalNode, columns: readonly (readonly TemporalNodeBase[])[], root: Track, attachments: readonly LoweringAttachment[],
|
|
63
|
+
constructor(ast: GraceFunction, host: VisualTemporalNode, columns: readonly (readonly TemporalNodeBase[])[], root: Track, attachments: readonly LoweringAttachment[], ctx: LoweringContext);
|
|
67
64
|
/** 成员共享全局时间状态,按发声顺序固化 */
|
|
68
65
|
onTimeState(state: TimeState): void | Fraction;
|
|
69
66
|
prepareHorizontal(line: HorizontalLineView): void;
|