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
|
@@ -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
|
/**
|
|
@@ -130,16 +130,10 @@ class DotFunction extends ASTFunctionNode {
|
|
|
130
130
|
loweringExit(ctx) {
|
|
131
131
|
const group = ctx.endLoweringGroup(this);
|
|
132
132
|
if (group.temporalCount !== 1) {
|
|
133
|
-
throw new ErrorDiagnostic("E_DOT_INVALID_CONTENT",
|
|
133
|
+
throw new ErrorDiagnostic("E_DOT_INVALID_CONTENT", "函数 @dot 只能接收 1个元素,但找到了 {count} 个", this.sourceSpan, { count: group.temporalCount });
|
|
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]; }
|
|
@@ -149,7 +143,7 @@ class DotFunction extends ASTFunctionNode {
|
|
|
149
143
|
this.content.parent = this;
|
|
150
144
|
const n = Math.max(0, Math.trunc(this.n));
|
|
151
145
|
if (n !== this.n) {
|
|
152
|
-
ctx.diagnostics.push(new WarningDiagnostic("W_DOT_INVALID_N",
|
|
146
|
+
ctx.diagnostics.push(new WarningDiagnostic("W_DOT_INVALID_N", "@dot 的数量参数 n 必须为非负整数,已被修正为 {n}", this.sourceSpan, { n }));
|
|
153
147
|
this.n = n;
|
|
154
148
|
}
|
|
155
149
|
}
|
|
@@ -1,6 +1,20 @@
|
|
|
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";
|
|
5
|
+
function findRecordBoundary(records, time, after = false) {
|
|
6
|
+
let low = 0;
|
|
7
|
+
let high = records.length;
|
|
8
|
+
while (low < high) {
|
|
9
|
+
const middle = (low + high) >>> 1;
|
|
10
|
+
const cmp = records[middle].host.t.compare(time);
|
|
11
|
+
if (after ? cmp <= 0 : cmp < 0)
|
|
12
|
+
low = middle + 1;
|
|
13
|
+
else
|
|
14
|
+
high = middle;
|
|
15
|
+
}
|
|
16
|
+
return low;
|
|
17
|
+
}
|
|
4
18
|
class DynFunction extends ASTFunctionNode {
|
|
5
19
|
static def = {
|
|
6
20
|
name: ["dyn"],
|
|
@@ -20,62 +34,64 @@ class DynFunction extends ASTFunctionNode {
|
|
|
20
34
|
{ name: "dv", description: "力度变化量,正数渐强,负数渐弱", type: "number", default: null },
|
|
21
35
|
],
|
|
22
36
|
};
|
|
23
|
-
static loweringFinalize
|
|
37
|
+
static loweringFinalize(result) {
|
|
24
38
|
const dynamics = result.attachments.filter((attachment) => attachment instanceof DynAttachment);
|
|
25
39
|
if (dynamics.length === 0)
|
|
26
40
|
return;
|
|
27
|
-
//
|
|
28
|
-
const
|
|
41
|
+
// 仅收集存在 @dyn 的音轨上的记录,避免无关声部也分配包装对象与排序
|
|
42
|
+
const recordsByTrack = new Map(dynamics.map(d => [d.track, []]));
|
|
29
43
|
for (const nodes of result.astToTemporal.values()) {
|
|
30
44
|
for (const node of nodes) {
|
|
31
45
|
const velocity = node.playbackState?.velocity;
|
|
32
46
|
if (velocity === undefined)
|
|
33
47
|
continue;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
host = host.foldedInto;
|
|
37
|
-
records.push({ node, host, velocity, increment: 0 });
|
|
48
|
+
const host = node.rootHost;
|
|
49
|
+
recordsByTrack.get(host.track)?.push({ node, host, velocity, increment: 0 });
|
|
38
50
|
}
|
|
39
51
|
}
|
|
40
|
-
|
|
52
|
+
for (const list of recordsByTrack.values()) {
|
|
53
|
+
list.sort((left, right) => left.host.t.compare(right.host.t) || left.node.order - right.node.order);
|
|
54
|
+
}
|
|
41
55
|
// 先累计全部 dyn 的贡献,最后统一写回,避免声明顺序改变后续 dyn 读取的原始力度
|
|
42
56
|
for (const dynamic of dynamics) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
57
|
+
const records = recordsByTrack.get(dynamic.track);
|
|
58
|
+
const endStart = findRecordBoundary(records, dynamic.toHost.t);
|
|
59
|
+
const afterEnd = findRecordBoundary(records, dynamic.toHost.t, true);
|
|
60
|
+
let endVelocity = dynamic.end.playbackState?.velocity;
|
|
61
|
+
for (let i = endStart; endVelocity === undefined && i < afterEnd; i++) {
|
|
62
|
+
if (records[i].host === dynamic.toHost)
|
|
63
|
+
endVelocity = records[i].velocity;
|
|
50
64
|
}
|
|
65
|
+
endVelocity ??= records[afterEnd - 1]?.velocity;
|
|
51
66
|
if (endVelocity === undefined) {
|
|
52
67
|
result.diagnostics.push(new WarningDiagnostic("W_DYN_NO_VELOCITY", "@dyn 终点及此前同轨没有可用的力度基准,仅绘制渐变线", dynamic.sourceSpan));
|
|
53
68
|
continue;
|
|
54
69
|
}
|
|
55
70
|
// 终点后保持完整增量,直到原始力度相对终点再次发生变化
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
71
|
+
let stopIndex = records.length;
|
|
72
|
+
for (let i = afterEnd; i < records.length; i++) {
|
|
73
|
+
if (records[i].velocity !== endVelocity) {
|
|
74
|
+
stopIndex = findRecordBoundary(records, records[i].host.t);
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const startIndex = findRecordBoundary(records, dynamic.fromHost.t);
|
|
59
79
|
const duration = dynamic.toHost.t.clone().sub(dynamic.fromHost.t);
|
|
80
|
+
for (let i = startIndex; i < stopIndex; i++) {
|
|
81
|
+
const progress = i >= endStart ? 1
|
|
82
|
+
: records[i].host.t.clone().sub(dynamic.fromHost.t).div(duration).toNumber();
|
|
83
|
+
records[i].increment += dynamic.dv * progress;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
for (const records of recordsByTrack.values()) {
|
|
60
87
|
for (const record of records) {
|
|
61
|
-
if (record.
|
|
88
|
+
if (record.increment === 0)
|
|
62
89
|
continue;
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
continue;
|
|
66
|
-
const progress = record.host.t.compare(dynamic.toHost.t) >= 0
|
|
67
|
-
? 1
|
|
68
|
-
: record.host.t.clone().sub(dynamic.fromHost.t).div(duration).toNumber();
|
|
69
|
-
record.increment += dynamic.dv * progress;
|
|
90
|
+
const velocity = Math.max(1, Math.min(127, record.velocity + record.increment));
|
|
91
|
+
record.node.playbackState = { ...record.node.playbackState, velocity };
|
|
70
92
|
}
|
|
71
93
|
}
|
|
72
|
-
|
|
73
|
-
if (record.increment === 0)
|
|
74
|
-
continue;
|
|
75
|
-
const velocity = Math.max(1, Math.min(127, record.velocity + record.increment));
|
|
76
|
-
record.node.playbackState = { ...record.node.playbackState, velocity };
|
|
77
|
-
}
|
|
78
|
-
};
|
|
94
|
+
}
|
|
79
95
|
from;
|
|
80
96
|
to;
|
|
81
97
|
dv;
|
|
@@ -87,12 +103,8 @@ class DynFunction extends ASTFunctionNode {
|
|
|
87
103
|
ctx.diagnostics.push(Diagnostic.warning.UnresolvedEndpoint("dyn", this.sourceSpan));
|
|
88
104
|
return [];
|
|
89
105
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
while (fromHost.foldedInto)
|
|
93
|
-
fromHost = fromHost.foldedInto;
|
|
94
|
-
while (toHost.foldedInto)
|
|
95
|
-
toHost = toHost.foldedInto;
|
|
106
|
+
const fromHost = from.rootHost;
|
|
107
|
+
const toHost = to.rootHost;
|
|
96
108
|
if (!isVisualTemporalNode(fromHost) || !isVisualTemporalNode(toHost)) {
|
|
97
109
|
ctx.diagnostics.push(Diagnostic.warning.UnresolvedEndpoint("dyn", this.sourceSpan));
|
|
98
110
|
return [];
|
|
@@ -109,6 +121,7 @@ class DynFunction extends ASTFunctionNode {
|
|
|
109
121
|
else {
|
|
110
122
|
ctx.addAttachment(new DynAttachment(this, from, toHost, fromHost));
|
|
111
123
|
}
|
|
124
|
+
ctx.deferFinalize(DynFunction.loweringFinalize);
|
|
112
125
|
return [];
|
|
113
126
|
}
|
|
114
127
|
constructor(span, args, ctx, parent = null) {
|
|
@@ -120,7 +133,7 @@ class DynFunction extends ASTFunctionNode {
|
|
|
120
133
|
}
|
|
121
134
|
dv = Math.max(-127, Math.min(127, dv));
|
|
122
135
|
if (dv !== inputDv) {
|
|
123
|
-
ctx.diagnostics.push(new WarningDiagnostic("W_DYN_DELTA_CLAMPED",
|
|
136
|
+
ctx.diagnostics.push(new WarningDiagnostic("W_DYN_DELTA_CLAMPED", "@dyn 的 dv 必须在 -127 到 127 之间,已被限制为 {dv}", span, { dv }));
|
|
124
137
|
}
|
|
125
138
|
this.from = from;
|
|
126
139
|
this.to = to;
|
|
@@ -166,10 +179,10 @@ class DynAttachment {
|
|
|
166
179
|
}
|
|
167
180
|
ranges.push({
|
|
168
181
|
line,
|
|
169
|
-
startX: line === fromLine ? this.fromHost.box.x :
|
|
182
|
+
startX: line === fromLine ? this.fromHost.box.x : lineEntryX(context, line, this.track),
|
|
170
183
|
endX: line === toLine
|
|
171
184
|
? this.toHost.box.x + this.toHost.box.w
|
|
172
|
-
:
|
|
185
|
+
: lineRightX(context, line),
|
|
173
186
|
});
|
|
174
187
|
}
|
|
175
188
|
// 允许左边超出一点
|
|
@@ -220,19 +233,4 @@ class DynAttachment {
|
|
|
220
233
|
},
|
|
221
234
|
};
|
|
222
235
|
}
|
|
223
|
-
lineEntryX(context, line) {
|
|
224
|
-
const host = context.lines[line].trackRuns.get(this.track)?.find(item => !item.T.isZero());
|
|
225
|
-
return host?.box.x ?? context.originX;
|
|
226
|
-
}
|
|
227
|
-
lineRightX(context, line) {
|
|
228
|
-
const runs = context.lines[line].trackRuns;
|
|
229
|
-
if (runs.size === 0)
|
|
230
|
-
return context.originX + context.width;
|
|
231
|
-
let right = context.originX;
|
|
232
|
-
for (const run of runs.values()) {
|
|
233
|
-
for (const host of run)
|
|
234
|
-
right = Math.max(right, host.box.x + host.box.w);
|
|
235
|
-
}
|
|
236
|
-
return right;
|
|
237
|
-
}
|
|
238
236
|
}
|
|
@@ -1,11 +1,20 @@
|
|
|
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
|
-
|
|
7
|
+
function findPitchNode(columns, node, host) {
|
|
8
|
+
const check = (item) => typeof item?.resolvedMidi === "number"
|
|
9
|
+
? item
|
|
10
|
+
: undefined;
|
|
11
|
+
if ("resolvedMidi" in node)
|
|
12
|
+
return check(node);
|
|
13
|
+
for (let i = columns.findIndex(col => col.includes(host)) - 1; i >= 0; i--) {
|
|
14
|
+
const previous = columns[i].find(item => item.track === host.track && "resolvedMidi" in item);
|
|
15
|
+
if (previous)
|
|
16
|
+
return check(previous);
|
|
17
|
+
}
|
|
9
18
|
}
|
|
10
19
|
class GlissFunction extends ASTFunctionNode {
|
|
11
20
|
static def = {
|
|
@@ -15,19 +24,11 @@ class GlissFunction extends ASTFunctionNode {
|
|
|
15
24
|
~~~jpfun
|
|
16
25
|
1 -@a 5@b @gliss(a, b)
|
|
17
26
|
~~~
|
|
18
|
-
|
|
27
|
+
若附属对象无音高,将使用前面最近的同轨有音高对象的音高;播放时从起点音段按半音阶离散过渡至终点音高。`,
|
|
19
28
|
allowExtraArgs: false,
|
|
20
29
|
args: [
|
|
21
|
-
{
|
|
22
|
-
|
|
23
|
-
default: null,
|
|
24
|
-
description: "一个端点的标签,先后按谱面时间确定"
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
type: "label",
|
|
28
|
-
default: null,
|
|
29
|
-
description: "另一个端点的标签"
|
|
30
|
-
},
|
|
30
|
+
{ type: "label", default: null, description: "一个端点的标签,先后按谱面时间确定" },
|
|
31
|
+
{ type: "label", default: null, description: "另一个端点的标签" },
|
|
31
32
|
],
|
|
32
33
|
};
|
|
33
34
|
from;
|
|
@@ -42,7 +43,9 @@ class GlissFunction extends ASTFunctionNode {
|
|
|
42
43
|
if (!from || !to || !isVisualTemporalNode(from) || !isVisualTemporalNode(to)) {
|
|
43
44
|
throw new ErrorDiagnostic("E_GLISS_ENDPOINT", "@gliss 的标签必须指向已生成且具有排版盒子的对象", this.sourceSpan);
|
|
44
45
|
}
|
|
45
|
-
|
|
46
|
+
const attachment = new GlissAttachment(from, to, this.sourceSpan);
|
|
47
|
+
ctx.addAttachment(attachment);
|
|
48
|
+
ctx.deferFinalize(result => attachment.finalize(result), 1);
|
|
46
49
|
return [];
|
|
47
50
|
}
|
|
48
51
|
toString(source) {
|
|
@@ -59,119 +62,144 @@ function layoutHost(node, line) {
|
|
|
59
62
|
return node;
|
|
60
63
|
}
|
|
61
64
|
class GlissAttachment {
|
|
62
|
-
from;
|
|
63
|
-
to;
|
|
64
65
|
sourceSpan;
|
|
65
|
-
diagnostics;
|
|
66
66
|
layer = "foreground";
|
|
67
67
|
endPoints;
|
|
68
68
|
direction;
|
|
69
|
-
|
|
70
|
-
constructor(from, to, sourceSpan, diagnostics) {
|
|
71
|
-
this.from = from;
|
|
72
|
-
this.to = to;
|
|
69
|
+
constructor(from, to, sourceSpan) {
|
|
73
70
|
this.sourceSpan = sourceSpan;
|
|
74
|
-
this.diagnostics = diagnostics;
|
|
75
71
|
this.endPoints = [from, to];
|
|
76
72
|
}
|
|
77
|
-
|
|
73
|
+
finalize({ columns, diagnostics }) {
|
|
78
74
|
const [a, b] = this.endPoints;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (fromHost.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const from = line && layoutHost(endpoint, line);
|
|
95
|
-
const to = line && layoutHost(target, line);
|
|
96
|
-
const start = from ? line.columnOf(from) : -1;
|
|
97
|
-
const end = to ? line.columnOf(to) : -1;
|
|
98
|
-
if (!line || start < 0 || end <= start) {
|
|
99
|
-
throw new ErrorDiagnostic("E_GLISS_DOMAIN", "@gliss 的端点必须位于同一排版域的不同时间列", sourceSpan);
|
|
75
|
+
let fromHost = layoutHost(a);
|
|
76
|
+
let toHost = layoutHost(b);
|
|
77
|
+
if (fromHost.t.equals(toHost.t)) {
|
|
78
|
+
throw new ErrorDiagnostic("E_GLISS_ORDER", "@gliss 两个端点不能位于同一时刻", this.sourceSpan);
|
|
79
|
+
}
|
|
80
|
+
if (fromHost.t.compare(toHost.t) > 0) {
|
|
81
|
+
this.endPoints = [b, a];
|
|
82
|
+
[fromHost, toHost] = [toHost, fromHost];
|
|
83
|
+
}
|
|
84
|
+
const [endpoint, target] = this.endPoints;
|
|
85
|
+
const sourcePitchNode = findPitchNode(columns, endpoint, fromHost);
|
|
86
|
+
const targetPitchNode = findPitchNode(columns, target, toHost);
|
|
87
|
+
if (!sourcePitchNode || !targetPitchNode) {
|
|
88
|
+
diagnostics.push(new WarningDiagnostic("W_GLISS_NO_PITCH", "@gliss 端点没有可用音高", this.sourceSpan));
|
|
89
|
+
return;
|
|
100
90
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
91
|
+
this.direction = Math.sign(targetPitchNode.resolvedMidi - sourcePitchNode.resolvedMidi);
|
|
92
|
+
const emit = endpoint.emitPlayback;
|
|
93
|
+
const targetMidi = targetPitchNode.resolvedMidi + (targetPitchNode.playbackState?.pitchShift ?? 0);
|
|
94
|
+
endpoint.emitPlayback = emitter => {
|
|
95
|
+
emit?.call(endpoint, emitter);
|
|
96
|
+
const { start: glissStart, end: glissEnd } = emitter;
|
|
97
|
+
emitter.defer(context => {
|
|
98
|
+
for (let i = context.notes.length - 1; i >= 0; i--) {
|
|
99
|
+
const note = context.notes[i];
|
|
100
|
+
if (note.track !== emitter.track)
|
|
101
|
+
continue;
|
|
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;
|
|
113
123
|
}
|
|
114
|
-
}
|
|
124
|
+
});
|
|
115
125
|
};
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
126
|
+
}
|
|
127
|
+
/** 定位端点所在时间列,并为箭头登记水平留白 */
|
|
128
|
+
prepareHorizontal(lines) {
|
|
129
|
+
const [endpoint, target] = this.endPoints;
|
|
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)) {
|
|
137
|
+
throw new ErrorDiagnostic("E_GLISS_DOMAIN", "@gliss 的端点必须位于同一排版域的不同时间列", this.sourceSpan);
|
|
123
138
|
}
|
|
124
|
-
const
|
|
139
|
+
const span = Math.max(endpoint.ast.size, target.ast.size) * 1.4;
|
|
140
|
+
const right = from.box.w - from.box.anchor + span;
|
|
125
141
|
// 只扩张求解器占位,不改变端点图形、附点位置或下一轮的 box
|
|
126
|
-
|
|
142
|
+
fromLine.registerHorizontalLayoutHook(from, from, ({ columns }) => {
|
|
127
143
|
// 留白作用于起点整列;取最大值,避免多条关系重复累加占位。
|
|
128
144
|
for (const element of columns[start])
|
|
129
145
|
element.WR = Math.max(element.WR, right);
|
|
130
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
|
+
}
|
|
131
154
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
createGeometry() {
|
|
136
|
-
// 子域附件可能直接进入几何测量,未经过 prepareHorizontal
|
|
137
|
-
const [from, to] = this.orderedEndpoints;
|
|
138
|
-
const size = this.size;
|
|
155
|
+
createGeometry(context) {
|
|
156
|
+
const [from, to] = this.endPoints;
|
|
157
|
+
const size = Math.max(from.ast.size, to.ast.size);
|
|
139
158
|
const gap = size * 0.12;
|
|
140
|
-
const
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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]);
|
|
150
175
|
}
|
|
151
|
-
if (end.x <= start.x) {
|
|
176
|
+
else if (end.x <= start.x) {
|
|
152
177
|
throw new ErrorDiagnostic("E_GLISS_SPACE", "@gliss 的端点之间没有可用的水平绘制空间", this.sourceSpan);
|
|
153
178
|
}
|
|
154
|
-
const angle = Math.atan2(end.y - start.y, end.x - start.x);
|
|
155
|
-
const length = Math.min(size * 0.3, Math.hypot(end.x - start.x, end.y - start.y) * 0.35);
|
|
156
|
-
const wing = (offset) => ({
|
|
157
|
-
x: end.x - length * Math.cos(angle + offset),
|
|
158
|
-
y: end.y - length * Math.sin(angle + offset),
|
|
159
|
-
});
|
|
160
|
-
const commands = [
|
|
161
|
-
{ op: "M", ...start }, { op: "L", ...end },
|
|
162
|
-
{ op: "M", ...wing(-Math.PI / 6) }, { op: "L", ...end },
|
|
163
|
-
{ op: "L", ...wing(Math.PI / 6) },
|
|
164
|
-
];
|
|
165
179
|
const strokeWidth = size * 0.05;
|
|
166
|
-
const
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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
|
+
});
|
|
171
199
|
return {
|
|
172
|
-
regions
|
|
200
|
+
regions,
|
|
173
201
|
// 跨轨连线不把整段高度算到起点轨,否则纵向求解会反复撑开两轨
|
|
174
|
-
occupancy: from.track === to.track ?
|
|
202
|
+
occupancy: from.track === to.track ? regions : [],
|
|
175
203
|
paint: (painter) => {
|
|
176
204
|
painter.drawPath(commands, { fill: "none", stroke: "#000", strokeWidth });
|
|
177
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,17 +60,11 @@ 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;
|
|
70
|
-
/**
|
|
71
|
-
* 播放时倚音从宿主借走的时值(前倚音从开头、后倚音从末尾)
|
|
72
|
-
*
|
|
73
|
-
* 比例 = 倚音块字面时长 / 四分音符,而四分音符 T=1,所以直接取各声部最晚的局部终点。
|
|
74
|
-
* 基准取宿主经过 div 与 dot 后的实际时值;延时线是独立事件、tie 不改 T,天然不计入。
|
|
75
|
-
* 局部时间按同一比例映射进借走的时值,各声部因此同时起奏。
|
|
76
|
-
*/
|
|
67
|
+
/** 按最长声部的书写时长 × 1/4 借时,最多占宿主一半;前倚音借开头,后倚音借末尾。 */
|
|
77
68
|
emitPlayback(emitter: PlaybackEmitter): void;
|
|
78
69
|
/**
|
|
79
70
|
* 宿主留在轨道基线上,倚音整体抬到它的左上或右上角
|